Annotation of loncom/interface/domainprefs.pm, revision 1.404
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.404 ! raeburn 4: # $Id: domainprefs.pm,v 1.403 2022/01/19 16:54:16 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.394 raeburn 224: 'proctoring','wafproxy','ipaccess'],$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.394 raeburn 263: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
264: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 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.394 raeburn 627: 'ipaccess' =>
628: {text => 'IP-based access control',
629: help => 'Domain_Configuration_IP_Access',
630: header => [{col1 => 'Setting',
631: col2 => 'Value'},],
632: print => \&print_ipaccess,
633: modify => \&modify_ipaccess,
634: },
1.3 raeburn 635: );
1.110 raeburn 636: if (keys(%servers) > 1) {
637: $prefs{'login'} = { text => 'Log-in page options',
638: help => 'Domain_Configuration_Login_Page',
639: header => [{col1 => 'Log-in Service',
640: col2 => 'Server Setting',},
641: {col1 => 'Log-in Page Items',
1.168 raeburn 642: col2 => ''},
643: {col1 => 'Log-in Help',
1.256 raeburn 644: col2 => 'Value'},
645: {col1 => 'Custom HTML in document head',
1.386 raeburn 646: col2 => 'Value'},
647: {col1 => 'SSO',
648: col2 => 'Dual login: SSO and non-SSO options'},
649: ],
1.230 raeburn 650: print => \&print_login,
651: modify => \&modify_login,
1.110 raeburn 652: };
653: }
1.174 foxr 654:
1.6 raeburn 655: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 656: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 657: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 658: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 659: text=>"Settings to display/modify"});
1.9 raeburn 660: my $confname = $dom.'-domainconfig';
1.174 foxr 661:
1.3 raeburn 662: if ($phase eq 'process') {
1.212 raeburn 663: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
664: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 665: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 666: $r->rflush();
1.212 raeburn 667: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 668: }
1.30 raeburn 669: } elsif ($phase eq 'display') {
1.192 raeburn 670: my $js = &recaptcha_js().
1.236 raeburn 671: &toggle_display_js();
1.171 raeburn 672: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 673: my ($othertitle,$usertypes,$types) =
674: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 675: $js .= &lonbalance_targets_js($dom,$types,\%servers,
676: $domconfig{'loadbalancing'}).
1.170 raeburn 677: &new_spares_js().
678: &common_domprefs_js().
679: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 680: }
1.216 raeburn 681: if (grep(/^requestcourses$/,@actions)) {
682: my $javascript_validations;
683: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
684: $js .= <<END;
685: <script type="text/javascript">
686: $javascript_validations
687: </script>
688: $coursebrowserjs
689: END
1.394 raeburn 690: } elsif (grep(/^ipaccess$/,@actions)) {
691: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 692: }
1.305 raeburn 693: if (grep(/^selfcreation$/,@actions)) {
694: $js .= &selfcreate_javascript();
695: }
1.286 raeburn 696: if (grep(/^contacts$/,@actions)) {
697: $js .= &contacts_javascript();
698: }
1.346 raeburn 699: if (grep(/^scantron$/,@actions)) {
700: $js .= &scantron_javascript();
701: }
1.150 raeburn 702: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 703: } else {
1.180 raeburn 704: # check if domconfig user exists for the domain.
705: my $servadm = $r->dir_config('lonAdmEMail');
706: my ($configuserok,$author_ok,$switchserver) =
707: &config_check($dom,$confname,$servadm);
708: unless ($configuserok eq 'ok') {
1.181 raeburn 709: &Apache::lonconfigsettings::print_header($r,$phase,$context);
710: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 711: $confname).
1.181 raeburn 712: '<br />'
713: );
1.180 raeburn 714: if ($switchserver) {
1.181 raeburn 715: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
716: '<br />'.
717: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
718: '<br />'.
719: &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).
720: '<br />'.
721: &mt('To do that now, use the following link: [_1]',$switchserver)
722: );
723: } else {
724: $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.').
725: '<br />'.
726: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
727: );
1.180 raeburn 728: }
729: $r->print(&Apache::loncommon::end_page());
730: return OK;
731: }
1.21 raeburn 732: if (keys(%domconfig) == 0) {
733: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 734: my @ids=&Apache::lonnet::current_machine_ids();
735: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 736: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 737: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 738: my $custom_img_count = 0;
739: foreach my $img (@loginimages) {
740: if ($designhash{$dom.'.login.'.$img} ne '') {
741: $custom_img_count ++;
742: }
743: }
744: foreach my $role (@roles) {
745: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
746: $custom_img_count ++;
747: }
748: }
749: if ($custom_img_count > 0) {
1.94 raeburn 750: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 751: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 752: $r->print(
753: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
754: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
755: &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 />'.
756: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
757: if ($switch_server) {
1.30 raeburn 758: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 759: }
1.91 raeburn 760: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 761: return OK;
762: }
763: }
764: }
1.91 raeburn 765: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 766: }
767: return OK;
768: }
769:
770: sub process_changes {
1.205 raeburn 771: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 772: my %domconfig;
773: if (ref($values) eq 'HASH') {
774: %domconfig = %{$values};
775: }
1.3 raeburn 776: my $output;
777: if ($action eq 'login') {
1.205 raeburn 778: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 779: } elsif ($action eq 'rolecolors') {
1.9 raeburn 780: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 781: $lastactref,%domconfig);
1.3 raeburn 782: } elsif ($action eq 'quotas') {
1.216 raeburn 783: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 784: } elsif ($action eq 'autoenroll') {
1.205 raeburn 785: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 786: } elsif ($action eq 'autoupdate') {
787: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 788: } elsif ($action eq 'autocreate') {
789: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 790: } elsif ($action eq 'directorysrch') {
1.295 raeburn 791: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 792: } elsif ($action eq 'usercreation') {
1.28 raeburn 793: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 794: } elsif ($action eq 'selfcreation') {
1.305 raeburn 795: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 796: } elsif ($action eq 'usermodification') {
797: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 798: } elsif ($action eq 'contacts') {
1.205 raeburn 799: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 800: } elsif ($action eq 'defaults') {
1.212 raeburn 801: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 802: } elsif ($action eq 'scantron') {
1.205 raeburn 803: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 804: } elsif ($action eq 'coursecategories') {
1.239 raeburn 805: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 806: } elsif ($action eq 'serverstatuses') {
807: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 808: } elsif ($action eq 'requestcourses') {
1.216 raeburn 809: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 810: } elsif ($action eq 'requestauthor') {
1.216 raeburn 811: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 812: } elsif ($action eq 'helpsettings') {
1.285 raeburn 813: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 814: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 815: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 816: } elsif ($action eq 'selfenrollment') {
817: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 818: } elsif ($action eq 'usersessions') {
1.212 raeburn 819: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 820: } elsif ($action eq 'loadbalancing') {
821: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 822: } elsif ($action eq 'ltitools') {
823: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 824: } elsif ($action eq 'proctoring') {
825: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 826: } elsif ($action eq 'ssl') {
827: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 828: } elsif ($action eq 'trust') {
829: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 830: } elsif ($action eq 'lti') {
831: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 832: } elsif ($action eq 'privacy') {
833: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 834: } elsif ($action eq 'passwords') {
835: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 836: } elsif ($action eq 'wafproxy') {
837: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 838: } elsif ($action eq 'ipaccess') {
839: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 840: }
841: return $output;
842: }
843:
844: sub print_config_box {
1.9 raeburn 845: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 846: my $rowtotal = 0;
1.49 raeburn 847: my $output;
848: if ($action eq 'coursecategories') {
849: $output = &coursecategories_javascript($settings);
1.236 raeburn 850: } elsif ($action eq 'defaults') {
851: $output = &defaults_javascript($settings);
1.354 raeburn 852: } elsif ($action eq 'passwords') {
853: $output = &passwords_javascript();
1.282 raeburn 854: } elsif ($action eq 'helpsettings') {
855: my (%privs,%levelscurrent);
856: my %full=();
857: my %levels=(
858: course => {},
859: domain => {},
860: system => {},
861: );
862: my $context = 'domain';
863: my $crstype = 'Course';
864: my $formname = 'display';
865: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
866: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
867: $output =
868: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
869: \@templateroles);
1.334 raeburn 870: } elsif ($action eq 'ltitools') {
871: $output .= <itools_javascript($settings);
872: } elsif ($action eq 'lti') {
873: $output .= <i_javascript($settings);
1.372 raeburn 874: } elsif ($action eq 'proctoring') {
875: $output .= &proctoring_javascript($settings);
1.381 raeburn 876: } elsif ($action eq 'wafproxy') {
877: $output .= &wafproxy_javascript($dom);
1.385 raeburn 878: } elsif ($action eq 'autoupdate') {
879: $output .= &autoupdate_javascript();
1.399 raeburn 880: } elsif ($action eq 'autoenroll') {
881: $output .= &autoenroll_javascript();
1.386 raeburn 882: } elsif ($action eq 'login') {
883: $output .= &saml_javascript();
1.394 raeburn 884: } elsif ($action eq 'ipaccess') {
885: $output .= &ipaccess_javascript($settings);
1.91 raeburn 886: }
1.236 raeburn 887: $output .=
1.30 raeburn 888: '<table class="LC_nested_outer">
1.3 raeburn 889: <tr>
1.306 raeburn 890: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 891: &mt($item->{text}).' '.
892: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
893: '</tr>';
1.30 raeburn 894: $rowtotal ++;
1.110 raeburn 895: my $numheaders = 1;
896: if (ref($item->{'header'}) eq 'ARRAY') {
897: $numheaders = scalar(@{$item->{'header'}});
898: }
899: if ($numheaders > 1) {
1.64 raeburn 900: my $colspan = '';
1.145 raeburn 901: my $rightcolspan = '';
1.369 raeburn 902: my $leftnobr = '';
1.238 raeburn 903: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 904: ($action eq 'directorysrch') ||
1.386 raeburn 905: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 906: $colspan = ' colspan="2"';
907: }
1.145 raeburn 908: if ($action eq 'usersessions') {
909: $rightcolspan = ' colspan="3"';
910: }
1.369 raeburn 911: if ($action eq 'passwords') {
912: $leftnobr = ' LC_nobreak';
913: }
1.30 raeburn 914: $output .= '
1.3 raeburn 915: <tr>
916: <td>
917: <table class="LC_nested">
918: <tr class="LC_info_row">
1.369 raeburn 919: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 920: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 921: </tr>';
1.69 raeburn 922: $rowtotal ++;
1.230 raeburn 923: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 924: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 925: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 926: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 927: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 928: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 929: } elsif ($action eq 'passwords') {
930: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 931: } elsif ($action eq 'coursecategories') {
1.230 raeburn 932: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 933: } elsif ($action eq 'scantron') {
934: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 935: } elsif ($action eq 'login') {
1.386 raeburn 936: if ($numheaders == 5) {
1.168 raeburn 937: $colspan = ' colspan="2"';
938: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
939: } else {
940: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
941: }
1.230 raeburn 942: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 943: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 944: } elsif ($action eq 'rolecolors') {
1.30 raeburn 945: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 946: }
1.30 raeburn 947: $output .= '
1.6 raeburn 948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
1.230 raeburn 955: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 956: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 957: </tr>';
958: $rowtotal ++;
1.230 raeburn 959: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
960: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 961: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 962: ($action eq 'trust') || ($action eq 'contacts') ||
963: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 964: if ($action eq 'coursecategories') {
965: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
966: $colspan = ' colspan="2"';
1.279 raeburn 967: } elsif ($action eq 'trust') {
968: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 969: } elsif ($action eq 'passwords') {
970: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 971: } else {
972: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
973: }
1.279 raeburn 974: if ($action eq 'trust') {
975: $output .= '
976: </table>
977: </td>
978: </tr>';
979: my @trusthdrs = qw(2 3 4 5 6 7);
980: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
981: for (my $i=0; $i<@trusthdrs; $i++) {
982: $output .= '
983: <tr>
984: <td>
985: <table class="LC_nested">
986: <tr class="LC_info_row">
987: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
988: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
989: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
990: </table>
991: </td>
992: </tr>';
993: }
994: $output .= '
995: <tr>
996: <td>
997: <table class="LC_nested">
998: <tr class="LC_info_row">
999: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1000: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1001: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1002: } else {
1003: $output .= '
1.63 raeburn 1004: </table>
1005: </td>
1006: </tr>
1007: <tr>
1008: <td>
1009: <table class="LC_nested">
1010: <tr class="LC_info_row">
1011: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1012: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1013: </tr>'."\n";
1.279 raeburn 1014: if ($action eq 'coursecategories') {
1015: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 1016: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 1017: if ($action eq 'passwords') {
1018: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1019: } else {
1020: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1021: }
1022: $output .= '
1.340 raeburn 1023: </tr>
1024: </table>
1025: </td>
1026: </tr>
1027: <tr>
1028: <td>
1029: <table class="LC_nested">
1030: <tr class="LC_info_row">
1.369 raeburn 1031: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1032: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1033: if ($action eq 'passwords') {
1034: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1035: } else {
1036: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1037: }
1038: $output .= '
1.340 raeburn 1039: </table>
1040: </td>
1041: </tr>
1042: <tr>';
1.279 raeburn 1043: } else {
1044: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1045: }
1.238 raeburn 1046: }
1.63 raeburn 1047: $rowtotal ++;
1.236 raeburn 1048: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1049: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1050: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1051: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1052: } elsif ($action eq 'scantron') {
1053: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1054: } elsif ($action eq 'ssl') {
1055: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1056: </table>
1057: </td>
1058: </tr>
1059: <tr>
1060: <td>
1061: <table class="LC_nested">
1062: <tr class="LC_info_row">
1063: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1064: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1065: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1066: </table>
1067: </td>
1068: </tr>
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1074: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1075: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1076: } elsif ($action eq 'login') {
1.386 raeburn 1077: if ($numheaders == 5) {
1.168 raeburn 1078: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1079: </table>
1080: </td>
1081: </tr>
1082: <tr>
1083: <td>
1084: <table class="LC_nested">
1085: <tr class="LC_info_row">
1086: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1087: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1088: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1089: $rowtotal ++;
1090: } else {
1091: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1092: }
1.256 raeburn 1093: $output .= '
1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">';
1.386 raeburn 1101: if ($numheaders == 5) {
1.256 raeburn 1102: $output .= '
1103: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1104: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1105: </tr>';
1106: } else {
1107: $output .= '
1108: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1109: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1110: </tr>';
1111: }
1112: $rowtotal ++;
1.386 raeburn 1113: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1114: </table>
1115: </td>
1116: </tr>
1117: <tr>
1118: <td>
1119: <table class="LC_nested">
1120: <tr class="LC_info_row">';
1121: if ($numheaders == 5) {
1122: $output .= '
1123: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1124: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1125: </tr>';
1126: } else {
1127: $output .= '
1128: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1129: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1130: </tr>';
1131: }
1132: $rowtotal ++;
1133: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1134: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1135: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1136: $rowtotal ++;
1137: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1138: </table>
1139: </td>
1140: </tr>
1141: <tr>
1142: <td>
1143: <table class="LC_nested">
1144: <tr class="LC_info_row">
1145: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1146: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1147: &textbookcourses_javascript($settings).
1148: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1149: </table>
1150: </td>
1151: </tr>
1152: <tr>
1153: <td>
1154: <table class="LC_nested">
1155: <tr class="LC_info_row">
1156: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1157: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1158: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 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">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1167: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1168: </tr>'.
1169: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1170: } elsif ($action eq 'requestauthor') {
1171: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1172: $rowtotal ++;
1.122 jms 1173: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1174: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1175: </table>
1176: </td>
1177: </tr>
1178: <tr>
1179: <td>
1180: <table class="LC_nested">
1181: <tr class="LC_info_row">
1.306 raeburn 1182: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1183: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1184: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1185: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1186: </tr>'.
1.30 raeburn 1187: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1188: </table>
1189: </td>
1190: </tr>
1191: <tr>
1192: <td>
1193: <table class="LC_nested">
1194: <tr class="LC_info_row">
1.59 bisitz 1195: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1196: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1197: </tr>'.
1.30 raeburn 1198: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1199: $rowtotal += 2;
1.6 raeburn 1200: }
1.3 raeburn 1201: } else {
1.30 raeburn 1202: $output .= '
1.3 raeburn 1203: <tr>
1204: <td>
1205: <table class="LC_nested">
1.30 raeburn 1206: <tr class="LC_info_row">';
1.277 raeburn 1207: if ($action eq 'login') {
1.30 raeburn 1208: $output .= '
1.59 bisitz 1209: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1210: } elsif ($action eq 'serverstatuses') {
1211: $output .= '
1.306 raeburn 1212: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1213: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1214:
1.6 raeburn 1215: } else {
1.30 raeburn 1216: $output .= '
1.306 raeburn 1217: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1218: }
1.72 raeburn 1219: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1220: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1221: &mt($item->{'header'}->[0]->{'col2'});
1222: if ($action eq 'serverstatuses') {
1223: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1224: }
1.69 raeburn 1225: } else {
1.306 raeburn 1226: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1227: &mt($item->{'header'}->[0]->{'col2'});
1228: }
1229: $output .= '</td>';
1230: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1231: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1232: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1233: &mt($item->{'header'}->[0]->{'col3'});
1234: } else {
1.306 raeburn 1235: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1236: &mt($item->{'header'}->[0]->{'col3'});
1237: }
1.69 raeburn 1238: if ($action eq 'serverstatuses') {
1239: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1240: }
1241: $output .= '</td>';
1.6 raeburn 1242: }
1.150 raeburn 1243: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1244: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1245: &mt($item->{'header'}->[0]->{'col4'});
1246: }
1.69 raeburn 1247: $output .= '</tr>';
1.48 raeburn 1248: $rowtotal ++;
1.168 raeburn 1249: if ($action eq 'quotas') {
1.86 raeburn 1250: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1251: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1252: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1253: ($action eq 'ltitools') || ($action eq 'lti') ||
1.394 raeburn 1254: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1255: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1256: }
1.3 raeburn 1257: }
1.30 raeburn 1258: $output .= '
1.3 raeburn 1259: </table>
1260: </td>
1261: </tr>
1.30 raeburn 1262: </table><br />';
1263: return ($output,$rowtotal);
1.1 raeburn 1264: }
1265:
1.3 raeburn 1266: sub print_login {
1.168 raeburn 1267: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1268: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1269: my %choices = &login_choices();
1.386 raeburn 1270: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1271: %lt = &login_file_options();
1272: $switchserver = &check_switchserver($dom,$confname);
1273: }
1.168 raeburn 1274: if ($caller eq 'service') {
1.149 raeburn 1275: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1276: my $choice = $choices{'disallowlogin'};
1277: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1278: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1279: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1280: '<th>'.$choices{'server'}.'</th>'.
1281: '<th>'.$choices{'serverpath'}.'</th>'.
1282: '<th>'.$choices{'custompath'}.'</th>'.
1283: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1284: my %disallowed;
1285: if (ref($settings) eq 'HASH') {
1286: if (ref($settings->{'loginvia'}) eq 'HASH') {
1287: %disallowed = %{$settings->{'loginvia'}};
1288: }
1289: }
1290: foreach my $lonhost (sort(keys(%servers))) {
1291: my $direct = 'selected="selected"';
1.128 raeburn 1292: if (ref($disallowed{$lonhost}) eq 'HASH') {
1293: if ($disallowed{$lonhost}{'server'} ne '') {
1294: $direct = '';
1295: }
1.110 raeburn 1296: }
1.115 raeburn 1297: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1298: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1299: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1300: '</option>';
1.184 raeburn 1301: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1302: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1303: my $selected = '';
1.128 raeburn 1304: if (ref($disallowed{$lonhost}) eq 'HASH') {
1305: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1306: $selected = 'selected="selected"';
1307: }
1.110 raeburn 1308: }
1309: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1310: $servers{$hostid}.'</option>';
1311: }
1.128 raeburn 1312: $datatable .= '</select></td>'.
1313: '<td><select name="'.$lonhost.'_serverpath">';
1314: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1315: my $pathname = $path;
1316: if ($path eq 'custom') {
1317: $pathname = &mt('Custom Path').' ->';
1318: }
1319: my $selected = '';
1320: if (ref($disallowed{$lonhost}) eq 'HASH') {
1321: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1322: $selected = 'selected="selected"';
1323: }
1324: } elsif ($path eq '') {
1325: $selected = 'selected="selected"';
1326: }
1327: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1328: }
1329: $datatable .= '</select></td>';
1330: my ($custom,$exempt);
1331: if (ref($disallowed{$lonhost}) eq 'HASH') {
1332: $custom = $disallowed{$lonhost}{'custompath'};
1333: $exempt = $disallowed{$lonhost}{'exempt'};
1334: }
1335: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1336: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1337: '</tr>';
1.110 raeburn 1338: }
1339: $datatable .= '</table></td></tr>';
1340: return $datatable;
1.168 raeburn 1341: } elsif ($caller eq 'page') {
1342: my %defaultchecked = (
1343: 'coursecatalog' => 'on',
1.188 raeburn 1344: 'helpdesk' => 'on',
1.168 raeburn 1345: 'adminmail' => 'off',
1346: 'newuser' => 'off',
1347: );
1.188 raeburn 1348: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1349: my (%checkedon,%checkedoff);
1.42 raeburn 1350: foreach my $item (@toggles) {
1.168 raeburn 1351: if ($defaultchecked{$item} eq 'on') {
1352: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1353: $checkedoff{$item} = ' ';
1.168 raeburn 1354: } elsif ($defaultchecked{$item} eq 'off') {
1355: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1356: $checkedon{$item} = ' ';
1357: }
1.1 raeburn 1358: }
1.168 raeburn 1359: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1360: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1361: my @logintext = ('textcol','bgcol');
1362: my @bgs = ('pgbg','mainbg','sidebg');
1363: my @links = ('link','alink','vlink');
1364: my %designhash = &Apache::loncommon::get_domainconf($dom);
1365: my %defaultdesign = %Apache::loncommon::defaultdesign;
1366: my (%is_custom,%designs);
1367: my %defaults = (
1368: font => $defaultdesign{'login.font'},
1369: );
1.6 raeburn 1370: foreach my $item (@images) {
1.168 raeburn 1371: $defaults{$item} = $defaultdesign{'login.'.$item};
1372: $defaults{'showlogo'}{$item} = 1;
1373: }
1374: foreach my $item (@bgs) {
1375: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1376: }
1.41 raeburn 1377: foreach my $item (@logintext) {
1.168 raeburn 1378: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1379: }
1.168 raeburn 1380: foreach my $item (@links) {
1381: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1382: }
1.168 raeburn 1383: if (ref($settings) eq 'HASH') {
1384: foreach my $item (@toggles) {
1385: if ($settings->{$item} eq '1') {
1386: $checkedon{$item} = ' checked="checked" ';
1387: $checkedoff{$item} = ' ';
1388: } elsif ($settings->{$item} eq '0') {
1389: $checkedoff{$item} = ' checked="checked" ';
1390: $checkedon{$item} = ' ';
1391: }
1392: }
1393: foreach my $item (@images) {
1394: if (defined($settings->{$item})) {
1395: $designs{$item} = $settings->{$item};
1396: $is_custom{$item} = 1;
1397: }
1398: if (defined($settings->{'showlogo'}{$item})) {
1399: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1400: }
1401: }
1.402 raeburn 1402: foreach my $item (@alttext) {
1403: if (ref($settings->{'alttext'}) eq 'HASH') {
1404: if ($settings->{'alttext'}->{$item} ne '') {
1405: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1406: }
1407: }
1408: }
1.168 raeburn 1409: foreach my $item (@logintext) {
1410: if ($settings->{$item} ne '') {
1411: $designs{'logintext'}{$item} = $settings->{$item};
1412: $is_custom{$item} = 1;
1413: }
1414: }
1415: if ($settings->{'font'} ne '') {
1416: $designs{'font'} = $settings->{'font'};
1417: $is_custom{'font'} = 1;
1418: }
1419: foreach my $item (@bgs) {
1420: if ($settings->{$item} ne '') {
1421: $designs{'bgs'}{$item} = $settings->{$item};
1422: $is_custom{$item} = 1;
1423: }
1424: }
1425: foreach my $item (@links) {
1426: if ($settings->{$item} ne '') {
1427: $designs{'links'}{$item} = $settings->{$item};
1428: $is_custom{$item} = 1;
1429: }
1430: }
1431: } else {
1432: if ($designhash{$dom.'.login.font'} ne '') {
1433: $designs{'font'} = $designhash{$dom.'.login.font'};
1434: $is_custom{'font'} = 1;
1435: }
1436: foreach my $item (@images) {
1437: if ($designhash{$dom.'.login.'.$item} ne '') {
1438: $designs{$item} = $designhash{$dom.'.login.'.$item};
1439: $is_custom{$item} = 1;
1440: }
1441: }
1442: foreach my $item (@bgs) {
1443: if ($designhash{$dom.'.login.'.$item} ne '') {
1444: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1445: $is_custom{$item} = 1;
1446: }
1.6 raeburn 1447: }
1.168 raeburn 1448: foreach my $item (@links) {
1449: if ($designhash{$dom.'.login.'.$item} ne '') {
1450: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1451: $is_custom{$item} = 1;
1452: }
1.6 raeburn 1453: }
1454: }
1.168 raeburn 1455: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1456: logo => 'Institution Logo',
1457: domlogo => 'Domain Logo',
1458: login => 'Login box');
1459: my $itemcount = 1;
1460: foreach my $item (@toggles) {
1461: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1462: $datatable .=
1463: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1464: '</td><td>'.
1465: '<span class="LC_nobreak"><label><input type="radio" name="'.
1466: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1467: '</label> <label><input type="radio" name="'.$item.'"'.
1468: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1469: '</tr>';
1470: $itemcount ++;
1.6 raeburn 1471: }
1.168 raeburn 1472: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1473: $datatable .= '</tr></table></td></tr>';
1474: } elsif ($caller eq 'help') {
1.386 raeburn 1475: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1476: my $itemcount = 1;
1477: $defaulturl = '/adm/loginproblems.html';
1478: $defaulttype = 'default';
1479: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1480: my @currlangs;
1481: if (ref($settings) eq 'HASH') {
1482: if (ref($settings->{'helpurl'}) eq 'HASH') {
1483: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1484: next if ($settings->{'helpurl'}{$key} eq '');
1485: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1486: $type{$key} = 'custom';
1487: unless ($key eq 'nolang') {
1488: push(@currlangs,$key);
1489: }
1490: }
1491: } elsif ($settings->{'helpurl'} ne '') {
1492: $type{'nolang'} = 'custom';
1493: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1494: }
1495: }
1.168 raeburn 1496: foreach my $lang ('nolang',sort(@currlangs)) {
1497: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1498: $datatable .= '<tr'.$css_class.'>';
1499: if ($url{$lang} eq '') {
1500: $url{$lang} = $defaulturl;
1501: }
1502: if ($type{$lang} eq '') {
1503: $type{$lang} = $defaulttype;
1504: }
1505: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1506: if ($lang eq 'nolang') {
1507: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1508: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1509: } else {
1510: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1511: $langchoices{$lang},
1512: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1513: }
1514: $datatable .= '</span></td>'."\n".
1515: '<td class="LC_left_item">';
1516: if ($type{$lang} eq 'custom') {
1517: $datatable .= '<span class="LC_nobreak"><label>'.
1518: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1519: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1520: } else {
1521: $datatable .= $lt{'upl'};
1522: }
1523: $datatable .='<br />';
1524: if ($switchserver) {
1525: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1526: } else {
1527: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1528: }
1.168 raeburn 1529: $datatable .= '</td></tr>';
1530: $itemcount ++;
1.6 raeburn 1531: }
1.168 raeburn 1532: my @addlangs;
1533: foreach my $lang (sort(keys(%langchoices))) {
1534: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1535: push(@addlangs,$lang);
1536: }
1537: if (@addlangs > 0) {
1538: my %toadd;
1539: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1540: $toadd{''} = &mt('Select');
1541: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1542: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1543: &mt('Add log-in help page for a specific language:').' '.
1544: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1545: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1546: if ($switchserver) {
1547: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1548: } else {
1549: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1550: }
1.168 raeburn 1551: $datatable .= '</td></tr>';
1.169 raeburn 1552: $itemcount ++;
1.6 raeburn 1553: }
1.169 raeburn 1554: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1555: } elsif ($caller eq 'headtag') {
1556: my %domservers = &Apache::lonnet::get_servers($dom);
1557: my $choice = $choices{'headtag'};
1558: $css_class = ' class="LC_odd_row"';
1559: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1560: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1561: '<th>'.$choices{'current'}.'</th>'.
1562: '<th>'.$choices{'action'}.'</th>'.
1563: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1564: my (%currurls,%currexempt);
1565: if (ref($settings) eq 'HASH') {
1566: if (ref($settings->{'headtag'}) eq 'HASH') {
1567: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1568: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1569: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1570: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1571: }
1572: }
1573: }
1574: }
1575: foreach my $lonhost (sort(keys(%domservers))) {
1576: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1577: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1578: if ($currurls{$lonhost}) {
1579: $datatable .= '<td class="LC_right_item"><a href="'.
1580: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1581: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1582: '">'.$lt{'curr'}.'</a></td>'.
1583: '<td><span class="LC_nobreak"><label>'.
1584: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1585: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1586: } else {
1587: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1588: }
1589: $datatable .='<br />';
1590: if ($switchserver) {
1591: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1592: } else {
1593: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1594: }
1.330 raeburn 1595: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1596: }
1597: $datatable .= '</table></td></tr>';
1.386 raeburn 1598: } elsif ($caller eq 'saml') {
1599: my %domservers = &Apache::lonnet::get_servers($dom);
1600: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1601: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1602: '<th>'.$choices{'samllanding'}.'</th>'.
1603: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1604: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1605: foreach my $lonhost (keys(%domservers)) {
1606: $samlurl{$lonhost} = '/adm/sso';
1607: $styleon{$lonhost} = 'display:none';
1608: $styleoff{$lonhost} = '';
1609: }
1610: if (ref($settings->{'saml'}) eq 'HASH') {
1611: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1612: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1613: $saml{$lonhost} = 1;
1614: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1615: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1616: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1617: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1618: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1619: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1620: $styleon{$lonhost} = '';
1621: $styleoff{$lonhost} = 'display:none';
1622: } else {
1623: $styleon{$lonhost} = 'display:none';
1624: $styleoff{$lonhost} = '';
1625: }
1626: }
1627: }
1628: my $itemcount = 1;
1629: foreach my $lonhost (sort(keys(%domservers))) {
1630: my $samlon = ' ';
1631: my $samloff = ' checked="checked" ';
1632: if ($saml{$lonhost}) {
1633: $samlon = $samloff;
1634: $samloff = ' ';
1635: }
1636: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1637: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1638: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1639: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1640: &mt('No').'</label>'.(' 'x2).
1641: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1642: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1643: &mt('Yes').'</label></span></td>'.
1644: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1645: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1646: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1647: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1648: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1649: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1650: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1651: $samltext{$lonhost}.'" /></td><td>';
1652: if ($samlimg{$lonhost}) {
1653: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1654: '<span class="LC_nobreak"><label>'.
1655: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1656: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1657: } else {
1658: $datatable .= $lt{'upl'};
1659: }
1660: $datatable .='<br />';
1661: if ($switchserver) {
1662: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1663: } else {
1664: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1665: }
1666: $datatable .= '</td>'.
1667: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1668: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1669: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1670: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1671: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1672: $samltitle{$lonhost}.'</textarea></td>'.
1673: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1674: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1675: '</table></td>'.
1676: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1677: $itemcount ++;
1678: }
1679: $datatable .= '</table></td></tr>';
1.1 raeburn 1680: }
1.6 raeburn 1681: return $datatable;
1682: }
1683:
1684: sub login_choices {
1685: my %choices =
1686: &Apache::lonlocal::texthash (
1.116 bisitz 1687: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1688: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1689: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1690: disallowlogin => "Login page requests redirected",
1691: hostid => "Server",
1.128 raeburn 1692: server => "Redirect to:",
1693: serverpath => "Path",
1694: custompath => "Custom",
1695: exempt => "Exempt IP(s)",
1.110 raeburn 1696: directlogin => "No redirect",
1697: newuser => "Link to create a user account",
1698: img => "Header",
1699: logo => "Main Logo",
1700: domlogo => "Domain Logo",
1701: login => "Log-in Header",
1702: textcol => "Text color",
1703: bgcol => "Box color",
1704: bgs => "Background colors",
1705: links => "Link colors",
1706: font => "Font color",
1707: pgbg => "Header",
1708: mainbg => "Page",
1709: sidebg => "Login box",
1710: link => "Link",
1711: alink => "Active link",
1712: vlink => "Visited link",
1.256 raeburn 1713: headtag => "Custom markup",
1714: action => "Action",
1715: current => "Current",
1.386 raeburn 1716: samllanding => "Dual login?",
1717: samloptions => "Options",
1.402 raeburn 1718: alttext => "Alt text",
1.6 raeburn 1719: );
1720: return %choices;
1721: }
1722:
1.386 raeburn 1723: sub login_file_options {
1724: return &Apache::lonlocal::texthash(
1725: del => 'Delete?',
1726: rep => 'Replace:',
1727: upl => 'Upload:',
1728: curr => 'View contents',
1729: default => 'Default',
1730: custom => 'Custom',
1731: none => 'None',
1732: );
1733: }
1734:
1.394 raeburn 1735: sub print_ipaccess {
1736: my ($dom,$settings,$rowtotal) = @_;
1737: my $css_class;
1738: my $itemcount = 0;
1739: my $datatable;
1740: my %ordered;
1741: if (ref($settings) eq 'HASH') {
1742: foreach my $item (keys(%{$settings})) {
1743: if (ref($settings->{$item}) eq 'HASH') {
1744: my $num = $settings->{$item}{'order'};
1745: if ($num eq '') {
1746: $num = scalar(keys(%{$settings}));
1747: }
1748: $ordered{$num} = $item;
1749: }
1750: }
1751: }
1752: my $maxnum = scalar(keys(%ordered));
1753: if (keys(%ordered)) {
1754: my @items = sort { $a <=> $b } keys(%ordered);
1755: for (my $i=0; $i<@items; $i++) {
1756: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1757: my $item = $ordered{$items[$i]};
1758: my ($name,$ipranges,%commblocks,%courses);
1759: if (ref($settings->{$item}) eq 'HASH') {
1760: $name = $settings->{$item}->{'name'};
1761: $ipranges = $settings->{$item}->{'ip'};
1762: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1763: %commblocks = %{$settings->{$item}->{'commblocks'}};
1764: }
1765: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1766: %courses = %{$settings->{$item}->{'courses'}};
1767: }
1768: }
1769: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1770: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1771: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1772: for (my $k=0; $k<=$maxnum; $k++) {
1773: my $vpos = $k+1;
1774: my $selstr;
1775: if ($k == $i) {
1776: $selstr = ' selected="selected" ';
1777: }
1778: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1779: }
1780: $datatable .= '</select>'.(' 'x2).
1781: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1782: &mt('Delete?').'</label></span></td>'.
1783: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1784: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1785: '</td></tr>';
1786: $itemcount ++;
1787: }
1788: }
1789: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1790: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1791: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1792: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1793: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1794: for (my $k=0; $k<$maxnum+1; $k++) {
1795: my $vpos = $k+1;
1796: my $selstr;
1797: if ($k == $maxnum) {
1798: $selstr = ' selected="selected" ';
1799: }
1800: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1801: }
1802: $datatable .= '</select> '."\n".
1803: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1804: '<td colspan="2">'.
1805: &ipaccess_options('add',$itemcount,$dom).
1806: '</td>'."\n".
1807: '</tr>'."\n";
1808: $$rowtotal ++;
1809: return $datatable;
1810: }
1811:
1812: sub ipaccess_options {
1813: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1814: my (%currblocks,%currcourses,$output);
1815: if (ref($blocksref) eq 'HASH') {
1816: %currblocks = %{$blocksref};
1817: }
1818: if (ref($coursesref) eq 'HASH') {
1819: %currcourses = %{$coursesref};
1820: }
1821: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1822: '<span class="LC_nobreak">'.&mt('Name').': '.
1823: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1824: '</span></fieldset>'.
1825: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1826: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1827: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1828: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1829: $ipranges.'</textarea></fieldset>'.
1830: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1831: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1832: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1833: '<table>';
1834: foreach my $cid (sort(keys(%currcourses))) {
1835: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1836: $output .= '<tr><td><span class="LC_nobreak">'.
1837: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1838: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1839: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1840: }
1841: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1842: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1843: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1844: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1845: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1846: '</span></td></tr></table>'."\n".
1847: '</fieldset>';
1848: return $output;
1849: }
1850:
1851: sub blocker_checkboxes {
1852: my ($num,$blocks) = @_;
1853: my ($typeorder,$types) = &commblocktype_text();
1854: my $numinrow = 6;
1855: my $output = '<table>';
1856: for (my $i=0; $i<@{$typeorder}; $i++) {
1857: my $block = $typeorder->[$i];
1858: my $blockstatus;
1859: if (ref($blocks) eq 'HASH') {
1860: if ($blocks->{$block} eq 'on') {
1861: $blockstatus = 'checked="checked"';
1862: }
1863: }
1864: my $rem = $i%($numinrow);
1865: if ($rem == 0) {
1866: if ($i > 0) {
1867: $output .= '</tr>';
1868: }
1869: $output .= '<tr>';
1870: }
1871: if ($i == scalar(@{$typeorder})-1) {
1872: my $colsleft = $numinrow-$rem;
1873: if ($colsleft > 1) {
1874: $output .= '<td colspan="'.$colsleft.'">';
1875: } else {
1876: $output .= '<td>';
1877: }
1878: } else {
1879: $output .= '<td>';
1880: }
1881: my $item = 'ipaccess_block_'.$num;
1882: if ($blockstatus) {
1883: $blockstatus = ' '.$blockstatus;
1884: }
1885: $output .= '<span class="LC_nobreak"><label>'."\n".
1886: '<input type="checkbox" name="'.$item.'"'.
1887: $blockstatus.' value="'.$block.'"'.' />'.
1888: $types->{$block}.'</label></span>'."\n".
1889: '<br /></td>';
1890: }
1891: $output .= '</tr></table>';
1892: return $output;
1893: }
1894:
1895: sub commblocktype_text {
1896: my %types = &Apache::lonlocal::texthash(
1897: 'com' => 'Messaging',
1898: 'chat' => 'Chat Room',
1899: 'boards' => 'Discussion',
1900: 'port' => 'Portfolio',
1901: 'groups' => 'Groups',
1902: 'blogs' => 'Blogs',
1903: 'about' => 'User Information',
1904: 'printout' => 'Printouts',
1905: 'passwd' => 'Change Password',
1906: 'grades' => 'Gradebook',
1.397 raeburn 1907: 'search' => 'Course search',
1908: 'wishlist' => 'Stored links',
1909: 'annotate' => 'Annotations',
1.394 raeburn 1910: );
1.397 raeburn 1911: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1912: return ($typeorder,\%types);
1913: }
1914:
1.6 raeburn 1915: sub print_rolecolors {
1.30 raeburn 1916: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1917: my %choices = &color_font_choices();
1918: my @bgs = ('pgbg','tabbg','sidebg');
1919: my @links = ('link','alink','vlink');
1920: my @images = ('img');
1921: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1922: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1923: my %defaultdesign = %Apache::loncommon::defaultdesign;
1924: my (%is_custom,%designs);
1.200 raeburn 1925: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1926: if (ref($settings) eq 'HASH') {
1927: if (ref($settings->{$role}) eq 'HASH') {
1928: if ($settings->{$role}->{'img'} ne '') {
1929: $designs{'img'} = $settings->{$role}->{'img'};
1930: $is_custom{'img'} = 1;
1931: }
1932: if ($settings->{$role}->{'font'} ne '') {
1933: $designs{'font'} = $settings->{$role}->{'font'};
1934: $is_custom{'font'} = 1;
1935: }
1.97 tempelho 1936: if ($settings->{$role}->{'fontmenu'} ne '') {
1937: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1938: $is_custom{'fontmenu'} = 1;
1939: }
1.6 raeburn 1940: foreach my $item (@bgs) {
1941: if ($settings->{$role}->{$item} ne '') {
1942: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1943: $is_custom{$item} = 1;
1944: }
1945: }
1946: foreach my $item (@links) {
1947: if ($settings->{$role}->{$item} ne '') {
1948: $designs{'links'}{$item} = $settings->{$role}->{$item};
1949: $is_custom{$item} = 1;
1950: }
1951: }
1952: }
1953: } else {
1954: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1955: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1956: $is_custom{'img'} = 1;
1957: }
1.97 tempelho 1958: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1959: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1960: $is_custom{'fontmenu'} = 1;
1961: }
1.6 raeburn 1962: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1963: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1964: $is_custom{'font'} = 1;
1965: }
1966: foreach my $item (@bgs) {
1967: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1968: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1969: $is_custom{$item} = 1;
1970:
1971: }
1972: }
1973: foreach my $item (@links) {
1974: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1975: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1976: $is_custom{$item} = 1;
1977: }
1978: }
1979: }
1980: my $itemcount = 1;
1.30 raeburn 1981: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1982: $datatable .= '</tr></table></td></tr>';
1983: return $datatable;
1984: }
1985:
1.200 raeburn 1986: sub role_defaults {
1987: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1988: my %defaults;
1989: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1990: return %defaults;
1991: }
1992: my %defaultdesign = %Apache::loncommon::defaultdesign;
1993: if ($role eq 'login') {
1994: %defaults = (
1995: font => $defaultdesign{$role.'.font'},
1996: );
1997: if (ref($logintext) eq 'ARRAY') {
1998: foreach my $item (@{$logintext}) {
1999: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2000: }
2001: }
2002: foreach my $item (@{$images}) {
2003: $defaults{'showlogo'}{$item} = 1;
2004: }
2005: } else {
2006: %defaults = (
2007: img => $defaultdesign{$role.'.img'},
2008: font => $defaultdesign{$role.'.font'},
2009: fontmenu => $defaultdesign{$role.'.fontmenu'},
2010: );
2011: }
2012: foreach my $item (@{$bgs}) {
2013: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2014: }
2015: foreach my $item (@{$links}) {
2016: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2017: }
2018: foreach my $item (@{$images}) {
2019: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2020: }
2021: return %defaults;
2022: }
2023:
1.6 raeburn 2024: sub display_color_options {
1.9 raeburn 2025: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2026: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2027: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2028: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2029: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2030: '<td>'.$choices->{'font'}.'</td>';
2031: if (!$is_custom->{'font'}) {
1.329 raeburn 2032: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2033: } else {
2034: $datatable .= '<td> </td>';
2035: }
1.174 foxr 2036: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2037:
1.8 raeburn 2038: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2039: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2040: ' value="'.$current_color.'" /> '.
1.329 raeburn 2041: ' </span></td></tr>';
1.107 raeburn 2042: unless ($role eq 'login') {
2043: $datatable .= '<tr'.$css_class.'>'.
2044: '<td>'.$choices->{'fontmenu'}.'</td>';
2045: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2046: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2047: } else {
2048: $datatable .= '<td> </td>';
2049: }
1.202 raeburn 2050: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2051: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2052: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2053: '<input class="colorchooser" type="text" size="10" name="'
2054: .$role.'_fontmenu"'.
2055: ' value="'.$current_color.'" /> '.
1.329 raeburn 2056: ' </span></td></tr>';
1.97 tempelho 2057: }
1.9 raeburn 2058: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2059: foreach my $img (@{$images}) {
1.18 albertel 2060: $itemcount ++;
1.6 raeburn 2061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2062: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2063: '<td>'.$choices->{$img};
1.402 raeburn 2064: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2065: if ($role eq 'login') {
2066: if ($img eq 'login') {
2067: $login_hdr_pick =
1.135 bisitz 2068: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2069: $logincolors =
2070: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2071: $designs,$defaults);
1.402 raeburn 2072: } else {
2073: if ($img ne 'domlogo') {
2074: $datatable.= &logo_display_options($img,$defaults,$designs);
2075: }
2076: if (ref($designs->{'alttext'}) eq 'HASH') {
2077: $alttext = $designs->{'alttext'}{$img};
2078: }
1.70 raeburn 2079: }
2080: }
2081: $datatable .= '</td>';
1.6 raeburn 2082: if ($designs->{$img} ne '') {
2083: $imgfile = $designs->{$img};
1.18 albertel 2084: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2085: } else {
2086: $imgfile = $defaults->{$img};
2087: }
2088: if ($imgfile) {
1.9 raeburn 2089: my ($showfile,$fullsize);
2090: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2091: my $urldir = $1;
2092: my $filename = $2;
2093: my @info = &Apache::lonnet::stat_file($designs->{$img});
2094: if (@info) {
2095: my $thumbfile = 'tn-'.$filename;
2096: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2097: if (@thumb) {
2098: $showfile = $urldir.'/'.$thumbfile;
2099: } else {
2100: $showfile = $imgfile;
2101: }
2102: } else {
2103: $showfile = '';
2104: }
2105: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2106: $showfile = $imgfile;
1.6 raeburn 2107: my $imgdir = $1;
2108: my $filename = $2;
1.159 raeburn 2109: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2110: $showfile = "/$imgdir/tn-".$filename;
2111: } else {
1.159 raeburn 2112: my $input = $londocroot.$imgfile;
2113: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2114: if (!-e $output) {
1.9 raeburn 2115: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2116: my ($fullwidth,$fullheight) = &check_dimensions($input);
2117: if ($fullwidth ne '' && $fullheight ne '') {
2118: if ($fullwidth > $width && $fullheight > $height) {
2119: my $size = $width.'x'.$height;
1.316 raeburn 2120: my @args = ('convert','-sample',$size,$input,$output);
2121: system({$args[0]} @args);
1.159 raeburn 2122: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2123: }
2124: }
1.6 raeburn 2125: }
2126: }
1.16 raeburn 2127: }
1.6 raeburn 2128: if ($showfile) {
1.40 raeburn 2129: if ($showfile =~ m{^/(adm|res)/}) {
2130: if ($showfile =~ m{^/res/}) {
2131: my $local_showfile =
2132: &Apache::lonnet::filelocation('',$showfile);
2133: &Apache::lonnet::repcopy($local_showfile);
2134: }
2135: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2136: }
2137: if ($imgfile) {
2138: if ($imgfile =~ m{^/(adm|res)/}) {
2139: if ($imgfile =~ m{^/res/}) {
2140: my $local_imgfile =
2141: &Apache::lonnet::filelocation('',$imgfile);
2142: &Apache::lonnet::repcopy($local_imgfile);
2143: }
2144: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2145: } else {
2146: $fullsize = $imgfile;
2147: }
2148: }
1.41 raeburn 2149: $datatable .= '<td>';
2150: if ($img eq 'login') {
1.135 bisitz 2151: $datatable .= $login_hdr_pick;
2152: }
1.41 raeburn 2153: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2154: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2155: } else {
1.201 raeburn 2156: $datatable .= '<td> </td><td class="LC_left_item">'.
2157: &mt('Upload:').'<br />';
1.6 raeburn 2158: }
2159: } else {
1.201 raeburn 2160: $datatable .= '<td> </td><td class="LC_left_item">'.
2161: &mt('Upload:').'<br />';
1.6 raeburn 2162: }
1.9 raeburn 2163: if ($switchserver) {
2164: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2165: } else {
1.135 bisitz 2166: if ($img ne 'login') { # suppress file selection for Log-in header
2167: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2168: }
1.9 raeburn 2169: }
1.402 raeburn 2170: if (($role eq 'login') && ($img ne 'login')) {
2171: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2172: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2173: '</label></span>';
2174: }
1.9 raeburn 2175: $datatable .= '</td></tr>';
1.6 raeburn 2176: }
2177: $itemcount ++;
2178: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2179: $datatable .= '<tr'.$css_class.'>'.
2180: '<td>'.$choices->{'bgs'}.'</td>';
2181: my $bgs_def;
2182: foreach my $item (@{$bgs}) {
2183: if (!$is_custom->{$item}) {
1.329 raeburn 2184: $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 2185: }
2186: }
2187: if ($bgs_def) {
1.8 raeburn 2188: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2189: } else {
2190: $datatable .= '<td> </td>';
2191: }
2192: $datatable .= '<td class="LC_right_item">'.
2193: '<table border="0"><tr>';
1.174 foxr 2194:
1.6 raeburn 2195: foreach my $item (@{$bgs}) {
1.306 raeburn 2196: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2197: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2198: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2199: $datatable .= ' ';
1.6 raeburn 2200: }
1.174 foxr 2201: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2202: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2203: }
2204: $datatable .= '</tr></table></td></tr>';
2205: $itemcount ++;
2206: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2207: $datatable .= '<tr'.$css_class.'>'.
2208: '<td>'.$choices->{'links'}.'</td>';
2209: my $links_def;
2210: foreach my $item (@{$links}) {
2211: if (!$is_custom->{$item}) {
1.329 raeburn 2212: $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 2213: }
2214: }
2215: if ($links_def) {
1.8 raeburn 2216: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2217: } else {
2218: $datatable .= '<td> </td>';
2219: }
2220: $datatable .= '<td class="LC_right_item">'.
2221: '<table border="0"><tr>';
2222: foreach my $item (@{$links}) {
1.234 raeburn 2223: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2224: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2225: if ($designs->{'links'}{$item}) {
1.174 foxr 2226: $datatable.=' ';
1.6 raeburn 2227: }
1.174 foxr 2228: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2229: '" /></td>';
2230: }
1.30 raeburn 2231: $$rowtotal += $itemcount;
1.3 raeburn 2232: return $datatable;
2233: }
2234:
1.70 raeburn 2235: sub logo_display_options {
2236: my ($img,$defaults,$designs) = @_;
2237: my $checkedon;
2238: if (ref($defaults) eq 'HASH') {
2239: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2240: if ($defaults->{'showlogo'}{$img}) {
2241: $checkedon = 'checked="checked" ';
2242: }
2243: }
2244: }
2245: if (ref($designs) eq 'HASH') {
2246: if (ref($designs->{'showlogo'}) eq 'HASH') {
2247: if (defined($designs->{'showlogo'}{$img})) {
2248: if ($designs->{'showlogo'}{$img} == 0) {
2249: $checkedon = '';
2250: } elsif ($designs->{'showlogo'}{$img} == 1) {
2251: $checkedon = 'checked="checked" ';
2252: }
2253: }
2254: }
2255: }
2256: return '<br /><label> <input type="checkbox" name="'.
2257: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2258: &mt('show').'</label>'."\n";
2259: }
2260:
1.41 raeburn 2261: sub login_header_options {
1.135 bisitz 2262: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2263: my $output = '';
1.41 raeburn 2264: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2265: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2266: if (!$is_custom->{'textcol'}) {
2267: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2268: ' ';
2269: }
2270: if (!$is_custom->{'bgcol'}) {
2271: $output .= $choices->{'bgcol'}.': '.
2272: '<span id="css_'.$role.'_font" style="background-color: '.
2273: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2274: }
2275: $output .= '<br />';
2276: }
2277: $output .='<br />';
2278: return $output;
2279: }
2280:
2281: sub login_text_colors {
1.201 raeburn 2282: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2283: my $color_menu = '<table border="0"><tr>';
2284: foreach my $item (@{$logintext}) {
1.306 raeburn 2285: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2286: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2287: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2288: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2289: }
2290: $color_menu .= '</tr></table><br />';
2291: return $color_menu;
2292: }
2293:
2294: sub image_changes {
2295: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2296: my $output;
1.135 bisitz 2297: if ($img eq 'login') {
1.331 raeburn 2298: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2299: } elsif (!$is_custom) {
1.70 raeburn 2300: if ($img ne 'domlogo') {
1.331 raeburn 2301: $output = &mt('Default image:').'<br />';
1.41 raeburn 2302: } else {
1.331 raeburn 2303: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2304: }
2305: }
1.331 raeburn 2306: if ($img ne 'login') {
1.135 bisitz 2307: if ($img_import) {
2308: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2309: }
2310: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2311: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2312: if ($is_custom) {
2313: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2314: '<input type="checkbox" name="'.
2315: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2316: '</label> '.&mt('Replace:').'</span><br />';
2317: } else {
1.306 raeburn 2318: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2319: }
1.41 raeburn 2320: }
2321: return $output;
2322: }
2323:
1.3 raeburn 2324: sub print_quotas {
1.86 raeburn 2325: my ($dom,$settings,$rowtotal,$action) = @_;
2326: my $context;
2327: if ($action eq 'quotas') {
2328: $context = 'tools';
2329: } else {
2330: $context = $action;
2331: }
1.197 raeburn 2332: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2333: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2334: my $typecount = 0;
1.101 raeburn 2335: my ($css_class,%titles);
1.86 raeburn 2336: if ($context eq 'requestcourses') {
1.325 raeburn 2337: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2338: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2339: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2340: %titles = &courserequest_titles();
1.163 raeburn 2341: } elsif ($context eq 'requestauthor') {
2342: @usertools = ('author');
2343: @options = ('norequest','approval','automatic');
1.210 raeburn 2344: %titles = &authorrequest_titles();
1.86 raeburn 2345: } else {
1.162 raeburn 2346: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2347: %titles = &tool_titles();
1.86 raeburn 2348: }
1.26 raeburn 2349: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2350: foreach my $type (@{$types}) {
1.197 raeburn 2351: my ($currdefquota,$currauthorquota);
1.163 raeburn 2352: unless (($context eq 'requestcourses') ||
2353: ($context eq 'requestauthor')) {
1.86 raeburn 2354: if (ref($settings) eq 'HASH') {
2355: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2356: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2357: } else {
2358: $currdefquota = $settings->{$type};
2359: }
1.197 raeburn 2360: if (ref($settings->{authorquota}) eq 'HASH') {
2361: $currauthorquota = $settings->{authorquota}->{$type};
2362: }
1.78 raeburn 2363: }
1.72 raeburn 2364: }
1.3 raeburn 2365: if (defined($usertypes->{$type})) {
2366: $typecount ++;
2367: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2368: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2369: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2370: '<td class="LC_left_item">';
1.101 raeburn 2371: if ($context eq 'requestcourses') {
2372: $datatable .= '<table><tr>';
2373: }
2374: my %cell;
1.72 raeburn 2375: foreach my $item (@usertools) {
1.101 raeburn 2376: if ($context eq 'requestcourses') {
2377: my ($curroption,$currlimit);
2378: if (ref($settings) eq 'HASH') {
2379: if (ref($settings->{$item}) eq 'HASH') {
2380: $curroption = $settings->{$item}->{$type};
2381: if ($curroption =~ /^autolimit=(\d*)$/) {
2382: $currlimit = $1;
2383: }
2384: }
2385: }
2386: if (!$curroption) {
2387: $curroption = 'norequest';
2388: }
2389: $datatable .= '<th>'.$titles{$item}.'</th>';
2390: foreach my $option (@options) {
2391: my $val = $option;
2392: if ($option eq 'norequest') {
2393: $val = 0;
2394: }
2395: if ($option eq 'validate') {
2396: my $canvalidate = 0;
2397: if (ref($validations{$item}) eq 'HASH') {
2398: if ($validations{$item}{$type}) {
2399: $canvalidate = 1;
2400: }
2401: }
2402: next if (!$canvalidate);
2403: }
2404: my $checked = '';
2405: if ($option eq $curroption) {
2406: $checked = ' checked="checked"';
2407: } elsif ($option eq 'autolimit') {
2408: if ($curroption =~ /^autolimit/) {
2409: $checked = ' checked="checked"';
2410: }
2411: }
2412: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2413: '<input type="radio" name="crsreq_'.$item.
2414: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2415: $titles{$option}.'</label>';
1.101 raeburn 2416: if ($option eq 'autolimit') {
1.127 raeburn 2417: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2418: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2419: 'value="'.$currlimit.'" />';
1.101 raeburn 2420: }
1.127 raeburn 2421: $cell{$item} .= '</span> ';
1.103 raeburn 2422: if ($option eq 'autolimit') {
1.127 raeburn 2423: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2424: }
1.101 raeburn 2425: }
1.163 raeburn 2426: } elsif ($context eq 'requestauthor') {
2427: my $curroption;
2428: if (ref($settings) eq 'HASH') {
2429: $curroption = $settings->{$type};
2430: }
2431: if (!$curroption) {
2432: $curroption = 'norequest';
2433: }
2434: foreach my $option (@options) {
2435: my $val = $option;
2436: if ($option eq 'norequest') {
2437: $val = 0;
2438: }
2439: my $checked = '';
2440: if ($option eq $curroption) {
2441: $checked = ' checked="checked"';
2442: }
2443: $datatable .= '<span class="LC_nobreak"><label>'.
2444: '<input type="radio" name="authorreq_'.$type.
2445: '" value="'.$val.'"'.$checked.' />'.
2446: $titles{$option}.'</label></span> ';
2447: }
1.101 raeburn 2448: } else {
2449: my $checked = 'checked="checked" ';
2450: if (ref($settings) eq 'HASH') {
2451: if (ref($settings->{$item}) eq 'HASH') {
2452: if ($settings->{$item}->{$type} == 0) {
2453: $checked = '';
2454: } elsif ($settings->{$item}->{$type} == 1) {
2455: $checked = 'checked="checked" ';
2456: }
1.78 raeburn 2457: }
1.72 raeburn 2458: }
1.101 raeburn 2459: $datatable .= '<span class="LC_nobreak"><label>'.
2460: '<input type="checkbox" name="'.$context.'_'.$item.
2461: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2462: '</label></span> ';
1.72 raeburn 2463: }
1.101 raeburn 2464: }
2465: if ($context eq 'requestcourses') {
2466: $datatable .= '</tr><tr>';
2467: foreach my $item (@usertools) {
1.106 raeburn 2468: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2469: }
2470: $datatable .= '</tr></table>';
1.72 raeburn 2471: }
1.86 raeburn 2472: $datatable .= '</td>';
1.163 raeburn 2473: unless (($context eq 'requestcourses') ||
2474: ($context eq 'requestauthor')) {
1.86 raeburn 2475: $datatable .=
1.197 raeburn 2476: '<td class="LC_right_item">'.
2477: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2478: '<input type="text" name="quota_'.$type.
1.72 raeburn 2479: '" value="'.$currdefquota.
1.197 raeburn 2480: '" size="5" /></span>'.(' ' x 2).
2481: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2482: '<input type="text" name="authorquota_'.$type.
2483: '" value="'.$currauthorquota.
2484: '" size="5" /></span></td>';
1.86 raeburn 2485: }
2486: $datatable .= '</tr>';
1.3 raeburn 2487: }
2488: }
2489: }
1.163 raeburn 2490: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2491: $defaultquota = '20';
1.197 raeburn 2492: $authorquota = '500';
1.86 raeburn 2493: if (ref($settings) eq 'HASH') {
2494: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2495: $defaultquota = $settings->{'defaultquota'}->{'default'};
2496: } elsif (defined($settings->{'default'})) {
2497: $defaultquota = $settings->{'default'};
2498: }
1.197 raeburn 2499: if (ref($settings->{'authorquota'}) eq 'HASH') {
2500: $authorquota = $settings->{'authorquota'}->{'default'};
2501: }
1.3 raeburn 2502: }
2503: }
2504: $typecount ++;
2505: $css_class = $typecount%2?' class="LC_odd_row"':'';
2506: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2507: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2508: '<td class="LC_left_item">';
1.101 raeburn 2509: if ($context eq 'requestcourses') {
2510: $datatable .= '<table><tr>';
2511: }
2512: my %defcell;
1.72 raeburn 2513: foreach my $item (@usertools) {
1.101 raeburn 2514: if ($context eq 'requestcourses') {
2515: my ($curroption,$currlimit);
2516: if (ref($settings) eq 'HASH') {
2517: if (ref($settings->{$item}) eq 'HASH') {
2518: $curroption = $settings->{$item}->{'default'};
2519: if ($curroption =~ /^autolimit=(\d*)$/) {
2520: $currlimit = $1;
2521: }
2522: }
2523: }
2524: if (!$curroption) {
2525: $curroption = 'norequest';
2526: }
2527: $datatable .= '<th>'.$titles{$item}.'</th>';
2528: foreach my $option (@options) {
2529: my $val = $option;
2530: if ($option eq 'norequest') {
2531: $val = 0;
2532: }
2533: if ($option eq 'validate') {
2534: my $canvalidate = 0;
2535: if (ref($validations{$item}) eq 'HASH') {
2536: if ($validations{$item}{'default'}) {
2537: $canvalidate = 1;
2538: }
2539: }
2540: next if (!$canvalidate);
2541: }
2542: my $checked = '';
2543: if ($option eq $curroption) {
2544: $checked = ' checked="checked"';
2545: } elsif ($option eq 'autolimit') {
2546: if ($curroption =~ /^autolimit/) {
2547: $checked = ' checked="checked"';
2548: }
2549: }
2550: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2551: '<input type="radio" name="crsreq_'.$item.
2552: '_default" value="'.$val.'"'.$checked.' />'.
2553: $titles{$option}.'</label>';
2554: if ($option eq 'autolimit') {
1.127 raeburn 2555: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2556: $item.'_limit_default" size="1" '.
2557: 'value="'.$currlimit.'" />';
2558: }
1.127 raeburn 2559: $defcell{$item} .= '</span> ';
1.104 raeburn 2560: if ($option eq 'autolimit') {
1.127 raeburn 2561: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2562: }
1.101 raeburn 2563: }
1.163 raeburn 2564: } elsif ($context eq 'requestauthor') {
2565: my $curroption;
2566: if (ref($settings) eq 'HASH') {
1.172 raeburn 2567: $curroption = $settings->{'default'};
1.163 raeburn 2568: }
2569: if (!$curroption) {
2570: $curroption = 'norequest';
2571: }
2572: foreach my $option (@options) {
2573: my $val = $option;
2574: if ($option eq 'norequest') {
2575: $val = 0;
2576: }
2577: my $checked = '';
2578: if ($option eq $curroption) {
2579: $checked = ' checked="checked"';
2580: }
2581: $datatable .= '<span class="LC_nobreak"><label>'.
2582: '<input type="radio" name="authorreq_default"'.
2583: ' value="'.$val.'"'.$checked.' />'.
2584: $titles{$option}.'</label></span> ';
2585: }
1.101 raeburn 2586: } else {
2587: my $checked = 'checked="checked" ';
2588: if (ref($settings) eq 'HASH') {
2589: if (ref($settings->{$item}) eq 'HASH') {
2590: if ($settings->{$item}->{'default'} == 0) {
2591: $checked = '';
2592: } elsif ($settings->{$item}->{'default'} == 1) {
2593: $checked = 'checked="checked" ';
2594: }
1.78 raeburn 2595: }
1.72 raeburn 2596: }
1.101 raeburn 2597: $datatable .= '<span class="LC_nobreak"><label>'.
2598: '<input type="checkbox" name="'.$context.'_'.$item.
2599: '" value="default" '.$checked.'/>'.$titles{$item}.
2600: '</label></span> ';
2601: }
2602: }
2603: if ($context eq 'requestcourses') {
2604: $datatable .= '</tr><tr>';
2605: foreach my $item (@usertools) {
1.106 raeburn 2606: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2607: }
1.101 raeburn 2608: $datatable .= '</tr></table>';
1.72 raeburn 2609: }
1.86 raeburn 2610: $datatable .= '</td>';
1.163 raeburn 2611: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2612: $datatable .= '<td class="LC_right_item">'.
2613: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2614: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2615: $defaultquota.'" size="5" /></span>'.(' ' x2).
2616: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2617: '<input type="text" name="authorquota" value="'.
2618: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2619: }
2620: $datatable .= '</tr>';
1.72 raeburn 2621: $typecount ++;
2622: $css_class = $typecount%2?' class="LC_odd_row"':'';
2623: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2624: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2625: if ($context eq 'requestcourses') {
1.109 raeburn 2626: $datatable .= &mt('(overrides affiliation, if set)').
2627: '</td>'.
2628: '<td class="LC_left_item">'.
2629: '<table><tr>';
1.101 raeburn 2630: } else {
1.109 raeburn 2631: $datatable .= &mt('(overrides affiliation, if checked)').
2632: '</td>'.
2633: '<td class="LC_left_item" colspan="2">'.
2634: '<br />';
1.101 raeburn 2635: }
2636: my %advcell;
1.72 raeburn 2637: foreach my $item (@usertools) {
1.101 raeburn 2638: if ($context eq 'requestcourses') {
2639: my ($curroption,$currlimit);
2640: if (ref($settings) eq 'HASH') {
2641: if (ref($settings->{$item}) eq 'HASH') {
2642: $curroption = $settings->{$item}->{'_LC_adv'};
2643: if ($curroption =~ /^autolimit=(\d*)$/) {
2644: $currlimit = $1;
2645: }
2646: }
2647: }
2648: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2649: my $checked = '';
2650: if ($curroption eq '') {
2651: $checked = ' checked="checked"';
2652: }
2653: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2654: '<input type="radio" name="crsreq_'.$item.
2655: '__LC_adv" value=""'.$checked.' />'.
2656: &mt('No override set').'</label></span> ';
1.101 raeburn 2657: foreach my $option (@options) {
2658: my $val = $option;
2659: if ($option eq 'norequest') {
2660: $val = 0;
2661: }
2662: if ($option eq 'validate') {
2663: my $canvalidate = 0;
2664: if (ref($validations{$item}) eq 'HASH') {
2665: if ($validations{$item}{'_LC_adv'}) {
2666: $canvalidate = 1;
2667: }
2668: }
2669: next if (!$canvalidate);
2670: }
2671: my $checked = '';
1.104 raeburn 2672: if ($val eq $curroption) {
1.101 raeburn 2673: $checked = ' checked="checked"';
2674: } elsif ($option eq 'autolimit') {
2675: if ($curroption =~ /^autolimit/) {
2676: $checked = ' checked="checked"';
2677: }
2678: }
2679: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2680: '<input type="radio" name="crsreq_'.$item.
2681: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2682: $titles{$option}.'</label>';
2683: if ($option eq 'autolimit') {
1.127 raeburn 2684: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2685: $item.'_limit__LC_adv" size="1" '.
2686: 'value="'.$currlimit.'" />';
2687: }
1.127 raeburn 2688: $advcell{$item} .= '</span> ';
1.104 raeburn 2689: if ($option eq 'autolimit') {
1.127 raeburn 2690: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2691: }
1.101 raeburn 2692: }
1.163 raeburn 2693: } elsif ($context eq 'requestauthor') {
2694: my $curroption;
2695: if (ref($settings) eq 'HASH') {
2696: $curroption = $settings->{'_LC_adv'};
2697: }
2698: my $checked = '';
2699: if ($curroption eq '') {
2700: $checked = ' checked="checked"';
2701: }
2702: $datatable .= '<span class="LC_nobreak"><label>'.
2703: '<input type="radio" name="authorreq__LC_adv"'.
2704: ' value=""'.$checked.' />'.
2705: &mt('No override set').'</label></span> ';
2706: foreach my $option (@options) {
2707: my $val = $option;
2708: if ($option eq 'norequest') {
2709: $val = 0;
2710: }
2711: my $checked = '';
2712: if ($val eq $curroption) {
2713: $checked = ' checked="checked"';
2714: }
2715: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2716: '<input type="radio" name="authorreq__LC_adv"'.
2717: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2718: $titles{$option}.'</label></span> ';
2719: }
1.101 raeburn 2720: } else {
2721: my $checked = 'checked="checked" ';
2722: if (ref($settings) eq 'HASH') {
2723: if (ref($settings->{$item}) eq 'HASH') {
2724: if ($settings->{$item}->{'_LC_adv'} == 0) {
2725: $checked = '';
2726: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2727: $checked = 'checked="checked" ';
2728: }
1.79 raeburn 2729: }
1.72 raeburn 2730: }
1.101 raeburn 2731: $datatable .= '<span class="LC_nobreak"><label>'.
2732: '<input type="checkbox" name="'.$context.'_'.$item.
2733: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2734: '</label></span> ';
2735: }
2736: }
2737: if ($context eq 'requestcourses') {
2738: $datatable .= '</tr><tr>';
2739: foreach my $item (@usertools) {
1.106 raeburn 2740: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2741: }
1.101 raeburn 2742: $datatable .= '</tr></table>';
1.72 raeburn 2743: }
1.98 raeburn 2744: $datatable .= '</td></tr>';
1.30 raeburn 2745: $$rowtotal += $typecount;
1.3 raeburn 2746: return $datatable;
2747: }
2748:
1.163 raeburn 2749: sub print_requestmail {
1.305 raeburn 2750: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2751: my ($now,$datatable,%currapp);
1.102 raeburn 2752: $now = time;
2753: if (ref($settings) eq 'HASH') {
2754: if (ref($settings->{'notify'}) eq 'HASH') {
2755: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2756: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2757: }
2758: }
2759: }
1.191 raeburn 2760: my $numinrow = 2;
1.224 raeburn 2761: my $css_class;
1.305 raeburn 2762: if ($$rowtotal%2) {
2763: $css_class = 'LC_odd_row';
2764: }
2765: if ($customcss) {
2766: $css_class .= " $customcss";
2767: }
2768: $css_class =~ s/^\s+//;
2769: if ($css_class) {
2770: $css_class = ' class="'.$css_class.'"';
2771: }
2772: if ($rowstyle) {
2773: $css_class .= ' style="'.$rowstyle.'"';
2774: }
1.163 raeburn 2775: my $text;
2776: if ($action eq 'requestcourses') {
2777: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2778: } elsif ($action eq 'requestauthor') {
2779: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2780: } else {
1.224 raeburn 2781: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2782: }
1.224 raeburn 2783: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2784: ' <td>'.$text.'</td>'.
1.102 raeburn 2785: ' <td class="LC_left_item">';
1.191 raeburn 2786: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2787: $action.'notifyapproval',%currapp);
1.191 raeburn 2788: if ($numdc > 0) {
2789: $datatable .= $table;
1.102 raeburn 2790: } else {
2791: $datatable .= &mt('There are no active Domain Coordinators');
2792: }
2793: $datatable .='</td></tr>';
2794: return $datatable;
2795: }
2796:
1.216 raeburn 2797: sub print_studentcode {
2798: my ($settings,$rowtotal) = @_;
2799: my $rownum = 0;
1.218 raeburn 2800: my ($output,%current);
1.325 raeburn 2801: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2802: if (ref($settings) eq 'HASH') {
2803: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2804: foreach my $type (@crstypes) {
2805: $current{$type} = $settings->{'uniquecode'}{$type};
2806: }
1.218 raeburn 2807: }
2808: }
2809: $output .= '<tr>'.
2810: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2811: '<td class="LC_left_item">';
2812: foreach my $type (@crstypes) {
2813: my $check = ' ';
2814: if ($current{$type}) {
2815: $check = ' checked="checked" ';
2816: }
2817: $output .= '<span class="LC_nobreak"><label>'.
2818: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2819: &mt($type).'</label></span>'.(' 'x2).' ';
2820: }
2821: $output .= '</td></tr>';
2822: $$rowtotal ++;
2823: return $output;
1.216 raeburn 2824: }
2825:
2826: sub print_textbookcourses {
1.242 raeburn 2827: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2828: my $rownum = 0;
2829: my $css_class;
2830: my $itemcount = 1;
2831: my $maxnum = 0;
2832: my $bookshash;
2833: if (ref($settings) eq 'HASH') {
1.242 raeburn 2834: $bookshash = $settings->{$type};
1.216 raeburn 2835: }
2836: my %ordered;
2837: if (ref($bookshash) eq 'HASH') {
2838: foreach my $item (keys(%{$bookshash})) {
2839: if (ref($bookshash->{$item}) eq 'HASH') {
2840: my $num = $bookshash->{$item}{'order'};
2841: $ordered{$num} = $item;
2842: }
2843: }
2844: }
2845: my $confname = $dom.'-domainconfig';
2846: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2847: my $maxnum = scalar(keys(%ordered));
2848: my $datatable;
1.216 raeburn 2849: if (keys(%ordered)) {
2850: my @items = sort { $a <=> $b } keys(%ordered);
2851: for (my $i=0; $i<@items; $i++) {
2852: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2853: my $key = $ordered{$items[$i]};
2854: my %coursehash=&Apache::lonnet::coursedescription($key);
2855: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2856: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2857: if (ref($bookshash->{$key}) eq 'HASH') {
2858: $subject = $bookshash->{$key}->{'subject'};
2859: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2860: if ($type eq 'textbooks') {
1.243 raeburn 2861: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2862: $author = $bookshash->{$key}->{'author'};
2863: $image = $bookshash->{$key}->{'image'};
2864: if ($image ne '') {
2865: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2866: my $imagethumb = "$path/tn-".$imagefile;
2867: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2868: }
1.216 raeburn 2869: }
2870: }
1.242 raeburn 2871: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2872: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2873: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2874: for (my $k=0; $k<=$maxnum; $k++) {
2875: my $vpos = $k+1;
2876: my $selstr;
2877: if ($k == $i) {
2878: $selstr = ' selected="selected" ';
2879: }
2880: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2881: }
2882: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2883: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2884: &mt('Delete?').'</label></span></td>'.
2885: '<td colspan="2">'.
1.242 raeburn 2886: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2887: (' 'x2).
1.242 raeburn 2888: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2889: if ($type eq 'textbooks') {
2890: $datatable .= (' 'x2).
1.243 raeburn 2891: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2892: (' 'x2).
1.242 raeburn 2893: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2894: (' 'x2).
2895: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2896: if ($image) {
1.267 raeburn 2897: $datatable .= $imgsrc.
1.242 raeburn 2898: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2899: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2900: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2901: }
2902: if ($switchserver) {
2903: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2904: } else {
2905: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2906: }
1.216 raeburn 2907: }
1.242 raeburn 2908: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2909: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2910: $coursetitle.'</span></td></tr>'."\n";
2911: $itemcount ++;
2912: }
2913: }
2914: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2915: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2916: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2917: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2918: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2919: for (my $k=0; $k<$maxnum+1; $k++) {
2920: my $vpos = $k+1;
2921: my $selstr;
2922: if ($k == $maxnum) {
2923: $selstr = ' selected="selected" ';
2924: }
2925: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2926: }
2927: $datatable .= '</select> '."\n".
1.334 raeburn 2928: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2929: '<td colspan="2">'.
1.242 raeburn 2930: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2931: (' 'x2).
1.242 raeburn 2932: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2933: (' 'x2);
2934: if ($type eq 'textbooks') {
1.243 raeburn 2935: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2936: (' 'x2).
2937: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2938: (' 'x2).
2939: '<span class="LC_nobreak">'.&mt('Image:').' ';
2940: if ($switchserver) {
2941: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2942: } else {
2943: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2944: }
1.334 raeburn 2945: $datatable .= '</span>'."\n";
1.216 raeburn 2946: }
1.334 raeburn 2947: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2948: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2949: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2950: &Apache::loncommon::selectcourse_link
1.334 raeburn 2951: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2952: '</span></td>'."\n".
2953: '</tr>'."\n";
2954: $itemcount ++;
2955: return $datatable;
2956: }
2957:
1.217 raeburn 2958: sub textbookcourses_javascript {
1.242 raeburn 2959: my ($settings) = @_;
2960: return unless(ref($settings) eq 'HASH');
2961: my (%ordered,%total,%jstext);
2962: foreach my $type ('textbooks','templates') {
2963: $total{$type} = 0;
2964: if (ref($settings->{$type}) eq 'HASH') {
2965: foreach my $item (keys(%{$settings->{$type}})) {
2966: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2967: my $num = $settings->{$type}->{$item}{'order'};
2968: $ordered{$type}{$num} = $item;
2969: }
2970: }
2971: $total{$type} = scalar(keys(%{$settings->{$type}}));
2972: }
2973: my @jsarray = ();
2974: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2975: push(@jsarray,$ordered{$type}{$item});
2976: }
2977: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2978: }
2979: return <<"ENDSCRIPT";
2980: <script type="text/javascript">
2981: // <![CDATA[
1.242 raeburn 2982: function reorderBooks(form,item,caller) {
1.217 raeburn 2983: var changedVal;
1.242 raeburn 2984: $jstext{'textbooks'};
2985: $jstext{'templates'};
2986: var newpos;
2987: var maxh;
2988: if (caller == 'textbooks') {
2989: newpos = 'textbooks_addbook_pos';
2990: maxh = 1 + $total{'textbooks'};
2991: } else {
2992: newpos = 'templates_addbook_pos';
2993: maxh = 1 + $total{'templates'};
2994: }
1.217 raeburn 2995: var current = new Array;
2996: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2997: if (item == newpos) {
2998: changedVal = newitemVal;
2999: } else {
3000: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3001: current[newitemVal] = newpos;
3002: }
1.242 raeburn 3003: if (caller == 'textbooks') {
3004: for (var i=0; i<textbooks.length; i++) {
3005: var elementName = 'textbooks_'+textbooks[i];
3006: if (elementName != item) {
3007: if (form.elements[elementName]) {
3008: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3009: current[currVal] = elementName;
3010: }
3011: }
3012: }
3013: }
3014: if (caller == 'templates') {
3015: for (var i=0; i<templates.length; i++) {
3016: var elementName = 'templates_'+templates[i];
3017: if (elementName != item) {
3018: if (form.elements[elementName]) {
3019: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3020: current[currVal] = elementName;
3021: }
1.217 raeburn 3022: }
3023: }
3024: }
3025: var oldVal;
3026: for (var j=0; j<maxh; j++) {
3027: if (current[j] == undefined) {
3028: oldVal = j;
3029: }
3030: }
3031: if (oldVal < changedVal) {
3032: for (var k=oldVal+1; k<=changedVal ; k++) {
3033: var elementName = current[k];
3034: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3035: }
3036: } else {
3037: for (var k=changedVal; k<oldVal; k++) {
3038: var elementName = current[k];
3039: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3040: }
3041: }
3042: return;
3043: }
3044:
3045: // ]]>
3046: </script>
3047:
3048: ENDSCRIPT
3049: }
3050:
1.267 raeburn 3051: sub ltitools_javascript {
3052: my ($settings) = @_;
1.319 raeburn 3053: my $togglejs = <itools_toggle_js();
3054: unless (ref($settings) eq 'HASH') {
3055: return $togglejs;
3056: }
1.267 raeburn 3057: my (%ordered,$total,%jstext);
3058: $total = 0;
3059: foreach my $item (keys(%{$settings})) {
3060: if (ref($settings->{$item}) eq 'HASH') {
3061: my $num = $settings->{$item}{'order'};
3062: $ordered{$num} = $item;
3063: }
3064: }
3065: $total = scalar(keys(%{$settings}));
3066: my @jsarray = ();
3067: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3068: push(@jsarray,$ordered{$item});
3069: }
3070: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3071: return <<"ENDSCRIPT";
3072: <script type="text/javascript">
3073: // <![CDATA[
1.319 raeburn 3074: function reorderLTITools(form,item) {
1.267 raeburn 3075: var changedVal;
3076: $jstext
3077: var newpos = 'ltitools_add_pos';
3078: var maxh = 1 + $total;
3079: var current = new Array;
3080: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3081: if (item == newpos) {
3082: changedVal = newitemVal;
3083: } else {
3084: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3085: current[newitemVal] = newpos;
3086: }
3087: for (var i=0; i<ltitools.length; i++) {
3088: var elementName = 'ltitools_'+ltitools[i];
3089: if (elementName != item) {
3090: if (form.elements[elementName]) {
3091: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3092: current[currVal] = elementName;
3093: }
3094: }
3095: }
3096: var oldVal;
3097: for (var j=0; j<maxh; j++) {
3098: if (current[j] == undefined) {
3099: oldVal = j;
3100: }
3101: }
3102: if (oldVal < changedVal) {
3103: for (var k=oldVal+1; k<=changedVal ; k++) {
3104: var elementName = current[k];
3105: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3106: }
3107: } else {
3108: for (var k=changedVal; k<oldVal; k++) {
3109: var elementName = current[k];
3110: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3111: }
3112: }
3113: return;
3114: }
3115:
3116: // ]]>
3117: </script>
3118:
1.319 raeburn 3119: $togglejs
3120:
3121: ENDSCRIPT
3122: }
3123:
3124: sub ltitools_toggle_js {
3125: return <<"ENDSCRIPT";
3126: <script type="text/javascript">
3127: // <![CDATA[
3128:
3129: function toggleLTITools(form,setting,item) {
3130: var radioname = '';
3131: var divid = '';
3132: if ((setting == 'passback') || (setting == 'roster')) {
3133: radioname = 'ltitools_'+setting+'_'+item;
3134: divid = 'ltitools_'+setting+'time_'+item;
3135: var num = form.elements[radioname].length;
3136: if (num) {
3137: var setvis = '';
3138: for (var i=0; i<num; i++) {
3139: if (form.elements[radioname][i].checked) {
3140: if (form.elements[radioname][i].value == '1') {
3141: if (document.getElementById(divid)) {
3142: document.getElementById(divid).style.display = 'inline-block';
3143: }
3144: setvis = 1;
3145: }
3146: break;
3147: }
3148: }
3149: }
3150: if (!setvis) {
3151: if (document.getElementById(divid)) {
3152: document.getElementById(divid).style.display = 'none';
3153: }
3154: }
3155: }
1.324 raeburn 3156: if (setting == 'user') {
3157: divid = 'ltitools_'+setting+'_div_'+item;
3158: var checkid = 'ltitools_'+setting+'_field_'+item;
3159: if (document.getElementById(divid)) {
3160: if (document.getElementById(checkid)) {
3161: if (document.getElementById(checkid).checked) {
3162: document.getElementById(divid).style.display = 'inline-block';
3163: } else {
3164: document.getElementById(divid).style.display = 'none';
3165: }
3166: }
3167: }
3168: }
1.319 raeburn 3169: return;
3170: }
3171: // ]]>
3172: </script>
3173:
1.267 raeburn 3174: ENDSCRIPT
3175: }
3176:
1.381 raeburn 3177: sub wafproxy_javascript {
3178: my ($dom) = @_;
3179: return <<"ENDSCRIPT";
3180: <script type="text/javascript">
3181: // <![CDATA[
3182: function updateWAF() {
3183: if (document.getElementById('wafproxy_remoteip')) {
3184: var wafremote = 0;
3185: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3186: wafremote = 1;
3187: }
3188: var fields = new Array('header','trust');
3189: for (var i=0; i<fields.length; i++) {
3190: if (document.getElementById('wafproxy_'+fields[i])) {
3191: if (wafremote == 1) {
3192: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3193: }
3194: else {
3195: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3196: }
3197: }
3198: }
3199: if (document.getElementById('wafproxyranges_$dom')) {
3200: if (wafremote == 1) {
3201: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3202: } else {
3203: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3204: if (document.display.wafproxy_vpnaccess[i].checked) {
3205: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3206: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3207: }
3208: }
3209: }
3210: }
3211: }
3212: }
3213: return;
3214: }
3215:
3216: function checkWAF() {
3217: if (document.getElementById('wafproxy_remoteip')) {
3218: var wafvpn = 0;
3219: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3220: if (document.display.wafproxy_vpnaccess[i].checked) {
3221: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3222: wafvpn = 1;
3223: }
3224: break;
3225: }
3226: }
3227: var vpn = new Array('vpnint','vpnext');
3228: for (var i=0; i<vpn.length; i++) {
3229: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3230: if (wafvpn == 1) {
3231: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3232: }
3233: else {
3234: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3235: }
3236: }
3237: }
3238: if (document.getElementById('wafproxyranges_$dom')) {
3239: if (wafvpn == 1) {
3240: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3241: }
3242: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3243: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3244: }
3245: }
3246: }
3247: return;
3248: }
3249:
3250: function toggleWAF() {
3251: if (document.getElementById('wafproxy_table')) {
3252: var wafproxy = 0;
3253: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3254: if (document.display.wafproxy_${dom}[i].checked) {
3255: if (document.display.wafproxy_${dom}[i].value == 1) {
3256: wafproxy = 1;
3257: break;
3258: }
3259: }
3260: }
3261: if (wafproxy == 1) {
3262: document.getElementById('wafproxy_table').style.display='inline';
3263: }
3264: else {
3265: document.getElementById('wafproxy_table').style.display='none';
3266: }
3267: if (document.getElementById('wafproxyrow_${dom}')) {
3268: if (wafproxy == 1) {
3269: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3270: }
3271: else {
3272: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3273: }
3274: }
3275: if (document.getElementById('nowafproxyrow_$dom')) {
3276: if (wafproxy == 1) {
3277: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3278: }
3279: else {
3280: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3281: }
3282: }
3283: }
3284: return;
3285: }
3286: // ]]>
3287: </script>
3288:
3289: ENDSCRIPT
3290: }
3291:
1.372 raeburn 3292: sub proctoring_javascript {
3293: my ($settings) = @_;
3294: my (%ordered,$total,%jstext);
3295: $total = 0;
3296: if (ref($settings) eq 'HASH') {
3297: foreach my $item (keys(%{$settings})) {
3298: if (ref($settings->{$item}) eq 'HASH') {
3299: my $num = $settings->{$item}{'order'};
3300: $ordered{$num} = $item;
3301: }
3302: }
3303: $total = scalar(keys(%{$settings}));
3304: } else {
3305: %ordered = (
3306: 0 => 'proctorio',
3307: 1 => 'examity',
3308: );
3309: $total = 2;
3310: }
3311: my @jsarray = ();
3312: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3313: push(@jsarray,$ordered{$item});
3314: }
3315: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3316: return <<"ENDSCRIPT";
3317: <script type="text/javascript">
3318: // <![CDATA[
3319: function reorderProctoring(form,item) {
3320: var changedVal;
3321: $jstext
3322: var maxh = $total;
3323: var current = new Array;
3324: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3325: for (var i=0; i<proctors.length; i++) {
3326: var elementName = 'proctoring_pos_'+proctors[i];
3327: if (elementName != item) {
3328: if (form.elements[elementName]) {
3329: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3330: current[currVal] = elementName;
3331: }
3332: }
3333: }
3334: var oldVal;
3335: for (var j=0; j<maxh; j++) {
3336: if (current[j] == undefined) {
3337: oldVal = j;
3338: }
3339: }
3340: if (oldVal < changedVal) {
3341: for (var k=oldVal+1; k<=changedVal ; k++) {
3342: var elementName = current[k];
3343: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3344: }
3345: } else {
3346: for (var k=changedVal; k<oldVal; k++) {
3347: var elementName = current[k];
3348: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3349: }
3350: }
3351: return;
3352: }
3353:
3354: function toggleProctoring(form,item) {
3355: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3356: if (fieldsets.length) {
3357: var radioname = 'proctoring_available_'+item;
3358: var num = form.elements[radioname].length;
3359: if (num) {
3360: var setvis = '';
3361: for (var i=0; i<num; i++) {
3362: if (form.elements[radioname][i].checked) {
3363: if (form.elements[radioname][i].value == '1') {
3364: setvis = 1;
3365: break;
3366: }
3367: }
3368: }
3369: for (var j=0; j<fieldsets.length; j++) {
3370: if (setvis) {
3371: fieldsets[j].style.display = 'block';
3372: } else {
3373: fieldsets[j].style.display = 'none';
3374: }
3375: }
3376: }
3377: }
3378: return;
3379: }
3380:
3381: // ]]>
3382: </script>
3383:
3384: ENDSCRIPT
3385: }
3386:
3387:
1.320 raeburn 3388: sub lti_javascript {
3389: my ($settings) = @_;
3390: my $togglejs = <i_toggle_js();
3391: unless (ref($settings) eq 'HASH') {
3392: return $togglejs;
3393: }
3394: my (%ordered,$total,%jstext);
1.390 raeburn 3395: $total = scalar(keys(%{$settings}));
1.320 raeburn 3396: foreach my $item (keys(%{$settings})) {
3397: if (ref($settings->{$item}) eq 'HASH') {
3398: my $num = $settings->{$item}{'order'};
1.390 raeburn 3399: if ($num eq '') {
3400: $num = $total - 1;
3401: }
1.320 raeburn 3402: $ordered{$num} = $item;
3403: }
3404: }
3405: my @jsarray = ();
3406: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3407: push(@jsarray,$ordered{$item});
3408: }
3409: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3410: return <<"ENDSCRIPT";
3411: <script type="text/javascript">
3412: // <![CDATA[
3413: function reorderLTI(form,item) {
3414: var changedVal;
3415: $jstext
3416: var newpos = 'lti_pos_add';
3417: var maxh = 1 + $total;
3418: var current = new Array;
3419: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3420: if (item == newpos) {
3421: changedVal = newitemVal;
3422: } else {
3423: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3424: current[newitemVal] = newpos;
3425: }
3426: for (var i=0; i<lti.length; i++) {
3427: var elementName = 'lti_pos_'+lti[i];
3428: if (elementName != item) {
3429: if (form.elements[elementName]) {
3430: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3431: current[currVal] = elementName;
3432: }
3433: }
3434: }
3435: var oldVal;
3436: for (var j=0; j<maxh; j++) {
3437: if (current[j] == undefined) {
3438: oldVal = j;
3439: }
3440: }
3441: if (oldVal < changedVal) {
3442: for (var k=oldVal+1; k<=changedVal ; k++) {
3443: var elementName = current[k];
3444: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3445: }
3446: } else {
3447: for (var k=changedVal; k<oldVal; k++) {
3448: var elementName = current[k];
3449: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3450: }
3451: }
3452: return;
3453: }
3454: // ]]>
3455: </script>
3456:
3457: $togglejs
3458:
3459: ENDSCRIPT
3460: }
3461:
3462: sub lti_toggle_js {
1.325 raeburn 3463: my %lcauthparmtext = &Apache::lonlocal::texthash (
3464: localauth => 'Local auth argument',
3465: krb => 'Kerberos domain',
3466: );
1.391 raeburn 3467: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3468: &js_escape(\$crsincalert);
1.320 raeburn 3469: return <<"ENDSCRIPT";
3470: <script type="text/javascript">
3471: // <![CDATA[
3472:
3473: function toggleLTI(form,setting,item) {
1.391 raeburn 3474: if ((setting == 'requser') || (setting == 'crsinc')) {
3475: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3476: var setvis = '';
3477: var radioname = 'lti_requser_'+item;
3478: var num = form.elements[radioname].length;
3479: if (num) {
3480: for (var i=0; i<num; i++) {
3481: if (form.elements[radioname][i].checked) {
3482: if (form.elements[radioname][i].value == '1') {
3483: setvis = 1;
3484: break;
3485: }
3486: }
3487: }
3488: }
3489: if (usrfieldsets.length) {
3490: for (var j=0; j<usrfieldsets.length; j++) {
3491: if (setvis) {
3492: usrfieldsets[j].style.display = 'block';
3493: } else {
3494: usrfieldsets[j].style.display = 'none';
3495: }
3496: }
3497: }
3498: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3499: if (crsfieldsets.length) {
3500: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3501: var num = form.elements[radioname].length;
3502: if (num) {
1.391 raeburn 3503: var crsvis = '';
1.345 raeburn 3504: for (var i=0; i<num; i++) {
3505: if (form.elements[radioname][i].checked) {
3506: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3507: if (setvis == '') {
3508: if (setting == 'crsinc'){
3509: alert("$crsincalert");
3510: form.elements[radioname][0].checked = true;
3511: }
3512: } else {
3513: crsvis = 1;
3514: }
3515: break;
1.345 raeburn 3516: }
3517: }
3518: }
1.391 raeburn 3519: setvis = crsvis;
3520: }
3521: for (var j=0; j<crsfieldsets.length; j++) {
3522: if (setvis) {
3523: crsfieldsets[j].style.display = 'block';
3524: } else {
3525: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3526: }
3527: }
3528: }
1.363 raeburn 3529: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3530: var radioname = '';
3531: var divid = '';
3532: if (setting == 'user') {
3533: radioname = 'lti_mapuser_'+item;
3534: divid = 'lti_userfield_'+item;
1.343 raeburn 3535: } else if (setting == 'crs') {
1.320 raeburn 3536: radioname = 'lti_mapcrs_'+item;
3537: divid = 'lti_crsfield_'+item;
1.363 raeburn 3538: } else if (setting == 'callback') {
3539: radioname = 'lti_callback_'+item;
3540: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3541: } else {
1.351 raeburn 3542: radioname = 'lti_passback_'+item;
1.337 raeburn 3543: divid = 'lti_passback_'+item;
1.320 raeburn 3544: }
3545: var num = form.elements[radioname].length;
3546: if (num) {
3547: var setvis = '';
3548: for (var i=0; i<num; i++) {
3549: if (form.elements[radioname][i].checked) {
1.363 raeburn 3550: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3551: if (form.elements[radioname][i].value == '1') {
3552: if (document.getElementById(divid)) {
3553: document.getElementById(divid).style.display = 'inline-block';
3554: }
3555: setvis = 1;
3556: break;
3557: }
3558: } else {
3559: if (form.elements[radioname][i].value == 'other') {
3560: if (document.getElementById(divid)) {
3561: document.getElementById(divid).style.display = 'inline-block';
3562: }
3563: setvis = 1;
3564: break;
1.320 raeburn 3565: }
3566: }
3567: }
3568: }
3569: if (!setvis) {
3570: if (document.getElementById(divid)) {
3571: document.getElementById(divid).style.display = 'none';
3572: }
3573: }
3574: }
3575: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3576: var numsec = form.elements['lti_crssec_'+item].length;
3577: if (numsec) {
3578: var setvis = '';
3579: for (var i=0; i<numsec; i++) {
3580: if (form.elements['lti_crssec_'+item][i].checked) {
3581: if (form.elements['lti_crssec_'+item][i].value == '1') {
3582: if (document.getElementById('lti_crssecfield_'+item)) {
3583: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3584: setvis = 1;
3585: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3586: if (numsrcsec) {
3587: var setsrcvis = '';
3588: for (var j=0; j<numsrcsec; j++) {
3589: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3590: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3591: if (document.getElementById('lti_secsrcfield_'+item)) {
3592: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3593: setsrcvis = 1;
3594: }
3595: }
3596: }
3597: }
3598: if (!setsrcvis) {
3599: if (document.getElementById('lti_secsrcfield_'+item)) {
3600: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3601: }
3602: }
3603: }
3604: }
3605: }
3606: }
3607: }
3608: if (!setvis) {
3609: if (document.getElementById('lti_crssecfield_'+item)) {
3610: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3611: }
3612: if (document.getElementById('lti_secsrcfield_'+item)) {
3613: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3614: }
3615: }
3616: }
1.325 raeburn 3617: } else if (setting == 'lcauth') {
3618: var numauth = form.elements['lti_lcauth_'+item].length;
3619: if (numauth) {
3620: for (var i=0; i<numauth; i++) {
3621: if (form.elements['lti_lcauth_'+item][i].checked) {
3622: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3623: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3624: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3625: } else {
3626: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3627: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3628: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3629: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3630: } else {
3631: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3632: }
3633: }
3634: }
3635: }
3636: }
3637: }
3638: }
1.326 raeburn 3639: } else if (setting == 'lcmenu') {
3640: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3641: var divid = 'lti_menufield_'+item;
3642: var setvis = '';
3643: for (var i=0; i<menus.length; i++) {
3644: var radioname = menus[i];
3645: var num = form.elements[radioname].length;
3646: if (num) {
3647: for (var j=0; j<num; j++) {
3648: if (form.elements[radioname][j].checked) {
3649: if (form.elements[radioname][j].value == '1') {
3650: if (document.getElementById(divid)) {
3651: document.getElementById(divid).style.display = 'inline-block';
3652: }
3653: setvis = 1;
3654: break;
3655: }
3656: }
3657: }
3658: }
3659: if (setvis == 1) {
3660: break;
3661: }
3662: }
3663: if (!setvis) {
3664: if (document.getElementById(divid)) {
3665: document.getElementById(divid).style.display = 'none';
3666: }
3667: }
1.320 raeburn 3668: }
3669: return;
3670: }
3671: // ]]>
3672: </script>
3673:
3674: ENDSCRIPT
3675: }
3676:
1.385 raeburn 3677: sub autoupdate_javascript {
3678: return <<"ENDSCRIPT";
3679: <script type="text/javascript">
3680: // <![CDATA[
3681: function toggleLastActiveDays(form) {
3682: var radioname = 'lastactive';
3683: var divid = 'lastactive_div';
3684: var num = form.elements[radioname].length;
3685: if (num) {
3686: var setvis = '';
3687: for (var i=0; i<num; i++) {
3688: if (form.elements[radioname][i].checked) {
3689: if (form.elements[radioname][i].value == '1') {
3690: if (document.getElementById(divid)) {
3691: document.getElementById(divid).style.display = 'inline-block';
3692: }
3693: setvis = 1;
3694: }
3695: break;
3696: }
3697: }
3698: if (!setvis) {
3699: if (document.getElementById(divid)) {
3700: document.getElementById(divid).style.display = 'none';
3701: }
3702: }
3703: }
3704: return;
3705: }
3706: // ]]>
3707: </script>
3708:
3709: ENDSCRIPT
3710: }
3711:
1.399 raeburn 3712: sub autoenroll_javascript {
3713: return <<"ENDSCRIPT";
3714: <script type="text/javascript">
3715: // <![CDATA[
3716: function toggleFailsafe(form) {
3717: var radioname = 'autoenroll_failsafe';
3718: var divid = 'autoenroll_failsafe_div';
3719: var num = form.elements[radioname].length;
3720: if (num) {
3721: var setvis = '';
3722: for (var i=0; i<num; i++) {
3723: if (form.elements[radioname][i].checked) {
3724: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3725: if (document.getElementById(divid)) {
3726: document.getElementById(divid).style.display = 'inline-block';
3727: }
3728: setvis = 1;
3729: }
3730: break;
3731: }
3732: }
3733: if (!setvis) {
3734: if (document.getElementById(divid)) {
3735: document.getElementById(divid).style.display = 'none';
3736: }
3737: }
3738: }
3739: return;
3740: }
3741: // ]]>
3742: </script>
3743:
3744: ENDSCRIPT
3745: }
3746:
1.386 raeburn 3747: sub saml_javascript {
3748: return <<"ENDSCRIPT";
3749: <script type="text/javascript">
3750: // <![CDATA[
3751: function toggleSamlOptions(form,hostid) {
3752: var radioname = 'saml_'+hostid;
3753: var tablecellon = 'samloptionson_'+hostid;
3754: var tablecelloff = 'samloptionsoff_'+hostid;
3755: var num = form.elements[radioname].length;
3756: if (num) {
3757: var setvis = '';
3758: for (var i=0; i<num; i++) {
3759: if (form.elements[radioname][i].checked) {
3760: if (form.elements[radioname][i].value == '1') {
3761: if (document.getElementById(tablecellon)) {
3762: document.getElementById(tablecellon).style.display='';
3763: }
3764: if (document.getElementById(tablecelloff)) {
3765: document.getElementById(tablecelloff).style.display='none';
3766: }
3767: setvis = 1;
3768: }
3769: break;
3770: }
3771: }
3772: if (!setvis) {
3773: if (document.getElementById(tablecellon)) {
3774: document.getElementById(tablecellon).style.display='none';
3775: }
3776: if (document.getElementById(tablecelloff)) {
3777: document.getElementById(tablecelloff).style.display='';
3778: }
3779: }
3780: }
3781: return;
3782: }
3783: // ]]>
3784: </script>
3785:
3786: ENDSCRIPT
3787: }
3788:
1.394 raeburn 3789: sub ipaccess_javascript {
3790: my ($settings) = @_;
3791: my (%ordered,$total,%jstext);
3792: $total = 0;
3793: if (ref($settings) eq 'HASH') {
3794: foreach my $item (keys(%{$settings})) {
3795: if (ref($settings->{$item}) eq 'HASH') {
3796: my $num = $settings->{$item}{'order'};
3797: $ordered{$num} = $item;
3798: }
3799: }
3800: $total = scalar(keys(%{$settings}));
3801: }
3802: my @jsarray = ();
3803: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3804: push(@jsarray,$ordered{$item});
3805: }
3806: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3807: return <<"ENDSCRIPT";
3808: <script type="text/javascript">
3809: // <![CDATA[
3810: function reorderIPaccess(form,item) {
3811: var changedVal;
3812: $jstext
3813: var newpos = 'ipaccess_pos_add';
3814: var maxh = 1 + $total;
3815: var current = new Array;
3816: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3817: if (item == newpos) {
3818: changedVal = newitemVal;
3819: } else {
3820: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3821: current[newitemVal] = newpos;
3822: }
3823: for (var i=0; i<ipaccess.length; i++) {
3824: var elementName = 'ipaccess_pos_'+ipaccess[i];
3825: if (elementName != item) {
3826: if (form.elements[elementName]) {
3827: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3828: current[currVal] = elementName;
3829: }
3830: }
3831: }
3832: var oldVal;
3833: for (var j=0; j<maxh; j++) {
3834: if (current[j] == undefined) {
3835: oldVal = j;
3836: }
3837: }
3838: if (oldVal < changedVal) {
3839: for (var k=oldVal+1; k<=changedVal ; k++) {
3840: var elementName = current[k];
3841: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3842: }
3843: } else {
3844: for (var k=changedVal; k<oldVal; k++) {
3845: var elementName = current[k];
3846: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3847: }
3848: }
3849: return;
3850: }
3851: // ]]>
3852: </script>
3853:
3854: ENDSCRIPT
3855: }
3856:
1.3 raeburn 3857: sub print_autoenroll {
1.30 raeburn 3858: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3859: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3860: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3861: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3862: $failsafesty = 'none';
3863: %failsafechecked = (
3864: off => ' checked="checked"',
3865: );
1.3 raeburn 3866: if (ref($settings) eq 'HASH') {
3867: if (exists($settings->{'run'})) {
3868: if ($settings->{'run'} eq '0') {
3869: $runoff = ' checked="checked" ';
3870: $runon = ' ';
3871: } else {
3872: $runon = ' checked="checked" ';
3873: $runoff = ' ';
3874: }
3875: } else {
3876: if ($autorun) {
3877: $runon = ' checked="checked" ';
3878: $runoff = ' ';
3879: } else {
3880: $runoff = ' checked="checked" ';
3881: $runon = ' ';
3882: }
3883: }
1.129 raeburn 3884: if (exists($settings->{'co-owners'})) {
3885: if ($settings->{'co-owners'} eq '0') {
3886: $coownersoff = ' checked="checked" ';
3887: $coownerson = ' ';
3888: } else {
3889: $coownerson = ' checked="checked" ';
3890: $coownersoff = ' ';
3891: }
3892: } else {
3893: $coownersoff = ' checked="checked" ';
3894: $coownerson = ' ';
3895: }
1.3 raeburn 3896: if (exists($settings->{'sender_domain'})) {
3897: $defdom = $settings->{'sender_domain'};
3898: }
1.399 raeburn 3899: if (exists($settings->{'failsafe'})) {
3900: $failsafe = $settings->{'failsafe'};
3901: if ($failsafe eq 'zero') {
1.400 raeburn 3902: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 3903: $failsafechecked{'off'} = '';
3904: $failsafesty = 'inline-block';
3905: } elsif ($failsafe eq 'any') {
3906: $failsafechecked{'any'} = ' checked="checked"';
3907: $failsafechecked{'off'} = '';
3908: }
3909: $autofailsafe = $settings->{'autofailsafe'};
3910: } elsif (exists($settings->{'autofailsafe'})) {
3911: $autofailsafe = $settings->{'autofailsafe'};
3912: if ($autofailsafe ne '') {
3913: $failsafechecked{'zero'} = ' checked="checked"';
3914: $failsafe = 'zero';
1.400 raeburn 3915: $failsafechecked{'off'} = '';
1.399 raeburn 3916: }
1.274 raeburn 3917: }
1.14 raeburn 3918: } else {
3919: if ($autorun) {
3920: $runon = ' checked="checked" ';
3921: $runoff = ' ';
3922: } else {
3923: $runoff = ' checked="checked" ';
3924: $runon = ' ';
3925: }
1.3 raeburn 3926: }
3927: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3928: my $notif_sender;
3929: if (ref($settings) eq 'HASH') {
3930: $notif_sender = $settings->{'sender_uname'};
3931: }
1.3 raeburn 3932: my $datatable='<tr class="LC_odd_row">'.
3933: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3934: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3935: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3936: $runon.' value="1" />'.&mt('Yes').'</label> '.
3937: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3938: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3939: '</tr><tr>'.
3940: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3941: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3942: &mt('username').': '.
3943: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3944: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3945: ': '.$domform.'</span></td></tr>'.
3946: '<tr class="LC_odd_row">'.
3947: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3948: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3949: '<input type="radio" name="autoassign_coowners"'.
3950: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3951: '<label><input type="radio" name="autoassign_coowners"'.
3952: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3953: '</tr><tr>'.
3954: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 3955: '<td class="LC_left_item"><span class="LC_nobreak">'.
3956: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3957: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3958: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
1.399 raeburn 3959: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3960: '<span class="LC_nobreak">'.
3961: &mt('Threshold for number of students in section to drop: [_1]',
3962: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3963: '</span></div></td></tr>';
1.274 raeburn 3964: $$rowtotal += 4;
1.3 raeburn 3965: return $datatable;
3966: }
3967:
3968: sub print_autoupdate {
1.30 raeburn 3969: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3970: my ($enable,$datatable);
1.3 raeburn 3971: if ($position eq 'top') {
1.385 raeburn 3972: my %choices = &Apache::lonlocal::texthash (
3973: run => 'Auto-update active?',
3974: classlists => 'Update information in classlists?',
3975: unexpired => 'Skip updates for users without active or future roles?',
3976: lastactive => 'Skip updates for inactive users?',
3977: );
3978: my $itemcount = 0;
1.3 raeburn 3979: my $updateon = ' ';
3980: my $updateoff = ' checked="checked" ';
3981: if (ref($settings) eq 'HASH') {
3982: if ($settings->{'run'} eq '1') {
3983: $updateon = $updateoff;
3984: $updateoff = ' ';
3985: }
3986: }
1.385 raeburn 3987: $enable = '<tr class="LC_odd_row">'.
3988: '<td>'.$choices{'run'}.'</td>'.
3989: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3990: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 3991: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3992: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3993: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3994: '</tr>';
1.385 raeburn 3995: my @toggles = ('classlists','unexpired');
3996: my %defaultchecked = ('classlists' => 'off',
3997: 'unexpired' => 'off'
3998: );
3999: $$rowtotal ++;
4000: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4001: \%choices,$itemcount,'','','left','no');
4002: $datatable = $enable.$datatable;
4003: $$rowtotal += $itemcount;
4004: my $lastactiveon = ' ';
4005: my $lastactiveoff = ' checked="checked" ';
4006: my $lastactivestyle = 'none';
4007: my $lastactivedays;
4008: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4009: if (ref($settings) eq 'HASH') {
4010: if ($settings->{'lastactive'} =~ /^\d+$/) {
4011: $lastactiveon = $lastactiveoff;
4012: $lastactiveoff = ' ';
4013: $lastactivestyle = 'inline-block';
4014: $lastactivedays = $settings->{'lastactive'};
4015: }
4016: }
4017: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4018: $datatable .= '<tr'.$css_class.'>'.
4019: '<td>'.$choices{'lastactive'}.'</td>'.
4020: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4021: '<input type="radio" name="lastactive"'.
4022: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4023: ' <label>'.
4024: '<input type="radio" name="lastactive"'.
4025: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4026: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4027: ': '.&mt('inactive = no activity in last [_1] days',
4028: '<input type="text" size="5" name="lastactivedays" value="'.
4029: $lastactivedays.'" />').
4030: '</span></td>'.
4031: '</tr>';
4032: $$rowtotal ++;
1.131 raeburn 4033: } elsif ($position eq 'middle') {
4034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4035: my $numinrow = 3;
4036: my $locknamesettings;
4037: $datatable .= &insttypes_row($settings,$types,$usertypes,
4038: $dom,$numinrow,$othertitle,
1.305 raeburn 4039: 'lockablenames',$rowtotal);
1.131 raeburn 4040: $$rowtotal ++;
1.3 raeburn 4041: } else {
1.44 raeburn 4042: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4043: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4044: 'permanentemail','id');
1.33 raeburn 4045: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4046: my $numrows = 0;
1.26 raeburn 4047: if (ref($types) eq 'ARRAY') {
4048: if (@{$types} > 0) {
4049: $datatable =
4050: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4051: \@fields,$types,\$numrows);
1.30 raeburn 4052: $$rowtotal += @{$types};
1.26 raeburn 4053: }
1.3 raeburn 4054: }
4055: $datatable .=
4056: &usertype_update_row($settings,{'default' => $othertitle},
4057: \%fieldtitles,\@fields,['default'],
4058: \$numrows);
1.30 raeburn 4059: $$rowtotal ++;
1.3 raeburn 4060: }
4061: return $datatable;
4062: }
4063:
1.125 raeburn 4064: sub print_autocreate {
4065: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4066: my (%createon,%createoff,%currhash);
1.125 raeburn 4067: my @types = ('xml','req');
4068: if (ref($settings) eq 'HASH') {
4069: foreach my $item (@types) {
4070: $createoff{$item} = ' checked="checked" ';
4071: $createon{$item} = ' ';
4072: if (exists($settings->{$item})) {
4073: if ($settings->{$item}) {
4074: $createon{$item} = ' checked="checked" ';
4075: $createoff{$item} = ' ';
4076: }
4077: }
4078: }
1.210 raeburn 4079: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4080: $currhash{$settings->{'xmldc'}} = 1;
4081: }
1.125 raeburn 4082: } else {
4083: foreach my $item (@types) {
4084: $createoff{$item} = ' checked="checked" ';
4085: $createon{$item} = ' ';
4086: }
4087: }
4088: $$rowtotal += 2;
1.191 raeburn 4089: my $numinrow = 2;
1.125 raeburn 4090: my $datatable='<tr class="LC_odd_row">'.
4091: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4092: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4093: '<input type="radio" name="autocreate_xml"'.
4094: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4095: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4096: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4097: '</td></tr><tr>'.
4098: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4099: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4100: '<input type="radio" name="autocreate_req"'.
4101: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4102: '<label><input type="radio" name="autocreate_req"'.
4103: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4104: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4105: 'autocreate_xmldc',%currhash);
1.247 raeburn 4106: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4107: if ($numdc > 1) {
1.247 raeburn 4108: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4109: '</td><td class="LC_left_item">';
1.125 raeburn 4110: } else {
1.247 raeburn 4111: $datatable .= &mt('Course creation processed as:').
4112: '</td><td class="LC_right_item">';
1.125 raeburn 4113: }
1.247 raeburn 4114: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4115: $$rowtotal += $rows;
1.125 raeburn 4116: return $datatable;
4117: }
4118:
1.23 raeburn 4119: sub print_directorysrch {
1.277 raeburn 4120: my ($position,$dom,$settings,$rowtotal) = @_;
4121: my $datatable;
4122: if ($position eq 'top') {
4123: my $instsrchon = ' ';
4124: my $instsrchoff = ' checked="checked" ';
4125: my ($exacton,$containson,$beginson);
4126: my $instlocalon = ' ';
4127: my $instlocaloff = ' checked="checked" ';
4128: if (ref($settings) eq 'HASH') {
4129: if ($settings->{'available'} eq '1') {
4130: $instsrchon = $instsrchoff;
4131: $instsrchoff = ' ';
4132: }
4133: if ($settings->{'localonly'} eq '1') {
4134: $instlocalon = $instlocaloff;
4135: $instlocaloff = ' ';
4136: }
4137: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4138: foreach my $type (@{$settings->{'searchtypes'}}) {
4139: if ($type eq 'exact') {
4140: $exacton = ' checked="checked" ';
4141: } elsif ($type eq 'contains') {
4142: $containson = ' checked="checked" ';
4143: } elsif ($type eq 'begins') {
4144: $beginson = ' checked="checked" ';
4145: }
4146: }
4147: } else {
4148: if ($settings->{'searchtypes'} eq 'exact') {
4149: $exacton = ' checked="checked" ';
4150: } elsif ($settings->{'searchtypes'} eq 'contains') {
4151: $containson = ' checked="checked" ';
4152: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4153: $exacton = ' checked="checked" ';
4154: $containson = ' checked="checked" ';
4155: }
4156: }
1.277 raeburn 4157: }
4158: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4159: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4160:
4161: my $numinrow = 4;
4162: my $cansrchrow = 0;
4163: $datatable='<tr class="LC_odd_row">'.
4164: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4165: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4166: '<input type="radio" name="dirsrch_available"'.
4167: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4168: '<label><input type="radio" name="dirsrch_available"'.
4169: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4170: '</tr><tr>'.
4171: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4172: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4173: '<input type="radio" name="dirsrch_instlocalonly"'.
4174: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4175: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4176: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4177: '</tr>';
4178: $$rowtotal += 2;
4179: if (ref($usertypes) eq 'HASH') {
4180: if (keys(%{$usertypes}) > 0) {
4181: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4182: $numinrow,$othertitle,'cansearch',
4183: $rowtotal);
1.277 raeburn 4184: $cansrchrow = 1;
1.25 raeburn 4185: }
1.23 raeburn 4186: }
1.277 raeburn 4187: if ($cansrchrow) {
4188: $$rowtotal ++;
4189: $datatable .= '<tr>';
4190: } else {
4191: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4192: }
1.277 raeburn 4193: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4194: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4195: foreach my $title (@{$titleorder}) {
4196: if (defined($searchtitles->{$title})) {
4197: my $check = ' ';
4198: if (ref($settings) eq 'HASH') {
4199: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4200: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4201: $check = ' checked="checked" ';
4202: }
1.39 raeburn 4203: }
1.25 raeburn 4204: }
1.277 raeburn 4205: $datatable .= '<td class="LC_left_item">'.
4206: '<span class="LC_nobreak"><label>'.
4207: '<input type="checkbox" name="searchby" '.
4208: 'value="'.$title.'"'.$check.'/>'.
4209: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4210: }
4211: }
1.277 raeburn 4212: $datatable .= '</tr></table></td></tr>';
4213: $$rowtotal ++;
4214: if ($cansrchrow) {
4215: $datatable .= '<tr class="LC_odd_row">';
4216: } else {
4217: $datatable .= '<tr>';
4218: }
4219: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4220: '<td class="LC_left_item" colspan="2">'.
4221: '<span class="LC_nobreak"><label>'.
4222: '<input type="checkbox" name="searchtypes" '.
4223: $exacton.' value="exact" />'.&mt('Exact match').
4224: '</label> '.
4225: '<label><input type="checkbox" name="searchtypes" '.
4226: $beginson.' value="begins" />'.&mt('Begins with').
4227: '</label> '.
4228: '<label><input type="checkbox" name="searchtypes" '.
4229: $containson.' value="contains" />'.&mt('Contains').
4230: '</label></span></td></tr>';
4231: $$rowtotal ++;
1.26 raeburn 4232: } else {
1.277 raeburn 4233: my $domsrchon = ' checked="checked" ';
4234: my $domsrchoff = ' ';
4235: my $domlocalon = ' ';
4236: my $domlocaloff = ' checked="checked" ';
4237: if (ref($settings) eq 'HASH') {
4238: if ($settings->{'lclocalonly'} eq '1') {
4239: $domlocalon = $domlocaloff;
4240: $domlocaloff = ' ';
4241: }
4242: if ($settings->{'lcavailable'} eq '0') {
4243: $domsrchoff = $domsrchon;
4244: $domsrchon = ' ';
4245: }
4246: }
4247: $datatable='<tr class="LC_odd_row">'.
4248: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4249: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4250: '<input type="radio" name="dirsrch_domavailable"'.
4251: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4252: '<label><input type="radio" name="dirsrch_domavailable"'.
4253: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4254: '</tr><tr>'.
4255: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4256: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4257: '<input type="radio" name="dirsrch_domlocalonly"'.
4258: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4259: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4260: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4261: '</tr>';
4262: $$rowtotal += 2;
1.26 raeburn 4263: }
1.25 raeburn 4264: return $datatable;
4265: }
4266:
1.28 raeburn 4267: sub print_contacts {
1.286 raeburn 4268: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4269: my $datatable;
4270: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4271: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4272: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4273: if ($position eq 'top') {
4274: if (ref($settings) eq 'HASH') {
4275: foreach my $item (@contacts) {
4276: if (exists($settings->{$item})) {
4277: $to{$item} = $settings->{$item};
4278: }
4279: }
4280: }
4281: } elsif ($position eq 'middle') {
4282: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4283: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4284: foreach my $type (@mailings) {
4285: $otheremails{$type} = '';
4286: }
1.340 raeburn 4287: } elsif ($position eq 'lower') {
4288: if (ref($settings) eq 'HASH') {
4289: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4290: %lonstatus = %{$settings->{'lonstatus'}};
4291: }
4292: }
1.286 raeburn 4293: } else {
4294: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4295: foreach my $type (@mailings) {
4296: $otheremails{$type} = '';
4297: }
1.286 raeburn 4298: $bccemails{'helpdeskmail'} = '';
4299: $bccemails{'otherdomsmail'} = '';
4300: $includestr{'helpdeskmail'} = '';
4301: $includestr{'otherdomsmail'} = '';
4302: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4303: }
1.28 raeburn 4304: if (ref($settings) eq 'HASH') {
1.340 raeburn 4305: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4306: foreach my $type (@mailings) {
4307: if (exists($settings->{$type})) {
4308: if (ref($settings->{$type}) eq 'HASH') {
4309: foreach my $item (@contacts) {
4310: if ($settings->{$type}{$item}) {
4311: $checked{$type}{$item} = ' checked="checked" ';
4312: }
4313: }
4314: $otheremails{$type} = $settings->{$type}{'others'};
4315: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4316: $bccemails{$type} = $settings->{$type}{'bcc'};
4317: if ($settings->{$type}{'include'} ne '') {
4318: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4319: $includestr{$type} = &unescape($includestr{$type});
4320: }
4321: }
4322: }
4323: } elsif ($type eq 'lonstatusmail') {
4324: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4325: }
1.28 raeburn 4326: }
4327: }
1.286 raeburn 4328: if ($position eq 'bottom') {
4329: foreach my $type (@mailings) {
4330: $bccemails{$type} = $settings->{$type}{'bcc'};
4331: if ($settings->{$type}{'include'} ne '') {
4332: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4333: $includestr{$type} = &unescape($includestr{$type});
4334: }
4335: }
4336: if (ref($settings->{'helpform'}) eq 'HASH') {
4337: if (ref($fields) eq 'ARRAY') {
4338: foreach my $field (@{$fields}) {
4339: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4340: }
1.286 raeburn 4341: }
4342: if (exists($settings->{'helpform'}{'maxsize'})) {
4343: $maxsize = $settings->{'helpform'}{'maxsize'};
4344: } else {
1.289 raeburn 4345: $maxsize = '1.0';
1.286 raeburn 4346: }
4347: } else {
4348: if (ref($fields) eq 'ARRAY') {
4349: foreach my $field (@{$fields}) {
4350: $currfield{$field} = 'yes';
1.134 raeburn 4351: }
1.28 raeburn 4352: }
1.286 raeburn 4353: $maxsize = '1.0';
1.28 raeburn 4354: }
4355: }
4356: } else {
1.286 raeburn 4357: if ($position eq 'top') {
4358: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4359: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4360: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4361: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4362: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4363: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4364: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4365: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4366: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4367: } elsif ($position eq 'bottom') {
4368: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4369: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4370: if (ref($fields) eq 'ARRAY') {
4371: foreach my $field (@{$fields}) {
4372: $currfield{$field} = 'yes';
4373: }
4374: }
4375: $maxsize = '1.0';
4376: }
1.28 raeburn 4377: }
4378: my ($titles,$short_titles) = &contact_titles();
4379: my $rownum = 0;
4380: my $css_class;
1.286 raeburn 4381: if ($position eq 'top') {
4382: foreach my $item (@contacts) {
4383: $css_class = $rownum%2?' class="LC_odd_row"':'';
4384: $datatable .= '<tr'.$css_class.'>'.
4385: '<td><span class="LC_nobreak">'.$titles->{$item}.
4386: '</span></td><td class="LC_right_item">'.
4387: '<input type="text" name="'.$item.'" value="'.
4388: $to{$item}.'" /></td></tr>';
4389: $rownum ++;
4390: }
1.315 raeburn 4391: } elsif ($position eq 'bottom') {
4392: $css_class = $rownum%2?' class="LC_odd_row"':'';
4393: $datatable .= '<tr'.$css_class.'>'.
4394: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4395: &mt('(e-mail, subject, and description always shown)').
4396: '</td><td class="LC_left_item">';
4397: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4398: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4399: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4400: foreach my $field (@{$fields}) {
4401: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4402: if (($field eq 'screenshot') || ($field eq 'cc')) {
4403: $datatable .= ' '.&mt('(logged-in users)');
4404: }
4405: $datatable .='</td><td>';
4406: my $clickaction;
4407: if ($field eq 'screenshot') {
4408: $clickaction = ' onclick="screenshotSize(this);"';
4409: }
4410: if (ref($possoptions->{$field}) eq 'ARRAY') {
4411: foreach my $option (@{$possoptions->{$field}}) {
4412: my $checked;
4413: if ($currfield{$field} eq $option) {
4414: $checked = ' checked="checked"';
4415: }
4416: $datatable .= '<span class="LC_nobreak"><label>'.
4417: '<input type="radio" name="helpform_'.$field.'" '.
4418: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4419: '</label></span>'.(' 'x2);
4420: }
4421: }
4422: if ($field eq 'screenshot') {
4423: my $display;
4424: if ($currfield{$field} eq 'no') {
4425: $display = ' style="display:none"';
4426: }
1.334 raeburn 4427: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4428: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4429: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4430: }
4431: $datatable .= '</td></tr>';
4432: }
4433: $datatable .= '</table>';
4434: }
4435: $datatable .= '</td></tr>'."\n";
4436: $rownum ++;
4437: }
1.340 raeburn 4438: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4439: foreach my $type (@mailings) {
4440: $css_class = $rownum%2?' class="LC_odd_row"':'';
4441: $datatable .= '<tr'.$css_class.'>'.
4442: '<td><span class="LC_nobreak">'.
4443: $titles->{$type}.': </span></td>'.
4444: '<td class="LC_left_item">';
4445: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4446: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4447: }
4448: $datatable .= '<span class="LC_nobreak">';
4449: foreach my $item (@contacts) {
4450: $datatable .= '<label>'.
4451: '<input type="checkbox" name="'.$type.'"'.
4452: $checked{$type}{$item}.
4453: ' value="'.$item.'" />'.$short_titles->{$item}.
4454: '</label> ';
4455: }
4456: $datatable .= '</span><br />'.&mt('Others').': '.
4457: '<input type="text" name="'.$type.'_others" '.
4458: 'value="'.$otheremails{$type}.'" />';
4459: my %locchecked;
4460: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4461: foreach my $loc ('s','b') {
4462: if ($includeloc{$type} eq $loc) {
4463: $locchecked{$loc} = ' checked="checked"';
4464: last;
4465: }
4466: }
4467: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4468: '<input type="text" name="'.$type.'_bcc" '.
4469: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4470: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4471: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4472: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4473: '<span class="LC_nobreak">'.&mt('Location:').' '.
4474: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4475: (' 'x2).
4476: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4477: '</span></fieldset>';
4478: }
4479: $datatable .= '</td></tr>'."\n";
4480: $rownum ++;
4481: }
1.28 raeburn 4482: }
1.286 raeburn 4483: if ($position eq 'middle') {
4484: my %choices;
1.340 raeburn 4485: my $corelink = &core_link_msu();
4486: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4487: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4488: $corelink);
4489: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4490: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4491: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4492: 'reportupdates' => 'on',
4493: 'reportstatus' => 'on');
1.286 raeburn 4494: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4495: \%choices,$rownum);
4496: $datatable .= $reports;
1.340 raeburn 4497: } elsif ($position eq 'lower') {
1.378 raeburn 4498: my (%current,%excluded,%weights);
1.340 raeburn 4499: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4500: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4501: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4502: } else {
1.378 raeburn 4503: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4504: }
4505: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4506: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4507: } else {
1.378 raeburn 4508: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4509: }
4510: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4511: foreach my $type ('E','W','N','U') {
1.340 raeburn 4512: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4513: $weights{$type} = $lonstatus{'weights'}{$type};
4514: } else {
4515: $weights{$type} = $defaults->{$type};
4516: }
4517: }
4518: } else {
1.341 raeburn 4519: foreach my $type ('E','W','N','U') {
1.340 raeburn 4520: $weights{$type} = $defaults->{$type};
4521: }
4522: }
4523: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4524: if (@{$lonstatus{'excluded'}} > 0) {
4525: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4526: }
4527: }
1.378 raeburn 4528: foreach my $item ('errorthreshold','errorsysmail') {
4529: $css_class = $rownum%2?' class="LC_odd_row"':'';
4530: $datatable .= '<tr'.$css_class.'>'.
4531: '<td class="LC_left_item"><span class="LC_nobreak">'.
4532: $titles->{$item}.
4533: '</span></td><td class="LC_left_item">'.
4534: '<input type="text" name="'.$item.'" value="'.
4535: $current{$item}.'" size="5" /></td></tr>';
4536: $rownum ++;
4537: }
1.340 raeburn 4538: $css_class = $rownum%2?' class="LC_odd_row"':'';
4539: $datatable .= '<tr'.$css_class.'>'.
4540: '<td class="LC_left_item">'.
4541: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4542: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4543: foreach my $type ('E','W','N','U') {
1.340 raeburn 4544: $datatable .= '<td>'.$names->{$type}.'<br />'.
4545: '<input type="text" name="errorweights_'.$type.'" value="'.
4546: $weights{$type}.'" size="5" /></td>';
4547: }
4548: $datatable .= '</tr></table></tr>';
4549: $rownum ++;
4550: $css_class = $rownum%2?' class="LC_odd_row"':'';
4551: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4552: $titles->{'errorexcluded'}.'</td>'.
4553: '<td class="LC_left_item"><table>';
4554: my $numinrow = 4;
4555: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4556: for (my $i=0; $i<@ids; $i++) {
4557: my $rem = $i%($numinrow);
4558: if ($rem == 0) {
4559: if ($i > 0) {
4560: $datatable .= '</tr>';
4561: }
4562: $datatable .= '<tr>';
4563: }
4564: my $check;
4565: if ($excluded{$ids[$i]}) {
4566: $check = ' checked="checked" ';
4567: }
4568: $datatable .= '<td class="LC_left_item">'.
4569: '<span class="LC_nobreak"><label>'.
4570: '<input type="checkbox" name="errorexcluded" '.
4571: 'value="'.$ids[$i].'"'.$check.' />'.
4572: $ids[$i].'</label></span></td>';
4573: }
4574: my $colsleft = $numinrow - @ids%($numinrow);
4575: if ($colsleft > 1 ) {
4576: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4577: ' </td>';
4578: } elsif ($colsleft == 1) {
4579: $datatable .= '<td class="LC_left_item"> </td>';
4580: }
4581: $datatable .= '</tr></table></td></tr>';
4582: $rownum ++;
1.286 raeburn 4583: } elsif ($position eq 'bottom') {
1.315 raeburn 4584: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4585: my (@posstypes,%usertypeshash);
4586: if (ref($types) eq 'ARRAY') {
4587: @posstypes = @{$types};
4588: }
4589: if (@posstypes) {
4590: if (ref($usertypes) eq 'HASH') {
4591: %usertypeshash = %{$usertypes};
4592: }
4593: my @overridden;
4594: my $numinrow = 4;
4595: if (ref($settings) eq 'HASH') {
4596: if (ref($settings->{'overrides'}) eq 'HASH') {
4597: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4598: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4599: push(@overridden,$key);
4600: foreach my $item (@contacts) {
4601: if ($settings->{'overrides'}{$key}{$item}) {
4602: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4603: }
4604: }
4605: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4606: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4607: $includeloc{'override_'.$key} = '';
4608: $includestr{'override_'.$key} = '';
4609: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4610: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4611: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4612: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4613: }
1.286 raeburn 4614: }
4615: }
4616: }
1.315 raeburn 4617: }
4618: my $customclass = 'LC_helpdesk_override';
4619: my $optionsprefix = 'LC_options_helpdesk_';
4620:
4621: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4622:
4623: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4624: $numinrow,$othertitle,'overrides',
4625: \$rownum,$onclicktypes,$customclass);
4626: $rownum ++;
4627: $usertypeshash{'default'} = $othertitle;
4628: foreach my $status (@posstypes) {
4629: my $css_class;
4630: if ($rownum%2) {
4631: $css_class = 'LC_odd_row ';
4632: }
4633: $css_class .= $customclass;
4634: my $rowid = $optionsprefix.$status;
4635: my $hidden = 1;
4636: my $currstyle = 'display:none';
4637: if (grep(/^\Q$status\E$/,@overridden)) {
4638: $currstyle = 'display:table-row';
4639: $hidden = 0;
4640: }
4641: my $key = 'override_'.$status;
4642: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4643: $includeloc{$key},$includestr{$key},$status,$rowid,
4644: $usertypeshash{$status},$css_class,$currstyle,
4645: \@contacts,$short_titles);
4646: unless ($hidden) {
4647: $rownum ++;
1.286 raeburn 4648: }
4649: }
1.134 raeburn 4650: }
1.28 raeburn 4651: }
1.30 raeburn 4652: $$rowtotal += $rownum;
1.28 raeburn 4653: return $datatable;
4654: }
4655:
1.340 raeburn 4656: sub core_link_msu {
4657: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4658: &mt('LON-CAPA core group - MSU'),600,500);
4659: }
4660:
1.315 raeburn 4661: sub overridden_helpdesk {
4662: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4663: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4664: my $class = 'LC_left_item';
4665: if ($css_class) {
4666: $css_class = ' class="'.$css_class.'"';
4667: }
4668: if ($rowid) {
4669: $rowid = ' id="'.$rowid.'"';
4670: }
4671: if ($rowstyle) {
4672: $rowstyle = ' style="'.$rowstyle.'"';
4673: }
4674: my ($output,$description);
4675: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4676: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4677: "<td>$description</td>\n".
4678: '<td class="'.$class.'" colspan="2">'.
4679: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4680: '<span class="LC_nobreak">';
4681: if (ref($contacts) eq 'ARRAY') {
4682: foreach my $item (@{$contacts}) {
4683: my $check;
4684: if (ref($checked) eq 'HASH') {
4685: $check = $checked->{$item};
4686: }
4687: my $title;
4688: if (ref($short_titles) eq 'HASH') {
4689: $title = $short_titles->{$item};
4690: }
4691: $output .= '<label>'.
4692: '<input type="checkbox" name="override_'.$type.'"'.$check.
4693: ' value="'.$item.'" />'.$title.'</label> ';
4694: }
4695: }
4696: $output .= '</span><br />'.&mt('Others').': '.
4697: '<input type="text" name="override_'.$type.'_others" '.
4698: 'value="'.$otheremails.'" />';
4699: my %locchecked;
4700: foreach my $loc ('s','b') {
4701: if ($includeloc eq $loc) {
4702: $locchecked{$loc} = ' checked="checked"';
4703: last;
4704: }
4705: }
4706: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4707: '<input type="text" name="override_'.$type.'_bcc" '.
4708: 'value="'.$bccemails.'" /></fieldset>'.
4709: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4710: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4711: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4712: '<span class="LC_nobreak">'.&mt('Location:').' '.
4713: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4714: (' 'x2).
4715: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4716: '</span></fieldset>'.
4717: '</td></tr>'."\n";
4718: return $output;
4719: }
4720:
1.286 raeburn 4721: sub contacts_javascript {
4722: return <<"ENDSCRIPT";
4723:
4724: <script type="text/javascript">
4725: // <![CDATA[
4726:
4727: function screenshotSize(field) {
4728: if (document.getElementById('help_screenshotsize')) {
4729: if (field.value == 'no') {
1.289 raeburn 4730: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4731: } else {
4732: document.getElementById('help_screenshotsize').style.display="";
4733: }
4734: }
4735: return;
4736: }
4737:
1.315 raeburn 4738: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4739: if (form.elements[checkbox].length != undefined) {
4740: var count = 0;
4741: if (docount) {
4742: for (var i=0; i<form.elements[checkbox].length; i++) {
4743: if (form.elements[checkbox][i].checked) {
4744: count ++;
4745: }
4746: }
4747: }
4748: for (var i=0; i<form.elements[checkbox].length; i++) {
4749: var type = form.elements[checkbox][i].value;
4750: if (document.getElementById(prefix+type)) {
4751: if (form.elements[checkbox][i].checked) {
4752: document.getElementById(prefix+type).style.display = 'table-row';
4753: if (count % 2 == 1) {
4754: document.getElementById(prefix+type).className = target+' LC_odd_row';
4755: } else {
4756: document.getElementById(prefix+type).className = target;
4757: }
4758: count ++;
4759: } else {
4760: document.getElementById(prefix+type).style.display = 'none';
4761: }
4762: }
4763: }
4764: }
4765: return;
4766: }
4767:
4768:
1.286 raeburn 4769: // ]]>
4770: </script>
4771:
4772: ENDSCRIPT
4773: }
4774:
1.118 jms 4775: sub print_helpsettings {
1.282 raeburn 4776: my ($position,$dom,$settings,$rowtotal) = @_;
4777: my $confname = $dom.'-domainconfig';
1.285 raeburn 4778: my $formname = 'display';
1.168 raeburn 4779: my ($datatable,$itemcount);
1.282 raeburn 4780: if ($position eq 'top') {
4781: $itemcount = 1;
4782: my (%choices,%defaultchecked,@toggles);
4783: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4784: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4785: &mt('LON-CAPA bug tracker'),600,500));
4786: %defaultchecked = ('submitbugs' => 'on');
4787: @toggles = ('submitbugs');
4788: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4789: \%choices,$itemcount);
4790: $$rowtotal ++;
4791: } else {
4792: my $css_class;
4793: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4794: my (%customroles,%ordered,%current);
1.301 raeburn 4795: if (ref($settings) eq 'HASH') {
4796: if (ref($settings->{'adhoc'}) eq 'HASH') {
4797: %current = %{$settings->{'adhoc'}};
4798: }
1.285 raeburn 4799: }
4800: my $count = 0;
4801: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4802: if ($key=~/^rolesdef\_(\w+)$/) {
4803: my $rolename = $1;
1.285 raeburn 4804: my (%privs,$order);
1.282 raeburn 4805: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4806: $customroles{$rolename} = \%privs;
1.285 raeburn 4807: if (ref($current{$rolename}) eq 'HASH') {
4808: $order = $current{$rolename}{'order'};
4809: }
4810: if ($order eq '') {
4811: $order = $count;
4812: }
4813: $ordered{$order} = $rolename;
4814: $count++;
4815: }
4816: }
4817: my $maxnum = scalar(keys(%ordered));
4818: my @roles_by_num = ();
4819: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4820: push(@roles_by_num,$item);
4821: }
4822: my $context = 'domprefs';
4823: my $crstype = 'Course';
4824: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4825: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4826: my ($numstatustypes,@jsarray);
4827: if (ref($types) eq 'ARRAY') {
4828: if (@{$types} > 0) {
4829: $numstatustypes = scalar(@{$types});
4830: push(@accesstypes,'status');
4831: @jsarray = ('bystatus');
1.282 raeburn 4832: }
4833: }
1.290 raeburn 4834: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4835: if (keys(%domhelpdesk)) {
4836: push(@accesstypes,('inc','exc'));
4837: push(@jsarray,('notinc','notexc'));
4838: }
4839: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4840: my $context = 'domprefs';
4841: my $crstype = 'Course';
1.285 raeburn 4842: my $prefix = 'helproles_';
4843: my $add_class = 'LC_hidden';
4844: foreach my $num (@roles_by_num) {
4845: my $role = $ordered{$num};
4846: my ($desc,$access,@statuses);
4847: if (ref($current{$role}) eq 'HASH') {
4848: $desc = $current{$role}{'desc'};
4849: $access = $current{$role}{'access'};
4850: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4851: @statuses = @{$current{$role}{'insttypes'}};
4852: }
4853: }
4854: if ($desc eq '') {
4855: $desc = $role;
4856: }
4857: my $identifier = 'custhelp'.$num;
1.282 raeburn 4858: my %full=();
4859: my %levels= (
4860: course => {},
4861: domain => {},
4862: system => {},
4863: );
4864: my %levelscurrent=(
4865: course => {},
4866: domain => {},
4867: system => {},
4868: );
4869: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4870: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4872: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4873: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4874: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4875: for (my $k=0; $k<=$maxnum; $k++) {
4876: my $vpos = $k+1;
4877: my $selstr;
4878: if ($k == $num) {
4879: $selstr = ' selected="selected" ';
4880: }
4881: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4882: }
4883: $datatable .= '</select>'.(' 'x2).
4884: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4885: '</td>'.
4886: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4887: &mt('Name shown to users:').
4888: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4889: '</fieldset>'.
4890: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4891: $othertitle,$usertypes,$types,\%domhelpdesk).
4892: '<fieldset>'.
4893: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4894: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4895: \%levelscurrent,$identifier,
4896: 'LC_hidden',$prefix.$num.'_privs').
4897: '</fieldset></td>';
1.282 raeburn 4898: $itemcount ++;
4899: }
4900: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4901: my $newcust = 'custhelp'.$count;
4902: my (%privs,%levelscurrent);
4903: my %full=();
4904: my %levels= (
4905: course => {},
4906: domain => {},
4907: system => {},
4908: );
4909: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4910: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4911: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4912: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4913: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4914: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4915: for (my $k=0; $k<$maxnum+1; $k++) {
4916: my $vpos = $k+1;
4917: my $selstr;
4918: if ($k == $maxnum) {
4919: $selstr = ' selected="selected" ';
4920: }
4921: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4922: }
4923: $datatable .= '</select> '."\n".
1.282 raeburn 4924: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4925: '</label></span></td>'.
1.285 raeburn 4926: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4927: '<span class="LC_nobreak">'.
4928: &mt('Internal name:').
4929: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4930: '</span>'.(' 'x4).
4931: '<span class="LC_nobreak">'.
4932: &mt('Name shown to users:').
4933: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4934: '</span></fieldset>'.
4935: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4936: $usertypes,$types,\%domhelpdesk).
4937: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4938: &Apache::lonuserutils::custom_role_header($context,$crstype,
4939: \@templateroles,$newcust).
4940: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4941: \%levelscurrent,$newcust).
1.334 raeburn 4942: '</fieldset>'.
4943: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4944: '</td></tr>';
1.282 raeburn 4945: $count ++;
4946: $$rowtotal += $count;
4947: }
1.166 raeburn 4948: return $datatable;
1.121 raeburn 4949: }
4950:
1.285 raeburn 4951: sub adhocbutton {
4952: my ($prefix,$num,$field,$visibility) = @_;
4953: my %lt = &Apache::lonlocal::texthash(
4954: show => 'Show details',
4955: hide => 'Hide details',
4956: );
4957: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4958: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4959: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4960: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4961: }
4962:
4963: sub helpsettings_javascript {
4964: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4965: return unless(ref($roles_by_num) eq 'ARRAY');
4966: my %html_js_lt = &Apache::lonlocal::texthash(
4967: show => 'Show details',
4968: hide => 'Hide details',
4969: );
4970: &html_escape(\%html_js_lt);
4971: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4972: return <<"ENDSCRIPT";
4973: <script type="text/javascript">
4974: // <![CDATA[
4975:
4976: function reorderHelpRoles(form,item) {
4977: var changedVal;
4978: $jstext
4979: var newpos = 'helproles_${total}_pos';
4980: var maxh = 1 + $total;
4981: var current = new Array();
4982: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4983: if (item == newpos) {
4984: changedVal = newitemVal;
4985: } else {
4986: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4987: current[newitemVal] = newpos;
4988: }
4989: for (var i=0; i<helproles.length; i++) {
4990: var elementName = 'helproles_'+helproles[i]+'_pos';
4991: if (elementName != item) {
4992: if (form.elements[elementName]) {
4993: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4994: current[currVal] = elementName;
4995: }
4996: }
4997: }
4998: var oldVal;
4999: for (var j=0; j<maxh; j++) {
5000: if (current[j] == undefined) {
5001: oldVal = j;
5002: }
5003: }
5004: if (oldVal < changedVal) {
5005: for (var k=oldVal+1; k<=changedVal ; k++) {
5006: var elementName = current[k];
5007: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5008: }
5009: } else {
5010: for (var k=changedVal; k<oldVal; k++) {
5011: var elementName = current[k];
5012: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5013: }
5014: }
5015: return;
5016: }
5017:
5018: function helpdeskAccess(num) {
5019: var curraccess = null;
5020: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5021: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5022: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5023: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5024: }
5025: }
5026: }
5027: var shown = Array();
5028: var hidden = Array();
5029: if (curraccess == 'none') {
5030: hidden = Array('$hiddenstr');
5031: } else {
5032: if (curraccess == 'status') {
5033: shown = Array('bystatus');
5034: hidden = Array('notinc','notexc');
5035: } else {
5036: if (curraccess == 'exc') {
5037: shown = Array('notexc');
5038: hidden = Array('notinc','bystatus');
5039: }
5040: if (curraccess == 'inc') {
5041: shown = Array('notinc');
5042: hidden = Array('notexc','bystatus');
5043: }
1.293 raeburn 5044: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5045: hidden = Array('notinc','notexc','bystatus');
5046: }
5047: }
5048: }
5049: if (hidden.length > 0) {
5050: for (var i=0; i<hidden.length; i++) {
5051: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5052: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5053: }
5054: }
5055: }
5056: if (shown.length > 0) {
5057: for (var i=0; i<shown.length; i++) {
5058: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5059: if (shown[i] == 'privs') {
5060: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5061: } else {
5062: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5063: }
5064: }
5065: }
5066: }
5067: return;
5068: }
5069:
5070: function toggleHelpdeskItem(num,field) {
5071: if (document.getElementById('helproles_'+num+'_'+field)) {
5072: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5073: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5074: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5075: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5076: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5077: }
5078: } else {
5079: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5080: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5081: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5082: }
5083: }
5084: }
5085: return;
5086: }
5087:
5088: // ]]>
5089: </script>
5090:
5091: ENDSCRIPT
5092: }
5093:
5094: sub helpdeskroles_access {
5095: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5096: $usertypes,$types,$domhelpdesk) = @_;
5097: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5098: my %lt = &Apache::lonlocal::texthash(
5099: 'rou' => 'Role usage',
5100: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5101: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5102: 'dh' => 'All with domain helpdesk role',
5103: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5104: 'none' => 'None',
5105: 'status' => 'Determined based on institutional status',
5106: 'inc' => 'Include all, but exclude specific personnel',
5107: 'exc' => 'Exclude all, but include specific personnel',
5108: );
5109: my %usecheck = (
5110: all => ' checked="checked"',
5111: );
5112: my %displaydiv = (
5113: status => 'none',
5114: inc => 'none',
5115: exc => 'none',
5116: priv => 'block',
5117: );
5118: my $output;
5119: if (ref($current) eq 'HASH') {
5120: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5121: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5122: $usecheck{$current->{access}} = $usecheck{'all'};
5123: delete($usecheck{'all'});
5124: if ($current->{access} =~ /^(status|inc|exc)$/) {
5125: my $access = $1;
5126: $displaydiv{$access} = 'inline';
5127: } elsif ($current->{access} eq 'none') {
5128: $displaydiv{'priv'} = 'none';
5129: }
5130: }
5131: }
5132: }
5133: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5134: '<p>'.$lt{'whi'}.'</p>';
5135: foreach my $access (@{$accesstypes}) {
5136: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5137: ' onclick="helpdeskAccess('."'$num'".');" />'.
5138: $lt{$access}.'</label>';
5139: if ($access eq 'status') {
5140: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5141: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5142: $othertitle,$usertypes,$types).
5143: '</div>';
5144: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5145: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5146: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5147: '</div>';
5148: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5149: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5150: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5151: '</div>';
5152: }
5153: $output .= '</p>';
5154: }
5155: $output .= '</fieldset>';
5156: return $output;
5157: }
5158:
1.121 raeburn 5159: sub radiobutton_prefs {
1.192 raeburn 5160: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5161: $additional,$align,$firstval) = @_;
1.121 raeburn 5162: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5163: (ref($choices) eq 'HASH'));
5164:
1.170 raeburn 5165: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5166:
5167: foreach my $item (@{$toggles}) {
5168: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5169: $checkedon{$item} = ' checked="checked" ';
5170: $checkedoff{$item} = ' ';
1.121 raeburn 5171: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5172: $checkedoff{$item} = ' checked="checked" ';
5173: $checkedon{$item} = ' ';
5174: }
5175: }
5176: if (ref($settings) eq 'HASH') {
1.121 raeburn 5177: foreach my $item (@{$toggles}) {
1.118 jms 5178: if ($settings->{$item} eq '1') {
5179: $checkedon{$item} = ' checked="checked" ';
5180: $checkedoff{$item} = ' ';
5181: } elsif ($settings->{$item} eq '0') {
5182: $checkedoff{$item} = ' checked="checked" ';
5183: $checkedon{$item} = ' ';
5184: }
5185: }
1.121 raeburn 5186: }
1.192 raeburn 5187: if ($onclick) {
5188: $onclick = ' onclick="'.$onclick.'"';
5189: }
1.121 raeburn 5190: foreach my $item (@{$toggles}) {
1.118 jms 5191: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5192: $datatable .=
1.306 raeburn 5193: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5194: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5195: '</span></td>';
5196: if ($align eq 'left') {
5197: $datatable .= '<td class="LC_left_item">';
5198: } else {
5199: $datatable .= '<td class="LC_right_item">';
5200: }
1.385 raeburn 5201: $datatable .= '<span class="LC_nobreak">';
5202: if ($firstval eq 'no') {
5203: $datatable .=
5204: '<label><input type="radio" name="'.
5205: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5206: '</label> <label><input type="radio" name="'.$item.'" '.
5207: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5208: } else {
5209: $datatable .=
5210: '<label><input type="radio" name="'.
5211: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5212: '</label> <label><input type="radio" name="'.$item.'" '.
5213: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5214: }
5215: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5216: $itemcount ++;
1.121 raeburn 5217: }
5218: return ($datatable,$itemcount);
5219: }
5220:
1.267 raeburn 5221: sub print_ltitools {
5222: my ($dom,$settings,$rowtotal) = @_;
5223: my $rownum = 0;
5224: my $css_class;
5225: my $itemcount = 1;
5226: my $maxnum = 0;
5227: my %ordered;
5228: if (ref($settings) eq 'HASH') {
5229: foreach my $item (keys(%{$settings})) {
5230: if (ref($settings->{$item}) eq 'HASH') {
5231: my $num = $settings->{$item}{'order'};
5232: $ordered{$num} = $item;
5233: }
5234: }
5235: }
5236: my $confname = $dom.'-domainconfig';
5237: my $switchserver = &check_switchserver($dom,$confname);
5238: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5239: my $datatable;
1.267 raeburn 5240: my %lt = <itools_names();
5241: my @courseroles = ('cc','in','ta','ep','st');
5242: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 5243: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 5244: if (keys(%ordered)) {
5245: my @items = sort { $a <=> $b } keys(%ordered);
5246: for (my $i=0; $i<@items; $i++) {
5247: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5248: my $item = $ordered{$items[$i]};
1.323 raeburn 5249: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 5250: if (ref($settings->{$item}) eq 'HASH') {
5251: $title = $settings->{$item}->{'title'};
5252: $url = $settings->{$item}->{'url'};
5253: $key = $settings->{$item}->{'key'};
5254: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 5255: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 5256: my $image = $settings->{$item}->{'image'};
5257: if ($image ne '') {
5258: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
5259: }
1.323 raeburn 5260: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
5261: $sigsel{'HMAC-256'} = ' selected="selected"';
5262: } else {
5263: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
5264: }
1.267 raeburn 5265: }
1.319 raeburn 5266: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 5267: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5268: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
5269: for (my $k=0; $k<=$maxnum; $k++) {
5270: my $vpos = $k+1;
5271: my $selstr;
5272: if ($k == $i) {
5273: $selstr = ' selected="selected" ';
5274: }
5275: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5276: }
5277: $datatable .= '</select>'.(' 'x2).
5278: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
5279: &mt('Delete?').'</label></span></td>'.
5280: '<td colspan="2">'.
5281: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5282: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 5283: (' 'x2).
5284: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
5285: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5286: (' 'x2).
5287: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
5288: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5289: (' 'x2).
5290: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
5291: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
5292: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 5293: '<br /><br />'.
1.323 raeburn 5294: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 5295: ' value="'.$url.'" /></span>'.
5296: (' 'x2).
1.319 raeburn 5297: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 5298: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
5299: (' 'x2).
1.322 raeburn 5300: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
5301: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
5302: (' 'x2).
1.267 raeburn 5303: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5304: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
5305: '<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>'.
5306: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
5307: '</fieldset>'.
5308: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5309: '<span class="LC_nobreak">'.&mt('Display target:');
5310: my %currdisp;
5311: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
5312: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
5313: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 5314: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
5315: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 5316: } else {
5317: $currdisp{'iframe'} = ' checked="checked"';
5318: }
5319: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
5320: $currdisp{'width'} = $1;
5321: }
5322: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
5323: $currdisp{'height'} = $1;
5324: }
1.296 raeburn 5325: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
5326: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 5327: } else {
5328: $currdisp{'iframe'} = ' checked="checked"';
5329: }
1.298 raeburn 5330: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5331: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
5332: $lt{$disp}.'</label>'.(' 'x2);
5333: }
5334: $datatable .= (' 'x4);
5335: foreach my $dimen ('width','height') {
5336: $datatable .= '<label>'.$lt{$dimen}.' '.
5337: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
5338: (' 'x2);
5339: }
1.334 raeburn 5340: $datatable .= '</span><br />'.
1.296 raeburn 5341: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5342: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 5343: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5344: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5345: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5346: my %units = (
5347: 'passback' => 'days',
5348: 'roster' => 'seconds',
5349: );
1.267 raeburn 5350: foreach my $extra ('passback','roster') {
1.319 raeburn 5351: my $validsty = 'none';
5352: my $currvalid;
1.267 raeburn 5353: my $checkedon = '';
5354: my $checkedoff = ' checked="checked"';
5355: if ($settings->{$item}->{$extra}) {
5356: $checkedon = $checkedoff;
5357: $checkedoff = '';
1.319 raeburn 5358: $validsty = 'inline-block';
5359: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5360: $currvalid = $settings->{$item}->{$extra.'valid'};
5361: }
5362: }
5363: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5364: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5365: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5366: &mt('No').'</label>'.(' 'x2).
5367: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5368: &mt('Yes').'</label></span></div>'.
5369: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5370: '<span class="LC_nobreak">'.
5371: &mt("at least [_1] $units{$extra} after launch",
5372: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5373: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5374: }
1.319 raeburn 5375: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5376: if ($imgsrc) {
5377: $datatable .= $imgsrc.
5378: '<label><input type="checkbox" name="ltitools_image_del"'.
5379: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5380: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5381: } else {
5382: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5383: }
5384: if ($switchserver) {
5385: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5386: } else {
5387: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5388: }
5389: $datatable .= '</span></fieldset>';
1.324 raeburn 5390: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5391: if (ref($settings->{$item}) eq 'HASH') {
5392: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5393: %checkedfields = %{$settings->{$item}->{'fields'}};
5394: }
1.324 raeburn 5395: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5396: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5397: %rolemaps = %{$settings->{$item}->{'roles'}};
5398: $checkedfields{'roles'} = 1;
5399: }
5400: }
5401: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5402: '<span class="LC_nobreak">';
1.324 raeburn 5403: my $userfieldstyle = 'display:none;';
5404: my $seluserdom = '';
5405: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5406: foreach my $field (@fields) {
1.324 raeburn 5407: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5408: if ($checkedfields{$field}) {
5409: $checked = ' checked="checked"';
5410: }
1.324 raeburn 5411: if ($field eq 'user') {
5412: $id = ' id="ltitools_user_field_'.$i.'"';
5413: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5414: if ($checked) {
5415: $userfieldstyle = 'display:inline-block';
5416: if ($userincdom) {
5417: $seluserdom = $unseluserdom;
5418: $unseluserdom = '';
5419: }
5420: }
5421: } else {
5422: $spacer = (' ' x2);
5423: }
1.267 raeburn 5424: $datatable .= '<label>'.
1.324 raeburn 5425: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5426: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5427: }
1.324 raeburn 5428: $datatable .= '</span>';
5429: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5430: '<span class="LC_nobreak"> : '.
5431: '<select name="ltitools_userincdom_'.$i.'">'.
5432: '<option value="">'.&mt('Select').'</option>'.
5433: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5434: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5435: '</select></span></div>';
5436: $datatable .= '</fieldset>'.
1.267 raeburn 5437: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5438: foreach my $role (@courseroles) {
5439: my ($selected,$selectnone);
5440: if (!$rolemaps{$role}) {
5441: $selectnone = ' selected="selected"';
5442: }
1.306 raeburn 5443: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5444: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5445: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5446: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5447: foreach my $ltirole (@ltiroles) {
5448: unless ($selectnone) {
5449: if ($rolemaps{$role} eq $ltirole) {
5450: $selected = ' selected="selected"';
5451: } else {
5452: $selected = '';
5453: }
5454: }
5455: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5456: }
5457: $datatable .= '</select></td>';
5458: }
1.273 raeburn 5459: $datatable .= '</tr></table></fieldset>';
5460: my %courseconfig;
5461: if (ref($settings->{$item}) eq 'HASH') {
5462: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5463: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5464: }
5465: }
5466: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5467: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5468: my $checked;
5469: if ($courseconfig{$item}) {
5470: $checked = ' checked="checked"';
5471: }
5472: $datatable .= '<label>'.
5473: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5474: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5475: }
5476: $datatable .= '</span></fieldset>'.
1.267 raeburn 5477: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5478: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5479: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5480: my %custom = %{$settings->{$item}->{'custom'}};
5481: if (keys(%custom) > 0) {
5482: foreach my $key (sort(keys(%custom))) {
5483: $datatable .= '<tr><td><span class="LC_nobreak">'.
5484: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5485: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5486: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5487: ' value="'.$custom{$key}.'" /></td></tr>';
5488: }
5489: }
5490: }
5491: $datatable .= '<tr><td><span class="LC_nobreak">'.
5492: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5493: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5494: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5495: $datatable .= '</table></fieldset></td></tr>'."\n";
5496: $itemcount ++;
5497: }
5498: }
5499: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5500: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5501: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5502: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5503: '<select name="ltitools_add_pos"'.$chgstr.'>';
5504: for (my $k=0; $k<$maxnum+1; $k++) {
5505: my $vpos = $k+1;
5506: my $selstr;
5507: if ($k == $maxnum) {
5508: $selstr = ' selected="selected" ';
5509: }
5510: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5511: }
5512: $datatable .= '</select> '."\n".
1.334 raeburn 5513: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5514: '<td colspan="2">'.
5515: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5516: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5517: (' 'x2).
5518: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5519: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5520: (' 'x2).
5521: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5522: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5523: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5524: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5525: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5526: '<br />'.
1.323 raeburn 5527: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5528: (' 'x2).
5529: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5530: (' 'x2).
1.322 raeburn 5531: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5532: (' 'x2).
1.267 raeburn 5533: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5534: '<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".
5535: '</fieldset>'.
5536: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5537: '<span class="LC_nobreak">'.&mt('Display target:');
5538: my %defaultdisp;
5539: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5540: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5541: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5542: $lt{$disp}.'</label>'.(' 'x2);
5543: }
5544: $datatable .= (' 'x4);
5545: foreach my $dimen ('width','height') {
5546: $datatable .= '<label>'.$lt{$dimen}.' '.
5547: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5548: (' 'x2);
5549: }
1.334 raeburn 5550: $datatable .= '</span><br />'.
1.296 raeburn 5551: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5552: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5553: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5554: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5555: '</div><div style=""></div><br />';
1.319 raeburn 5556: my %units = (
5557: 'passback' => 'days',
5558: 'roster' => 'seconds',
5559: );
5560: my %defaulttimes = (
5561: 'passback' => '7',
1.322 raeburn 5562: 'roster' => '300',
1.319 raeburn 5563: );
1.267 raeburn 5564: foreach my $extra ('passback','roster') {
1.319 raeburn 5565: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5566: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5567: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5568: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5569: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5570: &mt('Yes').'</label></span></div>'.
5571: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5572: '<span class="LC_nobreak">'.
5573: &mt("at least [_1] $units{$extra} after launch",
5574: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5575: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5576: }
1.319 raeburn 5577: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5578: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5579: if ($switchserver) {
5580: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5581: } else {
5582: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5583: }
5584: $datatable .= '</span></fieldset>'.
5585: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5586: '<span class="LC_nobreak">';
5587: foreach my $field (@fields) {
1.324 raeburn 5588: my ($id,$onclick,$spacer);
5589: if ($field eq 'user') {
5590: $id = ' id="ltitools_user_field_add"';
5591: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5592: } else {
5593: $spacer = (' ' x2);
5594: }
1.267 raeburn 5595: $datatable .= '<label>'.
1.324 raeburn 5596: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5597: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5598: }
1.324 raeburn 5599: $datatable .= '</span>'.
5600: '<div style="display:none;" id="ltitools_user_div_add">'.
5601: '<span class="LC_nobreak"> : '.
5602: '<select name="ltitools_userincdom_add">'.
5603: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5604: '<option value="0">'.&mt('username').'</option>'.
5605: '<option value="1">'.&mt('username:domain').'</option>'.
5606: '</select></span></div></fieldset>';
5607: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5608: foreach my $role (@courseroles) {
5609: my ($checked,$checkednone);
1.306 raeburn 5610: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5611: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5612: '<select name="ltitools_add_roles_'.$role.'">'.
5613: '<option value="" selected="selected">'.&mt('Select').'</option>';
5614: foreach my $ltirole (@ltiroles) {
5615: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5616: }
5617: $datatable .= '</select></td>';
5618: }
5619: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5620: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5621: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5622: $datatable .= '<label>'.
5623: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5624: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5625: }
5626: $datatable .= '</span></fieldset>'.
1.267 raeburn 5627: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5628: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5629: '<tr><td><span class="LC_nobreak">'.
5630: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5631: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5632: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5633: '</table></fieldset>'."\n".
1.267 raeburn 5634: '</td>'."\n".
5635: '</tr>'."\n";
5636: $itemcount ++;
5637: return $datatable;
5638: }
5639:
5640: sub ltitools_names {
5641: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5642: 'title' => 'Title',
5643: 'version' => 'Version',
5644: 'msgtype' => 'Message Type',
1.323 raeburn 5645: 'sigmethod' => 'Signature Method',
1.296 raeburn 5646: 'url' => 'URL',
5647: 'key' => 'Key',
1.322 raeburn 5648: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5649: 'secret' => 'Secret',
5650: 'icon' => 'Icon',
1.324 raeburn 5651: 'user' => 'User',
1.296 raeburn 5652: 'fullname' => 'Full Name',
5653: 'firstname' => 'First Name',
5654: 'lastname' => 'Last Name',
5655: 'email' => 'E-mail',
5656: 'roles' => 'Role',
1.298 raeburn 5657: 'window' => 'Window',
5658: 'tab' => 'Tab',
1.296 raeburn 5659: 'iframe' => 'iFrame',
5660: 'height' => 'Height',
5661: 'width' => 'Width',
5662: 'linktext' => 'Default Link Text',
5663: 'explanation' => 'Default Explanation',
5664: 'passback' => 'Tool can return grades:',
5665: 'roster' => 'Tool can retrieve roster:',
5666: 'crstarget' => 'Display target',
5667: 'crslabel' => 'Course label',
5668: 'crstitle' => 'Course title',
5669: 'crslinktext' => 'Link Text',
5670: 'crsexplanation' => 'Explanation',
1.318 raeburn 5671: 'crsappend' => 'Provider URL',
1.267 raeburn 5672: );
5673: return %lt;
5674: }
5675:
1.372 raeburn 5676: sub print_proctoring {
5677: my ($dom,$settings,$rowtotal) = @_;
5678: my $itemcount = 1;
5679: my (%ordered,%providernames,%current,%currentdef);
5680: my $confname = $dom.'-domainconfig';
5681: my $switchserver = &check_switchserver($dom,$confname);
5682: if (ref($settings) eq 'HASH') {
5683: foreach my $item (keys(%{$settings})) {
5684: if (ref($settings->{$item}) eq 'HASH') {
5685: my $num = $settings->{$item}{'order'};
5686: $ordered{$num} = $item;
5687: }
5688: }
5689: } else {
5690: %ordered = (
5691: 1 => 'proctorio',
5692: 2 => 'examity',
5693: );
5694: }
5695: %providernames = &proctoring_providernames();
5696: my $maxnum = scalar(keys(%ordered));
5697: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5698: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5699: if (ref($requref) eq 'HASH') {
5700: %requserfields = %{$requref};
5701: }
5702: if (ref($opturef) eq 'HASH') {
5703: %optuserfields = %{$opturef};
5704: }
5705: if (ref($defref) eq 'HASH') {
5706: %defaults = %{$defref};
5707: }
5708: if (ref($extref) eq 'HASH') {
5709: %extended = %{$extref};
5710: }
5711: if (ref($crsref) eq 'HASH') {
5712: %crsconf = %{$crsref};
5713: }
5714: if (ref($rolesref) eq 'ARRAY') {
5715: @courseroles = @{$rolesref};
5716: }
5717: if (ref($ltiref) eq 'ARRAY') {
5718: @ltiroles = @{$ltiref};
5719: }
5720: my $datatable;
5721: my $css_class;
5722: if (keys(%ordered)) {
5723: my @items = sort { $a <=> $b } keys(%ordered);
5724: for (my $i=0; $i<@items; $i++) {
5725: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5726: my $provider = $ordered{$items[$i]};
5727: my $optionsty = 'none';
5728: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5729: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5730: if (ref($settings) eq 'HASH') {
5731: if (ref($settings->{$provider}) eq 'HASH') {
5732: %current = %{$settings->{$provider}};
5733: if ($current{'available'}) {
5734: $optionsty = 'block';
5735: $available = 1;
5736: }
5737: if ($current{'lifetime'} =~ /^\d+$/) {
5738: $lifetime = $current{'lifetime'};
5739: }
5740: if ($current{'version'} =~ /^\d+\.\d+$/) {
5741: $version = $current{'version'};
5742: }
5743: if ($current{'image'} ne '') {
5744: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5745: }
5746: if (ref($current{'fields'}) eq 'ARRAY') {
5747: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5748: }
5749: $userincdom = $current{'incdom'};
5750: if (ref($current{'roles'}) eq 'HASH') {
5751: %rolemaps = %{$current{'roles'}};
5752: $checkedfields{'roles'} = 1;
5753: }
5754: if (ref($current{'defaults'}) eq 'ARRAY') {
5755: foreach my $val (@{$current{'defaults'}}) {
5756: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5757: $inuse{$val} = 1;
5758: } else {
5759: foreach my $poss (keys(%{$extended{$provider}})) {
5760: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5761: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5762: $inuse{$poss} = $val;
5763: last;
5764: }
5765: }
5766: }
5767: }
5768: }
5769: } elsif (ref($current{'defaults'}) eq 'HASH') {
5770: foreach my $key (keys(%{$current{'defaults'}})) {
5771: my $currval = $current{'defaults'}{$key};
5772: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5773: $inuse{$key} = 1;
5774: } else {
5775: my $match;
5776: foreach my $poss (keys(%{$extended{$provider}})) {
5777: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5778: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5779: $inuse{$poss} = $key;
5780: last;
5781: }
5782: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5783: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5784: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5785: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5786: $currentdef{$inner} = $currval;
5787: $match = 1;
5788: last;
5789: }
5790: } elsif ($inner eq $key) {
5791: $currentdef{$key} = $currval;
5792: $match = 1;
5793: last;
5794: }
5795: }
5796: }
5797: last if ($match);
5798: }
5799: }
5800: }
5801: }
5802: if (ref($current{'crsconf'}) eq 'ARRAY') {
5803: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5804: }
5805: }
5806: }
5807: my %lt = &proctoring_titles($provider);
5808: my %fieldtitles = &proctoring_fieldtitles($provider);
5809: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5810: my %checkedavailable = (
5811: yes => '',
5812: no => ' checked="checked"',
5813: );
5814: if ($available) {
5815: $checkedavailable{'yes'} = $checkedavailable{'no'};
5816: $checkedavailable{'no'} = '';
5817: }
5818: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5819: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5820: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5821: for (my $k=0; $k<$maxnum; $k++) {
5822: my $vpos = $k+1;
5823: my $selstr;
5824: if ($k == $i) {
5825: $selstr = ' selected="selected" ';
5826: }
5827: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5828: }
5829: if ($version eq '') {
5830: if ($provider eq 'proctorio') {
5831: $version = '1.0';
5832: } elsif ($provider eq 'examity') {
5833: $version = '1.1';
5834: }
5835: }
5836: if ($lifetime eq '') {
5837: $lifetime = '300';
5838: }
5839: $datatable .=
5840: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5841: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5842: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5843: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5844: '</td>'.
5845: '<td colspan="2">'.
5846: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5847: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5848: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5849: (' 'x2).
5850: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5851: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5852: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5853: (' 'x2).
5854: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5855: '<br />'.
5856: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5857: '<br />'.
5858: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5859: (' 'x2).
5860: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5861: '<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";
5862: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5863: if ($imgsrc) {
5864: $datatable .= $imgsrc.
5865: '<label><input type="checkbox" name="proctoring_image_del"'.
5866: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5867: '<span class="LC_nobreak"> '.&mt('Replace:');
5868: }
5869: $datatable .= ' ';
5870: if ($switchserver) {
5871: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5872: } else {
5873: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5874: }
5875: unless ($imgsrc) {
5876: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5877: }
5878: $datatable .= '</fieldset>'."\n";
5879: if (ref($requserfields{$provider}) eq 'ARRAY') {
5880: if (@{$requserfields{$provider}} > 0) {
5881: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5882: foreach my $field (@{$requserfields{$provider}}) {
5883: $datatable .= '<span class="LC_nobreak">'.
5884: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5885: $lt{$field}.'</label>';
5886: if ($field eq 'user') {
5887: my $seluserdom = '';
5888: my $unseluserdom = ' selected="selected"';
5889: if ($userincdom) {
5890: $seluserdom = $unseluserdom;
5891: $unseluserdom = '';
5892: }
5893: $datatable .= ': '.
5894: '<select name="proctoring_userincdom_'.$provider.'">'.
5895: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5896: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5897: '</select> ';
5898: } else {
5899: $datatable .= ' ';
5900: if ($field eq 'roles') {
5901: $showroles = 1;
5902: }
5903: }
5904: $datatable .= '</span> ';
5905: }
5906: }
5907: $datatable .= '</fieldset>'."\n";
5908: }
5909: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5910: if (@{$optuserfields{$provider}} > 0) {
5911: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5912: foreach my $field (@{$optuserfields{$provider}}) {
5913: my $checked;
5914: if ($checkedfields{$field}) {
5915: $checked = ' checked="checked"';
5916: }
5917: $datatable .= '<span class="LC_nobreak">'.
5918: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5919: }
5920: $datatable .= '</fieldset>'."\n";
5921: }
5922: }
5923: if (ref($defaults{$provider}) eq 'ARRAY') {
5924: if (@{$defaults{$provider}}) {
5925: my (%options,@selectboxes);
5926: if (ref($extended{$provider}) eq 'HASH') {
5927: %options = %{$extended{$provider}};
5928: }
5929: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5930: my ($rem,$numinrow,$dropdowns);
5931: if ($provider eq 'proctorio') {
5932: $datatable .= '<table>';
5933: $numinrow = 4;
5934: }
5935: my $i = 0;
5936: foreach my $field (@{$defaults{$provider}}) {
5937: my $checked;
5938: if ($inuse{$field}) {
5939: $checked = ' checked="checked"';
5940: }
5941: if ($provider eq 'examity') {
5942: if ($field eq 'display') {
5943: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5944: foreach my $option ('iframe','tab','window') {
5945: my $checkdisp;
5946: if ($currentdef{'target'} eq $option) {
5947: $checkdisp = ' checked="checked"';
5948: }
5949: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5950: $fieldtitles{$option}.'</label>'.(' 'x2);
5951: }
5952: $datatable .= (' 'x4);
5953: foreach my $dimen ('width','height') {
5954: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5955: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5956: 'value="'.$currentdef{$dimen}.'" /></label>'.
5957: (' 'x2);
5958: }
5959: $datatable .= '</span><br />'.
5960: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5961: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5962: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5963: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5964: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5965: $currentdef{'explanation'}.
5966: '</textarea></div><div style=""></div><br />';
5967: }
5968: } else {
5969: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5970: my ($output,$selnone);
5971: unless ($checked) {
5972: $selnone = ' selected="selected"';
5973: }
5974: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5975: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5976: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5977: foreach my $option (@{$options{$field}}) {
5978: my $sel;
5979: if ($inuse{$field} eq $option) {
5980: $sel = ' selected="selected"';
5981: }
5982: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5983: }
5984: $output .= '</select></span>';
5985: push(@selectboxes,$output);
5986: } else {
5987: $rem = $i%($numinrow);
5988: if ($rem == 0) {
5989: if ($i > 0) {
5990: $datatable .= '</tr>';
5991: }
5992: $datatable .= '<tr>';
5993: }
5994: $datatable .= '<td class="LC_left_item">'.
5995: '<span class="LC_nobreak">'.
5996: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5997: $fieldtitles{$field}.'</label></span></td>';
5998: $i++;
5999: }
6000: }
6001: }
6002: if ($provider eq 'proctorio') {
6003: if ($numinrow) {
6004: $rem = $i%$numinrow;
6005: }
6006: my $colsleft = $numinrow - $rem;
6007: if ($colsleft > 1) {
6008: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6009: } else {
6010: $datatable .= '<td class="LC_left_item">';
6011: }
6012: $datatable .= ' '.
6013: '</td></tr></table>';
6014: if (@selectboxes) {
6015: $datatable .= '<hr /><table>';
6016: $numinrow = 2;
6017: for (my $i=0; $i<@selectboxes; $i++) {
6018: $rem = $i%($numinrow);
6019: if ($rem == 0) {
6020: if ($i > 0) {
6021: $datatable .= '</tr>';
6022: }
6023: $datatable .= '<tr>';
6024: }
6025: $datatable .= '<td class="LC_left_item">'.
6026: $selectboxes[$i].'</td>';
6027: }
6028: if ($numinrow) {
6029: $rem = $i%$numinrow;
6030: }
6031: $colsleft = $numinrow - $rem;
6032: if ($colsleft > 1) {
6033: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6034: } else {
6035: $datatable .= '<td class="LC_left_item">';
6036: }
6037: $datatable .= ' '.
6038: '</td></tr></table>';
6039: }
6040: }
6041: $datatable .= '</fieldset>';
6042: }
6043: if (ref($crsconf{$provider}) eq 'ARRAY') {
6044: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6045: '<legend>'.&mt('Configurable in course').'</legend>';
6046: my ($rem,$numinrow);
6047: if ($provider eq 'proctorio') {
6048: $datatable .= '<table>';
6049: $numinrow = 4;
6050: }
6051: my $i = 0;
6052: foreach my $item (@{$crsconf{$provider}}) {
6053: my $name;
6054: if ($provider eq 'examity') {
6055: $name = $lt{'crs'.$item};
6056: } elsif ($provider eq 'proctorio') {
6057: $name = $fieldtitles{$item};
6058: $rem = $i%($numinrow);
6059: if ($rem == 0) {
6060: if ($i > 0) {
6061: $datatable .= '</tr>';
6062: }
6063: $datatable .= '<tr>';
6064: }
6065: $datatable .= '<td class="LC_left_item>';
6066: }
6067: my $checked;
6068: if ($crsconfig{$item}) {
6069: $checked = ' checked="checked"';
6070: }
6071: $datatable .= '<span class="LC_nobreak"><label>'.
6072: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
6073: $name.'</label></span>';
6074: if ($provider eq 'examity') {
6075: $datatable .= ' ';
6076: }
6077: $datatable .= "\n";
6078: $i++;
6079: }
6080: if ($provider eq 'proctorio') {
6081: if ($numinrow) {
6082: $rem = $i%$numinrow;
6083: }
6084: my $colsleft = $numinrow - $rem;
6085: if ($colsleft > 1) {
6086: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6087: } else {
6088: $datatable .= '<td class="LC_left_item">';
6089: }
6090: $datatable .= ' '.
6091: '</td></tr></table>';
6092: }
6093: $datatable .= '</fieldset>';
6094: }
6095: if ($showroles) {
6096: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6097: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
6098: foreach my $role (@courseroles) {
6099: my ($selected,$selectnone);
6100: if (!$rolemaps{$role}) {
6101: $selectnone = ' selected="selected"';
6102: }
6103: $datatable .= '<td style="text-align: center">'.
6104: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6105: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
6106: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6107: foreach my $ltirole (@ltiroles) {
6108: unless ($selectnone) {
6109: if ($rolemaps{$role} eq $ltirole) {
6110: $selected = ' selected="selected"';
6111: } else {
6112: $selected = '';
6113: }
6114: }
6115: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6116: }
6117: $datatable .= '</select></td>';
6118: }
6119: $datatable .= '</tr></table></fieldset>'.
6120: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6121: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6122: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6123: '<tr><td></td><td>lms</td>'.
6124: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6125: ' value="Loncapa" disabled="disabled"/></td></tr>';
6126: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6127: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6128: my %custom = %{$settings->{$provider}->{'custom'}};
6129: if (keys(%custom) > 0) {
6130: foreach my $key (sort(keys(%custom))) {
6131: next if ($key eq 'lms');
6132: $datatable .= '<tr><td><span class="LC_nobreak">'.
6133: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6134: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6135: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6136: ' value="'.$custom{$key}.'" /></td></tr>';
6137: }
6138: }
6139: }
6140: $datatable .= '<tr><td><span class="LC_nobreak">'.
6141: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6142: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6143: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6144: '</table></fieldset></td></tr>'."\n";
6145: }
6146: $datatable .= '</td></tr>';
6147: }
6148: $itemcount ++;
6149: }
6150: }
6151: return $datatable;
6152: }
6153:
6154: sub proctoring_data {
6155: my $requserfields = {
6156: proctorio => ['user'],
6157: examity => ['roles','user'],
6158: };
6159: my $optuserfields = {
6160: proctorio => ['fullname'],
6161: examity => ['fullname','firstname','lastname','email'],
6162: };
6163: my $defaults = {
6164: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6165: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6166: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6167: 'closetabs','onescreen','print','downloads','cache','rightclick',
6168: 'reentry','calculator','whiteboard'],
6169: examity => ['display'],
6170: };
6171: my $extended = {
6172: proctorio => {
6173: verifyid => ['verifyidauto','verifyidlive'],
6174: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6175: tabslinks => ['notabs','linksonly'],
6176: reentry => ['noreentry','agentreentry'],
6177: calculator => ['calculatorbasic','calculatorsci'],
6178: },
6179: examity => {
6180: display => {
6181: target => ['iframe','tab','window'],
6182: width => '',
6183: height => '',
6184: linktext => '',
6185: explanation => '',
6186: },
6187: },
6188: };
6189: my $crsconf = {
6190: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6191: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6192: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6193: 'closetabs','onescreen','print','downloads','cache','rightclick',
6194: 'reentry','calculator','whiteboard'],
6195: examity => ['label','title','target','linktext','explanation','append'],
6196: };
6197: my $courseroles = ['cc','in','ta','ep','st'];
6198: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6199: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6200: }
6201:
6202: sub proctoring_titles {
6203: my ($item) = @_;
6204: my (%common_lt,%custom_lt);
6205: %common_lt = &Apache::lonlocal::texthash (
6206: 'avai' => 'Available?',
6207: 'base' => 'Basic Settings',
6208: 'requ' => 'User data required to be sent on launch',
6209: 'optu' => 'User data optionally sent on launch',
6210: 'udsl' => 'User data sent on launch',
6211: 'defa' => 'Defaults for items configurable in course',
6212: 'sigmethod' => 'Signature Method',
6213: 'key' => 'Key',
6214: 'lifetime' => 'Nonce lifetime (s)',
6215: 'secret' => 'Secret',
6216: 'icon' => 'Icon',
6217: 'fullname' => 'Full Name',
6218: 'visible' => 'Visible input',
6219: 'username' => 'username',
6220: 'user' => 'User',
6221: );
6222: if ($item eq 'proctorio') {
6223: %custom_lt = &Apache::lonlocal::texthash (
6224: 'version' => 'OAuth version',
6225: 'url' => 'API URL',
6226: 'uname:dom' => 'username-domain',
6227: );
6228: } elsif ($item eq 'examity') {
6229: %custom_lt = &Apache::lonlocal::texthash (
6230: 'version' => 'LTI Version',
6231: 'url' => 'URL',
6232: 'uname:dom' => 'username:domain',
6233: 'msgtype' => 'Message Type',
6234: 'firstname' => 'First Name',
6235: 'lastname' => 'Last Name',
6236: 'email' => 'E-mail',
6237: 'roles' => 'Role',
6238: 'crstarget' => 'Display target',
6239: 'crslabel' => 'Course label',
6240: 'crstitle' => 'Course title',
6241: 'crslinktext' => 'Link Text',
6242: 'crsexplanation' => 'Explanation',
6243: 'crsappend' => 'Provider URL',
6244: );
6245: }
6246: my %lt = (%common_lt,%custom_lt);
6247: return %lt;
6248: }
6249:
6250: sub proctoring_fieldtitles {
6251: my ($item) = @_;
6252: if ($item eq 'proctorio') {
6253: return &Apache::lonlocal::texthash (
6254: 'recordvideo' => 'Record video',
6255: 'recordaudio' => 'Record audio',
6256: 'recordscreen' => 'Record screen',
6257: 'recordwebtraffic' => 'Record web traffic',
6258: 'recordroomstart' => 'Record room scan',
6259: 'verifyvideo' => 'Verify webcam',
6260: 'verifyaudio' => 'Verify microphone',
6261: 'verifydesktop' => 'Verify desktop recording',
6262: 'verifyid' => 'Photo ID verification',
6263: 'verifysignature' => 'Require signature',
6264: 'fullscreen' => 'Fullscreen',
6265: 'clipboard' => 'Disable copy/paste',
6266: 'tabslinks' => 'New tabs/windows',
6267: 'closetabs' => 'Close other tabs',
6268: 'onescreen' => 'Limit to single screen',
6269: 'print' => 'Disable Printing',
6270: 'downloads' => 'Disable Downloads',
6271: 'cache' => 'Empty cache after exam',
6272: 'rightclick' => 'Disable right click',
6273: 'reentry' => 'Re-entry to exam',
6274: 'calculator' => 'Onscreen calculator',
6275: 'whiteboard' => 'Onscreen whiteboard',
6276: 'verifyidauto' => 'Automated verification',
6277: 'verifyidlive' => 'Live agent verification',
6278: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6279: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6280: 'fullscreensever' => 'Forced, navigation away ends exam',
6281: 'notabs' => 'Disaallowed',
6282: 'linksonly' => 'Allowed from links in exam',
6283: 'noreentry' => 'Disallowed',
6284: 'agentreentry' => 'Agent required for re-entry',
6285: 'calculatorbasic' => 'Basic',
6286: 'calculatorsci' => 'Scientific',
6287: );
6288: } elsif ($item eq 'examity') {
6289: return &Apache::lonlocal::texthash (
6290: 'target' => 'Display target',
6291: 'window' => 'Window',
6292: 'tab' => 'Tab',
6293: 'iframe' => 'iFrame',
6294: 'height' => 'Height (pixels)',
6295: 'width' => 'Width (pixels)',
6296: 'linktext' => 'Default Link Text',
6297: 'explanation' => 'Default Explanation',
6298: 'append' => 'Provider URL',
6299: );
6300: }
6301: }
6302:
6303: sub proctoring_providernames {
6304: return (
6305: proctorio => 'Proctorio',
6306: examity => 'Examity',
6307: );
6308: }
6309:
1.320 raeburn 6310: sub print_lti {
6311: my ($dom,$settings,$rowtotal) = @_;
6312: my $itemcount = 1;
6313: my $maxnum = 0;
6314: my $css_class;
6315: my %ordered;
6316: if (ref($settings) eq 'HASH') {
6317: foreach my $item (keys(%{$settings})) {
6318: if (ref($settings->{$item}) eq 'HASH') {
6319: my $num = $settings->{$item}{'order'};
1.390 raeburn 6320: if ($num eq '') {
6321: $num = scalar(keys(%{$settings}));
6322: }
1.320 raeburn 6323: $ordered{$num} = $item;
6324: }
6325: }
6326: }
6327: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 6328: my $datatable;
1.320 raeburn 6329: my %lt = <i_names();
6330: if (keys(%ordered)) {
6331: my @items = sort { $a <=> $b } keys(%ordered);
6332: for (my $i=0; $i<@items; $i++) {
6333: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6334: my $item = $ordered{$items[$i]};
1.391 raeburn 6335: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320 raeburn 6336: if (ref($settings->{$item}) eq 'HASH') {
6337: $key = $settings->{$item}->{'key'};
6338: $secret = $settings->{$item}->{'secret'};
6339: $lifetime = $settings->{$item}->{'lifetime'};
6340: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 6341: $requser = $settings->{$item}->{'requser'};
1.391 raeburn 6342: $crsinc = $settings->{$item}->{'crsinc'};
1.320 raeburn 6343: $current = $settings->{$item};
6344: }
1.345 raeburn 6345: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6346: my %checkedrequser = (
6347: yes => ' checked="checked"',
6348: no => '',
6349: );
6350: if (!$requser) {
6351: $checkedrequser{'no'} = $checkedrequser{'yes'};
6352: $checkedrequser{'yes'} = '';
1.352 raeburn 6353: }
1.391 raeburn 6354: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6355: my %checkedcrsinc = (
6356: yes => ' checked="checked"',
6357: no => '',
6358: );
6359: if (!$crsinc) {
6360: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6361: $checkedcrsinc{'yes'} = '';
6362: }
1.320 raeburn 6363: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6364: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6365: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6366: for (my $k=0; $k<=$maxnum; $k++) {
6367: my $vpos = $k+1;
6368: my $selstr;
6369: if ($k == $i) {
6370: $selstr = ' selected="selected" ';
6371: }
6372: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6373: }
6374: $datatable .= '</select>'.(' 'x2).
6375: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6376: &mt('Delete?').'</label></span></td>'.
6377: '<td colspan="2">'.
6378: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6379: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6380: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 6381: (' 'x2).
6382: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6383: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6384: (' 'x2).
6385: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 6386: 'value="'.$lifetime.'" size="3" /></span>'.
6387: (' 'x2).
6388: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6389: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6390: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6391: '<br /><br />'.
1.391 raeburn 6392: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6393: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6394: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6395: (' 'x4).
1.320 raeburn 6396: '<span class="LC_nobreak">'.$lt{'key'}.
6397: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6398: (' 'x2).
6399: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6400: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6401: '<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>'.
6402: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6403: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6404: $itemcount ++;
6405: }
6406: }
6407: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6408: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6409: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6410: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6411: '<select name="lti_pos_add"'.$chgstr.'>';
6412: for (my $k=0; $k<$maxnum+1; $k++) {
6413: my $vpos = $k+1;
6414: my $selstr;
6415: if ($k == $maxnum) {
6416: $selstr = ' selected="selected" ';
6417: }
6418: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6419: }
6420: $datatable .= '</select> '."\n".
1.334 raeburn 6421: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6422: '<td colspan="2">'.
6423: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6424: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6425: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6426: (' 'x2).
6427: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6428: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6429: (' 'x2).
1.345 raeburn 6430: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6431: (' 'x2).
6432: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6433: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6434: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6435: '<br /><br />'.
1.391 raeburn 6436: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6437: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6438: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6439: (' 'x4).
1.320 raeburn 6440: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6441: (' 'x2).
6442: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6443: '<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 6444: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6445: '</td>'."\n".
6446: '</tr>'."\n";
6447: $$rowtotal ++;
6448: return $datatable;;
6449: }
6450:
6451: sub lti_names {
6452: my %lt = &Apache::lonlocal::texthash(
6453: 'version' => 'LTI Version',
6454: 'url' => 'URL',
6455: 'key' => 'Key',
1.322 raeburn 6456: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6457: 'consumer' => 'Consumer',
1.320 raeburn 6458: 'secret' => 'Secret',
1.345 raeburn 6459: 'requser' => "User's identity sent",
1.391 raeburn 6460: 'crsinc' => "Course's identity sent",
1.320 raeburn 6461: 'email' => 'Email address',
6462: 'sourcedid' => 'User ID',
6463: 'other' => 'Other',
6464: 'passback' => 'Can return grades to Consumer:',
6465: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6466: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6467: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6468: );
6469: return %lt;
6470: }
6471:
6472: sub lti_options {
1.325 raeburn 6473: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6474: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6475: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6476: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6477: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6478: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6479: $checked{'mapcrstype'} = {};
6480: $checked{'makeuser'} = {};
6481: $checked{'selfenroll'} = {};
6482: $checked{'crssec'} = {};
6483: $checked{'crssecsrc'} = {};
1.325 raeburn 6484: $checked{'lcauth'} = {};
1.326 raeburn 6485: $checked{'menuitem'} = {};
1.325 raeburn 6486: if ($num eq 'add') {
6487: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6488: }
1.320 raeburn 6489: my $userfieldsty = 'none';
6490: my $crsfieldsty = 'none';
6491: my $crssecfieldsty = 'none';
6492: my $secsrcfieldsty = 'none';
1.363 raeburn 6493: my $callbacksty = 'none';
1.337 raeburn 6494: my $passbacksty = 'none';
1.345 raeburn 6495: my $optionsty = 'block';
1.391 raeburn 6496: my $crssty = 'block';
1.325 raeburn 6497: my $lcauthparm;
6498: my $lcauthparmstyle = 'display:none';
6499: my $lcauthparmtext;
1.326 raeburn 6500: my $menusty;
1.325 raeburn 6501: my $numinrow = 4;
1.326 raeburn 6502: my %menutitles = <imenu_titles();
1.320 raeburn 6503:
6504: if (ref($current) eq 'HASH') {
1.345 raeburn 6505: if (!$current->{'requser'}) {
6506: $optionsty = 'none';
1.391 raeburn 6507: $crssty = 'none';
6508: } elsif (!$current->{'crsinc'}) {
6509: $crssty = 'none';
1.345 raeburn 6510: }
1.320 raeburn 6511: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6512: $checked{'mapuser'}{'sourcedid'} = '';
6513: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6514: $checked{'mapuser'}{'email'} = ' checked="checked"';
6515: } else {
6516: $checked{'mapuser'}{'other'} = ' checked="checked"';
6517: $userfield = $current->{'mapuser'};
6518: $userfieldsty = 'inline-block';
6519: }
6520: }
6521: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6522: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6523: if ($current->{'mapcrs'} eq 'context_id') {
6524: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6525: } else {
6526: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6527: $cidfield = $current->{'mapcrs'};
6528: $crsfieldsty = 'inline-block';
6529: }
6530: }
6531: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6532: foreach my $type (@{$current->{'mapcrstype'}}) {
6533: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6534: }
6535: }
1.392 raeburn 6536: if (!$current->{'storecrs'}) {
6537: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6538: $checked{'storecrs'}{'Y'} = '';
6539: }
1.345 raeburn 6540: if ($current->{'makecrs'}) {
1.320 raeburn 6541: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6542: }
1.320 raeburn 6543: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6544: foreach my $role (@{$current->{'makeuser'}}) {
6545: $checked{'makeuser'}{$role} = ' checked="checked"';
6546: }
6547: }
1.325 raeburn 6548: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6549: $checked{'lcauth'}{$1} = ' checked="checked"';
6550: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6551: $lcauthparm = $current->{'lcauthparm'};
6552: $lcauthparmstyle = 'display:table-row';
6553: if ($current->{'lcauth'} eq 'localauth') {
6554: $lcauthparmtext = &mt('Local auth argument');
6555: } else {
6556: $lcauthparmtext = &mt('Kerberos domain');
6557: }
6558: }
6559: }
1.320 raeburn 6560: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6561: foreach my $role (@{$current->{'selfenroll'}}) {
6562: $checked{'selfenroll'}{$role} = ' checked="checked"';
6563: }
6564: }
6565: if (ref($current->{'maproles'}) eq 'HASH') {
6566: %rolemaps = %{$current->{'maproles'}};
6567: }
6568: if ($current->{'section'} ne '') {
6569: $checked{'crssec'}{'Y'} = ' checked="checked"';
6570: $crssecfieldsty = 'inline-block';
6571: if ($current->{'section'} eq 'course_section_sourcedid') {
6572: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6573: } else {
6574: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6575: $crssecsrc = $current->{'section'};
6576: $secsrcfieldsty = 'inline-block';
6577: }
6578: } else {
6579: $checked{'crssec'}{'N'} = ' checked="checked"';
6580: }
1.363 raeburn 6581: if ($current->{'callback'} ne '') {
6582: $callback = $current->{'callback'};
6583: $checked{'callback'}{'Y'} = ' checked="checked"';
6584: $callbacksty = 'inline-block';
6585: } else {
6586: $checked{'callback'}{'N'} = ' checked="checked"';
6587: }
1.326 raeburn 6588: if ($current->{'topmenu'}) {
6589: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6590: } else {
6591: $checked{'topmenu'}{'N'} = ' checked="checked"';
6592: }
6593: if ($current->{'inlinemenu'}) {
6594: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6595: } else {
6596: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6597: }
6598: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6599: $menusty = 'inline-block';
6600: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6601: foreach my $item (@{$current->{'lcmenu'}}) {
6602: if (exists($menutitles{$item})) {
6603: $checked{'menuitem'}{$item} = ' checked="checked"';
6604: }
6605: }
6606: }
6607: } else {
6608: $menusty = 'none';
6609: }
1.320 raeburn 6610: } else {
6611: $checked{'makecrs'}{'N'} = ' checked="checked"';
6612: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6613: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6614: $checked{'topmenu'}{'N'} = ' checked="checked"';
6615: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6616: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6617: $menusty = 'inline-block';
1.320 raeburn 6618: }
1.325 raeburn 6619: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6620: my %coursetypetitles = &Apache::lonlocal::texthash (
6621: official => 'Official',
6622: unofficial => 'Unofficial',
6623: community => 'Community',
6624: textbook => 'Textbook',
6625: placement => 'Placement Test',
1.325 raeburn 6626: lti => 'LTI Provider',
1.320 raeburn 6627: );
1.325 raeburn 6628: my @authtypes = ('internal','krb4','krb5','localauth');
6629: my %shortauth = (
6630: internal => 'int',
6631: krb4 => 'krb4',
6632: krb5 => 'krb5',
6633: localauth => 'loc'
6634: );
6635: my %authnames = &authtype_names();
1.320 raeburn 6636: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6637: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6638: my @courseroles = ('cc','in','ta','ep','st');
6639: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6640: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6641: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6642: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6643: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6644: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6645: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6646: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6647: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6648: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6649: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6650: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6651: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6652: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6653: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6654: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6655: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6656: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6657: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6658: foreach my $option ('sourcedid','email','other') {
6659: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6660: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6661: ($option eq 'other' ? '' : (' 'x2) );
6662: }
6663: $output .= '</span></div>'.
6664: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6665: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6666: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6667: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6668: foreach my $ltirole (@ltiroles) {
6669: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6670: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6671: }
6672: $output .= '</fieldset>'.
1.391 raeburn 6673: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6674: '<table>'.
6675: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6676: '</table>'.
6677: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6678: '<td class="LC_left_item">';
6679: foreach my $auth ('lti',@authtypes) {
6680: my $authtext;
6681: if ($auth eq 'lti') {
6682: $authtext = &mt('None');
6683: } else {
6684: $authtext = $authnames{$shortauth{$auth}};
6685: }
6686: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6687: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6688: $authtext.'</label></span> ';
6689: }
6690: $output .= '</td></tr>'.
6691: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6692: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6693: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6694: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6695: '</table></fieldset>'.
1.391 raeburn 6696: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6697: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6698: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6699: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6700: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6701: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6702: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6703: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6704: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6705: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6706: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6707: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6708: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6709: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6710: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6711: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6712: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6713: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6714: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6715: (' 'x2);
6716: }
6717: $output .= '</span></div></fieldset>'.
6718: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6719: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6720: &mt('Unique course identifier').': ';
6721: foreach my $option ('course_offering_sourcedid','context_id','other') {
6722: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6723: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6724: ($option eq 'other' ? '' : (' 'x2) );
6725: }
1.334 raeburn 6726: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6727: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6728: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6729: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6730: foreach my $type (@coursetypes) {
6731: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6732: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6733: (' 'x2);
6734: }
1.392 raeburn 6735: $output .= '</span><br /><br />'.
6736: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6737: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6738: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6739: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6740: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6741: '</fieldset>'.
1.391 raeburn 6742: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6743: foreach my $ltirole (@lticourseroles) {
6744: my ($selected,$selectnone);
6745: if ($rolemaps{$ltirole} eq '') {
6746: $selectnone = ' selected="selected"';
6747: }
6748: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6749: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6750: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6751: foreach my $role (@courseroles) {
6752: unless ($selectnone) {
6753: if ($rolemaps{$ltirole} eq $role) {
6754: $selected = ' selected="selected"';
6755: } else {
6756: $selected = '';
6757: }
6758: }
6759: $output .= '<option value="'.$role.'"'.$selected.'>'.
6760: &Apache::lonnet::plaintext($role,'Course').
6761: '</option>';
6762: }
6763: $output .= '</select></td>';
6764: }
6765: $output .= '</tr></table></fieldset>'.
6766: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6767: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6768: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6769: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6770: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6771: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6772: '</fieldset>'.
1.391 raeburn 6773: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6774: foreach my $lticrsrole (@lticourseroles) {
6775: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6776: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6777: }
6778: $output .= '</fieldset>'.
1.391 raeburn 6779: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6780: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6781: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6782: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6783: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6784: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6785: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6786: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6787: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6788: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6789: &mt('Standard field').'</label>'.(' 'x2).
6790: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6791: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6792: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6793: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6794: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6795: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6796: foreach my $extra ('roster','passback') {
1.320 raeburn 6797: my $checkedon = '';
6798: my $checkedoff = ' checked="checked"';
1.337 raeburn 6799: if ($extra eq 'passback') {
6800: $pb1p1chk = ' checked="checked"';
6801: $pb1p0chk = '';
6802: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6803: } else {
6804: $onclickpb = '';
6805: }
1.320 raeburn 6806: if (ref($current) eq 'HASH') {
6807: if (($current->{$extra})) {
6808: $checkedon = $checkedoff;
6809: $checkedoff = '';
1.337 raeburn 6810: if ($extra eq 'passback') {
6811: $passbacksty = 'inline-block';
6812: }
6813: if ($current->{'passbackformat'} eq '1.0') {
6814: $pb1p0chk = ' checked="checked"';
6815: $pb1p1chk = '';
6816: }
1.320 raeburn 6817: }
6818: }
6819: $output .= $lt{$extra}.' '.
1.337 raeburn 6820: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6821: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6822: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6823: &mt('Yes').'</label><br />';
6824: }
1.337 raeburn 6825: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6826: '<span class="LC_nobreak">'.&mt('Grade format').
6827: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6828: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6829: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6830: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6831: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6832: $output .= '</span></div></fieldset>';
1.320 raeburn 6833: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6834: #
6835: # $output .= '</fieldset>'.
6836: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6837: return $output;
6838: }
6839:
1.326 raeburn 6840: sub ltimenu_titles {
6841: return &Apache::lonlocal::texthash(
6842: fullname => 'Full name',
6843: coursetitle => 'Course title',
6844: role => 'Role',
6845: logout => 'Logout',
6846: grades => 'Grades',
6847: );
6848: }
6849:
1.121 raeburn 6850: sub print_coursedefaults {
1.139 raeburn 6851: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6852: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6853: my $itemcount = 1;
1.192 raeburn 6854: my %choices = &Apache::lonlocal::texthash (
6855: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6856: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6857: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6858: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6859: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6860: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6861: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6862: texengine => 'Default method to display mathematics',
1.257 raeburn 6863: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6864: canclone => "People who may clone a course (besides course's owner and coordinators)",
6865: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.404 ! raeburn 6866: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.192 raeburn 6867: );
1.198 raeburn 6868: my %staticdefaults = (
6869: anonsurvey_threshold => 10,
6870: uploadquota => 500,
1.257 raeburn 6871: postsubmit => 60,
1.276 raeburn 6872: mysqltables => 172800,
1.198 raeburn 6873: );
1.139 raeburn 6874: if ($position eq 'top') {
1.257 raeburn 6875: %defaultchecked = (
6876: 'canuse_pdfforms' => 'off',
6877: 'uselcmath' => 'on',
6878: 'usejsme' => 'on',
1.398 raeburn 6879: 'inline_chem' => 'on',
1.289 raeburn 6880: 'canclone' => 'none',
1.257 raeburn 6881: );
1.398 raeburn 6882: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6883: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6884: if (ref($settings) eq 'HASH') {
6885: if ($settings->{'texengine'}) {
6886: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6887: $deftex = $settings->{'texengine'};
6888: }
6889: }
6890: }
6891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6892: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6893: '<span class="LC_nobreak">'.$choices{'texengine'}.
6894: '</span></td><td class="LC_right_item">'.
6895: '<select name="texengine">'."\n";
6896: my %texoptions = (
6897: MathJax => 'MathJax',
6898: mimetex => &mt('Convert to Images'),
6899: tth => &mt('TeX to HTML'),
6900: );
6901: foreach my $renderer ('MathJax','mimetex','tth') {
6902: my $selected = '';
6903: if ($renderer eq $deftex) {
6904: $selected = ' selected="selected"';
6905: }
6906: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6907: }
6908: $mathdisp .= '</select></td></tr>'."\n";
6909: $itemcount ++;
1.139 raeburn 6910: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6911: \%choices,$itemcount);
1.314 raeburn 6912: $datatable = $mathdisp.$datatable;
1.264 raeburn 6913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6914: $datatable .=
1.306 raeburn 6915: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6916: '<span class="LC_nobreak">'.$choices{'canclone'}.
6917: '</span></td><td class="LC_left_item">';
6918: my $currcanclone = 'none';
6919: my $onclick;
6920: my @cloneoptions = ('none','domain');
1.380 raeburn 6921: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6922: none => 'No additional course requesters',
6923: domain => "Any course requester in course's domain",
6924: instcode => 'Course requests for official courses ...',
6925: );
6926: my (%codedefaults,@code_order,@posscodes);
6927: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6928: \@code_order) eq 'ok') {
6929: if (@code_order > 0) {
6930: push(@cloneoptions,'instcode');
6931: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6932: }
6933: }
6934: if (ref($settings) eq 'HASH') {
6935: if ($settings->{'canclone'}) {
6936: if (ref($settings->{'canclone'}) eq 'HASH') {
6937: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6938: if (@code_order > 0) {
6939: $currcanclone = 'instcode';
6940: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6941: }
6942: }
6943: } elsif ($settings->{'canclone'} eq 'domain') {
6944: $currcanclone = $settings->{'canclone'};
6945: }
6946: }
1.289 raeburn 6947: }
1.264 raeburn 6948: foreach my $option (@cloneoptions) {
6949: my ($checked,$additional);
6950: if ($currcanclone eq $option) {
6951: $checked = ' checked="checked"';
6952: }
6953: if ($option eq 'instcode') {
6954: if (@code_order) {
6955: my $show = 'none';
6956: if ($checked) {
6957: $show = 'block';
6958: }
1.317 raeburn 6959: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6960: &mt('Institutional codes for new and cloned course have identical:').
6961: '<br />';
6962: foreach my $item (@code_order) {
6963: my $codechk;
6964: if ($checked) {
6965: if (grep(/^\Q$item\E$/,@posscodes)) {
6966: $codechk = ' checked="checked"';
6967: }
6968: }
6969: $additional .= '<label>'.
6970: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6971: $item.'</label>';
6972: }
6973: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6974: }
6975: }
6976: $datatable .=
6977: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6978: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6979: '</label> '.$additional.'</span><br />';
6980: }
6981: $datatable .= '</td>'.
6982: '</tr>';
6983: $itemcount ++;
1.139 raeburn 6984: } else {
6985: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6986: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6987: my $currusecredits = 0;
1.257 raeburn 6988: my $postsubmitclient = 1;
1.404 ! raeburn 6989: my $ltiauth = 0;
1.271 raeburn 6990: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6991: if (ref($settings) eq 'HASH') {
1.404 ! raeburn 6992: if ($settings->{'ltiauth'}) {
! 6993: $ltiauth = 1;
! 6994: }
1.139 raeburn 6995: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6996: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6997: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6998: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6999: }
7000: }
1.192 raeburn 7001: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7002: foreach my $type (@types) {
7003: next if ($type eq 'community');
7004: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7005: if ($defcredits{$type} ne '') {
7006: $currusecredits = 1;
7007: }
7008: }
7009: }
7010: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7011: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7012: $postsubmitclient = 0;
7013: foreach my $type (@types) {
7014: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7015: }
7016: } else {
7017: foreach my $type (@types) {
7018: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7019: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7020: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7021: } else {
7022: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7023: }
7024: } else {
7025: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7026: }
7027: }
7028: }
7029: } else {
7030: foreach my $type (@types) {
7031: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7032: }
7033: }
1.276 raeburn 7034: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7035: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7036: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7037: }
7038: } else {
7039: foreach my $type (@types) {
7040: $currmysql{$type} = $staticdefaults{'mysqltables'};
7041: }
7042: }
1.258 raeburn 7043: } else {
7044: foreach my $type (@types) {
7045: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7046: }
1.139 raeburn 7047: }
7048: if (!$currdefresponder) {
1.198 raeburn 7049: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7050: } elsif ($currdefresponder < 1) {
7051: $currdefresponder = 1;
7052: }
1.198 raeburn 7053: foreach my $type (@types) {
7054: if ($curruploadquota{$type} eq '') {
7055: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7056: }
7057: }
1.139 raeburn 7058: $datatable .=
1.192 raeburn 7059: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7060: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7061: '</span></td>'.
7062: '<td class="LC_right_item"><span class="LC_nobreak">'.
7063: '<input type="text" name="anonsurvey_threshold"'.
7064: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7065: '</td></tr>'."\n";
7066: $itemcount ++;
7067: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7068: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7069: $choices{'uploadquota'}.
7070: '</span></td>'.
1.306 raeburn 7071: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7072: '<table><tr>';
1.198 raeburn 7073: foreach my $type (@types) {
1.306 raeburn 7074: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7075: '<input type="text" name="uploadquota_'.$type.'"'.
7076: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7077: }
7078: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7079: $itemcount ++;
1.236 raeburn 7080: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7081: my $display = 'none';
1.192 raeburn 7082: if ($currusecredits) {
7083: $display = 'block';
7084: }
7085: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7086: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7087: foreach my $type (@types) {
7088: next if ($type eq 'community');
1.306 raeburn 7089: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7090: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7091: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7092: }
7093: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7094: %defaultchecked = ('coursecredits' => 'off');
7095: @toggles = ('coursecredits');
7096: my $current = {
7097: 'coursecredits' => $currusecredits,
7098: };
7099: (my $table,$itemcount) =
7100: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7101: \%choices,$itemcount,$onclick,$additional,'left');
7102: $datatable .= $table;
7103: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7104: my $display = 'none';
7105: if ($postsubmitclient) {
7106: $display = 'block';
7107: }
7108: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7109: &mt('Number of seconds submit is disabled').'<br />'.
7110: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7111: '<table><tr>';
1.257 raeburn 7112: foreach my $type (@types) {
1.306 raeburn 7113: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7114: '<input type="text" name="'.$type.'_timeout" value="'.
7115: $deftimeout{$type}.'" size="5" /></td>';
7116: }
7117: $additional .= '</tr></table></div>'."\n";
7118: %defaultchecked = ('postsubmit' => 'on');
7119: @toggles = ('postsubmit');
1.280 raeburn 7120: $current = {
7121: 'postsubmit' => $postsubmitclient,
7122: };
1.257 raeburn 7123: ($table,$itemcount) =
7124: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7125: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7126: $datatable .= $table;
1.276 raeburn 7127: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7128: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7129: $choices{'mysqltables'}.
7130: '</span></td>'.
1.306 raeburn 7131: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7132: '<table><tr>';
7133: foreach my $type (@types) {
1.306 raeburn 7134: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7135: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7136: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7137: }
7138: $datatable .= '</tr></table></td></tr>'."\n";
7139: $itemcount ++;
1.404 ! raeburn 7140: %defaultchecked = ('ltiauth' => 'off');
! 7141: @toggles = ('ltiauth');
! 7142: $current = {
! 7143: 'ltiauth' => $ltiauth,
! 7144: };
! 7145: ($table,$itemcount) =
! 7146: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
! 7147: \%choices,$itemcount,undef,undef,'left');
! 7148: $datatable .= $table;
! 7149: $itemcount ++;
1.139 raeburn 7150: }
1.192 raeburn 7151: $$rowtotal += $itemcount;
1.121 raeburn 7152: return $datatable;
1.118 jms 7153: }
7154:
1.231 raeburn 7155: sub print_selfenrollment {
7156: my ($position,$dom,$settings,$rowtotal) = @_;
7157: my ($css_class,$datatable);
7158: my $itemcount = 1;
1.271 raeburn 7159: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7160: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7161: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7162: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7163: my @rows;
7164: my $key;
7165: if ($position eq 'top') {
7166: $key = 'admin';
7167: if (ref($rowsref) eq 'ARRAY') {
7168: @rows = @{$rowsref};
7169: }
7170: } elsif ($position eq 'middle') {
7171: $key = 'default';
7172: @rows = ('types','registered','approval','limit');
7173: }
7174: foreach my $row (@rows) {
7175: if (defined($titlesref->{$row})) {
7176: $itemcount ++;
7177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7178: $datatable .= '<tr'.$css_class.'>'.
7179: '<td>'.$titlesref->{$row}.'</td>'.
7180: '<td class="LC_left_item">'.
7181: '<table><tr>';
7182: my (%current,%currentcap);
7183: if (ref($settings) eq 'HASH') {
7184: if (ref($settings->{$key}) eq 'HASH') {
7185: foreach my $type (@types) {
7186: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7187: $current{$type} = $settings->{$key}->{$type}->{$row};
7188: }
7189: if (($row eq 'limit') && ($key eq 'default')) {
7190: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7191: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7192: }
7193: }
7194: }
7195: }
7196: }
7197: my %roles = (
7198: '0' => &Apache::lonnet::plaintext('dc'),
7199: );
7200:
7201: foreach my $type (@types) {
7202: unless (($row eq 'registered') && ($key eq 'default')) {
7203: $datatable .= '<th>'.&mt($type).'</th>';
7204: }
7205: }
7206: unless (($row eq 'registered') && ($key eq 'default')) {
7207: $datatable .= '</tr><tr>';
7208: }
7209: foreach my $type (@types) {
7210: if ($type eq 'community') {
7211: $roles{'1'} = &mt('Community personnel');
7212: } else {
7213: $roles{'1'} = &mt('Course personnel');
7214: }
7215: $datatable .= '<td style="vertical-align: top">';
7216: if ($position eq 'top') {
7217: my %checked;
7218: if ($current{$type} eq '0') {
7219: $checked{'0'} = ' checked="checked"';
7220: } else {
7221: $checked{'1'} = ' checked="checked"';
7222: }
7223: foreach my $role ('1','0') {
7224: $datatable .= '<span class="LC_nobreak"><label>'.
7225: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7226: 'value="'.$role.'"'.$checked{$role}.' />'.
7227: $roles{$role}.'</label></span> ';
7228: }
7229: } else {
7230: if ($row eq 'types') {
7231: my %checked;
7232: if ($current{$type} =~ /^(all|dom)$/) {
7233: $checked{$1} = ' checked="checked"';
7234: } else {
7235: $checked{''} = ' checked="checked"';
7236: }
7237: foreach my $val ('','dom','all') {
7238: $datatable .= '<span class="LC_nobreak"><label>'.
7239: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7240: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7241: }
7242: } elsif ($row eq 'registered') {
7243: my %checked;
7244: if ($current{$type} eq '1') {
7245: $checked{'1'} = ' checked="checked"';
7246: } else {
7247: $checked{'0'} = ' checked="checked"';
7248: }
7249: foreach my $val ('0','1') {
7250: $datatable .= '<span class="LC_nobreak"><label>'.
7251: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7252: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7253: }
7254: } elsif ($row eq 'approval') {
7255: my %checked;
7256: if ($current{$type} =~ /^([12])$/) {
7257: $checked{$1} = ' checked="checked"';
7258: } else {
7259: $checked{'0'} = ' checked="checked"';
7260: }
7261: for my $val (0..2) {
7262: $datatable .= '<span class="LC_nobreak"><label>'.
7263: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7264: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7265: }
7266: } elsif ($row eq 'limit') {
7267: my %checked;
7268: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7269: $checked{$1} = ' checked="checked"';
7270: } else {
7271: $checked{'none'} = ' checked="checked"';
7272: }
7273: my $cap;
7274: if ($currentcap{$type} =~ /^\d+$/) {
7275: $cap = $currentcap{$type};
7276: }
7277: foreach my $val ('none','allstudents','selfenrolled') {
7278: $datatable .= '<span class="LC_nobreak"><label>'.
7279: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7280: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7281: }
7282: $datatable .= '<br />'.
7283: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7284: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7285: '</span>';
7286: }
7287: }
7288: $datatable .= '</td>';
7289: }
7290: $datatable .= '</tr>';
7291: }
7292: $datatable .= '</table></td></tr>';
7293: }
7294: } elsif ($position eq 'bottom') {
1.235 raeburn 7295: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7296: }
7297: $$rowtotal += $itemcount;
7298: return $datatable;
7299: }
7300:
7301: sub print_validation_rows {
7302: my ($caller,$dom,$settings,$rowtotal) = @_;
7303: my ($itemsref,$namesref,$fieldsref);
7304: if ($caller eq 'selfenroll') {
7305: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7306: } elsif ($caller eq 'requestcourses') {
7307: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7308: }
7309: my %currvalidation;
7310: if (ref($settings) eq 'HASH') {
7311: if (ref($settings->{'validation'}) eq 'HASH') {
7312: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7313: }
1.235 raeburn 7314: }
7315: my $datatable;
7316: my $itemcount = 0;
7317: foreach my $item (@{$itemsref}) {
7318: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7319: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7320: $namesref->{$item}.
7321: '</span></td>'.
7322: '<td class="LC_left_item">';
7323: if (($item eq 'url') || ($item eq 'button')) {
7324: $datatable .= '<span class="LC_nobreak">'.
7325: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7326: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7327: } elsif ($item eq 'fields') {
7328: my @currfields;
7329: if (ref($currvalidation{$item}) eq 'ARRAY') {
7330: @currfields = @{$currvalidation{$item}};
7331: }
7332: foreach my $field (@{$fieldsref}) {
7333: my $check = '';
7334: if (grep(/^\Q$field\E$/,@currfields)) {
7335: $check = ' checked="checked"';
7336: }
7337: $datatable .= '<span class="LC_nobreak"><label>'.
7338: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7339: ' value="'.$field.'"'.$check.' />'.$field.
7340: '</label></span> ';
7341: }
7342: } elsif ($item eq 'markup') {
1.334 raeburn 7343: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7344: $currvalidation{$item}.
1.231 raeburn 7345: '</textarea>';
1.235 raeburn 7346: }
7347: $datatable .= '</td></tr>'."\n";
7348: if (ref($rowtotal)) {
1.231 raeburn 7349: $itemcount ++;
7350: }
7351: }
1.235 raeburn 7352: if ($caller eq 'requestcourses') {
7353: my %currhash;
1.248 raeburn 7354: if (ref($settings) eq 'HASH') {
7355: if (ref($settings->{'validation'}) eq 'HASH') {
7356: if ($settings->{'validation'}{'dc'} ne '') {
7357: $currhash{$settings->{'validation'}{'dc'}} = 1;
7358: }
1.235 raeburn 7359: }
7360: }
7361: my $numinrow = 2;
7362: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7363: 'validationdc',%currhash);
1.247 raeburn 7364: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7365: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7366: if ($numdc > 1) {
1.247 raeburn 7367: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7368: } else {
1.247 raeburn 7369: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7370: }
1.247 raeburn 7371: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7372: $itemcount ++;
7373: }
7374: if (ref($rowtotal)) {
7375: $$rowtotal += $itemcount;
7376: }
1.231 raeburn 7377: return $datatable;
7378: }
7379:
1.357 raeburn 7380: sub print_privacy {
7381: my ($position,$dom,$settings,$rowtotal) = @_;
7382: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7383: my $itemcount = 0;
7384: unless ($position eq 'top') {
7385: @items = ('domain','author','course','community');
7386: %names = &Apache::lonlocal::texthash (
7387: domain => 'Assigned domain role(s)',
7388: author => 'Assigned co-author role(s)',
7389: course => 'Assigned course role(s)',
7390: community => 'Assigned community role',
7391: );
7392: $numinrow = 4;
7393: ($othertitle,$usertypes,$types) =
7394: &Apache::loncommon::sorted_inst_types($dom);
7395: }
7396: if (($position eq 'top') || ($position eq 'middle')) {
7397: my (%by_ip,%by_location,@intdoms,@instdoms);
7398: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7399: if ($position eq 'top') {
7400: my %curr;
7401: my @options = ('none','user','domain','auto');
7402: my %titles = &Apache::lonlocal::texthash (
7403: none => 'Not allowed',
7404: user => 'User authorizes',
7405: domain => 'DC authorizes',
7406: auto => 'Unrestricted',
7407: instdom => 'Other domain shares institution/provider',
7408: extdom => 'Other domain has different institution/provider',
7409: );
7410: my %names = &Apache::lonlocal::texthash (
7411: domain => 'Domain role',
7412: author => 'Co-author role',
7413: course => 'Course role',
7414: community => 'Community role',
7415: );
7416: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7417: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7418: foreach my $domtype ('instdom','extdom') {
7419: my (%checked,$skip);
7420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7421: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7422: '<td class="LC_left_item">';
7423: if ($domtype eq 'instdom') {
7424: unless (@instdoms > 1) {
7425: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7426: $skip = 1;
7427: }
7428: } elsif ($domtype eq 'extdom') {
7429: if (keys(%by_location) == 0) {
7430: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7431: $skip = 1;
7432: }
7433: }
7434: unless ($skip) {
7435: foreach my $roletype ('domain','author','course','community') {
7436: $checked{'auto'} = ' checked="checked"';
7437: if (ref($settings) eq 'HASH') {
7438: if (ref($settings->{approval}) eq 'HASH') {
7439: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7440: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7441: $checked{$1} = ' checked="checked"';
7442: $checked{'auto'} = '';
7443: }
7444: }
7445: }
7446: }
7447: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7448: foreach my $option (@options) {
7449: $datatable .= '<span class="LC_nobreak"><label>'.
7450: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7451: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7452: '</label></span> ';
7453: }
7454: $datatable .= '</fieldset>';
7455: }
7456: }
7457: $datatable .= '</td></tr>';
7458: $itemcount ++;
7459: }
7460: } elsif ($position eq 'middle') {
7461: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7462: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7463: foreach my $item (@{$types}) {
7464: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7465: $numinrow,$itemcount,'','','','','',
7466: '',$usertypes->{$item});
7467: $itemcount ++;
7468: }
7469: }
7470: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7471: $numinrow,$itemcount,'','','','','',
7472: '',$othertitle);
7473: $itemcount ++;
7474: } else {
1.360 raeburn 7475: my (@insttypes,%insttitles);
7476: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7477: @insttypes = @{$types};
7478: %insttitles = %{$usertypes};
7479: }
7480: foreach my $item (@insttypes,'default') {
7481: my $title;
7482: if ($item eq 'default') {
7483: $title = $othertitle;
7484: } else {
7485: $title = $insttitles{$item};
7486: }
7487: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7488: $datatable .= '<tr'.$css_class.'>'.
7489: '<td class="LC_left_item">'.$title.'</td>'.
7490: '<td class="LC_left_item">'.
7491: &mt('Nothing to set here, as there are no other domains').
7492: '</td></tr>';
7493: $itemcount ++;
7494: }
1.357 raeburn 7495: }
7496: }
7497: } else {
7498: my $prefix;
7499: if ($position eq 'lower') {
7500: $prefix = 'priv';
7501: } else {
7502: $prefix = 'unpriv';
7503: }
7504: foreach my $item (@items) {
7505: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7506: $numinrow,$itemcount,'','','','','',
7507: '',$names{$item});
7508: $itemcount ++;
7509: }
7510: }
7511: if (ref($rowtotal)) {
7512: $$rowtotal += $itemcount;
7513: }
7514: return $datatable;
7515: }
7516:
1.354 raeburn 7517: sub print_passwords {
7518: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7519: my ($datatable,$css_class);
7520: my $itemcount = 0;
7521: my %titles = &Apache::lonlocal::texthash (
7522: captcha => '"Forgot Password" CAPTCHA validation',
7523: link => 'Reset link expiration (hours)',
7524: case => 'Case-sensitive usernames/e-mail',
7525: prelink => 'Information required (form 1)',
7526: postlink => 'Information required (form 2)',
7527: emailsrc => 'LON-CAPA e-mail address type(s)',
7528: customtext => 'Domain specific text (HTML)',
7529: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7530: intauth_check => 'Check bcrypt cost if authenticated',
7531: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7532: permanent => 'Permanent e-mail address',
7533: critical => 'Critical notification address',
7534: notify => 'Notification address',
7535: min => 'Minimum password length',
7536: max => 'Maximum password length',
7537: chars => 'Required characters',
7538: expire => 'Password expiration (days)',
1.356 raeburn 7539: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7540: );
7541: if ($position eq 'top') {
7542: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7543: my $shownlinklife = 2;
7544: my $prelink = 'both';
7545: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7546: if (ref($settings) eq 'HASH') {
7547: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7548: $shownlinklife = $settings->{resetlink};
7549: }
7550: if (ref($settings->{resetcase}) eq 'ARRAY') {
7551: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7552: }
7553: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7554: $prelink = $settings->{resetprelink};
7555: }
7556: if (ref($settings->{resetpostlink}) eq 'HASH') {
7557: %postlink = %{$settings->{resetpostlink}};
7558: }
7559: if (ref($settings->{resetemail}) eq 'ARRAY') {
7560: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7561: }
7562: if ($settings->{resetremove}) {
7563: $nostdtext = 1;
7564: }
7565: if ($settings->{resetcustom}) {
7566: $customurl = $settings->{resetcustom};
7567: }
7568: } else {
7569: if (ref($types) eq 'ARRAY') {
7570: foreach my $item (@{$types}) {
7571: $casesens{$item} = 1;
7572: $postlink{$item} = ['username','email'];
7573: }
7574: }
7575: $casesens{'default'} = 1;
7576: $postlink{'default'} = ['username','email'];
7577: $prelink = 'both';
7578: %emailsrc = (
7579: permanent => 1,
7580: critical => 1,
7581: notify => 1,
7582: );
7583: }
7584: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7585: $itemcount ++;
7586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7587: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7588: '<td class="LC_left_item">'.
7589: '<input type="textbox" value="'.$shownlinklife.'" '.
7590: 'name="passwords_link" size="3" /></td></tr>';
7591: $itemcount ++;
7592: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7593: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7594: '<td class="LC_left_item">';
7595: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7596: foreach my $item (@{$types}) {
7597: my $checkedcase;
7598: if ($casesens{$item}) {
7599: $checkedcase = ' checked="checked"';
7600: }
7601: $datatable .= '<span class="LC_nobreak"><label>'.
7602: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7603: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7604: '</span> ';
1.354 raeburn 7605: }
7606: }
7607: my $checkedcase;
7608: if ($casesens{'default'}) {
7609: $checkedcase = ' checked="checked"';
7610: }
7611: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7612: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7613: $othertitle.'</label></span></td>';
7614: $itemcount ++;
7615: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7616: my %checkedpre = (
7617: both => ' checked="checked"',
7618: either => '',
7619: );
7620: if ($prelink eq 'either') {
7621: $checkedpre{either} = ' checked="checked"';
7622: $checkedpre{both} = '';
7623: }
7624: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7625: '<td class="LC_left_item"><span class="LC_nobreak">'.
7626: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7627: &mt('Both username and e-mail address').'</label></span> '.
7628: '<span class="LC_nobreak"><label>'.
7629: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7630: &mt('Either username or e-mail address').'</label></span></td></tr>';
7631: $itemcount ++;
7632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7633: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7634: '<td class="LC_left_item">';
7635: my %postlinked;
7636: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7637: foreach my $item (@{$types}) {
7638: undef(%postlinked);
7639: $datatable .= '<fieldset style="display: inline-block;">'.
7640: '<legend>'.$usertypes->{$item}.'</legend>';
7641: if (ref($postlink{$item}) eq 'ARRAY') {
7642: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7643: }
7644: foreach my $field ('email','username') {
7645: my $checked;
7646: if ($postlinked{$field}) {
7647: $checked = ' checked="checked"';
7648: }
7649: $datatable .= '<span class="LC_nobreak"><label>'.
7650: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7651: $field.'"'.$checked.' />'.$field.'</label>'.
7652: '<span> ';
7653: }
7654: $datatable .= '</fieldset>';
7655: }
7656: }
7657: if (ref($postlink{'default'}) eq 'ARRAY') {
7658: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7659: }
7660: $datatable .= '<fieldset style="display: inline-block;">'.
7661: '<legend>'.$othertitle.'</legend>';
7662: foreach my $field ('email','username') {
7663: my $checked;
7664: if ($postlinked{$field}) {
7665: $checked = ' checked="checked"';
7666: }
7667: $datatable .= '<span class="LC_nobreak"><label>'.
7668: '<input type="checkbox" name="passwords_postlink_default" value="'.
7669: $field.'"'.$checked.' />'.$field.'</label>'.
7670: '<span> ';
7671: }
7672: $datatable .= '</fieldset></td></tr>';
7673: $itemcount ++;
7674: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7675: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7676: '<td class="LC_left_item">';
7677: foreach my $type ('permanent','critical','notify') {
7678: my $checkedemail;
7679: if ($emailsrc{$type}) {
7680: $checkedemail = ' checked="checked"';
7681: }
7682: $datatable .= '<span class="LC_nobreak"><label>'.
7683: '<input type="checkbox" name="passwords_emailsrc" value="'.
7684: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7685: '<span> ';
7686: }
7687: $datatable .= '</td></tr>';
7688: $itemcount ++;
7689: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7690: my $switchserver = &check_switchserver($dom,$confname);
7691: my ($showstd,$noshowstd);
7692: if ($nostdtext) {
7693: $noshowstd = ' checked="checked"';
7694: } else {
7695: $showstd = ' checked="checked"';
7696: }
7697: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7698: '<td class="LC_left_item"><span class="LC_nobreak">'.
7699: &mt('Retain standard text:').
7700: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7701: &mt('Yes').'</label>'.' '.
7702: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7703: &mt('No').'</label></span><br />'.
7704: '<span class="LC_fontsize_small">'.
7705: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7706: &mt('Include custom text:');
7707: if ($customurl) {
1.369 raeburn 7708: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7709: undef,undef,undef,undef,'background-color:#ffffff');
7710: $datatable .= '<span class="LC_nobreak"> '.$link.
7711: '<label><input type="checkbox" name="passwords_custom_del"'.
7712: ' value="1" />'.&mt('Delete?').'</label></span>'.
7713: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7714: }
7715: if ($switchserver) {
7716: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7717: } else {
7718: $datatable .='<span class="LC_nobreak"> '.
7719: '<input type="file" name="passwords_customfile" /></span>';
7720: }
7721: $datatable .= '</td></tr>';
7722: } elsif ($position eq 'middle') {
7723: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7724: my @items = ('intauth_cost','intauth_check','intauth_switch');
7725: my %defaults;
7726: if (ref($domconf{'defaults'}) eq 'HASH') {
7727: %defaults = %{$domconf{'defaults'}};
7728: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7729: $defaults{'intauth_cost'} = 10;
7730: }
7731: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7732: $defaults{'intauth_check'} = 0;
7733: }
7734: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7735: $defaults{'intauth_switch'} = 0;
7736: }
7737: } else {
7738: %defaults = (
7739: 'intauth_cost' => 10,
7740: 'intauth_check' => 0,
7741: 'intauth_switch' => 0,
7742: );
7743: }
7744: foreach my $item (@items) {
7745: if ($itemcount%2) {
7746: $css_class = '';
7747: } else {
7748: $css_class = ' class="LC_odd_row" ';
7749: }
7750: $datatable .= '<tr'.$css_class.'>'.
7751: '<td><span class="LC_nobreak">'.$titles{$item}.
7752: '</span></td><td class="LC_left_item" colspan="3">';
7753: if ($item eq 'intauth_switch') {
7754: my @options = (0,1,2);
7755: my %optiondesc = &Apache::lonlocal::texthash (
7756: 0 => 'No',
7757: 1 => 'Yes',
7758: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7759: );
7760: $datatable .= '<table width="100%">';
7761: foreach my $option (@options) {
7762: my $checked = ' ';
7763: if ($defaults{$item} eq $option) {
7764: $checked = ' checked="checked"';
7765: }
7766: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7767: '<label><input type="radio" name="'.$item.
7768: '" value="'.$option.'"'.$checked.' />'.
7769: $optiondesc{$option}.'</label></span></td></tr>';
7770: }
7771: $datatable .= '</table>';
7772: } elsif ($item eq 'intauth_check') {
7773: my @options = (0,1,2);
7774: my %optiondesc = &Apache::lonlocal::texthash (
7775: 0 => 'No',
7776: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7777: 2 => 'Yes, disallow login if stored cost is less than domain default',
7778: );
7779: $datatable .= '<table width="100%">';
7780: foreach my $option (@options) {
7781: my $checked = ' ';
7782: my $onclick;
7783: if ($defaults{$item} eq $option) {
7784: $checked = ' checked="checked"';
7785: }
7786: if ($option == 2) {
7787: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7788: }
7789: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7790: '<label><input type="radio" name="'.$item.
7791: '" value="'.$option.'"'.$checked.$onclick.' />'.
7792: $optiondesc{$option}.'</label></span></td></tr>';
7793: }
7794: $datatable .= '</table>';
7795: } else {
7796: $datatable .= '<input type="text" name="'.$item.'" value="'.
7797: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7798: }
7799: $datatable .= '</td></tr>';
7800: $itemcount ++;
7801: }
7802: } elsif ($position eq 'lower') {
1.356 raeburn 7803: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7804: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7805: if (ref($settings) eq 'HASH') {
7806: if ($settings->{min}) {
7807: $min = $settings->{min};
7808: }
7809: if ($settings->{max}) {
7810: $max = $settings->{max};
7811: }
7812: if (ref($settings->{chars}) eq 'ARRAY') {
7813: map { $chars{$_} = 1; } (@{$settings->{chars}});
7814: }
7815: if ($settings->{expire}) {
7816: $expire = $settings->{expire};
7817: }
1.358 raeburn 7818: if ($settings->{numsaved}) {
7819: $numsaved = $settings->{numsaved};
1.356 raeburn 7820: }
1.354 raeburn 7821: }
7822: my %rulenames = &Apache::lonlocal::texthash(
7823: uc => 'At least one upper case letter',
7824: lc => 'At least one lower case letter',
7825: num => 'At least one number',
7826: spec => 'At least one non-alphanumeric',
7827: );
7828: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7829: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7830: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7831: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7832: 'onblur="javascript:warnIntPass(this);" />'.
7833: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7834: '</span></td></tr>';
7835: $itemcount ++;
7836: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7837: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7838: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7839: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7840: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7841: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7842: '</span></td></tr>';
7843: $itemcount ++;
7844: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7845: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7846: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7847: '</span></td>';
7848: my $numinrow = 2;
7849: my @possrules = ('uc','lc','num','spec');
7850: $datatable .= '<td class="LC_left_item"><table>';
7851: for (my $i=0; $i<@possrules; $i++) {
7852: my ($rem,$checked);
7853: if ($chars{$possrules[$i]}) {
7854: $checked = ' checked="checked"';
7855: }
7856: $rem = $i%($numinrow);
7857: if ($rem == 0) {
7858: if ($i > 0) {
7859: $datatable .= '</tr>';
7860: }
7861: $datatable .= '<tr>';
7862: }
7863: $datatable .= '<td><span class="LC_nobreak"><label>'.
7864: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7865: $rulenames{$possrules[$i]}.'</label></span></td>';
7866: }
7867: my $rem = @possrules%($numinrow);
7868: my $colsleft = $numinrow - $rem;
7869: if ($colsleft > 1 ) {
7870: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7871: ' </td>';
7872: } elsif ($colsleft == 1) {
7873: $datatable .= '<td class="LC_left_item"> </td>';
7874: }
7875: $datatable .='</table></td></tr>';
7876: $itemcount ++;
7877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7878: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7879: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7880: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7881: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7882: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7883: '</span></td></tr>';
1.356 raeburn 7884: $itemcount ++;
7885: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7886: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7887: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7888: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7889: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7890: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7891: '</span></td></tr>';
1.354 raeburn 7892: } else {
1.359 raeburn 7893: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7894: my %ownerchg = (
7895: by => {},
7896: for => {},
7897: );
7898: my %ownertitles = &Apache::lonlocal::texthash (
7899: by => 'Course owner status(es) allowed',
7900: for => 'Student status(es) allowed',
7901: );
1.354 raeburn 7902: if (ref($settings) eq 'HASH') {
1.359 raeburn 7903: if (ref($settings->{crsownerchg}) eq 'HASH') {
7904: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7905: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7906: }
7907: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7908: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7909: }
1.354 raeburn 7910: }
7911: }
7912: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7913: $datatable .= '<tr '.$css_class.'>'.
7914: '<td>'.
7915: &mt('Requirements').'<ul>'.
1.359 raeburn 7916: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7917: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7918: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7919: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7920: '</ul>'.
7921: '</td>'.
1.359 raeburn 7922: '<td class="LC_left_item">';
7923: foreach my $item ('by','for') {
7924: $datatable .= '<fieldset style="display: inline-block;">'.
7925: '<legend>'.$ownertitles{$item}.'</legend>';
7926: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7927: foreach my $type (@{$types}) {
7928: my $checked;
7929: if ($ownerchg{$item}{$type}) {
7930: $checked = ' checked="checked"';
7931: }
7932: $datatable .= '<span class="LC_nobreak"><label>'.
7933: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7934: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7935: '</span> ';
1.359 raeburn 7936: }
7937: }
7938: my $checked;
7939: if ($ownerchg{$item}{'default'}) {
7940: $checked = ' checked="checked"';
7941: }
7942: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7943: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7944: $othertitle.'</label></span></fieldset>';
7945: }
7946: $datatable .= '</td></tr>';
1.354 raeburn 7947: }
7948: return $datatable;
7949: }
7950:
1.373 raeburn 7951: sub print_wafproxy {
7952: my ($position,$dom,$settings,$rowtotal) = @_;
7953: my $css_class;
7954: my $itemcount = 0;
7955: my $datatable;
7956: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7957: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7958: my %lt = &wafproxy_titles();
1.373 raeburn 7959: foreach my $server (sort(keys(%servers))) {
7960: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7961: next if ($serverhome eq '');
1.373 raeburn 7962: my $serverdom;
7963: if ($serverhome ne $server) {
7964: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7965: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7966: $othercontrol{$server} = $serverdom;
7967: }
1.373 raeburn 7968: } else {
7969: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7970: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7971: if ($serverdom ne $dom) {
7972: $othercontrol{$server} = $serverdom;
7973: } else {
7974: $setdom = 1;
7975: if (ref($settings) eq 'HASH') {
7976: if (ref($settings->{'alias'}) eq 'HASH') {
7977: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7978: if ($aliases{$dom} ne '') {
7979: $showdom = 1;
7980: }
1.373 raeburn 7981: }
1.388 raeburn 7982: if (ref($settings->{'saml'}) eq 'HASH') {
7983: $saml{$dom} = $settings->{'saml'};
7984: }
1.373 raeburn 7985: }
7986: }
7987: }
7988: }
1.381 raeburn 7989: if ($setdom) {
7990: %{$values{$dom}} = ();
7991: if (ref($settings) eq 'HASH') {
7992: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7993: $values{$dom}{$item} = $settings->{$item};
7994: }
7995: }
7996: }
1.373 raeburn 7997: if (keys(%othercontrol)) {
7998: %otherdoms = reverse(%othercontrol);
7999: foreach my $domain (keys(%otherdoms)) {
8000: %{$values{$domain}} = ();
8001: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8002: if (ref($config{'wafproxy'}) eq 'HASH') {
8003: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 8004: if (exists($config{'wafproxy'}{'saml'})) {
8005: $saml{$domain} = $config{'wafproxy'}{'saml'};
8006: }
1.383 raeburn 8007: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8008: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8009: }
8010: }
8011: }
8012: }
8013: if ($position eq 'top') {
8014: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8015: my %aliasinfo;
1.373 raeburn 8016: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8017: $itemcount ++;
8018: my $dom_in_effect;
8019: my $aliasrows = '<tr>'.
1.383 raeburn 8020: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8021: &mt('Hostname').': '.
8022: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8023: if ($othercontrol{$server}) {
1.381 raeburn 8024: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8025: my ($current,$forsaml);
1.383 raeburn 8026: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8027: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8028: }
1.388 raeburn 8029: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8030: if ($saml{$dom_in_effect}{$server}) {
8031: $forsaml = 1;
8032: }
8033: }
1.383 raeburn 8034: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8035: &mt('Alias').': ';
1.373 raeburn 8036: if ($current) {
1.381 raeburn 8037: $aliasrows .= $current;
1.388 raeburn 8038: if ($forsaml) {
1.396 raeburn 8039: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8040: }
1.373 raeburn 8041: } else {
1.383 raeburn 8042: $aliasrows .= &mt('None');
1.373 raeburn 8043: }
1.383 raeburn 8044: $aliasrows .= ' <span class="LC_small">('.
8045: &mt('controlled by domain: [_1]',
8046: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8047: } else {
1.381 raeburn 8048: $dom_in_effect = $dom;
1.388 raeburn 8049: my ($current,$samlon,$samloff);
8050: $samloff = ' checked="checked"';
1.373 raeburn 8051: if (ref($aliases{$dom}) eq 'HASH') {
8052: if ($aliases{$dom}{$server}) {
8053: $current = $aliases{$dom}{$server};
8054: }
8055: }
1.388 raeburn 8056: if (ref($saml{$dom}) eq 'HASH') {
8057: if ($saml{$dom}{$server}) {
8058: $samlon = $samloff;
8059: undef($samloff);
8060: }
8061: }
1.383 raeburn 8062: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8063: &mt('Alias').': '.
1.381 raeburn 8064: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8065: 'value="'.$current.'" size="30" />'.
8066: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8067: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8068: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8069: &mt('No').'</label> <label>'.
8070: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8071: &mt('Yes').'</label></span>'.
8072: '</td>';
1.381 raeburn 8073: }
8074: $aliasrows .= '</tr>';
8075: $aliasinfo{$dom_in_effect} .= $aliasrows;
8076: }
8077: if ($aliasinfo{$dom}) {
8078: my ($onclick,$wafon,$wafoff,$showtable);
8079: $onclick = ' onclick="javascript:toggleWAF();"';
8080: $wafoff = ' checked="checked"';
8081: $showtable = ' style="display:none";';
8082: if ($showdom) {
8083: $wafon = $wafoff;
8084: $wafoff = '';
8085: $showtable = ' style="display:inline;"';
8086: }
8087: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8088: $datatable = '<tr'.$css_class.'>'.
8089: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8090: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8091: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8092: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8093: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8094: &mt('No').'</label></span></td>'.
8095: '<td class="LC_left_item">'.
8096: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8097: '</table></td></tr>';
8098: $itemcount++;
8099: }
1.383 raeburn 8100: if (keys(%otherdoms)) {
8101: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8102: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8103: $datatable .= '<tr'.$css_class.'>'.
8104: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8105: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8106: '</table></td></tr>';
1.381 raeburn 8107: $itemcount++;
1.373 raeburn 8108: }
8109: }
8110: } else {
1.383 raeburn 8111: my %ip_methods = &remoteip_methods();
1.373 raeburn 8112: if ($setdom) {
8113: $itemcount ++;
8114: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8115: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8116: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8117: $wafstyle = ' style="display:none;"';
8118: $nowafstyle = ' style="display:table-row;"';
8119: $currwafdisplay = ' style="display: none"';
8120: $wafrangestyle = ' style="display: none"';
8121: $curr_remotip = 'n';
1.382 raeburn 8122: $ssltossl = ' checked="checked"';
1.381 raeburn 8123: if ($showdom) {
8124: $wafstyle = ' style="display:table-row;"';
8125: $nowafstyle = ' style="display:none;"';
8126: if (keys(%{$values{$dom}})) {
8127: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8128: $curr_remotip = $values{$dom}{remoteip};
8129: }
8130: if ($curr_remotip eq 'h') {
8131: $currwafdisplay = ' style="display:table-row"';
8132: $wafrangestyle = ' style="display:inline-block;"';
8133: }
1.382 raeburn 8134: if ($values{$dom}{'sslopt'}) {
8135: $alltossl = ' checked="checked"';
8136: $ssltossl = '';
8137: }
1.381 raeburn 8138: }
8139: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8140: $vpndircheck = ' checked="checked"';
8141: $currwafvpn = ' style="display:table-row;"';
8142: $wafrangestyle = ' style="display:inline-block;"';
8143: } else {
8144: $vpnaliascheck = ' checked="checked"';
8145: $currwafvpn = ' style="display:none;"';
8146: }
8147: }
8148: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8149: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8150: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8151: '</tr>'.
8152: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8153: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8154: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8155: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8156: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8157: '<td class="LC_left_item"><table>'.
8158: '<tr>'.
8159: '<td valign="top">'.$lt{'remoteip'}.': '.
8160: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8161: foreach my $option ('m','h','n') {
8162: my $sel;
8163: if ($option eq $curr_remotip) {
8164: $sel = ' selected="selected"';
8165: }
8166: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8167: $ip_methods{$option}.'</option>';
8168: }
8169: $datatable .= '</select></td></tr>'."\n".
8170: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8171: $lt{'ipheader'}.': '.
8172: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8173: 'name="wafproxy_ipheader" />'.
8174: '</td></tr>'."\n".
8175: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8176: $lt{'trusted'}.':<br />'.
1.381 raeburn 8177: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8178: $values{$dom}{'trusted'}.'</textarea>'.
8179: '</td></tr>'."\n".
8180: '<tr><td><hr /></td></tr>'."\n".
8181: '<tr>'.
8182: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8183: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8184: $lt{'vpndirect'}.'</label>'.(' 'x2).
8185: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8186: $lt{'vpnaliased'}.'</label></span></td></tr>';
8187: foreach my $item ('vpnint','vpnext') {
8188: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8189: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8190: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8191: $values{$dom}{$item}.'</textarea>'.
8192: '</td></tr>'."\n";
1.373 raeburn 8193: }
1.382 raeburn 8194: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8195: '<tr>'.
8196: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8197: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8198: $lt{'alltossl'}.'</label>'.(' 'x2).
8199: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8200: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8201: '</table></td></tr>';
1.373 raeburn 8202: }
8203: if (keys(%otherdoms)) {
8204: foreach my $domain (sort(keys(%otherdoms))) {
8205: $itemcount ++;
8206: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8207: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8208: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8209: '<td class="LC_left_item"><table>';
1.382 raeburn 8210: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8211: my $showval = &mt('None');
1.382 raeburn 8212: if ($item eq 'ssl') {
8213: $showval = $lt{'ssltossl'};
8214: }
1.373 raeburn 8215: if ($values{$domain}{$item}) {
1.381 raeburn 8216: $showval = $values{$domain}{$item};
1.382 raeburn 8217: if ($item eq 'ssl') {
8218: $showval = $lt{'alltossl'};
1.383 raeburn 8219: } elsif ($item eq 'remoteip') {
8220: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8221: }
1.373 raeburn 8222: }
8223: $datatable .= '<tr>'.
8224: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8225: }
1.381 raeburn 8226: $datatable .= '</table></td></tr>';
1.373 raeburn 8227: }
8228: }
8229: }
8230: $$rowtotal += $itemcount;
8231: return $datatable;
8232: }
8233:
8234: sub wafproxy_titles {
8235: return &Apache::lonlocal::texthash(
1.381 raeburn 8236: remoteip => "Method for determining user's IP",
8237: ipheader => 'Request header containing remote IP',
8238: trusted => 'Trusted IP range(s)',
8239: vpnaccess => 'Access from institutional VPN',
8240: vpndirect => 'via regular hostname (no WAF)',
8241: vpnaliased => 'via aliased hostname (WAF)',
8242: vpnint => 'Internal IP Range(s) for VPN sessions',
8243: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8244: sslopt => 'Forwarding http/https',
1.381 raeburn 8245: alltossl => 'WAF forwards both http and https requests to https',
8246: ssltossl => 'WAF forwards http requests to http and https to https',
8247: );
8248: }
8249:
8250: sub remoteip_methods {
8251: return &Apache::lonlocal::texthash(
8252: m => 'Use Apache mod_remoteip',
8253: h => 'Use headers parsed by LON-CAPA',
8254: n => 'Not in use',
1.373 raeburn 8255: );
8256: }
8257:
1.137 raeburn 8258: sub print_usersessions {
8259: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8260: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8261: my (%by_ip,%by_location,@intdoms,@instdoms);
8262: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8263:
8264: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8265: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8266: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8267: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8268: if ($position eq 'top') {
1.152 raeburn 8269: if (keys(%serverhomes) > 1) {
1.145 raeburn 8270: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8271: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8272: if (ref($settings) eq 'HASH') {
8273: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8274: $curroffloadnow = $settings->{'offloadnow'};
8275: }
1.371 raeburn 8276: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8277: $curroffloadoth = $settings->{'offloadoth'};
8278: }
1.261 raeburn 8279: }
1.371 raeburn 8280: my $other_insts = scalar(keys(%by_location));
8281: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8282: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8283: } else {
1.140 raeburn 8284: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8285: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8286: '</td></tr>';
1.140 raeburn 8287: }
1.137 raeburn 8288: } else {
1.279 raeburn 8289: my %titles = &usersession_titles();
8290: my ($prefix,@types);
8291: if ($position eq 'bottom') {
8292: $prefix = 'remote';
8293: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8294: } else {
1.279 raeburn 8295: $prefix = 'hosted';
8296: @types = ('excludedomain','includedomain');
8297: }
8298: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8299: }
8300: $$rowtotal += $itemcount;
8301: return $datatable;
8302: }
8303:
8304: sub rules_by_location {
8305: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8306: my ($datatable,$itemcount,$css_class);
8307: if (keys(%{$by_location}) == 0) {
8308: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8309: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8310: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8311: '</td></tr>';
8312: $itemcount = 1;
8313: } else {
8314: $itemcount = 0;
8315: my $numinrow = 5;
8316: my (%current,%checkedon,%checkedoff);
8317: my @locations = sort(keys(%{$by_location}));
8318: foreach my $type (@{$types}) {
8319: $checkedon{$type} = '';
8320: $checkedoff{$type} = ' checked="checked"';
8321: }
8322: if (ref($settings) eq 'HASH') {
8323: if (ref($settings->{$prefix}) eq 'HASH') {
8324: foreach my $key (keys(%{$settings->{$prefix}})) {
8325: $current{$key} = $settings->{$prefix}{$key};
8326: if ($key eq 'version') {
8327: if ($current{$key} ne '') {
1.145 raeburn 8328: $checkedon{$key} = ' checked="checked"';
8329: $checkedoff{$key} = '';
8330: }
1.279 raeburn 8331: } elsif (ref($current{$key}) eq 'ARRAY') {
8332: $checkedon{$key} = ' checked="checked"';
8333: $checkedoff{$key} = '';
1.137 raeburn 8334: }
8335: }
8336: }
1.279 raeburn 8337: }
8338: foreach my $type (@{$types}) {
8339: next if ($type ne 'version' && !@locations);
8340: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8341: $datatable .= '<tr'.$css_class.'>
8342: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8343: <span class="LC_nobreak">
8344: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8345: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8346: if ($type eq 'version') {
8347: my @lcversions = &Apache::lonnet::all_loncaparevs();
8348: my $selector = '<select name="'.$prefix.'_version">';
8349: foreach my $version (@lcversions) {
8350: my $selected = '';
8351: if ($current{'version'} eq $version) {
8352: $selected = ' selected="selected"';
1.145 raeburn 8353: }
1.279 raeburn 8354: $selector .= ' <option value="'.$version.'"'.
8355: $selected.'>'.$version.'</option>';
8356: }
8357: $selector .= '</select> ';
8358: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8359: } else {
8360: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8361: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8362: ' />'.(' 'x2).
8363: '<input type="button" value="'.&mt('uncheck all').'" '.
8364: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8365: "\n".
8366: '</div><div><table>';
8367: my $rem;
8368: for (my $i=0; $i<@locations; $i++) {
8369: my ($showloc,$value,$checkedtype);
8370: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8371: my $ip = $by_location->{$locations[$i]}->[0];
8372: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8373: $value = join(':',@{$by_ip->{$ip}});
8374: $showloc = join(', ',@{$by_ip->{$ip}});
8375: if (ref($current{$type}) eq 'ARRAY') {
8376: foreach my $loc (@{$by_ip->{$ip}}) {
8377: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8378: $checkedtype = ' checked="checked"';
8379: last;
1.145 raeburn 8380: }
1.138 raeburn 8381: }
8382: }
8383: }
1.137 raeburn 8384: }
1.279 raeburn 8385: $rem = $i%($numinrow);
8386: if ($rem == 0) {
8387: if ($i > 0) {
8388: $datatable .= '</tr>';
8389: }
8390: $datatable .= '<tr>';
8391: }
8392: $datatable .= '<td class="LC_left_item">'.
8393: '<span class="LC_nobreak"><label>'.
8394: '<input type="checkbox" name="'.$prefix.'_'.$type.
8395: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8396: '</label></span></td>';
8397: }
8398: $rem = @locations%($numinrow);
8399: my $colsleft = $numinrow - $rem;
8400: if ($colsleft > 1 ) {
8401: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8402: ' </td>';
8403: } elsif ($colsleft == 1) {
8404: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8405: }
1.279 raeburn 8406: $datatable .= '</tr></table>';
1.137 raeburn 8407: }
1.279 raeburn 8408: $datatable .= '</td></tr>';
8409: $itemcount ++;
1.137 raeburn 8410: }
8411: }
1.279 raeburn 8412: return ($datatable,$itemcount);
1.137 raeburn 8413: }
8414:
1.275 raeburn 8415: sub print_ssl {
8416: my ($position,$dom,$settings,$rowtotal) = @_;
8417: my ($css_class,$datatable);
8418: my $itemcount = 1;
8419: if ($position eq 'top') {
1.281 raeburn 8420: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8421: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8422: my $same_institution;
8423: if ($intdom ne '') {
8424: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8425: if (ref($internet_names) eq 'ARRAY') {
8426: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8427: $same_institution = 1;
8428: }
8429: }
8430: }
1.275 raeburn 8431: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8432: $datatable = '<tr'.$css_class.'><td colspan="2">';
8433: if ($same_institution) {
8434: my %domservers = &Apache::lonnet::get_servers($dom);
8435: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8436: } else {
8437: $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.");
8438: }
8439: $datatable .= '</td></tr>';
1.275 raeburn 8440: $itemcount ++;
8441: } else {
8442: my %titles = &ssl_titles();
8443: my (%by_ip,%by_location,@intdoms,@instdoms);
8444: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8445: my @alldoms = &Apache::lonnet::all_domains();
8446: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8447: my @domservers = &Apache::lonnet::get_servers($dom);
8448: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8449: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8450: if (($position eq 'connto') || ($position eq 'connfrom')) {
8451: my $legacy;
8452: unless (ref($settings) eq 'HASH') {
8453: my $name;
8454: if ($position eq 'connto') {
8455: $name = 'loncAllowInsecure';
8456: } else {
8457: $name = 'londAllowInsecure';
8458: }
8459: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8460: my @ids=&Apache::lonnet::current_machine_ids();
8461: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8462: my %what = (
8463: $name => 1,
8464: );
8465: my ($result,$returnhash) =
8466: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8467: if ($result eq 'ok') {
8468: if (ref($returnhash) eq 'HASH') {
8469: $legacy = $returnhash->{$name};
8470: }
8471: }
8472: } else {
8473: $legacy = $Apache::lonnet::perlvar{$name};
8474: }
8475: }
1.275 raeburn 8476: foreach my $type ('dom','intdom','other') {
8477: my %checked;
8478: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8479: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8480: '<td class="LC_right_item">';
8481: my $skip;
8482: if ($type eq 'dom') {
8483: unless (keys(%servers) > 1) {
8484: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8485: $skip = 1;
8486: }
8487: }
8488: if ($type eq 'intdom') {
8489: unless (@instdoms > 1) {
8490: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8491: $skip = 1;
8492: }
8493: } elsif ($type eq 'other') {
8494: if (keys(%by_location) == 0) {
8495: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8496: $skip = 1;
8497: }
8498: }
8499: unless ($skip) {
8500: $checked{'yes'} = ' checked="checked"';
8501: if (ref($settings) eq 'HASH') {
1.293 raeburn 8502: if (ref($settings->{$position}) eq 'HASH') {
8503: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8504: $checked{$1} = $checked{'yes'};
8505: delete($checked{'yes'});
8506: }
8507: }
1.293 raeburn 8508: } else {
8509: if ($legacy == 0) {
8510: $checked{'req'} = $checked{'yes'};
8511: delete($checked{'yes'});
8512: }
1.275 raeburn 8513: }
8514: foreach my $option ('no','yes','req') {
8515: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8516: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8517: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8518: '</label></span>'.(' 'x2);
8519: }
8520: }
8521: $datatable .= '</td></tr>';
8522: $itemcount ++;
8523: }
8524: } else {
8525: my $prefix = 'replication';
8526: my @types = ('certreq','nocertreq');
1.279 raeburn 8527: if (keys(%by_location) == 0) {
8528: $datatable .= '<tr'.$css_class.'><td>'.
8529: &mt('Nothing to set here, as there are no other institutions').
8530: '</td></tr>';
8531: $itemcount ++;
1.275 raeburn 8532: } else {
1.279 raeburn 8533: ($datatable,$itemcount) =
8534: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8535: }
8536: }
8537: }
8538: $$rowtotal += $itemcount;
8539: return $datatable;
8540: }
8541:
8542: sub ssl_titles {
8543: return &Apache::lonlocal::texthash (
8544: dom => 'LON-CAPA servers/VMs from same domain',
8545: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8546: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8547: connto => 'Connections to other servers',
8548: connfrom => 'Connections from other servers',
1.275 raeburn 8549: replication => 'Replicating content to other institutions',
8550: certreq => 'Client certificate required, but specific domains exempt',
8551: nocertreq => 'No client certificate required, except for specific domains',
8552: no => 'SSL not used',
8553: yes => 'SSL Optional (used if available)',
8554: req => 'SSL Required',
8555: );
1.279 raeburn 8556: }
8557:
8558: sub print_trust {
8559: my ($prefix,$dom,$settings,$rowtotal) = @_;
8560: my ($css_class,$datatable,%checked,%choices);
8561: my (%by_ip,%by_location,@intdoms,@instdoms);
8562: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8563: my $itemcount = 1;
8564: my %titles = &trust_titles();
8565: my @types = ('exc','inc');
8566: if ($prefix eq 'top') {
8567: $prefix = 'content';
8568: } elsif ($prefix eq 'bottom') {
8569: $prefix = 'msg';
8570: }
8571: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8572: $$rowtotal += $itemcount;
8573: return $datatable;
8574: }
8575:
8576: sub trust_titles {
8577: return &Apache::lonlocal::texthash(
8578: content => "Access to this domain's content by others",
8579: shared => "Access to other domain's content by this domain",
8580: enroll => "Enrollment in this domain's courses by others",
8581: othcoau => "Co-author roles in this domain for others",
8582: coaurem => "Co-author roles for this domain's users elsewhere",
8583: domroles => "Domain roles in this domain assignable to others",
8584: catalog => "Course Catalog for this domain displayed elsewhere",
8585: reqcrs => "Requests for creation of courses in this domain by others",
8586: msg => "Users in other domains can send messages to this domain",
8587: exc => "Allow all, but exclude specific domains",
8588: inc => "Deny all, but include specific domains",
8589: );
1.275 raeburn 8590: }
8591:
1.138 raeburn 8592: sub build_location_hashes {
1.275 raeburn 8593: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8594: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8595: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8596: my %iphost = &Apache::lonnet::get_iphost();
8597: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8598: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8599: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8600: foreach my $id (@{$iphost{$primary_ip}}) {
8601: my $intdom = &Apache::lonnet::internet_dom($id);
8602: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8603: push(@{$intdoms},$intdom);
8604: }
8605: }
8606: }
8607: foreach my $ip (keys(%iphost)) {
8608: if (ref($iphost{$ip}) eq 'ARRAY') {
8609: foreach my $id (@{$iphost{$ip}}) {
8610: my $location = &Apache::lonnet::internet_dom($id);
8611: if ($location) {
1.275 raeburn 8612: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8613: my $dom = &Apache::lonnet::host_domain($id);
8614: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8615: push(@{$instdoms},$dom);
8616: }
8617: next;
8618: }
1.138 raeburn 8619: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8620: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8621: push(@{$by_ip->{$ip}},$location);
8622: }
8623: } else {
8624: $by_ip->{$ip} = [$location];
8625: }
8626: }
8627: }
8628: }
8629: }
8630: foreach my $ip (sort(keys(%{$by_ip}))) {
8631: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8632: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8633: my $first = $by_ip->{$ip}->[0];
8634: if (ref($by_location->{$first}) eq 'ARRAY') {
8635: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8636: push(@{$by_location->{$first}},$ip);
8637: }
8638: } else {
8639: $by_location->{$first} = [$ip];
8640: }
8641: }
8642: }
8643: return;
8644: }
8645:
1.145 raeburn 8646: sub current_offloads_to {
8647: my ($dom,$settings,$servers) = @_;
8648: my (%spareid,%otherdomconfigs);
1.152 raeburn 8649: if (ref($servers) eq 'HASH') {
1.145 raeburn 8650: foreach my $lonhost (sort(keys(%{$servers}))) {
8651: my $gotspares;
1.152 raeburn 8652: if (ref($settings) eq 'HASH') {
8653: if (ref($settings->{'spares'}) eq 'HASH') {
8654: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8655: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8656: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8657: $gotspares = 1;
8658: }
1.145 raeburn 8659: }
8660: }
8661: unless ($gotspares) {
8662: my $gotspares;
8663: my $serverhomeID =
8664: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8665: my $serverhomedom =
8666: &Apache::lonnet::host_domain($serverhomeID);
8667: if ($serverhomedom ne $dom) {
8668: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8669: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8670: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8671: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8672: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8673: $gotspares = 1;
8674: }
8675: }
8676: } else {
8677: $otherdomconfigs{$serverhomedom} =
8678: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8679: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8680: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8681: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8682: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8683: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8684: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8685: $gotspares = 1;
8686: }
8687: }
8688: }
8689: }
8690: }
8691: }
8692: }
8693: unless ($gotspares) {
8694: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8695: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8696: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8697: } else {
8698: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8699: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8700: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8701: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8702: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8703: } else {
1.150 raeburn 8704: my %what = (
8705: spareid => 1,
8706: );
8707: my ($result,$returnhash) =
8708: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8709: if ($result eq 'ok') {
8710: if (ref($returnhash) eq 'HASH') {
8711: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8712: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8713: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8714: }
8715: }
1.145 raeburn 8716: }
8717: }
8718: }
8719: }
8720: }
8721: }
8722: return %spareid;
8723: }
8724:
8725: sub spares_row {
1.371 raeburn 8726: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8727: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8728: my $css_class;
8729: my $numinrow = 4;
8730: my $itemcount = 1;
8731: my $datatable;
1.152 raeburn 8732: my %typetitles = &sparestype_titles();
8733: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8734: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8735: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8736: my ($othercontrol,$serverdom);
8737: if ($serverhome ne $server) {
8738: $serverdom = &Apache::lonnet::host_domain($serverhome);
8739: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8740: } else {
8741: $serverdom = &Apache::lonnet::host_domain($server);
8742: if ($serverdom ne $dom) {
8743: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8744: }
8745: }
8746: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8747: my ($checkednow,$checkedoth);
1.261 raeburn 8748: if (ref($curroffloadnow) eq 'HASH') {
8749: if ($curroffloadnow->{$server}) {
8750: $checkednow = ' checked="checked"';
8751: }
8752: }
1.371 raeburn 8753: if (ref($curroffloadoth) eq 'HASH') {
8754: if ($curroffloadoth->{$server}) {
8755: $checkedoth = ' checked="checked"';
8756: }
8757: }
1.145 raeburn 8758: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8759: $datatable .= '<tr'.$css_class.'>
8760: <td rowspan="2">
1.183 bisitz 8761: <span class="LC_nobreak">'.
8762: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8763: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8764: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8765: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8766: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8767: "\n";
1.371 raeburn 8768: if ($other_insts) {
8769: $datatable .= '<br />'.
8770: '<span class="LC_nobreak">'."\n".
8771: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8772: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8773: "\n";
8774: }
1.145 raeburn 8775: my (%current,%canselect);
1.152 raeburn 8776: my @choices =
8777: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8778: foreach my $type ('primary','default') {
8779: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8780: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8781: my @spares = @{$spareid->{$server}{$type}};
8782: if (@spares > 0) {
1.152 raeburn 8783: if ($othercontrol) {
8784: $current{$type} = join(', ',@spares);
8785: } else {
8786: $current{$type} .= '<table>';
8787: my $numspares = scalar(@spares);
8788: for (my $i=0; $i<@spares; $i++) {
8789: my $rem = $i%($numinrow);
8790: if ($rem == 0) {
8791: if ($i > 0) {
8792: $current{$type} .= '</tr>';
8793: }
8794: $current{$type} .= '<tr>';
1.145 raeburn 8795: }
1.152 raeburn 8796: $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'".');" /> '.
8797: $spareid->{$server}{$type}[$i].
8798: '</label></td>'."\n";
8799: }
8800: my $rem = @spares%($numinrow);
8801: my $colsleft = $numinrow - $rem;
8802: if ($colsleft > 1 ) {
8803: $current{$type} .= '<td colspan="'.$colsleft.
8804: '" class="LC_left_item">'.
8805: ' </td>';
8806: } elsif ($colsleft == 1) {
8807: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8808: }
1.152 raeburn 8809: $current{$type} .= '</tr></table>';
1.150 raeburn 8810: }
1.145 raeburn 8811: }
8812: }
8813: if ($current{$type} eq '') {
8814: $current{$type} = &mt('None specified');
8815: }
1.152 raeburn 8816: if ($othercontrol) {
8817: if ($type eq 'primary') {
8818: $canselect{$type} = $othercontrol;
8819: }
8820: } else {
8821: $canselect{$type} =
8822: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8823: '<select name="newspare_'.$type.'_'.$server.'" '.
8824: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8825: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8826: if (@choices > 0) {
8827: foreach my $lonhost (@choices) {
8828: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8829: }
8830: }
8831: $canselect{$type} .= '</select>'."\n";
8832: }
8833: } else {
8834: $current{$type} = &mt('Could not be determined');
8835: if ($type eq 'primary') {
8836: $canselect{$type} = $othercontrol;
8837: }
1.145 raeburn 8838: }
1.152 raeburn 8839: if ($type eq 'default') {
8840: $datatable .= '<tr'.$css_class.'>';
8841: }
8842: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8843: '<td>'.$current{$type}.'</td>'."\n".
8844: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8845: }
8846: $itemcount ++;
8847: }
8848: }
8849: $$rowtotal += $itemcount;
8850: return $datatable;
8851: }
8852:
1.152 raeburn 8853: sub possible_newspares {
8854: my ($server,$currspares,$serverhomes,$altids) = @_;
8855: my $serverhostname = &Apache::lonnet::hostname($server);
8856: my %excluded;
8857: if ($serverhostname ne '') {
8858: %excluded = (
8859: $serverhostname => 1,
8860: );
8861: }
8862: if (ref($currspares) eq 'HASH') {
8863: foreach my $type (keys(%{$currspares})) {
8864: if (ref($currspares->{$type}) eq 'ARRAY') {
8865: if (@{$currspares->{$type}} > 0) {
8866: foreach my $curr (@{$currspares->{$type}}) {
8867: my $hostname = &Apache::lonnet::hostname($curr);
8868: $excluded{$hostname} = 1;
8869: }
8870: }
8871: }
8872: }
8873: }
8874: my @choices;
8875: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8876: if (keys(%{$serverhomes}) > 1) {
8877: foreach my $name (sort(keys(%{$serverhomes}))) {
8878: unless ($excluded{$name}) {
8879: if (exists($altids->{$serverhomes->{$name}})) {
8880: push(@choices,$altids->{$serverhomes->{$name}});
8881: } else {
8882: push(@choices,$serverhomes->{$name});
1.145 raeburn 8883: }
8884: }
8885: }
8886: }
8887: }
1.152 raeburn 8888: return sort(@choices);
1.145 raeburn 8889: }
8890:
1.150 raeburn 8891: sub print_loadbalancing {
8892: my ($dom,$settings,$rowtotal) = @_;
8893: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8894: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8895: my $numinrow = 1;
8896: my $datatable;
8897: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8898: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8899: if (ref($settings) eq 'HASH') {
8900: %existing = %{$settings};
8901: }
8902: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8903: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8904: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8905: } else {
8906: return;
8907: }
8908: my ($othertitle,$usertypes,$types) =
8909: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8910: my $rownum = 8;
1.150 raeburn 8911: if (ref($types) eq 'ARRAY') {
8912: $rownum += scalar(@{$types});
8913: }
1.171 raeburn 8914: my @css_class = ('LC_odd_row','LC_even_row');
8915: my $balnum = 0;
8916: my $islast;
8917: my (@toshow,$disabledtext);
8918: if (keys(%currbalancer) > 0) {
8919: @toshow = sort(keys(%currbalancer));
8920: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8921: push(@toshow,'');
8922: }
8923: } else {
8924: @toshow = ('');
8925: $disabledtext = &mt('No existing load balancer');
8926: }
8927: foreach my $lonhost (@toshow) {
8928: if ($balnum == scalar(@toshow)-1) {
8929: $islast = 1;
8930: } else {
8931: $islast = 0;
8932: }
8933: my $cssidx = $balnum%2;
8934: my $targets_div_style = 'display: none';
8935: my $disabled_div_style = 'display: block';
8936: my $homedom_div_style = 'display: none';
8937: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8938: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8939: '<p>';
8940: if ($lonhost eq '') {
1.210 raeburn 8941: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8942: if (keys(%currbalancer) > 0) {
8943: $datatable .= &mt('Add balancer:');
8944: } else {
8945: $datatable .= &mt('Enable balancer:');
8946: }
8947: $datatable .= ' '.
8948: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8949: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8950: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8951: '<option value="" selected="selected">'.&mt('None').
8952: '</option>'."\n";
8953: foreach my $server (sort(keys(%servers))) {
8954: next if ($currbalancer{$server});
8955: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8956: }
1.210 raeburn 8957: $datatable .=
1.171 raeburn 8958: '</select>'."\n".
8959: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8960: } else {
8961: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8962: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8963: &mt('Stop balancing').'</label>'.
8964: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8965: $targets_div_style = 'display: block';
8966: $disabled_div_style = 'display: none';
8967: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8968: $homedom_div_style = 'display: block';
8969: }
8970: }
1.306 raeburn 8971: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8972: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8973: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8974: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8975: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8976: my @sparestypes = ('primary','default');
8977: my %typetitles = &sparestype_titles();
1.284 raeburn 8978: my %hostherechecked = (
8979: no => ' checked="checked"',
8980: );
1.342 raeburn 8981: my %balcookiechecked = (
8982: no => ' checked="checked"',
8983: );
1.171 raeburn 8984: foreach my $sparetype (@sparestypes) {
8985: my $targettable;
8986: for (my $i=0; $i<$numspares; $i++) {
8987: my $checked;
8988: if (ref($currtargets{$lonhost}) eq 'HASH') {
8989: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8990: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8991: $checked = ' checked="checked"';
8992: }
8993: }
8994: }
8995: my ($chkboxval,$disabled);
8996: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8997: $chkboxval = $spares[$i];
8998: }
8999: if (exists($currbalancer{$spares[$i]})) {
9000: $disabled = ' disabled="disabled"';
9001: }
1.210 raeburn 9002: $targettable .=
1.253 raeburn 9003: '<td><span class="LC_nobreak"><label>'.
9004: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9005: $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 9006: '</span></label></span></td>';
1.171 raeburn 9007: my $rem = $i%($numinrow);
9008: if ($rem == 0) {
9009: if (($i > 0) && ($i < $numspares-1)) {
9010: $targettable .= '</tr>';
9011: }
9012: if ($i < $numspares-1) {
9013: $targettable .= '<tr>';
1.150 raeburn 9014: }
9015: }
9016: }
1.171 raeburn 9017: if ($targettable ne '') {
9018: my $rem = $numspares%($numinrow);
9019: my $colsleft = $numinrow - $rem;
9020: if ($colsleft > 1 ) {
9021: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9022: ' </td>';
9023: } elsif ($colsleft == 1) {
9024: $targettable .= '<td class="LC_left_item"> </td>';
9025: }
9026: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9027: '<table><tr>'.$targettable.'</tr></table><br />';
9028: }
1.284 raeburn 9029: $hostherechecked{$sparetype} = '';
9030: if (ref($currtargets{$lonhost}) eq 'HASH') {
9031: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9032: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9033: $hostherechecked{$sparetype} = ' checked="checked"';
9034: $hostherechecked{'no'} = '';
9035: }
9036: }
9037: }
9038: }
1.342 raeburn 9039: if ($currcookies{$lonhost}) {
9040: %balcookiechecked = (
9041: yes => ' checked="checked"',
9042: );
9043: }
1.284 raeburn 9044: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9045: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9046: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9047: foreach my $sparetype (@sparestypes) {
9048: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9049: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9050: '</i></label><br />';
1.171 raeburn 9051: }
1.342 raeburn 9052: $datatable .= &mt('Use balancer cookie').'<br />'.
9053: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9054: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9055: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9056: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9057: '</div></td></tr>'.
1.171 raeburn 9058: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9059: $othertitle,$usertypes,$types,\%servers,
9060: \%currbalancer,$lonhost,
9061: $targets_div_style,$homedom_div_style,
9062: $css_class[$cssidx],$balnum,$islast);
9063: $$rowtotal += $rownum;
9064: $balnum ++;
9065: }
9066: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9067: return $datatable;
9068: }
9069:
9070: sub get_loadbalancers_config {
1.342 raeburn 9071: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9072: return unless ((ref($servers) eq 'HASH') &&
9073: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9074: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9075: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9076: if (keys(%{$existing}) > 0) {
9077: my $oldlonhost;
9078: foreach my $key (sort(keys(%{$existing}))) {
9079: if ($key eq 'lonhost') {
9080: $oldlonhost = $existing->{'lonhost'};
9081: $currbalancer->{$oldlonhost} = 1;
9082: } elsif ($key eq 'targets') {
9083: if ($oldlonhost) {
9084: $currtargets->{$oldlonhost} = $existing->{'targets'};
9085: }
9086: } elsif ($key eq 'rules') {
9087: if ($oldlonhost) {
9088: $currrules->{$oldlonhost} = $existing->{'rules'};
9089: }
9090: } elsif (ref($existing->{$key}) eq 'HASH') {
9091: $currbalancer->{$key} = 1;
9092: $currtargets->{$key} = $existing->{$key}{'targets'};
9093: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9094: if ($existing->{$key}{'cookie'}) {
9095: $currcookies->{$key} = 1;
9096: }
1.150 raeburn 9097: }
9098: }
1.171 raeburn 9099: } else {
9100: my ($balancerref,$targetsref) =
9101: &Apache::lonnet::get_lonbalancer_config($servers);
9102: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9103: foreach my $server (sort(keys(%{$balancerref}))) {
9104: $currbalancer->{$server} = 1;
9105: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9106: }
9107: }
9108: }
1.171 raeburn 9109: return;
1.150 raeburn 9110: }
9111:
9112: sub loadbalancing_rules {
9113: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9114: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9115: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9116: my $output;
1.171 raeburn 9117: my $num = 0;
1.210 raeburn 9118: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9119: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9120: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9121: foreach my $type (@{$alltypes}) {
1.171 raeburn 9122: $num ++;
1.150 raeburn 9123: my $current;
9124: if (ref($currrules) eq 'HASH') {
9125: $current = $currrules->{$type};
9126: }
1.253 raeburn 9127: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9128: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9129: $current = '';
9130: }
9131: }
9132: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9133: $servers,$currbalancer,$lonhost,$dom,
9134: $targets_div_style,$homedom_div_style,
9135: $css_class,$balnum,$num,$islast);
1.150 raeburn 9136: }
9137: }
9138: return $output;
9139: }
9140:
9141: sub loadbalancing_titles {
9142: my ($dom,$intdom,$usertypes,$types) = @_;
9143: my %othertypes = (
9144: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9145: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9146: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9147: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9148: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9149: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9150: );
1.209 raeburn 9151: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9152: my @available;
1.150 raeburn 9153: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9154: @available = @{$types};
1.150 raeburn 9155: }
1.302 raeburn 9156: unless (grep(/^default$/,@available)) {
9157: push(@available,'default');
9158: }
9159: unshift(@alltypes,@available);
1.150 raeburn 9160: my %titles;
9161: foreach my $type (@alltypes) {
9162: if ($type =~ /^_LC_/) {
9163: $titles{$type} = $othertypes{$type};
9164: } elsif ($type eq 'default') {
9165: $titles{$type} = &mt('All users from [_1]',$dom);
9166: if (ref($types) eq 'ARRAY') {
9167: if (@{$types} > 0) {
9168: $titles{$type} = &mt('Other users from [_1]',$dom);
9169: }
9170: }
9171: } elsif (ref($usertypes) eq 'HASH') {
9172: $titles{$type} = $usertypes->{$type};
9173: }
9174: }
9175: return (\@alltypes,\%othertypes,\%titles);
9176: }
9177:
9178: sub loadbalance_rule_row {
1.171 raeburn 9179: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9180: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9181: my @rulenames;
1.150 raeburn 9182: my %ruletitles = &offloadtype_text();
1.209 raeburn 9183: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9184: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9185: } else {
1.209 raeburn 9186: @rulenames = ('default','homeserver');
9187: if ($type eq '_LC_external') {
9188: push(@rulenames,'externalbalancer');
9189: } else {
9190: push(@rulenames,'specific');
9191: }
9192: push(@rulenames,'none');
1.150 raeburn 9193: }
9194: my $style = $targets_div_style;
1.253 raeburn 9195: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9196: $style = $homedom_div_style;
9197: }
1.171 raeburn 9198: my $space;
9199: if ($islast && $num == 1) {
1.317 raeburn 9200: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9201: }
1.210 raeburn 9202: my $output =
1.306 raeburn 9203: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9204: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9205: '<td valaign="top">'.$space.
9206: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9207: for (my $i=0; $i<@rulenames; $i++) {
9208: my $rule = $rulenames[$i];
9209: my ($checked,$extra);
9210: if ($rulenames[$i] eq 'default') {
9211: $rule = '';
9212: }
9213: if ($rulenames[$i] eq 'specific') {
9214: if (ref($servers) eq 'HASH') {
9215: my $default;
9216: if (($current ne '') && (exists($servers->{$current}))) {
9217: $checked = ' checked="checked"';
9218: }
9219: unless ($checked) {
9220: $default = ' selected="selected"';
9221: }
1.210 raeburn 9222: $extra =
1.171 raeburn 9223: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9224: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9225: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9226: '<option value=""'.$default.'></option>'."\n";
9227: foreach my $server (sort(keys(%{$servers}))) {
9228: if (ref($currbalancer) eq 'HASH') {
9229: next if (exists($currbalancer->{$server}));
9230: }
1.150 raeburn 9231: my $selected;
1.171 raeburn 9232: if ($server eq $current) {
1.150 raeburn 9233: $selected = ' selected="selected"';
9234: }
1.171 raeburn 9235: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9236: }
9237: $extra .= '</select>';
9238: }
9239: } elsif ($rule eq $current) {
9240: $checked = ' checked="checked"';
9241: }
9242: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9243: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9244: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9245: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9246: ')"'.$checked.' /> ';
9247: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9248: $output .= $ruletitles{'particular'};
9249: } else {
9250: $output .= $ruletitles{$rulenames[$i]};
9251: }
9252: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9253: }
9254: $output .= '</div></td></tr>'."\n";
9255: return $output;
9256: }
9257:
9258: sub offloadtype_text {
9259: my %ruletitles = &Apache::lonlocal::texthash (
9260: 'default' => 'Offloads to default destinations',
9261: 'homeserver' => "Offloads to user's home server",
9262: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9263: 'specific' => 'Offloads to specific server',
1.161 raeburn 9264: 'none' => 'No offload',
1.209 raeburn 9265: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9266: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9267: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9268: );
9269: return %ruletitles;
9270: }
9271:
9272: sub sparestype_titles {
9273: my %typestitles = &Apache::lonlocal::texthash (
9274: 'primary' => 'primary',
9275: 'default' => 'default',
9276: );
9277: return %typestitles;
9278: }
9279:
1.28 raeburn 9280: sub contact_titles {
9281: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9282: 'supportemail' => 'Support E-mail address',
9283: 'adminemail' => 'Default Server Admin E-mail address',
9284: 'errormail' => 'Error reports to be e-mailed to',
9285: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9286: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9287: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9288: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9289: 'requestsmail' => 'E-mail from course requests requiring approval',
9290: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9291: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9292: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9293: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9294: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9295: 'errorweights' => 'Weights used to compute error count',
9296: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9297: );
9298: my %short_titles = &Apache::lonlocal::texthash (
9299: adminemail => 'Admin E-mail address',
9300: supportemail => 'Support E-mail',
9301: );
9302: return (\%titles,\%short_titles);
9303: }
9304:
1.286 raeburn 9305: sub helpform_fields {
9306: my %titles = &Apache::lonlocal::texthash (
9307: 'username' => 'Name',
9308: 'user' => 'Username/domain',
9309: 'phone' => 'Phone',
9310: 'cc' => 'Cc e-mail',
9311: 'course' => 'Course Details',
9312: 'section' => 'Sections',
1.289 raeburn 9313: 'screenshot' => 'File upload',
1.286 raeburn 9314: );
9315: my @fields = ('username','phone','user','course','section','cc','screenshot');
9316: my %possoptions = (
9317: username => ['yes','no','req'],
1.289 raeburn 9318: phone => ['yes','no','req'],
1.286 raeburn 9319: user => ['yes','no'],
1.289 raeburn 9320: cc => ['yes','no'],
1.286 raeburn 9321: course => ['yes','no'],
9322: section => ['yes','no'],
9323: screenshot => ['yes','no'],
9324: );
9325: my %fieldoptions = &Apache::lonlocal::texthash (
9326: 'yes' => 'Optional',
9327: 'req' => 'Required',
9328: 'no' => "Not shown",
9329: );
9330: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9331: }
9332:
1.72 raeburn 9333: sub tool_titles {
9334: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9335: aboutme => 'Personal web page',
1.86 raeburn 9336: blog => 'Blog',
1.162 raeburn 9337: webdav => 'WebDAV',
1.86 raeburn 9338: portfolio => 'Portfolio',
1.88 bisitz 9339: official => 'Official courses (with institutional codes)',
9340: unofficial => 'Unofficial courses',
1.98 raeburn 9341: community => 'Communities',
1.216 raeburn 9342: textbook => 'Textbook courses',
1.271 raeburn 9343: placement => 'Placement tests',
1.86 raeburn 9344: );
1.72 raeburn 9345: return %titles;
9346: }
9347:
1.101 raeburn 9348: sub courserequest_titles {
9349: my %titles = &Apache::lonlocal::texthash (
9350: official => 'Official',
9351: unofficial => 'Unofficial',
9352: community => 'Communities',
1.216 raeburn 9353: textbook => 'Textbook',
1.271 raeburn 9354: placement => 'Placement tests',
1.325 raeburn 9355: lti => 'LTI Provider',
1.101 raeburn 9356: norequest => 'Not allowed',
1.325 raeburn 9357: approval => 'Approval by DC',
1.101 raeburn 9358: validate => 'With validation',
9359: autolimit => 'Numerical limit',
1.103 raeburn 9360: unlimited => '(blank for unlimited)',
1.101 raeburn 9361: );
9362: return %titles;
9363: }
9364:
1.163 raeburn 9365: sub authorrequest_titles {
9366: my %titles = &Apache::lonlocal::texthash (
9367: norequest => 'Not allowed',
9368: approval => 'Approval by Dom. Coord.',
9369: automatic => 'Automatic approval',
9370: );
9371: return %titles;
1.210 raeburn 9372: }
1.163 raeburn 9373:
1.101 raeburn 9374: sub courserequest_conditions {
9375: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9376: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9377: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9378: );
9379: return %conditions;
9380: }
9381:
9382:
1.27 raeburn 9383: sub print_usercreation {
1.30 raeburn 9384: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9385: my $numinrow = 4;
1.28 raeburn 9386: my $datatable;
9387: if ($position eq 'top') {
1.30 raeburn 9388: $$rowtotal ++;
1.34 raeburn 9389: my $rowcount = 0;
1.32 raeburn 9390: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9391: if (ref($rules) eq 'HASH') {
9392: if (keys(%{$rules}) > 0) {
1.32 raeburn 9393: $datatable .= &user_formats_row('username',$settings,$rules,
9394: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9395: $$rowtotal ++;
1.32 raeburn 9396: $rowcount ++;
9397: }
9398: }
9399: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9400: if (ref($idrules) eq 'HASH') {
9401: if (keys(%{$idrules}) > 0) {
9402: $datatable .= &user_formats_row('id',$settings,$idrules,
9403: $idruleorder,$numinrow,$rowcount);
9404: $$rowtotal ++;
9405: $rowcount ++;
1.28 raeburn 9406: }
9407: }
1.39 raeburn 9408: if ($rowcount == 0) {
9409: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9410: $$rowtotal ++;
9411: $rowcount ++;
9412: }
1.34 raeburn 9413: } elsif ($position eq 'middle') {
1.224 raeburn 9414: my @creators = ('author','course','requestcrs');
1.37 raeburn 9415: my ($rules,$ruleorder) =
9416: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9417: my %lt = &usercreation_types();
9418: my %checked;
9419: if (ref($settings) eq 'HASH') {
9420: if (ref($settings->{'cancreate'}) eq 'HASH') {
9421: foreach my $item (@creators) {
9422: $checked{$item} = $settings->{'cancreate'}{$item};
9423: }
9424: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9425: foreach my $item (@creators) {
9426: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9427: $checked{$item} = 'none';
9428: }
9429: }
9430: }
9431: }
9432: my $rownum = 0;
9433: foreach my $item (@creators) {
9434: $rownum ++;
1.224 raeburn 9435: if ($checked{$item} eq '') {
9436: $checked{$item} = 'any';
1.34 raeburn 9437: }
9438: my $css_class;
9439: if ($rownum%2) {
9440: $css_class = '';
9441: } else {
9442: $css_class = ' class="LC_odd_row" ';
9443: }
9444: $datatable .= '<tr'.$css_class.'>'.
9445: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9446: '</span></td><td style="text-align: right">';
1.224 raeburn 9447: my @options = ('any');
9448: if (ref($rules) eq 'HASH') {
9449: if (keys(%{$rules}) > 0) {
9450: push(@options,('official','unofficial'));
1.37 raeburn 9451: }
9452: }
1.224 raeburn 9453: push(@options,'none');
1.37 raeburn 9454: foreach my $option (@options) {
1.50 raeburn 9455: my $type = 'radio';
1.34 raeburn 9456: my $check = ' ';
1.224 raeburn 9457: if ($checked{$item} eq $option) {
9458: $check = ' checked="checked" ';
1.34 raeburn 9459: }
9460: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9461: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9462: $item.'" value="'.$option.'"'.$check.'/> '.
9463: $lt{$option}.'</label> </span>';
9464: }
9465: $datatable .= '</td></tr>';
9466: }
1.28 raeburn 9467: } else {
9468: my @contexts = ('author','course','domain');
1.325 raeburn 9469: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9470: my %checked;
9471: if (ref($settings) eq 'HASH') {
9472: if (ref($settings->{'authtypes'}) eq 'HASH') {
9473: foreach my $item (@contexts) {
9474: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9475: foreach my $auth (@authtypes) {
9476: if ($settings->{'authtypes'}{$item}{$auth}) {
9477: $checked{$item}{$auth} = ' checked="checked" ';
9478: }
9479: }
9480: }
9481: }
1.27 raeburn 9482: }
1.35 raeburn 9483: } else {
9484: foreach my $item (@contexts) {
1.36 raeburn 9485: foreach my $auth (@authtypes) {
1.35 raeburn 9486: $checked{$item}{$auth} = ' checked="checked" ';
9487: }
9488: }
1.27 raeburn 9489: }
1.28 raeburn 9490: my %title = &context_names();
9491: my %authname = &authtype_names();
9492: my $rownum = 0;
9493: my $css_class;
9494: foreach my $item (@contexts) {
9495: if ($rownum%2) {
9496: $css_class = '';
9497: } else {
9498: $css_class = ' class="LC_odd_row" ';
9499: }
1.30 raeburn 9500: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9501: '<td>'.$title{$item}.
9502: '</td><td class="LC_left_item">'.
9503: '<span class="LC_nobreak">';
9504: foreach my $auth (@authtypes) {
9505: $datatable .= '<label>'.
9506: '<input type="checkbox" name="'.$item.'_auth" '.
9507: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9508: $authname{$auth}.'</label> ';
9509: }
9510: $datatable .= '</span></td></tr>';
9511: $rownum ++;
1.27 raeburn 9512: }
1.30 raeburn 9513: $$rowtotal += $rownum;
1.27 raeburn 9514: }
9515: return $datatable;
9516: }
9517:
1.224 raeburn 9518: sub print_selfcreation {
9519: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9520: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9521: $emaildomain,$datatable);
1.224 raeburn 9522: if (ref($settings) eq 'HASH') {
9523: if (ref($settings->{'cancreate'}) eq 'HASH') {
9524: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9525: if (ref($createsettings) eq 'HASH') {
9526: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9527: @selfcreate = @{$createsettings->{'selfcreate'}};
9528: } elsif ($createsettings->{'selfcreate'} ne '') {
9529: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9530: @selfcreate = ('email','login','sso');
9531: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9532: @selfcreate = ($createsettings->{'selfcreate'});
9533: }
9534: }
9535: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9536: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9537: }
1.305 raeburn 9538: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9539: $emailoptions = $createsettings->{'emailoptions'};
9540: }
1.303 raeburn 9541: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9542: $emailverified = $createsettings->{'emailverified'};
9543: }
9544: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9545: $emaildomain = $createsettings->{'emaildomain'};
9546: }
1.224 raeburn 9547: }
9548: }
9549: }
9550: my %radiohash;
9551: my $numinrow = 4;
9552: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9553: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9554: if ($position eq 'top') {
9555: my %choices = &Apache::lonlocal::texthash (
9556: cancreate_login => 'Institutional Login',
9557: cancreate_sso => 'Institutional Single Sign On',
9558: );
9559: my @toggles = sort(keys(%choices));
9560: my %defaultchecked = (
9561: 'cancreate_login' => 'off',
9562: 'cancreate_sso' => 'off',
9563: );
1.228 raeburn 9564: my ($onclick,$itemcount);
1.224 raeburn 9565: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9566: \%choices,$itemcount,$onclick);
1.228 raeburn 9567: $$rowtotal += $itemcount;
9568:
1.224 raeburn 9569: if (ref($usertypes) eq 'HASH') {
9570: if (keys(%{$usertypes}) > 0) {
9571: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9572: $dom,$numinrow,$othertitle,
1.305 raeburn 9573: 'statustocreate',$rowtotal);
1.224 raeburn 9574: $$rowtotal ++;
9575: }
9576: }
1.240 raeburn 9577: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9578: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9579: $fieldtitles{'inststatus'} = &mt('Institutional status');
9580: my $rem;
9581: my $numperrow = 2;
9582: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9583: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9584: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9585: '<td class="LC_left_item">'."\n".
1.334 raeburn 9586: '<table>'."\n";
1.240 raeburn 9587: for (my $i=0; $i<@fields; $i++) {
9588: $rem = $i%($numperrow);
9589: if ($rem == 0) {
9590: if ($i > 0) {
9591: $datatable .= '</tr>';
9592: }
9593: $datatable .= '<tr>';
9594: }
9595: my $currval;
1.248 raeburn 9596: if (ref($createsettings) eq 'HASH') {
9597: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9598: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9599: }
1.240 raeburn 9600: }
9601: $datatable .= '<td class="LC_left_item">'.
9602: '<span class="LC_nobreak">'.
9603: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9604: 'value="'.$currval.'" size="10" /> '.
9605: $fieldtitles{$fields[$i]}.'</span></td>';
9606: }
9607: my $colsleft = $numperrow - $rem;
9608: if ($colsleft > 1 ) {
9609: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9610: ' </td>';
9611: } elsif ($colsleft == 1) {
9612: $datatable .= '<td class="LC_left_item"> </td>';
9613: }
9614: $datatable .= '</tr></table></td></tr>';
9615: $$rowtotal ++;
1.224 raeburn 9616: } elsif ($position eq 'middle') {
9617: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9618: my @posstypes;
1.224 raeburn 9619: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9620: @posstypes = @{$types};
9621: }
9622: unless (grep(/^default$/,@posstypes)) {
9623: push(@posstypes,'default');
9624: }
9625: my %usertypeshash;
9626: if (ref($usertypes) eq 'HASH') {
9627: %usertypeshash = %{$usertypes};
9628: }
9629: $usertypeshash{'default'} = $othertitle;
9630: foreach my $status (@posstypes) {
9631: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9632: $numinrow,$$rowtotal,\%usertypeshash);
9633: $$rowtotal ++;
1.224 raeburn 9634: }
9635: } else {
1.236 raeburn 9636: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9637: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9638: );
9639: my @toggles = sort(keys(%choices));
9640: my %defaultchecked = (
9641: 'cancreate_email' => 'off',
9642: );
1.305 raeburn 9643: my $customclass = 'LC_selfcreate_email';
9644: my $classprefix = 'LC_canmodify_emailusername_';
9645: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9646: my $display = 'none';
1.305 raeburn 9647: my $rowstyle = 'display:none';
1.236 raeburn 9648: if (grep(/^\Qemail\E$/,@selfcreate)) {
9649: $display = 'block';
1.305 raeburn 9650: $rowstyle = 'display:table-row';
1.236 raeburn 9651: }
1.305 raeburn 9652: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9653: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9654: \%choices,$$rowtotal,$onclick);
9655: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9656: $rowstyle);
9657: $$rowtotal ++;
9658: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9659: $rowstyle);
9660: $$rowtotal ++;
9661: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9662: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9663: my ($emailrules,$emailruleorder) =
9664: &Apache::lonnet::inst_userrules($dom,'email');
9665: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9666: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9667: if (ref($types) eq 'ARRAY') {
9668: @posstypes = @{$types};
9669: }
9670: if (@posstypes) {
9671: unless (grep(/^default$/,@posstypes)) {
9672: push(@posstypes,'default');
1.302 raeburn 9673: }
9674: if (ref($usertypes) eq 'HASH') {
9675: %usertypeshash = %{$usertypes};
9676: }
1.305 raeburn 9677: my $currassign;
9678: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9679: $currassign = {
9680: selfassign => $domdefaults{'inststatusguest'},
9681: };
9682: @ordered = @{$domdefaults{'inststatusguest'}};
9683: } else {
9684: $currassign = { selfassign => [] };
9685: }
9686: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9687: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9688: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9689: $numinrow,$othertitle,'selfassign',
9690: $rowtotal,$onclicktypes,$customclass,
9691: $rowstyle);
9692: $$rowtotal ++;
1.302 raeburn 9693: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9694: foreach my $status (@posstypes) {
9695: my $css_class;
9696: if ($$rowtotal%2) {
9697: $css_class = 'LC_odd_row ';
9698: }
9699: $css_class .= $customclass;
9700: my $rowid = $optionsprefix.$status;
9701: my $hidden = 1;
9702: my $currstyle = 'display:none';
9703: if (grep(/^\Q$status\E$/,@ordered)) {
9704: $currstyle = $rowstyle;
9705: $hidden = 0;
9706: }
9707: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9708: $emailrules,$emailruleorder,$settings,$status,$rowid,
9709: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9710: unless ($hidden) {
9711: $$rowtotal ++;
9712: }
1.224 raeburn 9713: }
1.302 raeburn 9714: } else {
1.305 raeburn 9715: my $css_class;
9716: if ($$rowtotal%2) {
9717: $css_class = 'LC_odd_row ';
9718: }
9719: $css_class .= $customclass;
1.302 raeburn 9720: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9721: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9722: $emailrules,$emailruleorder,$settings,'default','',
9723: $othertitle,$css_class,$rowstyle,$intdom);
9724: $$rowtotal ++;
1.224 raeburn 9725: }
9726: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9727: $numinrow = 1;
1.305 raeburn 9728: if (@posstypes) {
9729: foreach my $status (@posstypes) {
9730: my $rowid = $classprefix.$status;
9731: my $datarowstyle = 'display:none';
9732: if (grep(/^\Q$status\E$/,@ordered)) {
9733: $datarowstyle = $rowstyle;
9734: }
9735: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9736: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9737: $infotitles,$rowid,$customclass,$datarowstyle);
9738: unless ($datarowstyle eq 'display:none') {
9739: $$rowtotal ++;
9740: }
1.224 raeburn 9741: }
1.305 raeburn 9742: } else {
9743: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9744: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9745: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9746: }
9747: }
9748: return $datatable;
9749: }
9750:
1.305 raeburn 9751: sub selfcreate_javascript {
9752: return <<"ENDSCRIPT";
9753:
9754: <script type="text/javascript">
9755: // <![CDATA[
9756:
9757: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9758: var x = document.getElementsByClassName(target);
9759: var insttypes = 0;
9760: var insttypeRegExp = new RegExp(prefix);
9761: if ((x.length != undefined) && (x.length > 0)) {
9762: if (form.elements[radio].length != undefined) {
9763: for (var i=0; i<form.elements[radio].length; i++) {
9764: if (form.elements[radio][i].checked) {
9765: if (form.elements[radio][i].value == 1) {
9766: for (var j=0; j<x.length; j++) {
9767: if (x[j].id == 'undefined') {
9768: x[j].style.display = 'table-row';
9769: } else if (insttypeRegExp.test(x[j].id)) {
9770: insttypes ++;
9771: } else {
9772: x[j].style.display = 'table-row';
9773: }
9774: }
9775: } else {
9776: for (var j=0; j<x.length; j++) {
9777: x[j].style.display = 'none';
9778: }
1.236 raeburn 9779: }
1.305 raeburn 9780: break;
9781: }
9782: }
9783: if (insttypes > 0) {
9784: toggleDataRow(form,checkbox,target,altprefix);
9785: toggleDataRow(form,checkbox,target,prefix,1);
9786: }
9787: }
9788: }
9789: return;
9790: }
9791:
9792: function toggleDataRow(form,checkbox,target,prefix,docount) {
9793: if (form.elements[checkbox].length != undefined) {
9794: var count = 0;
9795: if (docount) {
9796: for (var i=0; i<form.elements[checkbox].length; i++) {
9797: if (form.elements[checkbox][i].checked) {
9798: count ++;
1.236 raeburn 9799: }
1.305 raeburn 9800: }
9801: }
9802: for (var i=0; i<form.elements[checkbox].length; i++) {
9803: var type = form.elements[checkbox][i].value;
9804: if (document.getElementById(prefix+type)) {
9805: if (form.elements[checkbox][i].checked) {
9806: document.getElementById(prefix+type).style.display = 'table-row';
9807: if (count % 2 == 1) {
9808: document.getElementById(prefix+type).className = target+' LC_odd_row';
9809: } else {
9810: document.getElementById(prefix+type).className = target;
1.236 raeburn 9811: }
1.305 raeburn 9812: count ++;
1.236 raeburn 9813: } else {
1.305 raeburn 9814: document.getElementById(prefix+type).style.display = 'none';
9815: }
9816: }
9817: }
9818: }
9819: return;
9820: }
9821:
9822: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9823: var caller = radio+'_'+status;
9824: if (form.elements[caller].length != undefined) {
9825: for (var i=0; i<form.elements[caller].length; i++) {
9826: if (form.elements[caller][i].checked) {
9827: if (document.getElementById(altprefix+'_inst_'+status)) {
9828: var curr = form.elements[caller][i].value;
9829: if (prefix) {
9830: document.getElementById(prefix+'_'+status).style.display = 'none';
9831: }
9832: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9833: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9834: if (curr == 'custom') {
9835: if (prefix) {
9836: document.getElementById(prefix+'_'+status).style.display = 'inline';
9837: }
9838: } else if (curr == 'inst') {
9839: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9840: } else if (curr == 'noninst') {
9841: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9842: }
1.305 raeburn 9843: break;
1.236 raeburn 9844: }
9845: }
9846: }
9847: }
9848: }
9849:
1.305 raeburn 9850: // ]]>
9851: </script>
9852:
9853: ENDSCRIPT
9854: }
9855:
9856: sub noninst_users {
9857: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9858: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9859: my $class = 'LC_left_item';
9860: if ($css_class) {
9861: $css_class = ' class="'.$css_class.'"';
9862: }
9863: if ($rowid) {
9864: $rowid = ' id="'.$rowid.'"';
9865: }
9866: if ($rowstyle) {
9867: $rowstyle = ' style="'.$rowstyle.'"';
9868: }
9869: my ($output,$description);
9870: if ($type eq 'default') {
9871: $description = &mt('Requests for: [_1]',$typetitle);
9872: } else {
9873: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9874: }
9875: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9876: "<td>$description</td>\n".
9877: '<td class="'.$class.'" colspan="2">'.
9878: '<table><tr>';
9879: my %headers = &Apache::lonlocal::texthash(
9880: approve => 'Processing',
9881: email => 'E-mail',
9882: username => 'Username',
9883: );
9884: foreach my $item ('approve','email','username') {
9885: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9886: }
1.305 raeburn 9887: $output .= '</tr><tr>';
9888: foreach my $item ('approve','email','username') {
1.306 raeburn 9889: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9890: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9891: if ($item eq 'approve') {
9892: %choices = &Apache::lonlocal::texthash (
9893: automatic => 'Automatically approved',
9894: approval => 'Queued for approval',
9895: );
9896: @options = ('automatic','approval');
9897: $hashref = $processing;
9898: $defoption = 'automatic';
9899: $name = 'cancreate_emailprocess_'.$type;
9900: } elsif ($item eq 'email') {
9901: %choices = &Apache::lonlocal::texthash (
9902: any => 'Any e-mail',
9903: inst => 'Institutional only',
9904: noninst => 'Non-institutional only',
9905: custom => 'Custom restrictions',
9906: );
9907: @options = ('any','inst','noninst');
9908: my $showcustom;
9909: if (ref($emailrules) eq 'HASH') {
9910: if (keys(%{$emailrules}) > 0) {
9911: push(@options,'custom');
9912: $showcustom = 'cancreate_emailrule';
9913: if (ref($settings) eq 'HASH') {
9914: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9915: foreach my $rule (@{$settings->{'email_rule'}}) {
9916: if (exists($emailrules->{$rule})) {
9917: $hascustom ++;
9918: }
9919: }
9920: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9921: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9922: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9923: if (exists($emailrules->{$rule})) {
9924: $hascustom ++;
9925: }
9926: }
9927: }
9928: }
9929: }
9930: }
9931: }
9932: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9933: "'cancreate_emaildomain','$type'".');"';
9934: $hashref = $emailoptions;
9935: $defoption = 'any';
9936: $name = 'cancreate_emailoptions_'.$type;
9937: } elsif ($item eq 'username') {
9938: %choices = &Apache::lonlocal::texthash (
9939: all => 'Same as e-mail',
9940: first => 'Omit @domain',
9941: free => 'Free to choose',
9942: );
9943: @options = ('all','first','free');
9944: $hashref = $emailverified;
9945: $defoption = 'all';
9946: $name = 'cancreate_usernameoptions_'.$type;
9947: }
9948: foreach my $option (@options) {
9949: my $checked;
9950: if (ref($hashref) eq 'HASH') {
9951: if ($type eq '') {
9952: if (!exists($hashref->{'default'})) {
9953: if ($option eq $defoption) {
9954: $checked = ' checked="checked"';
9955: }
9956: } else {
9957: if ($hashref->{'default'} eq $option) {
9958: $checked = ' checked="checked"';
9959: }
1.303 raeburn 9960: }
9961: } else {
1.305 raeburn 9962: if (!exists($hashref->{$type})) {
9963: if ($option eq $defoption) {
9964: $checked = ' checked="checked"';
9965: }
9966: } else {
9967: if ($hashref->{$type} eq $option) {
9968: $checked = ' checked="checked"';
9969: }
1.303 raeburn 9970: }
9971: }
1.305 raeburn 9972: } elsif (($item eq 'email') && ($hascustom)) {
9973: if ($option eq 'custom') {
9974: $checked = ' checked="checked"';
9975: }
9976: } elsif ($option eq $defoption) {
9977: $checked = ' checked="checked"';
9978: }
9979: $output .= '<span class="LC_nobreak"><label>'.
9980: '<input type="radio" name="'.$name.'"'.
9981: $checked.' value="'.$option.'"'.$onclick.' />'.
9982: $choices{$option}.'</label></span><br />';
9983: if ($item eq 'email') {
9984: if ($option eq 'custom') {
9985: my $id = 'cancreate_emailrule_'.$type;
9986: my $display = 'none';
9987: if ($checked) {
9988: $display = 'inline';
1.303 raeburn 9989: }
1.305 raeburn 9990: my $numinrow = 2;
9991: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9992: '<legend>'.&mt('Disallow').'</legend><table>'.
9993: &user_formats_row('email',$settings,$emailrules,
9994: $emailruleorder,$numinrow,'',$type);
9995: '</table></fieldset>';
9996: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9997: my %text = &Apache::lonlocal::texthash (
9998: inst => 'must end:',
9999: noninst => 'cannot end:',
10000: );
10001: my $value;
10002: if (ref($emaildomain) eq 'HASH') {
10003: if (ref($emaildomain->{$type}) eq 'HASH') {
10004: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10005: }
10006: }
1.305 raeburn 10007: if ($value eq '') {
10008: $value = '@'.$intdom;
10009: }
10010: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10011: my $display = 'none';
10012: if ($checked) {
10013: $display = 'inline';
10014: }
10015: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10016: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10017: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10018: '</div>';
1.303 raeburn 10019: }
10020: }
10021: }
1.305 raeburn 10022: $output .= '</td>'."\n";
1.303 raeburn 10023: }
1.305 raeburn 10024: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10025: return $output;
10026: }
10027:
1.165 raeburn 10028: sub captcha_choice {
1.305 raeburn 10029: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10030: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10031: $vertext,$currver);
1.165 raeburn 10032: my %lt = &captcha_phrases();
10033: $keyentry = 'hidden';
1.354 raeburn 10034: my $colspan=2;
1.165 raeburn 10035: if ($context eq 'cancreate') {
1.224 raeburn 10036: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10037: } elsif ($context eq 'login') {
10038: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10039: } elsif ($context eq 'passwords') {
10040: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10041: $colspan=1;
1.165 raeburn 10042: }
10043: if (ref($settings) eq 'HASH') {
10044: if ($settings->{'captcha'}) {
10045: $checked{$settings->{'captcha'}} = ' checked="checked"';
10046: } else {
10047: $checked{'original'} = ' checked="checked"';
10048: }
10049: if ($settings->{'captcha'} eq 'recaptcha') {
10050: $pubtext = $lt{'pub'};
10051: $privtext = $lt{'priv'};
10052: $keyentry = 'text';
1.269 raeburn 10053: $vertext = $lt{'ver'};
10054: $currver = $settings->{'recaptchaversion'};
10055: if ($currver ne '2') {
10056: $currver = 1;
10057: }
1.165 raeburn 10058: }
10059: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10060: $currpub = $settings->{'recaptchakeys'}{'public'};
10061: $currpriv = $settings->{'recaptchakeys'}{'private'};
10062: }
10063: } else {
10064: $checked{'original'} = ' checked="checked"';
10065: }
1.305 raeburn 10066: my $css_class;
10067: if ($itemcount%2) {
10068: $css_class = 'LC_odd_row';
10069: }
10070: if ($customcss) {
10071: $css_class .= " $customcss";
10072: }
10073: $css_class =~ s/^\s+//;
10074: if ($css_class) {
10075: $css_class = ' class="'.$css_class.'"';
10076: }
10077: if ($rowstyle) {
10078: $css_class .= ' style="'.$rowstyle.'"';
10079: }
1.169 raeburn 10080: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10081: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10082: '<table><tr><td>'."\n";
10083: foreach my $option ('original','recaptcha','notused') {
10084: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10085: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10086: $lt{$option}.'</label></span>';
10087: unless ($option eq 'notused') {
10088: $output .= (' 'x2)."\n";
10089: }
10090: }
10091: #
10092: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10093: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10094: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10095: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10096: #
1.165 raeburn 10097: $output .= '</td></tr>'."\n".
1.305 raeburn 10098: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10099: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10100: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10101: $currpub.'" size="40" /></span><br />'."\n".
10102: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10103: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10104: $currpriv.'" size="40" /></span><br />'.
10105: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10106: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10107: $currver.'" size="3" /></span><br />'.
10108: '</td></tr></table>'."\n".
1.165 raeburn 10109: '</td></tr>';
10110: return $output;
10111: }
10112:
1.32 raeburn 10113: sub user_formats_row {
1.305 raeburn 10114: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10115: my $output;
10116: my %text = (
10117: 'username' => 'new usernames',
10118: 'id' => 'IDs',
10119: );
1.305 raeburn 10120: unless ($type eq 'email') {
10121: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10122: $output = '<tr '.$css_class.'>'.
10123: '<td><span class="LC_nobreak">'.
10124: &mt("Format rules to check for $text{$type}: ").
10125: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10126: }
1.27 raeburn 10127: my $rem;
10128: if (ref($ruleorder) eq 'ARRAY') {
10129: for (my $i=0; $i<@{$ruleorder}; $i++) {
10130: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10131: my $rem = $i%($numinrow);
10132: if ($rem == 0) {
10133: if ($i > 0) {
10134: $output .= '</tr>';
10135: }
10136: $output .= '<tr>';
10137: }
10138: my $check = ' ';
1.39 raeburn 10139: if (ref($settings) eq 'HASH') {
10140: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10141: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10142: $check = ' checked="checked" ';
10143: }
1.305 raeburn 10144: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10145: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10146: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10147: $check = ' checked="checked" ';
10148: }
10149: }
1.27 raeburn 10150: }
10151: }
1.305 raeburn 10152: my $name = $type.'_rule';
10153: if ($type eq 'email') {
10154: $name .= '_'.$status;
10155: }
1.27 raeburn 10156: $output .= '<td class="LC_left_item">'.
10157: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10158: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10159: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10160: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10161: }
10162: }
10163: $rem = @{$ruleorder}%($numinrow);
10164: }
1.305 raeburn 10165: my $colsleft;
10166: if ($rem) {
10167: $colsleft = $numinrow - $rem;
10168: }
1.27 raeburn 10169: if ($colsleft > 1 ) {
10170: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10171: ' </td>';
10172: } elsif ($colsleft == 1) {
10173: $output .= '<td class="LC_left_item"> </td>';
10174: }
1.305 raeburn 10175: $output .= '</tr></table>';
10176: unless ($type eq 'email') {
10177: $output .= '</td></tr>';
10178: }
1.27 raeburn 10179: return $output;
10180: }
10181:
1.34 raeburn 10182: sub usercreation_types {
10183: my %lt = &Apache::lonlocal::texthash (
10184: author => 'When adding a co-author',
10185: course => 'When adding a user to a course',
1.100 raeburn 10186: requestcrs => 'When requesting a course',
1.34 raeburn 10187: any => 'Any',
10188: official => 'Institutional only ',
10189: unofficial => 'Non-institutional only',
10190: none => 'None',
10191: );
10192: return %lt;
1.48 raeburn 10193: }
1.34 raeburn 10194:
1.224 raeburn 10195: sub selfcreation_types {
10196: my %lt = &Apache::lonlocal::texthash (
10197: selfcreate => 'User creates own account',
10198: any => 'Any',
10199: official => 'Institutional only ',
10200: unofficial => 'Non-institutional only',
10201: email => 'E-mail address',
10202: login => 'Institutional Login',
10203: sso => 'SSO',
10204: );
10205: }
10206:
1.28 raeburn 10207: sub authtype_names {
10208: my %lt = &Apache::lonlocal::texthash(
10209: int => 'Internal',
10210: krb4 => 'Kerberos 4',
10211: krb5 => 'Kerberos 5',
10212: loc => 'Local',
1.325 raeburn 10213: lti => 'LTI',
1.28 raeburn 10214: );
10215: return %lt;
10216: }
10217:
10218: sub context_names {
10219: my %context_title = &Apache::lonlocal::texthash(
10220: author => 'Creating users when an Author',
10221: course => 'Creating users when in a course',
10222: domain => 'Creating users when a Domain Coordinator',
10223: );
10224: return %context_title;
10225: }
10226:
1.33 raeburn 10227: sub print_usermodification {
10228: my ($position,$dom,$settings,$rowtotal) = @_;
10229: my $numinrow = 4;
10230: my ($context,$datatable,$rowcount);
10231: if ($position eq 'top') {
10232: $rowcount = 0;
10233: $context = 'author';
10234: foreach my $role ('ca','aa') {
10235: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10236: $numinrow,$rowcount);
10237: $$rowtotal ++;
10238: $rowcount ++;
10239: }
1.230 raeburn 10240: } elsif ($position eq 'bottom') {
1.33 raeburn 10241: $context = 'course';
10242: $rowcount = 0;
10243: foreach my $role ('st','ep','ta','in','cr') {
10244: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10245: $numinrow,$rowcount);
10246: $$rowtotal ++;
10247: $rowcount ++;
10248: }
10249: }
10250: return $datatable;
10251: }
10252:
1.43 raeburn 10253: sub print_defaults {
1.236 raeburn 10254: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10255: my $rownum = 0;
1.294 raeburn 10256: my ($datatable,$css_class,$titles);
10257: unless ($position eq 'bottom') {
10258: $titles = &defaults_titles($dom);
10259: }
1.236 raeburn 10260: if ($position eq 'top') {
10261: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10262: 'datelocale_def','portal_def');
10263: my %defaults;
10264: if (ref($settings) eq 'HASH') {
10265: %defaults = %{$settings};
1.43 raeburn 10266: } else {
1.236 raeburn 10267: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10268: foreach my $item (@items) {
10269: $defaults{$item} = $domdefaults{$item};
10270: }
1.43 raeburn 10271: }
1.236 raeburn 10272: foreach my $item (@items) {
10273: if ($rownum%2) {
10274: $css_class = '';
10275: } else {
10276: $css_class = ' class="LC_odd_row" ';
10277: }
10278: $datatable .= '<tr'.$css_class.'>'.
10279: '<td><span class="LC_nobreak">'.$titles->{$item}.
10280: '</span></td><td class="LC_right_item" colspan="3">';
10281: if ($item eq 'auth_def') {
1.325 raeburn 10282: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10283: my %shortauth = (
10284: internal => 'int',
10285: krb4 => 'krb4',
10286: krb5 => 'krb5',
1.325 raeburn 10287: localauth => 'loc',
10288: lti => 'lti',
1.236 raeburn 10289: );
10290: my %authnames = &authtype_names();
10291: foreach my $auth (@authtypes) {
10292: my $checked = ' ';
10293: if ($defaults{$item} eq $auth) {
10294: $checked = ' checked="checked" ';
10295: }
10296: $datatable .= '<label><input type="radio" name="'.$item.
10297: '" value="'.$auth.'"'.$checked.'/>'.
10298: $authnames{$shortauth{$auth}}.'</label> ';
10299: }
10300: } elsif ($item eq 'timezone_def') {
10301: my $includeempty = 1;
10302: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10303: } elsif ($item eq 'datelocale_def') {
10304: my $includeempty = 1;
10305: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10306: } elsif ($item eq 'lang_def') {
1.263 raeburn 10307: my $includeempty = 1;
10308: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 10309: } else {
10310: my $size;
10311: if ($item eq 'portal_def') {
10312: $size = ' size="25"';
10313: }
10314: $datatable .= '<input type="text" name="'.$item.'" value="'.
10315: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 10316: }
1.236 raeburn 10317: $datatable .= '</td></tr>';
10318: $rownum ++;
10319: }
1.354 raeburn 10320: } else {
1.294 raeburn 10321: my %defaults;
10322: if (ref($settings) eq 'HASH') {
1.354 raeburn 10323: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10324: my $maxnum = @{$settings->{'inststatusorder'}};
10325: for (my $i=0; $i<$maxnum; $i++) {
10326: $css_class = $rownum%2?' class="LC_odd_row"':'';
10327: my $item = $settings->{'inststatusorder'}->[$i];
10328: my $title = $settings->{'inststatustypes'}->{$item};
10329: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10330: $datatable .= '<tr'.$css_class.'>'.
10331: '<td><span class="LC_nobreak">'.
10332: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10333: for (my $k=0; $k<=$maxnum; $k++) {
10334: my $vpos = $k+1;
10335: my $selstr;
10336: if ($k == $i) {
10337: $selstr = ' selected="selected" ';
10338: }
10339: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10340: }
10341: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10342: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10343: &mt('delete').'</span></td>'.
1.380 raeburn 10344: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10345: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10346: '</span></td></tr>';
10347: }
10348: $css_class = $rownum%2?' class="LC_odd_row"':'';
10349: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10350: $datatable .= '<tr '.$css_class.'>'.
10351: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10352: for (my $k=0; $k<=$maxnum; $k++) {
10353: my $vpos = $k+1;
10354: my $selstr;
10355: if ($k == $maxnum) {
10356: $selstr = ' selected="selected" ';
10357: }
10358: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10359: }
10360: $datatable .= '</select> '.&mt('Internal ID:').
10361: '<input type="text" size="10" name="addinststatus" value="" />'.
10362: ' '.&mt('(new)').
10363: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10364: &mt('Name displayed').':'.
1.354 raeburn 10365: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10366: '</tr>'."\n";
10367: $rownum ++;
1.294 raeburn 10368: }
1.354 raeburn 10369: }
10370: }
10371: $$rowtotal += $rownum;
1.43 raeburn 10372: return $datatable;
10373: }
10374:
1.168 raeburn 10375: sub get_languages_hash {
10376: my %langchoices;
10377: foreach my $id (&Apache::loncommon::languageids()) {
10378: my $code = &Apache::loncommon::supportedlanguagecode($id);
10379: if ($code ne '') {
10380: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10381: }
10382: }
10383: return %langchoices;
10384: }
10385:
1.43 raeburn 10386: sub defaults_titles {
1.141 raeburn 10387: my ($dom) = @_;
1.43 raeburn 10388: my %titles = &Apache::lonlocal::texthash (
10389: 'auth_def' => 'Default authentication type',
10390: 'auth_arg_def' => 'Default authentication argument',
10391: 'lang_def' => 'Default language',
1.54 raeburn 10392: 'timezone_def' => 'Default timezone',
1.68 raeburn 10393: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10394: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 10395: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10396: 'intauth_check' => 'Check bcrypt cost if authenticated',
10397: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10398: );
1.141 raeburn 10399: if ($dom) {
10400: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10401: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10402: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10403: $protocol = 'http' if ($protocol ne 'https');
10404: if ($uint_dom) {
10405: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10406: $uint_dom);
10407: }
10408: }
1.43 raeburn 10409: return (\%titles);
10410: }
10411:
1.346 raeburn 10412: sub print_scantron {
10413: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10414: if ($position eq 'top') {
10415: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10416: } else {
10417: return &print_scantronconfig($dom,$settings,\$rowtotal);
10418: }
10419: }
10420:
10421: sub scantron_javascript {
10422: return <<"ENDSCRIPT";
10423:
10424: <script type="text/javascript">
10425: // <![CDATA[
10426:
10427: function toggleScantron(form) {
1.347 raeburn 10428: var csvfieldset = new Array();
1.346 raeburn 10429: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10430: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10431: }
10432: if (document.getElementById('scantroncsv_options')) {
10433: csvfieldset.push(document.getElementById('scantroncsv_options'));
10434: }
10435: if (csvfieldset.length) {
1.346 raeburn 10436: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10437: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10438: if (scantroncsv.checked) {
1.347 raeburn 10439: for (var i=0; i<csvfieldset.length; i++) {
10440: csvfieldset[i].style.display = 'block';
10441: }
1.346 raeburn 10442: } else {
1.347 raeburn 10443: for (var i=0; i<csvfieldset.length; i++) {
10444: csvfieldset[i].style.display = 'none';
10445: }
1.346 raeburn 10446: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10447: if (csvselects.length) {
10448: for (var j=0; j<csvselects.length; j++) {
10449: csvselects[j].selectedIndex = 0;
10450: }
10451: }
10452: }
10453: }
10454: }
10455: return;
10456: }
10457: // ]]>
10458: </script>
10459:
10460: ENDSCRIPT
10461:
10462: }
10463:
1.46 raeburn 10464: sub print_scantronformat {
10465: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10466: my $itemcount = 1;
1.60 raeburn 10467: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10468: %confhash);
1.46 raeburn 10469: my $switchserver = &check_switchserver($dom,$confname);
10470: my %lt = &Apache::lonlocal::texthash (
1.95 www 10471: default => 'Default bubblesheet format file error',
10472: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10473: );
10474: my %scantronfiles = (
10475: default => 'default.tab',
10476: custom => 'custom.tab',
10477: );
10478: foreach my $key (keys(%scantronfiles)) {
10479: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10480: .$scantronfiles{$key};
10481: }
10482: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10483: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10484: if (!$switchserver) {
10485: my $servadm = $r->dir_config('lonAdmEMail');
10486: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10487: if ($configuserok eq 'ok') {
10488: if ($author_ok eq 'ok') {
10489: my %legacyfile = (
1.346 raeburn 10490: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10491: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10492: );
10493: my %md5chk;
10494: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10495: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10496: chomp($md5chk{$type});
1.46 raeburn 10497: }
10498: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10499: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10500: ($scantronurls{$type},my $error) =
1.46 raeburn 10501: &legacy_scantronformat($r,$dom,$confname,
10502: $type,$legacyfile{$type},
10503: $scantronurls{$type},
10504: $scantronfiles{$type});
1.60 raeburn 10505: if ($error ne '') {
10506: $error{$type} = $error;
10507: }
10508: }
10509: if (keys(%error) == 0) {
10510: $is_custom = 1;
1.346 raeburn 10511: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10512: $scantronurls{'custom'};
1.346 raeburn 10513: my $putresult =
1.60 raeburn 10514: &Apache::lonnet::put_dom('configuration',
10515: \%confhash,$dom);
10516: if ($putresult ne 'ok') {
1.346 raeburn 10517: $error{'custom'} =
1.60 raeburn 10518: '<span class="LC_error">'.
10519: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10520: }
1.46 raeburn 10521: }
10522: } else {
1.60 raeburn 10523: ($scantronurls{'default'},my $error) =
1.46 raeburn 10524: &legacy_scantronformat($r,$dom,$confname,
10525: 'default',$legacyfile{'default'},
10526: $scantronurls{'default'},
10527: $scantronfiles{'default'});
1.60 raeburn 10528: if ($error eq '') {
10529: $confhash{'scantron'}{'scantronformat'} = '';
10530: my $putresult =
10531: &Apache::lonnet::put_dom('configuration',
10532: \%confhash,$dom);
10533: if ($putresult ne 'ok') {
10534: $error{'default'} =
10535: '<span class="LC_error">'.
10536: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10537: }
10538: } else {
10539: $error{'default'} = $error;
10540: }
1.46 raeburn 10541: }
10542: }
10543: }
10544: } else {
1.95 www 10545: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10546: }
10547: }
10548: if (ref($settings) eq 'HASH') {
10549: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10550: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10551: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10552: $scantronurl = '';
10553: } else {
10554: $scantronurl = $settings->{'scantronformat'};
10555: }
10556: $is_custom = 1;
10557: } else {
10558: $scantronurl = $scantronurls{'default'};
10559: }
10560: } else {
1.60 raeburn 10561: if ($is_custom) {
10562: $scantronurl = $scantronurls{'custom'};
10563: } else {
10564: $scantronurl = $scantronurls{'default'};
10565: }
1.46 raeburn 10566: }
10567: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10568: $datatable .= '<tr'.$css_class.'>';
10569: if (!$is_custom) {
1.65 raeburn 10570: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10571: '<span class="LC_nobreak">';
1.46 raeburn 10572: if ($scantronurl) {
1.199 raeburn 10573: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10574: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10575: } else {
10576: $datatable = &mt('File unavailable for display');
10577: }
1.65 raeburn 10578: $datatable .= '</span></td>';
1.60 raeburn 10579: if (keys(%error) == 0) {
1.306 raeburn 10580: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10581: if (!$switchserver) {
10582: $datatable .= &mt('Upload:').'<br />';
10583: }
10584: } else {
10585: my $errorstr;
10586: foreach my $key (sort(keys(%error))) {
10587: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10588: }
10589: $datatable .= '<td>'.$errorstr;
10590: }
1.46 raeburn 10591: } else {
10592: if (keys(%error) > 0) {
10593: my $errorstr;
10594: foreach my $key (sort(keys(%error))) {
10595: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10596: }
1.60 raeburn 10597: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10598: } elsif ($scantronurl) {
1.199 raeburn 10599: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10600: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10601: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10602: $link.
10603: '<label><input type="checkbox" name="scantronformat_del"'.
10604: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10605: '<td><span class="LC_nobreak"> '.
10606: &mt('Replace:').'</span><br />';
1.46 raeburn 10607: }
10608: }
10609: if (keys(%error) == 0) {
10610: if ($switchserver) {
10611: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10612: } else {
1.65 raeburn 10613: $datatable .='<span class="LC_nobreak"> '.
10614: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10615: }
10616: }
10617: $datatable .= '</td></tr>';
10618: $$rowtotal ++;
10619: return $datatable;
10620: }
10621:
10622: sub legacy_scantronformat {
10623: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10624: my ($url,$error);
10625: my @statinfo = &Apache::lonnet::stat_file($newurl);
10626: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10627: (my $result,$url) =
10628: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10629: '','',$newfile);
10630: if ($result ne 'ok') {
1.130 raeburn 10631: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10632: }
10633: }
10634: return ($url,$error);
10635: }
1.43 raeburn 10636:
1.346 raeburn 10637: sub print_scantronconfig {
10638: my ($dom,$settings,$rowtotal) = @_;
10639: my $itemcount = 2;
10640: my $is_checked = ' checked="checked"';
1.347 raeburn 10641: my %optionson = (
10642: hdr => ' checked="checked"',
10643: pad => ' checked="checked"',
10644: rem => ' checked="checked"',
10645: );
10646: my %optionsoff = (
10647: hdr => '',
10648: pad => '',
10649: rem => '',
10650: );
1.346 raeburn 10651: my $currcsvsty = 'none';
1.347 raeburn 10652: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10653: my @fields = &scantroncsv_fields();
10654: my %titles = &scantronconfig_titles();
10655: if (ref($settings) eq 'HASH') {
10656: if (ref($settings->{config}) eq 'HASH') {
10657: if ($settings->{config}->{dat}) {
10658: $checked{'dat'} = $is_checked;
10659: }
10660: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10661: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10662: %csvfields = %{$settings->{config}->{csv}->{fields}};
10663: if (keys(%csvfields) > 0) {
10664: $checked{'csv'} = $is_checked;
10665: $currcsvsty = 'block';
10666: }
10667: }
10668: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10669: %csvoptions = %{$settings->{config}->{csv}->{options}};
10670: foreach my $option (keys(%optionson)) {
10671: unless ($csvoptions{$option}) {
10672: $optionsoff{$option} = $optionson{$option};
10673: $optionson{$option} = '';
10674: }
10675: }
1.346 raeburn 10676: }
10677: }
10678: } else {
10679: $checked{'dat'} = $is_checked;
10680: }
10681: } else {
10682: $checked{'dat'} = $is_checked;
10683: }
10684: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10685: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10686: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10687: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10688: foreach my $item ('dat','csv') {
10689: my $id;
10690: if ($item eq 'csv') {
10691: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10692: }
1.346 raeburn 10693: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10694: $titles{$item}.'</label>'.(' 'x3);
10695: if ($item eq 'csv') {
10696: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10697: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10698: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10699: foreach my $col (@fields) {
10700: my $selnone;
10701: if ($csvfields{$col} eq '') {
10702: $selnone = ' selected="selected"';
10703: }
10704: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10705: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10706: '<option value=""'.$selnone.'></option>';
10707: for (my $i=0; $i<20; $i++) {
10708: my $shown = $i+1;
10709: my $sel;
10710: unless ($selnone) {
10711: if (exists($csvfields{$col})) {
10712: if ($csvfields{$col} == $i) {
10713: $sel = ' selected="selected"';
10714: }
10715: }
10716: }
10717: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10718: }
10719: $datatable .= '</select></td></tr>';
10720: }
1.347 raeburn 10721: $datatable .= '</table></fieldset>'.
10722: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10723: '<legend>'.&mt('CSV Options').'</legend>';
10724: foreach my $option ('hdr','pad','rem') {
10725: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10726: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10727: &mt('Yes').'</label>'.(' 'x2)."\n".
10728: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10729: }
10730: $datatable .= '</fieldset>';
1.346 raeburn 10731: $itemcount ++;
10732: }
10733: }
10734: $datatable .= '</td></tr>';
10735: $$rowtotal ++;
10736: return $datatable;
10737: }
10738:
10739: sub scantronconfig_titles {
10740: return &Apache::lonlocal::texthash(
10741: dat => 'Standard format (.dat)',
10742: csv => 'Comma separated values (.csv)',
1.347 raeburn 10743: hdr => 'Remove first line in file (contains column titles)',
10744: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10745: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10746: CODE => 'CODE',
10747: ID => 'Student ID',
10748: PaperID => 'Paper ID',
10749: FirstName => 'First Name',
10750: LastName => 'Last Name',
10751: FirstQuestion => 'First Question Response',
10752: Section => 'Section',
10753: );
10754: }
10755:
10756: sub scantroncsv_fields {
10757: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10758: }
10759:
1.49 raeburn 10760: sub print_coursecategories {
1.57 raeburn 10761: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10762: my $datatable;
10763: if ($position eq 'top') {
1.238 raeburn 10764: my (%checked);
10765: my @catitems = ('unauth','auth');
10766: my @cattypes = ('std','domonly','codesrch','none');
10767: $checked{'unauth'} = 'std';
10768: $checked{'auth'} = 'std';
10769: if (ref($settings) eq 'HASH') {
10770: foreach my $type (@cattypes) {
10771: if ($type eq $settings->{'unauth'}) {
10772: $checked{'unauth'} = $type;
10773: }
10774: if ($type eq $settings->{'auth'}) {
10775: $checked{'auth'} = $type;
10776: }
10777: }
10778: }
10779: my %lt = &Apache::lonlocal::texthash (
10780: unauth => 'Catalog type for unauthenticated users',
10781: auth => 'Catalog type for authenticated users',
10782: none => 'No catalog',
10783: std => 'Standard catalog',
10784: domonly => 'Domain-only catalog',
10785: codesrch => "Code search form",
10786: );
10787: my $itemcount = 0;
10788: foreach my $item (@catitems) {
10789: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10790: $datatable .= '<tr '.$css_class.'>'.
10791: '<td>'.$lt{$item}.'</td>'.
10792: '<td class="LC_right_item"><span class="LC_nobreak">';
10793: foreach my $type (@cattypes) {
10794: my $ischecked;
10795: if ($checked{$item} eq $type) {
10796: $ischecked=' checked="checked"';
10797: }
10798: $datatable .= '<label>'.
10799: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10800: ' />'.$lt{$type}.'</label> ';
10801: }
1.327 raeburn 10802: $datatable .= '</span></td></tr>';
1.238 raeburn 10803: $itemcount ++;
10804: }
10805: $$rowtotal += $itemcount;
10806: } elsif ($position eq 'middle') {
1.57 raeburn 10807: my $toggle_cats_crs = ' ';
10808: my $toggle_cats_dom = ' checked="checked" ';
10809: my $can_cat_crs = ' ';
10810: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10811: my $toggle_catscomm_comm = ' ';
10812: my $toggle_catscomm_dom = ' checked="checked" ';
10813: my $can_catcomm_comm = ' ';
10814: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10815: my $toggle_catsplace_place = ' ';
10816: my $toggle_catsplace_dom = ' checked="checked" ';
10817: my $can_catplace_place = ' ';
10818: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10819:
1.57 raeburn 10820: if (ref($settings) eq 'HASH') {
10821: if ($settings->{'togglecats'} eq 'crs') {
10822: $toggle_cats_crs = $toggle_cats_dom;
10823: $toggle_cats_dom = ' ';
10824: }
10825: if ($settings->{'categorize'} eq 'crs') {
10826: $can_cat_crs = $can_cat_dom;
10827: $can_cat_dom = ' ';
10828: }
1.120 raeburn 10829: if ($settings->{'togglecatscomm'} eq 'comm') {
10830: $toggle_catscomm_comm = $toggle_catscomm_dom;
10831: $toggle_catscomm_dom = ' ';
10832: }
10833: if ($settings->{'categorizecomm'} eq 'comm') {
10834: $can_catcomm_comm = $can_catcomm_dom;
10835: $can_catcomm_dom = ' ';
10836: }
1.272 raeburn 10837: if ($settings->{'togglecatsplace'} eq 'place') {
10838: $toggle_catsplace_place = $toggle_catsplace_dom;
10839: $toggle_catsplace_dom = ' ';
10840: }
10841: if ($settings->{'categorizeplace'} eq 'place') {
10842: $can_catplace_place = $can_catplace_dom;
10843: $can_catplace_dom = ' ';
10844: }
1.57 raeburn 10845: }
10846: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10847: togglecats => 'Show/Hide a course in catalog',
10848: togglecatscomm => 'Show/Hide a community in catalog',
10849: togglecatsplace => 'Show/Hide a placement test in catalog',
10850: categorize => 'Assign a category to a course',
10851: categorizecomm => 'Assign a category to a community',
10852: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10853: );
10854: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10855: dom => 'Set in Domain',
10856: crs => 'Set in Course',
10857: comm => 'Set in Community',
10858: place => 'Set in Placement Test',
1.57 raeburn 10859: );
10860: $datatable = '<tr class="LC_odd_row">'.
10861: '<td>'.$title{'togglecats'}.'</td>'.
10862: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10863: '<input type="radio" name="togglecats"'.
10864: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10865: '<label><input type="radio" name="togglecats"'.
10866: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10867: '</tr><tr>'.
10868: '<td>'.$title{'categorize'}.'</td>'.
10869: '<td class="LC_right_item"><span class="LC_nobreak">'.
10870: '<label><input type="radio" name="categorize"'.
10871: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10872: '<label><input type="radio" name="categorize"'.
10873: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10874: '</tr><tr class="LC_odd_row">'.
10875: '<td>'.$title{'togglecatscomm'}.'</td>'.
10876: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10877: '<input type="radio" name="togglecatscomm"'.
10878: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10879: '<label><input type="radio" name="togglecatscomm"'.
10880: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10881: '</tr><tr>'.
10882: '<td>'.$title{'categorizecomm'}.'</td>'.
10883: '<td class="LC_right_item"><span class="LC_nobreak">'.
10884: '<label><input type="radio" name="categorizecomm"'.
10885: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10886: '<label><input type="radio" name="categorizecomm"'.
10887: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10888: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10889: '<td>'.$title{'togglecatsplace'}.'</td>'.
10890: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10891: '<input type="radio" name="togglecatsplace"'.
10892: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10893: '<label><input type="radio" name="togglecatscomm"'.
10894: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10895: '</tr><tr>'.
10896: '<td>'.$title{'categorizeplace'}.'</td>'.
10897: '<td class="LC_right_item"><span class="LC_nobreak">'.
10898: '<label><input type="radio" name="categorizeplace"'.
10899: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10900: '<label><input type="radio" name="categorizeplace"'.
10901: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10902: '</tr>';
1.272 raeburn 10903: $$rowtotal += 6;
1.57 raeburn 10904: } else {
10905: my $css_class;
10906: my $itemcount = 1;
10907: my $cathash;
10908: if (ref($settings) eq 'HASH') {
10909: $cathash = $settings->{'cats'};
10910: }
10911: if (ref($cathash) eq 'HASH') {
10912: my (@cats,@trails,%allitems,%idx,@jsarray);
10913: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10914: \%allitems,\%idx,\@jsarray);
10915: my $maxdepth = scalar(@cats);
10916: my $colattrib = '';
10917: if ($maxdepth > 2) {
10918: $colattrib = ' colspan="2" ';
10919: }
10920: my @path;
10921: if (@cats > 0) {
10922: if (ref($cats[0]) eq 'ARRAY') {
10923: my $numtop = @{$cats[0]};
10924: my $maxnum = $numtop;
1.120 raeburn 10925: my %default_names = (
10926: instcode => &mt('Official courses'),
10927: communities => &mt('Communities'),
1.272 raeburn 10928: placement => &mt('Placement Tests'),
1.120 raeburn 10929: );
10930:
10931: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10932: ($cathash->{'instcode::0'} eq '') ||
10933: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10934: ($cathash->{'communities::0'} eq '') ||
10935: (!grep(/^placement$/,@{$cats[0]})) ||
10936: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10937: $maxnum ++;
10938: }
10939: my $lastidx;
10940: for (my $i=0; $i<$numtop; $i++) {
10941: my $parent = $cats[0][$i];
10942: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10943: my $item = &escape($parent).'::0';
10944: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10945: $lastidx = $idx{$item};
10946: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10947: .'<select name="'.$item.'"'.$chgstr.'>';
10948: for (my $k=0; $k<=$maxnum; $k++) {
10949: my $vpos = $k+1;
10950: my $selstr;
10951: if ($k == $i) {
10952: $selstr = ' selected="selected" ';
10953: }
10954: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10955: }
1.214 raeburn 10956: $datatable .= '</select></span></td><td>';
1.272 raeburn 10957: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10958: $datatable .= '<span class="LC_nobreak">'
10959: .$default_names{$parent}.'</span>';
10960: if ($parent eq 'instcode') {
10961: $datatable .= '<br /><span class="LC_nobreak">('
10962: .&mt('with institutional codes')
10963: .')</span></td><td'.$colattrib.'>';
10964: } else {
10965: $datatable .= '<table><tr><td>';
10966: }
10967: $datatable .= '<span class="LC_nobreak">'
10968: .'<label><input type="radio" name="'
10969: .$parent.'" value="1" checked="checked" />'
10970: .&mt('Display').'</label>';
10971: if ($parent eq 'instcode') {
10972: $datatable .= ' ';
10973: } else {
10974: $datatable .= '</span></td></tr><tr><td>'
10975: .'<span class="LC_nobreak">';
10976: }
10977: $datatable .= '<label><input type="radio" name="'
10978: .$parent.'" value="0" />'
10979: .&mt('Do not display').'</label></span>';
1.272 raeburn 10980: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10981: $datatable .= '</td></tr></table>';
10982: }
10983: $datatable .= '</td>';
1.57 raeburn 10984: } else {
10985: $datatable .= $parent
1.214 raeburn 10986: .' <span class="LC_nobreak"><label>'
10987: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10988: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10989: }
10990: my $depth = 1;
10991: push(@path,$parent);
10992: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10993: pop(@path);
10994: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10995: $itemcount ++;
10996: }
1.48 raeburn 10997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10998: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10999: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11000: for (my $k=0; $k<=$maxnum; $k++) {
11001: my $vpos = $k+1;
11002: my $selstr;
1.57 raeburn 11003: if ($k == $numtop) {
1.48 raeburn 11004: $selstr = ' selected="selected" ';
11005: }
11006: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11007: }
1.59 bisitz 11008: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11009: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11010: .'</tr>'."\n";
1.48 raeburn 11011: $itemcount ++;
1.272 raeburn 11012: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11013: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11014: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11015: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11016: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11017: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11018: for (my $k=0; $k<=$maxnum; $k++) {
11019: my $vpos = $k+1;
11020: my $selstr;
11021: if ($k == $maxnum) {
11022: $selstr = ' selected="selected" ';
11023: }
11024: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11025: }
1.120 raeburn 11026: $datatable .= '</select></span></td>'.
11027: '<td><span class="LC_nobreak">'.
11028: $default_names{$default}.'</span>';
11029: if ($default eq 'instcode') {
11030: $datatable .= '<br /><span class="LC_nobreak">('
11031: .&mt('with institutional codes').')</span>';
11032: }
11033: $datatable .= '</td>'
11034: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11035: .&mt('Display').'</label> '
11036: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11037: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11038: }
11039: }
11040: }
1.57 raeburn 11041: } else {
11042: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11043: }
11044: } else {
1.327 raeburn 11045: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11046: .&initialize_categories($itemcount);
1.48 raeburn 11047: }
1.57 raeburn 11048: $$rowtotal += $itemcount;
1.48 raeburn 11049: }
11050: return $datatable;
11051: }
11052:
1.69 raeburn 11053: sub print_serverstatuses {
11054: my ($dom,$settings,$rowtotal) = @_;
11055: my $datatable;
11056: my @pages = &serverstatus_pages();
11057: my (%namedaccess,%machineaccess);
11058: foreach my $type (@pages) {
11059: $namedaccess{$type} = '';
11060: $machineaccess{$type}= '';
11061: }
11062: if (ref($settings) eq 'HASH') {
11063: foreach my $type (@pages) {
11064: if (exists($settings->{$type})) {
11065: if (ref($settings->{$type}) eq 'HASH') {
11066: foreach my $key (keys(%{$settings->{$type}})) {
11067: if ($key eq 'namedusers') {
11068: $namedaccess{$type} = $settings->{$type}->{$key};
11069: } elsif ($key eq 'machines') {
11070: $machineaccess{$type} = $settings->{$type}->{$key};
11071: }
11072: }
11073: }
11074: }
11075: }
11076: }
1.81 raeburn 11077: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11078: my $rownum = 0;
11079: my $css_class;
11080: foreach my $type (@pages) {
11081: $rownum ++;
11082: $css_class = $rownum%2?' class="LC_odd_row"':'';
11083: $datatable .= '<tr'.$css_class.'>'.
11084: '<td><span class="LC_nobreak">'.
11085: $titles->{$type}.'</span></td>'.
11086: '<td class="LC_left_item">'.
11087: '<input type="text" name="'.$type.'_namedusers" '.
11088: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11089: '<td class="LC_right_item">'.
11090: '<span class="LC_nobreak">'.
11091: '<input type="text" name="'.$type.'_machines" '.
11092: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11093: '</span></td></tr>'."\n";
1.69 raeburn 11094: }
11095: $$rowtotal += $rownum;
11096: return $datatable;
11097: }
11098:
11099: sub serverstatus_pages {
11100: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11101: 'checksums','clusterstatus','certstatus','metadata_keywords',
11102: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11103: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11104: }
11105:
1.236 raeburn 11106: sub defaults_javascript {
11107: my ($settings) = @_;
1.354 raeburn 11108: return unless (ref($settings) eq 'HASH');
1.236 raeburn 11109: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11110: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11111: if ($maxnum eq '') {
11112: $maxnum = 0;
11113: }
11114: $maxnum ++;
1.249 raeburn 11115: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11116: return <<"ENDSCRIPT";
11117: <script type="text/javascript">
11118: // <![CDATA[
11119: function reorderTypes(form,caller) {
11120: var changedVal;
11121: $jstext
11122: var newpos = 'addinststatus_pos';
11123: var current = new Array;
11124: var maxh = $maxnum;
11125: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11126: var oldVal;
11127: if (caller == newpos) {
11128: changedVal = newitemVal;
11129: } else {
11130: var curritem = 'inststatus_pos_'+caller;
11131: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11132: current[newitemVal] = newpos;
11133: }
11134: for (var i=0; i<inststatuses.length; i++) {
11135: if (inststatuses[i] != caller) {
11136: var elementName = 'inststatus_pos_'+inststatuses[i];
11137: if (form.elements[elementName]) {
11138: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11139: current[currVal] = elementName;
11140: }
11141: }
11142: }
11143: for (var j=0; j<maxh; j++) {
11144: if (current[j] == undefined) {
11145: oldVal = j;
11146: }
11147: }
11148: if (oldVal < changedVal) {
11149: for (var k=oldVal+1; k<=changedVal ; k++) {
11150: var elementName = current[k];
11151: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11152: }
11153: } else {
11154: for (var k=changedVal; k<oldVal; k++) {
11155: var elementName = current[k];
11156: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11157: }
11158: }
11159: return;
11160: }
11161:
11162: // ]]>
11163: </script>
11164:
11165: ENDSCRIPT
11166: }
1.354 raeburn 11167: return;
11168: }
11169:
11170: sub passwords_javascript {
1.365 raeburn 11171: my %intalert = &Apache::lonlocal::texthash (
11172: 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.',
11173: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11174: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11175: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11176: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11177: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11178: );
11179: &js_escape(\%intalert);
11180: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 11181: my $intauthjs = <<"ENDSCRIPT";
11182:
11183: function warnIntAuth(field) {
11184: if (field.name == 'intauth_check') {
11185: if (field.value == '2') {
1.365 raeburn 11186: alert('$intalert{authcheck}');
1.354 raeburn 11187: }
11188: }
11189: if (field.name == 'intauth_cost') {
11190: field.value.replace(/\s/g,'');
11191: if (field.value != '') {
11192: var regexdigit=/^\\d+\$/;
11193: if (!regexdigit.test(field.value)) {
1.365 raeburn 11194: alert('$intalert{authcost}');
11195: }
11196: }
11197: }
11198: return;
11199: }
11200:
11201: function warnIntPass(field) {
11202: field.value.replace(/^\s+/,'');
11203: field.value.replace(/\s+\$/,'');
11204: var regexdigit=/^\\d+\$/;
11205: if (field.name == 'passwords_min') {
11206: if (field.value == '') {
11207: alert('$intalert{passmin}');
11208: field.value = '$defmin';
11209: } else {
11210: if (!regexdigit.test(field.value)) {
11211: alert('$intalert{passmin}');
11212: field.value = '$defmin';
11213: }
1.366 raeburn 11214: var minval = parseInt(field.value,10);
1.365 raeburn 11215: if (minval < $defmin) {
11216: alert('$intalert{passmin}');
11217: field.value = '$defmin';
11218: }
11219: }
11220: } else {
11221: if (field.value == '0') {
11222: field.value = '';
11223: }
11224: if (field.value != '') {
11225: if (field.name == 'passwords_expire') {
11226: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11227: if (!regexpposnum.test(field.value)) {
11228: alert('$intalert{passexp}');
11229: field.value = '';
11230: } else {
11231: var expval = parseFloat(field.value);
11232: if (expval == 0) {
11233: alert('$intalert{passexp}');
11234: field.value = '';
11235: }
11236: }
11237: } else {
11238: if (!regexdigit.test(field.value)) {
11239: if (field.name == 'passwords_max') {
11240: alert('$intalert{passmax}');
11241: } else {
11242: if (field.name == 'passwords_numsaved') {
11243: alert('$intalert{passnum}');
11244: }
11245: }
1.370 raeburn 11246: field.value = '';
1.365 raeburn 11247: }
1.354 raeburn 11248: }
11249: }
11250: }
11251: return;
11252: }
11253:
11254: ENDSCRIPT
11255: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11256: }
11257:
1.49 raeburn 11258: sub coursecategories_javascript {
11259: my ($settings) = @_;
1.57 raeburn 11260: my ($output,$jstext,$cathash);
1.49 raeburn 11261: if (ref($settings) eq 'HASH') {
1.57 raeburn 11262: $cathash = $settings->{'cats'};
11263: }
11264: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11265: my (@cats,@jsarray,%idx);
1.57 raeburn 11266: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11267: if (@jsarray > 0) {
11268: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11269: for (my $i=0; $i<@jsarray; $i++) {
11270: if (ref($jsarray[$i]) eq 'ARRAY') {
11271: my $catstr = join('","',@{$jsarray[$i]});
11272: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11273: }
11274: }
11275: }
11276: } else {
11277: $jstext = ' var categories = Array(1);'."\n".
11278: ' categories[0] = Array("instcode_pos");'."\n";
11279: }
1.237 bisitz 11280: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11281: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11282: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11283: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11284: &js_escape(\$instcode_reserved);
11285: &js_escape(\$communities_reserved);
1.272 raeburn 11286: &js_escape(\$placement_reserved);
1.265 damieng 11287: &js_escape(\$choose_again);
1.49 raeburn 11288: $output = <<"ENDSCRIPT";
11289: <script type="text/javascript">
1.109 raeburn 11290: // <![CDATA[
1.49 raeburn 11291: function reorderCats(form,parent,item,idx) {
11292: var changedVal;
11293: $jstext
11294: var newpos = 'addcategory_pos';
11295: if (parent == '') {
11296: var has_instcode = 0;
11297: var maxtop = categories[idx].length;
11298: for (var j=0; j<maxtop; j++) {
11299: if (categories[idx][j] == 'instcode::0') {
11300: has_instcode == 1;
11301: }
11302: }
11303: if (has_instcode == 0) {
11304: categories[idx][maxtop] = 'instcode_pos';
11305: }
11306: } else {
11307: newpos += '_'+parent;
11308: }
11309: var maxh = 1 + categories[idx].length;
11310: var current = new Array;
11311: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11312: if (item == newpos) {
11313: changedVal = newitemVal;
11314: } else {
11315: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11316: current[newitemVal] = newpos;
11317: }
11318: for (var i=0; i<categories[idx].length; i++) {
11319: var elementName = categories[idx][i];
11320: if (elementName != item) {
11321: if (form.elements[elementName]) {
11322: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11323: current[currVal] = elementName;
11324: }
11325: }
11326: }
11327: var oldVal;
11328: for (var j=0; j<maxh; j++) {
11329: if (current[j] == undefined) {
11330: oldVal = j;
11331: }
11332: }
11333: if (oldVal < changedVal) {
11334: for (var k=oldVal+1; k<=changedVal ; k++) {
11335: var elementName = current[k];
11336: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11337: }
11338: } else {
11339: for (var k=changedVal; k<oldVal; k++) {
11340: var elementName = current[k];
11341: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11342: }
11343: }
11344: return;
11345: }
1.120 raeburn 11346:
11347: function categoryCheck(form) {
11348: if (form.elements['addcategory_name'].value == 'instcode') {
11349: alert('$instcode_reserved\\n$choose_again');
11350: return false;
11351: }
11352: if (form.elements['addcategory_name'].value == 'communities') {
11353: alert('$communities_reserved\\n$choose_again');
11354: return false;
11355: }
1.272 raeburn 11356: if (form.elements['addcategory_name'].value == 'placement') {
11357: alert('$placement_reserved\\n$choose_again');
11358: return false;
11359: }
1.120 raeburn 11360: return true;
11361: }
11362:
1.109 raeburn 11363: // ]]>
1.49 raeburn 11364: </script>
11365:
11366: ENDSCRIPT
11367: return $output;
11368: }
11369:
1.48 raeburn 11370: sub initialize_categories {
11371: my ($itemcount) = @_;
1.120 raeburn 11372: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11373: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11374: instcode => 'Official courses (with institutional codes)',
11375: communities => 'Communities',
1.272 raeburn 11376: placement => 'Placement Tests',
1.120 raeburn 11377: );
1.328 raeburn 11378: my %selnum = (
11379: instcode => '0',
11380: communities => '1',
11381: placement => '2',
11382: );
11383: my %selected;
1.272 raeburn 11384: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11386: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11387: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11388: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11389: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11390: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11391: .'<option value="0"'.$selected{'0'}.'>1</option>'
11392: .'<option value="1"'.$selected{'1'}.'>2</option>'
11393: .'<option value="2"'.$selected{'2'}.'>3</option>'
11394: .'<option value="3">4</option></select> '
1.120 raeburn 11395: .$default_names{$default}
11396: .'</span></td><td><span class="LC_nobreak">'
11397: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11398: .&mt('Display').'</label> <label>'
11399: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11400: .'</label></span></td></tr>';
1.120 raeburn 11401: $itemcount ++;
11402: }
1.48 raeburn 11403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11404: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11405: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11406: .'<select name="addcategory_pos"'.$chgstr.'>'
11407: .'<option value="0">1</option>'
11408: .'<option value="1">2</option>'
1.328 raeburn 11409: .'<option value="2">3</option>'
11410: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11411: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11412: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11413: .'</td></tr>';
1.48 raeburn 11414: return $datatable;
11415: }
11416:
11417: sub build_category_rows {
1.49 raeburn 11418: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11419: my ($text,$name,$item,$chgstr);
1.48 raeburn 11420: if (ref($cats) eq 'ARRAY') {
11421: my $maxdepth = scalar(@{$cats});
11422: if (ref($cats->[$depth]) eq 'HASH') {
11423: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11424: my $numchildren = @{$cats->[$depth]{$parent}};
11425: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11426: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11427: my ($idxnum,$parent_name,$parent_item);
11428: my $higher = $depth - 1;
11429: if ($higher == 0) {
11430: $parent_name = &escape($parent).'::'.$higher;
11431: } else {
11432: if (ref($path) eq 'ARRAY') {
11433: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11434: }
11435: }
11436: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11437: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11438: if ($j < $numchildren) {
1.48 raeburn 11439: $name = $cats->[$depth]{$parent}[$j];
11440: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11441: $idxnum = $idx->{$item};
11442: } else {
11443: $name = $parent_name;
11444: $item = $parent_item;
1.48 raeburn 11445: }
1.49 raeburn 11446: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11447: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11448: for (my $i=0; $i<=$numchildren; $i++) {
11449: my $vpos = $i+1;
11450: my $selstr;
11451: if ($j == $i) {
11452: $selstr = ' selected="selected" ';
11453: }
11454: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11455: }
11456: $text .= '</select> ';
11457: if ($j < $numchildren) {
11458: my $deeper = $depth+1;
11459: $text .= $name.' '
11460: .'<label><input type="checkbox" name="deletecategory" value="'
11461: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11462: if(ref($path) eq 'ARRAY') {
11463: push(@{$path},$name);
1.49 raeburn 11464: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11465: pop(@{$path});
11466: }
11467: } else {
1.330 raeburn 11468: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11469: if ($j == $numchildren) {
11470: $text .= $name;
11471: } else {
11472: $text .= $item;
11473: }
11474: $text .= '" value="" />';
11475: }
11476: $text .= '</td></tr>';
11477: }
11478: $text .= '</table></td>';
11479: } else {
11480: my $higher = $depth-1;
11481: if ($higher == 0) {
11482: $name = &escape($parent).'::'.$higher;
11483: } else {
11484: if (ref($path) eq 'ARRAY') {
11485: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11486: }
11487: }
11488: my $colspan;
11489: if ($parent ne 'instcode') {
11490: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11491: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11492: }
11493: }
11494: }
11495: }
11496: return $text;
11497: }
11498:
1.33 raeburn 11499: sub modifiable_userdata_row {
1.305 raeburn 11500: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11501: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11502: my ($role,$rolename,$statustype);
11503: $role = $item;
1.224 raeburn 11504: if ($context eq 'cancreate') {
1.305 raeburn 11505: if ($item =~ /^(emailusername)_(.+)$/) {
11506: $role = $1;
11507: $statustype = $2;
1.228 raeburn 11508: if (ref($usertypes) eq 'HASH') {
11509: if ($usertypes->{$statustype}) {
11510: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11511: } else {
11512: $rolename = &mt('Data provided by user');
11513: }
11514: }
1.224 raeburn 11515: }
11516: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11517: if (ref($usertypes) eq 'HASH') {
11518: $rolename = $usertypes->{$role};
11519: } else {
11520: $rolename = $role;
11521: }
1.325 raeburn 11522: } elsif ($context eq 'lti') {
11523: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11524: } elsif ($context eq 'privacy') {
11525: $rolename = $itemdesc;
1.33 raeburn 11526: } else {
1.63 raeburn 11527: if ($role eq 'cr') {
11528: $rolename = &mt('Custom role');
11529: } else {
11530: $rolename = &Apache::lonnet::plaintext($role);
11531: }
1.33 raeburn 11532: }
1.224 raeburn 11533: my (@fields,%fieldtitles);
11534: if (ref($fieldsref) eq 'ARRAY') {
11535: @fields = @{$fieldsref};
11536: } else {
11537: @fields = ('lastname','firstname','middlename','generation',
11538: 'permanentemail','id');
11539: }
11540: if ((ref($titlesref) eq 'HASH')) {
11541: %fieldtitles = %{$titlesref};
11542: } else {
11543: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11544: }
1.33 raeburn 11545: my $output;
1.305 raeburn 11546: my $css_class;
11547: if ($rowcount%2) {
11548: $css_class = 'LC_odd_row';
11549: }
11550: if ($customcss) {
11551: $css_class .= " $customcss";
11552: }
11553: $css_class =~ s/^\s+//;
11554: if ($css_class) {
11555: $css_class = ' class="'.$css_class.'"';
11556: }
11557: if ($rowstyle) {
11558: $css_class .= ' style="'.$rowstyle.'"';
11559: }
11560: if ($rowid) {
11561: $rowid = ' id="'.$rowid.'"';
11562: }
11563: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11564: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11565: '<td class="LC_left_item" colspan="2"><table>';
11566: my $rem;
11567: my %checks;
1.325 raeburn 11568: my %current;
1.33 raeburn 11569: if (ref($settings) eq 'HASH') {
1.325 raeburn 11570: my $hashref;
11571: if ($context eq 'lti') {
11572: if (ref($settings) eq 'HASH') {
11573: $hashref = $settings->{'instdata'};
11574: }
1.357 raeburn 11575: } elsif ($context eq 'privacy') {
11576: my ($key,$inner) = split(/_/,$role);
11577: if (ref($settings) eq 'HASH') {
11578: if (ref($settings->{$key}) eq 'HASH') {
11579: $hashref = $settings->{$key}->{$inner};
11580: }
11581: }
1.325 raeburn 11582: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11583: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11584: $hashref = $settings->{'lti_instdata'};
11585: }
11586: if ($role eq 'emailusername') {
11587: if ($statustype) {
11588: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11589: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11590: }
1.325 raeburn 11591: }
11592: }
11593: }
11594: if (ref($hashref) eq 'HASH') {
11595: foreach my $field (@fields) {
11596: if ($hashref->{$field}) {
11597: if ($role eq 'emailusername') {
11598: $checks{$field} = $hashref->{$field};
11599: } else {
11600: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11601: }
11602: }
11603: }
11604: }
11605: }
1.305 raeburn 11606:
11607: my $total = scalar(@fields);
11608: for (my $i=0; $i<$total; $i++) {
11609: $rem = $i%($numinrow);
1.33 raeburn 11610: if ($rem == 0) {
11611: if ($i > 0) {
11612: $output .= '</tr>';
11613: }
11614: $output .= '<tr>';
11615: }
11616: my $check = ' ';
1.228 raeburn 11617: unless ($role eq 'emailusername') {
11618: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11619: $check = $checks{$fields[$i]};
1.357 raeburn 11620: } elsif ($context eq 'privacy') {
11621: if ($role =~ /^priv_(domain|course)$/) {
11622: if (ref($settings) ne 'HASH') {
11623: $check = ' checked="checked" ';
11624: }
11625: } elsif ($role =~ /^priv_(author|community)$/) {
11626: if (ref($settings) ne 'HASH') {
11627: unless ($fields[$i] eq 'id') {
11628: $check = ' checked="checked" ';
11629: }
11630: }
11631: } elsif ($role =~ /^(unpriv|othdom)_/) {
11632: if (ref($settings) ne 'HASH') {
11633: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11634: $check = ' checked="checked" ';
11635: }
11636: }
11637: }
1.325 raeburn 11638: } elsif ($context ne 'lti') {
1.228 raeburn 11639: if ($role eq 'st') {
11640: if (ref($settings) ne 'HASH') {
11641: $check = ' checked="checked" ';
11642: }
1.33 raeburn 11643: }
11644: }
11645: }
11646: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11647: '<span class="LC_nobreak">';
1.325 raeburn 11648: my $prefix = 'canmodify';
1.228 raeburn 11649: if ($role eq 'emailusername') {
11650: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11651: $checks{$fields[$i]} = 'omit';
11652: }
11653: foreach my $option ('required','optional','omit') {
11654: my $checked='';
11655: if ($checks{$fields[$i]} eq $option) {
11656: $checked='checked="checked" ';
11657: }
11658: $output .= '<label>'.
1.325 raeburn 11659: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11660: &mt($option).'</label>'.(' ' x2);
11661: }
11662: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11663: } else {
1.325 raeburn 11664: if ($context eq 'lti') {
11665: $prefix = 'lti';
1.357 raeburn 11666: } elsif ($context eq 'privacy') {
11667: $prefix = 'privacy';
1.325 raeburn 11668: }
1.228 raeburn 11669: $output .= '<label>'.
1.325 raeburn 11670: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11671: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11672: '</label>';
11673: }
11674: $output .= '</span></td>';
1.33 raeburn 11675: }
1.305 raeburn 11676: $rem = $total%$numinrow;
11677: my $colsleft;
11678: if ($rem) {
11679: $colsleft = $numinrow - $rem;
11680: }
11681: if ($colsleft > 1) {
1.33 raeburn 11682: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11683: ' </td>';
11684: } elsif ($colsleft == 1) {
11685: $output .= '<td class="LC_left_item"> </td>';
11686: }
11687: $output .= '</tr></table></td></tr>';
11688: return $output;
11689: }
1.28 raeburn 11690:
1.93 raeburn 11691: sub insttypes_row {
1.305 raeburn 11692: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11693: $customcss,$rowstyle) = @_;
1.93 raeburn 11694: my %lt = &Apache::lonlocal::texthash (
11695: cansearch => 'Users allowed to search',
11696: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11697: lockablenames => 'User preference to lock name',
1.305 raeburn 11698: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11699: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11700: );
11701: my $showdom;
11702: if ($context eq 'cansearch') {
11703: $showdom = ' ('.$dom.')';
11704: }
1.165 raeburn 11705: my $class = 'LC_left_item';
11706: if ($context eq 'statustocreate') {
11707: $class = 'LC_right_item';
11708: }
1.305 raeburn 11709: my $css_class;
11710: if ($$rowtotal%2) {
11711: $css_class = 'LC_odd_row';
11712: }
11713: if ($customcss) {
11714: $css_class .= ' '.$customcss;
11715: }
11716: $css_class =~ s/^\s+//;
11717: if ($css_class) {
11718: $css_class = ' class="'.$css_class.'"';
11719: }
11720: if ($rowstyle) {
11721: $css_class .= ' style="'.$rowstyle.'"';
11722: }
11723: if ($onclick) {
11724: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11725: }
11726: my $output = '<tr'.$css_class.'>'.
11727: '<td>'.$lt{$context}.$showdom.
11728: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11729: my $rem;
11730: if (ref($types) eq 'ARRAY') {
11731: for (my $i=0; $i<@{$types}; $i++) {
11732: if (defined($usertypes->{$types->[$i]})) {
11733: my $rem = $i%($numinrow);
11734: if ($rem == 0) {
11735: if ($i > 0) {
11736: $output .= '</tr>';
11737: }
11738: $output .= '<tr>';
1.23 raeburn 11739: }
1.26 raeburn 11740: my $check = ' ';
1.99 raeburn 11741: if (ref($settings) eq 'HASH') {
11742: if (ref($settings->{$context}) eq 'ARRAY') {
11743: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11744: $check = ' checked="checked" ';
11745: }
1.315 raeburn 11746: } elsif (ref($settings->{$context}) eq 'HASH') {
11747: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11748: $check = ' checked="checked" ';
11749: }
1.99 raeburn 11750: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11751: $check = ' checked="checked" ';
11752: }
1.23 raeburn 11753: }
1.26 raeburn 11754: $output .= '<td class="LC_left_item">'.
11755: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11756: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11757: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11758: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11759: }
11760: }
1.26 raeburn 11761: $rem = @{$types}%($numinrow);
1.23 raeburn 11762: }
11763: my $colsleft = $numinrow - $rem;
1.315 raeburn 11764: if ($context eq 'overrides') {
11765: if ($colsleft > 1) {
11766: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11767: } else {
11768: $output .= '<td class="LC_left_item">';
11769: }
11770: $output .= ' ';
1.23 raeburn 11771: } else {
1.334 raeburn 11772: if ($rem == 0) {
1.315 raeburn 11773: $output .= '<tr>';
11774: }
11775: if ($colsleft > 1) {
11776: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11777: } else {
11778: $output .= '<td class="LC_left_item">';
11779: }
11780: my $defcheck = ' ';
11781: if (ref($settings) eq 'HASH') {
11782: if (ref($settings->{$context}) eq 'ARRAY') {
11783: if (grep(/^default$/,@{$settings->{$context}})) {
11784: $defcheck = ' checked="checked" ';
11785: }
11786: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11787: $defcheck = ' checked="checked" ';
11788: }
1.26 raeburn 11789: }
1.315 raeburn 11790: $output .= '<span class="LC_nobreak"><label>'.
11791: '<input type="checkbox" name="'.$context.'" '.
11792: 'value="default"'.$defcheck.$onclick.' />'.
11793: $othertitle.'</label></span>';
1.23 raeburn 11794: }
1.315 raeburn 11795: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11796: return $output;
1.23 raeburn 11797: }
11798:
11799: sub sorted_searchtitles {
11800: my %searchtitles = &Apache::lonlocal::texthash(
11801: 'uname' => 'username',
11802: 'lastname' => 'last name',
11803: 'lastfirst' => 'last name, first name',
11804: );
11805: my @titleorder = ('uname','lastname','lastfirst');
11806: return (\%searchtitles,\@titleorder);
11807: }
11808:
1.25 raeburn 11809: sub sorted_searchtypes {
11810: my %srchtypes_desc = (
11811: exact => 'is exact match',
11812: contains => 'contains ..',
11813: begins => 'begins with ..',
11814: );
11815: my @srchtypeorder = ('exact','begins','contains');
11816: return (\%srchtypes_desc,\@srchtypeorder);
11817: }
11818:
1.3 raeburn 11819: sub usertype_update_row {
11820: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11821: my $datatable;
11822: my $numinrow = 4;
11823: foreach my $type (@{$types}) {
11824: if (defined($usertypes->{$type})) {
11825: $$rownums ++;
11826: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11827: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11828: '</td><td class="LC_left_item"><table>';
11829: for (my $i=0; $i<@{$fields}; $i++) {
11830: my $rem = $i%($numinrow);
11831: if ($rem == 0) {
11832: if ($i > 0) {
11833: $datatable .= '</tr>';
11834: }
11835: $datatable .= '<tr>';
11836: }
11837: my $check = ' ';
1.39 raeburn 11838: if (ref($settings) eq 'HASH') {
11839: if (ref($settings->{'fields'}) eq 'HASH') {
11840: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11841: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11842: $check = ' checked="checked" ';
11843: }
1.3 raeburn 11844: }
11845: }
11846: }
11847:
11848: if ($i == @{$fields}-1) {
11849: my $colsleft = $numinrow - $rem;
11850: if ($colsleft > 1) {
11851: $datatable .= '<td colspan="'.$colsleft.'">';
11852: } else {
11853: $datatable .= '<td>';
11854: }
11855: } else {
11856: $datatable .= '<td>';
11857: }
1.8 raeburn 11858: $datatable .= '<span class="LC_nobreak"><label>'.
11859: '<input type="checkbox" name="updateable_'.$type.
11860: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11861: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11862: }
11863: $datatable .= '</tr></table></td></tr>';
11864: }
11865: }
11866: return $datatable;
1.1 raeburn 11867: }
11868:
11869: sub modify_login {
1.205 raeburn 11870: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11871: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11872: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11873: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11874: %title = ( coursecatalog => 'Display course catalog',
11875: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11876: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11877: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11878: loginheader => 'Log-in box header',
11879: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11880: @offon = ('off','on');
1.112 raeburn 11881: if (ref($domconfig{login}) eq 'HASH') {
11882: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11883: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11884: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11885: }
11886: }
1.386 raeburn 11887: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11888: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11889: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11890: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11891: $saml{$lonhost} = 1;
11892: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11893: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11894: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11895: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11896: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11897: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11898: }
11899: }
11900: }
1.112 raeburn 11901: }
1.9 raeburn 11902: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11903: \%domconfig,\%loginhash);
1.188 raeburn 11904: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11905: foreach my $item (@toggles) {
11906: $loginhash{login}{$item} = $env{'form.'.$item};
11907: }
1.41 raeburn 11908: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11909: if (ref($colchanges{'login'}) eq 'HASH') {
11910: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11911: \%loginhash);
11912: }
1.110 raeburn 11913:
1.149 raeburn 11914: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11915: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11916: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11917: if (keys(%servers) > 1) {
11918: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11919: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11920: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11921: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11922: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11923: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11924: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11925: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11926: $changes{'loginvia'}{$lonhost} = 1;
11927: } else {
11928: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11929: $changes{'loginvia'}{$lonhost} = 1;
11930: }
11931: } else {
11932: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11933: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11934: $changes{'loginvia'}{$lonhost} = 1;
11935: }
11936: }
11937: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11938: foreach my $item (@loginvia_attribs) {
11939: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11940: }
11941: } else {
11942: foreach my $item (@loginvia_attribs) {
11943: my $new = $env{'form.'.$lonhost.'_'.$item};
11944: if (($item eq 'serverpath') && ($new eq 'custom')) {
11945: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11946: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11947: $new = '/';
11948: }
11949: }
11950: if (($item eq 'custompath') &&
11951: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11952: $new = '';
11953: }
11954: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11955: $changes{'loginvia'}{$lonhost} = 1;
11956: }
11957: if ($item eq 'exempt') {
1.256 raeburn 11958: $new = &check_exempt_addresses($new);
1.128 raeburn 11959: }
11960: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11961: }
11962: }
1.112 raeburn 11963: } else {
1.128 raeburn 11964: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11965: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11966: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11967: foreach my $item (@loginvia_attribs) {
11968: my $new = $env{'form.'.$lonhost.'_'.$item};
11969: if (($item eq 'serverpath') && ($new eq 'custom')) {
11970: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11971: $new = '/';
11972: }
11973: }
11974: if (($item eq 'custompath') &&
11975: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11976: $new = '';
11977: }
11978: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11979: }
1.110 raeburn 11980: }
11981: }
11982: }
11983: }
1.119 raeburn 11984:
1.168 raeburn 11985: my $servadm = $r->dir_config('lonAdmEMail');
11986: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11987: if (ref($domconfig{'login'}) eq 'HASH') {
11988: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11989: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11990: if ($lang eq 'nolang') {
11991: push(@currlangs,$lang);
11992: } elsif (defined($langchoices{$lang})) {
11993: push(@currlangs,$lang);
11994: } else {
11995: next;
11996: }
11997: }
11998: }
11999: }
12000: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12001: if (@currlangs > 0) {
12002: foreach my $lang (@currlangs) {
12003: if (grep(/^\Q$lang\E$/,@delurls)) {
12004: $changes{'helpurl'}{$lang} = 1;
12005: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12006: $changes{'helpurl'}{$lang} = 1;
12007: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12008: push(@newlangs,$lang);
12009: } else {
12010: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12011: }
12012: }
12013: }
12014: unless (grep(/^nolang$/,@currlangs)) {
12015: if ($env{'form.loginhelpurl_nolang.filename'}) {
12016: $changes{'helpurl'}{'nolang'} = 1;
12017: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12018: push(@newlangs,'nolang');
12019: }
12020: }
12021: if ($env{'form.loginhelpurl_add_lang'}) {
12022: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12023: ($env{'form.loginhelpurl_add_file.filename'})) {
12024: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12025: $addedfile = $env{'form.loginhelpurl_add_lang'};
12026: }
12027: }
12028: if ((@newlangs > 0) || ($addedfile)) {
12029: my $error;
12030: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12031: if ($configuserok eq 'ok') {
12032: if ($switchserver) {
12033: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12034: } elsif ($author_ok eq 'ok') {
12035: my @allnew = @newlangs;
12036: if ($addedfile ne '') {
12037: push(@allnew,$addedfile);
12038: }
12039: foreach my $lang (@allnew) {
12040: my $formelem = 'loginhelpurl_'.$lang;
12041: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12042: $formelem = 'loginhelpurl_add_file';
12043: }
12044: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12045: "help/$lang",'','',$newfile{$lang});
12046: if ($result eq 'ok') {
12047: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12048: $changes{'helpurl'}{$lang} = 1;
12049: } else {
12050: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12051: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12052: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12053: (!grep(/^\Q$lang\E$/,@delurls))) {
12054: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12055: }
12056: }
12057: }
12058: } else {
12059: $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);
12060: }
12061: } else {
12062: $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);
12063: }
12064: if ($error) {
12065: &Apache::lonnet::logthis($error);
12066: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12067: }
12068: }
1.256 raeburn 12069:
12070: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12071: if (ref($domconfig{'login'}) eq 'HASH') {
12072: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12073: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12074: if ($domservers{$lonhost}) {
12075: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12076: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12077: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12078: }
12079: }
12080: }
12081: }
12082: }
12083: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12084: foreach my $lonhost (sort(keys(%domservers))) {
12085: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12086: $changes{'headtag'}{$lonhost} = 1;
12087: } else {
12088: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12089: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12090: }
12091: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12092: push(@newhosts,$lonhost);
12093: } elsif ($currheadtagurls{$lonhost}) {
12094: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12095: if ($currexempt{$lonhost}) {
1.289 raeburn 12096: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12097: $changes{'headtag'}{$lonhost} = 1;
12098: }
12099: } elsif ($possexempt{$lonhost}) {
12100: $changes{'headtag'}{$lonhost} = 1;
12101: }
12102: if ($possexempt{$lonhost}) {
12103: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12104: }
12105: }
12106: }
12107: }
12108: if (@newhosts) {
12109: my $error;
12110: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12111: if ($configuserok eq 'ok') {
12112: if ($switchserver) {
12113: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12114: } elsif ($author_ok eq 'ok') {
12115: foreach my $lonhost (@newhosts) {
12116: my $formelem = 'loginheadtag_'.$lonhost;
12117: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12118: "login/headtag/$lonhost",'','',
12119: $env{'form.loginheadtag_'.$lonhost.'.filename'});
12120: if ($result eq 'ok') {
12121: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12122: $changes{'headtag'}{$lonhost} = 1;
12123: if ($possexempt{$lonhost}) {
12124: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12125: }
12126: } else {
12127: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12128: $newheadtagurls{$lonhost},$result);
12129: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12130: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12131: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12132: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12133: }
12134: }
12135: }
12136: } else {
12137: $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);
12138: }
12139: } else {
12140: $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);
12141: }
12142: if ($error) {
12143: &Apache::lonnet::logthis($error);
12144: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12145: }
12146: }
1.386 raeburn 12147: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12148: my @newsamlimgs;
12149: foreach my $lonhost (keys(%domservers)) {
12150: if ($env{'form.saml_'.$lonhost}) {
12151: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12152: push(@newsamlimgs,$lonhost);
12153: }
12154: foreach my $item ('text','alt','url','title','notsso') {
12155: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12156: }
12157: if ($saml{$lonhost}) {
12158: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12159: #FIXME Need to obsolete published image
12160: delete($currsaml{$lonhost}{'img'});
12161: $changes{'saml'}{$lonhost} = 1;
12162: }
12163: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12164: $changes{'saml'}{$lonhost} = 1;
12165: }
12166: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12167: $changes{'saml'}{$lonhost} = 1;
12168: }
12169: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12170: $changes{'saml'}{$lonhost} = 1;
12171: }
12172: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12173: $changes{'saml'}{$lonhost} = 1;
12174: }
12175: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12176: $changes{'saml'}{$lonhost} = 1;
12177: }
12178: } else {
12179: $changes{'saml'}{$lonhost} = 1;
12180: }
12181: foreach my $item ('text','alt','url','title','notsso') {
12182: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12183: }
12184: } else {
1.389 raeburn 12185: if ($saml{$lonhost}) {
12186: $changes{'saml'}{$lonhost} = 1;
12187: delete($currsaml{$lonhost});
12188: }
1.386 raeburn 12189: }
12190: }
12191: foreach my $posshost (keys(%currsaml)) {
12192: unless (exists($domservers{$posshost})) {
12193: delete($currsaml{$posshost});
12194: }
12195: }
12196: %{$loginhash{'login'}{'saml'}} = %currsaml;
12197: if (@newsamlimgs) {
12198: my $error;
12199: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12200: if ($configuserok eq 'ok') {
12201: if ($switchserver) {
12202: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12203: } elsif ($author_ok eq 'ok') {
12204: foreach my $lonhost (@newsamlimgs) {
12205: my $formelem = 'saml_img_'.$lonhost;
12206: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12207: "login/saml/$lonhost",'','',
12208: $env{'form.saml_img_'.$lonhost.'.filename'});
12209: if ($result eq 'ok') {
12210: $currsaml{$lonhost}{'img'} = $imgurl;
12211: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12212: $changes{'saml'}{$lonhost} = 1;
12213: } else {
12214: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12215: $lonhost,$result);
12216: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12217: }
12218: }
12219: } else {
12220: $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);
12221: }
12222: } else {
12223: $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);
12224: }
12225: if ($error) {
12226: &Apache::lonnet::logthis($error);
12227: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12228: }
12229: }
1.169 raeburn 12230: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12231:
12232: my $defaulthelpfile = '/adm/loginproblems.html';
12233: my $defaulttext = &mt('Default in use');
12234:
1.1 raeburn 12235: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12236: $dom);
12237: if ($putresult eq 'ok') {
1.188 raeburn 12238: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12239: my %defaultchecked = (
12240: 'coursecatalog' => 'on',
1.188 raeburn 12241: 'helpdesk' => 'on',
1.42 raeburn 12242: 'adminmail' => 'off',
1.43 raeburn 12243: 'newuser' => 'off',
1.42 raeburn 12244: );
1.55 raeburn 12245: if (ref($domconfig{'login'}) eq 'HASH') {
12246: foreach my $item (@toggles) {
12247: if ($defaultchecked{$item} eq 'on') {
12248: if (($domconfig{'login'}{$item} eq '0') &&
12249: ($env{'form.'.$item} eq '1')) {
12250: $changes{$item} = 1;
12251: } elsif (($domconfig{'login'}{$item} eq '' ||
12252: $domconfig{'login'}{$item} eq '1') &&
12253: ($env{'form.'.$item} eq '0')) {
12254: $changes{$item} = 1;
12255: }
12256: } elsif ($defaultchecked{$item} eq 'off') {
12257: if (($domconfig{'login'}{$item} eq '1') &&
12258: ($env{'form.'.$item} eq '0')) {
12259: $changes{$item} = 1;
12260: } elsif (($domconfig{'login'}{$item} eq '' ||
12261: $domconfig{'login'}{$item} eq '0') &&
12262: ($env{'form.'.$item} eq '1')) {
12263: $changes{$item} = 1;
12264: }
1.42 raeburn 12265: }
12266: }
1.41 raeburn 12267: }
1.6 raeburn 12268: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12269: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12270: if (exists($changes{'saml'})) {
12271: my $hostid_in_use;
12272: my @hosts = &Apache::lonnet::current_machine_ids();
12273: if (@hosts > 1) {
12274: foreach my $hostid (@hosts) {
12275: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12276: $hostid_in_use = $hostid;
12277: last;
12278: }
12279: }
12280: } else {
12281: $hostid_in_use = $r->dir_config('lonHostID');
12282: }
12283: if (($hostid_in_use) &&
12284: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12285: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12286: }
12287: if (ref($lastactref) eq 'HASH') {
12288: if (ref($changes{'saml'}) eq 'HASH') {
12289: my %updates;
12290: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12291: $lastactref->{'samllanding'} = \%updates;
12292: }
12293: }
12294: }
1.212 raeburn 12295: if (ref($lastactref) eq 'HASH') {
12296: $lastactref->{'domainconfig'} = 1;
12297: }
1.1 raeburn 12298: $resulttext = &mt('Changes made:').'<ul>';
12299: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12300: if ($item eq 'loginvia') {
1.112 raeburn 12301: if (ref($changes{$item}) eq 'HASH') {
12302: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12303: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12304: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12305: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12306: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12307: $protocol = 'http' if ($protocol ne 'https');
12308: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12309:
12310: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12311: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12312: } else {
12313: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12314: }
12315: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12316: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12317: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12318: }
12319: $resulttext .= '</li>';
12320: } else {
12321: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12322: }
1.112 raeburn 12323: } else {
1.128 raeburn 12324: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12325: }
12326: }
1.128 raeburn 12327: $resulttext .= '</ul></li>';
1.112 raeburn 12328: }
1.168 raeburn 12329: } elsif ($item eq 'helpurl') {
12330: if (ref($changes{$item}) eq 'HASH') {
12331: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12332: if (grep(/^\Q$lang\E$/,@delurls)) {
12333: my ($chg,$link);
12334: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12335: if ($lang eq 'nolang') {
12336: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12337: } else {
12338: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12339: }
12340: $resulttext .= '<li>'.$chg.'</li>';
12341: } else {
12342: my $chg;
12343: if ($lang eq 'nolang') {
12344: $chg = &mt('custom log-in help file for no preferred language');
12345: } else {
12346: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12347: }
12348: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12349: $loginhash{'login'}{'helpurl'}{$lang}.
12350: '?inhibitmenu=yes',$chg,600,500).
12351: '</li>';
12352: }
12353: }
12354: }
1.256 raeburn 12355: } elsif ($item eq 'headtag') {
12356: if (ref($changes{$item}) eq 'HASH') {
12357: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12358: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12359: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12360: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12361: $resulttext .= '<li><a href="'.
12362: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12363: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12364: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12365: if ($possexempt{$lonhost}) {
12366: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12367: } else {
12368: $resulttext .= &mt('included for any client IP');
12369: }
12370: $resulttext .= '</li>';
12371: }
12372: }
12373: }
1.386 raeburn 12374: } elsif ($item eq 'saml') {
12375: if (ref($changes{$item}) eq 'HASH') {
12376: my %notlt = (
12377: text => 'Text for log-in by SSO',
12378: img => 'SSO button image',
12379: alt => 'Alt text for button image',
12380: url => 'SSO URL',
12381: title => 'Tooltip for SSO link',
12382: notsso => 'Text for non-SSO log-in',
12383: );
12384: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12385: if (ref($currsaml{$lonhost}) eq 'HASH') {
12386: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12387: '<ul>';
12388: foreach my $key ('text','img','alt','url','title','notsso') {
12389: if ($currsaml{$lonhost}{$key} eq '') {
12390: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12391: } else {
12392: my $value = "'$currsaml{$lonhost}{$key}'";
12393: if ($key eq 'img') {
12394: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
12395: }
12396: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12397: $value).'</li>';
12398: }
12399: }
12400: $resulttext .= '</ul></li>';
12401: } else {
12402: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12403: }
12404: }
12405: }
1.169 raeburn 12406: } elsif ($item eq 'captcha') {
12407: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12408: my $chgtxt;
1.169 raeburn 12409: if ($loginhash{'login'}{$item} eq 'notused') {
12410: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12411: } else {
12412: my %captchas = &captcha_phrases();
12413: if ($captchas{$loginhash{'login'}{$item}}) {
12414: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12415: } else {
12416: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12417: }
12418: }
12419: $resulttext .= '<li>'.$chgtxt.'</li>';
12420: }
12421: } elsif ($item eq 'recaptchakeys') {
12422: if (ref($loginhash{'login'}) eq 'HASH') {
12423: my ($privkey,$pubkey);
12424: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12425: $pubkey = $loginhash{'login'}{$item}{'public'};
12426: $privkey = $loginhash{'login'}{$item}{'private'};
12427: }
12428: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12429: if (!$pubkey) {
12430: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12431: } else {
12432: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12433: }
12434: if (!$privkey) {
12435: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12436: } else {
1.251 raeburn 12437: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12438: }
12439: $chgtxt .= '</ul>';
12440: $resulttext .= '<li>'.$chgtxt.'</li>';
12441: }
1.269 raeburn 12442: } elsif ($item eq 'recaptchaversion') {
12443: if (ref($loginhash{'login'}) eq 'HASH') {
12444: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12445: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12446: '</li>';
12447: }
12448: }
1.41 raeburn 12449: } else {
12450: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12451: }
1.1 raeburn 12452: }
1.6 raeburn 12453: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12454: } else {
12455: $resulttext = &mt('No changes made to log-in page settings');
12456: }
12457: } else {
1.11 albertel 12458: $resulttext = '<span class="LC_error">'.
12459: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12460: }
1.6 raeburn 12461: if ($errors) {
1.9 raeburn 12462: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12463: $errors.'</ul>';
12464: }
12465: return $resulttext;
12466: }
12467:
1.256 raeburn 12468: sub check_exempt_addresses {
12469: my ($iplist) = @_;
12470: $iplist =~ s/^\s+//;
12471: $iplist =~ s/\s+$//;
12472: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12473: my (@okips,$new);
12474: foreach my $ip (@poss_ips) {
12475: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12476: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12477: push(@okips,$ip);
12478: }
12479: }
12480: }
12481: if (@okips > 0) {
12482: $new = join(',',@okips);
12483: } else {
12484: $new = '';
12485: }
12486: return $new;
12487: }
12488:
1.6 raeburn 12489: sub color_font_choices {
12490: my %choices =
12491: &Apache::lonlocal::texthash (
12492: img => "Header",
12493: bgs => "Background colors",
12494: links => "Link colors",
1.55 raeburn 12495: images => "Images",
1.6 raeburn 12496: font => "Font color",
1.201 raeburn 12497: fontmenu => "Font menu",
1.76 raeburn 12498: pgbg => "Page",
1.6 raeburn 12499: tabbg => "Header",
12500: sidebg => "Border",
12501: link => "Link",
12502: alink => "Active link",
12503: vlink => "Visited link",
12504: );
12505: return %choices;
12506: }
12507:
1.394 raeburn 12508: sub modify_ipaccess {
12509: my ($dom,$lastactref,%domconfig) = @_;
12510: my (@allpos,%changes,%confhash,$errors,$resulttext);
12511: my (@items,%deletions,%itemids,@warnings);
12512: my ($typeorder,$types) = &commblocktype_text();
12513: if ($env{'form.ipaccess_add'}) {
12514: my $name = $env{'form.ipaccess_name_add'};
12515: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12516: if ($newid) {
12517: $itemids{'add'} = $newid;
12518: push(@items,'add');
12519: $changes{$newid} = 1;
12520: } else {
12521: $error = &mt('Failed to acquire unique ID for new IP access control item');
12522: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12523: }
12524: }
12525: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12526: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12527: if (@todelete) {
12528: map { $deletions{$_} = 1; } @todelete;
12529: }
12530: my $maxnum = $env{'form.ipaccess_maxnum'};
12531: for (my $i=0; $i<$maxnum; $i++) {
12532: my $itemid = $env{'form.ipaccess_id_'.$i};
12533: $itemid =~ s/\D+//g;
12534: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12535: if ($deletions{$itemid}) {
12536: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12537: } else {
12538: push(@items,$i);
12539: $itemids{$i} = $itemid;
12540: }
12541: }
12542: }
12543: }
12544: foreach my $idx (@items) {
12545: my $itemid = $itemids{$idx};
12546: next unless ($itemid);
12547: my %current;
12548: unless ($idx eq 'add') {
12549: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12550: %current = %{$domconfig{'ipaccess'}{$itemid}};
12551: }
12552: }
12553: my $position = $env{'form.ipaccess_pos_'.$itemid};
12554: $position =~ s/\D+//g;
12555: if ($position ne '') {
12556: $allpos[$position] = $itemid;
12557: }
12558: my $name = $env{'form.ipaccess_name_'.$idx};
12559: $name =~ s/^\s+|\s+$//g;
12560: $confhash{$itemid}{'name'} = $name;
12561: my $possrange = $env{'form.ipaccess_range_'.$idx};
12562: $possrange =~ s/^\s+|\s+$//g;
12563: unless ($possrange eq '') {
12564: $possrange =~ s/[\r\n]+/\s/g;
12565: $possrange =~ s/\s*-\s*/-/g;
12566: $possrange =~ s/\s+/,/g;
12567: $possrange =~ s/,+/,/g;
12568: if ($possrange ne '') {
12569: my (@ok,$count);
12570: $count = 0;
12571: foreach my $poss (split(/\,/,$possrange)) {
12572: $count ++;
12573: $poss = &validate_ip_pattern($poss);
12574: if ($poss ne '') {
12575: push(@ok,$poss);
12576: }
12577: }
12578: my $diff = $count - scalar(@ok);
12579: if ($diff) {
12580: $errors .= '<li><span class="LC_error">'.
12581: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12582: $diff,$name).
12583: '</span></li>';
12584: }
12585: if (@ok) {
12586: my @cidr_list;
12587: foreach my $item (@ok) {
12588: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
12589: }
12590: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
12591: }
12592: }
12593: }
12594: foreach my $field ('name','ip') {
12595: unless (($idx eq 'add') || ($changes{$itemid})) {
12596: if ($current{$field} ne $confhash{$itemid}{$field}) {
12597: $changes{$itemid} = 1;
12598: last;
12599: }
12600: }
12601: }
12602: $confhash{$itemid}{'commblocks'} = {};
12603:
12604: my %commblocks;
12605: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
12606: foreach my $type (@{$typeorder}) {
12607: if ($commblocks{$type}) {
12608: $confhash{$itemid}{'commblocks'}{$type} = 'on';
12609: }
12610: unless (($idx eq 'add') || ($changes{$itemid})) {
12611: if (ref($current{'commblocks'}) eq 'HASH') {
12612: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
12613: $changes{$itemid} = 1;
12614: }
12615: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
12616: $changes{$itemid} = 1;
12617: }
12618: }
12619: }
12620: $confhash{$itemid}{'courses'} = {};
12621: my %crsdeletions;
12622: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
12623: if (@delcrs) {
12624: map { $crsdeletions{$_} = 1; } @delcrs;
12625: }
12626: if (ref($current{'courses'}) eq 'HASH') {
12627: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
12628: if ($crsdeletions{$cid}) {
12629: $changes{$itemid} = 1;
12630: } else {
12631: $confhash{$itemid}{'courses'}{$cid} = 1;
12632: }
12633: }
12634: }
12635: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
12636: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
12637: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
12638: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
12639: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
12640: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
12641: $errors .= '<li><span class="LC_error">'.
12642: &mt('Invalid courseID [_1] omitted from list of allowed courses',
12643: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
12644: '</span></li>';
12645: } else {
12646: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
12647: $changes{$itemid} = 1;
12648: }
12649: }
12650: }
12651: if (@allpos > 0) {
12652: my $idx = 0;
12653: foreach my $itemid (@allpos) {
12654: if ($itemid ne '') {
12655: $confhash{$itemid}{'order'} = $idx;
12656: unless ($changes{$itemid}) {
12657: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12658: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12659: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
12660: $changes{$itemid} = 1;
12661: }
12662: }
12663: }
12664: }
12665: $idx ++;
12666: }
12667: }
12668: }
12669: if (keys(%changes)) {
12670: my %defaultshash = (
12671: ipaccess => \%confhash,
12672: );
12673: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12674: $dom);
12675: if ($putresult eq 'ok') {
12676: my $cachetime = 1800;
12677: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
12678: if (ref($lastactref) eq 'HASH') {
12679: $lastactref->{'ipaccess'} = 1;
12680: }
12681: $resulttext = &mt('Changes made:').'<ul>';
12682: my %bynum;
12683: foreach my $itemid (sort(keys(%changes))) {
12684: if (ref($confhash{$itemid}) eq 'HASH') {
12685: my $position = $confhash{$itemid}{'order'};
12686: if ($position =~ /^\d+$/) {
12687: $bynum{$position} = $itemid;
12688: }
12689: }
12690: }
12691: if (keys(%deletions)) {
12692: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
12693: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12694: }
12695: }
12696: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12697: my $itemid = $bynum{$pos};
12698: if (ref($confhash{$itemid}) eq 'HASH') {
12699: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
12700: my $position = $pos + 1;
12701: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12702: if ($confhash{$itemid}{'ip'} eq '') {
12703: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
12704: } else {
12705: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
12706: }
12707: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
12708: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
12709: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
12710: '</li>';
12711: } else {
12712: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
12713: }
12714: if (keys(%{$confhash{$itemid}{'courses'}})) {
12715: my @courses;
12716: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
12717: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
12718: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12719: }
12720: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12721: join('</li><li>',@courses).'</li></ul>';
12722: } else {
12723: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12724: }
1.395 raeburn 12725: $resulttext .= '</ul></li>';
1.394 raeburn 12726: }
12727: }
1.395 raeburn 12728: $resulttext .= '</ul>';
1.394 raeburn 12729: } else {
12730: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12731: }
12732: } else {
12733: $resulttext = &mt('No changes made');
12734: }
12735: if ($errors) {
12736: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12737: $errors.'</ul></p>';
12738: }
12739: return $resulttext;
12740: }
12741:
12742: sub get_ipaccess_id {
12743: my ($domain,$location) = @_;
12744: # get lock on ipaccess db
12745: my $lockhash = {
12746: lock => $env{'user.name'}.
12747: ':'.$env{'user.domain'},
12748: };
12749: my $tries = 0;
12750: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12751: my ($id,$error);
12752:
12753: while (($gotlock ne 'ok') && ($tries<10)) {
12754: $tries ++;
12755: sleep (0.1);
12756: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12757: }
12758: if ($gotlock eq 'ok') {
12759: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12760: if ($currids{'lock'}) {
12761: delete($currids{'lock'});
12762: if (keys(%currids)) {
12763: my @curr = sort { $a <=> $b } keys(%currids);
12764: if ($curr[-1] =~ /^\d+$/) {
12765: $id = 1 + $curr[-1];
12766: }
12767: } else {
12768: $id = 1;
12769: }
12770: if ($id) {
12771: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12772: $error = 'nostore';
12773: }
12774: } else {
12775: $error = 'nonumber';
12776: }
12777: }
12778: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12779: } else {
12780: $error = 'nolock';
12781: }
12782: return ($id,$error);
12783: }
12784:
1.6 raeburn 12785: sub modify_rolecolors {
1.205 raeburn 12786: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12787: my ($resulttext,%rolehash);
12788: $rolehash{'rolecolors'} = {};
1.55 raeburn 12789: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12790: if ($domconfig{'rolecolors'} eq '') {
12791: $domconfig{'rolecolors'} = {};
12792: }
12793: }
1.9 raeburn 12794: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12795: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12796: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12797: $dom);
12798: if ($putresult eq 'ok') {
12799: if (keys(%changes) > 0) {
1.41 raeburn 12800: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12801: if (ref($lastactref) eq 'HASH') {
12802: $lastactref->{'domainconfig'} = 1;
12803: }
1.6 raeburn 12804: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12805: $rolehash{'rolecolors'});
12806: } else {
12807: $resulttext = &mt('No changes made to default color schemes');
12808: }
12809: } else {
1.11 albertel 12810: $resulttext = '<span class="LC_error">'.
12811: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12812: }
12813: if ($errors) {
12814: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12815: $errors.'</ul>';
12816: }
12817: return $resulttext;
12818: }
12819:
12820: sub modify_colors {
1.9 raeburn 12821: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12822: my (%changes,%choices);
1.51 raeburn 12823: my @bgs;
1.6 raeburn 12824: my @links = ('link','alink','vlink');
1.41 raeburn 12825: my @logintext;
1.6 raeburn 12826: my @images;
12827: my $servadm = $r->dir_config('lonAdmEMail');
12828: my $errors;
1.200 raeburn 12829: my %defaults;
1.6 raeburn 12830: foreach my $role (@{$roles}) {
12831: if ($role eq 'login') {
1.12 raeburn 12832: %choices = &login_choices();
1.41 raeburn 12833: @logintext = ('textcol','bgcol');
1.12 raeburn 12834: } else {
12835: %choices = &color_font_choices();
12836: }
12837: if ($role eq 'login') {
1.41 raeburn 12838: @images = ('img','logo','domlogo','login');
1.51 raeburn 12839: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12840: } else {
12841: @images = ('img');
1.200 raeburn 12842: @bgs = ('pgbg','tabbg','sidebg');
12843: }
12844: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12845: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12846: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12847: }
12848: if ($role eq 'login') {
12849: foreach my $item (@logintext) {
1.234 raeburn 12850: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12851: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12852: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12853: }
12854: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12855: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12856: }
12857: }
12858: } else {
1.234 raeburn 12859: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12860: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12861: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12862: }
12863: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12864: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12865: }
1.6 raeburn 12866: }
1.200 raeburn 12867: foreach my $item (@bgs) {
1.234 raeburn 12868: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12869: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12870: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12871: }
12872: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12873: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12874: }
12875: }
12876: foreach my $item (@links) {
1.234 raeburn 12877: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12878: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12879: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12880: }
12881: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12882: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12883: }
1.6 raeburn 12884: }
1.46 raeburn 12885: my ($configuserok,$author_ok,$switchserver) =
12886: &config_check($dom,$confname,$servadm);
1.9 raeburn 12887: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12888: if (ref($domconfig->{$role}) ne 'HASH') {
12889: $domconfig->{$role} = {};
12890: }
1.8 raeburn 12891: foreach my $img (@images) {
1.402 raeburn 12892: if ($role eq 'login') {
12893: if (($img eq 'img') || ($img eq 'logo')) {
12894: if (defined($env{'form.login_showlogo_'.$img})) {
12895: $confhash->{$role}{'showlogo'}{$img} = 1;
12896: } else {
12897: $confhash->{$role}{'showlogo'}{$img} = 0;
12898: }
12899: }
12900: if ($env{'form.login_alt_'.$img} ne '') {
12901: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 12902: }
1.402 raeburn 12903: }
1.18 albertel 12904: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12905: && !defined($domconfig->{$role}{$img})
12906: && !$env{'form.'.$role.'_del_'.$img}
12907: && $env{'form.'.$role.'_import_'.$img}) {
12908: # import the old configured image from the .tab setting
12909: # if they haven't provided a new one
12910: $domconfig->{$role}{$img} =
12911: $env{'form.'.$role.'_import_'.$img};
12912: }
1.6 raeburn 12913: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12914: my $error;
1.6 raeburn 12915: if ($configuserok eq 'ok') {
1.9 raeburn 12916: if ($switchserver) {
1.12 raeburn 12917: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12918: } else {
12919: if ($author_ok eq 'ok') {
12920: my ($result,$logourl) =
12921: &publishlogo($r,'upload',$role.'_'.$img,
12922: $dom,$confname,$img,$width,$height);
12923: if ($result eq 'ok') {
12924: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12925: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12926: } else {
1.12 raeburn 12927: $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 12928: }
12929: } else {
1.46 raeburn 12930: $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 12931: }
12932: }
12933: } else {
1.46 raeburn 12934: $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 12935: }
12936: if ($error) {
1.8 raeburn 12937: &Apache::lonnet::logthis($error);
1.11 albertel 12938: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12939: }
12940: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12941: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12942: my $error;
12943: if ($configuserok eq 'ok') {
12944: # is confname an author?
12945: if ($switchserver eq '') {
12946: if ($author_ok eq 'ok') {
12947: my ($result,$logourl) =
12948: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12949: $dom,$confname,$img,$width,$height);
12950: if ($result eq 'ok') {
12951: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12952: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12953: }
12954: }
12955: }
12956: }
1.6 raeburn 12957: }
12958: }
12959: }
12960: if (ref($domconfig) eq 'HASH') {
12961: if (ref($domconfig->{$role}) eq 'HASH') {
12962: foreach my $img (@images) {
12963: if ($domconfig->{$role}{$img} ne '') {
12964: if ($env{'form.'.$role.'_del_'.$img}) {
12965: $confhash->{$role}{$img} = '';
1.12 raeburn 12966: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12967: } else {
1.9 raeburn 12968: if ($confhash->{$role}{$img} eq '') {
12969: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12970: }
1.6 raeburn 12971: }
12972: } else {
12973: if ($env{'form.'.$role.'_del_'.$img}) {
12974: $confhash->{$role}{$img} = '';
1.12 raeburn 12975: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12976: }
12977: }
1.402 raeburn 12978: if ($role eq 'login') {
12979: if (($img eq 'logo') || ($img eq 'img')) {
12980: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12981: if ($confhash->{$role}{'showlogo'}{$img} ne
12982: $domconfig->{$role}{'showlogo'}{$img}) {
12983: $changes{$role}{'showlogo'}{$img} = 1;
12984: }
12985: } else {
12986: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12987: $changes{$role}{'showlogo'}{$img} = 1;
12988: }
1.70 raeburn 12989: }
1.402 raeburn 12990: }
12991: if ($img ne 'login') {
12992: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
12993: if ($confhash->{$role}{'alttext'}{$img} ne
12994: $domconfig->{$role}{'alttext'}{$img}) {
12995: $changes{$role}{'alttext'}{$img} = 1;
12996: }
12997: } else {
12998: if ($confhash->{$role}{'alttext'}{$img} ne '') {
12999: $changes{$role}{'alttext'}{$img} = 1;
13000: }
1.70 raeburn 13001: }
13002: }
13003: }
13004: }
1.6 raeburn 13005: if ($domconfig->{$role}{'font'} ne '') {
13006: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13007: $changes{$role}{'font'} = 1;
13008: }
13009: } else {
13010: if ($confhash->{$role}{'font'}) {
13011: $changes{$role}{'font'} = 1;
13012: }
13013: }
1.107 raeburn 13014: if ($role ne 'login') {
13015: if ($domconfig->{$role}{'fontmenu'} ne '') {
13016: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13017: $changes{$role}{'fontmenu'} = 1;
13018: }
13019: } else {
13020: if ($confhash->{$role}{'fontmenu'}) {
13021: $changes{$role}{'fontmenu'} = 1;
13022: }
1.97 tempelho 13023: }
13024: }
1.6 raeburn 13025: foreach my $item (@bgs) {
13026: if ($domconfig->{$role}{$item} ne '') {
13027: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13028: $changes{$role}{'bgs'}{$item} = 1;
13029: }
13030: } else {
13031: if ($confhash->{$role}{$item}) {
13032: $changes{$role}{'bgs'}{$item} = 1;
13033: }
13034: }
13035: }
13036: foreach my $item (@links) {
13037: if ($domconfig->{$role}{$item} ne '') {
13038: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13039: $changes{$role}{'links'}{$item} = 1;
13040: }
13041: } else {
13042: if ($confhash->{$role}{$item}) {
13043: $changes{$role}{'links'}{$item} = 1;
13044: }
13045: }
13046: }
1.41 raeburn 13047: foreach my $item (@logintext) {
13048: if ($domconfig->{$role}{$item} ne '') {
13049: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13050: $changes{$role}{'logintext'}{$item} = 1;
13051: }
13052: } else {
13053: if ($confhash->{$role}{$item}) {
13054: $changes{$role}{'logintext'}{$item} = 1;
13055: }
13056: }
13057: }
1.6 raeburn 13058: } else {
13059: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13060: \@logintext,$confhash,\%changes);
1.6 raeburn 13061: }
13062: } else {
13063: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13064: \@logintext,$confhash,\%changes);
1.6 raeburn 13065: }
13066: }
13067: return ($errors,%changes);
13068: }
13069:
1.46 raeburn 13070: sub config_check {
13071: my ($dom,$confname,$servadm) = @_;
13072: my ($configuserok,$author_ok,$switchserver,%currroles);
13073: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13074: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13075: $confname,$servadm);
13076: if ($configuserok eq 'ok') {
13077: $switchserver = &check_switchserver($dom,$confname);
13078: if ($switchserver eq '') {
13079: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13080: }
13081: }
13082: return ($configuserok,$author_ok,$switchserver);
13083: }
13084:
1.6 raeburn 13085: sub default_change_checker {
1.41 raeburn 13086: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13087: foreach my $item (@{$links}) {
13088: if ($confhash->{$role}{$item}) {
13089: $changes->{$role}{'links'}{$item} = 1;
13090: }
13091: }
13092: foreach my $item (@{$bgs}) {
13093: if ($confhash->{$role}{$item}) {
13094: $changes->{$role}{'bgs'}{$item} = 1;
13095: }
13096: }
1.41 raeburn 13097: foreach my $item (@{$logintext}) {
13098: if ($confhash->{$role}{$item}) {
13099: $changes->{$role}{'logintext'}{$item} = 1;
13100: }
13101: }
1.6 raeburn 13102: foreach my $img (@{$images}) {
13103: if ($env{'form.'.$role.'_del_'.$img}) {
13104: $confhash->{$role}{$img} = '';
1.12 raeburn 13105: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13106: }
1.70 raeburn 13107: if ($role eq 'login') {
13108: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13109: $changes->{$role}{'showlogo'}{$img} = 1;
13110: }
1.402 raeburn 13111: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13112: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13113: $changes->{$role}{'alttext'}{$img} = 1;
13114: }
13115: }
1.70 raeburn 13116: }
1.6 raeburn 13117: }
13118: if ($confhash->{$role}{'font'}) {
13119: $changes->{$role}{'font'} = 1;
13120: }
1.48 raeburn 13121: }
1.6 raeburn 13122:
13123: sub display_colorchgs {
13124: my ($dom,$changes,$roles,$confhash) = @_;
13125: my (%choices,$resulttext);
13126: if (!grep(/^login$/,@{$roles})) {
13127: $resulttext = &mt('Changes made:').'<br />';
13128: }
13129: foreach my $role (@{$roles}) {
13130: if ($role eq 'login') {
13131: %choices = &login_choices();
13132: } else {
13133: %choices = &color_font_choices();
13134: }
13135: if (ref($changes->{$role}) eq 'HASH') {
13136: if ($role ne 'login') {
13137: $resulttext .= '<h4>'.&mt($role).'</h4>';
13138: }
13139: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13140: if ($role ne 'login') {
13141: $resulttext .= '<ul>';
13142: }
13143: if (ref($changes->{$role}{$key}) eq 'HASH') {
13144: if ($role ne 'login') {
13145: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13146: }
13147: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13148: if (($role eq 'login') && ($key eq 'showlogo')) {
13149: if ($confhash->{$role}{$key}{$item}) {
13150: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13151: } else {
13152: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13153: }
1.402 raeburn 13154: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13155: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13156: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13157: $confhash->{$role}{$key}{$item}).'</li>';
13158: } else {
13159: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13160: }
1.70 raeburn 13161: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13162: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13163: } else {
1.12 raeburn 13164: my $newitem = $confhash->{$role}{$item};
13165: if ($key eq 'images') {
1.306 raeburn 13166: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13167: }
13168: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13169: }
13170: }
13171: if ($role ne 'login') {
13172: $resulttext .= '</ul></li>';
13173: }
13174: } else {
13175: if ($confhash->{$role}{$key} eq '') {
13176: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13177: } else {
13178: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13179: }
13180: }
13181: if ($role ne 'login') {
13182: $resulttext .= '</ul>';
13183: }
13184: }
13185: }
13186: }
1.3 raeburn 13187: return $resulttext;
1.1 raeburn 13188: }
13189:
1.9 raeburn 13190: sub thumb_dimensions {
13191: return ('200','50');
13192: }
13193:
1.16 raeburn 13194: sub check_dimensions {
13195: my ($inputfile) = @_;
13196: my ($fullwidth,$fullheight);
13197: if ($inputfile =~ m|^[/\w.\-]+$|) {
13198: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13199: my $imageinfo = <PIPE>;
13200: if (!close(PIPE)) {
13201: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13202: }
13203: chomp($imageinfo);
13204: my ($fullsize) =
1.21 raeburn 13205: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13206: if ($fullsize) {
13207: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13208: }
13209: }
13210: }
13211: return ($fullwidth,$fullheight);
13212: }
13213:
1.9 raeburn 13214: sub check_configuser {
13215: my ($uhome,$dom,$confname,$servadm) = @_;
13216: my ($configuserok,%currroles);
13217: if ($uhome eq 'no_host') {
13218: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13219: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13220: $configuserok =
13221: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13222: $configpass,'','','','','',undef,$servadm);
13223: } else {
13224: $configuserok = 'ok';
13225: %currroles =
13226: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13227: }
13228: return ($configuserok,%currroles);
13229: }
13230:
13231: sub check_authorstatus {
13232: my ($dom,$confname,%currroles) = @_;
13233: my $author_ok;
1.40 raeburn 13234: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13235: my $start = time;
13236: my $end = 0;
13237: $author_ok =
13238: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13239: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13240: } else {
13241: $author_ok = 'ok';
13242: }
13243: return $author_ok;
13244: }
13245:
13246: sub publishlogo {
1.46 raeburn 13247: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 13248: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 13249: if ($action eq 'upload') {
13250: $fname=$env{'form.'.$formname.'.filename'};
13251: chop($env{'form.'.$formname});
13252: } else {
13253: ($fname) = ($formname =~ /([^\/]+)$/);
13254: }
1.46 raeburn 13255: if ($savefileas ne '') {
13256: $fname = $savefileas;
13257: }
1.9 raeburn 13258: $fname=&Apache::lonnet::clean_filename($fname);
13259: # See if there is anything left
13260: unless ($fname) { return ('error: no uploaded file'); }
13261: $fname="$subdir/$fname";
1.210 raeburn 13262: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 13263: my $filepath="$docroot/priv";
13264: my $relpath = "$dom/$confname";
1.9 raeburn 13265: my ($fnamepath,$file,$fetchthumb);
13266: $file=$fname;
13267: if ($fname=~m|/|) {
13268: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
13269: }
1.164 raeburn 13270: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 13271: my $count;
1.164 raeburn 13272: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 13273: $filepath.="/$parts[$count]";
13274: if ((-e $filepath)!=1) {
13275: mkdir($filepath,02770);
13276: }
13277: }
13278: # Check for bad extension and disallow upload
13279: if ($file=~/\.(\w+)$/ &&
13280: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
13281: $output =
1.207 bisitz 13282: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 13283: } elsif ($file=~/\.(\w+)$/ &&
13284: !defined(&Apache::loncommon::fileembstyle($1))) {
13285: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
13286: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 13287: $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 13288: } elsif (-d "$filepath/$file") {
1.195 bisitz 13289: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 13290: } else {
13291: my $source = $filepath.'/'.$file;
13292: my $logfile;
1.316 raeburn 13293: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 13294: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 13295: }
13296: print $logfile
13297: "\n================= Publish ".localtime()." ================\n".
13298: $env{'user.name'}.':'.$env{'user.domain'}."\n";
13299: # Save the file
1.316 raeburn 13300: if (!open(FH,">",$source)) {
1.9 raeburn 13301: &Apache::lonnet::logthis('Failed to create '.$source);
13302: return (&mt('Failed to create file'));
13303: }
13304: if ($action eq 'upload') {
13305: if (!print FH ($env{'form.'.$formname})) {
13306: &Apache::lonnet::logthis('Failed to write to '.$source);
13307: return (&mt('Failed to write file'));
13308: }
13309: } else {
13310: my $original = &Apache::lonnet::filelocation('',$formname);
13311: if(!copy($original,$source)) {
13312: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
13313: return (&mt('Failed to write file'));
13314: }
13315: }
13316: close(FH);
13317: chmod(0660, $source); # Permissions to rw-rw---.
13318:
13319: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
13320: my $copyfile=$targetdir.'/'.$file;
13321:
13322: my @parts=split(/\//,$targetdir);
13323: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
13324: for (my $count=5;$count<=$#parts;$count++) {
13325: $path.="/$parts[$count]";
13326: if (!-e $path) {
13327: print $logfile "\nCreating directory ".$path;
13328: mkdir($path,02770);
13329: }
13330: }
13331: my $versionresult;
13332: if (-e $copyfile) {
13333: $versionresult = &logo_versioning($targetdir,$file,$logfile);
13334: } else {
13335: $versionresult = 'ok';
13336: }
13337: if ($versionresult eq 'ok') {
13338: if (copy($source,$copyfile)) {
13339: print $logfile "\nCopied original source to ".$copyfile."\n";
13340: $output = 'ok';
13341: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 13342: push(@{$modified_urls},[$copyfile,$source]);
13343: my $metaoutput =
13344: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
13345: unless ($registered_cleanup) {
13346: my $handlers = $r->get_handlers('PerlCleanupHandler');
13347: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13348: $registered_cleanup=1;
13349: }
1.9 raeburn 13350: } else {
13351: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
13352: $output = &mt('Failed to copy file to RES space').", $!";
13353: }
13354: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
13355: my $inputfile = $filepath.'/'.$file;
13356: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 13357: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
13358: if ($fullwidth ne '' && $fullheight ne '') {
13359: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
13360: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 13361: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
13362: system({$args[0]} @args);
1.16 raeburn 13363: chmod(0660, $filepath.'/tn-'.$file);
13364: if (-e $outfile) {
13365: my $copyfile=$targetdir.'/tn-'.$file;
13366: if (copy($outfile,$copyfile)) {
13367: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 13368: my $thumb_metaoutput =
13369: &write_metadata($dom,$confname,$formname,
13370: $targetdir,'tn-'.$file,$logfile);
13371: push(@{$modified_urls},[$copyfile,$outfile]);
13372: unless ($registered_cleanup) {
13373: my $handlers = $r->get_handlers('PerlCleanupHandler');
13374: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13375: $registered_cleanup=1;
13376: }
1.267 raeburn 13377: $madethumb = 1;
1.16 raeburn 13378: } else {
13379: print $logfile "\nUnable to write ".$copyfile.
13380: ':'.$!."\n";
13381: }
13382: }
1.9 raeburn 13383: }
13384: }
13385: }
13386: } else {
13387: $output = $versionresult;
13388: }
13389: }
1.267 raeburn 13390: return ($output,$logourl,$madethumb);
1.9 raeburn 13391: }
13392:
13393: sub logo_versioning {
13394: my ($targetdir,$file,$logfile) = @_;
13395: my $target = $targetdir.'/'.$file;
13396: my ($maxversion,$fn,$extn,$output);
13397: $maxversion = 0;
13398: if ($file =~ /^(.+)\.(\w+)$/) {
13399: $fn=$1;
13400: $extn=$2;
13401: }
13402: opendir(DIR,$targetdir);
13403: while (my $filename=readdir(DIR)) {
13404: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
13405: $maxversion=($1>$maxversion)?$1:$maxversion;
13406: }
13407: }
13408: $maxversion++;
13409: print $logfile "\nCreating old version ".$maxversion."\n";
13410: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
13411: if (copy($target,$copyfile)) {
13412: print $logfile "Copied old target to ".$copyfile."\n";
13413: $copyfile=$copyfile.'.meta';
13414: if (copy($target.'.meta',$copyfile)) {
13415: print $logfile "Copied old target metadata to ".$copyfile."\n";
13416: $output = 'ok';
13417: } else {
13418: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
13419: $output = &mt('Failed to copy old meta').", $!, ";
13420: }
13421: } else {
13422: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
13423: $output = &mt('Failed to copy old target').", $!, ";
13424: }
13425: return $output;
13426: }
13427:
13428: sub write_metadata {
13429: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
13430: my (%metadatafields,%metadatakeys,$output);
13431: $metadatafields{'title'}=$formname;
13432: $metadatafields{'creationdate'}=time;
13433: $metadatafields{'lastrevisiondate'}=time;
13434: $metadatafields{'copyright'}='public';
13435: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
13436: $env{'user.domain'};
13437: $metadatafields{'authorspace'}=$confname.':'.$dom;
13438: $metadatafields{'domain'}=$dom;
13439: {
13440: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
13441: my $mfh;
1.316 raeburn 13442: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 13443: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 13444: unless ($_=~/\./) {
13445: my $unikey=$_;
13446: $unikey=~/^([A-Za-z]+)/;
13447: my $tag=$1;
13448: $tag=~tr/A-Z/a-z/;
13449: print $mfh "\n\<$tag";
13450: foreach (split(/\,/,$metadatakeys{$unikey})) {
13451: my $value=$metadatafields{$unikey.'.'.$_};
13452: $value=~s/\"/\'\'/g;
13453: print $mfh ' '.$_.'="'.$value.'"';
13454: }
13455: print $mfh '>'.
13456: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
13457: .'</'.$tag.'>';
13458: }
13459: }
13460: $output = 'ok';
13461: print $logfile "\nWrote metadata";
13462: close($mfh);
13463: } else {
13464: print $logfile "\nFailed to open metadata file";
1.9 raeburn 13465: $output = &mt('Could not write metadata');
13466: }
13467: }
1.155 raeburn 13468: return $output;
13469: }
13470:
13471: sub notifysubscribed {
13472: foreach my $targetsource (@{$modified_urls}){
13473: next unless (ref($targetsource) eq 'ARRAY');
13474: my ($target,$source)=@{$targetsource};
13475: if ($source ne '') {
1.316 raeburn 13476: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13477: print $logfh "\nCleanup phase: Notifications\n";
13478: my @subscribed=&subscribed_hosts($target);
13479: foreach my $subhost (@subscribed) {
13480: print $logfh "\nNotifying host ".$subhost.':';
13481: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13482: print $logfh $reply;
13483: }
13484: my @subscribedmeta=&subscribed_hosts("$target.meta");
13485: foreach my $subhost (@subscribedmeta) {
13486: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13487: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13488: $subhost);
13489: print $logfh $reply;
13490: }
13491: print $logfh "\n============ Done ============\n";
1.160 raeburn 13492: close($logfh);
1.155 raeburn 13493: }
13494: }
13495: }
13496: return OK;
13497: }
13498:
13499: sub subscribed_hosts {
13500: my ($target) = @_;
13501: my @subscribed;
1.316 raeburn 13502: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13503: while (my $subline=<$fh>) {
13504: if ($subline =~ /^($match_lonid):/) {
13505: my $host = $1;
13506: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13507: unless (grep(/^\Q$host\E$/,@subscribed)) {
13508: push(@subscribed,$host);
13509: }
13510: }
13511: }
13512: }
13513: }
13514: return @subscribed;
1.9 raeburn 13515: }
13516:
13517: sub check_switchserver {
13518: my ($dom,$confname) = @_;
13519: my ($allowed,$switchserver);
13520: my $home = &Apache::lonnet::homeserver($confname,$dom);
13521: if ($home eq 'no_host') {
13522: $home = &Apache::lonnet::domain($dom,'primary');
13523: }
13524: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13525: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13526: if (!$allowed) {
1.180 raeburn 13527: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13528: }
13529: return $switchserver;
13530: }
13531:
1.1 raeburn 13532: sub modify_quotas {
1.216 raeburn 13533: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13534: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13535: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13536: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13537: $validationfieldsref);
1.86 raeburn 13538: if ($action eq 'quotas') {
13539: $context = 'tools';
1.163 raeburn 13540: } else {
1.86 raeburn 13541: $context = $action;
13542: }
13543: if ($context eq 'requestcourses') {
1.325 raeburn 13544: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13545: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13546: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13547: %titles = &courserequest_titles();
13548: $toolregexp = join('|',@usertools);
13549: %conditions = &courserequest_conditions();
1.216 raeburn 13550: $confname = $dom.'-domainconfig';
13551: my $servadm = $r->dir_config('lonAdmEMail');
13552: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13553: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13554: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13555: } elsif ($context eq 'requestauthor') {
13556: @usertools = ('author');
13557: %titles = &authorrequest_titles();
1.86 raeburn 13558: } else {
1.162 raeburn 13559: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 13560: %titles = &tool_titles();
1.86 raeburn 13561: }
1.212 raeburn 13562: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13563: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13564: foreach my $key (keys(%env)) {
1.101 raeburn 13565: if ($context eq 'requestcourses') {
13566: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13567: my $item = $1;
13568: my $type = $2;
13569: if ($type =~ /^limit_(.+)/) {
13570: $limithash{$item}{$1} = $env{$key};
13571: } else {
13572: $confhash{$item}{$type} = $env{$key};
13573: }
13574: }
1.163 raeburn 13575: } elsif ($context eq 'requestauthor') {
13576: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13577: $confhash{$1} = $env{$key};
13578: }
1.101 raeburn 13579: } else {
1.86 raeburn 13580: if ($key =~ /^form\.quota_(.+)$/) {
13581: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13582: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13583: $confhash{'authorquota'}{$1} = $env{$key};
13584: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13585: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13586: }
1.72 raeburn 13587: }
13588: }
1.163 raeburn 13589: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 13590: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 13591: @approvalnotify = sort(@approvalnotify);
13592: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 13593: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 13594: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
13595: foreach my $type (@hasuniquecode) {
13596: if (grep(/^\Q$type\E$/,@crstypes)) {
13597: $confhash{'uniquecode'}{$type} = 1;
13598: }
1.216 raeburn 13599: }
1.242 raeburn 13600: my (%newbook,%allpos);
1.216 raeburn 13601: if ($context eq 'requestcourses') {
1.242 raeburn 13602: foreach my $type ('textbooks','templates') {
13603: @{$allpos{$type}} = ();
13604: my $invalid;
13605: if ($type eq 'textbooks') {
13606: $invalid = &mt('Invalid LON-CAPA course for textbook');
13607: } else {
13608: $invalid = &mt('Invalid LON-CAPA course for template');
13609: }
13610: if ($env{'form.'.$type.'_addbook'}) {
13611: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
13612: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
13613: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
13614: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
13615: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
13616: } else {
13617: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
13618: my $position = $env{'form.'.$type.'_addbook_pos'};
13619: $position =~ s/\D+//g;
13620: if ($position ne '') {
13621: $allpos{$type}[$position] = $newbook{$type};
13622: }
1.216 raeburn 13623: }
1.242 raeburn 13624: } else {
13625: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 13626: }
13627: }
1.242 raeburn 13628: }
1.216 raeburn 13629: }
1.102 raeburn 13630: if (ref($domconfig{$action}) eq 'HASH') {
13631: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
13632: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
13633: $changes{'notify'}{'approval'} = 1;
13634: }
13635: } else {
1.144 raeburn 13636: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13637: $changes{'notify'}{'approval'} = 1;
13638: }
13639: }
1.218 raeburn 13640: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
13641: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13642: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
13643: unless ($confhash{'uniquecode'}{$crstype}) {
13644: $changes{'uniquecode'} = 1;
13645: }
13646: }
13647: unless ($changes{'uniquecode'}) {
13648: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
13649: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
13650: $changes{'uniquecode'} = 1;
13651: }
13652: }
13653: }
13654: } else {
13655: $changes{'uniquecode'} = 1;
13656: }
13657: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
13658: $changes{'uniquecode'} = 1;
1.216 raeburn 13659: }
13660: if ($context eq 'requestcourses') {
1.242 raeburn 13661: foreach my $type ('textbooks','templates') {
13662: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13663: my %deletions;
13664: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
13665: if (@todelete) {
13666: map { $deletions{$_} = 1; } @todelete;
13667: }
13668: my %imgdeletions;
13669: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13670: if (@todeleteimages) {
13671: map { $imgdeletions{$_} = 1; } @todeleteimages;
13672: }
13673: my $maxnum = $env{'form.'.$type.'_maxnum'};
13674: for (my $i=0; $i<=$maxnum; $i++) {
13675: my $itemid = $env{'form.'.$type.'_id_'.$i};
13676: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13677: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13678: if ($deletions{$key}) {
13679: if ($domconfig{$action}{$type}{$key}{'image'}) {
13680: #FIXME need to obsolete item in RES space
13681: }
13682: next;
13683: } else {
13684: my $newpos = $env{'form.'.$itemid};
13685: $newpos =~ s/\D+//g;
1.243 raeburn 13686: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13687: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13688: ($type eq 'templates'));
1.242 raeburn 13689: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13690: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13691: $changes{$type}{$key} = 1;
13692: }
13693: }
13694: $allpos{$type}[$newpos] = $key;
13695: }
13696: if ($imgdeletions{$key}) {
13697: $changes{$type}{$key} = 1;
1.216 raeburn 13698: #FIXME need to obsolete item in RES space
1.242 raeburn 13699: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13700: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13701: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13702: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13703: } else {
13704: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13705: $cdom,$cnum,$type,$configuserok,
13706: $switchserver,$author_ok);
13707: if ($imgurl) {
13708: $confhash{$type}{$key}{'image'} = $imgurl;
13709: $changes{$type}{$key} = 1;
13710: }
13711: if ($error) {
13712: &Apache::lonnet::logthis($error);
13713: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13714: }
13715: }
1.242 raeburn 13716: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13717: $confhash{$type}{$key}{'image'} =
13718: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13719: }
13720: }
13721: }
13722: }
13723: }
13724: }
1.102 raeburn 13725: } else {
1.144 raeburn 13726: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13727: $changes{'notify'}{'approval'} = 1;
13728: }
1.218 raeburn 13729: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13730: $changes{'uniquecode'} = 1;
13731: }
13732: }
13733: if ($context eq 'requestcourses') {
1.242 raeburn 13734: foreach my $type ('textbooks','templates') {
13735: if ($newbook{$type}) {
13736: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13737: foreach my $item ('subject','title','publisher','author') {
13738: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13739: ($type eq 'template'));
1.242 raeburn 13740: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13741: if ($env{'form.'.$type.'_addbook_'.$item}) {
13742: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13743: }
13744: }
13745: if ($type eq 'textbooks') {
13746: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13747: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13748: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13749: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13750: } else {
13751: my ($imageurl,$error) =
13752: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13753: $configuserok,$switchserver,$author_ok);
13754: if ($imageurl) {
13755: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13756: }
13757: if ($error) {
13758: &Apache::lonnet::logthis($error);
13759: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13760: }
1.242 raeburn 13761: }
13762: }
1.216 raeburn 13763: }
13764: }
1.242 raeburn 13765: if (@{$allpos{$type}} > 0) {
13766: my $idx = 0;
13767: foreach my $item (@{$allpos{$type}}) {
13768: if ($item ne '') {
13769: $confhash{$type}{$item}{'order'} = $idx;
13770: if (ref($domconfig{$action}) eq 'HASH') {
13771: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13772: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13773: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13774: $changes{$type}{$item} = 1;
13775: }
1.216 raeburn 13776: }
13777: }
13778: }
1.242 raeburn 13779: $idx ++;
1.216 raeburn 13780: }
13781: }
13782: }
13783: }
1.235 raeburn 13784: if (ref($validationitemsref) eq 'ARRAY') {
13785: foreach my $item (@{$validationitemsref}) {
13786: if ($item eq 'fields') {
13787: my @changed;
13788: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13789: if (@{$confhash{'validation'}{$item}} > 0) {
13790: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13791: }
1.266 raeburn 13792: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13793: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13794: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13795: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13796: $domconfig{'requestcourses'}{'validation'}{$item});
13797: } else {
13798: @changed = @{$confhash{'validation'}{$item}};
13799: }
1.235 raeburn 13800: } else {
13801: @changed = @{$confhash{'validation'}{$item}};
13802: }
13803: } else {
13804: @changed = @{$confhash{'validation'}{$item}};
13805: }
13806: if (@changed) {
13807: if ($confhash{'validation'}{$item}) {
13808: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13809: } else {
13810: $changes{'validation'}{$item} = &mt('None');
13811: }
13812: }
13813: } else {
13814: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13815: if ($item eq 'markup') {
13816: if ($env{'form.requestcourses_validation_'.$item}) {
13817: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13818: }
13819: }
1.266 raeburn 13820: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13821: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13822: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13823: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13824: }
13825: } else {
13826: if ($confhash{'validation'}{$item} ne '') {
13827: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13828: }
1.235 raeburn 13829: }
13830: } else {
13831: if ($confhash{'validation'}{$item} ne '') {
13832: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13833: }
13834: }
13835: }
13836: }
13837: }
13838: if ($env{'form.validationdc'}) {
13839: my $newval = $env{'form.validationdc'};
1.285 raeburn 13840: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13841: if (exists($domcoords{$newval})) {
13842: $confhash{'validation'}{'dc'} = $newval;
13843: }
13844: }
13845: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13846: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13847: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13848: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13849: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13850: if ($confhash{'validation'}{'dc'} eq '') {
13851: $changes{'validation'}{'dc'} = &mt('None');
13852: } else {
13853: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13854: }
1.235 raeburn 13855: }
1.266 raeburn 13856: } elsif ($confhash{'validation'}{'dc'} ne '') {
13857: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13858: }
13859: } elsif ($confhash{'validation'}{'dc'} ne '') {
13860: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13861: }
13862: } elsif ($confhash{'validation'}{'dc'} ne '') {
13863: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13864: }
1.266 raeburn 13865: } else {
13866: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13867: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13868: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13869: $changes{'validation'}{'dc'} = &mt('None');
13870: }
13871: }
1.235 raeburn 13872: }
13873: }
1.102 raeburn 13874: }
13875: } else {
1.86 raeburn 13876: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13877: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13878: }
1.72 raeburn 13879: foreach my $item (@usertools) {
13880: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13881: my $unset;
1.101 raeburn 13882: if ($context eq 'requestcourses') {
1.104 raeburn 13883: $unset = '0';
13884: if ($type eq '_LC_adv') {
13885: $unset = '';
13886: }
1.101 raeburn 13887: if ($confhash{$item}{$type} eq 'autolimit') {
13888: $confhash{$item}{$type} .= '=';
13889: unless ($limithash{$item}{$type} =~ /\D/) {
13890: $confhash{$item}{$type} .= $limithash{$item}{$type};
13891: }
13892: }
1.163 raeburn 13893: } elsif ($context eq 'requestauthor') {
13894: $unset = '0';
13895: if ($type eq '_LC_adv') {
13896: $unset = '';
13897: }
1.72 raeburn 13898: } else {
1.101 raeburn 13899: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13900: $confhash{$item}{$type} = 1;
13901: } else {
13902: $confhash{$item}{$type} = 0;
13903: }
1.72 raeburn 13904: }
1.86 raeburn 13905: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13906: if ($action eq 'requestauthor') {
13907: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13908: $changes{$type} = 1;
13909: }
13910: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13911: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13912: $changes{$item}{$type} = 1;
13913: }
13914: } else {
13915: if ($context eq 'requestcourses') {
1.104 raeburn 13916: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13917: $changes{$item}{$type} = 1;
13918: }
13919: } else {
13920: if (!$confhash{$item}{$type}) {
13921: $changes{$item}{$type} = 1;
13922: }
13923: }
13924: }
13925: } else {
13926: if ($context eq 'requestcourses') {
1.104 raeburn 13927: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13928: $changes{$item}{$type} = 1;
13929: }
1.163 raeburn 13930: } elsif ($context eq 'requestauthor') {
13931: if ($confhash{$type} ne $unset) {
13932: $changes{$type} = 1;
13933: }
1.72 raeburn 13934: } else {
13935: if (!$confhash{$item}{$type}) {
13936: $changes{$item}{$type} = 1;
13937: }
13938: }
13939: }
1.1 raeburn 13940: }
13941: }
1.163 raeburn 13942: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13943: if (ref($domconfig{'quotas'}) eq 'HASH') {
13944: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13945: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13946: if (exists($confhash{'defaultquota'}{$key})) {
13947: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13948: $changes{'defaultquota'}{$key} = 1;
13949: }
13950: } else {
13951: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13952: }
13953: }
1.86 raeburn 13954: } else {
13955: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13956: if (exists($confhash{'defaultquota'}{$key})) {
13957: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13958: $changes{'defaultquota'}{$key} = 1;
13959: }
13960: } else {
13961: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13962: }
1.1 raeburn 13963: }
13964: }
1.197 raeburn 13965: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13966: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13967: if (exists($confhash{'authorquota'}{$key})) {
13968: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13969: $changes{'authorquota'}{$key} = 1;
13970: }
13971: } else {
13972: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13973: }
13974: }
13975: }
1.1 raeburn 13976: }
1.86 raeburn 13977: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13978: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13979: if (ref($domconfig{'quotas'}) eq 'HASH') {
13980: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13981: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13982: $changes{'defaultquota'}{$key} = 1;
13983: }
13984: } else {
13985: if (!exists($domconfig{'quotas'}{$key})) {
13986: $changes{'defaultquota'}{$key} = 1;
13987: }
1.72 raeburn 13988: }
13989: } else {
1.86 raeburn 13990: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13991: }
1.1 raeburn 13992: }
13993: }
1.197 raeburn 13994: if (ref($confhash{'authorquota'}) eq 'HASH') {
13995: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13996: if (ref($domconfig{'quotas'}) eq 'HASH') {
13997: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13998: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13999: $changes{'authorquota'}{$key} = 1;
14000: }
14001: } else {
14002: $changes{'authorquota'}{$key} = 1;
14003: }
14004: } else {
14005: $changes{'authorquota'}{$key} = 1;
14006: }
14007: }
14008: }
1.1 raeburn 14009: }
1.72 raeburn 14010:
1.163 raeburn 14011: if ($context eq 'requestauthor') {
14012: $domdefaults{'requestauthor'} = \%confhash;
14013: } else {
14014: foreach my $key (keys(%confhash)) {
1.242 raeburn 14015: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14016: $domdefaults{$key} = $confhash{$key};
14017: }
1.163 raeburn 14018: }
1.72 raeburn 14019: }
1.163 raeburn 14020:
1.1 raeburn 14021: my %quotahash = (
1.86 raeburn 14022: $action => { %confhash }
1.1 raeburn 14023: );
14024: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14025: $dom);
14026: if ($putresult eq 'ok') {
14027: if (keys(%changes) > 0) {
1.72 raeburn 14028: my $cachetime = 24*60*60;
14029: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14030: if (ref($lastactref) eq 'HASH') {
14031: $lastactref->{'domdefaults'} = 1;
14032: }
1.1 raeburn 14033: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14034: unless (($context eq 'requestcourses') ||
1.163 raeburn 14035: ($context eq 'requestauthor')) {
1.86 raeburn 14036: if (ref($changes{'defaultquota'}) eq 'HASH') {
14037: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14038: foreach my $type (@{$types},'default') {
14039: if (defined($changes{'defaultquota'}{$type})) {
14040: my $typetitle = $usertypes->{$type};
14041: if ($type eq 'default') {
14042: $typetitle = $othertitle;
14043: }
1.213 raeburn 14044: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14045: }
14046: }
1.86 raeburn 14047: $resulttext .= '</ul></li>';
1.72 raeburn 14048: }
1.197 raeburn 14049: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 14050: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 14051: foreach my $type (@{$types},'default') {
14052: if (defined($changes{'authorquota'}{$type})) {
14053: my $typetitle = $usertypes->{$type};
14054: if ($type eq 'default') {
14055: $typetitle = $othertitle;
14056: }
1.213 raeburn 14057: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 14058: }
14059: }
14060: $resulttext .= '</ul></li>';
14061: }
1.72 raeburn 14062: }
1.80 raeburn 14063: my %newenv;
1.72 raeburn 14064: foreach my $item (@usertools) {
1.163 raeburn 14065: my (%haschgs,%inconf);
14066: if ($context eq 'requestauthor') {
14067: %haschgs = %changes;
1.210 raeburn 14068: %inconf = %confhash;
1.163 raeburn 14069: } else {
14070: if (ref($changes{$item}) eq 'HASH') {
14071: %haschgs = %{$changes{$item}};
14072: }
14073: if (ref($confhash{$item}) eq 'HASH') {
14074: %inconf = %{$confhash{$item}};
14075: }
14076: }
14077: if (keys(%haschgs) > 0) {
1.80 raeburn 14078: my $newacc =
14079: &Apache::lonnet::usertools_access($env{'user.name'},
14080: $env{'user.domain'},
1.86 raeburn 14081: $item,'reload',$context);
1.210 raeburn 14082: if (($context eq 'requestcourses') ||
1.163 raeburn 14083: ($context eq 'requestauthor')) {
1.108 raeburn 14084: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14085: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14086: }
14087: } else {
14088: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14089: $newenv{'environment.availabletools.'.$item} = $newacc;
14090: }
1.80 raeburn 14091: }
1.163 raeburn 14092: unless ($context eq 'requestauthor') {
14093: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14094: }
1.72 raeburn 14095: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14096: if ($haschgs{$type}) {
1.72 raeburn 14097: my $typetitle = $usertypes->{$type};
14098: if ($type eq 'default') {
14099: $typetitle = $othertitle;
14100: } elsif ($type eq '_LC_adv') {
14101: $typetitle = 'LON-CAPA Advanced Users';
14102: }
1.163 raeburn 14103: if ($inconf{$type}) {
1.101 raeburn 14104: if ($context eq 'requestcourses') {
14105: my $cond;
1.163 raeburn 14106: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14107: if ($1 eq '') {
14108: $cond = &mt('(Automatic processing of any request).');
14109: } else {
14110: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14111: }
14112: } else {
1.163 raeburn 14113: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14114: }
14115: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14116: } elsif ($context eq 'requestauthor') {
14117: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14118: $titles{$inconf{$type}},$typetitle);
14119:
1.101 raeburn 14120: } else {
14121: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14122: }
1.72 raeburn 14123: } else {
1.104 raeburn 14124: if ($type eq '_LC_adv') {
1.163 raeburn 14125: if ($inconf{$type} eq '0') {
1.104 raeburn 14126: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14127: } else {
14128: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14129: }
14130: } else {
14131: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14132: }
1.72 raeburn 14133: }
14134: }
1.26 raeburn 14135: }
1.163 raeburn 14136: unless ($context eq 'requestauthor') {
14137: $resulttext .= '</ul></li>';
14138: }
1.26 raeburn 14139: }
1.1 raeburn 14140: }
1.163 raeburn 14141: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14142: if (ref($changes{'notify'}) eq 'HASH') {
14143: if ($changes{'notify'}{'approval'}) {
14144: if (ref($confhash{'notify'}) eq 'HASH') {
14145: if ($confhash{'notify'}{'approval'}) {
14146: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14147: } else {
1.163 raeburn 14148: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14149: }
14150: }
14151: }
14152: }
14153: }
1.216 raeburn 14154: if ($action eq 'requestcourses') {
14155: my @offon = ('off','on');
14156: if ($changes{'uniquecode'}) {
1.218 raeburn 14157: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14158: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14159: $resulttext .= '<li>'.
14160: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14161: '</li>';
14162: } else {
14163: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14164: '</li>';
14165: }
1.216 raeburn 14166: }
1.242 raeburn 14167: foreach my $type ('textbooks','templates') {
14168: if (ref($changes{$type}) eq 'HASH') {
14169: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14170: foreach my $key (sort(keys(%{$changes{$type}}))) {
14171: my %coursehash = &Apache::lonnet::coursedescription($key);
14172: my $coursetitle = $coursehash{'description'};
14173: my $position = $confhash{$type}{$key}{'order'} + 1;
14174: $resulttext .= '<li>';
1.243 raeburn 14175: foreach my $item ('subject','title','publisher','author') {
14176: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14177: ($type eq 'templates'));
1.242 raeburn 14178: my $name = $item.':';
14179: $name =~ s/^(\w)/\U$1/;
14180: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14181: }
14182: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14183: if ($type eq 'textbooks') {
14184: if ($confhash{$type}{$key}{'image'}) {
14185: $resulttext .= ' '.&mt('Image: [_1]',
14186: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14187: ' alt="Textbook cover" />').'<br />';
14188: }
14189: }
14190: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14191: }
1.242 raeburn 14192: $resulttext .= '</ul></li>';
1.216 raeburn 14193: }
14194: }
1.235 raeburn 14195: if (ref($changes{'validation'}) eq 'HASH') {
14196: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14197: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14198: foreach my $item (@{$validationitemsref}) {
14199: if (exists($changes{'validation'}{$item})) {
14200: if ($item eq 'markup') {
14201: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14202: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14203: } else {
14204: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14205: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14206: }
14207: }
14208: }
14209: if (exists($changes{'validation'}{'dc'})) {
14210: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14211: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14212: }
14213: }
14214: }
1.216 raeburn 14215: }
1.1 raeburn 14216: $resulttext .= '</ul>';
1.80 raeburn 14217: if (keys(%newenv)) {
14218: &Apache::lonnet::appenv(\%newenv);
14219: }
1.1 raeburn 14220: } else {
1.86 raeburn 14221: if ($context eq 'requestcourses') {
14222: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14223: } elsif ($context eq 'requestauthor') {
14224: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14225: } else {
1.90 weissno 14226: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14227: }
1.1 raeburn 14228: }
14229: } else {
1.11 albertel 14230: $resulttext = '<span class="LC_error">'.
14231: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14232: }
1.216 raeburn 14233: if ($errors) {
14234: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14235: '<ul>'.$errors.'</ul></p>';
14236: }
1.3 raeburn 14237: return $resulttext;
1.1 raeburn 14238: }
14239:
1.216 raeburn 14240: sub process_textbook_image {
1.242 raeburn 14241: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14242: my $filename = $env{'form.'.$caller.'.filename'};
14243: my ($error,$url);
14244: my ($width,$height) = (50,50);
14245: if ($configuserok eq 'ok') {
14246: if ($switchserver) {
14247: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14248: $switchserver);
14249: } elsif ($author_ok eq 'ok') {
14250: my ($result,$imageurl) =
14251: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 14252: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 14253: if ($result eq 'ok') {
14254: $url = $imageurl;
14255: } else {
14256: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14257: }
14258: } else {
14259: $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);
14260: }
14261: } else {
14262: $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);
14263: }
14264: return ($url,$error);
14265: }
14266:
1.267 raeburn 14267: sub modify_ltitools {
14268: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14269: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 14270: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 14271: my $confname = $dom.'-domainconfig';
14272: my $servadm = $r->dir_config('lonAdmEMail');
14273: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14274: my (%posslti,%possfield);
14275: my @courseroles = ('cc','in','ta','ep','st');
14276: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
14277: map { $posslti{$_} = 1; } @ltiroles;
14278: my @allfields = ('fullname','firstname','lastname','email','user','roles');
14279: map { $possfield{$_} = 1; } @allfields;
14280: my %lt = <itools_names();
14281: if ($env{'form.ltitools_add'}) {
14282: my $title = $env{'form.ltitools_add_title'};
14283: $title =~ s/(`)/'/g;
14284: ($newid,my $error) = &get_ltitools_id($dom,$title);
14285: if ($newid) {
14286: my $position = $env{'form.ltitools_add_pos'};
14287: $position =~ s/\D+//g;
14288: if ($position ne '') {
14289: $allpos[$position] = $newid;
14290: }
14291: $changes{$newid} = 1;
1.322 raeburn 14292: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 14293: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 14294: if ($item eq 'lifetime') {
14295: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
14296: }
1.267 raeburn 14297: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 14298: if (($item eq 'key') || ($item eq 'secret')) {
14299: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14300: } else {
14301: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14302: }
1.267 raeburn 14303: }
14304: }
14305: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
14306: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
14307: }
14308: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
14309: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
14310: }
1.323 raeburn 14311: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
14312: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
14313: } else {
14314: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
14315: }
1.296 raeburn 14316: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 14317: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
14318: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 14319: if (($item eq 'width') || ($item eq 'height')) {
14320: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
14321: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14322: }
14323: } else {
14324: if ($env{'form.ltitools_add_'.$item} ne '') {
14325: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14326: }
1.267 raeburn 14327: }
14328: }
14329: if ($env{'form.ltitools_add_target'} eq 'window') {
14330: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 14331: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
14332: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 14333: } else {
14334: $confhash{$newid}{'display'}{'target'} = 'iframe';
14335: }
14336: foreach my $item ('passback','roster') {
1.319 raeburn 14337: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 14338: $confhash{$newid}{$item} = 1;
1.319 raeburn 14339: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
14340: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
14341: $lifetime =~ s/^\s+|\s+$//g;
14342: if ($lifetime =~ /^\d+\.?\d*$/) {
14343: $confhash{$newid}{$item.'valid'} = $lifetime;
14344: }
14345: }
1.267 raeburn 14346: }
14347: }
14348: if ($env{'form.ltitools_add_image.filename'} ne '') {
14349: my ($imageurl,$error) =
1.307 raeburn 14350: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 14351: $configuserok,$switchserver,$author_ok);
14352: if ($imageurl) {
14353: $confhash{$newid}{'image'} = $imageurl;
14354: }
14355: if ($error) {
14356: &Apache::lonnet::logthis($error);
14357: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14358: }
14359: }
14360: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
14361: foreach my $field (@fields) {
14362: if ($possfield{$field}) {
14363: if ($field eq 'roles') {
14364: foreach my $role (@courseroles) {
14365: my $choice = $env{'form.ltitools_add_roles_'.$role};
14366: if (($choice ne '') && ($posslti{$choice})) {
14367: $confhash{$newid}{'roles'}{$role} = $choice;
14368: if ($role eq 'cc') {
14369: $confhash{$newid}{'roles'}{'co'} = $choice;
14370: }
14371: }
14372: }
14373: } else {
14374: $confhash{$newid}{'fields'}{$field} = 1;
14375: }
14376: }
14377: }
1.324 raeburn 14378: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
14379: if ($confhash{$newid}{'fields'}{'user'}) {
14380: if ($env{'form.ltitools_userincdom_add'}) {
14381: $confhash{$newid}{'incdom'} = 1;
14382: }
14383: }
14384: }
1.273 raeburn 14385: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
14386: foreach my $item (@courseconfig) {
14387: $confhash{$newid}{'crsconf'}{$item} = 1;
14388: }
1.267 raeburn 14389: if ($env{'form.ltitools_add_custom'}) {
14390: my $name = $env{'form.ltitools_add_custom_name'};
14391: my $value = $env{'form.ltitools_add_custom_value'};
14392: $value =~ s/(`)/'/g;
14393: $name =~ s/(`)/'/g;
14394: $confhash{$newid}{'custom'}{$name} = $value;
14395: }
14396: } else {
14397: my $error = &mt('Failed to acquire unique ID for new external tool');
14398: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14399: }
14400: }
14401: if (ref($domconfig{$action}) eq 'HASH') {
14402: my %deletions;
14403: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
14404: if (@todelete) {
14405: map { $deletions{$_} = 1; } @todelete;
14406: }
14407: my %customadds;
14408: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
14409: if (@newcustom) {
14410: map { $customadds{$_} = 1; } @newcustom;
14411: }
14412: my %imgdeletions;
14413: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
14414: if (@todeleteimages) {
14415: map { $imgdeletions{$_} = 1; } @todeleteimages;
14416: }
14417: my $maxnum = $env{'form.ltitools_maxnum'};
14418: for (my $i=0; $i<=$maxnum; $i++) {
14419: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 14420: $itemid =~ s/\D+//g;
1.267 raeburn 14421: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14422: if ($deletions{$itemid}) {
14423: if ($domconfig{$action}{$itemid}{'image'}) {
14424: #FIXME need to obsolete item in RES space
14425: }
14426: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
14427: next;
14428: } else {
14429: my $newpos = $env{'form.ltitools_'.$itemid};
14430: $newpos =~ s/\D+//g;
1.322 raeburn 14431: foreach my $item ('title','url','lifetime') {
1.267 raeburn 14432: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14433: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14434: $changes{$itemid} = 1;
14435: }
14436: }
1.297 raeburn 14437: foreach my $item ('key','secret') {
14438: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14439: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
14440: $changes{$itemid} = 1;
14441: }
14442: }
1.267 raeburn 14443: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
14444: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
14445: }
14446: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
14447: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
14448: }
1.323 raeburn 14449: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
14450: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
14451: } else {
14452: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
14453: }
14454: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
14455: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
14456: $changes{$itemid} = 1;
14457: }
14458: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
14459: $changes{$itemid} = 1;
14460: }
1.267 raeburn 14461: foreach my $size ('width','height') {
14462: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
14463: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
14464: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
14465: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
14466: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14467: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
14468: $changes{$itemid} = 1;
14469: }
14470: } else {
14471: $changes{$itemid} = 1;
14472: }
1.296 raeburn 14473: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14474: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
14475: $changes{$itemid} = 1;
14476: }
14477: }
14478: }
14479: foreach my $item ('linktext','explanation') {
14480: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
14481: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
14482: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
14483: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14484: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14485: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
14486: $changes{$itemid} = 1;
14487: }
14488: } else {
14489: $changes{$itemid} = 1;
14490: }
14491: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14492: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
14493: $changes{$itemid} = 1;
14494: }
1.267 raeburn 14495: }
14496: }
14497: if ($env{'form.ltitools_target_'.$i} eq 'window') {
14498: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 14499: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
14500: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 14501: } else {
14502: $confhash{$itemid}{'display'}{'target'} = 'iframe';
14503: }
14504: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14505: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
14506: $changes{$itemid} = 1;
14507: }
14508: } else {
14509: $changes{$itemid} = 1;
14510: }
14511: foreach my $extra ('passback','roster') {
14512: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
14513: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 14514: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 14515: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 14516: $lifetime =~ s/^\s+|\s+$//g;
14517: if ($lifetime =~ /^\d+\.?\d*$/) {
14518: $confhash{$itemid}{$extra.'valid'} = $lifetime;
14519: }
14520: }
1.267 raeburn 14521: }
14522: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
14523: $changes{$itemid} = 1;
14524: }
1.319 raeburn 14525: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
14526: $changes{$itemid} = 1;
14527: }
1.267 raeburn 14528: }
1.273 raeburn 14529: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 14530: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 14531: if (grep(/^\Q$item\E$/,@courseconfig)) {
14532: $confhash{$itemid}{'crsconf'}{$item} = 1;
14533: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
14534: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
14535: $changes{$itemid} = 1;
14536: }
14537: } else {
14538: $changes{$itemid} = 1;
14539: }
14540: }
14541: }
1.267 raeburn 14542: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
14543: foreach my $field (@fields) {
14544: if ($possfield{$field}) {
14545: if ($field eq 'roles') {
14546: foreach my $role (@courseroles) {
14547: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
14548: if (($choice ne '') && ($posslti{$choice})) {
14549: $confhash{$itemid}{'roles'}{$role} = $choice;
14550: if ($role eq 'cc') {
14551: $confhash{$itemid}{'roles'}{'co'} = $choice;
14552: }
14553: }
14554: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
14555: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
14556: $changes{$itemid} = 1;
14557: }
14558: } elsif ($confhash{$itemid}{'roles'}{$role}) {
14559: $changes{$itemid} = 1;
14560: }
14561: }
14562: } else {
14563: $confhash{$itemid}{'fields'}{$field} = 1;
14564: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
14565: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
14566: $changes{$itemid} = 1;
14567: }
14568: } else {
14569: $changes{$itemid} = 1;
14570: }
14571: }
14572: }
14573: }
1.324 raeburn 14574: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14575: if ($confhash{$itemid}{'fields'}{'user'}) {
14576: if ($env{'form.ltitools_userincdom_'.$i}) {
14577: $confhash{$itemid}{'incdom'} = 1;
14578: }
14579: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
14580: $changes{$itemid} = 1;
14581: }
14582: }
14583: }
1.267 raeburn 14584: $allpos[$newpos] = $itemid;
14585: }
14586: if ($imgdeletions{$itemid}) {
14587: $changes{$itemid} = 1;
14588: #FIXME need to obsolete item in RES space
14589: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
14590: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
14591: $itemid,$configuserok,$switchserver,
14592: $author_ok);
14593: if ($imgurl) {
14594: $confhash{$itemid}{'image'} = $imgurl;
14595: $changes{$itemid} = 1;
14596: }
14597: if ($error) {
14598: &Apache::lonnet::logthis($error);
14599: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14600: }
14601: } elsif ($domconfig{$action}{$itemid}{'image'}) {
14602: $confhash{$itemid}{'image'} =
14603: $domconfig{$action}{$itemid}{'image'};
14604: }
14605: if ($customadds{$i}) {
14606: my $name = $env{'form.ltitools_custom_name_'.$i};
14607: $name =~ s/(`)/'/g;
14608: $name =~ s/^\s+//;
14609: $name =~ s/\s+$//;
14610: my $value = $env{'form.ltitools_custom_value_'.$i};
14611: $value =~ s/(`)/'/g;
14612: $value =~ s/^\s+//;
14613: $value =~ s/\s+$//;
14614: if ($name ne '') {
14615: $confhash{$itemid}{'custom'}{$name} = $value;
14616: $changes{$itemid} = 1;
14617: }
14618: }
14619: my %customdels;
14620: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
14621: if (@customdeletions) {
14622: $changes{$itemid} = 1;
14623: }
14624: map { $customdels{$_} = 1; } @customdeletions;
14625: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
14626: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
14627: unless ($customdels{$key}) {
14628: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
14629: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
14630: }
14631: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
14632: $changes{$itemid} = 1;
14633: }
14634: }
14635: }
14636: }
14637: unless ($changes{$itemid}) {
14638: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
14639: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
14640: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14641: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
14642: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
14643: $changes{$itemid} = 1;
14644: last;
14645: }
14646: }
14647: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
14648: $changes{$itemid} = 1;
14649: }
14650: }
14651: last if ($changes{$itemid});
14652: }
14653: }
14654: }
14655: }
14656: }
14657: if (@allpos > 0) {
14658: my $idx = 0;
14659: foreach my $itemid (@allpos) {
14660: if ($itemid ne '') {
14661: $confhash{$itemid}{'order'} = $idx;
14662: if (ref($domconfig{$action}) eq 'HASH') {
14663: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14664: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14665: $changes{$itemid} = 1;
14666: }
14667: }
14668: }
14669: $idx ++;
14670: }
14671: }
14672: }
14673: my %ltitoolshash = (
14674: $action => { %confhash }
14675: );
14676: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
14677: $dom);
14678: if ($putresult eq 'ok') {
1.297 raeburn 14679: my %ltienchash = (
14680: $action => { %encconfig }
14681: );
1.384 raeburn 14682: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 14683: if (keys(%changes) > 0) {
14684: my $cachetime = 24*60*60;
1.297 raeburn 14685: my %ltiall = %confhash;
14686: foreach my $id (keys(%ltiall)) {
14687: if (ref($encconfig{$id}) eq 'HASH') {
14688: foreach my $item ('key','secret') {
14689: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14690: }
14691: }
14692: }
14693: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 14694: if (ref($lastactref) eq 'HASH') {
14695: $lastactref->{'ltitools'} = 1;
14696: }
14697: $resulttext = &mt('Changes made:').'<ul>';
14698: my %bynum;
14699: foreach my $itemid (sort(keys(%changes))) {
14700: my $position = $confhash{$itemid}{'order'};
14701: $bynum{$position} = $itemid;
14702: }
14703: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14704: my $itemid = $bynum{$pos};
14705: if (ref($confhash{$itemid}) ne 'HASH') {
14706: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14707: } else {
14708: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
14709: if ($confhash{$itemid}{'image'}) {
14710: $resulttext .= ' '.
14711: '<img src="'.$confhash{$itemid}{'image'}.'"'.
14712: ' alt="'.&mt('Tool Provider icon').'" />';
14713: }
14714: $resulttext .= '</li><ul>';
14715: my $position = $pos + 1;
14716: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 14717: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 14718: if ($confhash{$itemid}{$item} ne '') {
14719: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14720: }
14721: }
1.297 raeburn 14722: if ($encconfig{$itemid}{'key'} ne '') {
14723: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14724: }
14725: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 14726: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 14727: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 14728: $resulttext .= ('*'x$num).'</li>';
14729: }
1.273 raeburn 14730: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 14731: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 14732: my $numconfig = 0;
14733: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
14734: foreach my $item (@possconfig) {
14735: if ($confhash{$itemid}{'crsconf'}{$item}) {
14736: $numconfig ++;
1.296 raeburn 14737: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 14738: }
14739: }
14740: }
14741: if (!$numconfig) {
1.372 raeburn 14742: $resulttext .= ' '.&mt('None');
1.273 raeburn 14743: }
14744: $resulttext .= '</li>';
1.267 raeburn 14745: foreach my $item ('passback','roster') {
14746: $resulttext .= '<li>'.$lt{$item}.' ';
14747: if ($confhash{$itemid}{$item}) {
14748: $resulttext .= &mt('Yes');
1.319 raeburn 14749: if ($confhash{$itemid}{$item.'valid'}) {
14750: if ($item eq 'passback') {
14751: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14752: $confhash{$itemid}{$item.'valid'});
14753: } else {
14754: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14755: $confhash{$itemid}{$item.'valid'});
14756: }
14757: }
1.267 raeburn 14758: } else {
14759: $resulttext .= &mt('No');
14760: }
14761: $resulttext .= '</li>';
14762: }
14763: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14764: my $displaylist;
14765: if ($confhash{$itemid}{'display'}{'target'}) {
14766: $displaylist = &mt('Display target').': '.
14767: $confhash{$itemid}{'display'}{'target'}.',';
14768: }
14769: foreach my $size ('width','height') {
14770: if ($confhash{$itemid}{'display'}{$size}) {
14771: $displaylist .= (' 'x2).$lt{$size}.': '.
14772: $confhash{$itemid}{'display'}{$size}.',';
14773: }
14774: }
14775: if ($displaylist) {
14776: $displaylist =~ s/,$//;
14777: $resulttext .= '<li>'.$displaylist.'</li>';
14778: }
1.296 raeburn 14779: foreach my $item ('linktext','explanation') {
14780: if ($confhash{$itemid}{'display'}{$item}) {
14781: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14782: }
14783: }
14784: }
1.267 raeburn 14785: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14786: my $fieldlist;
14787: foreach my $field (@allfields) {
14788: if ($confhash{$itemid}{'fields'}{$field}) {
14789: $fieldlist .= (' 'x2).$lt{$field}.',';
14790: }
14791: }
14792: if ($fieldlist) {
14793: $fieldlist =~ s/,$//;
1.324 raeburn 14794: if ($confhash{$itemid}{'fields'}{'user'}) {
14795: if ($confhash{$itemid}{'incdom'}) {
14796: $fieldlist .= ' ('.&mt('username:domain').')';
14797: } else {
14798: $fieldlist .= ' ('.&mt('username').')';
14799: }
14800: }
1.267 raeburn 14801: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14802: }
14803: }
14804: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14805: my $rolemaps;
14806: foreach my $role (@courseroles) {
14807: if ($confhash{$itemid}{'roles'}{$role}) {
14808: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14809: $confhash{$itemid}{'roles'}{$role}.',';
14810: }
14811: }
14812: if ($rolemaps) {
14813: $rolemaps =~ s/,$//;
14814: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14815: }
14816: }
14817: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14818: my $customlist;
14819: if (keys(%{$confhash{$itemid}{'custom'}})) {
14820: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14821: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14822: }
14823: }
14824: if ($customlist) {
1.317 raeburn 14825: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14826: }
14827: }
14828: $resulttext .= '</ul></li>';
14829: }
14830: }
14831: $resulttext .= '</ul>';
14832: } else {
14833: $resulttext = &mt('No changes made.');
14834: }
14835: } else {
14836: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14837: }
14838: if ($errors) {
14839: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14840: $errors.'</ul>';
14841: }
14842: return $resulttext;
14843: }
14844:
14845: sub process_ltitools_image {
14846: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14847: my $filename = $env{'form.'.$caller.'.filename'};
14848: my ($error,$url);
14849: my ($width,$height) = (21,21);
14850: if ($configuserok eq 'ok') {
14851: if ($switchserver) {
14852: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14853: $switchserver);
14854: } elsif ($author_ok eq 'ok') {
14855: my ($result,$imageurl,$madethumb) =
14856: &publishlogo($r,'upload',$caller,$dom,$confname,
14857: "ltitools/$itemid/icon",$width,$height);
14858: if ($result eq 'ok') {
14859: if ($madethumb) {
14860: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14861: my $imagethumb = "$path/tn-".$imagefile;
14862: $url = $imagethumb;
14863: } else {
14864: $url = $imageurl;
14865: }
14866: } else {
14867: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14868: }
14869: } else {
14870: $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);
14871: }
14872: } else {
14873: $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);
14874: }
14875: return ($url,$error);
14876: }
14877:
14878: sub get_ltitools_id {
14879: my ($cdom,$title) = @_;
14880: # get lock on ltitools db
14881: my $lockhash = {
14882: lock => $env{'user.name'}.
14883: ':'.$env{'user.domain'},
14884: };
14885: my $tries = 0;
14886: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14887: my ($id,$error);
14888:
14889: while (($gotlock ne 'ok') && ($tries<10)) {
14890: $tries ++;
14891: sleep (0.1);
14892: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14893: }
14894: if ($gotlock eq 'ok') {
14895: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14896: if ($currids{'lock'}) {
14897: delete($currids{'lock'});
14898: if (keys(%currids)) {
14899: my @curr = sort { $a <=> $b } keys(%currids);
14900: if ($curr[-1] =~ /^\d+$/) {
14901: $id = 1 + $curr[-1];
14902: }
14903: } else {
14904: $id = 1;
14905: }
14906: if ($id) {
14907: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14908: $error = 'nostore';
14909: }
14910: } else {
14911: $error = 'nonumber';
14912: }
14913: }
14914: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14915: } else {
14916: $error = 'nolock';
14917: }
14918: return ($id,$error);
14919: }
14920:
1.372 raeburn 14921: sub modify_proctoring {
14922: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14923: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14924: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14925: my $confname = $dom.'-domainconfig';
14926: my $servadm = $r->dir_config('lonAdmEMail');
14927: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14928: my %providernames = &proctoring_providernames();
14929: my $maxnum = scalar(keys(%providernames));
14930:
14931: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14932: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14933: if (ref($requref) eq 'HASH') {
14934: %requserfields = %{$requref};
14935: }
14936: if (ref($opturef) eq 'HASH') {
14937: %optuserfields = %{$opturef};
14938: }
14939: if (ref($defref) eq 'HASH') {
14940: %defaults = %{$defref};
14941: }
14942: if (ref($extref) eq 'HASH') {
14943: %extended = %{$extref};
14944: }
14945: if (ref($crsref) eq 'HASH') {
14946: %crsconf = %{$crsref};
14947: }
14948: if (ref($rolesref) eq 'ARRAY') {
14949: @courseroles = @{$rolesref};
14950: }
14951: if (ref($ltiref) eq 'ARRAY') {
14952: @ltiroles = @{$ltiref};
14953: }
14954:
14955: if (ref($domconfig{$action}) eq 'HASH') {
14956: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14957: if (@todeleteimages) {
14958: map { $imgdeletions{$_} = 1; } @todeleteimages;
14959: }
14960: }
14961: my %customadds;
14962: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14963: if (@newcustom) {
14964: map { $customadds{$_} = 1; } @newcustom;
14965: }
14966: foreach my $provider (sort(keys(%providernames))) {
14967: $confhash{$provider} = {};
14968: my $pos = $env{'form.proctoring_pos_'.$provider};
14969: $pos =~ s/\D+//g;
14970: $allpos[$pos] = $provider;
14971: my (%current,%currentenc);
14972: my $showroles = 0;
14973: if (ref($domconfig{$action}) eq 'HASH') {
14974: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14975: %current = %{$domconfig{$action}{$provider}};
14976: foreach my $item ('key','secret') {
14977: $currentenc{$item} = $current{$item};
14978: delete($current{$item});
14979: }
14980: }
14981: }
14982: if ($env{'form.proctoring_available_'.$provider}) {
14983: $confhash{$provider}{'available'} = 1;
14984: unless ($current{'available'}) {
14985: $changes{$provider} = 1;
14986: }
14987: } else {
14988: %{$confhash{$provider}} = %current;
14989: %{$encconfhash{$provider}} = %currentenc;
14990: $confhash{$provider}{'available'} = 0;
14991: if ($current{'available'}) {
14992: $changes{$provider} = 1;
14993: }
14994: }
14995: if ($confhash{$provider}{'available'}) {
14996: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14997: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14998: if ($field eq 'lifetime') {
14999: if ($possval =~ /^\d+$/) {
15000: $confhash{$provider}{$field} = $possval;
15001: }
15002: } elsif ($field eq 'version') {
15003: if ($possval =~ /^\d+\.\d+$/) {
15004: $confhash{$provider}{$field} = $possval;
15005: }
15006: } elsif ($field eq 'sigmethod') {
15007: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15008: $confhash{$provider}{$field} = $possval;
15009: }
15010: } elsif ($field eq 'url') {
15011: $confhash{$provider}{$field} = $possval;
15012: } elsif (($field eq 'key') || ($field eq 'secret')) {
15013: $encconfhash{$provider}{$field} = $possval;
15014: unless ($currentenc{$field} eq $possval) {
15015: $changes{$provider} = 1;
15016: }
15017: }
15018: unless (($field eq 'key') || ($field eq 'secret')) {
15019: unless ($current{$field} eq $confhash{$provider}{$field}) {
15020: $changes{$provider} = 1;
15021: }
15022: }
15023: }
15024: if ($imgdeletions{$provider}) {
15025: $changes{$provider} = 1;
15026: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15027: my ($imageurl,$error) =
15028: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15029: $configuserok,$switchserver,$author_ok);
15030: if ($imageurl) {
15031: $confhash{$provider}{'image'} = $imageurl;
15032: $changes{$provider} = 1;
15033: }
15034: if ($error) {
15035: &Apache::lonnet::logthis($error);
15036: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15037: }
15038: } elsif (exists($current{'image'})) {
15039: $confhash{$provider}{'image'} = $current{'image'};
15040: }
15041: if (ref($requserfields{$provider}) eq 'ARRAY') {
15042: if (@{$requserfields{$provider}} > 0) {
15043: if (grep(/^user$/,@{$requserfields{$provider}})) {
15044: if ($env{'form.proctoring_userincdom_'.$provider}) {
15045: $confhash{$provider}{'incdom'} = 1;
15046: }
15047: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15048: $changes{$provider} = 1;
15049: }
15050: }
15051: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15052: $showroles = 1;
15053: }
15054: }
15055: }
15056: $confhash{$provider}{'fields'} = [];
15057: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15058: if (@{$optuserfields{$provider}} > 0) {
15059: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15060: foreach my $field (@{$optuserfields{$provider}}) {
15061: if (grep(/^\Q$field\E$/,@optfields)) {
15062: push(@{$confhash{$provider}{'fields'}},$field);
15063: }
15064: }
15065: }
15066: if (ref($current{'fields'}) eq 'ARRAY') {
15067: unless ($changes{$provider}) {
15068: my @new = sort(@{$confhash{$provider}{'fields'}});
15069: my @old = sort(@{$current{'fields'}});
15070: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15071: if (@diffs) {
15072: $changes{$provider} = 1;
15073: }
15074: }
15075: } elsif (@{$confhash{$provider}{'fields'}}) {
15076: $changes{$provider} = 1;
15077: }
15078: }
15079: if (ref($defaults{$provider}) eq 'ARRAY') {
15080: if (@{$defaults{$provider}} > 0) {
15081: my %options;
15082: if (ref($extended{$provider}) eq 'HASH') {
15083: %options = %{$extended{$provider}};
15084: }
15085: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15086: foreach my $field (@{$defaults{$provider}}) {
15087: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15088: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15089: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15090: push(@{$confhash{$provider}{'defaults'}},$poss);
15091: }
15092: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15093: foreach my $inner (keys(%{$options{$field}})) {
15094: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15095: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15096: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15097: $confhash{$provider}{'defaults'}{$inner} = $poss;
15098: }
15099: } else {
15100: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15101: }
15102: }
15103: } else {
15104: if (grep(/^\Q$field\E$/,@checked)) {
15105: push(@{$confhash{$provider}{'defaults'}},$field);
15106: }
15107: }
15108: }
15109: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15110: if (ref($current{'defaults'}) eq 'ARRAY') {
15111: unless ($changes{$provider}) {
15112: my @new = sort(@{$confhash{$provider}{'defaults'}});
15113: my @old = sort(@{$current{'defaults'}});
15114: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15115: if (@diffs) {
15116: $changes{$provider} = 1;
15117: }
15118: }
15119: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15120: if (@{$current{'defaults'}}) {
15121: $changes{$provider} = 1;
15122: }
15123: }
15124: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15125: if (ref($current{'defaults'}) eq 'HASH') {
15126: unless ($changes{$provider}) {
15127: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15128: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15129: $changes{$provider} = 1;
15130: last;
15131: }
15132: }
15133: }
15134: unless ($changes{$provider}) {
15135: foreach my $key (keys(%{$current{'defaults'}})) {
15136: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15137: $changes{$provider} = 1;
15138: last;
15139: }
15140: }
15141: }
15142: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15143: $changes{$provider} = 1;
15144: }
15145: }
15146: }
15147: }
15148: if (ref($crsconf{$provider}) eq 'ARRAY') {
15149: if (@{$crsconf{$provider}} > 0) {
15150: $confhash{$provider}{'crsconf'} = [];
15151: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15152: foreach my $crsfield (@{$crsconf{$provider}}) {
15153: if (grep(/^\Q$crsfield\E$/,@checked)) {
15154: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15155: }
15156: }
15157: if (ref($current{'crsconf'}) eq 'ARRAY') {
15158: unless ($changes{$provider}) {
15159: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15160: my @old = sort(@{$current{'crsconf'}});
15161: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15162: if (@diffs) {
15163: $changes{$provider} = 1;
15164: }
15165: }
15166: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15167: $changes{$provider} = 1;
15168: }
15169: }
15170: }
15171: if ($showroles) {
15172: $confhash{$provider}{'roles'} = {};
15173: foreach my $role (@courseroles) {
15174: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15175: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15176: $confhash{$provider}{'roles'}{$role} = $poss;
15177: }
15178: }
15179: unless ($changes{$provider}) {
15180: if (ref($current{'roles'}) eq 'HASH') {
15181: foreach my $role (keys(%{$current{'roles'}})) {
15182: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15183: $changes{$provider} = 1;
15184: last
15185: }
15186: }
15187: unless ($changes{$provider}) {
15188: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15189: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15190: $changes{$provider} = 1;
15191: last;
15192: }
15193: }
15194: }
15195: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15196: $changes{$provider} = 1;
15197: }
15198: }
15199: }
15200: if (ref($current{'custom'}) eq 'HASH') {
15201: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15202: foreach my $key (keys(%{$current{'custom'}})) {
15203: if (grep(/^\Q$key\E$/,@customdels)) {
15204: $changes{$provider} = 1;
15205: } else {
15206: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15207: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15208: $changes{$provider} = 1;
15209: }
15210: }
15211: }
15212: }
15213: if ($customadds{$provider}) {
15214: my $name = $env{'form.proctoring_custom_name_'.$provider};
15215: $name =~ s/(`)/'/g;
15216: $name =~ s/^\s+//;
15217: $name =~ s/\s+$//;
15218: my $value = $env{'form.proctoring_custom_value_'.$provider};
15219: $value =~ s/(`)/'/g;
15220: $value =~ s/^\s+//;
15221: $value =~ s/\s+$//;
15222: if ($name ne '') {
15223: $confhash{$provider}{'custom'}{$name} = $value;
15224: $changes{$provider} = 1;
15225: }
15226: }
15227: }
15228: }
15229: if (@allpos > 0) {
15230: my $idx = 0;
15231: foreach my $provider (@allpos) {
15232: if ($provider ne '') {
15233: $confhash{$provider}{'order'} = $idx;
15234: unless ($changes{$provider}) {
15235: if (ref($domconfig{$action}) eq 'HASH') {
15236: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15237: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15238: $changes{$provider} = 1;
15239: }
15240: }
15241: }
15242: }
15243: $idx ++;
15244: }
15245: }
15246: }
15247: my %proc_hash = (
15248: $action => { %confhash }
15249: );
15250: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15251: $dom);
15252: if ($putresult eq 'ok') {
15253: my %proc_enchash = (
15254: $action => { %encconfhash }
15255: );
1.384 raeburn 15256: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15257: if (keys(%changes) > 0) {
15258: my $cachetime = 24*60*60;
15259: my %procall = %confhash;
15260: foreach my $provider (keys(%procall)) {
15261: if (ref($encconfhash{$provider}) eq 'HASH') {
15262: foreach my $key ('key','secret') {
15263: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15264: }
15265: }
15266: }
15267: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15268: if (ref($lastactref) eq 'HASH') {
15269: $lastactref->{'proctoring'} = 1;
15270: }
15271: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15272: my %bynum;
15273: foreach my $provider (sort(keys(%changes))) {
15274: my $position = $confhash{$provider}{'order'};
15275: $bynum{$position} = $provider;
15276: }
15277: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15278: my $provider = $bynum{$pos};
15279: my %lt = &proctoring_titles($provider);
15280: my %fieldtitles = &proctoring_fieldtitles($provider);
15281: if (!$confhash{$provider}{'available'}) {
15282: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15283: } else {
15284: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15285: if ($confhash{$provider}{'image'}) {
15286: $resulttext .= ' '.
15287: '<img src="'.$confhash{$provider}{'image'}.'"'.
15288: ' alt="'.&mt('Proctoring icon').'" />';
15289: }
15290: $resulttext .= '<ul>';
15291: my $position = $pos + 1;
15292: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15293: foreach my $key ('version','sigmethod','url','lifetime') {
15294: if ($confhash{$provider}{$key} ne '') {
15295: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15296: }
15297: }
15298: if ($encconfhash{$provider}{'key'} ne '') {
15299: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15300: }
15301: if ($encconfhash{$provider}{'secret'} ne '') {
15302: $resulttext .= '<li>'.$lt{'secret'}.': ';
15303: my $num = length($encconfhash{$provider}{'secret'});
15304: $resulttext .= ('*'x$num).'</li>';
15305: }
15306: my (@fields,$showroles);
15307: if (ref($requserfields{$provider}) eq 'ARRAY') {
15308: push(@fields,@{$requserfields{$provider}});
15309: }
15310: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15311: push(@fields,@{$confhash{$provider}{'fields'}});
15312: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15313: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15314: }
15315: if (@fields) {
15316: if (grep(/^roles$/,@fields)) {
15317: $showroles = 1;
15318: }
15319: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15320: join('", "', map { $lt{$_}; } @fields).'"</li>';
15321: }
15322: if (ref($requserfields{$provider}) eq 'ARRAY') {
15323: if (grep(/^user$/,@{$requserfields{$provider}})) {
15324: if ($confhash{$provider}{'incdom'}) {
15325: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15326: } else {
15327: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15328: }
15329: }
15330: }
15331: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15332: if (@{$confhash{$provider}{'defaults'}} > 0) {
15333: $resulttext .= '<li>'.$lt{'defa'};
15334: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15335: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15336: }
15337: $resulttext =~ s/,$//;
15338: $resulttext .= '</li>';
15339: }
15340: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15341: if (keys(%{$confhash{$provider}{'defaults'}})) {
15342: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15343: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15344: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15345: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15346: }
15347: }
15348: $resulttext .= '</ul></li>';
15349: }
15350: }
15351: if (ref($crsconf{$provider}) eq 'ARRAY') {
15352: if (@{$crsconf{$provider}} > 0) {
15353: $resulttext .= '<li>'.&mt('Configurable in course:');
15354: my $numconfig = 0;
15355: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15356: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15357: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15358: $numconfig ++;
15359: if ($provider eq 'examity') {
15360: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15361: } else {
15362: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15363: }
15364: }
15365: $resulttext =~ s/,$//;
15366: }
15367: }
15368: if (!$numconfig) {
15369: $resulttext .= ' '.&mt('None');
15370: }
15371: $resulttext .= '</li>';
15372: }
15373: }
15374: if ($showroles) {
15375: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15376: my $rolemaps;
15377: foreach my $role (@courseroles) {
15378: if ($confhash{$provider}{'roles'}{$role}) {
15379: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15380: $confhash{$provider}{'roles'}{$role}.',';
15381: }
15382: }
15383: if ($rolemaps) {
15384: $rolemaps =~ s/,$//;
15385: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15386: }
15387: }
15388: }
15389: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15390: my $customlist;
15391: if (keys(%{$confhash{$provider}{'custom'}})) {
15392: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15393: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15394: }
15395: $customlist =~ s/,$//;
15396: }
15397: if ($customlist) {
15398: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15399: }
15400: }
15401: $resulttext .= '</ul></li>';
15402: }
15403: }
15404: $resulttext .= '</ul>';
15405: } else {
15406: $resulttext = &mt('No changes made.');
15407: }
15408: } else {
15409: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15410: }
15411: if ($errors) {
15412: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15413: $errors.'</ul>';
15414: }
15415: return $resulttext;
15416: }
15417:
15418: sub process_proctoring_image {
15419: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15420: my $filename = $env{'form.'.$caller.'.filename'};
15421: my ($error,$url);
15422: my ($width,$height) = (21,21);
15423: if ($configuserok eq 'ok') {
15424: if ($switchserver) {
15425: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15426: $switchserver);
15427: } elsif ($author_ok eq 'ok') {
15428: my ($result,$imageurl,$madethumb) =
15429: &publishlogo($r,'upload',$caller,$dom,$confname,
15430: "proctoring/$provider/icon",$width,$height);
15431: if ($result eq 'ok') {
15432: if ($madethumb) {
15433: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15434: my $imagethumb = "$path/tn-".$imagefile;
15435: $url = $imagethumb;
15436: } else {
15437: $url = $imageurl;
15438: }
15439: } else {
15440: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15441: }
15442: } else {
15443: $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);
15444: }
15445: } else {
15446: $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);
15447: }
15448: return ($url,$error);
15449: }
15450:
1.320 raeburn 15451: sub modify_lti {
15452: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15453: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15454: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
15455: my (%posslti,%posslticrs,%posscrstype);
15456: my @courseroles = ('cc','in','ta','ep','st');
15457: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15458: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15459: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15460: my %coursetypetitles = &Apache::lonlocal::texthash (
15461: official => 'Official',
15462: unofficial => 'Unofficial',
15463: community => 'Community',
15464: textbook => 'Textbook',
15465: placement => 'Placement Test',
1.392 raeburn 15466: lti => 'LTI Provider',
1.320 raeburn 15467: );
1.325 raeburn 15468: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15469: my %lt = <i_names();
15470: map { $posslti{$_} = 1; } @ltiroles;
15471: map { $posslticrs{$_} = 1; } @lticourseroles;
15472: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15473:
1.326 raeburn 15474: my %menutitles = <imenu_titles();
15475:
1.320 raeburn 15476: my (@items,%deletions,%itemids);
15477: if ($env{'form.lti_add'}) {
15478: my $consumer = $env{'form.lti_consumer_add'};
15479: $consumer =~ s/(`)/'/g;
15480: ($newid,my $error) = &get_lti_id($dom,$consumer);
15481: if ($newid) {
15482: $itemids{'add'} = $newid;
15483: push(@items,'add');
15484: $changes{$newid} = 1;
15485: } else {
15486: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15487: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15488: }
15489: }
15490: if (ref($domconfig{$action}) eq 'HASH') {
15491: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15492: if (@todelete) {
15493: map { $deletions{$_} = 1; } @todelete;
15494: }
15495: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15496: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15497: my $itemid = $env{'form.lti_id_'.$i};
15498: $itemid =~ s/\D+//g;
15499: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15500: if ($deletions{$itemid}) {
15501: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15502: } else {
1.390 raeburn 15503: push(@items,$i);
15504: $itemids{$i} = $itemid;
1.320 raeburn 15505: }
15506: }
15507: }
15508: }
15509: foreach my $idx (@items) {
15510: my $itemid = $itemids{$idx};
15511: next unless ($itemid);
1.390 raeburn 15512: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15513: $position =~ s/\D+//g;
15514: if ($position ne '') {
15515: $allpos[$position] = $itemid;
15516: }
1.391 raeburn 15517: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 15518: my $formitem = 'form.lti_'.$item.'_'.$idx;
15519: $env{$formitem} =~ s/(`)/'/g;
15520: if ($item eq 'lifetime') {
15521: $env{$formitem} =~ s/[^\d.]//g;
15522: }
15523: if ($env{$formitem} ne '') {
15524: if (($item eq 'key') || ($item eq 'secret')) {
15525: $encconfig{$itemid}{$item} = $env{$formitem};
15526: } else {
15527: $confhash{$itemid}{$item} = $env{$formitem};
15528: unless (($idx eq 'add') || ($changes{$itemid})) {
15529: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
15530: $changes{$itemid} = 1;
15531: }
15532: }
15533: }
15534: }
15535: }
15536: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15537: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15538: }
1.345 raeburn 15539: if ($confhash{$itemid}{'requser'}) {
15540: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
15541: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
15542: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15543: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15544: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15545: my $mapuser = $env{'form.lti_customuser_'.$idx};
15546: $mapuser =~ s/(`)/'/g;
15547: $mapuser =~ s/^\s+|\s+$//g;
15548: $confhash{$itemid}{'mapuser'} = $mapuser;
15549: }
15550: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15551: my @makeuser;
15552: foreach my $ltirole (sort(@possmakeuser)) {
15553: if ($posslti{$ltirole}) {
15554: push(@makeuser,$ltirole);
15555: }
15556: }
15557: $confhash{$itemid}{'makeuser'} = \@makeuser;
15558: if (@makeuser) {
15559: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15560: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15561: $confhash{$itemid}{'lcauth'} = $lcauth;
15562: if ($lcauth ne 'internal') {
15563: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15564: $lcauthparm =~ s/^(\s+|\s+)$//g;
15565: $lcauthparm =~ s/`//g;
15566: if ($lcauthparm ne '') {
15567: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15568: }
15569: }
15570: } else {
15571: $confhash{$itemid}{'lcauth'} = 'lti';
15572: }
1.320 raeburn 15573: }
1.345 raeburn 15574: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15575: if (@possinstdata) {
15576: foreach my $field (@possinstdata) {
15577: if (exists($fieldtitles{$field})) {
15578: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15579: }
15580: }
15581: }
1.363 raeburn 15582: if ($env{'form.lti_callback_'.$idx}) {
15583: if ($env{'form.lti_callbackparam_'.$idx}) {
15584: my $callback = $env{'form.lti_callbackparam_'.$idx};
15585: $callback =~ s/^\s+|\s+$//g;
15586: $confhash{$itemid}{'callback'} = $callback;
15587: }
15588: }
1.391 raeburn 15589: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15590: if ($env{'form.lti_'.$field.'_'.$idx}) {
15591: $confhash{$itemid}{$field} = 1;
15592: }
1.320 raeburn 15593: }
1.345 raeburn 15594: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15595: $confhash{$itemid}{lcmenu} = [];
15596: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15597: foreach my $field (@possmenu) {
15598: if (exists($menutitles{$field})) {
15599: if ($field eq 'grades') {
15600: next unless ($env{'form.lti_inlinemenu_'.$idx});
15601: }
15602: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15603: }
15604: }
15605: }
1.391 raeburn 15606: if ($confhash{$itemid}{'crsinc'}) {
15607: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15608: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15609: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15610: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15611: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15612: $mapcrs =~ s/(`)/'/g;
15613: $mapcrs =~ s/^\s+|\s+$//g;
15614: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15615: }
15616: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15617: my @crstypes;
15618: foreach my $type (sort(@posstypes)) {
15619: if ($posscrstype{$type}) {
15620: push(@crstypes,$type);
15621: }
15622: }
15623: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15624: if ($env{'form.lti_storecrs_'.$idx}) {
15625: $confhash{$itemid}{'storecrs'} = 1;
15626: }
1.391 raeburn 15627: if ($env{'form.lti_makecrs_'.$idx}) {
15628: $confhash{$itemid}{'makecrs'} = 1;
15629: }
15630: foreach my $ltirole (@lticourseroles) {
15631: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15632: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15633: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15634: }
15635: }
15636: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15637: my @selfenroll;
15638: foreach my $type (sort(@possenroll)) {
15639: if ($posslticrs{$type}) {
15640: push(@selfenroll,$type);
15641: }
15642: }
15643: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15644: if ($env{'form.lti_crssec_'.$idx}) {
15645: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15646: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15647: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15648: my $section = $env{'form.lti_customsection_'.$idx};
15649: $section =~ s/(`)/'/g;
15650: $section =~ s/^\s+|\s+$//g;
15651: if ($section ne '') {
15652: $confhash{$itemid}{'section'} = $section;
15653: }
15654: }
15655: }
15656: foreach my $field ('passback','roster') {
15657: if ($env{'form.lti_'.$field.'_'.$idx}) {
15658: $confhash{$itemid}{$field} = 1;
15659: }
15660: }
15661: if ($env{'form.lti_passback_'.$idx}) {
15662: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15663: $confhash{$itemid}{'passbackformat'} = '1.0';
15664: } else {
15665: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15666: }
15667: }
1.391 raeburn 15668: }
15669: unless (($idx eq 'add') || ($changes{$itemid})) {
15670: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15671: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 15672: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15673: $changes{$itemid} = 1;
15674: }
1.345 raeburn 15675: }
15676: unless ($changes{$itemid}) {
1.391 raeburn 15677: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
15678: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15679: $changes{$itemid} = 1;
15680: }
15681: }
1.345 raeburn 15682: }
1.391 raeburn 15683: foreach my $field ('mapcrstype','selfenroll') {
15684: unless ($changes{$itemid}) {
15685: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15686: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15687: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15688: $confhash{$itemid}{$field});
15689: if (@diffs) {
15690: $changes{$itemid} = 1;
15691: }
15692: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15693: $changes{$itemid} = 1;
15694: }
15695: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15696: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15697: $changes{$itemid} = 1;
15698: }
15699: }
1.391 raeburn 15700: }
15701: }
15702: unless ($changes{$itemid}) {
15703: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
15704: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15705: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
15706: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
15707: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15708: $changes{$itemid} = 1;
15709: last;
15710: }
15711: }
1.391 raeburn 15712: unless ($changes{$itemid}) {
15713: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15714: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
15715: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
15716: $changes{$itemid} = 1;
15717: last;
15718: }
15719: }
15720: }
15721: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
15722: $changes{$itemid} = 1;
1.345 raeburn 15723: }
1.391 raeburn 15724: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15725: unless ($changes{$itemid}) {
15726: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15727: $changes{$itemid} = 1;
15728: }
15729: }
15730: }
15731: }
15732: }
15733: unless ($changes{$itemid}) {
15734: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
15735: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15736: $changes{$itemid} = 1;
1.320 raeburn 15737: }
1.391 raeburn 15738: }
15739: unless ($changes{$itemid}) {
15740: foreach my $field ('makeuser','lcmenu') {
15741: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15742: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15743: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15744: $confhash{$itemid}{$field});
15745: if (@diffs) {
15746: $changes{$itemid} = 1;
15747: }
15748: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15749: $changes{$itemid} = 1;
15750: }
15751: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15752: if (@{$confhash{$itemid}{$field}} > 0) {
15753: $changes{$itemid} = 1;
15754: }
1.345 raeburn 15755: }
1.320 raeburn 15756: }
15757: }
15758: }
15759: }
15760: }
15761: }
15762: if (@allpos > 0) {
15763: my $idx = 0;
15764: foreach my $itemid (@allpos) {
15765: if ($itemid ne '') {
15766: $confhash{$itemid}{'order'} = $idx;
15767: if (ref($domconfig{$action}) eq 'HASH') {
15768: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15769: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15770: $changes{$itemid} = 1;
15771: }
15772: }
15773: }
15774: $idx ++;
15775: }
15776: }
15777: }
15778: my %ltihash = (
15779: $action => { %confhash }
15780: );
15781: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
15782: $dom);
15783: if ($putresult eq 'ok') {
15784: my %ltienchash = (
15785: $action => { %encconfig }
15786: );
1.384 raeburn 15787: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15788: if (keys(%changes) > 0) {
15789: my $cachetime = 24*60*60;
15790: my %ltiall = %confhash;
15791: foreach my $id (keys(%ltiall)) {
15792: if (ref($encconfig{$id}) eq 'HASH') {
15793: foreach my $item ('key','secret') {
15794: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15795: }
15796: }
15797: }
15798: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15799: if (ref($lastactref) eq 'HASH') {
15800: $lastactref->{'lti'} = 1;
15801: }
15802: $resulttext = &mt('Changes made:').'<ul>';
15803: my %bynum;
15804: foreach my $itemid (sort(keys(%changes))) {
15805: my $position = $confhash{$itemid}{'order'};
15806: $bynum{$position} = $itemid;
15807: }
15808: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15809: my $itemid = $bynum{$pos};
15810: if (ref($confhash{$itemid}) ne 'HASH') {
15811: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15812: } else {
1.390 raeburn 15813: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15814: my $position = $pos + 1;
15815: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15816: foreach my $item ('version','lifetime') {
15817: if ($confhash{$itemid}{$item} ne '') {
15818: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15819: }
15820: }
15821: if ($encconfig{$itemid}{'key'} ne '') {
15822: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15823: }
15824: if ($encconfig{$itemid}{'secret'} ne '') {
15825: $resulttext .= '<li>'.$lt{'secret'}.': ';
15826: my $num = length($encconfig{$itemid}{'secret'});
15827: $resulttext .= ('*'x$num).'</li>';
15828: }
1.345 raeburn 15829: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15830: if ($confhash{$itemid}{'callback'}) {
15831: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15832: } else {
1.392 raeburn 15833: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15834: }
1.345 raeburn 15835: if ($confhash{$itemid}{'mapuser'}) {
15836: my $shownmapuser;
15837: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15838: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15839: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15840: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15841: } else {
15842: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15843: }
1.345 raeburn 15844: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15845: }
1.345 raeburn 15846: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15847: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15848: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15849: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15850: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15851: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15852: } else {
15853: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15854: $confhash{$itemid}{'lcauth'});
15855: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15856: $resulttext .= '; '.&mt('a randomly generated password will be created');
15857: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15858: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15859: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15860: }
15861: } else {
15862: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15863: }
15864: }
15865: $resulttext .= '</li>';
15866: } else {
15867: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15868: }
1.320 raeburn 15869: }
1.345 raeburn 15870: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15871: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15872: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15873: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15874: } else {
1.345 raeburn 15875: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15876: }
1.320 raeburn 15877: }
1.391 raeburn 15878: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15879: $resulttext .= '<li>'.$lt{$item}.': ';
15880: if ($confhash{$itemid}{$item}) {
15881: $resulttext .= &mt('Yes');
15882: } else {
15883: $resulttext .= &mt('No');
1.337 raeburn 15884: }
1.345 raeburn 15885: $resulttext .= '</li>';
1.320 raeburn 15886: }
1.345 raeburn 15887: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15888: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15889: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15890: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15891: } else {
15892: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15893: }
15894: }
15895: if ($confhash{$itemid}{'crsinc'}) {
15896: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15897: my $rolemaps;
15898: foreach my $role (@ltiroles) {
15899: if ($confhash{$itemid}{'maproles'}{$role}) {
15900: $rolemaps .= (' 'x2).$role.'='.
15901: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15902: 'Course').',';
15903: }
15904: }
15905: if ($rolemaps) {
15906: $rolemaps =~ s/,$//;
15907: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15908: }
15909: }
15910: if ($confhash{$itemid}{'mapcrs'}) {
15911: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15912: }
15913: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15914: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15915: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15916: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15917: '</li>';
15918: } else {
15919: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15920: }
15921: }
1.392 raeburn 15922: if ($confhash{$itemid}{'storecrs'}) {
15923: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
15924: }
1.391 raeburn 15925: if ($confhash{$itemid}{'makecrs'}) {
15926: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15927: } else {
15928: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15929: }
15930: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15931: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15932: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15933: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15934: '</li>';
15935: } else {
15936: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15937: }
15938: }
15939: if ($confhash{$itemid}{'section'}) {
15940: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15941: $resulttext .= '<li>'.&mt('User section from standard field:').
15942: ' (course_section_sourcedid)'.'</li>';
15943: } else {
15944: $resulttext .= '<li>'.&mt('User section from:').' '.
15945: $confhash{$itemid}{'section'}.'</li>';
15946: }
1.345 raeburn 15947: } else {
1.391 raeburn 15948: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15949: }
15950: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15951: $resulttext .= '<li>'.$lt{$item}.': ';
15952: if ($confhash{$itemid}{$item}) {
15953: $resulttext .= &mt('Yes');
15954: if ($item eq 'passback') {
15955: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15956: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15957: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15958: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15959: }
15960: }
15961: } else {
15962: $resulttext .= &mt('No');
15963: }
15964: $resulttext .= '</li>';
15965: }
15966: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15967: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15968: $resulttext .= '<li>'.&mt('Menu items:').' '.
15969: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15970: } else {
15971: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15972: }
1.345 raeburn 15973: }
1.326 raeburn 15974: }
15975: }
1.320 raeburn 15976: $resulttext .= '</ul></li>';
15977: }
15978: }
15979: $resulttext .= '</ul>';
15980: } else {
15981: $resulttext = &mt('No changes made.');
15982: }
15983: } else {
15984: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15985: }
15986: if ($errors) {
15987: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15988: $errors.'</ul>';
15989: }
15990: return $resulttext;
15991: }
15992:
15993: sub get_lti_id {
15994: my ($domain,$consumer) = @_;
15995: # get lock on lti db
15996: my $lockhash = {
15997: lock => $env{'user.name'}.
15998: ':'.$env{'user.domain'},
15999: };
16000: my $tries = 0;
16001: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16002: my ($id,$error);
16003:
16004: while (($gotlock ne 'ok') && ($tries<10)) {
16005: $tries ++;
16006: sleep (0.1);
16007: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
16008: }
16009: if ($gotlock eq 'ok') {
16010: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
16011: if ($currids{'lock'}) {
16012: delete($currids{'lock'});
16013: if (keys(%currids)) {
16014: my @curr = sort { $a <=> $b } keys(%currids);
16015: if ($curr[-1] =~ /^\d+$/) {
16016: $id = 1 + $curr[-1];
16017: }
16018: } else {
16019: $id = 1;
16020: }
16021: if ($id) {
16022: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
16023: $error = 'nostore';
16024: }
16025: } else {
16026: $error = 'nonumber';
16027: }
16028: }
16029: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
16030: } else {
16031: $error = 'nolock';
16032: }
16033: return ($id,$error);
16034: }
16035:
1.3 raeburn 16036: sub modify_autoenroll {
1.205 raeburn 16037: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16038: my ($resulttext,%changes);
16039: my %currautoenroll;
16040: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16041: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16042: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16043: }
16044: }
16045: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16046: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16047: sender => 'Sender for notification messages',
1.274 raeburn 16048: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16049: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16050: my @offon = ('off','on');
1.17 raeburn 16051: my $sender_uname = $env{'form.sender_uname'};
16052: my $sender_domain = $env{'form.sender_domain'};
16053: if ($sender_domain eq '') {
16054: $sender_uname = '';
16055: } elsif ($sender_uname eq '') {
16056: $sender_domain = '';
16057: }
1.129 raeburn 16058: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16059: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16060: $autofailsafe =~ s{^\s+|\s+$}{}g;
16061: if ($autofailsafe =~ /\D/) {
16062: undef($autofailsafe);
16063: }
1.274 raeburn 16064: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16065: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16066: $failsafe = 'off';
1.400 raeburn 16067: undef($autofailsafe);
1.274 raeburn 16068: }
1.1 raeburn 16069: my %autoenrollhash = (
1.129 raeburn 16070: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16071: 'sender_uname' => $sender_uname,
16072: 'sender_domain' => $sender_domain,
16073: 'co-owners' => $coowners,
1.399 raeburn 16074: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16075: 'failsafe' => $failsafe,
1.1 raeburn 16076: }
16077: );
1.4 raeburn 16078: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16079: $dom);
1.1 raeburn 16080: if ($putresult eq 'ok') {
16081: if (exists($currautoenroll{'run'})) {
16082: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16083: $changes{'run'} = 1;
16084: }
16085: } elsif ($autorun) {
16086: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16087: $changes{'run'} = 1;
1.1 raeburn 16088: }
16089: }
1.17 raeburn 16090: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16091: $changes{'sender'} = 1;
16092: }
1.17 raeburn 16093: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16094: $changes{'sender'} = 1;
16095: }
1.129 raeburn 16096: if ($currautoenroll{'co-owners'} ne '') {
16097: if ($currautoenroll{'co-owners'} ne $coowners) {
16098: $changes{'coowners'} = 1;
16099: }
16100: } elsif ($coowners) {
16101: $changes{'coowners'} = 1;
1.274 raeburn 16102: }
1.399 raeburn 16103: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16104: $changes{'autofailsafe'} = 1;
16105: }
1.399 raeburn 16106: if ($currautoenroll{'failsafe'} ne $failsafe) {
16107: $changes{'failsafe'} = 1;
16108: }
1.1 raeburn 16109: if (keys(%changes) > 0) {
16110: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16111: if ($changes{'run'}) {
1.1 raeburn 16112: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16113: }
16114: if ($changes{'sender'}) {
1.17 raeburn 16115: if ($sender_uname eq '' || $sender_domain eq '') {
16116: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16117: } else {
16118: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16119: }
1.1 raeburn 16120: }
1.129 raeburn 16121: if ($changes{'coowners'}) {
16122: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16123: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16124: if (ref($lastactref) eq 'HASH') {
16125: $lastactref->{'domainconfig'} = 1;
16126: }
1.129 raeburn 16127: }
1.274 raeburn 16128: if ($changes{'autofailsafe'}) {
1.399 raeburn 16129: if ($autofailsafe ne '') {
16130: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16131: } else {
1.399 raeburn 16132: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16133: }
1.399 raeburn 16134: }
16135: if ($changes{'failsafe'}) {
16136: if ($failsafe eq 'off') {
16137: unless ($changes{'autofailsafe'}) {
16138: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16139: }
16140: } elsif ($failsafe eq 'zero') {
16141: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16142: } else {
16143: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16144: }
16145: }
16146: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16147: &Apache::lonnet::get_domain_defaults($dom,1);
16148: if (ref($lastactref) eq 'HASH') {
16149: $lastactref->{'domdefaults'} = 1;
16150: }
16151: }
1.1 raeburn 16152: $resulttext .= '</ul>';
16153: } else {
16154: $resulttext = &mt('No changes made to auto-enrollment settings');
16155: }
16156: } else {
1.11 albertel 16157: $resulttext = '<span class="LC_error">'.
16158: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16159: }
1.3 raeburn 16160: return $resulttext;
1.1 raeburn 16161: }
16162:
16163: sub modify_autoupdate {
1.3 raeburn 16164: my ($dom,%domconfig) = @_;
1.1 raeburn 16165: my ($resulttext,%currautoupdate,%fields,%changes);
16166: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16167: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16168: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16169: }
16170: }
16171: my @offon = ('off','on');
16172: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16173: run => 'Auto-update:',
16174: classlists => 'Updates to user information in classlists?',
16175: unexpired => 'Skip updates for users without active or future roles?',
16176: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16177: );
1.44 raeburn 16178: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16179: my %fieldtitles = &Apache::lonlocal::texthash (
16180: id => 'Student/Employee ID',
1.20 raeburn 16181: permanentemail => 'E-mail address',
1.1 raeburn 16182: lastname => 'Last Name',
16183: firstname => 'First Name',
16184: middlename => 'Middle Name',
1.132 raeburn 16185: generation => 'Generation',
1.1 raeburn 16186: );
1.142 raeburn 16187: $othertitle = &mt('All users');
1.1 raeburn 16188: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16189: $othertitle = &mt('Other users');
1.1 raeburn 16190: }
16191: foreach my $key (keys(%env)) {
16192: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16193: my ($usertype,$item) = ($1,$2);
16194: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16195: if ($usertype eq 'default') {
16196: push(@{$fields{$1}},$2);
16197: } elsif (ref($types) eq 'ARRAY') {
16198: if (grep(/^\Q$usertype\E$/,@{$types})) {
16199: push(@{$fields{$1}},$2);
16200: }
16201: }
16202: }
1.1 raeburn 16203: }
16204: }
1.131 raeburn 16205: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16206: @lockablenames = sort(@lockablenames);
16207: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16208: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16209: if (@changed) {
16210: $changes{'lockablenames'} = 1;
16211: }
16212: } else {
16213: if (@lockablenames) {
16214: $changes{'lockablenames'} = 1;
16215: }
16216: }
1.1 raeburn 16217: my %updatehash = (
16218: autoupdate => { run => $env{'form.autoupdate_run'},
16219: classlists => $env{'form.classlists'},
1.385 raeburn 16220: unexpired => $env{'form.unexpired'},
1.1 raeburn 16221: fields => {%fields},
1.131 raeburn 16222: lockablenames => \@lockablenames,
1.1 raeburn 16223: }
16224: );
1.385 raeburn 16225: my $lastactivedays;
16226: if ($env{'form.lastactive'}) {
16227: $lastactivedays = $env{'form.lastactivedays'};
16228: $lastactivedays =~ s/^\s+|\s+$//g;
16229: unless ($lastactivedays =~ /^\d+$/) {
16230: undef($lastactivedays);
16231: $env{'form.lastactive'} = 0;
16232: }
16233: }
16234: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16235: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16236: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16237: if (exists($updatehash{autoupdate}{$key})) {
16238: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16239: $changes{$key} = 1;
16240: }
16241: }
16242: } elsif ($key eq 'fields') {
16243: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16244: foreach my $item (@{$types},'default') {
1.1 raeburn 16245: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16246: my $change = 0;
16247: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16248: if (!exists($fields{$item})) {
16249: $change = 1;
1.132 raeburn 16250: last;
1.1 raeburn 16251: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16252: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16253: $change = 1;
1.132 raeburn 16254: last;
1.1 raeburn 16255: }
16256: }
16257: }
16258: if ($change) {
16259: push(@{$changes{$key}},$item);
16260: }
1.26 raeburn 16261: }
1.1 raeburn 16262: }
16263: }
1.131 raeburn 16264: } elsif ($key eq 'lockablenames') {
16265: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16266: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16267: if (@changed) {
16268: $changes{'lockablenames'} = 1;
16269: }
16270: } else {
16271: if (@lockablenames) {
16272: $changes{'lockablenames'} = 1;
16273: }
16274: }
16275: }
16276: }
16277: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16278: if (@lockablenames) {
16279: $changes{'lockablenames'} = 1;
1.1 raeburn 16280: }
16281: }
1.385 raeburn 16282: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16283: if ($updatehash{'autoupdate'}{'unexpired'}) {
16284: $changes{'unexpired'} = 1;
16285: }
16286: }
16287: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16288: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16289: $changes{'lastactive'} = 1;
16290: }
16291: }
1.26 raeburn 16292: foreach my $item (@{$types},'default') {
16293: if (defined($fields{$item})) {
16294: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16295: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16296: my $change = 0;
16297: if (ref($fields{$item}) eq 'ARRAY') {
16298: foreach my $type (@{$fields{$item}}) {
16299: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16300: $change = 1;
16301: last;
16302: }
16303: }
16304: }
16305: if ($change) {
16306: push(@{$changes{'fields'}},$item);
16307: }
16308: } else {
1.26 raeburn 16309: push(@{$changes{'fields'}},$item);
16310: }
16311: } else {
16312: push(@{$changes{'fields'}},$item);
1.1 raeburn 16313: }
16314: }
16315: }
16316: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16317: $dom);
16318: if ($putresult eq 'ok') {
16319: if (keys(%changes) > 0) {
16320: $resulttext = &mt('Changes made:').'<ul>';
16321: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16322: if ($key eq 'lockablenames') {
16323: $resulttext .= '<li>';
16324: if (@lockablenames) {
16325: $usertypes->{'default'} = $othertitle;
16326: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16327: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16328: } else {
16329: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16330: }
16331: $resulttext .= '</li>';
16332: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16333: foreach my $item (@{$changes{$key}}) {
16334: my @newvalues;
16335: foreach my $type (@{$fields{$item}}) {
16336: push(@newvalues,$fieldtitles{$type});
16337: }
1.3 raeburn 16338: my $newvaluestr;
16339: if (@newvalues > 0) {
16340: $newvaluestr = join(', ',@newvalues);
16341: } else {
16342: $newvaluestr = &mt('none');
1.6 raeburn 16343: }
1.1 raeburn 16344: if ($item eq 'default') {
1.26 raeburn 16345: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16346: } else {
1.26 raeburn 16347: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16348: }
16349: }
16350: } else {
16351: my $newvalue;
16352: if ($key eq 'run') {
16353: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16354: } elsif ($key eq 'lastactive') {
16355: $newvalue = $offon[$env{'form.lastactive'}];
16356: unless ($lastactivedays eq '') {
16357: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16358: }
1.1 raeburn 16359: } else {
16360: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16361: }
1.1 raeburn 16362: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16363: }
16364: }
16365: $resulttext .= '</ul>';
16366: } else {
1.3 raeburn 16367: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16368: }
16369: } else {
1.11 albertel 16370: $resulttext = '<span class="LC_error">'.
16371: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16372: }
1.3 raeburn 16373: return $resulttext;
1.1 raeburn 16374: }
16375:
1.125 raeburn 16376: sub modify_autocreate {
16377: my ($dom,%domconfig) = @_;
16378: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16379: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16380: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16381: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16382: }
16383: }
16384: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16385: req => 'Auto-creation of validated requests for official courses',
16386: xmldc => 'Identity of course creator of courses from XML files',
16387: );
16388: my @types = ('xml','req');
16389: foreach my $item (@types) {
16390: $newvals{$item} = $env{'form.autocreate_'.$item};
16391: $newvals{$item} =~ s/\D//g;
16392: $newvals{$item} = 0 if ($newvals{$item} eq '');
16393: }
16394: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16395: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16396: unless (exists($domcoords{$newvals{'xmldc'}})) {
16397: $newvals{'xmldc'} = '';
16398: }
16399: %autocreatehash = (
16400: autocreate => { xml => $newvals{'xml'},
16401: req => $newvals{'req'},
16402: }
16403: );
16404: if ($newvals{'xmldc'} ne '') {
16405: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16406: }
16407: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16408: $dom);
16409: if ($putresult eq 'ok') {
16410: my @items = @types;
16411: if ($newvals{'xml'}) {
16412: push(@items,'xmldc');
16413: }
16414: foreach my $item (@items) {
16415: if (exists($currautocreate{$item})) {
16416: if ($currautocreate{$item} ne $newvals{$item}) {
16417: $changes{$item} = 1;
16418: }
16419: } elsif ($newvals{$item}) {
16420: $changes{$item} = 1;
16421: }
16422: }
16423: if (keys(%changes) > 0) {
16424: my @offon = ('off','on');
16425: $resulttext = &mt('Changes made:').'<ul>';
16426: foreach my $item (@types) {
16427: if ($changes{$item}) {
16428: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16429: $resulttext .= '<li>'.
16430: &mt("$title{$item} set to [_1]$newtxt [_2]",
16431: '<b>','</b>').
16432: '</li>';
1.125 raeburn 16433: }
16434: }
16435: if ($changes{'xmldc'}) {
16436: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16437: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16438: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16439: }
16440: $resulttext .= '</ul>';
16441: } else {
16442: $resulttext = &mt('No changes made to auto-creation settings');
16443: }
16444: } else {
16445: $resulttext = '<span class="LC_error">'.
16446: &mt('An error occurred: [_1]',$putresult).'</span>';
16447: }
16448: return $resulttext;
16449: }
16450:
1.23 raeburn 16451: sub modify_directorysrch {
1.295 raeburn 16452: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16453: my ($resulttext,%changes);
16454: my %currdirsrch;
16455: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16456: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16457: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16458: }
16459: }
1.277 raeburn 16460: my %title = ( available => 'Institutional directory search available',
16461: localonly => 'Other domains can search institution',
16462: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16463: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16464: searchby => 'Search types',
16465: searchtypes => 'Search latitude');
16466: my @offon = ('off','on');
1.24 raeburn 16467: my @otherdoms = ('Yes','No');
1.23 raeburn 16468:
1.25 raeburn 16469: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16470: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16471: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16472:
1.44 raeburn 16473: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16474: if (keys(%{$usertypes}) == 0) {
16475: @cansearch = ('default');
16476: } else {
16477: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16478: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16479: if (!grep(/^\Q$type\E$/,@cansearch)) {
16480: push(@{$changes{'cansearch'}},$type);
16481: }
1.23 raeburn 16482: }
1.26 raeburn 16483: foreach my $type (@cansearch) {
16484: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16485: push(@{$changes{'cansearch'}},$type);
16486: }
1.23 raeburn 16487: }
1.26 raeburn 16488: } else {
16489: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16490: }
16491: }
16492:
16493: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16494: foreach my $by (@{$currdirsrch{'searchby'}}) {
16495: if (!grep(/^\Q$by\E$/,@searchby)) {
16496: push(@{$changes{'searchby'}},$by);
16497: }
16498: }
16499: foreach my $by (@searchby) {
16500: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16501: push(@{$changes{'searchby'}},$by);
16502: }
16503: }
16504: } else {
16505: push(@{$changes{'searchby'}},@searchby);
16506: }
1.25 raeburn 16507:
16508: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16509: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16510: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16511: push(@{$changes{'searchtypes'}},$type);
16512: }
16513: }
16514: foreach my $type (@searchtypes) {
16515: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16516: push(@{$changes{'searchtypes'}},$type);
16517: }
16518: }
16519: } else {
16520: if (exists($currdirsrch{'searchtypes'})) {
16521: foreach my $type (@searchtypes) {
16522: if ($type ne $currdirsrch{'searchtypes'}) {
16523: push(@{$changes{'searchtypes'}},$type);
16524: }
16525: }
16526: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16527: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16528: }
16529: } else {
16530: push(@{$changes{'searchtypes'}},@searchtypes);
16531: }
16532: }
16533:
1.23 raeburn 16534: my %dirsrch_hash = (
16535: directorysrch => { available => $env{'form.dirsrch_available'},
16536: cansearch => \@cansearch,
1.277 raeburn 16537: localonly => $env{'form.dirsrch_instlocalonly'},
16538: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16539: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16540: searchby => \@searchby,
1.25 raeburn 16541: searchtypes => \@searchtypes,
1.23 raeburn 16542: }
16543: );
16544: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16545: $dom);
16546: if ($putresult eq 'ok') {
16547: if (exists($currdirsrch{'available'})) {
16548: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16549: $changes{'available'} = 1;
16550: }
16551: } else {
16552: if ($env{'form.dirsrch_available'} eq '1') {
16553: $changes{'available'} = 1;
16554: }
16555: }
1.277 raeburn 16556: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16557: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16558: $changes{'lcavailable'} = 1;
16559: }
1.277 raeburn 16560: } else {
16561: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16562: $changes{'lcavailable'} = 1;
16563: }
16564: }
1.24 raeburn 16565: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16566: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16567: $changes{'localonly'} = 1;
16568: }
1.24 raeburn 16569: } else {
1.277 raeburn 16570: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16571: $changes{'localonly'} = 1;
16572: }
16573: }
1.277 raeburn 16574: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16575: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16576: $changes{'lclocalonly'} = 1;
16577: }
1.277 raeburn 16578: } else {
16579: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16580: $changes{'lclocalonly'} = 1;
16581: }
16582: }
1.23 raeburn 16583: if (keys(%changes) > 0) {
16584: $resulttext = &mt('Changes made:').'<ul>';
16585: if ($changes{'available'}) {
16586: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16587: }
1.277 raeburn 16588: if ($changes{'lcavailable'}) {
16589: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16590: }
1.24 raeburn 16591: if ($changes{'localonly'}) {
1.277 raeburn 16592: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16593: }
1.277 raeburn 16594: if ($changes{'lclocalonly'}) {
16595: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16596: }
1.23 raeburn 16597: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16598: my $chgtext;
1.26 raeburn 16599: if (ref($usertypes) eq 'HASH') {
16600: if (keys(%{$usertypes}) > 0) {
16601: foreach my $type (@{$types}) {
16602: if (grep(/^\Q$type\E$/,@cansearch)) {
16603: $chgtext .= $usertypes->{$type}.'; ';
16604: }
16605: }
16606: if (grep(/^default$/,@cansearch)) {
16607: $chgtext .= $othertitle;
16608: } else {
16609: $chgtext =~ s/\; $//;
16610: }
1.210 raeburn 16611: $resulttext .=
1.178 raeburn 16612: '<li>'.
16613: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16614: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16615: '</li>';
1.23 raeburn 16616: }
16617: }
16618: }
16619: if (ref($changes{'searchby'}) eq 'ARRAY') {
16620: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16621: my $chgtext;
16622: foreach my $type (@{$titleorder}) {
16623: if (grep(/^\Q$type\E$/,@searchby)) {
16624: if (defined($searchtitles->{$type})) {
16625: $chgtext .= $searchtitles->{$type}.'; ';
16626: }
16627: }
16628: }
16629: $chgtext =~ s/\; $//;
16630: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16631: }
1.25 raeburn 16632: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16633: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16634: my $chgtext;
16635: foreach my $type (@{$srchtypeorder}) {
16636: if (grep(/^\Q$type\E$/,@searchtypes)) {
16637: if (defined($srchtypes_desc->{$type})) {
16638: $chgtext .= $srchtypes_desc->{$type}.'; ';
16639: }
16640: }
16641: }
16642: $chgtext =~ s/\; $//;
1.178 raeburn 16643: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16644: }
16645: $resulttext .= '</ul>';
1.295 raeburn 16646: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16647: if (ref($lastactref) eq 'HASH') {
16648: $lastactref->{'directorysrch'} = 1;
16649: }
1.23 raeburn 16650: } else {
1.277 raeburn 16651: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 16652: }
16653: } else {
16654: $resulttext = '<span class="LC_error">'.
1.27 raeburn 16655: &mt('An error occurred: [_1]',$putresult).'</span>';
16656: }
16657: return $resulttext;
16658: }
16659:
1.28 raeburn 16660: sub modify_contacts {
1.205 raeburn 16661: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 16662: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
16663: if (ref($domconfig{'contacts'}) eq 'HASH') {
16664: foreach my $key (keys(%{$domconfig{'contacts'}})) {
16665: $currsetting{$key} = $domconfig{'contacts'}{$key};
16666: }
16667: }
1.286 raeburn 16668: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 16669: my @contacts = ('supportemail','adminemail');
1.286 raeburn 16670: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 16671: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 16672: my @toggles = ('reporterrors','reportupdates','reportstatus');
16673: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 16674: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 16675: foreach my $type (@mailings) {
16676: @{$newsetting{$type}} =
16677: &Apache::loncommon::get_env_multiple('form.'.$type);
16678: foreach my $item (@contacts) {
16679: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
16680: $contacts_hash{contacts}{$type}{$item} = 1;
16681: } else {
16682: $contacts_hash{contacts}{$type}{$item} = 0;
16683: }
1.289 raeburn 16684: }
1.28 raeburn 16685: $others{$type} = $env{'form.'.$type.'_others'};
16686: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 16687: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16688: $bcc{$type} = $env{'form.'.$type.'_bcc'};
16689: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 16690: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
16691: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16692: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16693: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16694: }
1.134 raeburn 16695: }
1.28 raeburn 16696: }
16697: foreach my $item (@contacts) {
16698: $to{$item} = $env{'form.'.$item};
16699: $contacts_hash{'contacts'}{$item} = $to{$item};
16700: }
1.203 raeburn 16701: foreach my $item (@toggles) {
16702: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16703: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16704: }
16705: }
1.340 raeburn 16706: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16707: foreach my $item (@lonstatus) {
16708: if ($item eq 'excluded') {
16709: my (%serverhomes,@excluded);
16710: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16711: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16712: if (@possexcluded) {
16713: foreach my $id (sort(@possexcluded)) {
16714: if ($serverhomes{$id}) {
16715: push(@excluded,$id);
16716: }
16717: }
16718: }
16719: if (@excluded) {
16720: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16721: }
16722: } elsif ($item eq 'weights') {
1.377 raeburn 16723: foreach my $type ('E','W','N','U') {
1.340 raeburn 16724: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16725: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16726: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16727: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16728: $env{'form.error'.$item.'_'.$type};
16729: }
16730: }
16731: }
16732: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16733: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16734: if ($env{'form.error'.$item} =~ /^\d+$/) {
16735: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16736: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16737: }
16738: }
16739: }
16740: }
1.286 raeburn 16741: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16742: foreach my $field (@{$fields}) {
16743: if (ref($possoptions->{$field}) eq 'ARRAY') {
16744: my $value = $env{'form.helpform_'.$field};
16745: $value =~ s/^\s+|\s+$//g;
16746: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16747: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16748: if ($field eq 'screenshot') {
16749: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16750: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16751: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16752: }
16753: }
16754: }
16755: }
16756: }
16757: }
1.315 raeburn 16758: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16759: my (@statuses,%usertypeshash,@overrides);
16760: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16761: @statuses = @{$types};
16762: if (ref($usertypes) eq 'HASH') {
16763: %usertypeshash = %{$usertypes};
16764: }
16765: }
16766: if (@statuses) {
16767: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16768: foreach my $type (@possoverrides) {
16769: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16770: push(@overrides,$type);
16771: }
16772: }
16773: if (@overrides) {
16774: foreach my $type (@overrides) {
16775: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16776: foreach my $item (@contacts) {
16777: if (grep(/^\Q$item\E$/,@standard)) {
16778: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16779: $newsetting{'override_'.$type}{$item} = 1;
16780: } else {
16781: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16782: $newsetting{'override_'.$type}{$item} = 0;
16783: }
16784: }
16785: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16786: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16787: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16788: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16789: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16790: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16791: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16792: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16793: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16794: }
16795: }
16796: }
16797: }
1.28 raeburn 16798: if (keys(%currsetting) > 0) {
16799: foreach my $item (@contacts) {
16800: if ($to{$item} ne $currsetting{$item}) {
16801: $changes{$item} = 1;
16802: }
16803: }
16804: foreach my $type (@mailings) {
16805: foreach my $item (@contacts) {
16806: if (ref($currsetting{$type}) eq 'HASH') {
16807: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16808: push(@{$changes{$type}},$item);
16809: }
16810: } else {
16811: push(@{$changes{$type}},@{$newsetting{$type}});
16812: }
16813: }
16814: if ($others{$type} ne $currsetting{$type}{'others'}) {
16815: push(@{$changes{$type}},'others');
16816: }
1.289 raeburn 16817: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16818: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16819: push(@{$changes{$type}},'bcc');
16820: }
1.286 raeburn 16821: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16822: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16823: push(@{$changes{$type}},'include');
16824: }
16825: }
16826: }
16827: if (ref($fields) eq 'ARRAY') {
16828: if (ref($currsetting{'helpform'}) eq 'HASH') {
16829: foreach my $field (@{$fields}) {
16830: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16831: push(@{$changes{'helpform'}},$field);
16832: }
16833: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16834: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16835: push(@{$changes{'helpform'}},'maxsize');
16836: }
16837: }
16838: }
16839: } else {
16840: foreach my $field (@{$fields}) {
16841: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16842: push(@{$changes{'helpform'}},$field);
16843: }
16844: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16845: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16846: push(@{$changes{'helpform'}},'maxsize');
16847: }
16848: }
16849: }
1.134 raeburn 16850: }
1.28 raeburn 16851: }
1.315 raeburn 16852: if (@statuses) {
16853: if (ref($currsetting{'overrides'}) eq 'HASH') {
16854: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16855: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16856: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16857: foreach my $item (@contacts,'bcc','others','include') {
16858: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16859: push(@{$changes{'overrides'}},$key);
16860: last;
16861: }
16862: }
16863: } else {
16864: push(@{$changes{'overrides'}},$key);
16865: }
16866: }
16867: }
16868: foreach my $key (@overrides) {
16869: unless (exists($currsetting{'overrides'}{$key})) {
16870: push(@{$changes{'overrides'}},$key);
16871: }
16872: }
16873: } else {
16874: foreach my $key (@overrides) {
16875: push(@{$changes{'overrides'}},$key);
16876: }
16877: }
16878: }
1.340 raeburn 16879: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16880: foreach my $key ('excluded','weights','threshold','sysmail') {
16881: if ($key eq 'excluded') {
16882: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16883: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16884: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16885: (@{$currsetting{'lonstatus'}{$key}})) {
16886: my @diffs =
16887: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16888: $currsetting{'lonstatus'}{$key});
16889: if (@diffs) {
16890: push(@{$changes{'lonstatus'}},$key);
16891: }
16892: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16893: push(@{$changes{'lonstatus'}},$key);
16894: }
16895: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16896: (@{$currsetting{'lonstatus'}{$key}})) {
16897: push(@{$changes{'lonstatus'}},$key);
16898: }
16899: } elsif ($key eq 'weights') {
16900: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16901: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16902: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16903: foreach my $type ('E','W','N','U') {
1.340 raeburn 16904: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16905: $currsetting{'lonstatus'}{$key}{$type}) {
16906: push(@{$changes{'lonstatus'}},$key);
16907: last;
16908: }
16909: }
16910: } else {
1.341 raeburn 16911: foreach my $type ('E','W','N','U') {
1.340 raeburn 16912: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16913: push(@{$changes{'lonstatus'}},$key);
16914: last;
16915: }
16916: }
16917: }
16918: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16919: foreach my $type ('E','W','N','U') {
1.340 raeburn 16920: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16921: push(@{$changes{'lonstatus'}},$key);
16922: last;
16923: }
16924: }
16925: }
16926: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16927: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16928: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16929: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16930: push(@{$changes{'lonstatus'}},$key);
16931: }
16932: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16933: push(@{$changes{'lonstatus'}},$key);
16934: }
16935: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16936: push(@{$changes{'lonstatus'}},$key);
16937: }
16938: }
16939: }
16940: } else {
16941: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16942: foreach my $key ('excluded','weights','threshold','sysmail') {
16943: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16944: push(@{$changes{'lonstatus'}},$key);
16945: }
16946: }
16947: }
16948: }
1.28 raeburn 16949: } else {
16950: my %default;
16951: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16952: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16953: $default{'errormail'} = 'adminemail';
16954: $default{'packagesmail'} = 'adminemail';
16955: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16956: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16957: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16958: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16959: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16960: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16961: foreach my $item (@contacts) {
16962: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16963: $changes{$item} = 1;
1.203 raeburn 16964: }
1.28 raeburn 16965: }
16966: foreach my $type (@mailings) {
16967: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16968: push(@{$changes{$type}},@{$newsetting{$type}});
16969: }
16970: if ($others{$type} ne '') {
16971: push(@{$changes{$type}},'others');
1.134 raeburn 16972: }
1.286 raeburn 16973: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16974: if ($bcc{$type} ne '') {
16975: push(@{$changes{$type}},'bcc');
16976: }
1.286 raeburn 16977: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16978: push(@{$changes{$type}},'include');
16979: }
1.134 raeburn 16980: }
1.28 raeburn 16981: }
1.286 raeburn 16982: if (ref($fields) eq 'ARRAY') {
16983: foreach my $field (@{$fields}) {
16984: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16985: push(@{$changes{'helpform'}},$field);
16986: }
16987: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16988: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16989: push(@{$changes{'helpform'}},'maxsize');
16990: }
16991: }
16992: }
1.289 raeburn 16993: }
1.340 raeburn 16994: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16995: foreach my $key ('excluded','weights','threshold','sysmail') {
16996: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16997: push(@{$changes{'lonstatus'}},$key);
16998: }
16999: }
17000: }
1.28 raeburn 17001: }
1.203 raeburn 17002: foreach my $item (@toggles) {
17003: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17004: $changes{$item} = 1;
17005: } elsif ((!$env{'form.'.$item}) &&
17006: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17007: $changes{$item} = 1;
17008: }
17009: }
1.28 raeburn 17010: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17011: $dom);
17012: if ($putresult eq 'ok') {
17013: if (keys(%changes) > 0) {
1.205 raeburn 17014: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17015: if (ref($lastactref) eq 'HASH') {
17016: $lastactref->{'domainconfig'} = 1;
17017: }
1.28 raeburn 17018: my ($titles,$short_titles) = &contact_titles();
17019: $resulttext = &mt('Changes made:').'<ul>';
17020: foreach my $item (@contacts) {
17021: if ($changes{$item}) {
17022: $resulttext .= '<li>'.$titles->{$item}.
17023: &mt(' set to: ').
17024: '<span class="LC_cusr_emph">'.
17025: $to{$item}.'</span></li>';
17026: }
17027: }
17028: foreach my $type (@mailings) {
17029: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17030: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17031: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17032: } else {
17033: $resulttext .= '<li>'.$titles->{$type}.': ';
17034: }
1.28 raeburn 17035: my @text;
17036: foreach my $item (@{$newsetting{$type}}) {
17037: push(@text,$short_titles->{$item});
17038: }
17039: if ($others{$type} ne '') {
17040: push(@text,$others{$type});
17041: }
1.286 raeburn 17042: if (@text) {
17043: $resulttext .= '<span class="LC_cusr_emph">'.
17044: join(', ',@text).'</span>';
17045: }
17046: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17047: if ($bcc{$type} ne '') {
1.286 raeburn 17048: my $bcctext;
17049: if (@text) {
1.289 raeburn 17050: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17051: } else {
17052: $bcctext = '(Bcc)';
17053: }
17054: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17055: } elsif (!@text) {
17056: $resulttext .= &mt('No one');
17057: }
1.289 raeburn 17058: if ($includestr{$type} ne '') {
1.286 raeburn 17059: if ($includeloc{$type} eq 'b') {
17060: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17061: } elsif ($includeloc{$type} eq 's') {
17062: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17063: }
1.134 raeburn 17064: }
1.286 raeburn 17065: } elsif (!@text) {
17066: $resulttext .= &mt('No recipients');
1.134 raeburn 17067: }
17068: $resulttext .= '</li>';
1.28 raeburn 17069: }
17070: }
1.315 raeburn 17071: if (ref($changes{'overrides'}) eq 'ARRAY') {
17072: my @deletions;
17073: foreach my $type (@{$changes{'overrides'}}) {
17074: if ($usertypeshash{$type}) {
17075: if (grep(/^\Q$type\E/,@overrides)) {
17076: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17077: $usertypeshash{$type}).'<ul><li>';
17078: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17079: my @text;
17080: foreach my $item (@contacts) {
17081: if ($newsetting{'override_'.$type}{$item}) {
17082: push(@text,$short_titles->{$item});
17083: }
17084: }
17085: if ($newsetting{'override_'.$type}{'others'} ne '') {
17086: push(@text,$newsetting{'override_'.$type}{'others'});
17087: }
17088:
17089: if (@text) {
17090: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17091: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17092: }
17093: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17094: my $bcctext;
17095: if (@text) {
17096: $bcctext = ' '.&mt('with Bcc to');
17097: } else {
17098: $bcctext = '(Bcc)';
17099: }
17100: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17101: } elsif (!@text) {
17102: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17103: }
17104: $resulttext .= '</li>';
17105: if ($newsetting{'override_'.$type}{'include'} ne '') {
17106: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17107: if ($loc eq 'b') {
17108: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17109: } elsif ($loc eq 's') {
17110: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17111: }
17112: }
17113: }
17114: $resulttext .= '</li></ul></li>';
17115: } else {
17116: push(@deletions,$usertypeshash{$type});
17117: }
17118: }
17119: }
17120: if (@deletions) {
17121: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17122: join(', ',@deletions)).'</li>';
17123: }
17124: }
1.203 raeburn 17125: my @offon = ('off','on');
1.340 raeburn 17126: my $corelink = &core_link_msu();
1.203 raeburn 17127: if ($changes{'reporterrors'}) {
17128: $resulttext .= '<li>'.
17129: &mt('E-mail error reports to [_1] set to "'.
17130: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17131: $corelink).
1.203 raeburn 17132: '</li>';
17133: }
17134: if ($changes{'reportupdates'}) {
17135: $resulttext .= '<li>'.
17136: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17137: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17138: $corelink).
1.203 raeburn 17139: '</li>';
17140: }
1.340 raeburn 17141: if ($changes{'reportstatus'}) {
17142: $resulttext .= '<li>'.
17143: &mt('E-mail status if errors above threshold to [_1] set to "'.
17144: $offon[$env{'form.reportstatus'}].'".',
17145: $corelink).
17146: '</li>';
17147: }
17148: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17149: $resulttext .= '<li>'.
17150: &mt('Nightly status check e-mail settings').':<ul>';
17151: my (%defval,%use_def,%shown);
17152: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17153: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17154: $defval{'weights'} =
1.341 raeburn 17155: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17156: $defval{'excluded'} = &mt('None');
17157: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17158: foreach my $item ('threshold','sysmail','weights','excluded') {
17159: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17160: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17161: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17162: } elsif ($item eq 'weights') {
17163: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17164: foreach my $type ('E','W','N','U') {
1.340 raeburn 17165: $shown{$item} .= $lonstatus_names->{$type}.'=';
17166: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17167: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17168: } else {
17169: $shown{$item} .= $lonstatus_defs->{$type};
17170: }
17171: $shown{$item} .= ', ';
17172: }
17173: $shown{$item} =~ s/, $//;
17174: } else {
17175: $shown{$item} = $defval{$item};
17176: }
17177: } elsif ($item eq 'excluded') {
17178: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17179: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17180: } else {
17181: $shown{$item} = $defval{$item};
17182: }
17183: }
17184: } else {
17185: $shown{$item} = $defval{$item};
17186: }
17187: }
17188: } else {
17189: foreach my $item ('threshold','weights','excluded','sysmail') {
17190: $shown{$item} = $defval{$item};
17191: }
17192: }
17193: foreach my $item ('threshold','weights','excluded','sysmail') {
17194: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17195: $shown{$item}).'</li>';
17196: }
17197: $resulttext .= '</ul></li>';
17198: }
1.286 raeburn 17199: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17200: my (@optional,@required,@unused,$maxsizechg);
17201: foreach my $field (@{$changes{'helpform'}}) {
17202: if ($field eq 'maxsize') {
17203: $maxsizechg = 1;
17204: next;
17205: }
17206: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17207: push(@optional,$field);
1.286 raeburn 17208: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17209: push(@unused,$field);
17210: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17211: push(@required,$field);
1.286 raeburn 17212: }
17213: }
17214: if (@optional) {
17215: $resulttext .= '<li>'.
17216: &mt('Help form fields changed to "Optional": [_1].',
17217: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17218: '</li>';
17219: }
17220: if (@required) {
17221: $resulttext .= '<li>'.
17222: &mt('Help form fields changed to "Required": [_1].',
17223: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17224: '</li>';
17225: }
17226: if (@unused) {
17227: $resulttext .= '<li>'.
17228: &mt('Help form fields changed to "Not shown": [_1].',
17229: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17230: '</li>';
17231: }
17232: if ($maxsizechg) {
17233: $resulttext .= '<li>'.
17234: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17235: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17236: '</li>';
17237: }
17238: }
1.28 raeburn 17239: $resulttext .= '</ul>';
17240: } else {
1.288 raeburn 17241: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17242: }
17243: } else {
17244: $resulttext = '<span class="LC_error">'.
17245: &mt('An error occurred: [_1].',$putresult).'</span>';
17246: }
17247: return $resulttext;
17248: }
17249:
1.357 raeburn 17250: sub modify_privacy {
17251: my ($dom,%domconfig) = @_;
17252: my ($resulttext,%current,%changes);
17253: if (ref($domconfig{'privacy'}) eq 'HASH') {
17254: %current = %{$domconfig{'privacy'}};
17255: }
17256: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17257: my @items = ('domain','author','course','community');
17258: my %names = &Apache::lonlocal::texthash (
17259: domain => 'Assigned domain role(s)',
17260: author => 'Assigned co-author role(s)',
17261: course => 'Assigned course role(s)',
17262: community => 'Assigned community role',
17263: );
17264: my %roles = &Apache::lonlocal::texthash (
17265: domain => 'Domain role',
17266: author => 'Co-author role',
17267: course => 'Course role',
17268: community => 'Community role',
17269: );
17270: my %titles = &Apache::lonlocal::texthash (
17271: approval => 'Approval for role in different domain',
17272: othdom => 'User information available in other domain',
17273: priv => 'Information viewable by privileged user in same domain',
17274: unpriv => 'Information viewable by unprivileged user in same domain',
17275: instdom => 'Other domain shares institution/provider',
17276: extdom => 'Other domain has different institution/provider',
17277: none => 'Not allowed',
17278: user => 'User authorizes',
17279: domain => 'Domain Coordinator authorizes',
17280: auto => 'Unrestricted',
17281: );
17282: my %fieldnames = &Apache::lonlocal::texthash (
17283: id => 'Student/Employee ID',
17284: permanentemail => 'E-mail address',
17285: lastname => 'Last Name',
17286: firstname => 'First Name',
17287: middlename => 'Middle Name',
17288: generation => 'Generation',
17289: );
17290: my ($othertitle,$usertypes,$types) =
17291: &Apache::loncommon::sorted_inst_types($dom);
17292: my (%by_ip,%by_location,@intdoms,@instdoms);
17293: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17294:
17295: my %privacyhash = (
17296: 'approval' => {
17297: instdom => {},
17298: extdom => {},
17299: },
17300: 'othdom' => {},
17301: 'priv' => {},
17302: 'unpriv' => {},
17303: );
17304: foreach my $item (@items) {
17305: if (@instdoms > 1) {
17306: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
17307: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17308: }
17309: if (ref($current{'approval'}) eq 'HASH') {
17310: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17311: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17312: $changes{'approval'} = 1;
17313: }
17314: }
17315: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17316: $changes{'approval'} = 1;
17317: }
17318: }
17319: if (keys(%by_location) > 0) {
17320: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17321: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17322: }
17323: if (ref($current{'approval'}) eq 'HASH') {
17324: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17325: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17326: $changes{'approval'} = 1;
17327: }
17328: }
17329: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17330: $changes{'approval'} = 1;
17331: }
17332: }
17333: foreach my $status ('priv','unpriv') {
17334: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17335: my @newvalues;
17336: foreach my $field (@possibles) {
17337: if (grep(/^\Q$field\E$/,@fields)) {
17338: $privacyhash{$status}{$item}{$field} = 1;
17339: push(@newvalues,$field);
17340: }
17341: }
17342: @newvalues = sort(@newvalues);
17343: if (ref($current{$status}) eq 'HASH') {
17344: if (ref($current{$status}{$item}) eq 'HASH') {
17345: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17346: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17347: if (@diffs > 0) {
17348: $changes{$status} = 1;
17349: }
17350: }
17351: } else {
17352: my @stdfields;
17353: foreach my $field (@fields) {
17354: if ($field eq 'id') {
17355: next if ($status eq 'unpriv');
17356: next if (($status eq 'priv') && ($item eq 'community'));
17357: }
17358: push(@stdfields,$field);
17359: }
17360: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17361: if (@diffs > 0) {
17362: $changes{$status} = 1;
17363: }
17364: }
17365: }
17366: }
17367: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17368: my @statuses;
17369: if (ref($types) eq 'ARRAY') {
17370: @statuses = @{$types};
17371: }
17372: foreach my $type (@statuses,'default') {
17373: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17374: my @newvalues;
17375: foreach my $field (sort(@possfields)) {
17376: if (grep(/^\Q$field\E$/,@fields)) {
17377: $privacyhash{'othdom'}{$type}{$field} = 1;
17378: push(@newvalues,$field);
17379: }
17380: }
17381: @newvalues = sort(@newvalues);
17382: if (ref($current{'othdom'}) eq 'HASH') {
17383: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17384: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17385: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17386: if (@diffs > 0) {
17387: $changes{'othdom'} = 1;
17388: }
17389: }
17390: } else {
17391: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17392: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17393: if (@diffs > 0) {
17394: $changes{'othdom'} = 1;
17395: }
17396: }
17397: }
17398: }
17399: my %confighash = (
17400: privacy => \%privacyhash,
17401: );
17402: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17403: if ($putresult eq 'ok') {
17404: if (keys(%changes) > 0) {
17405: $resulttext = &mt('Changes made: ').'<ul>';
17406: foreach my $key ('approval','othdom','priv','unpriv') {
17407: if ($changes{$key}) {
17408: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17409: if ($key eq 'approval') {
17410: if (keys(%{$privacyhash{$key}{instdom}})) {
17411: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17412: foreach my $item (@items) {
17413: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17414: }
17415: $resulttext .= '</ul></li>';
17416: }
17417: if (keys(%{$privacyhash{$key}{extdom}})) {
17418: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17419: foreach my $item (@items) {
17420: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17421: }
17422: $resulttext .= '</ul></li>';
17423: }
17424: } elsif ($key eq 'othdom') {
17425: my @statuses;
17426: if (ref($types) eq 'ARRAY') {
17427: @statuses = @{$types};
17428: }
17429: if (ref($privacyhash{$key}) eq 'HASH') {
17430: foreach my $status (@statuses,'default') {
17431: if ($status eq 'default') {
17432: $resulttext .= '<li>'.$othertitle.': ';
17433: } elsif (ref($usertypes) eq 'HASH') {
17434: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17435: } else {
17436: next;
17437: }
17438: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17439: if (keys(%{$privacyhash{$key}{$status}})) {
17440: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17441: } else {
17442: $resulttext .= &mt('none');
17443: }
17444: }
17445: $resulttext .= '</li>';
17446: }
17447: }
17448: } else {
17449: foreach my $item (@items) {
17450: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17451: $resulttext .= '<li>'.$names{$item}.': ';
17452: if (keys(%{$privacyhash{$key}{$item}})) {
17453: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17454: } else {
17455: $resulttext .= &mt('none');
17456: }
17457: $resulttext .= '</li>';
17458: }
17459: }
17460: }
17461: $resulttext .= '</ul></li>';
17462: }
17463: }
17464: } else {
17465: $resulttext = &mt('No changes made to user information settings');
17466: }
17467: } else {
17468: $resulttext = '<span class="LC_error">'.
17469: &mt('An error occurred: [_1]',$putresult).'</span>';
17470: }
17471: return $resulttext;
17472: }
17473:
1.354 raeburn 17474: sub modify_passwords {
17475: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17476: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17477: $updatedefaults,$updateconf);
1.354 raeburn 17478: my $customfn = 'resetpw.html';
17479: if (ref($domconfig{'passwords'}) eq 'HASH') {
17480: %current = %{$domconfig{'passwords'}};
17481: }
17482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17483: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17484: if (ref($types) eq 'ARRAY') {
17485: @oktypes = @{$types};
17486: }
17487: push(@oktypes,'default');
17488:
17489: my %titles = &Apache::lonlocal::texthash (
17490: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17491: intauth_check => 'Check bcrypt cost if authenticated',
17492: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17493: permanent => 'Permanent e-mail address',
17494: critical => 'Critical notification address',
17495: notify => 'Notification address',
17496: min => 'Minimum password length',
17497: max => 'Maximum password length',
17498: chars => 'Required characters',
17499: expire => 'Password expiration (days)',
1.356 raeburn 17500: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17501: reset => 'Resetting Forgotten Password',
17502: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17503: rules => 'Rules for LON-CAPA Passwords',
17504: crsownerchg => 'Course Owner Changing Student Passwords',
17505: username => 'Username',
17506: email => 'E-mail address',
17507: );
17508:
17509: #
17510: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17511: #
17512: my (%curr_defaults,%save_defaults);
17513: if (ref($domconfig{'defaults'}) eq 'HASH') {
17514: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17515: if ($key =~ /^intauth_(cost|check|switch)$/) {
17516: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17517: } else {
17518: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17519: }
17520: }
17521: }
17522: my %staticdefaults = (
17523: 'resetlink' => 2,
17524: 'resetcase' => \@oktypes,
17525: 'resetprelink' => 'both',
17526: 'resetemail' => ['critical','notify','permanent'],
17527: 'intauth_cost' => 10,
17528: 'intauth_check' => 0,
17529: 'intauth_switch' => 0,
17530: );
1.365 raeburn 17531: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17532: foreach my $type (@oktypes) {
17533: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17534: }
17535: my $linklife = $env{'form.passwords_link'};
17536: $linklife =~ s/^\s+|\s+$//g;
17537: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17538: $newvalues{'resetlink'} = $linklife;
17539: if ($current{'resetlink'}) {
17540: if ($current{'resetlink'} ne $linklife) {
17541: $changes{'reset'} = 1;
17542: }
1.368 raeburn 17543: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17544: if ($staticdefaults{'resetlink'} ne $linklife) {
17545: $changes{'reset'} = 1;
17546: }
17547: }
17548: } elsif ($current{'resetlink'}) {
17549: $changes{'reset'} = 1;
17550: }
17551: my @casesens;
17552: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17553: foreach my $case (sort(@posscase)) {
17554: if (grep(/^\Q$case\E$/,@oktypes)) {
17555: push(@casesens,$case);
17556: }
17557: }
17558: $newvalues{'resetcase'} = \@casesens;
17559: if (ref($current{'resetcase'}) eq 'ARRAY') {
17560: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17561: if (@diffs > 0) {
17562: $changes{'reset'} = 1;
17563: }
1.368 raeburn 17564: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17565: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17566: if (@diffs > 0) {
17567: $changes{'reset'} = 1;
17568: }
17569: }
17570: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17571: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17572: if (exists($current{'resetprelink'})) {
17573: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17574: $changes{'reset'} = 1;
17575: }
1.368 raeburn 17576: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17577: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17578: $changes{'reset'} = 1;
17579: }
17580: }
17581: } elsif ($current{'resetprelink'}) {
17582: $changes{'reset'} = 1;
17583: }
17584: foreach my $type (@oktypes) {
17585: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17586: my @postlink;
17587: foreach my $item (sort(@possplink)) {
17588: if ($item =~ /^(email|username)$/) {
17589: push(@postlink,$item);
17590: }
17591: }
17592: $newvalues{'resetpostlink'}{$type} = \@postlink;
17593: unless ($changes{'reset'}) {
17594: if (ref($current{'resetpostlink'}) eq 'HASH') {
17595: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17596: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17597: if (@diffs > 0) {
17598: $changes{'reset'} = 1;
17599: }
17600: } else {
17601: $changes{'reset'} = 1;
17602: }
1.368 raeburn 17603: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17604: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17605: if (@diffs > 0) {
17606: $changes{'reset'} = 1;
17607: }
17608: }
17609: }
17610: }
17611: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
17612: my @resetemail;
17613: foreach my $item (sort(@possemailsrc)) {
17614: if ($item =~ /^(permanent|critical|notify)$/) {
17615: push(@resetemail,$item);
17616: }
17617: }
17618: $newvalues{'resetemail'} = \@resetemail;
17619: unless ($changes{'reset'}) {
17620: if (ref($current{'resetemail'}) eq 'ARRAY') {
17621: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
17622: if (@diffs > 0) {
17623: $changes{'reset'} = 1;
17624: }
1.368 raeburn 17625: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17626: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
17627: if (@diffs > 0) {
17628: $changes{'reset'} = 1;
17629: }
17630: }
17631: }
17632: if ($env{'form.passwords_stdtext'} == 0) {
17633: $newvalues{'resetremove'} = 1;
17634: unless ($current{'resetremove'}) {
17635: $changes{'reset'} = 1;
17636: }
17637: } elsif ($current{'resetremove'}) {
17638: $changes{'reset'} = 1;
17639: }
17640: if ($env{'form.passwords_customfile.filename'} ne '') {
17641: my $servadm = $r->dir_config('lonAdmEMail');
17642: my ($configuserok,$author_ok,$switchserver) =
17643: &config_check($dom,$confname,$servadm);
17644: my $error;
17645: if ($configuserok eq 'ok') {
17646: if ($switchserver) {
17647: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
17648: } else {
17649: if ($author_ok eq 'ok') {
17650: my ($result,$customurl) =
17651: &publishlogo($r,'upload','passwords_customfile',$dom,
17652: $confname,'customtext/resetpw','','',$customfn);
17653: if ($result eq 'ok') {
17654: $newvalues{'resetcustom'} = $customurl;
17655: $changes{'reset'} = 1;
17656: } else {
17657: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
17658: }
17659: } else {
17660: $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);
17661: }
17662: }
17663: } else {
17664: $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);
17665: }
17666: if ($error) {
17667: &Apache::lonnet::logthis($error);
17668: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17669: }
17670: } elsif ($current{'resetcustom'}) {
17671: if ($env{'form.passwords_custom_del'}) {
17672: $changes{'reset'} = 1;
17673: } else {
17674: $newvalues{'resetcustom'} = $current{'resetcustom'};
17675: }
17676: }
17677: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
17678: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
17679: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
17680: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
17681: $changes{'intauth'} = 1;
17682: }
17683: } else {
17684: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
17685: }
17686: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
17687: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
17688: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
17689: $changes{'intauth'} = 1;
17690: }
17691: } else {
17692: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17693: }
17694: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17695: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17696: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17697: $changes{'intauth'} = 1;
17698: }
17699: } else {
17700: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17701: }
17702: foreach my $item ('cost','check','switch') {
17703: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17704: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17705: $updatedefaults = 1;
17706: }
17707: }
1.356 raeburn 17708: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17709: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 17710: my $ruleok;
17711: if ($rule eq 'expire') {
1.365 raeburn 17712: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17713: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 17714: $ruleok = 1;
1.356 raeburn 17715: }
1.365 raeburn 17716: } elsif ($rule eq 'min') {
17717: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
17718: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
17719: $ruleok = 1;
17720: }
17721: }
17722: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
17723: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 17724: $ruleok = 1;
17725: }
17726: if ($ruleok) {
1.354 raeburn 17727: $newvalues{$rule} = $env{'form.passwords_'.$rule};
17728: if (exists($current{$rule})) {
17729: if ($newvalues{$rule} ne $current{$rule}) {
17730: $changes{'rules'} = 1;
17731: }
17732: } elsif ($rule eq 'min') {
17733: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
17734: $changes{'rules'} = 1;
17735: }
1.370 raeburn 17736: } else {
17737: $changes{'rules'} = 1;
1.354 raeburn 17738: }
17739: } elsif (exists($current{$rule})) {
17740: $changes{'rules'} = 1;
17741: }
17742: }
17743: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
17744: my @chars;
17745: foreach my $item (sort(@posschars)) {
17746: if ($item =~ /^(uc|lc|num|spec)$/) {
17747: push(@chars,$item);
17748: }
17749: }
17750: $newvalues{'chars'} = \@chars;
17751: unless ($changes{'rules'}) {
17752: if (ref($current{'chars'}) eq 'ARRAY') {
17753: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
17754: if (@diffs > 0) {
17755: $changes{'rules'} = 1;
17756: }
17757: } else {
17758: if (@chars > 0) {
17759: $changes{'rules'} = 1;
17760: }
17761: }
17762: }
1.359 raeburn 17763: my %crsownerchg = (
17764: by => [],
17765: for => [],
17766: );
17767: foreach my $item ('by','for') {
17768: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17769: foreach my $type (sort(@posstypes)) {
17770: if (grep(/^\Q$type\E$/,@oktypes)) {
17771: push(@{$crsownerchg{$item}},$type);
17772: }
17773: }
17774: }
17775: $newvalues{'crsownerchg'} = \%crsownerchg;
17776: if (ref($current{'crsownerchg'}) eq 'HASH') {
17777: foreach my $item ('by','for') {
17778: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17779: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17780: if (@diffs > 0) {
17781: $changes{'crsownerchg'} = 1;
17782: last;
17783: }
17784: }
17785: }
1.368 raeburn 17786: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17787: foreach my $item ('by','for') {
17788: if (@{$crsownerchg{$item}} > 0) {
17789: $changes{'crsownerchg'} = 1;
17790: last;
17791: }
1.354 raeburn 17792: }
17793: }
17794:
17795: my %confighash = (
17796: defaults => \%save_defaults,
17797: passwords => \%newvalues,
17798: );
17799: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17800:
17801: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17802: if ($putresult eq 'ok') {
17803: if (keys(%changes) > 0) {
17804: $resulttext = &mt('Changes made: ').'<ul>';
17805: foreach my $key ('reset','intauth','rules','crsownerchg') {
17806: if ($changes{$key}) {
1.355 raeburn 17807: unless ($key eq 'intauth') {
17808: $updateconf = 1;
17809: }
1.354 raeburn 17810: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17811: if ($key eq 'reset') {
17812: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17813: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17814: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17815: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17816: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17817: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17818: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17819: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17820: }
1.354 raeburn 17821: } else {
17822: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17823: }
17824: if ($confighash{'passwords'}{'resetlink'}) {
17825: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17826: } else {
17827: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17828: &mt('Will default to 2 hours').'</li>';
17829: }
17830: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17831: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17832: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17833: } else {
17834: my $casesens;
17835: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17836: if ($type eq 'default') {
17837: $casesens .= $othertitle.', ';
17838: } elsif ($usertypes->{$type} ne '') {
17839: $casesens .= $usertypes->{$type}.', ';
17840: }
17841: }
17842: $casesens =~ s/\Q, \E$//;
17843: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17844: }
17845: } else {
17846: $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>';
17847: }
17848: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17849: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17850: } else {
17851: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17852: }
17853: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17854: my $output;
17855: if (ref($types) eq 'ARRAY') {
17856: foreach my $type (@{$types}) {
17857: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17858: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17859: $output .= $usertypes->{$type}.' -- '.&mt('none');
17860: } else {
17861: $output .= $usertypes->{$type}.' -- '.
17862: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17863: }
17864: }
17865: }
17866: }
17867: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17868: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17869: $output .= $othertitle.' -- '.&mt('none');
17870: } else {
17871: $output .= $othertitle.' -- '.
17872: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17873: }
17874: }
17875: if ($output) {
17876: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17877: } else {
17878: $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>';
17879: }
17880: } else {
17881: $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>';
17882: }
17883: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17884: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17885: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17886: } else {
17887: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17888: }
17889: } else {
1.379 raeburn 17890: $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 17891: }
17892: if ($confighash{'passwords'}{'resetremove'}) {
17893: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17894: } else {
17895: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17896: }
17897: if ($confighash{'passwords'}{'resetcustom'}) {
17898: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17899: &mt('custom text'),600,500,undef,undef,
17900: undef,undef,'background-color:#ffffff');
17901: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17902: } else {
17903: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17904: }
17905: } elsif ($key eq 'intauth') {
17906: foreach my $item ('cost','switch','check') {
17907: my $value = $save_defaults{$key.'_'.$item};
17908: if ($item eq 'switch') {
17909: my %optiondesc = &Apache::lonlocal::texthash (
17910: 0 => 'No',
17911: 1 => 'Yes',
17912: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17913: );
17914: if ($value =~ /^(0|1|2)$/) {
17915: $value = $optiondesc{$value};
17916: } else {
17917: $value = &mt('none -- defaults to No');
17918: }
17919: } elsif ($item eq 'check') {
17920: my %optiondesc = &Apache::lonlocal::texthash (
17921: 0 => 'No',
17922: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17923: 2 => 'Yes, disallow login if stored cost is less than domain default',
17924: );
17925: if ($value =~ /^(0|1|2)$/) {
17926: $value = $optiondesc{$value};
17927: } else {
17928: $value = &mt('none -- defaults to No');
17929: }
17930: }
17931: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17932: }
17933: } elsif ($key eq 'rules') {
1.356 raeburn 17934: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17935: if ($confighash{'passwords'}{$rule} eq '') {
17936: if ($rule eq 'min') {
1.356 raeburn 17937: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17938: ' '.&mt('Default of [_1] will be used',
17939: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17940: } else {
17941: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17942: }
17943: } else {
17944: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17945: }
17946: }
1.370 raeburn 17947: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17948: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17949: my %rulenames = &Apache::lonlocal::texthash(
17950: uc => 'At least one upper case letter',
17951: lc => 'At least one lower case letter',
17952: num => 'At least one number',
17953: spec => 'At least one non-alphanumeric',
17954: );
17955: my $needed = '<ul><li>'.
17956: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17957: '</li></ul>';
17958: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17959: } else {
17960: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17961: }
17962: } else {
17963: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17964: }
1.354 raeburn 17965: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17966: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17967: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17968: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17969: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17970: } else {
17971: my %crsownerstr;
17972: foreach my $item ('by','for') {
17973: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17974: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17975: if ($type eq 'default') {
17976: $crsownerstr{$item} .= $othertitle.', ';
17977: } elsif ($usertypes->{$type} ne '') {
17978: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17979: }
17980: }
17981: $crsownerstr{$item} =~ s/\Q, \E$//;
17982: }
17983: }
17984: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17985: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17986: }
1.354 raeburn 17987: } else {
1.359 raeburn 17988: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17989: }
17990: }
17991: $resulttext .= '</ul></li>';
17992: }
17993: }
17994: $resulttext .= '</ul>';
17995: } else {
17996: $resulttext = &mt('No changes made to password settings');
17997: }
1.355 raeburn 17998: my $cachetime = 24*60*60;
1.354 raeburn 17999: if ($updatedefaults) {
18000: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18001: if (ref($lastactref) eq 'HASH') {
18002: $lastactref->{'domdefaults'} = 1;
18003: }
18004: }
1.355 raeburn 18005: if ($updateconf) {
18006: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18007: if (ref($lastactref) eq 'HASH') {
18008: $lastactref->{'passwdconf'} = 1;
18009: }
18010: }
1.354 raeburn 18011: } else {
18012: $resulttext = '<span class="LC_error">'.
18013: &mt('An error occurred: [_1]',$putresult).'</span>';
18014: }
18015: if ($errors) {
18016: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18017: $errors.'</ul></p>';
18018: }
18019: return $resulttext;
18020: }
18021:
1.28 raeburn 18022: sub modify_usercreation {
1.27 raeburn 18023: my ($dom,%domconfig) = @_;
1.224 raeburn 18024: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18025: my $warningmsg;
1.27 raeburn 18026: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18027: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18028: if ($key eq 'cancreate') {
18029: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18030: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18031: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18032: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18033: } else {
1.224 raeburn 18034: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18035: }
18036: }
18037: }
18038: } elsif ($key eq 'email_rule') {
18039: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18040: } else {
18041: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18042: }
1.27 raeburn 18043: }
18044: }
18045: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18046: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18047: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18048: foreach my $item(@contexts) {
1.224 raeburn 18049: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18050: }
1.34 raeburn 18051: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18052: foreach my $item (@contexts) {
1.224 raeburn 18053: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18054: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18055: }
1.27 raeburn 18056: }
1.34 raeburn 18057: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18058: foreach my $item (@contexts) {
1.43 raeburn 18059: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18060: if ($cancreate{$item} ne 'any') {
18061: push(@{$changes{'cancreate'}},$item);
18062: }
18063: } else {
18064: if ($cancreate{$item} ne 'none') {
18065: push(@{$changes{'cancreate'}},$item);
18066: }
1.27 raeburn 18067: }
18068: }
18069: } else {
1.43 raeburn 18070: foreach my $item (@contexts) {
1.34 raeburn 18071: push(@{$changes{'cancreate'}},$item);
18072: }
1.27 raeburn 18073: }
1.34 raeburn 18074:
1.27 raeburn 18075: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18076: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18077: if (!grep(/^\Q$type\E$/,@username_rule)) {
18078: push(@{$changes{'username_rule'}},$type);
18079: }
18080: }
18081: foreach my $type (@username_rule) {
18082: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18083: push(@{$changes{'username_rule'}},$type);
18084: }
18085: }
18086: } else {
18087: push(@{$changes{'username_rule'}},@username_rule);
18088: }
18089:
1.32 raeburn 18090: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18091: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18092: if (!grep(/^\Q$type\E$/,@id_rule)) {
18093: push(@{$changes{'id_rule'}},$type);
18094: }
18095: }
18096: foreach my $type (@id_rule) {
18097: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18098: push(@{$changes{'id_rule'}},$type);
18099: }
18100: }
18101: } else {
18102: push(@{$changes{'id_rule'}},@id_rule);
18103: }
18104:
1.43 raeburn 18105: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18106: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18107: my %authhash;
1.43 raeburn 18108: foreach my $item (@authen_contexts) {
1.28 raeburn 18109: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18110: foreach my $auth (@authtypes) {
18111: if (grep(/^\Q$auth\E$/,@authallowed)) {
18112: $authhash{$item}{$auth} = 1;
18113: } else {
18114: $authhash{$item}{$auth} = 0;
18115: }
18116: }
18117: }
18118: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18119: foreach my $item (@authen_contexts) {
1.28 raeburn 18120: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18121: foreach my $auth (@authtypes) {
18122: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18123: push(@{$changes{'authtypes'}},$item);
18124: last;
18125: }
18126: }
18127: }
18128: }
18129: } else {
1.43 raeburn 18130: foreach my $item (@authen_contexts) {
1.28 raeburn 18131: push(@{$changes{'authtypes'}},$item);
18132: }
18133: }
18134:
1.224 raeburn 18135: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18136: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18137: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18138: $save_usercreate{'id_rule'} = \@id_rule;
18139: $save_usercreate{'username_rule'} = \@username_rule,
18140: $save_usercreate{'authtypes'} = \%authhash;
18141:
1.27 raeburn 18142: my %usercreation_hash = (
1.224 raeburn 18143: usercreation => \%save_usercreate,
18144: );
1.27 raeburn 18145:
18146: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18147: $dom);
1.50 raeburn 18148:
1.224 raeburn 18149: if ($putresult eq 'ok') {
18150: if (keys(%changes) > 0) {
18151: $resulttext = &mt('Changes made:').'<ul>';
18152: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18153: my %lt = &usercreation_types();
18154: foreach my $type (@{$changes{'cancreate'}}) {
18155: my $chgtext = $lt{$type}.', ';
18156: if ($cancreate{$type} eq 'none') {
18157: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18158: } elsif ($cancreate{$type} eq 'any') {
18159: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18160: } elsif ($cancreate{$type} eq 'official') {
18161: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18162: } elsif ($cancreate{$type} eq 'unofficial') {
18163: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18164: }
18165: $resulttext .= '<li>'.$chgtext.'</li>';
18166: }
18167: }
18168: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18169: my ($rules,$ruleorder) =
18170: &Apache::lonnet::inst_userrules($dom,'username');
18171: my $chgtext = '<ul>';
18172: foreach my $type (@username_rule) {
18173: if (ref($rules->{$type}) eq 'HASH') {
18174: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18175: }
18176: }
18177: $chgtext .= '</ul>';
18178: if (@username_rule > 0) {
18179: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18180: } else {
18181: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18182: }
18183: }
18184: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18185: my ($idrules,$idruleorder) =
18186: &Apache::lonnet::inst_userrules($dom,'id');
18187: my $chgtext = '<ul>';
18188: foreach my $type (@id_rule) {
18189: if (ref($idrules->{$type}) eq 'HASH') {
18190: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18191: }
18192: }
18193: $chgtext .= '</ul>';
18194: if (@id_rule > 0) {
18195: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18196: } else {
18197: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18198: }
18199: }
18200: my %authname = &authtype_names();
18201: my %context_title = &context_names();
18202: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18203: my $chgtext = '<ul>';
18204: foreach my $type (@{$changes{'authtypes'}}) {
18205: my @allowed;
18206: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18207: foreach my $auth (@authtypes) {
18208: if ($authhash{$type}{$auth}) {
18209: push(@allowed,$authname{$auth});
18210: }
18211: }
18212: if (@allowed > 0) {
18213: $chgtext .= join(', ',@allowed).'</li>';
18214: } else {
18215: $chgtext .= &mt('none').'</li>';
18216: }
18217: }
18218: $chgtext .= '</ul>';
18219: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18220: $resulttext .= '</li>';
18221: }
18222: $resulttext .= '</ul>';
18223: } else {
18224: $resulttext = &mt('No changes made to user creation settings');
18225: }
18226: } else {
18227: $resulttext = '<span class="LC_error">'.
18228: &mt('An error occurred: [_1]',$putresult).'</span>';
18229: }
18230: if ($warningmsg ne '') {
18231: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18232: }
18233: return $resulttext;
18234: }
18235:
18236: sub modify_selfcreation {
1.305 raeburn 18237: my ($dom,$lastactref,%domconfig) = @_;
18238: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18239: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18240: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18241: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18242: if (ref($typesref) eq 'ARRAY') {
18243: @types = @{$typesref};
18244: }
18245: if (ref($usertypesref) eq 'HASH') {
18246: %usertypes = %{$usertypesref};
1.228 raeburn 18247: }
1.303 raeburn 18248: $usertypes{'default'} = $othertitle;
1.224 raeburn 18249: #
18250: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18251: #
18252: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18253: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18254: if ($key eq 'cancreate') {
18255: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18256: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18257: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18258: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18259: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18260: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18261: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18262: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18263: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18264: } else {
18265: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18266: }
18267: }
18268: }
18269: } elsif ($key eq 'email_rule') {
18270: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18271: } else {
18272: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18273: }
18274: }
18275: }
18276: #
18277: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18278: #
18279: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18280: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18281: if ($key eq 'selfcreate') {
18282: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18283: } else {
18284: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18285: }
18286: }
18287: }
1.305 raeburn 18288: #
18289: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18290: #
18291: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18292: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18293: if ($key eq 'inststatusguest') {
18294: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18295: } else {
18296: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18297: }
18298: }
18299: }
1.224 raeburn 18300:
18301: my @contexts = ('selfcreate');
18302: @{$cancreate{'selfcreate'}} = ();
18303: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18304: if (@types) {
18305: @{$cancreate{'statustocreate'}} = ();
18306: }
1.236 raeburn 18307: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18308: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18309: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18310: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18311: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18312: my %selfcreatetypes = (
18313: sso => 'users authenticated by institutional single sign on',
18314: login => 'users authenticated by institutional log-in',
1.303 raeburn 18315: email => 'users verified by e-mail',
1.50 raeburn 18316: );
1.224 raeburn 18317: #
18318: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18319: # is permitted.
18320: #
1.305 raeburn 18321: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18322:
1.305 raeburn 18323: my (@statuses,%email_rule);
1.228 raeburn 18324: foreach my $item ('login','sso','email') {
1.224 raeburn 18325: if ($item eq 'email') {
1.236 raeburn 18326: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18327: if (@types) {
18328: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18329: foreach my $status (@poss_statuses) {
18330: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18331: push(@statuses,$status);
18332: }
18333: }
18334: $save_inststatus{'inststatusguest'} = \@statuses;
18335: } else {
18336: push(@statuses,'default');
18337: }
18338: if (@statuses) {
18339: my %curr_rule;
18340: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18341: foreach my $type (@statuses) {
18342: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18343: }
1.305 raeburn 18344: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18345: foreach my $type (@statuses) {
18346: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18347: }
18348: }
18349: push(@{$cancreate{'selfcreate'}},'email');
18350: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18351: my %curremaildom;
18352: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18353: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18354: }
18355: foreach my $type (@statuses) {
18356: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18357: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18358: }
18359: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18360: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18361: }
18362: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18363: #
18364: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18365: #
18366: my $chosen = $1;
18367: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18368: my $emaildom;
18369: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
18370: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
18371: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18372: if (ref($curremaildom{$type}) eq 'HASH') {
18373: if (exists($curremaildom{$type}{$chosen})) {
18374: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18375: push(@{$changes{'cancreate'}},'emaildomain');
18376: }
18377: } elsif ($emaildom ne '') {
18378: push(@{$changes{'cancreate'}},'emaildomain');
18379: }
18380: } elsif ($emaildom ne '') {
18381: push(@{$changes{'cancreate'}},'emaildomain');
18382: }
18383: }
18384: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18385: } elsif ($chosen eq 'custom') {
18386: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18387: $email_rule{$type} = [];
18388: if (ref($emailrules) eq 'HASH') {
18389: foreach my $rule (@possemail_rules) {
18390: if (exists($emailrules->{$rule})) {
18391: push(@{$email_rule{$type}},$rule);
18392: }
18393: }
18394: }
18395: if (@{$email_rule{$type}}) {
18396: $cancreate{'emailoptions'}{$type} = 'custom';
18397: if (ref($curr_rule{$type}) eq 'ARRAY') {
18398: if (@{$curr_rule{$type}} > 0) {
18399: foreach my $rule (@{$curr_rule{$type}}) {
18400: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18401: push(@{$changes{'email_rule'}},$type);
18402: }
18403: }
18404: }
18405: foreach my $type (@{$email_rule{$type}}) {
18406: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18407: push(@{$changes{'email_rule'}},$type);
18408: }
18409: }
18410: } else {
18411: push(@{$changes{'email_rule'}},$type);
18412: }
18413: }
18414: } else {
18415: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18416: }
18417: }
18418: }
18419: if (@types) {
18420: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18421: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18422: if (@changed) {
18423: push(@{$changes{'inststatus'}},'inststatusguest');
18424: }
18425: } else {
18426: push(@{$changes{'inststatus'}},'inststatusguest');
18427: }
18428: }
18429: } else {
18430: delete($env{'form.cancreate_email'});
18431: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18432: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18433: push(@{$changes{'inststatus'}},'inststatusguest');
18434: }
18435: }
18436: }
18437: } else {
18438: $save_inststatus{'inststatusguest'} = [];
18439: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18440: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18441: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18442: }
18443: }
1.224 raeburn 18444: }
18445: } else {
18446: if ($env{'form.cancreate_'.$item}) {
18447: push(@{$cancreate{'selfcreate'}},$item);
18448: }
18449: }
18450: }
1.305 raeburn 18451: my (%userinfo,%savecaptcha);
1.224 raeburn 18452: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18453: #
1.228 raeburn 18454: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18455: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18456: #
1.236 raeburn 18457:
1.244 raeburn 18458: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18459: push(@contexts,'emailusername');
1.305 raeburn 18460: if (@statuses) {
18461: foreach my $type (@statuses) {
1.228 raeburn 18462: if (ref($infofields) eq 'ARRAY') {
18463: foreach my $field (@{$infofields}) {
18464: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18465: $cancreate{'emailusername'}{$type}{$field} = $1;
18466: }
18467: }
1.224 raeburn 18468: }
18469: }
18470: }
18471: #
18472: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18473: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18474: #
18475:
18476: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18477: @approvalnotify = sort(@approvalnotify);
18478: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18479: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18480: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18481: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18482: push(@{$changes{'cancreate'}},'notify');
18483: }
18484: } else {
18485: if ($cancreate{'notify'}{'approval'}) {
18486: push(@{$changes{'cancreate'}},'notify');
18487: }
18488: }
18489: } elsif ($cancreate{'notify'}{'approval'}) {
18490: push(@{$changes{'cancreate'}},'notify');
18491: }
18492:
18493: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18494: }
18495: #
1.236 raeburn 18496: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18497: # institutional log-in.
18498: #
18499: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18500: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18501: ($domdefaults{'auth_def'} eq 'localauth'))) {
18502: $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.').' '.
18503: &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.');
18504: }
18505: }
18506: my @fields = ('lastname','firstname','middlename','generation',
18507: 'permanentemail','id');
1.240 raeburn 18508: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18509: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18510: #
18511: # Where usernames may created for institutional log-in and/or institutional single sign on:
18512: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18513: # may self-create accounts
18514: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18515: # which the user may supply, if institutional data is unavailable.
18516: #
18517: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18518: if (@types) {
1.305 raeburn 18519: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18520: push(@contexts,'statustocreate');
1.303 raeburn 18521: foreach my $type (@types) {
1.224 raeburn 18522: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18523: foreach my $field (@fields) {
18524: if (grep(/^\Q$field\E$/,@modifiable)) {
18525: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18526: } else {
18527: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18528: }
18529: }
18530: }
18531: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18532: foreach my $type (@types) {
1.224 raeburn 18533: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18534: foreach my $field (@fields) {
18535: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18536: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18537: push(@{$changes{'selfcreate'}},$type);
18538: last;
18539: }
18540: }
18541: }
18542: }
18543: } else {
1.303 raeburn 18544: foreach my $type (@types) {
1.224 raeburn 18545: push(@{$changes{'selfcreate'}},$type);
18546: }
18547: }
18548: }
1.240 raeburn 18549: foreach my $field (@shibfields) {
18550: if ($env{'form.shibenv_'.$field} ne '') {
18551: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18552: }
18553: }
18554: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18555: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18556: foreach my $field (@shibfields) {
18557: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18558: push(@{$changes{'cancreate'}},'shibenv');
18559: }
18560: }
18561: } else {
18562: foreach my $field (@shibfields) {
18563: if ($env{'form.shibenv_'.$field}) {
18564: push(@{$changes{'cancreate'}},'shibenv');
18565: last;
18566: }
18567: }
18568: }
18569: }
1.224 raeburn 18570: }
18571: foreach my $item (@contexts) {
18572: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18573: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18574: if (ref($cancreate{$item}) eq 'ARRAY') {
18575: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18576: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18577: push(@{$changes{'cancreate'}},$item);
18578: }
18579: }
18580: }
18581: }
18582: if (ref($cancreate{$item}) eq 'ARRAY') {
18583: foreach my $type (@{$cancreate{$item}}) {
18584: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18585: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18586: push(@{$changes{'cancreate'}},$item);
18587: }
18588: }
18589: }
18590: }
18591: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
18592: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 18593: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
18594: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18595: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
18596: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18597: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18598: push(@{$changes{'cancreate'}},$item);
18599: }
18600: }
18601: }
1.305 raeburn 18602: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18603: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18604: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18605: push(@{$changes{'cancreate'}},$item);
18606: }
1.224 raeburn 18607: }
18608: }
18609: }
1.305 raeburn 18610: foreach my $type (keys(%{$cancreate{$item}})) {
18611: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18612: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18613: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18614: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18615: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18616: push(@{$changes{'cancreate'}},$item);
18617: }
18618: }
18619: } else {
18620: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18621: push(@{$changes{'cancreate'}},$item);
18622: }
18623: }
18624: }
1.305 raeburn 18625: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18626: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18627: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18628: push(@{$changes{'cancreate'}},$item);
18629: }
1.224 raeburn 18630: }
18631: }
18632: }
18633: }
18634: } elsif ($curr_usercreation{'cancreate'}{$item}) {
18635: if (ref($cancreate{$item}) eq 'ARRAY') {
18636: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
18637: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18638: push(@{$changes{'cancreate'}},$item);
18639: }
18640: }
1.305 raeburn 18641: }
18642: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18643: if (ref($cancreate{$item}) eq 'HASH') {
18644: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18645: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 18646: }
18647: }
18648: } elsif ($item eq 'emailusername') {
1.228 raeburn 18649: if (ref($cancreate{$item}) eq 'HASH') {
18650: foreach my $type (keys(%{$cancreate{$item}})) {
18651: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18652: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18653: if ($cancreate{$item}{$type}{$field}) {
18654: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18655: push(@{$changes{'cancreate'}},$item);
18656: }
18657: last;
18658: }
18659: }
18660: }
18661: }
1.224 raeburn 18662: }
18663: }
18664: }
18665: #
18666: # Populate %save_usercreate hash with updates to self-creation configuration.
18667: #
18668: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
18669: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 18670: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 18671: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
18672: if (ref($cancreate{'notify'}) eq 'HASH') {
18673: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
18674: }
1.236 raeburn 18675: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
18676: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
18677: }
1.303 raeburn 18678: if (ref($cancreate{'emailverified'}) eq 'HASH') {
18679: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
18680: }
1.305 raeburn 18681: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
18682: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
18683: }
1.303 raeburn 18684: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
18685: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
18686: }
1.224 raeburn 18687: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18688: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
18689: }
1.240 raeburn 18690: if (ref($cancreate{'shibenv'}) eq 'HASH') {
18691: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18692: }
1.224 raeburn 18693: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18694: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18695:
18696: my %userconfig_hash = (
18697: usercreation => \%save_usercreate,
18698: usermodification => \%save_usermodify,
1.305 raeburn 18699: inststatus => \%save_inststatus,
1.224 raeburn 18700: );
1.305 raeburn 18701:
1.224 raeburn 18702: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18703: $dom);
18704: #
1.305 raeburn 18705: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18706: #
1.27 raeburn 18707: if ($putresult eq 'ok') {
18708: if (keys(%changes) > 0) {
18709: $resulttext = &mt('Changes made:').'<ul>';
18710: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18711: my %lt = &selfcreation_types();
1.34 raeburn 18712: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18713: my $chgtext = '';
1.45 raeburn 18714: if ($type eq 'selfcreate') {
1.50 raeburn 18715: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18716: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18717: } else {
1.224 raeburn 18718: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18719: '<ul>';
1.50 raeburn 18720: foreach my $case (@{$cancreate{$type}}) {
18721: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18722: }
18723: $chgtext .= '</ul>';
1.100 raeburn 18724: if (ref($cancreate{$type}) eq 'ARRAY') {
18725: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18726: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18727: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18728: $chgtext .= '<span class="LC_warning">'.
18729: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18730: '</span><br />';
18731: }
18732: }
18733: }
18734: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18735: if (!@statuses) {
18736: $chgtext .= '<span class="LC_warning">'.
18737: &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.").
18738: '</span><br />';
1.303 raeburn 18739:
1.100 raeburn 18740: }
18741: }
18742: }
1.43 raeburn 18743: }
1.240 raeburn 18744: } elsif ($type eq 'shibenv') {
18745: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18746: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18747: } else {
18748: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18749: '<ul>';
18750: foreach my $field (@shibfields) {
18751: next if ($cancreate{$type}{$field} eq '');
18752: if ($field eq 'inststatus') {
18753: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18754: } else {
18755: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18756: }
18757: }
18758: $chgtext .= '</ul>';
1.303 raeburn 18759: }
1.93 raeburn 18760: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18761: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18762: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18763: if (@{$cancreate{'selfcreate'}} > 0) {
18764: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18765: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18766: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18767: $chgtext .= '<br />'.
18768: '<span class="LC_warning">'.
18769: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18770: '</span>';
18771: }
1.303 raeburn 18772: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18773: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18774: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18775: } else {
18776: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18777: }
18778: $chgtext .= '<ul>';
18779: foreach my $case (@{$cancreate{$type}}) {
18780: if ($case eq 'default') {
18781: $chgtext .= '<li>'.$othertitle.'</li>';
18782: } else {
1.303 raeburn 18783: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18784: }
18785: }
1.100 raeburn 18786: $chgtext .= '</ul>';
18787: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18788: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18789: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18790: '</span>';
1.100 raeburn 18791: }
18792: }
18793: } else {
18794: if (@{$cancreate{$type}} == 0) {
18795: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18796: } else {
18797: $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 18798: }
18799: }
1.303 raeburn 18800: $chgtext .= '<br />';
1.93 raeburn 18801: }
1.236 raeburn 18802: } elsif ($type eq 'selfcreateprocessing') {
18803: my %choices = &Apache::lonlocal::texthash (
18804: automatic => 'Automatic approval',
18805: approval => 'Queued for approval',
18806: );
1.305 raeburn 18807: if (@types) {
18808: if (@statuses) {
1.303 raeburn 18809: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18810: '<ul>';
1.305 raeburn 18811: foreach my $status (@statuses) {
18812: if ($status eq 'default') {
18813: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18814: } else {
1.305 raeburn 18815: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18816: }
18817: }
18818: $chgtext .= '</ul>';
18819: }
18820: } else {
18821: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18822: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18823: }
18824: } elsif ($type eq 'emailverified') {
18825: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18826: all => 'Same as e-mail',
18827: first => 'Omit @domain',
18828: free => 'Free to choose',
1.303 raeburn 18829: );
1.305 raeburn 18830: if (@types) {
18831: if (@statuses) {
1.303 raeburn 18832: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18833: '<ul>';
1.305 raeburn 18834: foreach my $status (@statuses) {
1.362 raeburn 18835: if ($status eq 'default') {
1.305 raeburn 18836: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18837: } else {
1.305 raeburn 18838: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18839: }
18840: }
18841: $chgtext .= '</ul>';
18842: }
18843: } else {
1.305 raeburn 18844: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18845: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18846: }
1.305 raeburn 18847: } elsif ($type eq 'emailoptions') {
18848: my %options = &Apache::lonlocal::texthash (
18849: any => 'Any e-mail',
18850: inst => 'Institutional only',
18851: noninst => 'Non-institutional only',
18852: custom => 'Custom restrictions',
18853: );
18854: if (@types) {
18855: if (@statuses) {
18856: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18857: '<ul>';
18858: foreach my $status (@statuses) {
18859: if ($type eq 'default') {
18860: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18861: } else {
18862: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18863: }
18864: }
1.305 raeburn 18865: $chgtext .= '</ul>';
18866: }
18867: } else {
18868: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18869: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18870: } else {
18871: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18872: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18873: }
1.305 raeburn 18874: }
18875: } elsif ($type eq 'emaildomain') {
18876: my $output;
18877: if (@statuses) {
18878: foreach my $type (@statuses) {
18879: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18880: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18881: if ($type eq 'default') {
18882: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18883: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18884: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18885: } else {
18886: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18887: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18888: }
1.303 raeburn 18889: } else {
1.305 raeburn 18890: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18891: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18892: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18893: } else {
18894: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18895: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18896: }
1.303 raeburn 18897: }
1.305 raeburn 18898: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18899: if ($type eq 'default') {
18900: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18901: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18902: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18903: } else {
18904: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18905: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18906: }
1.303 raeburn 18907: } else {
1.305 raeburn 18908: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18909: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18910: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18911: } else {
18912: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18913: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18914: }
1.303 raeburn 18915: }
18916: }
18917: }
18918: }
1.305 raeburn 18919: }
18920: if ($output ne '') {
18921: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18922: '<ul>'.$output.'</ul>';
1.236 raeburn 18923: }
1.165 raeburn 18924: } elsif ($type eq 'captcha') {
1.224 raeburn 18925: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18926: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18927: } else {
18928: my %captchas = &captcha_phrases();
1.224 raeburn 18929: if ($captchas{$savecaptcha{$type}}) {
18930: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18931: } else {
1.210 raeburn 18932: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18933: }
18934: }
18935: } elsif ($type eq 'recaptchakeys') {
18936: my ($privkey,$pubkey);
1.224 raeburn 18937: if (ref($savecaptcha{$type}) eq 'HASH') {
18938: $pubkey = $savecaptcha{$type}{'public'};
18939: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18940: }
18941: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18942: if (!$pubkey) {
18943: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18944: } else {
18945: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18946: }
18947: if (!$privkey) {
18948: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18949: } else {
18950: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18951: }
18952: $chgtext .= '</ul>';
1.269 raeburn 18953: } elsif ($type eq 'recaptchaversion') {
18954: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18955: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18956: }
1.224 raeburn 18957: } elsif ($type eq 'emailusername') {
18958: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18959: if (@statuses) {
18960: foreach my $type (@statuses) {
1.228 raeburn 18961: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18962: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18963: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18964: '<ul>';
18965: foreach my $field (@{$infofields}) {
18966: if ($cancreate{'emailusername'}{$type}{$field}) {
18967: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18968: }
18969: }
1.245 raeburn 18970: $chgtext .= '</ul>';
18971: } else {
1.303 raeburn 18972: $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 18973: }
18974: } else {
1.303 raeburn 18975: $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 18976: }
18977: }
18978: }
18979: }
18980: } elsif ($type eq 'notify') {
1.303 raeburn 18981: my $numapprove = 0;
1.224 raeburn 18982: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18983: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18984: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18985: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18986: $numapprove ++;
1.224 raeburn 18987: }
18988: }
1.43 raeburn 18989: }
1.303 raeburn 18990: unless ($numapprove) {
18991: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18992: }
1.34 raeburn 18993: }
1.224 raeburn 18994: if ($chgtext) {
18995: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18996: }
18997: }
18998: }
1.305 raeburn 18999: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19000: my ($emailrules,$emailruleorder) =
19001: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19002: foreach my $type (@{$changes{'email_rule'}}) {
19003: if (ref($email_rule{$type}) eq 'ARRAY') {
19004: my $chgtext = '<ul>';
19005: foreach my $rule (@{$email_rule{$type}}) {
19006: if (ref($emailrules->{$rule}) eq 'HASH') {
19007: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19008: }
19009: }
19010: $chgtext .= '</ul>';
1.310 raeburn 19011: my $typename;
1.305 raeburn 19012: if (@types) {
19013: if ($type eq 'default') {
19014: $typename = $othertitle;
19015: } else {
19016: $typename = $usertypes{$type};
19017: }
19018: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19019: }
19020: if (@{$email_rule{$type}} > 0) {
19021: $resulttext .= '<li>'.
19022: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19023: $usertypes{$type}).
19024: $chgtext.
19025: '</li>';
19026: } else {
19027: $resulttext .= '<li>'.
1.310 raeburn 19028: &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 19029: '</li>'.
1.310 raeburn 19030: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19031: }
1.43 raeburn 19032: }
19033: }
1.305 raeburn 19034: }
19035: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19036: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19037: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19038: my $chgtext = '<ul>';
19039: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19040: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19041: }
19042: $chgtext .= '</ul>';
19043: $resulttext .= '<li>'.
19044: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19045: $chgtext.
19046: '</li>';
19047: } else {
19048: $resulttext .= '<li>'.
19049: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19050: '</li>';
19051: }
1.43 raeburn 19052: }
19053: }
1.224 raeburn 19054: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19055: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19056: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19057: foreach my $type (@{$changes{'selfcreate'}}) {
19058: my $typename = $type;
1.303 raeburn 19059: if (keys(%usertypes) > 0) {
19060: if ($usertypes{$type} ne '') {
19061: $typename = $usertypes{$type};
1.224 raeburn 19062: }
19063: }
19064: my @modifiable;
19065: $resulttext .= '<li>'.
19066: &mt('Self-creation of account by users with status: [_1]',
19067: '<span class="LC_cusr_emph">'.$typename.'</span>').
19068: ' - '.&mt('modifiable fields (if institutional data blank): ');
19069: foreach my $field (@fields) {
19070: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19071: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19072: }
19073: }
1.224 raeburn 19074: if (@modifiable > 0) {
19075: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19076: } else {
1.224 raeburn 19077: $resulttext .= &mt('none');
1.43 raeburn 19078: }
1.224 raeburn 19079: $resulttext .= '</li>';
1.28 raeburn 19080: }
1.224 raeburn 19081: $resulttext .= '</ul></li>';
1.28 raeburn 19082: }
1.27 raeburn 19083: $resulttext .= '</ul>';
1.305 raeburn 19084: my $cachetime = 24*60*60;
19085: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19086: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19087: if (ref($lastactref) eq 'HASH') {
19088: $lastactref->{'domdefaults'} = 1;
19089: }
1.27 raeburn 19090: } else {
1.224 raeburn 19091: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19092: }
19093: } else {
19094: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19095: &mt('An error occurred: [_1]',$putresult).'</span>';
19096: }
1.43 raeburn 19097: if ($warningmsg ne '') {
19098: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19099: }
1.23 raeburn 19100: return $resulttext;
19101: }
19102:
1.165 raeburn 19103: sub process_captcha {
1.369 raeburn 19104: my ($container,$changes,$newsettings,$currsettings) = @_;
19105: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19106: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19107: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19108: $newsettings->{'captcha'} = 'original';
19109: }
1.369 raeburn 19110: my %current;
19111: if (ref($currsettings) eq 'HASH') {
19112: %current = %{$currsettings};
19113: }
19114: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19115: if ($container eq 'cancreate') {
1.169 raeburn 19116: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19117: push(@{$changes->{'cancreate'}},'captcha');
19118: } elsif (!defined($changes->{'cancreate'})) {
19119: $changes->{'cancreate'} = ['captcha'];
19120: }
1.368 raeburn 19121: } elsif ($container eq 'passwords') {
19122: $changes->{'reset'} = 1;
1.169 raeburn 19123: } else {
19124: $changes->{'captcha'} = 1;
1.165 raeburn 19125: }
19126: }
1.269 raeburn 19127: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19128: if ($newsettings->{'captcha'} eq 'recaptcha') {
19129: $newpub = $env{'form.'.$container.'_recaptchapub'};
19130: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19131: $newpub =~ s/[^\w\-]//g;
19132: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19133: $newsettings->{'recaptchakeys'} = {
19134: public => $newpub,
19135: private => $newpriv,
19136: };
1.269 raeburn 19137: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19138: $newversion =~ s/\D//g;
19139: if ($newversion ne '2') {
19140: $newversion = 1;
19141: }
19142: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19143: }
1.369 raeburn 19144: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19145: $currpub = $current{'recaptchakeys'}{'public'};
19146: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19147: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19148: $newsettings->{'recaptchakeys'} = {
19149: public => '',
19150: private => '',
19151: }
19152: }
1.165 raeburn 19153: }
1.369 raeburn 19154: if ($current{'captcha'} eq 'recaptcha') {
19155: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19156: if ($currversion ne '2') {
19157: $currversion = 1;
19158: }
19159: }
19160: if ($currversion ne $newversion) {
19161: if ($container eq 'cancreate') {
19162: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19163: push(@{$changes->{'cancreate'}},'recaptchaversion');
19164: } elsif (!defined($changes->{'cancreate'})) {
19165: $changes->{'cancreate'} = ['recaptchaversion'];
19166: }
1.368 raeburn 19167: } elsif ($container eq 'passwords') {
19168: $changes->{'reset'} = 1;
1.269 raeburn 19169: } else {
19170: $changes->{'recaptchaversion'} = 1;
19171: }
19172: }
1.165 raeburn 19173: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19174: if ($container eq 'cancreate') {
19175: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19176: push(@{$changes->{'cancreate'}},'recaptchakeys');
19177: } elsif (!defined($changes->{'cancreate'})) {
19178: $changes->{'cancreate'} = ['recaptchakeys'];
19179: }
1.368 raeburn 19180: } elsif ($container eq 'passwords') {
19181: $changes->{'reset'} = 1;
1.169 raeburn 19182: } else {
1.210 raeburn 19183: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19184: }
19185: }
19186: return;
19187: }
19188:
1.33 raeburn 19189: sub modify_usermodification {
19190: my ($dom,%domconfig) = @_;
1.224 raeburn 19191: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19192: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19193: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19194: if ($key eq 'selfcreate') {
19195: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19196: } else {
19197: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19198: }
1.33 raeburn 19199: }
19200: }
1.224 raeburn 19201: my @contexts = ('author','course');
1.33 raeburn 19202: my %context_title = (
19203: author => 'In author context',
19204: course => 'In course context',
19205: );
19206: my @fields = ('lastname','firstname','middlename','generation',
19207: 'permanentemail','id');
19208: my %roles = (
19209: author => ['ca','aa'],
19210: course => ['st','ep','ta','in','cr'],
19211: );
19212: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19213: foreach my $context (@contexts) {
19214: foreach my $role (@{$roles{$context}}) {
19215: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19216: foreach my $item (@fields) {
19217: if (grep(/^\Q$item\E$/,@modifiable)) {
19218: $modifyhash{$context}{$role}{$item} = 1;
19219: } else {
19220: $modifyhash{$context}{$role}{$item} = 0;
19221: }
19222: }
19223: }
19224: if (ref($curr_usermodification{$context}) eq 'HASH') {
19225: foreach my $role (@{$roles{$context}}) {
19226: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19227: foreach my $field (@fields) {
19228: if ($modifyhash{$context}{$role}{$field} ne
19229: $curr_usermodification{$context}{$role}{$field}) {
19230: push(@{$changes{$context}},$role);
19231: last;
19232: }
19233: }
19234: }
19235: }
19236: } else {
19237: foreach my $context (@contexts) {
19238: foreach my $role (@{$roles{$context}}) {
19239: push(@{$changes{$context}},$role);
19240: }
19241: }
19242: }
19243: }
19244: my %usermodification_hash = (
19245: usermodification => \%modifyhash,
19246: );
19247: my $putresult = &Apache::lonnet::put_dom('configuration',
19248: \%usermodification_hash,$dom);
19249: if ($putresult eq 'ok') {
19250: if (keys(%changes) > 0) {
19251: $resulttext = &mt('Changes made: ').'<ul>';
19252: foreach my $context (@contexts) {
19253: if (ref($changes{$context}) eq 'ARRAY') {
19254: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19255: if (ref($changes{$context}) eq 'ARRAY') {
19256: foreach my $role (@{$changes{$context}}) {
19257: my $rolename;
1.224 raeburn 19258: if ($role eq 'cr') {
19259: $rolename = &mt('Custom');
1.33 raeburn 19260: } else {
1.224 raeburn 19261: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19262: }
19263: my @modifiable;
1.224 raeburn 19264: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19265: foreach my $field (@fields) {
19266: if ($modifyhash{$context}{$role}{$field}) {
19267: push(@modifiable,$fieldtitles{$field});
19268: }
19269: }
19270: if (@modifiable > 0) {
19271: $resulttext .= join(', ',@modifiable);
19272: } else {
19273: $resulttext .= &mt('none');
19274: }
19275: $resulttext .= '</li>';
19276: }
19277: $resulttext .= '</ul></li>';
19278: }
19279: }
19280: }
19281: $resulttext .= '</ul>';
19282: } else {
19283: $resulttext = &mt('No changes made to user modification settings');
19284: }
19285: } else {
19286: $resulttext = '<span class="LC_error">'.
19287: &mt('An error occurred: [_1]',$putresult).'</span>';
19288: }
19289: return $resulttext;
19290: }
19291:
1.43 raeburn 19292: sub modify_defaults {
1.212 raeburn 19293: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19294: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19295: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19296: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19297: 'portal_def');
1.325 raeburn 19298: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19299: foreach my $item (@items) {
19300: $newvalues{$item} = $env{'form.'.$item};
19301: if ($item eq 'auth_def') {
19302: if ($newvalues{$item} ne '') {
19303: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19304: push(@errors,$item);
19305: }
19306: }
19307: } elsif ($item eq 'lang_def') {
19308: if ($newvalues{$item} ne '') {
19309: if ($newvalues{$item} =~ /^(\w+)/) {
19310: my $langcode = $1;
1.103 raeburn 19311: if ($langcode ne 'x_chef') {
19312: if (code2language($langcode) eq '') {
19313: push(@errors,$item);
19314: }
1.43 raeburn 19315: }
19316: } else {
19317: push(@errors,$item);
19318: }
19319: }
1.54 raeburn 19320: } elsif ($item eq 'timezone_def') {
19321: if ($newvalues{$item} ne '') {
1.62 raeburn 19322: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19323: push(@errors,$item);
19324: }
19325: }
1.68 raeburn 19326: } elsif ($item eq 'datelocale_def') {
19327: if ($newvalues{$item} ne '') {
19328: my @datelocale_ids = DateTime::Locale->ids();
19329: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19330: push(@errors,$item);
19331: }
19332: }
1.141 raeburn 19333: } elsif ($item eq 'portal_def') {
19334: if ($newvalues{$item} ne '') {
19335: 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])\/?$/) {
19336: push(@errors,$item);
19337: }
19338: }
1.43 raeburn 19339: }
19340: if (grep(/^\Q$item\E$/,@errors)) {
19341: $newvalues{$item} = $domdefaults{$item};
19342: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19343: $changes{$item} = 1;
19344: }
1.72 raeburn 19345: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19346: }
1.354 raeburn 19347: my %staticdefaults = (
19348: 'intauth_cost' => 10,
19349: 'intauth_check' => 0,
19350: 'intauth_switch' => 0,
19351: );
19352: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19353: if (exists($domdefaults{$item})) {
19354: $newvalues{$item} = $domdefaults{$item};
19355: } else {
19356: $newvalues{$item} = $staticdefaults{$item};
19357: }
19358: }
1.43 raeburn 19359: my %defaults_hash = (
1.72 raeburn 19360: defaults => \%newvalues,
19361: );
1.43 raeburn 19362: my $title = &defaults_titles();
1.236 raeburn 19363:
19364: my $currinststatus;
19365: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19366: $currinststatus = $domconfig{'inststatus'};
19367: } else {
19368: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19369: $currinststatus = {
19370: inststatustypes => $usertypes,
19371: inststatusorder => $types,
19372: inststatusguest => [],
19373: };
19374: }
19375: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19376: my @allpos;
19377: my %alltypes;
1.305 raeburn 19378: my @inststatusguest;
19379: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19380: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19381: unless (grep(/^\Q$type\E$/,@todelete)) {
19382: push(@inststatusguest,$type);
19383: }
19384: }
19385: }
19386: my ($currtitles,$currorder);
1.236 raeburn 19387: if (ref($currinststatus) eq 'HASH') {
19388: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19389: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19390: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19391: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19392: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19393: }
19394: }
19395: unless (grep(/^\Q$type\E$/,@todelete)) {
19396: my $position = $env{'form.inststatus_pos_'.$type};
19397: $position =~ s/\D+//g;
19398: $allpos[$position] = $type;
19399: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19400: $alltypes{$type} =~ s/`//g;
19401: }
19402: }
19403: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19404: $currtitles =~ s/,$//;
19405: }
19406: }
19407: if ($env{'form.addinststatus'}) {
19408: my $newtype = $env{'form.addinststatus'};
19409: $newtype =~ s/\W//g;
19410: unless (exists($alltypes{$newtype})) {
19411: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19412: $alltypes{$newtype} =~ s/`//g;
19413: my $position = $env{'form.addinststatus_pos'};
19414: $position =~ s/\D+//g;
19415: if ($position ne '') {
19416: $allpos[$position] = $newtype;
19417: }
19418: }
19419: }
1.305 raeburn 19420: my @orderedstatus;
1.236 raeburn 19421: foreach my $type (@allpos) {
19422: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19423: push(@orderedstatus,$type);
19424: }
19425: }
19426: foreach my $type (keys(%alltypes)) {
19427: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19428: delete($alltypes{$type});
19429: }
19430: }
19431: $defaults_hash{'inststatus'} = {
19432: inststatustypes => \%alltypes,
19433: inststatusorder => \@orderedstatus,
1.305 raeburn 19434: inststatusguest => \@inststatusguest,
1.236 raeburn 19435: };
19436: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19437: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19438: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19439: }
19440: }
19441: if ($currorder ne join(',',@orderedstatus)) {
19442: $changes{'inststatus'}{'inststatusorder'} = 1;
19443: }
19444: my $newtitles;
19445: foreach my $item (@orderedstatus) {
19446: $newtitles .= $alltypes{$item}.',';
19447: }
19448: $newtitles =~ s/,$//;
19449: if ($currtitles ne $newtitles) {
19450: $changes{'inststatus'}{'inststatustypes'} = 1;
19451: }
1.43 raeburn 19452: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19453: $dom);
19454: if ($putresult eq 'ok') {
19455: if (keys(%changes) > 0) {
19456: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19457: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19458: 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";
19459: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19460: if ($item eq 'inststatus') {
19461: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19462: if (@orderedstatus) {
1.236 raeburn 19463: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19464: foreach my $type (@orderedstatus) {
19465: $resulttext .= $alltypes{$type}.', ';
19466: }
19467: $resulttext =~ s/, $//;
19468: $resulttext .= '</li>';
1.305 raeburn 19469: } else {
19470: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19471: }
19472: }
19473: } else {
19474: my $value = $env{'form.'.$item};
19475: if ($value eq '') {
19476: $value = &mt('none');
19477: } elsif ($item eq 'auth_def') {
19478: my %authnames = &authtype_names();
19479: my %shortauth = (
19480: internal => 'int',
19481: krb4 => 'krb4',
19482: krb5 => 'krb5',
19483: localauth => 'loc',
1.325 raeburn 19484: lti => 'lti',
1.236 raeburn 19485: );
19486: $value = $authnames{$shortauth{$value}};
19487: }
19488: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
19489: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 19490: }
19491: }
19492: $resulttext .= '</ul>';
19493: $mailmsgtext .= "\n";
19494: my $cachetime = 24*60*60;
1.72 raeburn 19495: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19496: if (ref($lastactref) eq 'HASH') {
19497: $lastactref->{'domdefaults'} = 1;
19498: }
1.68 raeburn 19499: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 19500: my $notify = 1;
19501: if (ref($domconfig{'contacts'}) eq 'HASH') {
19502: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
19503: $notify = 0;
19504: }
19505: }
19506: if ($notify) {
19507: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
19508: "LON-CAPA Domain Settings Change - $dom",
19509: $mailmsgtext);
19510: }
1.54 raeburn 19511: }
1.43 raeburn 19512: } else {
1.54 raeburn 19513: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 19514: }
19515: } else {
19516: $resulttext = '<span class="LC_error">'.
19517: &mt('An error occurred: [_1]',$putresult).'</span>';
19518: }
19519: if (@errors > 0) {
19520: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
19521: foreach my $item (@errors) {
19522: $resulttext .= ' "'.$title->{$item}.'",';
19523: }
19524: $resulttext =~ s/,$//;
19525: }
19526: return $resulttext;
19527: }
19528:
1.46 raeburn 19529: sub modify_scantron {
1.205 raeburn 19530: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 19531: my ($resulttext,%confhash,%changes,$errors);
19532: my $custom = 'custom.tab';
19533: my $default = 'default.tab';
19534: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 19535: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 19536: &config_check($dom,$confname,$servadm);
19537: if ($env{'form.scantronformat.filename'} ne '') {
19538: my $error;
19539: if ($configuserok eq 'ok') {
19540: if ($switchserver) {
1.130 raeburn 19541: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 19542: } else {
19543: if ($author_ok eq 'ok') {
19544: my ($result,$scantronurl) =
19545: &publishlogo($r,'upload','scantronformat',$dom,
19546: $confname,'scantron','','',$custom);
19547: if ($result eq 'ok') {
19548: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 19549: $changes{'scantronformat'} = 1;
1.46 raeburn 19550: } else {
19551: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
19552: }
19553: } else {
19554: $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);
19555: }
19556: }
19557: } else {
19558: $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);
19559: }
19560: if ($error) {
19561: &Apache::lonnet::logthis($error);
19562: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
19563: }
19564: }
1.48 raeburn 19565: if (ref($domconfig{'scantron'}) eq 'HASH') {
19566: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
19567: if ($env{'form.scantronformat_del'}) {
19568: $confhash{'scantron'}{'scantronformat'} = '';
19569: $changes{'scantronformat'} = 1;
1.347 raeburn 19570: } else {
19571: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 19572: }
19573: }
19574: }
1.347 raeburn 19575: my @options = ('hdr','pad','rem');
1.346 raeburn 19576: my @fields = &scantroncsv_fields();
19577: my %titles = &scantronconfig_titles();
1.347 raeburn 19578: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 19579: my ($newdat,$currdat,%newcol,%currcol);
19580: if (grep(/^dat$/,@formats)) {
19581: $confhash{'scantron'}{config}{dat} = 1;
19582: $newdat = 1;
19583: } else {
19584: $newdat = 0;
19585: }
19586: if (grep(/^csv$/,@formats)) {
19587: my %bynum;
19588: foreach my $field (@fields) {
19589: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
19590: my $posscol = $1;
19591: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 19592: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 19593: $bynum{$posscol} = $field;
19594: $newcol{$field} = $posscol;
19595: }
19596: }
19597: }
1.347 raeburn 19598: if (keys(%newcol)) {
19599: foreach my $option (@options) {
19600: if ($env{'form.scantroncsv_'.$option}) {
19601: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
19602: }
19603: }
19604: }
1.346 raeburn 19605: }
19606: $currdat = 1;
19607: if (ref($domconfig{'scantron'}) eq 'HASH') {
19608: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 19609: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 19610: $currdat = 0;
19611: }
19612: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19613: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19614: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
19615: }
1.346 raeburn 19616: }
19617: }
19618: }
19619: if ($currdat != $newdat) {
19620: $changes{'config'} = 1;
19621: } else {
19622: foreach my $field (@fields) {
19623: if ($currcol{$field} ne '') {
19624: if ($currcol{$field} ne $newcol{$field}) {
19625: $changes{'config'} = 1;
19626: last;
1.347 raeburn 19627: }
1.346 raeburn 19628: } elsif ($newcol{$field} ne '') {
19629: $changes{'config'} = 1;
19630: last;
19631: }
19632: }
19633: }
1.46 raeburn 19634: if (keys(%confhash) > 0) {
19635: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
19636: $dom);
19637: if ($putresult eq 'ok') {
19638: if (keys(%changes) > 0) {
1.48 raeburn 19639: if (ref($confhash{'scantron'}) eq 'HASH') {
19640: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 19641: if ($changes{'scantronformat'}) {
19642: if ($confhash{'scantron'}{'scantronformat'} eq '') {
19643: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
19644: } else {
19645: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
19646: }
19647: }
1.347 raeburn 19648: if ($changes{'config'}) {
1.346 raeburn 19649: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
19650: if ($confhash{'scantron'}{'config'}{'dat'}) {
19651: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
19652: }
19653: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19654: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19655: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
19656: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
19657: foreach my $field (@fields) {
19658: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
19659: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
19660: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
19661: }
19662: }
19663: $resulttext .= '</ul></li>';
19664: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
19665: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
19666: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
19667: foreach my $option (@options) {
19668: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
19669: $resulttext .= '<li>'.$titles{$option}.'</li>';
19670: }
19671: }
19672: $resulttext .= '</ul></li>';
19673: }
1.346 raeburn 19674: }
19675: }
19676: }
19677: }
19678: } else {
19679: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
19680: }
1.46 raeburn 19681: }
1.48 raeburn 19682: $resulttext .= '</ul>';
19683: } else {
1.130 raeburn 19684: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 19685: }
19686: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 19687: if (ref($lastactref) eq 'HASH') {
19688: $lastactref->{'domainconfig'} = 1;
19689: }
1.46 raeburn 19690: } else {
1.346 raeburn 19691: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19692: }
19693: } else {
19694: $resulttext = '<span class="LC_error">'.
19695: &mt('An error occurred: [_1]',$putresult).'</span>';
19696: }
19697: } else {
1.130 raeburn 19698: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19699: }
19700: if ($errors) {
1.353 raeburn 19701: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19702: $errors.'</ul></p>';
1.46 raeburn 19703: }
19704: return $resulttext;
19705: }
19706:
1.48 raeburn 19707: sub modify_coursecategories {
1.239 raeburn 19708: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19709: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19710: $cathash);
1.48 raeburn 19711: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19712: my @catitems = ('unauth','auth');
19713: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19714: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19715: $cathash = $domconfig{'coursecategories'}{'cats'};
19716: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19717: $changes{'togglecats'} = 1;
19718: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19719: }
19720: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19721: $changes{'categorize'} = 1;
19722: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19723: }
1.120 raeburn 19724: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19725: $changes{'togglecatscomm'} = 1;
19726: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19727: }
19728: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19729: $changes{'categorizecomm'} = 1;
19730: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19731:
19732: }
19733: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19734: $changes{'togglecatsplace'} = 1;
19735: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19736: }
19737: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19738: $changes{'categorizeplace'} = 1;
19739: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19740: }
1.238 raeburn 19741: foreach my $item (@catitems) {
19742: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19743: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19744: $changes{$item} = 1;
19745: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19746: }
19747: }
19748: }
1.57 raeburn 19749: } else {
19750: $changes{'togglecats'} = 1;
19751: $changes{'categorize'} = 1;
1.124 raeburn 19752: $changes{'togglecatscomm'} = 1;
19753: $changes{'categorizecomm'} = 1;
1.272 raeburn 19754: $changes{'togglecatsplace'} = 1;
19755: $changes{'categorizeplace'} = 1;
1.87 raeburn 19756: $domconfig{'coursecategories'} = {
19757: togglecats => $env{'form.togglecats'},
19758: categorize => $env{'form.categorize'},
1.124 raeburn 19759: togglecatscomm => $env{'form.togglecatscomm'},
19760: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19761: togglecatsplace => $env{'form.togglecatsplace'},
19762: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19763: };
1.238 raeburn 19764: foreach my $item (@catitems) {
19765: if ($env{'form.coursecat_'.$item} ne 'std') {
19766: $changes{$item} = 1;
19767: }
19768: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19769: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19770: }
19771: }
1.57 raeburn 19772: }
19773: if (ref($cathash) eq 'HASH') {
19774: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19775: push (@deletecategory,'instcode::0');
19776: }
1.120 raeburn 19777: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19778: push(@deletecategory,'communities::0');
19779: }
1.272 raeburn 19780: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19781: push(@deletecategory,'placement::0');
19782: }
1.48 raeburn 19783: }
1.57 raeburn 19784: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19785: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19786: if (@deletecategory > 0) {
19787: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19788: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19789: foreach my $item (@deletecategory) {
1.57 raeburn 19790: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19791: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19792: $deletions{$item} = 1;
1.57 raeburn 19793: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19794: }
19795: }
19796: }
1.57 raeburn 19797: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19798: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19799: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19800: $reorderings{$item} = 1;
1.57 raeburn 19801: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19802: }
19803: if ($env{'form.addcategory_name_'.$item} ne '') {
19804: my $newcat = $env{'form.addcategory_name_'.$item};
19805: my $newdepth = $depth+1;
19806: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19807: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19808: $adds{$newitem} = 1;
19809: }
19810: if ($env{'form.subcat_'.$item} ne '') {
19811: my $newcat = $env{'form.subcat_'.$item};
19812: my $newdepth = $depth+1;
19813: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19814: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19815: $adds{$newitem} = 1;
19816: }
19817: }
19818: }
19819: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19820: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19821: my $newitem = 'instcode::0';
1.57 raeburn 19822: if ($cathash->{$newitem} eq '') {
19823: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19824: $adds{$newitem} = 1;
19825: }
19826: } else {
19827: my $newitem = 'instcode::0';
1.57 raeburn 19828: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19829: $adds{$newitem} = 1;
19830: }
19831: }
1.120 raeburn 19832: if ($env{'form.communities'} eq '1') {
19833: if (ref($cathash) eq 'HASH') {
19834: my $newitem = 'communities::0';
19835: if ($cathash->{$newitem} eq '') {
19836: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19837: $adds{$newitem} = 1;
19838: }
19839: } else {
19840: my $newitem = 'communities::0';
19841: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19842: $adds{$newitem} = 1;
19843: }
19844: }
1.272 raeburn 19845: if ($env{'form.placement'} eq '1') {
19846: if (ref($cathash) eq 'HASH') {
19847: my $newitem = 'placement::0';
19848: if ($cathash->{$newitem} eq '') {
19849: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19850: $adds{$newitem} = 1;
19851: }
19852: } else {
19853: my $newitem = 'placement::0';
19854: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19855: $adds{$newitem} = 1;
19856: }
19857: }
1.48 raeburn 19858: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19859: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19860: ($env{'form.addcategory_name'} ne 'communities') &&
19861: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19862: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19863: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19864: $adds{$newitem} = 1;
19865: }
1.48 raeburn 19866: }
1.57 raeburn 19867: my $putresult;
1.48 raeburn 19868: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19869: if (keys(%deletions) > 0) {
19870: foreach my $key (keys(%deletions)) {
19871: if ($predelallitems{$key} ne '') {
19872: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19873: }
19874: }
19875: }
19876: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19877: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19878: if (ref($chkcats[0]) eq 'ARRAY') {
19879: my $depth = 0;
19880: my $chg = 0;
19881: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19882: my $name = $chkcats[0][$i];
19883: my $item;
19884: if ($name eq '') {
19885: $chg ++;
19886: } else {
19887: $item = &escape($name).'::0';
19888: if ($chg) {
1.57 raeburn 19889: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19890: }
19891: $depth ++;
1.57 raeburn 19892: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19893: $depth --;
19894: }
19895: }
19896: }
1.57 raeburn 19897: }
19898: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19899: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19900: if ($putresult eq 'ok') {
1.57 raeburn 19901: my %title = (
1.120 raeburn 19902: togglecats => 'Show/Hide a course in catalog',
19903: categorize => 'Assign a category to a course',
19904: togglecatscomm => 'Show/Hide a community in catalog',
19905: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19906: );
19907: my %level = (
1.120 raeburn 19908: dom => 'set in Domain ("Modify Course/Community")',
19909: crs => 'set in Course ("Course Configuration")',
19910: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19911: none => 'No catalog',
19912: std => 'Standard catalog',
19913: domonly => 'Domain-only catalog',
19914: codesrch => 'Code search form',
1.57 raeburn 19915: );
1.48 raeburn 19916: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19917: if ($changes{'togglecats'}) {
19918: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19919: }
19920: if ($changes{'categorize'}) {
19921: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19922: }
1.120 raeburn 19923: if ($changes{'togglecatscomm'}) {
19924: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19925: }
19926: if ($changes{'categorizecomm'}) {
19927: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19928: }
1.238 raeburn 19929: if ($changes{'unauth'}) {
19930: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19931: }
19932: if ($changes{'auth'}) {
19933: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19934: }
1.57 raeburn 19935: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19936: my $cathash;
19937: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19938: $cathash = $domconfig{'coursecategories'}{'cats'};
19939: } else {
19940: $cathash = {};
19941: }
19942: my (@cats,@trails,%allitems);
19943: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19944: if (keys(%deletions) > 0) {
19945: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19946: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19947: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19948: }
19949: $resulttext .= '</ul></li>';
19950: }
19951: if (keys(%reorderings) > 0) {
19952: my %sort_by_trail;
19953: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19954: foreach my $key (keys(%reorderings)) {
19955: if ($allitems{$key} ne '') {
19956: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19957: }
1.48 raeburn 19958: }
1.57 raeburn 19959: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19960: $resulttext .= '<li>'.$trails[$trail].'</li>';
19961: }
19962: $resulttext .= '</ul></li>';
1.48 raeburn 19963: }
1.57 raeburn 19964: if (keys(%adds) > 0) {
19965: my %sort_by_trail;
19966: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19967: foreach my $key (keys(%adds)) {
19968: if ($allitems{$key} ne '') {
19969: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19970: }
19971: }
19972: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19973: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19974: }
1.57 raeburn 19975: $resulttext .= '</ul></li>';
1.48 raeburn 19976: }
1.364 raeburn 19977: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19978: if (ref($lastactref) eq 'HASH') {
19979: $lastactref->{'cats'} = 1;
19980: }
1.48 raeburn 19981: }
19982: $resulttext .= '</ul>';
1.239 raeburn 19983: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19984: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19985: if ($changes{'auth'}) {
19986: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19987: }
19988: if ($changes{'unauth'}) {
19989: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19990: }
19991: my $cachetime = 24*60*60;
19992: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19993: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19994: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19995: }
19996: }
1.48 raeburn 19997: } else {
19998: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19999: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20000: }
20001: } else {
1.120 raeburn 20002: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20003: }
20004: return $resulttext;
20005: }
20006:
1.69 raeburn 20007: sub modify_serverstatuses {
20008: my ($dom,%domconfig) = @_;
20009: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20010: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20011: %currserverstatus = %{$domconfig{'serverstatuses'}};
20012: }
20013: my @pages = &serverstatus_pages();
20014: foreach my $type (@pages) {
20015: $newserverstatus{$type}{'namedusers'} = '';
20016: $newserverstatus{$type}{'machines'} = '';
20017: if (defined($env{'form.'.$type.'_namedusers'})) {
20018: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20019: my @okusers;
20020: foreach my $user (@users) {
20021: my ($uname,$udom) = split(/:/,$user);
20022: if (($udom =~ /^$match_domain$/) &&
20023: (&Apache::lonnet::domain($udom)) &&
20024: ($uname =~ /^$match_username$/)) {
20025: if (!grep(/^\Q$user\E/,@okusers)) {
20026: push(@okusers,$user);
20027: }
20028: }
20029: }
20030: if (@okusers > 0) {
20031: @okusers = sort(@okusers);
20032: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20033: }
20034: }
20035: if (defined($env{'form.'.$type.'_machines'})) {
20036: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20037: my @okmachines;
20038: foreach my $ip (@machines) {
20039: my @parts = split(/\./,$ip);
20040: next if (@parts < 4);
20041: my $badip = 0;
20042: for (my $i=0; $i<4; $i++) {
20043: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20044: $badip = 1;
20045: last;
20046: }
20047: }
20048: if (!$badip) {
20049: push(@okmachines,$ip);
20050: }
20051: }
20052: @okmachines = sort(@okmachines);
20053: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20054: }
20055: }
20056: my %serverstatushash = (
20057: serverstatuses => \%newserverstatus,
20058: );
20059: foreach my $type (@pages) {
1.83 raeburn 20060: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20061: my (@current,@new);
1.83 raeburn 20062: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20063: if ($currserverstatus{$type}{$setting} ne '') {
20064: @current = split(/,/,$currserverstatus{$type}{$setting});
20065: }
20066: }
20067: if ($newserverstatus{$type}{$setting} ne '') {
20068: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20069: }
20070: if (@current > 0) {
20071: if (@new > 0) {
20072: foreach my $item (@current) {
20073: if (!grep(/^\Q$item\E$/,@new)) {
20074: $changes{$type}{$setting} = 1;
1.82 raeburn 20075: last;
20076: }
20077: }
1.84 raeburn 20078: foreach my $item (@new) {
20079: if (!grep(/^\Q$item\E$/,@current)) {
20080: $changes{$type}{$setting} = 1;
20081: last;
1.82 raeburn 20082: }
20083: }
20084: } else {
1.83 raeburn 20085: $changes{$type}{$setting} = 1;
1.69 raeburn 20086: }
1.83 raeburn 20087: } elsif (@new > 0) {
20088: $changes{$type}{$setting} = 1;
1.69 raeburn 20089: }
20090: }
20091: }
20092: if (keys(%changes) > 0) {
1.81 raeburn 20093: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20094: my $putresult = &Apache::lonnet::put_dom('configuration',
20095: \%serverstatushash,$dom);
20096: if ($putresult eq 'ok') {
20097: $resulttext .= &mt('Changes made:').'<ul>';
20098: foreach my $type (@pages) {
1.84 raeburn 20099: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20100: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20101: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20102: if ($newserverstatus{$type}{'namedusers'} eq '') {
20103: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20104: } else {
20105: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20106: }
1.84 raeburn 20107: }
20108: if ($changes{$type}{'machines'}) {
1.69 raeburn 20109: if ($newserverstatus{$type}{'machines'} eq '') {
20110: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20111: } else {
20112: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20113: }
20114:
20115: }
20116: $resulttext .= '</ul></li>';
20117: }
20118: }
20119: $resulttext .= '</ul>';
20120: } else {
20121: $resulttext = '<span class="LC_error">'.
20122: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20123:
20124: }
20125: } else {
20126: $resulttext = &mt('No changes made to access to server status pages');
20127: }
20128: return $resulttext;
20129: }
20130:
1.118 jms 20131: sub modify_helpsettings {
1.285 raeburn 20132: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20133: my ($resulttext,$errors,%changes,%helphash);
20134: my %defaultchecked = ('submitbugs' => 'on');
20135: my @offon = ('off','on');
1.118 jms 20136: my @toggles = ('submitbugs');
1.285 raeburn 20137: my %current = ('submitbugs' => '',
20138: 'adhoc' => {},
20139: );
1.118 jms 20140: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20141: %current = %{$domconfig{'helpsettings'}};
20142: }
1.285 raeburn 20143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20144: foreach my $item (@toggles) {
20145: if ($defaultchecked{$item} eq 'on') {
20146: if ($current{$item} eq '') {
20147: if ($env{'form.'.$item} eq '0') {
20148: $changes{$item} = 1;
20149: }
20150: } elsif ($current{$item} ne $env{'form.'.$item}) {
20151: $changes{$item} = 1;
20152: }
20153: } elsif ($defaultchecked{$item} eq 'off') {
20154: if ($current{$item} eq '') {
20155: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20156: $changes{$item} = 1;
20157: }
1.282 raeburn 20158: } elsif ($current{$item} ne $env{'form.'.$item}) {
20159: $changes{$item} = 1;
20160: }
20161: }
20162: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20163: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20164: }
20165: }
1.285 raeburn 20166: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20167: my $confname = $dom.'-domainconfig';
20168: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20169: my (@allpos,%newsettings,%changedprivs,$newrole);
20170: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20171: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20172: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20173: my %lt = &Apache::lonlocal::texthash(
20174: s => 'system',
20175: d => 'domain',
20176: order => 'Display order',
20177: access => 'Role usage',
1.291 raeburn 20178: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20179: dh => 'All with domain helpdesk role',
20180: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20181: none => 'None',
20182: status => 'Determined based on institutional status',
20183: inc => 'Include all, but exclude specific personnel',
20184: exc => 'Exclude all, but include specific personnel',
20185: );
20186: for (my $num=0; $num<=$maxnum; $num++) {
20187: my ($prefix,$identifier,$rolename,%curr);
20188: if ($num == $maxnum) {
20189: next unless ($env{'form.newcusthelp'} == $maxnum);
20190: $identifier = 'custhelp'.$num;
20191: $prefix = 'helproles_'.$num;
20192: $rolename = $env{'form.custhelpname'.$num};
20193: $rolename=~s/[^A-Za-z0-9]//gs;
20194: next if ($rolename eq '');
20195: next if (exists($existing{'rolesdef_'.$rolename}));
20196: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20197: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20198: $newprivs{'c'},$confname,$dom);
20199: if ($result ne 'ok') {
20200: $errors .= '<li><span class="LC_error">'.
20201: &mt('An error occurred storing the new custom role: [_1]',
20202: $result).'</span></li>';
20203: next;
20204: } else {
20205: $changedprivs{$rolename} = \%newprivs;
20206: $newrole = $rolename;
20207: }
20208: } else {
20209: $prefix = 'helproles_'.$num;
20210: $rolename = $env{'form.'.$prefix};
20211: next if ($rolename eq '');
20212: next unless (exists($existing{'rolesdef_'.$rolename}));
20213: $identifier = 'custhelp'.$num;
20214: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20215: my %currprivs;
1.289 raeburn 20216: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20217: split(/\_/,$existing{'rolesdef_'.$rolename});
20218: foreach my $level ('c','d','s') {
20219: if ($newprivs{$level} ne $currprivs{$level}) {
20220: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20221: $newprivs{'c'},$confname,$dom);
20222: if ($result ne 'ok') {
20223: $errors .= '<li><span class="LC_error">'.
20224: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20225: $rolename,$result).'</span></li>';
20226: } else {
20227: $changedprivs{$rolename} = \%newprivs;
20228: }
20229: last;
20230: }
20231: }
20232: if (ref($current{'adhoc'}) eq 'HASH') {
20233: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20234: %curr = %{$current{'adhoc'}{$rolename}};
20235: }
20236: }
20237: }
20238: my $newpos = $env{'form.'.$prefix.'_pos'};
20239: $newpos =~ s/\D+//g;
20240: $allpos[$newpos] = $rolename;
20241: my $newdesc = $env{'form.'.$prefix.'_desc'};
20242: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20243: if ($curr{'desc'}) {
20244: if ($curr{'desc'} ne $newdesc) {
20245: $changes{'customrole'}{$rolename}{'desc'} = 1;
20246: $newsettings{$rolename}{'desc'} = $newdesc;
20247: }
20248: } elsif ($newdesc ne '') {
20249: $changes{'customrole'}{$rolename}{'desc'} = 1;
20250: $newsettings{$rolename}{'desc'} = $newdesc;
20251: }
20252: my $access = $env{'form.'.$prefix.'_access'};
20253: if (grep(/^\Q$access\E$/,@accesstypes)) {
20254: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20255: if ($access eq 'status') {
20256: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20257: if (scalar(@statuses) == 0) {
1.289 raeburn 20258: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20259: } else {
20260: my (@shownstatus,$numtypes);
20261: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20262: if (ref($types) eq 'ARRAY') {
20263: $numtypes = scalar(@{$types});
20264: foreach my $type (sort(@statuses)) {
20265: if ($type eq 'default') {
20266: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20267: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20268: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20269: push(@shownstatus,$usertypes->{$type});
20270: }
20271: }
20272: }
20273: if (grep(/^default$/,@statuses)) {
20274: push(@shownstatus,$othertitle);
20275: }
20276: if (scalar(@shownstatus) == 1+$numtypes) {
20277: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20278: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20279: } else {
20280: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20281: if (ref($curr{'status'}) eq 'ARRAY') {
20282: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20283: if (@diffs) {
20284: $changes{'customrole'}{$rolename}{$access} = 1;
20285: }
20286: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20287: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20288: }
1.166 raeburn 20289: }
20290: }
1.285 raeburn 20291: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20292: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20293: my @newspecstaff;
20294: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20295: foreach my $person (sort(@personnel)) {
20296: if ($domhelpdesk{$person}) {
20297: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20298: }
20299: }
20300: if (ref($curr{$access}) eq 'ARRAY') {
20301: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20302: if (@diffs) {
20303: $changes{'customrole'}{$rolename}{$access} = 1;
20304: }
20305: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20306: $changes{'customrole'}{$rolename}{$access} = 1;
20307: }
20308: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20309: my ($uname,$udom) = split(/:/,$person);
20310: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20311: }
20312: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20313: }
1.285 raeburn 20314: } else {
20315: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20316: }
20317: unless ($curr{'access'} eq $access) {
20318: $changes{'customrole'}{$rolename}{'access'} = 1;
20319: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20320: }
20321: }
1.285 raeburn 20322: if (@allpos > 0) {
20323: my $idx = 0;
20324: foreach my $rolename (@allpos) {
20325: if ($rolename ne '') {
20326: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20327: if (ref($current{'adhoc'}) eq 'HASH') {
20328: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20329: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20330: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20331: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20332: }
20333: }
1.282 raeburn 20334: }
1.285 raeburn 20335: $idx ++;
1.166 raeburn 20336: }
20337: }
1.118 jms 20338: }
1.123 jms 20339: my $putresult;
20340: if (keys(%changes) > 0) {
1.166 raeburn 20341: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20342: if ($putresult eq 'ok') {
1.285 raeburn 20343: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20344: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20345: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20346: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20347: }
20348: }
20349: my $cachetime = 24*60*60;
20350: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20351: if (ref($lastactref) eq 'HASH') {
20352: $lastactref->{'domdefaults'} = 1;
20353: }
20354: } else {
20355: $errors .= '<li><span class="LC_error">'.
20356: &mt('An error occurred storing the settings: [_1]',
20357: $putresult).'</span></li>';
20358: }
20359: }
20360: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20361: $resulttext = &mt('Changes made:').'<ul>';
20362: my (%shownprivs,@levelorder);
20363: @levelorder = ('c','d','s');
20364: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20365: foreach my $item (sort(keys(%changes))) {
20366: if ($item eq 'submitbugs') {
20367: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20368: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20369: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20370: } elsif ($item eq 'customrole') {
20371: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20372: my @keyorder = ('order','desc','access','status','exc','inc');
20373: my %keytext = &Apache::lonlocal::texthash(
20374: order => 'Order',
20375: desc => 'Role description',
20376: access => 'Role usage',
1.300 droeschl 20377: status => 'Allowed institutional types',
1.285 raeburn 20378: exc => 'Allowed personnel',
20379: inc => 'Disallowed personnel',
20380: );
1.282 raeburn 20381: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20382: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20383: if ($role eq $newrole) {
20384: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20385: $role).'<ul>';
20386: } else {
20387: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20388: $role).'<ul>';
20389: }
20390: foreach my $key (@keyorder) {
20391: if ($changes{'customrole'}{$role}{$key}) {
20392: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20393: $keytext{$key},$newsettings{$role}{$key}).
20394: '</li>';
20395: }
20396: }
20397: if (ref($changedprivs{$role}) eq 'HASH') {
20398: $shownprivs{$role} = 1;
20399: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20400: foreach my $level (@levelorder) {
20401: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20402: next if ($item eq '');
20403: my ($priv) = split(/\&/,$item,2);
20404: if (&Apache::lonnet::plaintext($priv)) {
20405: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20406: unless ($level eq 'c') {
20407: $resulttext .= ' ('.$lt{$level}.')';
20408: }
20409: $resulttext .= '</li>';
20410: }
20411: }
20412: }
20413: $resulttext .= '</ul>';
20414: }
20415: $resulttext .= '</ul></li>';
20416: }
20417: }
20418: }
20419: }
20420: }
20421: }
20422: if (keys(%changedprivs)) {
20423: foreach my $role (sort(keys(%changedprivs))) {
20424: unless ($shownprivs{$role}) {
20425: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20426: $role).'<ul>'.
20427: '<li>'.&mt('Privileges set to :').'<ul>';
20428: foreach my $level (@levelorder) {
20429: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20430: next if ($item eq '');
20431: my ($priv) = split(/\&/,$item,2);
20432: if (&Apache::lonnet::plaintext($priv)) {
20433: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20434: unless ($level eq 'c') {
20435: $resulttext .= ' ('.$lt{$level}.')';
20436: }
20437: $resulttext .= '</li>';
20438: }
1.282 raeburn 20439: }
20440: }
1.285 raeburn 20441: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20442: }
20443: }
20444: }
1.285 raeburn 20445: $resulttext .= '</ul>';
20446: } else {
20447: $resulttext = &mt('No changes made to help settings');
1.118 jms 20448: }
20449: if ($errors) {
1.168 raeburn 20450: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20451: $errors.'</ul>';
1.118 jms 20452: }
20453: return $resulttext;
20454: }
20455:
1.121 raeburn 20456: sub modify_coursedefaults {
1.212 raeburn 20457: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20458: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20459: my %defaultchecked = (
20460: 'canuse_pdfforms' => 'off',
20461: 'uselcmath' => 'on',
1.398 raeburn 20462: 'usejsme' => 'on',
20463: 'inline_chem' => 'on',
1.404 ! raeburn 20464: 'ltiauth' => 'off',
1.257 raeburn 20465: );
1.404 ! raeburn 20466: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20467: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20468: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
20469: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
20470: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 20471: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 20472: my %staticdefaults = (
20473: anonsurvey_threshold => 10,
20474: uploadquota => 500,
1.257 raeburn 20475: postsubmit => 60,
1.276 raeburn 20476: mysqltables => 172800,
1.198 raeburn 20477: );
1.314 raeburn 20478: my %texoptions = (
20479: MathJax => 'MathJax',
20480: mimetex => &mt('Convert to Images'),
20481: tth => &mt('TeX to HTML'),
20482: );
1.121 raeburn 20483: $defaultshash{'coursedefaults'} = {};
20484:
20485: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
20486: if ($domconfig{'coursedefaults'} eq '') {
20487: $domconfig{'coursedefaults'} = {};
20488: }
20489: }
20490:
20491: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
20492: foreach my $item (@toggles) {
20493: if ($defaultchecked{$item} eq 'on') {
20494: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20495: ($env{'form.'.$item} eq '0')) {
20496: $changes{$item} = 1;
1.192 raeburn 20497: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 20498: $changes{$item} = 1;
20499: }
20500: } elsif ($defaultchecked{$item} eq 'off') {
20501: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20502: ($env{'form.'.$item} eq '1')) {
20503: $changes{$item} = 1;
20504: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
20505: $changes{$item} = 1;
20506: }
20507: }
20508: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
20509: }
1.198 raeburn 20510: foreach my $item (@numbers) {
20511: my ($currdef,$newdef);
1.208 raeburn 20512: $newdef = $env{'form.'.$item};
1.198 raeburn 20513: if ($item eq 'anonsurvey_threshold') {
20514: $currdef = $domconfig{'coursedefaults'}{$item};
20515: $newdef =~ s/\D//g;
20516: if ($newdef eq '' || $newdef < 1) {
20517: $newdef = 1;
20518: }
20519: $defaultshash{'coursedefaults'}{$item} = $newdef;
20520: } else {
1.276 raeburn 20521: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
20522: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
20523: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 20524: }
20525: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 20526: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 20527: }
20528: if ($currdef ne $newdef) {
20529: if ($item eq 'anonsurvey_threshold') {
20530: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
20531: $changes{$item} = 1;
20532: }
1.276 raeburn 20533: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 20534: my $setting = $1;
1.276 raeburn 20535: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
20536: $changes{$setting} = 1;
1.198 raeburn 20537: }
20538: }
1.139 raeburn 20539: }
20540: }
1.314 raeburn 20541: my $texengine;
20542: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
20543: $texengine = $env{'form.texengine'};
1.349 raeburn 20544: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
20545: if ($currdef eq '') {
20546: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 20547: $changes{'texengine'} = 1;
20548: }
1.349 raeburn 20549: } elsif ($currdef ne $texengine) {
1.314 raeburn 20550: $changes{'texengine'} = 1;
20551: }
20552: }
20553: if ($texengine ne '') {
20554: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
20555: }
1.264 raeburn 20556: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
20557: my @currclonecode;
20558: if (ref($currclone) eq 'HASH') {
20559: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
20560: @currclonecode = @{$currclone->{'instcode'}};
20561: }
20562: }
20563: my $newclone;
1.289 raeburn 20564: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 20565: $newclone = $env{'form.canclone'};
20566: }
20567: if ($newclone eq 'instcode') {
20568: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
20569: my (%codedefaults,@code_order,@clonecode);
20570: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
20571: \@code_order);
20572: foreach my $item (@code_order) {
20573: if (grep(/^\Q$item\E$/,@newcodes)) {
20574: push(@clonecode,$item);
20575: }
20576: }
20577: if (@clonecode) {
20578: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
20579: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
20580: if (@diffs) {
20581: $changes{'canclone'} = 1;
20582: }
20583: } else {
20584: $newclone eq '';
20585: }
20586: } elsif ($newclone ne '') {
1.289 raeburn 20587: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
20588: }
1.264 raeburn 20589: if ($newclone ne $currclone) {
20590: $changes{'canclone'} = 1;
20591: }
1.257 raeburn 20592: my %credits;
20593: foreach my $type (@types) {
20594: unless ($type eq 'community') {
20595: $credits{$type} = $env{'form.'.$type.'_credits'};
20596: $credits{$type} =~ s/[^\d.]+//g;
20597: }
20598: }
20599: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
20600: ($env{'form.coursecredits'} eq '1')) {
20601: $changes{'coursecredits'} = 1;
20602: foreach my $type (keys(%credits)) {
20603: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20604: }
20605: } else {
1.289 raeburn 20606: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 20607: foreach my $type (@types) {
20608: unless ($type eq 'community') {
1.289 raeburn 20609: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 20610: $changes{'coursecredits'} = 1;
20611: }
20612: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20613: }
20614: }
20615: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20616: foreach my $type (@types) {
20617: unless ($type eq 'community') {
20618: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
20619: $changes{'coursecredits'} = 1;
20620: last;
20621: }
20622: }
20623: }
20624: }
20625: }
20626: if ($env{'form.postsubmit'} eq '1') {
20627: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
20628: my %currtimeout;
20629: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20630: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
20631: $changes{'postsubmit'} = 1;
20632: }
20633: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20634: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
20635: }
20636: } else {
20637: $changes{'postsubmit'} = 1;
20638: }
20639: foreach my $type (@types) {
20640: my $timeout = $env{'form.'.$type.'_timeout'};
20641: $timeout =~ s/\D//g;
20642: if ($timeout == $staticdefaults{'postsubmit'}) {
20643: $timeout = '';
20644: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
20645: $timeout = '0';
20646: }
20647: unless ($timeout eq '') {
20648: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
20649: }
20650: if (exists($currtimeout{$type})) {
20651: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 20652: $changes{'postsubmit'} = 1;
1.257 raeburn 20653: }
20654: } elsif ($timeout ne '') {
20655: $changes{'postsubmit'} = 1;
20656: }
20657: }
20658: } else {
20659: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
20660: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20661: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
20662: $changes{'postsubmit'} = 1;
20663: }
20664: } else {
20665: $changes{'postsubmit'} = 1;
20666: }
1.192 raeburn 20667: }
1.121 raeburn 20668: }
20669: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20670: $dom);
20671: if ($putresult eq 'ok') {
20672: if (keys(%changes) > 0) {
1.213 raeburn 20673: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 20674: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 20675: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 20676: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.404 ! raeburn 20677: ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
! 20678: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.257 raeburn 20679: if ($changes{$item}) {
20680: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
20681: }
1.289 raeburn 20682: }
1.192 raeburn 20683: if ($changes{'coursecredits'}) {
20684: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 20685: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
20686: $domdefaults{$type.'credits'} =
20687: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
20688: }
20689: }
20690: }
20691: if ($changes{'postsubmit'}) {
20692: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20693: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
20694: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20695: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20696: $domdefaults{$type.'postsubtimeout'} =
20697: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20698: }
20699: }
1.192 raeburn 20700: }
20701: }
1.198 raeburn 20702: if ($changes{'uploadquota'}) {
20703: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20704: foreach my $type (@types) {
20705: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20706: }
20707: }
20708: }
1.264 raeburn 20709: if ($changes{'canclone'}) {
20710: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20711: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20712: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20713: if (@clonecodes) {
20714: $domdefaults{'canclone'} = join('+',@clonecodes);
20715: }
20716: }
20717: } else {
20718: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20719: }
20720: }
1.121 raeburn 20721: my $cachetime = 24*60*60;
20722: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20723: if (ref($lastactref) eq 'HASH') {
20724: $lastactref->{'domdefaults'} = 1;
20725: }
1.121 raeburn 20726: }
20727: $resulttext = &mt('Changes made:').'<ul>';
20728: foreach my $item (sort(keys(%changes))) {
20729: if ($item eq 'canuse_pdfforms') {
20730: if ($env{'form.'.$item} eq '1') {
20731: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20732: } else {
20733: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20734: }
1.257 raeburn 20735: } elsif ($item eq 'uselcmath') {
20736: if ($env{'form.'.$item} eq '1') {
20737: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20738: } else {
20739: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20740: }
20741: } elsif ($item eq 'usejsme') {
20742: if ($env{'form.'.$item} eq '1') {
20743: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20744: } else {
1.289 raeburn 20745: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20746: }
1.398 raeburn 20747: } elsif ($item eq 'inline_chem') {
20748: if ($env{'form.'.$item} eq '1') {
20749: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
20750: } else {
20751: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
20752: }
1.314 raeburn 20753: } elsif ($item eq 'texengine') {
20754: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20755: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20756: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20757: }
1.139 raeburn 20758: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20759: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20760: } elsif ($item eq 'uploadquota') {
20761: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20762: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20763: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20764: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20765: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20766: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20767: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20768: '</ul>'.
20769: '</li>';
20770: } else {
20771: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20772: }
1.276 raeburn 20773: } elsif ($item eq 'mysqltables') {
20774: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20775: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20776: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20777: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20778: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20779: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20780: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20781: '</ul>'.
20782: '</li>';
20783: } else {
20784: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20785: }
1.257 raeburn 20786: } elsif ($item eq 'postsubmit') {
20787: if ($domdefaults{'postsubmit'} eq 'off') {
20788: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20789: } else {
20790: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20791: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20792: $resulttext .= &mt('durations:').'<ul>';
20793: foreach my $type (@types) {
20794: $resulttext .= '<li>';
20795: my $timeout;
20796: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20797: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20798: }
20799: my $display;
20800: if ($timeout eq '0') {
20801: $display = &mt('unlimited');
20802: } elsif ($timeout eq '') {
20803: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20804: } else {
20805: $display = &mt('[quant,_1,second]',$timeout);
20806: }
20807: if ($type eq 'community') {
20808: $resulttext .= &mt('Communities');
20809: } elsif ($type eq 'official') {
20810: $resulttext .= &mt('Official courses');
20811: } elsif ($type eq 'unofficial') {
20812: $resulttext .= &mt('Unofficial courses');
20813: } elsif ($type eq 'textbook') {
20814: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20815: } elsif ($type eq 'placement') {
20816: $resulttext .= &mt('Placement tests');
1.257 raeburn 20817: }
20818: $resulttext .= ' -- '.$display.'</li>';
20819: }
20820: $resulttext .= '</ul>';
20821: }
1.289 raeburn 20822: $resulttext .= '</li>';
1.257 raeburn 20823: }
1.192 raeburn 20824: } elsif ($item eq 'coursecredits') {
20825: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20826: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20827: ($domdefaults{'unofficialcredits'} eq '') &&
20828: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20829: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20830: } else {
20831: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20832: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20833: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20834: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20835: '</ul>'.
20836: '</li>';
20837: }
20838: } else {
20839: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20840: }
1.264 raeburn 20841: } elsif ($item eq 'canclone') {
20842: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20843: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20844: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20845: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20846: }
20847: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20848: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20849: } else {
1.289 raeburn 20850: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20851: }
1.404 ! raeburn 20852: } elsif ($item eq 'ltiauth') {
! 20853: if ($env{'form.'.$item} eq '1') {
! 20854: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
! 20855: } else {
! 20856: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
! 20857: }
1.140 raeburn 20858: }
1.121 raeburn 20859: }
20860: $resulttext .= '</ul>';
20861: } else {
20862: $resulttext = &mt('No changes made to course defaults');
20863: }
20864: } else {
20865: $resulttext = '<span class="LC_error">'.
20866: &mt('An error occurred: [_1]',$putresult).'</span>';
20867: }
20868: return $resulttext;
20869: }
20870:
1.231 raeburn 20871: sub modify_selfenrollment {
20872: my ($dom,$lastactref,%domconfig) = @_;
20873: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20874: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20875: my %titles = &tool_titles();
1.232 raeburn 20876: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20877: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20878: $ordered{'default'} = ['types','registered','approval','limit'];
20879:
20880: my (%roles,%shown,%toplevel);
20881: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20882:
20883: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20884: if ($domconfig{'selfenrollment'} eq '') {
20885: $domconfig{'selfenrollment'} = {};
20886: }
20887: }
20888: %toplevel = (
20889: admin => 'Configuration Rights',
20890: default => 'Default settings',
20891: validation => 'Validation of self-enrollment requests',
20892: );
1.233 raeburn 20893: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20894:
20895: if (ref($ordered{'admin'}) eq 'ARRAY') {
20896: foreach my $item (@{$ordered{'admin'}}) {
20897: foreach my $type (@types) {
20898: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20899: $selfenrollhash{'admin'}{$type}{$item} = 1;
20900: } else {
20901: $selfenrollhash{'admin'}{$type}{$item} = 0;
20902: }
20903: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20904: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20905: if ($selfenrollhash{'admin'}{$type}{$item} ne
20906: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20907: push(@{$changes{'admin'}{$type}},$item);
20908: }
20909: } else {
20910: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20911: push(@{$changes{'admin'}{$type}},$item);
20912: }
20913: }
20914: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20915: push(@{$changes{'admin'}{$type}},$item);
20916: }
20917: }
20918: }
20919: }
20920:
20921: foreach my $item (@{$ordered{'default'}}) {
20922: foreach my $type (@types) {
20923: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20924: if ($item eq 'types') {
20925: unless (($value eq 'all') || ($value eq 'dom')) {
20926: $value = '';
20927: }
20928: } elsif ($item eq 'registered') {
20929: unless ($value eq '1') {
20930: $value = 0;
20931: }
20932: } elsif ($item eq 'approval') {
20933: unless ($value =~ /^[012]$/) {
20934: $value = 0;
20935: }
20936: } else {
20937: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20938: $value = 'none';
20939: }
20940: }
20941: $selfenrollhash{'default'}{$type}{$item} = $value;
20942: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20943: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20944: if ($selfenrollhash{'default'}{$type}{$item} ne
20945: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20946: push(@{$changes{'default'}{$type}},$item);
20947: }
20948: } else {
20949: push(@{$changes{'default'}{$type}},$item);
20950: }
20951: } else {
20952: push(@{$changes{'default'}{$type}},$item);
20953: }
20954: if ($item eq 'limit') {
20955: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20956: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20957: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20958: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20959: }
20960: } else {
20961: $selfenrollhash{'default'}{$type}{'cap'} = '';
20962: }
20963: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20964: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20965: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20966: push(@{$changes{'default'}{$type}},'cap');
20967: }
20968: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20969: push(@{$changes{'default'}{$type}},'cap');
20970: }
20971: }
20972: }
20973: }
20974:
20975: foreach my $item (@{$itemsref}) {
20976: if ($item eq 'fields') {
20977: my @changed;
20978: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20979: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20980: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20981: }
20982: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20983: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20984: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20985: $domconfig{'selfenrollment'}{'validation'}{$item});
20986: } else {
20987: @changed = @{$selfenrollhash{'validation'}{$item}};
20988: }
20989: } else {
20990: @changed = @{$selfenrollhash{'validation'}{$item}};
20991: }
20992: if (@changed) {
20993: if ($selfenrollhash{'validation'}{$item}) {
20994: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20995: } else {
20996: $changes{'validation'}{$item} = &mt('None');
20997: }
20998: }
20999: } else {
21000: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21001: if ($item eq 'markup') {
21002: if ($env{'form.selfenroll_validation_'.$item}) {
21003: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21004: }
21005: }
21006: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21007: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21008: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21009: }
21010: }
21011: }
21012: }
21013:
21014: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21015: $dom);
21016: if ($putresult eq 'ok') {
21017: if (keys(%changes) > 0) {
21018: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21019: $resulttext = &mt('Changes made:').'<ul>';
21020: foreach my $key ('admin','default','validation') {
21021: if (ref($changes{$key}) eq 'HASH') {
21022: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21023: if ($key eq 'validation') {
21024: foreach my $item (@{$itemsref}) {
21025: if (exists($changes{$key}{$item})) {
21026: if ($item eq 'markup') {
21027: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21028: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21029: } else {
21030: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21031: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21032: }
21033: }
21034: }
21035: } else {
21036: foreach my $type (@types) {
21037: if ($type eq 'community') {
21038: $roles{'1'} = &mt('Community personnel');
21039: } else {
21040: $roles{'1'} = &mt('Course personnel');
21041: }
21042: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21043: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21044: if ($key eq 'admin') {
21045: my @mgrdc = ();
21046: if (ref($ordered{$key}) eq 'ARRAY') {
21047: foreach my $item (@{$ordered{'admin'}}) {
21048: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21049: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21050: push(@mgrdc,$item);
21051: }
21052: }
21053: }
21054: if (@mgrdc) {
21055: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21056: } else {
21057: delete($domdefaults{$type.'selfenrolladmdc'});
21058: }
21059: }
21060: } else {
21061: if (ref($ordered{$key}) eq 'ARRAY') {
21062: foreach my $item (@{$ordered{$key}}) {
21063: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21064: $domdefaults{$type.'selfenroll'.$item} =
21065: $selfenrollhash{$key}{$type}{$item};
21066: }
21067: }
21068: }
21069: }
21070: }
1.231 raeburn 21071: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21072: foreach my $item (@{$ordered{$key}}) {
21073: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21074: $resulttext .= '<li>';
21075: if ($key eq 'admin') {
21076: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21077: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21078: } else {
21079: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21080: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21081: }
21082: $resulttext .= '</li>';
21083: }
21084: }
21085: $resulttext .= '</ul></li>';
21086: }
21087: }
21088: $resulttext .= '</ul></li>';
21089: }
21090: }
1.305 raeburn 21091: }
21092: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21093: my $cachetime = 24*60*60;
21094: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21095: if (ref($lastactref) eq 'HASH') {
21096: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21097: }
1.231 raeburn 21098: }
21099: $resulttext .= '</ul>';
21100: } else {
21101: $resulttext = &mt('No changes made to self-enrollment settings');
21102: }
21103: } else {
21104: $resulttext = '<span class="LC_error">'.
21105: &mt('An error occurred: [_1]',$putresult).'</span>';
21106: }
21107: return $resulttext;
21108: }
21109:
1.373 raeburn 21110: sub modify_wafproxy {
21111: my ($dom,$action,$lastactref,%domconfig) = @_;
21112: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21113: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21114: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21115: foreach my $server (sort(keys(%servers))) {
21116: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21117: if ($serverhome eq $server) {
21118: my $serverdom = &Apache::lonnet::host_domain($server);
21119: if ($serverdom eq $dom) {
21120: $canset{$server} = 1;
21121: }
21122: }
21123: }
1.381 raeburn 21124: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21125: %{$values{$dom}} = ();
21126: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21127: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21128: }
1.388 raeburn 21129: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21130: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21131: }
1.382 raeburn 21132: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21133: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21134: }
21135: }
1.373 raeburn 21136: my $output;
21137: if (keys(%canset)) {
21138: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21139: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21140: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21141: if ($env{'form.wafproxy_'.$dom}) {
21142: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21143: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21144: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21145: $changes{'alias'} = 1;
21146: }
1.388 raeburn 21147: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21148: $wafproxy{'saml'}{$key} = 1;
21149: }
21150: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21151: $changes{'saml'} = 1;
21152: }
1.381 raeburn 21153: } else {
21154: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21155: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21156: if ($curralias{$key}) {
21157: $changes{'alias'} = 1;
21158: }
1.388 raeburn 21159: if ($currsaml{$key}) {
21160: $changes{'saml'} = 1;
21161: }
1.373 raeburn 21162: }
21163: if ($wafproxy{'alias'}{$key} eq '') {
21164: if ($curralias{$key}) {
21165: $expirecache{$key} = 1;
21166: }
21167: delete($wafproxy{'alias'}{$key});
21168: }
1.388 raeburn 21169: if ($wafproxy{'saml'}{$key} eq '') {
21170: if ($currsaml{$key}) {
21171: $expiresaml{$key} = 1;
21172: }
21173: delete($wafproxy{'saml'}{$key});
21174: }
1.373 raeburn 21175: }
21176: unless (keys(%{$wafproxy{'alias'}})) {
21177: delete($wafproxy{'alias'});
21178: }
1.388 raeburn 21179: unless (keys(%{$wafproxy{'saml'}})) {
21180: delete($wafproxy{'saml'});
21181: }
21182: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21183: my %warn = (
21184: trusted => 'trusted IP range(s)',
1.381 raeburn 21185: vpnint => 'internal IP range(s) for VPN sessions(s)',
21186: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21187: );
1.382 raeburn 21188: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21189: my $possible = $env{'form.wafproxy_'.$item};
21190: $possible =~ s/^\s+|\s+$//g;
21191: if ($possible ne '') {
1.381 raeburn 21192: if ($item eq 'remoteip') {
21193: if ($possible =~ /^[mhn]$/) {
21194: $wafproxy{$item} = $possible;
21195: }
21196: } elsif ($item eq 'ipheader') {
21197: if ($wafproxy{'remoteip'} eq 'h') {
21198: $wafproxy{$item} = $possible;
21199: }
1.382 raeburn 21200: } elsif ($item eq 'sslopt') {
21201: if ($possible =~ /^0|1$/) {
21202: $wafproxy{$item} = $possible;
21203: }
1.373 raeburn 21204: } else {
21205: my (@ok,$count);
1.381 raeburn 21206: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21207: unless ($env{'form.wafproxy_vpnaccess'}) {
21208: $possible = '';
21209: }
21210: } elsif ($item eq 'trusted') {
21211: unless ($wafproxy{'remoteip'} eq 'h') {
21212: $possible = '';
21213: }
21214: }
21215: unless ($possible eq '') {
21216: $possible =~ s/[\r\n]+/\s/g;
21217: $possible =~ s/\s*-\s*/-/g;
21218: $possible =~ s/\s+/,/g;
1.393 raeburn 21219: $possible =~ s/,+/,/g;
1.381 raeburn 21220: }
1.373 raeburn 21221: $count = 0;
1.381 raeburn 21222: if ($possible ne '') {
1.373 raeburn 21223: foreach my $poss (split(/\,/,$possible)) {
21224: $count ++;
1.393 raeburn 21225: $poss = &validate_ip_pattern($poss);
21226: if ($poss ne '') {
1.373 raeburn 21227: push(@ok,$poss);
21228: }
21229: }
21230: my $diff = $count - scalar(@ok);
21231: if ($diff) {
21232: push(@warnings,'<li>'.
21233: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21234: $diff,$warn{$item}).
21235: '</li>');
21236: }
1.393 raeburn 21237: if (@ok) {
21238: my @cidr_list;
21239: foreach my $item (@ok) {
21240: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21241: }
21242: $wafproxy{$item} = join(',',@cidr_list);
21243: }
1.373 raeburn 21244: }
21245: }
1.381 raeburn 21246: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21247: $changes{$item} = 1;
21248: }
1.381 raeburn 21249: } elsif ($currvalue{$item}) {
21250: $changes{$item} = 1;
21251: }
21252: }
21253: } else {
21254: if (keys(%curralias)) {
21255: $changes{'alias'} = 1;
1.388 raeburn 21256: }
21257: if (keys(%currsaml)) {
21258: $changes{'saml'} = 1;
1.381 raeburn 21259: }
21260: if (keys(%currvalue)) {
21261: foreach my $key (keys(%currvalue)) {
21262: $changes{$key} = 1;
1.373 raeburn 21263: }
21264: }
21265: }
21266: if (keys(%changes)) {
21267: my %defaultshash = (
21268: wafproxy => \%wafproxy,
21269: );
21270: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21271: $dom);
21272: if ($putresult eq 'ok') {
21273: my $cachetime = 24*60*60;
21274: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21275: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21276: if ($changes{$item}) {
21277: unless ($updatedomdefs) {
21278: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21279: $updatedomdefs = 1;
21280: }
21281: if ($wafproxy{$item}) {
21282: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21283: } elsif (exists($domdefaults{'waf_'.$item})) {
21284: delete($domdefaults{'waf_'.$item});
21285: }
21286: }
21287: }
21288: if ($updatedomdefs) {
21289: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21290: if (ref($lastactref) eq 'HASH') {
21291: $lastactref->{'domdefaults'} = 1;
21292: }
21293: }
21294: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21295: my %updates = %expirecache;
21296: foreach my $key (keys(%expirecache)) {
21297: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21298: }
21299: if (ref($wafproxy{'alias'}) eq 'HASH') {
21300: my $cachetime = 24*60*60;
21301: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21302: $updates{$key} = 1;
21303: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21304: $cachetime);
21305: }
21306: }
21307: if (ref($lastactref) eq 'HASH') {
21308: $lastactref->{'proxyalias'} = \%updates;
21309: }
21310: }
1.388 raeburn 21311: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21312: my %samlupdates = %expiresaml;
21313: foreach my $key (keys(%expiresaml)) {
21314: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21315: }
21316: if (ref($wafproxy{'saml'}) eq 'HASH') {
21317: my $cachetime = 24*60*60;
21318: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21319: $samlupdates{$key} = 1;
21320: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21321: $cachetime);
21322: }
21323: }
21324: if (ref($lastactref) eq 'HASH') {
21325: $lastactref->{'proxysaml'} = \%samlupdates;
21326: }
21327: }
1.373 raeburn 21328: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21329: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21330: if ($changes{$item}) {
21331: if ($item eq 'alias') {
21332: my $numaliased = 0;
21333: if (ref($wafproxy{'alias'}) eq 'HASH') {
21334: my $shown;
21335: if (keys(%{$wafproxy{'alias'}})) {
21336: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21337: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21338: &Apache::lonnet::hostname($server),
21339: $wafproxy{'alias'}{$server}).'</li>';
21340: $numaliased ++;
21341: }
21342: if ($numaliased) {
21343: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21344: '<ul>'.$shown.'</ul>').'</li>';
21345: }
21346: }
21347: }
21348: unless ($numaliased) {
21349: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21350: }
1.388 raeburn 21351: } elsif ($item eq 'saml') {
21352: my $shown;
21353: if (ref($wafproxy{'saml'}) eq 'HASH') {
21354: if (keys(%{$wafproxy{'saml'}})) {
21355: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21356: }
21357: }
21358: if ($shown) {
1.396 raeburn 21359: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21360: $shown).'</li>';
21361: } else {
1.396 raeburn 21362: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21363: }
1.373 raeburn 21364: } else {
1.381 raeburn 21365: if ($item eq 'remoteip') {
21366: my %ip_methods = &remoteip_methods();
21367: if ($wafproxy{$item} =~ /^[mh]$/) {
21368: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
21369: $ip_methods{$wafproxy{$item}}).'</li>';
21370: } else {
21371: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
21372: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
21373: '</li>';
21374: } else {
21375: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
21376: }
21377: }
21378: } elsif ($item eq 'ipheader') {
1.373 raeburn 21379: if ($wafproxy{$item}) {
1.381 raeburn 21380: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 21381: $wafproxy{$item}).'</li>';
21382: } else {
1.381 raeburn 21383: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 21384: }
21385: } elsif ($item eq 'trusted') {
21386: if ($wafproxy{$item}) {
1.381 raeburn 21387: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 21388: $wafproxy{$item}).'</li>';
21389: } else {
21390: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
21391: }
1.381 raeburn 21392: } elsif ($item eq 'vpnint') {
21393: if ($wafproxy{$item}) {
21394: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
21395: $wafproxy{$item}).'</li>';
21396: } else {
21397: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
21398: }
21399: } elsif ($item eq 'vpnext') {
1.373 raeburn 21400: if ($wafproxy{$item}) {
1.381 raeburn 21401: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 21402: $wafproxy{$item}).'</li>';
21403: } else {
1.381 raeburn 21404: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 21405: }
1.382 raeburn 21406: } elsif ($item eq 'sslopt') {
21407: if ($wafproxy{$item}) {
21408: $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>';
21409: } else {
21410: $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>';
21411: }
1.373 raeburn 21412: }
21413: }
21414: }
21415: }
21416: } else {
21417: $output = '<span class="LC_error">'.
21418: &mt('An error occurred: [_1]',$putresult).'</span>';
21419: }
21420: } elsif (keys(%canset)) {
21421: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
21422: }
21423: if (@warnings) {
21424: $output .= '<br />'.&mt('Warnings:').'<ul>'.
21425: join("\n",@warnings).'</ul>';
21426: }
21427: return $output;
21428: }
21429:
21430: sub validate_ip_pattern {
21431: my ($pattern) = @_;
21432: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
21433: my ($start,$end) = ($1,$2);
21434: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 21435: if (($start !~ m{/}) && ($end !~ m{/})) {
21436: return $start.'-'.$end;
21437: }
21438: }
21439: } elsif ($pattern ne '') {
21440: $pattern = &Net::CIDR::cidrvalidate($pattern);
21441: if ($pattern ne '') {
21442: return $pattern;
1.373 raeburn 21443: }
21444: }
1.393 raeburn 21445: return;
1.373 raeburn 21446: }
21447:
1.137 raeburn 21448: sub modify_usersessions {
1.212 raeburn 21449: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 21450: my @hostingtypes = ('version','excludedomain','includedomain');
21451: my @offloadtypes = ('primary','default');
21452: my %types = (
21453: remote => \@hostingtypes,
21454: hosted => \@hostingtypes,
21455: spares => \@offloadtypes,
21456: );
21457: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 21458: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 21459: my (%by_ip,%by_location,@intdoms,@instdoms);
21460: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 21461: my @locations = sort(keys(%by_location));
1.137 raeburn 21462: my (%defaultshash,%changes);
21463: foreach my $prefix (@prefixes) {
21464: $defaultshash{'usersessions'}{$prefix} = {};
21465: }
1.212 raeburn 21466: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 21467: my $resulttext;
1.138 raeburn 21468: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 21469: foreach my $prefix (@prefixes) {
1.145 raeburn 21470: next if ($prefix eq 'spares');
21471: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 21472: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21473: if ($type eq 'version') {
21474: my $value = $env{'form.'.$prefix.'_'.$type};
21475: my $okvalue;
21476: if ($value ne '') {
21477: if (grep(/^\Q$value\E$/,@lcversions)) {
21478: $okvalue = $value;
21479: }
21480: }
21481: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21482: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21483: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
21484: if ($inuse == 0) {
21485: $changes{$prefix}{$type} = 1;
21486: } else {
21487: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
21488: $changes{$prefix}{$type} = 1;
21489: }
21490: if ($okvalue ne '') {
21491: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21492: }
21493: }
21494: } else {
21495: if (($inuse == 1) && ($okvalue ne '')) {
21496: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21497: $changes{$prefix}{$type} = 1;
21498: }
21499: }
21500: } else {
21501: if (($inuse == 1) && ($okvalue ne '')) {
21502: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21503: $changes{$prefix}{$type} = 1;
21504: }
21505: }
21506: } else {
21507: if (($inuse == 1) && ($okvalue ne '')) {
21508: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21509: $changes{$prefix}{$type} = 1;
21510: }
21511: }
21512: } else {
21513: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21514: my @okvals;
21515: foreach my $val (@vals) {
1.138 raeburn 21516: if ($val =~ /:/) {
21517: my @items = split(/:/,$val);
21518: foreach my $item (@items) {
21519: if (ref($by_location{$item}) eq 'ARRAY') {
21520: push(@okvals,$item);
21521: }
21522: }
21523: } else {
21524: if (ref($by_location{$val}) eq 'ARRAY') {
21525: push(@okvals,$val);
21526: }
1.137 raeburn 21527: }
21528: }
21529: @okvals = sort(@okvals);
21530: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21531: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21532: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21533: if ($inuse == 0) {
21534: $changes{$prefix}{$type} = 1;
21535: } else {
21536: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21537: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
21538: if (@changed > 0) {
21539: $changes{$prefix}{$type} = 1;
21540: }
21541: }
21542: } else {
21543: if ($inuse == 1) {
21544: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21545: $changes{$prefix}{$type} = 1;
21546: }
21547: }
21548: } else {
21549: if ($inuse == 1) {
21550: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21551: $changes{$prefix}{$type} = 1;
21552: }
21553: }
21554: } else {
21555: if ($inuse == 1) {
21556: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21557: $changes{$prefix}{$type} = 1;
21558: }
21559: }
21560: }
21561: }
21562: }
1.145 raeburn 21563:
21564: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 21565: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 21566: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
21567: my $savespares;
21568:
21569: foreach my $lonhost (sort(keys(%servers))) {
21570: my $serverhomeID =
21571: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 21572: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 21573: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
21574: my %spareschg;
21575: foreach my $type (@{$types{'spares'}}) {
21576: my @okspares;
21577: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
21578: foreach my $server (@checked) {
1.152 raeburn 21579: if (&Apache::lonnet::hostname($server) ne '') {
21580: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
21581: unless (grep(/^\Q$server\E$/,@okspares)) {
21582: push(@okspares,$server);
21583: }
1.145 raeburn 21584: }
21585: }
21586: }
21587: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
21588: my $newspare;
1.152 raeburn 21589: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
21590: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 21591: $newspare = $new;
21592: }
21593: }
1.152 raeburn 21594: my @spares;
21595: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
21596: @spares = sort(@okspares,$newspare);
21597: } else {
21598: @spares = sort(@okspares);
21599: }
21600: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 21601: if (ref($spareid{$lonhost}) eq 'HASH') {
21602: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 21603: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 21604: if (@diffs > 0) {
21605: $spareschg{$type} = 1;
21606: }
21607: }
21608: }
21609: }
21610: if (keys(%spareschg) > 0) {
21611: $changes{'spares'}{$lonhost} = \%spareschg;
21612: }
21613: }
1.261 raeburn 21614: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 21615: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 21616: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
21617: my @okoffload;
21618: if (@offloadnow) {
21619: foreach my $server (@offloadnow) {
21620: if (&Apache::lonnet::hostname($server) ne '') {
21621: unless (grep(/^\Q$server\E$/,@okoffload)) {
21622: push(@okoffload,$server);
21623: }
21624: }
21625: }
21626: if (@okoffload) {
21627: foreach my $lonhost (@okoffload) {
21628: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
21629: }
21630: }
21631: }
1.371 raeburn 21632: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
21633: my @okoffloadoth;
21634: if (@offloadoth) {
21635: foreach my $server (@offloadoth) {
21636: if (&Apache::lonnet::hostname($server) ne '') {
21637: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
21638: push(@okoffloadoth,$server);
21639: }
21640: }
21641: }
21642: if (@okoffloadoth) {
21643: foreach my $lonhost (@okoffloadoth) {
21644: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
21645: }
21646: }
21647: }
1.145 raeburn 21648: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21649: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
21650: if (ref($changes{'spares'}) eq 'HASH') {
21651: if (keys(%{$changes{'spares'}}) > 0) {
21652: $savespares = 1;
21653: }
21654: }
21655: } else {
21656: $savespares = 1;
21657: }
1.371 raeburn 21658: foreach my $offload ('offloadnow','offloadoth') {
21659: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
21660: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
21661: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
21662: $changes{$offload} = 1;
21663: last;
21664: }
1.261 raeburn 21665: }
1.371 raeburn 21666: unless ($changes{$offload}) {
21667: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
21668: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
21669: $changes{$offload} = 1;
21670: last;
21671: }
1.261 raeburn 21672: }
21673: }
1.371 raeburn 21674: } else {
21675: if (($offload eq 'offloadnow') && (@okoffload)) {
21676: $changes{'offloadnow'} = 1;
21677: }
21678: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
21679: $changes{'offloadoth'} = 1;
21680: }
21681: }
21682: }
21683: } else {
21684: if (@okoffload) {
1.261 raeburn 21685: $changes{'offloadnow'} = 1;
21686: }
1.371 raeburn 21687: if (@okoffloadoth) {
21688: $changes{'offloadoth'} = 1;
21689: }
1.145 raeburn 21690: }
1.147 raeburn 21691: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
21692: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 21693: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21694: $dom);
21695: if ($putresult eq 'ok') {
21696: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21697: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
21698: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
21699: }
21700: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
21701: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
21702: }
1.261 raeburn 21703: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21704: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
21705: }
1.371 raeburn 21706: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21707: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
21708: }
1.137 raeburn 21709: }
21710: my $cachetime = 24*60*60;
21711: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 21712: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 21713: if (ref($lastactref) eq 'HASH') {
21714: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 21715: $lastactref->{'usersessions'} = 1;
1.212 raeburn 21716: }
1.147 raeburn 21717: if (keys(%changes) > 0) {
21718: my %lt = &usersession_titles();
21719: $resulttext = &mt('Changes made:').'<ul>';
21720: foreach my $prefix (@prefixes) {
21721: if (ref($changes{$prefix}) eq 'HASH') {
21722: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21723: if ($prefix eq 'spares') {
21724: if (ref($changes{$prefix}) eq 'HASH') {
21725: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21726: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21727: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21728: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21729: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21730: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21731: foreach my $type (@{$types{$prefix}}) {
21732: if ($changes{$prefix}{$lonhost}{$type}) {
21733: my $offloadto = &mt('None');
21734: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21735: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21736: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21737: }
1.145 raeburn 21738: }
1.147 raeburn 21739: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21740: }
1.137 raeburn 21741: }
21742: }
1.147 raeburn 21743: $resulttext .= '</li>';
1.137 raeburn 21744: }
21745: }
1.147 raeburn 21746: } else {
21747: foreach my $type (@{$types{$prefix}}) {
21748: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21749: my ($newvalue,$notinuse);
1.147 raeburn 21750: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21751: if (ref($defaultshash{'usersessions'}{$prefix})) {
21752: if ($type eq 'version') {
21753: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21754: } else {
21755: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21756: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21757: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21758: }
21759: } else {
21760: $notinuse = 1;
1.147 raeburn 21761: }
1.145 raeburn 21762: }
21763: }
21764: }
1.147 raeburn 21765: if ($newvalue eq '') {
21766: if ($type eq 'version') {
21767: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21768: } elsif ($notinuse) {
21769: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21770: } else {
21771: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21772: }
1.145 raeburn 21773: } else {
1.147 raeburn 21774: if ($type eq 'version') {
1.344 raeburn 21775: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21776: }
21777: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21778: }
1.137 raeburn 21779: }
21780: }
21781: }
1.147 raeburn 21782: $resulttext .= '</ul>';
1.137 raeburn 21783: }
21784: }
1.261 raeburn 21785: if ($changes{'offloadnow'}) {
21786: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21787: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21788: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21789: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21790: $resulttext .= '<li>'.$lonhost.'</li>';
21791: }
21792: $resulttext .= '</ul>';
21793: } else {
1.371 raeburn 21794: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21795: }
21796: } else {
21797: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21798: }
21799: }
21800: if ($changes{'offloadoth'}) {
21801: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21802: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21803: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21804: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21805: $resulttext .= '<li>'.$lonhost.'</li>';
21806: }
21807: $resulttext .= '</ul>';
21808: } else {
21809: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21810: }
21811: } else {
1.371 raeburn 21812: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21813: }
21814: }
1.147 raeburn 21815: $resulttext .= '</ul>';
21816: } else {
21817: $resulttext = $nochgmsg;
1.137 raeburn 21818: }
21819: } else {
21820: $resulttext = '<span class="LC_error">'.
21821: &mt('An error occurred: [_1]',$putresult).'</span>';
21822: }
21823: } else {
1.147 raeburn 21824: $resulttext = $nochgmsg;
1.137 raeburn 21825: }
21826: return $resulttext;
21827: }
21828:
1.275 raeburn 21829: sub modify_ssl {
21830: my ($dom,$lastactref,%domconfig) = @_;
21831: my (%by_ip,%by_location,@intdoms,@instdoms);
21832: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21833: my @locations = sort(keys(%by_location));
21834: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21835: my (%defaultshash,%changes);
21836: my $action = 'ssl';
1.293 raeburn 21837: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21838: foreach my $prefix (@prefixes) {
21839: $defaultshash{$action}{$prefix} = {};
21840: }
21841: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21842: my $resulttext;
21843: my %iphost = &Apache::lonnet::get_iphost();
21844: my @reptypes = ('certreq','nocertreq');
21845: my @connecttypes = ('dom','intdom','other');
21846: my %types = (
1.293 raeburn 21847: connto => \@connecttypes,
21848: connfrom => \@connecttypes,
21849: replication => \@reptypes,
1.275 raeburn 21850: );
21851: foreach my $prefix (sort(keys(%types))) {
21852: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21853: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21854: my $value = 'yes';
21855: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21856: $value = $env{'form.'.$prefix.'_'.$type};
21857: }
1.335 raeburn 21858: if (ref($domconfig{$action}) eq 'HASH') {
21859: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21860: if ($domconfig{$action}{$prefix}{$type} ne '') {
21861: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21862: $changes{$prefix}{$type} = 1;
21863: }
21864: $defaultshash{$action}{$prefix}{$type} = $value;
21865: } else {
21866: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21867: $changes{$prefix}{$type} = 1;
21868: }
21869: } else {
21870: $defaultshash{$action}{$prefix}{$type} = $value;
21871: $changes{$prefix}{$type} = 1;
21872: }
21873: } else {
21874: $defaultshash{$action}{$prefix}{$type} = $value;
21875: $changes{$prefix}{$type} = 1;
21876: }
21877: if (($type eq 'dom') && (keys(%servers) == 1)) {
21878: delete($changes{$prefix}{$type});
21879: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21880: delete($changes{$prefix}{$type});
21881: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21882: delete($changes{$prefix}{$type});
21883: }
21884: } elsif ($prefix eq 'replication') {
21885: if (@locations > 0) {
21886: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21887: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21888: my @okvals;
21889: foreach my $val (@vals) {
21890: if ($val =~ /:/) {
21891: my @items = split(/:/,$val);
21892: foreach my $item (@items) {
21893: if (ref($by_location{$item}) eq 'ARRAY') {
21894: push(@okvals,$item);
21895: }
21896: }
21897: } else {
21898: if (ref($by_location{$val}) eq 'ARRAY') {
21899: push(@okvals,$val);
21900: }
21901: }
21902: }
21903: @okvals = sort(@okvals);
21904: if (ref($domconfig{$action}) eq 'HASH') {
21905: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21906: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21907: if ($inuse == 0) {
21908: $changes{$prefix}{$type} = 1;
21909: } else {
21910: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21911: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21912: if (@changed > 0) {
21913: $changes{$prefix}{$type} = 1;
21914: }
21915: }
21916: } else {
21917: if ($inuse == 1) {
21918: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21919: $changes{$prefix}{$type} = 1;
21920: }
21921: }
21922: } else {
21923: if ($inuse == 1) {
21924: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21925: $changes{$prefix}{$type} = 1;
21926: }
21927: }
21928: } else {
21929: if ($inuse == 1) {
21930: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21931: $changes{$prefix}{$type} = 1;
21932: }
21933: }
21934: }
21935: }
21936: }
21937: }
1.336 raeburn 21938: if (keys(%changes)) {
21939: foreach my $prefix (keys(%changes)) {
21940: if (ref($changes{$prefix}) eq 'HASH') {
21941: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21942: delete($changes{$prefix});
21943: }
21944: } else {
21945: delete($changes{$prefix});
21946: }
21947: }
21948: }
1.275 raeburn 21949: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21950: if (keys(%changes) > 0) {
21951: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21952: $dom);
21953: if ($putresult eq 'ok') {
21954: if (ref($defaultshash{$action}) eq 'HASH') {
21955: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21956: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21957: }
1.293 raeburn 21958: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21959: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21960: }
21961: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21962: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21963: }
21964: }
21965: my $cachetime = 24*60*60;
21966: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21967: if (ref($lastactref) eq 'HASH') {
21968: $lastactref->{'domdefaults'} = 1;
21969: }
21970: if (keys(%changes) > 0) {
21971: my %titles = &ssl_titles();
21972: $resulttext = &mt('Changes made:').'<ul>';
21973: foreach my $prefix (@prefixes) {
21974: if (ref($changes{$prefix}) eq 'HASH') {
21975: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21976: foreach my $type (@{$types{$prefix}}) {
21977: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21978: my ($newvalue,$notinuse);
1.275 raeburn 21979: if (ref($defaultshash{$action}) eq 'HASH') {
21980: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21981: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21982: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21983: } else {
21984: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21985: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21986: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21987: }
21988: } else {
21989: $notinuse = 1;
1.275 raeburn 21990: }
21991: }
21992: }
1.344 raeburn 21993: if ($notinuse) {
21994: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21995: } elsif ($newvalue eq '') {
1.275 raeburn 21996: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21997: } else {
21998: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21999: }
22000: }
22001: }
22002: }
22003: $resulttext .= '</ul>';
22004: }
22005: }
22006: } else {
22007: $resulttext = $nochgmsg;
22008: }
22009: } else {
22010: $resulttext = '<span class="LC_error">'.
22011: &mt('An error occurred: [_1]',$putresult).'</span>';
22012: }
22013: } else {
22014: $resulttext = $nochgmsg;
22015: }
22016: return $resulttext;
22017: }
22018:
1.279 raeburn 22019: sub modify_trust {
22020: my ($dom,$lastactref,%domconfig) = @_;
22021: my (%by_ip,%by_location,@intdoms,@instdoms);
22022: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22023: my @locations = sort(keys(%by_location));
22024: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22025: my @types = ('exc','inc');
22026: my (%defaultshash,%changes);
22027: foreach my $prefix (@prefixes) {
22028: $defaultshash{'trust'}{$prefix} = {};
22029: }
22030: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22031: my $resulttext;
22032: foreach my $prefix (@prefixes) {
22033: foreach my $type (@types) {
22034: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22035: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22036: my @okvals;
22037: foreach my $val (@vals) {
22038: if ($val =~ /:/) {
22039: my @items = split(/:/,$val);
22040: foreach my $item (@items) {
22041: if (ref($by_location{$item}) eq 'ARRAY') {
22042: push(@okvals,$item);
22043: }
22044: }
22045: } else {
22046: if (ref($by_location{$val}) eq 'ARRAY') {
22047: push(@okvals,$val);
22048: }
22049: }
22050: }
22051: @okvals = sort(@okvals);
22052: if (ref($domconfig{'trust'}) eq 'HASH') {
22053: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22054: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22055: if ($inuse == 0) {
22056: $changes{$prefix}{$type} = 1;
22057: } else {
22058: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22059: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22060: if (@changed > 0) {
22061: $changes{$prefix}{$type} = 1;
22062: }
22063: }
22064: } else {
22065: if ($inuse == 1) {
22066: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22067: $changes{$prefix}{$type} = 1;
22068: }
22069: }
22070: } else {
22071: if ($inuse == 1) {
22072: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22073: $changes{$prefix}{$type} = 1;
22074: }
22075: }
22076: } else {
22077: if ($inuse == 1) {
22078: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22079: $changes{$prefix}{$type} = 1;
22080: }
22081: }
22082: }
22083: }
22084: my $nochgmsg = &mt('No changes made to trust settings.');
22085: if (keys(%changes) > 0) {
22086: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22087: $dom);
22088: if ($putresult eq 'ok') {
22089: if (ref($defaultshash{'trust'}) eq 'HASH') {
22090: foreach my $prefix (@prefixes) {
22091: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22092: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22093: }
22094: }
22095: }
22096: my $cachetime = 24*60*60;
22097: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22098: if (ref($lastactref) eq 'HASH') {
22099: $lastactref->{'domdefaults'} = 1;
22100: }
22101: if (keys(%changes) > 0) {
22102: my %lt = &trust_titles();
22103: $resulttext = &mt('Changes made:').'<ul>';
22104: foreach my $prefix (@prefixes) {
22105: if (ref($changes{$prefix}) eq 'HASH') {
22106: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22107: foreach my $type (@types) {
22108: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22109: my ($newvalue,$notinuse);
1.279 raeburn 22110: if (ref($defaultshash{'trust'}) eq 'HASH') {
22111: if (ref($defaultshash{'trust'}{$prefix})) {
22112: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22113: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22114: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22115: }
1.344 raeburn 22116: } else {
22117: $notinuse = 1;
1.279 raeburn 22118: }
22119: }
22120: }
1.344 raeburn 22121: if ($notinuse) {
22122: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22123: } elsif ($newvalue eq '') {
1.279 raeburn 22124: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22125: } else {
22126: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22127: }
22128: }
22129: }
22130: $resulttext .= '</ul>';
22131: }
22132: }
22133: $resulttext .= '</ul>';
22134: } else {
22135: $resulttext = $nochgmsg;
22136: }
22137: } else {
22138: $resulttext = '<span class="LC_error">'.
22139: &mt('An error occurred: [_1]',$putresult).'</span>';
22140: }
22141: } else {
22142: $resulttext = $nochgmsg;
22143: }
22144: return $resulttext;
22145: }
22146:
1.150 raeburn 22147: sub modify_loadbalancing {
22148: my ($dom,%domconfig) = @_;
22149: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22150: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22151: my ($othertitle,$usertypes,$types) =
22152: &Apache::loncommon::sorted_inst_types($dom);
22153: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22154: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22155: my @sparestypes = ('primary','default');
22156: my %typetitles = &sparestype_titles();
22157: my $resulttext;
1.342 raeburn 22158: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22159: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22160: %existing = %{$domconfig{'loadbalancing'}};
22161: }
22162: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22163: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22164: my ($saveloadbalancing,%defaultshash,%changes);
22165: my ($alltypes,$othertypes,$titles) =
22166: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22167: my %ruletitles = &offloadtype_text();
22168: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22169: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22170: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22171: if ($balancer eq '') {
22172: next;
22173: }
1.210 raeburn 22174: if (!exists($servers{$balancer})) {
1.171 raeburn 22175: if (exists($currbalancer{$balancer})) {
22176: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22177: }
1.171 raeburn 22178: next;
22179: }
22180: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22181: push(@{$changes{'delete'}},$balancer);
22182: next;
22183: }
22184: if (!exists($currbalancer{$balancer})) {
22185: push(@{$changes{'add'}},$balancer);
22186: }
22187: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22188: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22189: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22190: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22191: $saveloadbalancing = 1;
22192: }
22193: foreach my $sparetype (@sparestypes) {
22194: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22195: my @offloadto;
22196: foreach my $target (@targets) {
22197: if (($servers{$target}) && ($target ne $balancer)) {
22198: if ($sparetype eq 'default') {
22199: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22200: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22201: }
22202: }
1.171 raeburn 22203: unless(grep(/^\Q$target\E$/,@offloadto)) {
22204: push(@offloadto,$target);
22205: }
1.150 raeburn 22206: }
22207: }
1.284 raeburn 22208: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22209: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22210: push(@offloadto,$balancer);
22211: }
22212: }
22213: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22214: }
1.342 raeburn 22215: if ($env{'form.loadbalancing_cookie_'.$i}) {
22216: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
22217: if (exists($currbalancer{$balancer})) {
22218: unless ($currcookies{$balancer}) {
22219: $changes{'curr'}{$balancer}{'cookie'} = 1;
22220: }
22221: }
22222: } elsif (exists($currbalancer{$balancer})) {
22223: if ($currcookies{$balancer}) {
22224: $changes{'curr'}{$balancer}{'cookie'} = 1;
22225: }
22226: }
1.171 raeburn 22227: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22228: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22229: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22230: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22231: if (@targetdiffs > 0) {
1.171 raeburn 22232: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22233: }
1.171 raeburn 22234: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22235: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22236: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22237: }
22238: }
22239: }
22240: } else {
1.171 raeburn 22241: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22242: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22243: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22244: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22245: $changes{'curr'}{$balancer}{'targets'} = 1;
22246: }
1.150 raeburn 22247: }
22248: }
1.210 raeburn 22249: }
1.150 raeburn 22250: }
22251: my $ishomedom;
1.171 raeburn 22252: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22253: $ishomedom = 1;
1.150 raeburn 22254: }
22255: if (ref($alltypes) eq 'ARRAY') {
22256: foreach my $type (@{$alltypes}) {
22257: my $rule;
1.210 raeburn 22258: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22259: (!$ishomedom)) {
1.171 raeburn 22260: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22261: }
22262: if ($rule eq 'specific') {
1.255 raeburn 22263: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22264: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22265: $rule = $specifiedhost;
22266: }
1.150 raeburn 22267: }
1.171 raeburn 22268: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22269: if (ref($currrules{$balancer}) eq 'HASH') {
22270: if ($rule ne $currrules{$balancer}{$type}) {
22271: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22272: }
22273: } elsif ($rule ne '') {
1.171 raeburn 22274: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22275: }
22276: }
22277: }
1.171 raeburn 22278: }
22279: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22280: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22281: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22282: $defaultshash{'loadbalancing'} = {};
22283: }
22284: my $putresult = &Apache::lonnet::put_dom('configuration',
22285: \%defaultshash,$dom);
22286: if ($putresult eq 'ok') {
22287: if (keys(%changes) > 0) {
1.252 raeburn 22288: my %toupdate;
1.171 raeburn 22289: if (ref($changes{'delete'}) eq 'ARRAY') {
22290: foreach my $balancer (sort(@{$changes{'delete'}})) {
22291: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22292: $toupdate{$balancer} = 1;
1.150 raeburn 22293: }
1.171 raeburn 22294: }
22295: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22296: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22297: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22298: $toupdate{$balancer} = 1;
1.171 raeburn 22299: }
22300: }
22301: if (ref($changes{'curr'}) eq 'HASH') {
22302: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22303: $toupdate{$balancer} = 1;
1.171 raeburn 22304: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22305: if ($changes{'curr'}{$balancer}{'targets'}) {
22306: my %offloadstr;
22307: foreach my $sparetype (@sparestypes) {
22308: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22309: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22310: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22311: }
22312: }
1.150 raeburn 22313: }
1.171 raeburn 22314: if (keys(%offloadstr) == 0) {
22315: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22316: } else {
1.171 raeburn 22317: my $showoffload;
22318: foreach my $sparetype (@sparestypes) {
22319: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22320: if (defined($offloadstr{$sparetype})) {
22321: $showoffload .= $offloadstr{$sparetype};
22322: } else {
22323: $showoffload .= &mt('None');
22324: }
22325: $showoffload .= (' 'x3);
22326: }
22327: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22328: }
22329: }
22330: }
1.171 raeburn 22331: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22332: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22333: foreach my $type (@{$alltypes}) {
22334: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22335: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22336: my $balancetext;
22337: if ($rule eq '') {
22338: $balancetext = $ruletitles{'default'};
1.209 raeburn 22339: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22340: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22341: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22342: foreach my $sparetype (@sparestypes) {
22343: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22344: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22345: }
22346: }
1.253 raeburn 22347: foreach my $item (@{$alltypes}) {
22348: next if ($item =~ /^_LC_ipchange/);
22349: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22350: if ($hasrule eq 'homeserver') {
22351: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22352: } else {
22353: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22354: if ($servers{$hasrule}) {
22355: $toupdate{$hasrule} = 1;
22356: }
22357: }
22358: }
22359: }
1.254 raeburn 22360: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22361: $balancetext = $ruletitles{$rule};
22362: } else {
22363: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22364: $balancetext = $ruletitles{'particular'}.' '.$receiver;
22365: if ($receiver) {
22366: $toupdate{$receiver};
22367: }
22368: }
22369: } else {
22370: $balancetext = $ruletitles{$rule};
1.252 raeburn 22371: }
1.171 raeburn 22372: } else {
22373: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
22374: }
1.210 raeburn 22375: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 22376: }
22377: }
22378: }
22379: }
1.342 raeburn 22380: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 22381: if ($currcookies{$balancer}) {
22382: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
22383: $balancer).'</li>';
22384: } else {
22385: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
22386: $balancer).'</li>';
22387: }
1.342 raeburn 22388: }
1.375 raeburn 22389: }
22390: }
22391: if (keys(%toupdate)) {
22392: my %thismachine;
22393: my $updatedhere;
22394: my $cachetime = 60*60*24;
22395: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
22396: foreach my $lonhost (keys(%toupdate)) {
22397: if ($thismachine{$lonhost}) {
22398: unless ($updatedhere) {
22399: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
22400: $defaultshash{'loadbalancing'},
22401: $cachetime);
22402: $updatedhere = 1;
1.252 raeburn 22403: }
1.375 raeburn 22404: } else {
22405: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
22406: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 22407: }
1.150 raeburn 22408: }
1.171 raeburn 22409: }
22410: if ($resulttext ne '') {
22411: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 22412: } else {
22413: $resulttext = $nochgmsg;
22414: }
22415: } else {
1.171 raeburn 22416: $resulttext = $nochgmsg;
1.150 raeburn 22417: }
22418: } else {
1.171 raeburn 22419: $resulttext = '<span class="LC_error">'.
22420: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 22421: }
22422: } else {
1.171 raeburn 22423: $resulttext = $nochgmsg;
1.150 raeburn 22424: }
22425: return $resulttext;
22426: }
22427:
1.48 raeburn 22428: sub recurse_check {
22429: my ($chkcats,$categories,$depth,$name) = @_;
22430: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
22431: my $chg = 0;
22432: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
22433: my $category = $chkcats->[$depth]{$name}[$j];
22434: my $item;
22435: if ($category eq '') {
22436: $chg ++;
22437: } else {
22438: my $deeper = $depth + 1;
22439: $item = &escape($category).':'.&escape($name).':'.$depth;
22440: if ($chg) {
22441: $categories->{$item} -= $chg;
22442: }
22443: &recurse_check($chkcats,$categories,$deeper,$category);
22444: $deeper --;
22445: }
22446: }
22447: }
22448: return;
22449: }
22450:
22451: sub recurse_cat_deletes {
22452: my ($item,$coursecategories,$deletions) = @_;
22453: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
22454: my $subdepth = $depth + 1;
22455: if (ref($coursecategories) eq 'HASH') {
22456: foreach my $subitem (keys(%{$coursecategories})) {
22457: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
22458: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
22459: delete($coursecategories->{$subitem});
22460: $deletions->{$subitem} = 1;
22461: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 22462: }
1.48 raeburn 22463: }
22464: }
22465: return;
22466: }
22467:
1.125 raeburn 22468: sub active_dc_picker {
1.191 raeburn 22469: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 22470: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 22471: my @domcoord = keys(%domcoords);
22472: if (keys(%currhash)) {
22473: foreach my $dc (keys(%currhash)) {
22474: unless (exists($domcoords{$dc})) {
22475: push(@domcoord,$dc);
22476: }
22477: }
22478: }
22479: @domcoord = sort(@domcoord);
1.210 raeburn 22480: my $numdcs = scalar(@domcoord);
1.191 raeburn 22481: my $rows = 0;
22482: my $table;
1.125 raeburn 22483: if ($numdcs > 1) {
1.191 raeburn 22484: $table = '<table>';
22485: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 22486: my $rem = $i%($numinrow);
22487: if ($rem == 0) {
22488: if ($i > 0) {
1.191 raeburn 22489: $table .= '</tr>';
1.125 raeburn 22490: }
1.191 raeburn 22491: $table .= '<tr>';
22492: $rows ++;
1.125 raeburn 22493: }
1.191 raeburn 22494: my $check = '';
22495: if ($inputtype eq 'radio') {
22496: if (keys(%currhash) == 0) {
22497: if (!$i) {
22498: $check = ' checked="checked"';
22499: }
22500: } elsif (exists($currhash{$domcoord[$i]})) {
22501: $check = ' checked="checked"';
22502: }
22503: } else {
22504: if (exists($currhash{$domcoord[$i]})) {
22505: $check = ' checked="checked"';
1.125 raeburn 22506: }
22507: }
1.191 raeburn 22508: if ($i == @domcoord - 1) {
1.125 raeburn 22509: my $colsleft = $numinrow - $rem;
22510: if ($colsleft > 1) {
1.191 raeburn 22511: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 22512: } else {
1.191 raeburn 22513: $table .= '<td class="LC_left_item">';
1.125 raeburn 22514: }
22515: } else {
1.191 raeburn 22516: $table .= '<td class="LC_left_item">';
22517: }
22518: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
22519: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
22520: $table .= '<span class="LC_nobreak"><label>'.
22521: '<input type="'.$inputtype.'" name="'.$name.'"'.
22522: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
22523: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 22524: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 22525: }
1.219 raeburn 22526: $table .= '</label></span></td>';
1.191 raeburn 22527: }
22528: $table .= '</tr></table>';
22529: } elsif ($numdcs == 1) {
1.219 raeburn 22530: my ($dcname,$dcdom) = split(':',$domcoord[0]);
22531: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 22532: if ($inputtype eq 'radio') {
1.247 raeburn 22533: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 22534: if ($user ne $dcname.':'.$dcdom) {
22535: $table .= ' ('.$dcname.':'.$dcdom.')';
22536: }
1.191 raeburn 22537: } else {
22538: my $check;
22539: if (exists($currhash{$domcoord[0]})) {
22540: $check = ' checked="checked"';
1.125 raeburn 22541: }
1.247 raeburn 22542: $table = '<span class="LC_nobreak"><label>'.
22543: '<input type="checkbox" name="'.$name.'" '.
22544: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 22545: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 22546: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 22547: }
1.220 raeburn 22548: $table .= '</label></span>';
1.191 raeburn 22549: $rows ++;
1.125 raeburn 22550: }
22551: }
1.191 raeburn 22552: return ($numdcs,$table,$rows);
1.125 raeburn 22553: }
22554:
1.137 raeburn 22555: sub usersession_titles {
22556: return &Apache::lonlocal::texthash(
22557: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
22558: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 22559: spares => 'Servers offloaded to, when busy',
1.137 raeburn 22560: version => 'LON-CAPA version requirement',
1.138 raeburn 22561: excludedomain => 'Allow all, but exclude specific domains',
22562: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 22563: primary => 'Primary (checked first)',
1.154 raeburn 22564: default => 'Default',
1.137 raeburn 22565: );
22566: }
22567:
1.152 raeburn 22568: sub id_for_thisdom {
22569: my (%servers) = @_;
22570: my %altids;
22571: foreach my $server (keys(%servers)) {
22572: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22573: if ($serverhome ne $server) {
22574: $altids{$serverhome} = $server;
22575: }
22576: }
22577: return %altids;
22578: }
22579:
1.150 raeburn 22580: sub count_servers {
22581: my ($currbalancer,%servers) = @_;
22582: my (@spares,$numspares);
22583: foreach my $lonhost (sort(keys(%servers))) {
22584: next if ($currbalancer eq $lonhost);
22585: push(@spares,$lonhost);
22586: }
22587: if ($currbalancer) {
22588: $numspares = scalar(@spares);
22589: } else {
22590: $numspares = scalar(@spares) - 1;
22591: }
22592: return ($numspares,@spares);
22593: }
22594:
22595: sub lonbalance_targets_js {
1.171 raeburn 22596: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 22597: my $select = &mt('Select');
22598: my ($alltargets,$allishome,$allinsttypes,@alltypes);
22599: if (ref($servers) eq 'HASH') {
22600: $alltargets = join("','",sort(keys(%{$servers})));
22601: my @homedoms;
22602: foreach my $server (sort(keys(%{$servers}))) {
22603: if (&Apache::lonnet::host_domain($server) eq $dom) {
22604: push(@homedoms,'1');
22605: } else {
22606: push(@homedoms,'0');
22607: }
22608: }
22609: $allishome = join("','",@homedoms);
22610: }
22611: if (ref($types) eq 'ARRAY') {
22612: if (@{$types} > 0) {
22613: @alltypes = @{$types};
22614: }
22615: }
22616: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
22617: $allinsttypes = join("','",@alltypes);
1.342 raeburn 22618: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22619: if (ref($settings) eq 'HASH') {
22620: %existing = %{$settings};
22621: }
22622: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 22623: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 22624: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 22625: return <<"END";
22626:
22627: <script type="text/javascript">
22628: // <![CDATA[
22629:
1.171 raeburn 22630: currBalancers = new Array('$balancers');
22631:
22632: function toggleTargets(balnum) {
22633: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22634: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
22635: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
22636: var prevbalancer = prevhostitem.value;
22637: var baltotal = document.getElementById('loadbalancing_total').value;
22638: prevhostitem.value = balancer;
22639: if (prevbalancer != '') {
22640: var prevIdx = currBalancers.indexOf(prevbalancer);
22641: if (prevIdx != -1) {
22642: currBalancers.splice(prevIdx,1);
22643: }
22644: }
1.150 raeburn 22645: if (balancer == '') {
1.171 raeburn 22646: hideSpares(balnum);
1.150 raeburn 22647: } else {
1.171 raeburn 22648: var currIdx = currBalancers.indexOf(balancer);
22649: if (currIdx == -1) {
22650: currBalancers.push(balancer);
22651: }
1.150 raeburn 22652: var homedoms = new Array('$allishome');
1.171 raeburn 22653: var ishomedom = homedoms[lonhostitem.selectedIndex];
22654: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 22655: }
1.171 raeburn 22656: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 22657: return;
22658: }
22659:
1.171 raeburn 22660: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 22661: var alltargets = new Array('$alltargets');
22662: var insttypes = new Array('$allinsttypes');
1.151 raeburn 22663: var offloadtypes = new Array('primary','default');
22664:
1.171 raeburn 22665: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
22666: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 22667:
1.151 raeburn 22668: for (var i=0; i<offloadtypes.length; i++) {
22669: var count = 0;
22670: for (var j=0; j<alltargets.length; j++) {
22671: if (alltargets[j] != balancer) {
1.171 raeburn 22672: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
22673: item.value = alltargets[j];
22674: item.style.textAlign='left';
22675: item.style.textFace='normal';
22676: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
22677: if (currBalancers.indexOf(alltargets[j]) == -1) {
22678: item.disabled = '';
22679: } else {
22680: item.disabled = 'disabled';
22681: item.checked = false;
22682: }
1.151 raeburn 22683: count ++;
22684: }
1.150 raeburn 22685: }
22686: }
1.151 raeburn 22687: for (var k=0; k<insttypes.length; k++) {
22688: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 22689: if (ishomedom == 1) {
1.171 raeburn 22690: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22691: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22692: } else {
1.171 raeburn 22693: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22694: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 22695: }
22696: } else {
1.171 raeburn 22697: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22698: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22699: }
1.151 raeburn 22700: if ((insttypes[k] != '_LC_external') &&
22701: ((insttypes[k] != '_LC_internetdom') ||
22702: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 22703: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
22704: item.options.length = 0;
22705: item.options[0] = new Option("","",true,true);
1.210 raeburn 22706: var idx = 0;
1.151 raeburn 22707: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 22708: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
22709: idx ++;
22710: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 22711: }
22712: }
22713: }
22714: }
22715: return;
22716: }
22717:
1.171 raeburn 22718: function hideSpares(balnum) {
1.150 raeburn 22719: var alltargets = new Array('$alltargets');
22720: var insttypes = new Array('$allinsttypes');
22721: var offloadtypes = new Array('primary','default');
22722:
1.171 raeburn 22723: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22724: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22725:
22726: var total = alltargets.length - 1;
22727: for (var i=0; i<offloadtypes; i++) {
22728: for (var j=0; j<total; j++) {
1.171 raeburn 22729: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22730: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22731: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22732: }
1.150 raeburn 22733: }
22734: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22735: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22736: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22737: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22738: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22739: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22740: }
22741: }
22742: return;
22743: }
22744:
1.171 raeburn 22745: function checkOffloads(item,balnum,type) {
1.150 raeburn 22746: var alltargets = new Array('$alltargets');
22747: var offloadtypes = new Array('primary','default');
22748: if (item.checked) {
22749: var total = alltargets.length - 1;
22750: var other;
22751: if (type == offloadtypes[0]) {
1.151 raeburn 22752: other = offloadtypes[1];
1.150 raeburn 22753: } else {
1.151 raeburn 22754: other = offloadtypes[0];
1.150 raeburn 22755: }
22756: for (var i=0; i<total; i++) {
1.171 raeburn 22757: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22758: if (server == item.value) {
1.171 raeburn 22759: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22760: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22761: }
22762: }
22763: }
22764: }
22765: return;
22766: }
22767:
1.171 raeburn 22768: function singleServerToggle(balnum,type) {
22769: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22770: if (offloadtoSelIdx == 0) {
1.171 raeburn 22771: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22772: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22773:
22774: } else {
1.171 raeburn 22775: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22776: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22777: }
22778: return;
22779: }
22780:
1.171 raeburn 22781: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22782: if (type == '_LC_external') {
1.171 raeburn 22783: return;
1.150 raeburn 22784: }
1.171 raeburn 22785: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22786: for (var i=0; i<typesRules.length; i++) {
22787: if (formname.elements[typesRules[i]].checked) {
22788: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22789: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22790: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22791: } else {
1.171 raeburn 22792: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22793: }
22794: }
22795: }
22796: return;
22797: }
22798:
22799: function balancerDeleteChange(balnum) {
22800: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22801: var baltotal = document.getElementById('loadbalancing_total').value;
22802: var addtarget;
22803: var removetarget;
22804: var action = 'delete';
22805: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22806: var lonhost = hostitem.value;
22807: var currIdx = currBalancers.indexOf(lonhost);
22808: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22809: if (currIdx != -1) {
22810: currBalancers.splice(currIdx,1);
22811: }
22812: addtarget = lonhost;
22813: } else {
22814: if (currIdx == -1) {
22815: currBalancers.push(lonhost);
22816: }
22817: removetarget = lonhost;
22818: action = 'undelete';
22819: }
22820: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22821: }
22822: return;
22823: }
22824:
22825: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22826: if (baltotal > 1) {
22827: var offloadtypes = new Array('primary','default');
22828: var alltargets = new Array('$alltargets');
22829: var insttypes = new Array('$allinsttypes');
22830: for (var i=0; i<baltotal; i++) {
22831: if (i != balnum) {
22832: for (var j=0; j<offloadtypes.length; j++) {
22833: var total = alltargets.length - 1;
22834: for (var k=0; k<total; k++) {
22835: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22836: var server = serveritem.value;
22837: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22838: if (server == addtarget) {
22839: serveritem.disabled = '';
22840: }
22841: }
22842: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22843: if (server == removetarget) {
22844: serveritem.disabled = 'disabled';
22845: serveritem.checked = false;
22846: }
22847: }
22848: }
22849: }
22850: for (var j=0; j<insttypes.length; j++) {
22851: if (insttypes[j] != '_LC_external') {
22852: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22853: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22854: var currSel = singleserver.selectedIndex;
22855: var currVal = singleserver.options[currSel].value;
22856: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22857: var numoptions = singleserver.options.length;
22858: var needsnew = 1;
22859: for (var k=0; k<numoptions; k++) {
22860: if (singleserver.options[k] == addtarget) {
22861: needsnew = 0;
22862: break;
22863: }
22864: }
22865: if (needsnew == 1) {
22866: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22867: }
22868: }
22869: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22870: singleserver.options.length = 0;
22871: if ((currVal) && (currVal != removetarget)) {
22872: singleserver.options[0] = new Option("","",false,false);
22873: } else {
22874: singleserver.options[0] = new Option("","",true,true);
22875: }
22876: var idx = 0;
22877: for (var m=0; m<alltargets.length; m++) {
22878: if (currBalancers.indexOf(alltargets[m]) == -1) {
22879: idx ++;
22880: if (currVal == alltargets[m]) {
22881: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22882: } else {
22883: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22884: }
22885: }
22886: }
22887: }
22888: }
22889: }
22890: }
1.150 raeburn 22891: }
22892: }
22893: }
22894: return;
22895: }
22896:
1.152 raeburn 22897: // ]]>
22898: </script>
22899:
22900: END
22901: }
22902:
1.372 raeburn 22903:
1.152 raeburn 22904: sub new_spares_js {
22905: my @sparestypes = ('primary','default');
22906: my $types = join("','",@sparestypes);
22907: my $select = &mt('Select');
22908: return <<"END";
22909:
22910: <script type="text/javascript">
22911: // <![CDATA[
22912:
22913: function updateNewSpares(formname,lonhost) {
22914: var types = new Array('$types');
22915: var include = new Array();
22916: var exclude = new Array();
22917: for (var i=0; i<types.length; i++) {
22918: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22919: for (var j=0; j<spareboxes.length; j++) {
22920: if (formname.elements[spareboxes[j]].checked) {
22921: exclude.push(formname.elements[spareboxes[j]].value);
22922: } else {
22923: include.push(formname.elements[spareboxes[j]].value);
22924: }
22925: }
22926: }
22927: for (var i=0; i<types.length; i++) {
22928: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22929: var selIdx = newSpare.selectedIndex;
22930: var currnew = newSpare.options[selIdx].value;
22931: var okSpares = new Array();
22932: for (var j=0; j<newSpare.options.length; j++) {
22933: var possible = newSpare.options[j].value;
22934: if (possible != '') {
22935: if (exclude.indexOf(possible) == -1) {
22936: okSpares.push(possible);
22937: } else {
22938: if (currnew == possible) {
22939: selIdx = 0;
22940: }
22941: }
22942: }
22943: }
22944: for (var k=0; k<include.length; k++) {
22945: if (okSpares.indexOf(include[k]) == -1) {
22946: okSpares.push(include[k]);
22947: }
22948: }
22949: okSpares.sort();
22950: newSpare.options.length = 0;
22951: if (selIdx == 0) {
22952: newSpare.options[0] = new Option("$select","",true,true);
22953: } else {
22954: newSpare.options[0] = new Option("$select","",false,false);
22955: }
22956: for (var m=0; m<okSpares.length; m++) {
22957: var idx = m+1;
22958: var selThis = 0;
22959: if (selIdx != 0) {
22960: if (okSpares[m] == currnew) {
22961: selThis = 1;
22962: }
22963: }
22964: if (selThis == 1) {
22965: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22966: } else {
22967: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22968: }
22969: }
22970: }
22971: return;
22972: }
22973:
22974: function checkNewSpares(lonhost,type) {
22975: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22976: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22977: if (chosen != '') {
1.152 raeburn 22978: var othertype;
22979: var othernewSpare;
22980: if (type == 'primary') {
22981: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22982: }
22983: if (type == 'default') {
22984: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22985: }
22986: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22987: othernewSpare.selectedIndex = 0;
22988: }
22989: }
22990: return;
22991: }
22992:
22993: // ]]>
22994: </script>
22995:
22996: END
22997:
22998: }
22999:
23000: sub common_domprefs_js {
23001: return <<"END";
23002:
23003: <script type="text/javascript">
23004: // <![CDATA[
23005:
1.150 raeburn 23006: function getIndicesByName(formname,item) {
1.152 raeburn 23007: var group = new Array();
1.150 raeburn 23008: for (var i=0;i<formname.elements.length;i++) {
23009: if (formname.elements[i].name == item) {
1.152 raeburn 23010: group.push(formname.elements[i].id);
1.150 raeburn 23011: }
23012: }
1.152 raeburn 23013: return group;
1.150 raeburn 23014: }
23015:
23016: // ]]>
23017: </script>
23018:
23019: END
1.152 raeburn 23020:
1.150 raeburn 23021: }
23022:
1.165 raeburn 23023: sub recaptcha_js {
23024: my %lt = &captcha_phrases();
23025: return <<"END";
23026:
23027: <script type="text/javascript">
23028: // <![CDATA[
23029:
23030: function updateCaptcha(caller,context) {
23031: var privitem;
23032: var pubitem;
23033: var privtext;
23034: var pubtext;
1.269 raeburn 23035: var versionitem;
23036: var versiontext;
1.165 raeburn 23037: if (document.getElementById(context+'_recaptchapub')) {
23038: pubitem = document.getElementById(context+'_recaptchapub');
23039: } else {
23040: return;
23041: }
23042: if (document.getElementById(context+'_recaptchapriv')) {
23043: privitem = document.getElementById(context+'_recaptchapriv');
23044: } else {
23045: return;
23046: }
23047: if (document.getElementById(context+'_recaptchapubtxt')) {
23048: pubtext = document.getElementById(context+'_recaptchapubtxt');
23049: } else {
23050: return;
23051: }
23052: if (document.getElementById(context+'_recaptchaprivtxt')) {
23053: privtext = document.getElementById(context+'_recaptchaprivtxt');
23054: } else {
23055: return;
23056: }
1.269 raeburn 23057: if (document.getElementById(context+'_recaptchaversion')) {
23058: versionitem = document.getElementById(context+'_recaptchaversion');
23059: } else {
23060: return;
23061: }
23062: if (document.getElementById(context+'_recaptchavertxt')) {
23063: versiontext = document.getElementById(context+'_recaptchavertxt');
23064: } else {
23065: return;
23066: }
1.165 raeburn 23067: if (caller.checked) {
23068: if (caller.value == 'recaptcha') {
23069: pubitem.type = 'text';
23070: privitem.type = 'text';
23071: pubitem.size = '40';
23072: privitem.size = '40';
23073: pubtext.innerHTML = "$lt{'pub'}";
23074: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23075: versionitem.type = 'text';
23076: versionitem.size = '3';
1.289 raeburn 23077: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23078: } else {
23079: pubitem.type = 'hidden';
23080: privitem.type = 'hidden';
1.269 raeburn 23081: versionitem.type = 'hidden';
1.165 raeburn 23082: pubtext.innerHTML = '';
23083: privtext.innerHTML = '';
1.269 raeburn 23084: versiontext.innerHTML = '';
1.165 raeburn 23085: }
23086: }
23087: return;
23088: }
23089:
23090: // ]]>
23091: </script>
23092:
23093: END
23094:
23095: }
23096:
1.236 raeburn 23097: sub toggle_display_js {
1.192 raeburn 23098: return <<"END";
23099:
23100: <script type="text/javascript">
23101: // <![CDATA[
23102:
1.236 raeburn 23103: function toggleDisplay(domForm,caller) {
23104: if (document.getElementById(caller)) {
23105: var divitem = document.getElementById(caller);
23106: var optionsElement = domForm.coursecredits;
1.264 raeburn 23107: var checkval = 1;
23108: var dispval = 'block';
1.303 raeburn 23109: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23110: if (caller == 'emailoptions') {
1.372 raeburn 23111: optionsElement = domForm.cancreate_email;
1.236 raeburn 23112: }
1.257 raeburn 23113: if (caller == 'studentsubmission') {
23114: optionsElement = domForm.postsubmit;
23115: }
1.264 raeburn 23116: if (caller == 'cloneinstcode') {
23117: optionsElement = domForm.canclone;
23118: checkval = 'instcode';
23119: }
1.303 raeburn 23120: if (selfcreateRegExp.test(caller)) {
23121: optionsElement = domForm.elements[caller];
23122: checkval = 'other';
23123: dispval = 'inline'
23124: }
1.236 raeburn 23125: if (optionsElement.length) {
1.192 raeburn 23126: var currval;
1.236 raeburn 23127: for (var i=0; i<optionsElement.length; i++) {
23128: if (optionsElement[i].checked) {
23129: currval = optionsElement[i].value;
1.192 raeburn 23130: }
23131: }
1.264 raeburn 23132: if (currval == checkval) {
23133: divitem.style.display = dispval;
1.192 raeburn 23134: } else {
1.236 raeburn 23135: divitem.style.display = 'none';
1.192 raeburn 23136: }
23137: }
23138: }
23139: return;
23140: }
23141:
23142: // ]]>
23143: </script>
23144:
23145: END
23146:
23147: }
23148:
1.165 raeburn 23149: sub captcha_phrases {
23150: return &Apache::lonlocal::texthash (
23151: priv => 'Private key',
23152: pub => 'Public key',
23153: original => 'original (CAPTCHA)',
23154: recaptcha => 'successor (ReCAPTCHA)',
23155: notused => 'unused',
1.289 raeburn 23156: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23157: );
23158: }
23159:
1.205 raeburn 23160: sub devalidate_remote_domconfs {
1.212 raeburn 23161: my ($dom,$cachekeys) = @_;
23162: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23163: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23164: my %thismachine;
23165: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23166: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23167: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
23168: 'ipaccess');
1.386 raeburn 23169: my %cache_by_lonhost;
23170: if (exists($cachekeys->{'samllanding'})) {
23171: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23172: my %landing = %{$cachekeys->{'samllanding'}};
23173: my %domservers = &Apache::lonnet::get_servers($dom);
23174: if (keys(%domservers)) {
23175: foreach my $server (keys(%domservers)) {
23176: my @cached;
23177: next if ($thismachine{$server});
23178: if ($landing{$server}) {
23179: push(@cached,&escape('samllanding').':'.&escape($server));
23180: }
23181: if (@cached) {
23182: $cache_by_lonhost{$server} = \@cached;
23183: }
23184: }
23185: }
23186: }
23187: }
1.260 raeburn 23188: if (keys(%servers)) {
1.205 raeburn 23189: foreach my $server (keys(%servers)) {
23190: next if ($thismachine{$server});
1.212 raeburn 23191: my @cached;
23192: foreach my $name (@posscached) {
23193: if ($cachekeys->{$name}) {
1.388 raeburn 23194: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23195: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23196: foreach my $key (keys(%{$cachekeys->{$name}})) {
23197: push(@cached,&escape($name).':'.&escape($key));
23198: }
23199: }
23200: } else {
23201: push(@cached,&escape($name).':'.&escape($dom));
23202: }
1.212 raeburn 23203: }
23204: }
1.386 raeburn 23205: if ((exists($cache_by_lonhost{$server})) &&
23206: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23207: push(@cached,@{$cache_by_lonhost{$server}});
23208: }
1.212 raeburn 23209: if (@cached) {
23210: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23211: }
1.205 raeburn 23212: }
23213: }
23214: return;
23215: }
23216:
1.3 raeburn 23217: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>