Annotation of loncom/interface/domainprefs.pm, revision 1.397
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.397 ! raeburn 4: # $Id: domainprefs.pm,v 1.396 2021/12/06 03:31:54 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.386 raeburn 880: } elsif ($action eq 'login') {
881: $output .= &saml_javascript();
1.394 raeburn 882: } elsif ($action eq 'ipaccess') {
883: $output .= &ipaccess_javascript($settings);
1.91 raeburn 884: }
1.236 raeburn 885: $output .=
1.30 raeburn 886: '<table class="LC_nested_outer">
1.3 raeburn 887: <tr>
1.306 raeburn 888: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 889: &mt($item->{text}).' '.
890: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
891: '</tr>';
1.30 raeburn 892: $rowtotal ++;
1.110 raeburn 893: my $numheaders = 1;
894: if (ref($item->{'header'}) eq 'ARRAY') {
895: $numheaders = scalar(@{$item->{'header'}});
896: }
897: if ($numheaders > 1) {
1.64 raeburn 898: my $colspan = '';
1.145 raeburn 899: my $rightcolspan = '';
1.369 raeburn 900: my $leftnobr = '';
1.238 raeburn 901: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 902: ($action eq 'directorysrch') ||
1.386 raeburn 903: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 904: $colspan = ' colspan="2"';
905: }
1.145 raeburn 906: if ($action eq 'usersessions') {
907: $rightcolspan = ' colspan="3"';
908: }
1.369 raeburn 909: if ($action eq 'passwords') {
910: $leftnobr = ' LC_nobreak';
911: }
1.30 raeburn 912: $output .= '
1.3 raeburn 913: <tr>
914: <td>
915: <table class="LC_nested">
916: <tr class="LC_info_row">
1.369 raeburn 917: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 918: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 919: </tr>';
1.69 raeburn 920: $rowtotal ++;
1.230 raeburn 921: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 922: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 923: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 924: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.373 raeburn 925: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy')) {
1.230 raeburn 926: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 927: } elsif ($action eq 'passwords') {
928: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 929: } elsif ($action eq 'coursecategories') {
1.230 raeburn 930: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 931: } elsif ($action eq 'scantron') {
932: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 933: } elsif ($action eq 'login') {
1.386 raeburn 934: if ($numheaders == 5) {
1.168 raeburn 935: $colspan = ' colspan="2"';
936: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
937: } else {
938: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
939: }
1.230 raeburn 940: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 941: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 942: } elsif ($action eq 'rolecolors') {
1.30 raeburn 943: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 944: }
1.30 raeburn 945: $output .= '
1.6 raeburn 946: </table>
947: </td>
948: </tr>
949: <tr>
950: <td>
951: <table class="LC_nested">
952: <tr class="LC_info_row">
1.230 raeburn 953: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 954: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 955: </tr>';
956: $rowtotal ++;
1.230 raeburn 957: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
958: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 959: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 960: ($action eq 'trust') || ($action eq 'contacts') ||
961: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 962: if ($action eq 'coursecategories') {
963: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
964: $colspan = ' colspan="2"';
1.279 raeburn 965: } elsif ($action eq 'trust') {
966: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 967: } elsif ($action eq 'passwords') {
968: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 969: } else {
970: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
971: }
1.279 raeburn 972: if ($action eq 'trust') {
973: $output .= '
974: </table>
975: </td>
976: </tr>';
977: my @trusthdrs = qw(2 3 4 5 6 7);
978: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
979: for (my $i=0; $i<@trusthdrs; $i++) {
980: $output .= '
981: <tr>
982: <td>
983: <table class="LC_nested">
984: <tr class="LC_info_row">
985: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
986: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
987: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
988: </table>
989: </td>
990: </tr>';
991: }
992: $output .= '
993: <tr>
994: <td>
995: <table class="LC_nested">
996: <tr class="LC_info_row">
997: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
998: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
999: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1000: } else {
1001: $output .= '
1.63 raeburn 1002: </table>
1003: </td>
1004: </tr>
1005: <tr>
1006: <td>
1007: <table class="LC_nested">
1008: <tr class="LC_info_row">
1009: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1010: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1011: </tr>'."\n";
1.279 raeburn 1012: if ($action eq 'coursecategories') {
1013: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 1014: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 1015: if ($action eq 'passwords') {
1016: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1017: } else {
1018: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1019: }
1020: $output .= '
1.340 raeburn 1021: </tr>
1022: </table>
1023: </td>
1024: </tr>
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">
1.369 raeburn 1029: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1030: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1031: if ($action eq 'passwords') {
1032: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1033: } else {
1034: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1035: }
1036: $output .= '
1.340 raeburn 1037: </table>
1038: </td>
1039: </tr>
1040: <tr>';
1.279 raeburn 1041: } else {
1042: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1043: }
1.238 raeburn 1044: }
1.63 raeburn 1045: $rowtotal ++;
1.236 raeburn 1046: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 1047: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.373 raeburn 1048: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.230 raeburn 1049: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1050: } elsif ($action eq 'scantron') {
1051: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1052: } elsif ($action eq 'ssl') {
1053: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1054: </table>
1055: </td>
1056: </tr>
1057: <tr>
1058: <td>
1059: <table class="LC_nested">
1060: <tr class="LC_info_row">
1061: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1062: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1063: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1064: </table>
1065: </td>
1066: </tr>
1067: <tr>
1068: <td>
1069: <table class="LC_nested">
1070: <tr class="LC_info_row">
1071: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1072: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1073: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1074: } elsif ($action eq 'login') {
1.386 raeburn 1075: if ($numheaders == 5) {
1.168 raeburn 1076: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1077: </table>
1078: </td>
1079: </tr>
1080: <tr>
1081: <td>
1082: <table class="LC_nested">
1083: <tr class="LC_info_row">
1084: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1085: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1086: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1087: $rowtotal ++;
1088: } else {
1089: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1090: }
1.256 raeburn 1091: $output .= '
1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">';
1.386 raeburn 1099: if ($numheaders == 5) {
1.256 raeburn 1100: $output .= '
1101: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1102: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1103: </tr>';
1104: } else {
1105: $output .= '
1106: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1107: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1108: </tr>';
1109: }
1110: $rowtotal ++;
1.386 raeburn 1111: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1112: </table>
1113: </td>
1114: </tr>
1115: <tr>
1116: <td>
1117: <table class="LC_nested">
1118: <tr class="LC_info_row">';
1119: if ($numheaders == 5) {
1120: $output .= '
1121: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1122: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1123: </tr>';
1124: } else {
1125: $output .= '
1126: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1127: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1128: </tr>';
1129: }
1130: $rowtotal ++;
1131: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1132: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1133: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1134: $rowtotal ++;
1135: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1136: </table>
1137: </td>
1138: </tr>
1139: <tr>
1140: <td>
1141: <table class="LC_nested">
1142: <tr class="LC_info_row">
1143: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1144: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1145: &textbookcourses_javascript($settings).
1146: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1147: </table>
1148: </td>
1149: </tr>
1150: <tr>
1151: <td>
1152: <table class="LC_nested">
1153: <tr class="LC_info_row">
1154: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1155: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1156: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1157: </table>
1158: </td>
1159: </tr>
1160: <tr>
1161: <td>
1162: <table class="LC_nested">
1163: <tr class="LC_info_row">
1.306 raeburn 1164: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1165: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1166: </tr>'.
1167: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1168: } elsif ($action eq 'requestauthor') {
1169: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1170: $rowtotal ++;
1.122 jms 1171: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1172: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1173: </table>
1174: </td>
1175: </tr>
1176: <tr>
1177: <td>
1178: <table class="LC_nested">
1179: <tr class="LC_info_row">
1.306 raeburn 1180: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1181: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1182: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1183: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1184: </tr>'.
1.30 raeburn 1185: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">
1.59 bisitz 1193: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1194: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1195: </tr>'.
1.30 raeburn 1196: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1197: $rowtotal += 2;
1.6 raeburn 1198: }
1.3 raeburn 1199: } else {
1.30 raeburn 1200: $output .= '
1.3 raeburn 1201: <tr>
1202: <td>
1203: <table class="LC_nested">
1.30 raeburn 1204: <tr class="LC_info_row">';
1.277 raeburn 1205: if ($action eq 'login') {
1.30 raeburn 1206: $output .= '
1.59 bisitz 1207: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1208: } elsif ($action eq 'serverstatuses') {
1209: $output .= '
1.306 raeburn 1210: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1211: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1212:
1.6 raeburn 1213: } else {
1.30 raeburn 1214: $output .= '
1.306 raeburn 1215: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1216: }
1.72 raeburn 1217: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1218: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1219: &mt($item->{'header'}->[0]->{'col2'});
1220: if ($action eq 'serverstatuses') {
1221: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1222: }
1.69 raeburn 1223: } else {
1.306 raeburn 1224: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1225: &mt($item->{'header'}->[0]->{'col2'});
1226: }
1227: $output .= '</td>';
1228: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1229: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1230: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1231: &mt($item->{'header'}->[0]->{'col3'});
1232: } else {
1.306 raeburn 1233: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1234: &mt($item->{'header'}->[0]->{'col3'});
1235: }
1.69 raeburn 1236: if ($action eq 'serverstatuses') {
1237: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1238: }
1239: $output .= '</td>';
1.6 raeburn 1240: }
1.150 raeburn 1241: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1242: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1243: &mt($item->{'header'}->[0]->{'col4'});
1244: }
1.69 raeburn 1245: $output .= '</tr>';
1.48 raeburn 1246: $rowtotal ++;
1.168 raeburn 1247: if ($action eq 'quotas') {
1.86 raeburn 1248: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1249: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1250: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.372 raeburn 1251: ($action eq 'ltitools') || ($action eq 'lti') ||
1.394 raeburn 1252: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1253: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1254: }
1.3 raeburn 1255: }
1.30 raeburn 1256: $output .= '
1.3 raeburn 1257: </table>
1258: </td>
1259: </tr>
1.30 raeburn 1260: </table><br />';
1261: return ($output,$rowtotal);
1.1 raeburn 1262: }
1263:
1.3 raeburn 1264: sub print_login {
1.168 raeburn 1265: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1266: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1267: my %choices = &login_choices();
1.386 raeburn 1268: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1269: %lt = &login_file_options();
1270: $switchserver = &check_switchserver($dom,$confname);
1271: }
1.168 raeburn 1272: if ($caller eq 'service') {
1.149 raeburn 1273: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1274: my $choice = $choices{'disallowlogin'};
1275: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1276: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1277: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1278: '<th>'.$choices{'server'}.'</th>'.
1279: '<th>'.$choices{'serverpath'}.'</th>'.
1280: '<th>'.$choices{'custompath'}.'</th>'.
1281: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1282: my %disallowed;
1283: if (ref($settings) eq 'HASH') {
1284: if (ref($settings->{'loginvia'}) eq 'HASH') {
1285: %disallowed = %{$settings->{'loginvia'}};
1286: }
1287: }
1288: foreach my $lonhost (sort(keys(%servers))) {
1289: my $direct = 'selected="selected"';
1.128 raeburn 1290: if (ref($disallowed{$lonhost}) eq 'HASH') {
1291: if ($disallowed{$lonhost}{'server'} ne '') {
1292: $direct = '';
1293: }
1.110 raeburn 1294: }
1.115 raeburn 1295: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1296: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1297: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1298: '</option>';
1.184 raeburn 1299: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1300: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1301: my $selected = '';
1.128 raeburn 1302: if (ref($disallowed{$lonhost}) eq 'HASH') {
1303: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1304: $selected = 'selected="selected"';
1305: }
1.110 raeburn 1306: }
1307: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1308: $servers{$hostid}.'</option>';
1309: }
1.128 raeburn 1310: $datatable .= '</select></td>'.
1311: '<td><select name="'.$lonhost.'_serverpath">';
1312: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1313: my $pathname = $path;
1314: if ($path eq 'custom') {
1315: $pathname = &mt('Custom Path').' ->';
1316: }
1317: my $selected = '';
1318: if (ref($disallowed{$lonhost}) eq 'HASH') {
1319: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1320: $selected = 'selected="selected"';
1321: }
1322: } elsif ($path eq '') {
1323: $selected = 'selected="selected"';
1324: }
1325: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1326: }
1327: $datatable .= '</select></td>';
1328: my ($custom,$exempt);
1329: if (ref($disallowed{$lonhost}) eq 'HASH') {
1330: $custom = $disallowed{$lonhost}{'custompath'};
1331: $exempt = $disallowed{$lonhost}{'exempt'};
1332: }
1333: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1334: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1335: '</tr>';
1.110 raeburn 1336: }
1337: $datatable .= '</table></td></tr>';
1338: return $datatable;
1.168 raeburn 1339: } elsif ($caller eq 'page') {
1340: my %defaultchecked = (
1341: 'coursecatalog' => 'on',
1.188 raeburn 1342: 'helpdesk' => 'on',
1.168 raeburn 1343: 'adminmail' => 'off',
1344: 'newuser' => 'off',
1345: );
1.188 raeburn 1346: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1347: my (%checkedon,%checkedoff);
1.42 raeburn 1348: foreach my $item (@toggles) {
1.168 raeburn 1349: if ($defaultchecked{$item} eq 'on') {
1350: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1351: $checkedoff{$item} = ' ';
1.168 raeburn 1352: } elsif ($defaultchecked{$item} eq 'off') {
1353: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1354: $checkedon{$item} = ' ';
1355: }
1.1 raeburn 1356: }
1.168 raeburn 1357: my @images = ('img','logo','domlogo','login');
1358: my @logintext = ('textcol','bgcol');
1359: my @bgs = ('pgbg','mainbg','sidebg');
1360: my @links = ('link','alink','vlink');
1361: my %designhash = &Apache::loncommon::get_domainconf($dom);
1362: my %defaultdesign = %Apache::loncommon::defaultdesign;
1363: my (%is_custom,%designs);
1364: my %defaults = (
1365: font => $defaultdesign{'login.font'},
1366: );
1.6 raeburn 1367: foreach my $item (@images) {
1.168 raeburn 1368: $defaults{$item} = $defaultdesign{'login.'.$item};
1369: $defaults{'showlogo'}{$item} = 1;
1370: }
1371: foreach my $item (@bgs) {
1372: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1373: }
1.41 raeburn 1374: foreach my $item (@logintext) {
1.168 raeburn 1375: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1376: }
1.168 raeburn 1377: foreach my $item (@links) {
1378: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1379: }
1.168 raeburn 1380: if (ref($settings) eq 'HASH') {
1381: foreach my $item (@toggles) {
1382: if ($settings->{$item} eq '1') {
1383: $checkedon{$item} = ' checked="checked" ';
1384: $checkedoff{$item} = ' ';
1385: } elsif ($settings->{$item} eq '0') {
1386: $checkedoff{$item} = ' checked="checked" ';
1387: $checkedon{$item} = ' ';
1388: }
1389: }
1390: foreach my $item (@images) {
1391: if (defined($settings->{$item})) {
1392: $designs{$item} = $settings->{$item};
1393: $is_custom{$item} = 1;
1394: }
1395: if (defined($settings->{'showlogo'}{$item})) {
1396: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1397: }
1398: }
1399: foreach my $item (@logintext) {
1400: if ($settings->{$item} ne '') {
1401: $designs{'logintext'}{$item} = $settings->{$item};
1402: $is_custom{$item} = 1;
1403: }
1404: }
1405: if ($settings->{'font'} ne '') {
1406: $designs{'font'} = $settings->{'font'};
1407: $is_custom{'font'} = 1;
1408: }
1409: foreach my $item (@bgs) {
1410: if ($settings->{$item} ne '') {
1411: $designs{'bgs'}{$item} = $settings->{$item};
1412: $is_custom{$item} = 1;
1413: }
1414: }
1415: foreach my $item (@links) {
1416: if ($settings->{$item} ne '') {
1417: $designs{'links'}{$item} = $settings->{$item};
1418: $is_custom{$item} = 1;
1419: }
1420: }
1421: } else {
1422: if ($designhash{$dom.'.login.font'} ne '') {
1423: $designs{'font'} = $designhash{$dom.'.login.font'};
1424: $is_custom{'font'} = 1;
1425: }
1426: foreach my $item (@images) {
1427: if ($designhash{$dom.'.login.'.$item} ne '') {
1428: $designs{$item} = $designhash{$dom.'.login.'.$item};
1429: $is_custom{$item} = 1;
1430: }
1431: }
1432: foreach my $item (@bgs) {
1433: if ($designhash{$dom.'.login.'.$item} ne '') {
1434: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1435: $is_custom{$item} = 1;
1436: }
1.6 raeburn 1437: }
1.168 raeburn 1438: foreach my $item (@links) {
1439: if ($designhash{$dom.'.login.'.$item} ne '') {
1440: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1441: $is_custom{$item} = 1;
1442: }
1.6 raeburn 1443: }
1444: }
1.168 raeburn 1445: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1446: logo => 'Institution Logo',
1447: domlogo => 'Domain Logo',
1448: login => 'Login box');
1449: my $itemcount = 1;
1450: foreach my $item (@toggles) {
1451: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1452: $datatable .=
1453: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1454: '</td><td>'.
1455: '<span class="LC_nobreak"><label><input type="radio" name="'.
1456: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1457: '</label> <label><input type="radio" name="'.$item.'"'.
1458: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1459: '</tr>';
1460: $itemcount ++;
1.6 raeburn 1461: }
1.168 raeburn 1462: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1463: $datatable .= '</tr></table></td></tr>';
1464: } elsif ($caller eq 'help') {
1.386 raeburn 1465: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1466: my $itemcount = 1;
1467: $defaulturl = '/adm/loginproblems.html';
1468: $defaulttype = 'default';
1469: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1470: my @currlangs;
1471: if (ref($settings) eq 'HASH') {
1472: if (ref($settings->{'helpurl'}) eq 'HASH') {
1473: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1474: next if ($settings->{'helpurl'}{$key} eq '');
1475: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1476: $type{$key} = 'custom';
1477: unless ($key eq 'nolang') {
1478: push(@currlangs,$key);
1479: }
1480: }
1481: } elsif ($settings->{'helpurl'} ne '') {
1482: $type{'nolang'} = 'custom';
1483: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1484: }
1485: }
1.168 raeburn 1486: foreach my $lang ('nolang',sort(@currlangs)) {
1487: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1488: $datatable .= '<tr'.$css_class.'>';
1489: if ($url{$lang} eq '') {
1490: $url{$lang} = $defaulturl;
1491: }
1492: if ($type{$lang} eq '') {
1493: $type{$lang} = $defaulttype;
1494: }
1495: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1496: if ($lang eq 'nolang') {
1497: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1498: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1499: } else {
1500: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1501: $langchoices{$lang},
1502: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1503: }
1504: $datatable .= '</span></td>'."\n".
1505: '<td class="LC_left_item">';
1506: if ($type{$lang} eq 'custom') {
1507: $datatable .= '<span class="LC_nobreak"><label>'.
1508: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1509: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1510: } else {
1511: $datatable .= $lt{'upl'};
1512: }
1513: $datatable .='<br />';
1514: if ($switchserver) {
1515: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1516: } else {
1517: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1518: }
1.168 raeburn 1519: $datatable .= '</td></tr>';
1520: $itemcount ++;
1.6 raeburn 1521: }
1.168 raeburn 1522: my @addlangs;
1523: foreach my $lang (sort(keys(%langchoices))) {
1524: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1525: push(@addlangs,$lang);
1526: }
1527: if (@addlangs > 0) {
1528: my %toadd;
1529: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1530: $toadd{''} = &mt('Select');
1531: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1532: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1533: &mt('Add log-in help page for a specific language:').' '.
1534: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1535: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1536: if ($switchserver) {
1537: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1538: } else {
1539: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1540: }
1.168 raeburn 1541: $datatable .= '</td></tr>';
1.169 raeburn 1542: $itemcount ++;
1.6 raeburn 1543: }
1.169 raeburn 1544: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1545: } elsif ($caller eq 'headtag') {
1546: my %domservers = &Apache::lonnet::get_servers($dom);
1547: my $choice = $choices{'headtag'};
1548: $css_class = ' class="LC_odd_row"';
1549: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1550: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1551: '<th>'.$choices{'current'}.'</th>'.
1552: '<th>'.$choices{'action'}.'</th>'.
1553: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1554: my (%currurls,%currexempt);
1555: if (ref($settings) eq 'HASH') {
1556: if (ref($settings->{'headtag'}) eq 'HASH') {
1557: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1558: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1559: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1560: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1561: }
1562: }
1563: }
1564: }
1565: foreach my $lonhost (sort(keys(%domservers))) {
1566: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1567: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1568: if ($currurls{$lonhost}) {
1569: $datatable .= '<td class="LC_right_item"><a href="'.
1570: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1571: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1572: '">'.$lt{'curr'}.'</a></td>'.
1573: '<td><span class="LC_nobreak"><label>'.
1574: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1575: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1576: } else {
1577: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1578: }
1579: $datatable .='<br />';
1580: if ($switchserver) {
1581: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1582: } else {
1583: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1584: }
1.330 raeburn 1585: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1586: }
1587: $datatable .= '</table></td></tr>';
1.386 raeburn 1588: } elsif ($caller eq 'saml') {
1589: my %domservers = &Apache::lonnet::get_servers($dom);
1590: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1591: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1592: '<th>'.$choices{'samllanding'}.'</th>'.
1593: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1594: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1595: foreach my $lonhost (keys(%domservers)) {
1596: $samlurl{$lonhost} = '/adm/sso';
1597: $styleon{$lonhost} = 'display:none';
1598: $styleoff{$lonhost} = '';
1599: }
1600: if (ref($settings->{'saml'}) eq 'HASH') {
1601: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1602: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1603: $saml{$lonhost} = 1;
1604: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1605: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1606: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1607: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1608: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1609: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1610: $styleon{$lonhost} = '';
1611: $styleoff{$lonhost} = 'display:none';
1612: } else {
1613: $styleon{$lonhost} = 'display:none';
1614: $styleoff{$lonhost} = '';
1615: }
1616: }
1617: }
1618: my $itemcount = 1;
1619: foreach my $lonhost (sort(keys(%domservers))) {
1620: my $samlon = ' ';
1621: my $samloff = ' checked="checked" ';
1622: if ($saml{$lonhost}) {
1623: $samlon = $samloff;
1624: $samloff = ' ';
1625: }
1626: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1627: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1628: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1629: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1630: &mt('No').'</label>'.(' 'x2).
1631: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1632: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1633: &mt('Yes').'</label></span></td>'.
1634: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1635: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1636: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1637: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1638: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1639: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1640: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1641: $samltext{$lonhost}.'" /></td><td>';
1642: if ($samlimg{$lonhost}) {
1643: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1644: '<span class="LC_nobreak"><label>'.
1645: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1646: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1647: } else {
1648: $datatable .= $lt{'upl'};
1649: }
1650: $datatable .='<br />';
1651: if ($switchserver) {
1652: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1653: } else {
1654: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1655: }
1656: $datatable .= '</td>'.
1657: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1658: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1659: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1660: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1661: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1662: $samltitle{$lonhost}.'</textarea></td>'.
1663: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1664: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1665: '</table></td>'.
1666: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1667: $itemcount ++;
1668: }
1669: $datatable .= '</table></td></tr>';
1.1 raeburn 1670: }
1.6 raeburn 1671: return $datatable;
1672: }
1673:
1674: sub login_choices {
1675: my %choices =
1676: &Apache::lonlocal::texthash (
1.116 bisitz 1677: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1678: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1679: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1680: disallowlogin => "Login page requests redirected",
1681: hostid => "Server",
1.128 raeburn 1682: server => "Redirect to:",
1683: serverpath => "Path",
1684: custompath => "Custom",
1685: exempt => "Exempt IP(s)",
1.110 raeburn 1686: directlogin => "No redirect",
1687: newuser => "Link to create a user account",
1688: img => "Header",
1689: logo => "Main Logo",
1690: domlogo => "Domain Logo",
1691: login => "Log-in Header",
1692: textcol => "Text color",
1693: bgcol => "Box color",
1694: bgs => "Background colors",
1695: links => "Link colors",
1696: font => "Font color",
1697: pgbg => "Header",
1698: mainbg => "Page",
1699: sidebg => "Login box",
1700: link => "Link",
1701: alink => "Active link",
1702: vlink => "Visited link",
1.256 raeburn 1703: headtag => "Custom markup",
1704: action => "Action",
1705: current => "Current",
1.386 raeburn 1706: samllanding => "Dual login?",
1707: samloptions => "Options",
1.6 raeburn 1708: );
1709: return %choices;
1710: }
1711:
1.386 raeburn 1712: sub login_file_options {
1713: return &Apache::lonlocal::texthash(
1714: del => 'Delete?',
1715: rep => 'Replace:',
1716: upl => 'Upload:',
1717: curr => 'View contents',
1718: default => 'Default',
1719: custom => 'Custom',
1720: none => 'None',
1721: );
1722: }
1723:
1.394 raeburn 1724: sub print_ipaccess {
1725: my ($dom,$settings,$rowtotal) = @_;
1726: my $css_class;
1727: my $itemcount = 0;
1728: my $datatable;
1729: my %ordered;
1730: if (ref($settings) eq 'HASH') {
1731: foreach my $item (keys(%{$settings})) {
1732: if (ref($settings->{$item}) eq 'HASH') {
1733: my $num = $settings->{$item}{'order'};
1734: if ($num eq '') {
1735: $num = scalar(keys(%{$settings}));
1736: }
1737: $ordered{$num} = $item;
1738: }
1739: }
1740: }
1741: my $maxnum = scalar(keys(%ordered));
1742: if (keys(%ordered)) {
1743: my @items = sort { $a <=> $b } keys(%ordered);
1744: for (my $i=0; $i<@items; $i++) {
1745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1746: my $item = $ordered{$items[$i]};
1747: my ($name,$ipranges,%commblocks,%courses);
1748: if (ref($settings->{$item}) eq 'HASH') {
1749: $name = $settings->{$item}->{'name'};
1750: $ipranges = $settings->{$item}->{'ip'};
1751: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1752: %commblocks = %{$settings->{$item}->{'commblocks'}};
1753: }
1754: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1755: %courses = %{$settings->{$item}->{'courses'}};
1756: }
1757: }
1758: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1759: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1760: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1761: for (my $k=0; $k<=$maxnum; $k++) {
1762: my $vpos = $k+1;
1763: my $selstr;
1764: if ($k == $i) {
1765: $selstr = ' selected="selected" ';
1766: }
1767: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1768: }
1769: $datatable .= '</select>'.(' 'x2).
1770: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1771: &mt('Delete?').'</label></span></td>'.
1772: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1773: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1774: '</td></tr>';
1775: $itemcount ++;
1776: }
1777: }
1778: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1779: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1780: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1781: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1782: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1783: for (my $k=0; $k<$maxnum+1; $k++) {
1784: my $vpos = $k+1;
1785: my $selstr;
1786: if ($k == $maxnum) {
1787: $selstr = ' selected="selected" ';
1788: }
1789: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1790: }
1791: $datatable .= '</select> '."\n".
1792: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1793: '<td colspan="2">'.
1794: &ipaccess_options('add',$itemcount,$dom).
1795: '</td>'."\n".
1796: '</tr>'."\n";
1797: $$rowtotal ++;
1798: return $datatable;
1799: }
1800:
1801: sub ipaccess_options {
1802: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1803: my (%currblocks,%currcourses,$output);
1804: if (ref($blocksref) eq 'HASH') {
1805: %currblocks = %{$blocksref};
1806: }
1807: if (ref($coursesref) eq 'HASH') {
1808: %currcourses = %{$coursesref};
1809: }
1810: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1811: '<span class="LC_nobreak">'.&mt('Name').': '.
1812: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1813: '</span></fieldset>'.
1814: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1815: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1816: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1817: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1818: $ipranges.'</textarea></fieldset>'.
1819: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1820: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1821: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1822: '<table>';
1823: foreach my $cid (sort(keys(%currcourses))) {
1824: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1825: $output .= '<tr><td><span class="LC_nobreak">'.
1826: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1827: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1828: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1829: }
1830: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1831: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1832: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1833: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1834: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1835: '</span></td></tr></table>'."\n".
1836: '</fieldset>';
1837: return $output;
1838: }
1839:
1840: sub blocker_checkboxes {
1841: my ($num,$blocks) = @_;
1842: my ($typeorder,$types) = &commblocktype_text();
1843: my $numinrow = 6;
1844: my $output = '<table>';
1845: for (my $i=0; $i<@{$typeorder}; $i++) {
1846: my $block = $typeorder->[$i];
1847: my $blockstatus;
1848: if (ref($blocks) eq 'HASH') {
1849: if ($blocks->{$block} eq 'on') {
1850: $blockstatus = 'checked="checked"';
1851: }
1852: }
1853: my $rem = $i%($numinrow);
1854: if ($rem == 0) {
1855: if ($i > 0) {
1856: $output .= '</tr>';
1857: }
1858: $output .= '<tr>';
1859: }
1860: if ($i == scalar(@{$typeorder})-1) {
1861: my $colsleft = $numinrow-$rem;
1862: if ($colsleft > 1) {
1863: $output .= '<td colspan="'.$colsleft.'">';
1864: } else {
1865: $output .= '<td>';
1866: }
1867: } else {
1868: $output .= '<td>';
1869: }
1870: my $item = 'ipaccess_block_'.$num;
1871: if ($blockstatus) {
1872: $blockstatus = ' '.$blockstatus;
1873: }
1874: $output .= '<span class="LC_nobreak"><label>'."\n".
1875: '<input type="checkbox" name="'.$item.'"'.
1876: $blockstatus.' value="'.$block.'"'.' />'.
1877: $types->{$block}.'</label></span>'."\n".
1878: '<br /></td>';
1879: }
1880: $output .= '</tr></table>';
1881: return $output;
1882: }
1883:
1884: sub commblocktype_text {
1885: my %types = &Apache::lonlocal::texthash(
1886: 'com' => 'Messaging',
1887: 'chat' => 'Chat Room',
1888: 'boards' => 'Discussion',
1889: 'port' => 'Portfolio',
1890: 'groups' => 'Groups',
1891: 'blogs' => 'Blogs',
1892: 'about' => 'User Information',
1893: 'printout' => 'Printouts',
1894: 'passwd' => 'Change Password',
1895: 'grades' => 'Gradebook',
1.397 ! raeburn 1896: 'search' => 'Course search',
! 1897: 'wishlist' => 'Stored links',
! 1898: 'annotate' => 'Annotations',
1.394 raeburn 1899: );
1.397 ! raeburn 1900: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1901: return ($typeorder,\%types);
1902: }
1903:
1.6 raeburn 1904: sub print_rolecolors {
1.30 raeburn 1905: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1906: my %choices = &color_font_choices();
1907: my @bgs = ('pgbg','tabbg','sidebg');
1908: my @links = ('link','alink','vlink');
1909: my @images = ('img');
1910: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1911: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1912: my %defaultdesign = %Apache::loncommon::defaultdesign;
1913: my (%is_custom,%designs);
1.200 raeburn 1914: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1915: if (ref($settings) eq 'HASH') {
1916: if (ref($settings->{$role}) eq 'HASH') {
1917: if ($settings->{$role}->{'img'} ne '') {
1918: $designs{'img'} = $settings->{$role}->{'img'};
1919: $is_custom{'img'} = 1;
1920: }
1921: if ($settings->{$role}->{'font'} ne '') {
1922: $designs{'font'} = $settings->{$role}->{'font'};
1923: $is_custom{'font'} = 1;
1924: }
1.97 tempelho 1925: if ($settings->{$role}->{'fontmenu'} ne '') {
1926: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1927: $is_custom{'fontmenu'} = 1;
1928: }
1.6 raeburn 1929: foreach my $item (@bgs) {
1930: if ($settings->{$role}->{$item} ne '') {
1931: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1932: $is_custom{$item} = 1;
1933: }
1934: }
1935: foreach my $item (@links) {
1936: if ($settings->{$role}->{$item} ne '') {
1937: $designs{'links'}{$item} = $settings->{$role}->{$item};
1938: $is_custom{$item} = 1;
1939: }
1940: }
1941: }
1942: } else {
1943: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1944: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1945: $is_custom{'img'} = 1;
1946: }
1.97 tempelho 1947: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1948: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1949: $is_custom{'fontmenu'} = 1;
1950: }
1.6 raeburn 1951: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1952: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1953: $is_custom{'font'} = 1;
1954: }
1955: foreach my $item (@bgs) {
1956: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1957: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1958: $is_custom{$item} = 1;
1959:
1960: }
1961: }
1962: foreach my $item (@links) {
1963: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1964: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1965: $is_custom{$item} = 1;
1966: }
1967: }
1968: }
1969: my $itemcount = 1;
1.30 raeburn 1970: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1971: $datatable .= '</tr></table></td></tr>';
1972: return $datatable;
1973: }
1974:
1.200 raeburn 1975: sub role_defaults {
1976: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1977: my %defaults;
1978: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1979: return %defaults;
1980: }
1981: my %defaultdesign = %Apache::loncommon::defaultdesign;
1982: if ($role eq 'login') {
1983: %defaults = (
1984: font => $defaultdesign{$role.'.font'},
1985: );
1986: if (ref($logintext) eq 'ARRAY') {
1987: foreach my $item (@{$logintext}) {
1988: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1989: }
1990: }
1991: foreach my $item (@{$images}) {
1992: $defaults{'showlogo'}{$item} = 1;
1993: }
1994: } else {
1995: %defaults = (
1996: img => $defaultdesign{$role.'.img'},
1997: font => $defaultdesign{$role.'.font'},
1998: fontmenu => $defaultdesign{$role.'.fontmenu'},
1999: );
2000: }
2001: foreach my $item (@{$bgs}) {
2002: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2003: }
2004: foreach my $item (@{$links}) {
2005: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2006: }
2007: foreach my $item (@{$images}) {
2008: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2009: }
2010: return %defaults;
2011: }
2012:
1.6 raeburn 2013: sub display_color_options {
1.9 raeburn 2014: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2015: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2016: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2017: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2018: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2019: '<td>'.$choices->{'font'}.'</td>';
2020: if (!$is_custom->{'font'}) {
1.329 raeburn 2021: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2022: } else {
2023: $datatable .= '<td> </td>';
2024: }
1.174 foxr 2025: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2026:
1.8 raeburn 2027: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2028: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2029: ' value="'.$current_color.'" /> '.
1.329 raeburn 2030: ' </span></td></tr>';
1.107 raeburn 2031: unless ($role eq 'login') {
2032: $datatable .= '<tr'.$css_class.'>'.
2033: '<td>'.$choices->{'fontmenu'}.'</td>';
2034: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2035: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2036: } else {
2037: $datatable .= '<td> </td>';
2038: }
1.202 raeburn 2039: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2040: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2041: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2042: '<input class="colorchooser" type="text" size="10" name="'
2043: .$role.'_fontmenu"'.
2044: ' value="'.$current_color.'" /> '.
1.329 raeburn 2045: ' </span></td></tr>';
1.97 tempelho 2046: }
1.9 raeburn 2047: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2048: foreach my $img (@{$images}) {
1.18 albertel 2049: $itemcount ++;
1.6 raeburn 2050: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2051: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2052: '<td>'.$choices->{$img};
1.41 raeburn 2053: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 2054: if ($role eq 'login') {
2055: if ($img eq 'login') {
2056: $login_hdr_pick =
1.135 bisitz 2057: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2058: $logincolors =
2059: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2060: $designs,$defaults);
1.70 raeburn 2061: } elsif ($img ne 'domlogo') {
2062: $datatable.= &logo_display_options($img,$defaults,$designs);
2063: }
2064: }
2065: $datatable .= '</td>';
1.6 raeburn 2066: if ($designs->{$img} ne '') {
2067: $imgfile = $designs->{$img};
1.18 albertel 2068: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2069: } else {
2070: $imgfile = $defaults->{$img};
2071: }
2072: if ($imgfile) {
1.9 raeburn 2073: my ($showfile,$fullsize);
2074: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2075: my $urldir = $1;
2076: my $filename = $2;
2077: my @info = &Apache::lonnet::stat_file($designs->{$img});
2078: if (@info) {
2079: my $thumbfile = 'tn-'.$filename;
2080: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2081: if (@thumb) {
2082: $showfile = $urldir.'/'.$thumbfile;
2083: } else {
2084: $showfile = $imgfile;
2085: }
2086: } else {
2087: $showfile = '';
2088: }
2089: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2090: $showfile = $imgfile;
1.6 raeburn 2091: my $imgdir = $1;
2092: my $filename = $2;
1.159 raeburn 2093: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2094: $showfile = "/$imgdir/tn-".$filename;
2095: } else {
1.159 raeburn 2096: my $input = $londocroot.$imgfile;
2097: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2098: if (!-e $output) {
1.9 raeburn 2099: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2100: my ($fullwidth,$fullheight) = &check_dimensions($input);
2101: if ($fullwidth ne '' && $fullheight ne '') {
2102: if ($fullwidth > $width && $fullheight > $height) {
2103: my $size = $width.'x'.$height;
1.316 raeburn 2104: my @args = ('convert','-sample',$size,$input,$output);
2105: system({$args[0]} @args);
1.159 raeburn 2106: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2107: }
2108: }
1.6 raeburn 2109: }
2110: }
1.16 raeburn 2111: }
1.6 raeburn 2112: if ($showfile) {
1.40 raeburn 2113: if ($showfile =~ m{^/(adm|res)/}) {
2114: if ($showfile =~ m{^/res/}) {
2115: my $local_showfile =
2116: &Apache::lonnet::filelocation('',$showfile);
2117: &Apache::lonnet::repcopy($local_showfile);
2118: }
2119: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2120: }
2121: if ($imgfile) {
2122: if ($imgfile =~ m{^/(adm|res)/}) {
2123: if ($imgfile =~ m{^/res/}) {
2124: my $local_imgfile =
2125: &Apache::lonnet::filelocation('',$imgfile);
2126: &Apache::lonnet::repcopy($local_imgfile);
2127: }
2128: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2129: } else {
2130: $fullsize = $imgfile;
2131: }
2132: }
1.41 raeburn 2133: $datatable .= '<td>';
2134: if ($img eq 'login') {
1.135 bisitz 2135: $datatable .= $login_hdr_pick;
2136: }
1.41 raeburn 2137: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2138: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2139: } else {
1.201 raeburn 2140: $datatable .= '<td> </td><td class="LC_left_item">'.
2141: &mt('Upload:').'<br />';
1.6 raeburn 2142: }
2143: } else {
1.201 raeburn 2144: $datatable .= '<td> </td><td class="LC_left_item">'.
2145: &mt('Upload:').'<br />';
1.6 raeburn 2146: }
1.9 raeburn 2147: if ($switchserver) {
2148: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2149: } else {
1.135 bisitz 2150: if ($img ne 'login') { # suppress file selection for Log-in header
2151: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2152: }
1.9 raeburn 2153: }
2154: $datatable .= '</td></tr>';
1.6 raeburn 2155: }
2156: $itemcount ++;
2157: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2158: $datatable .= '<tr'.$css_class.'>'.
2159: '<td>'.$choices->{'bgs'}.'</td>';
2160: my $bgs_def;
2161: foreach my $item (@{$bgs}) {
2162: if (!$is_custom->{$item}) {
1.329 raeburn 2163: $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 2164: }
2165: }
2166: if ($bgs_def) {
1.8 raeburn 2167: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2168: } else {
2169: $datatable .= '<td> </td>';
2170: }
2171: $datatable .= '<td class="LC_right_item">'.
2172: '<table border="0"><tr>';
1.174 foxr 2173:
1.6 raeburn 2174: foreach my $item (@{$bgs}) {
1.306 raeburn 2175: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2176: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2177: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2178: $datatable .= ' ';
1.6 raeburn 2179: }
1.174 foxr 2180: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2181: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2182: }
2183: $datatable .= '</tr></table></td></tr>';
2184: $itemcount ++;
2185: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2186: $datatable .= '<tr'.$css_class.'>'.
2187: '<td>'.$choices->{'links'}.'</td>';
2188: my $links_def;
2189: foreach my $item (@{$links}) {
2190: if (!$is_custom->{$item}) {
1.329 raeburn 2191: $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 2192: }
2193: }
2194: if ($links_def) {
1.8 raeburn 2195: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2196: } else {
2197: $datatable .= '<td> </td>';
2198: }
2199: $datatable .= '<td class="LC_right_item">'.
2200: '<table border="0"><tr>';
2201: foreach my $item (@{$links}) {
1.234 raeburn 2202: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2203: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2204: if ($designs->{'links'}{$item}) {
1.174 foxr 2205: $datatable.=' ';
1.6 raeburn 2206: }
1.174 foxr 2207: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2208: '" /></td>';
2209: }
1.30 raeburn 2210: $$rowtotal += $itemcount;
1.3 raeburn 2211: return $datatable;
2212: }
2213:
1.70 raeburn 2214: sub logo_display_options {
2215: my ($img,$defaults,$designs) = @_;
2216: my $checkedon;
2217: if (ref($defaults) eq 'HASH') {
2218: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2219: if ($defaults->{'showlogo'}{$img}) {
2220: $checkedon = 'checked="checked" ';
2221: }
2222: }
2223: }
2224: if (ref($designs) eq 'HASH') {
2225: if (ref($designs->{'showlogo'}) eq 'HASH') {
2226: if (defined($designs->{'showlogo'}{$img})) {
2227: if ($designs->{'showlogo'}{$img} == 0) {
2228: $checkedon = '';
2229: } elsif ($designs->{'showlogo'}{$img} == 1) {
2230: $checkedon = 'checked="checked" ';
2231: }
2232: }
2233: }
2234: }
2235: return '<br /><label> <input type="checkbox" name="'.
2236: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2237: &mt('show').'</label>'."\n";
2238: }
2239:
1.41 raeburn 2240: sub login_header_options {
1.135 bisitz 2241: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2242: my $output = '';
1.41 raeburn 2243: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2244: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2245: if (!$is_custom->{'textcol'}) {
2246: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2247: ' ';
2248: }
2249: if (!$is_custom->{'bgcol'}) {
2250: $output .= $choices->{'bgcol'}.': '.
2251: '<span id="css_'.$role.'_font" style="background-color: '.
2252: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2253: }
2254: $output .= '<br />';
2255: }
2256: $output .='<br />';
2257: return $output;
2258: }
2259:
2260: sub login_text_colors {
1.201 raeburn 2261: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2262: my $color_menu = '<table border="0"><tr>';
2263: foreach my $item (@{$logintext}) {
1.306 raeburn 2264: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2265: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2266: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2267: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2268: }
2269: $color_menu .= '</tr></table><br />';
2270: return $color_menu;
2271: }
2272:
2273: sub image_changes {
2274: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2275: my $output;
1.135 bisitz 2276: if ($img eq 'login') {
1.331 raeburn 2277: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2278: } elsif (!$is_custom) {
1.70 raeburn 2279: if ($img ne 'domlogo') {
1.331 raeburn 2280: $output = &mt('Default image:').'<br />';
1.41 raeburn 2281: } else {
1.331 raeburn 2282: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2283: }
2284: }
1.331 raeburn 2285: if ($img ne 'login') {
1.135 bisitz 2286: if ($img_import) {
2287: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2288: }
2289: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2290: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2291: if ($is_custom) {
2292: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2293: '<input type="checkbox" name="'.
2294: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2295: '</label> '.&mt('Replace:').'</span><br />';
2296: } else {
1.306 raeburn 2297: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2298: }
1.41 raeburn 2299: }
2300: return $output;
2301: }
2302:
1.3 raeburn 2303: sub print_quotas {
1.86 raeburn 2304: my ($dom,$settings,$rowtotal,$action) = @_;
2305: my $context;
2306: if ($action eq 'quotas') {
2307: $context = 'tools';
2308: } else {
2309: $context = $action;
2310: }
1.197 raeburn 2311: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2312: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2313: my $typecount = 0;
1.101 raeburn 2314: my ($css_class,%titles);
1.86 raeburn 2315: if ($context eq 'requestcourses') {
1.325 raeburn 2316: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2317: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2318: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2319: %titles = &courserequest_titles();
1.163 raeburn 2320: } elsif ($context eq 'requestauthor') {
2321: @usertools = ('author');
2322: @options = ('norequest','approval','automatic');
1.210 raeburn 2323: %titles = &authorrequest_titles();
1.86 raeburn 2324: } else {
1.162 raeburn 2325: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2326: %titles = &tool_titles();
1.86 raeburn 2327: }
1.26 raeburn 2328: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2329: foreach my $type (@{$types}) {
1.197 raeburn 2330: my ($currdefquota,$currauthorquota);
1.163 raeburn 2331: unless (($context eq 'requestcourses') ||
2332: ($context eq 'requestauthor')) {
1.86 raeburn 2333: if (ref($settings) eq 'HASH') {
2334: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2335: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2336: } else {
2337: $currdefquota = $settings->{$type};
2338: }
1.197 raeburn 2339: if (ref($settings->{authorquota}) eq 'HASH') {
2340: $currauthorquota = $settings->{authorquota}->{$type};
2341: }
1.78 raeburn 2342: }
1.72 raeburn 2343: }
1.3 raeburn 2344: if (defined($usertypes->{$type})) {
2345: $typecount ++;
2346: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2347: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2348: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2349: '<td class="LC_left_item">';
1.101 raeburn 2350: if ($context eq 'requestcourses') {
2351: $datatable .= '<table><tr>';
2352: }
2353: my %cell;
1.72 raeburn 2354: foreach my $item (@usertools) {
1.101 raeburn 2355: if ($context eq 'requestcourses') {
2356: my ($curroption,$currlimit);
2357: if (ref($settings) eq 'HASH') {
2358: if (ref($settings->{$item}) eq 'HASH') {
2359: $curroption = $settings->{$item}->{$type};
2360: if ($curroption =~ /^autolimit=(\d*)$/) {
2361: $currlimit = $1;
2362: }
2363: }
2364: }
2365: if (!$curroption) {
2366: $curroption = 'norequest';
2367: }
2368: $datatable .= '<th>'.$titles{$item}.'</th>';
2369: foreach my $option (@options) {
2370: my $val = $option;
2371: if ($option eq 'norequest') {
2372: $val = 0;
2373: }
2374: if ($option eq 'validate') {
2375: my $canvalidate = 0;
2376: if (ref($validations{$item}) eq 'HASH') {
2377: if ($validations{$item}{$type}) {
2378: $canvalidate = 1;
2379: }
2380: }
2381: next if (!$canvalidate);
2382: }
2383: my $checked = '';
2384: if ($option eq $curroption) {
2385: $checked = ' checked="checked"';
2386: } elsif ($option eq 'autolimit') {
2387: if ($curroption =~ /^autolimit/) {
2388: $checked = ' checked="checked"';
2389: }
2390: }
2391: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2392: '<input type="radio" name="crsreq_'.$item.
2393: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2394: $titles{$option}.'</label>';
1.101 raeburn 2395: if ($option eq 'autolimit') {
1.127 raeburn 2396: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2397: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2398: 'value="'.$currlimit.'" />';
1.101 raeburn 2399: }
1.127 raeburn 2400: $cell{$item} .= '</span> ';
1.103 raeburn 2401: if ($option eq 'autolimit') {
1.127 raeburn 2402: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2403: }
1.101 raeburn 2404: }
1.163 raeburn 2405: } elsif ($context eq 'requestauthor') {
2406: my $curroption;
2407: if (ref($settings) eq 'HASH') {
2408: $curroption = $settings->{$type};
2409: }
2410: if (!$curroption) {
2411: $curroption = 'norequest';
2412: }
2413: foreach my $option (@options) {
2414: my $val = $option;
2415: if ($option eq 'norequest') {
2416: $val = 0;
2417: }
2418: my $checked = '';
2419: if ($option eq $curroption) {
2420: $checked = ' checked="checked"';
2421: }
2422: $datatable .= '<span class="LC_nobreak"><label>'.
2423: '<input type="radio" name="authorreq_'.$type.
2424: '" value="'.$val.'"'.$checked.' />'.
2425: $titles{$option}.'</label></span> ';
2426: }
1.101 raeburn 2427: } else {
2428: my $checked = 'checked="checked" ';
2429: if (ref($settings) eq 'HASH') {
2430: if (ref($settings->{$item}) eq 'HASH') {
2431: if ($settings->{$item}->{$type} == 0) {
2432: $checked = '';
2433: } elsif ($settings->{$item}->{$type} == 1) {
2434: $checked = 'checked="checked" ';
2435: }
1.78 raeburn 2436: }
1.72 raeburn 2437: }
1.101 raeburn 2438: $datatable .= '<span class="LC_nobreak"><label>'.
2439: '<input type="checkbox" name="'.$context.'_'.$item.
2440: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2441: '</label></span> ';
1.72 raeburn 2442: }
1.101 raeburn 2443: }
2444: if ($context eq 'requestcourses') {
2445: $datatable .= '</tr><tr>';
2446: foreach my $item (@usertools) {
1.106 raeburn 2447: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2448: }
2449: $datatable .= '</tr></table>';
1.72 raeburn 2450: }
1.86 raeburn 2451: $datatable .= '</td>';
1.163 raeburn 2452: unless (($context eq 'requestcourses') ||
2453: ($context eq 'requestauthor')) {
1.86 raeburn 2454: $datatable .=
1.197 raeburn 2455: '<td class="LC_right_item">'.
2456: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2457: '<input type="text" name="quota_'.$type.
1.72 raeburn 2458: '" value="'.$currdefquota.
1.197 raeburn 2459: '" size="5" /></span>'.(' ' x 2).
2460: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2461: '<input type="text" name="authorquota_'.$type.
2462: '" value="'.$currauthorquota.
2463: '" size="5" /></span></td>';
1.86 raeburn 2464: }
2465: $datatable .= '</tr>';
1.3 raeburn 2466: }
2467: }
2468: }
1.163 raeburn 2469: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2470: $defaultquota = '20';
1.197 raeburn 2471: $authorquota = '500';
1.86 raeburn 2472: if (ref($settings) eq 'HASH') {
2473: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2474: $defaultquota = $settings->{'defaultquota'}->{'default'};
2475: } elsif (defined($settings->{'default'})) {
2476: $defaultquota = $settings->{'default'};
2477: }
1.197 raeburn 2478: if (ref($settings->{'authorquota'}) eq 'HASH') {
2479: $authorquota = $settings->{'authorquota'}->{'default'};
2480: }
1.3 raeburn 2481: }
2482: }
2483: $typecount ++;
2484: $css_class = $typecount%2?' class="LC_odd_row"':'';
2485: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2486: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2487: '<td class="LC_left_item">';
1.101 raeburn 2488: if ($context eq 'requestcourses') {
2489: $datatable .= '<table><tr>';
2490: }
2491: my %defcell;
1.72 raeburn 2492: foreach my $item (@usertools) {
1.101 raeburn 2493: if ($context eq 'requestcourses') {
2494: my ($curroption,$currlimit);
2495: if (ref($settings) eq 'HASH') {
2496: if (ref($settings->{$item}) eq 'HASH') {
2497: $curroption = $settings->{$item}->{'default'};
2498: if ($curroption =~ /^autolimit=(\d*)$/) {
2499: $currlimit = $1;
2500: }
2501: }
2502: }
2503: if (!$curroption) {
2504: $curroption = 'norequest';
2505: }
2506: $datatable .= '<th>'.$titles{$item}.'</th>';
2507: foreach my $option (@options) {
2508: my $val = $option;
2509: if ($option eq 'norequest') {
2510: $val = 0;
2511: }
2512: if ($option eq 'validate') {
2513: my $canvalidate = 0;
2514: if (ref($validations{$item}) eq 'HASH') {
2515: if ($validations{$item}{'default'}) {
2516: $canvalidate = 1;
2517: }
2518: }
2519: next if (!$canvalidate);
2520: }
2521: my $checked = '';
2522: if ($option eq $curroption) {
2523: $checked = ' checked="checked"';
2524: } elsif ($option eq 'autolimit') {
2525: if ($curroption =~ /^autolimit/) {
2526: $checked = ' checked="checked"';
2527: }
2528: }
2529: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2530: '<input type="radio" name="crsreq_'.$item.
2531: '_default" value="'.$val.'"'.$checked.' />'.
2532: $titles{$option}.'</label>';
2533: if ($option eq 'autolimit') {
1.127 raeburn 2534: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2535: $item.'_limit_default" size="1" '.
2536: 'value="'.$currlimit.'" />';
2537: }
1.127 raeburn 2538: $defcell{$item} .= '</span> ';
1.104 raeburn 2539: if ($option eq 'autolimit') {
1.127 raeburn 2540: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2541: }
1.101 raeburn 2542: }
1.163 raeburn 2543: } elsif ($context eq 'requestauthor') {
2544: my $curroption;
2545: if (ref($settings) eq 'HASH') {
1.172 raeburn 2546: $curroption = $settings->{'default'};
1.163 raeburn 2547: }
2548: if (!$curroption) {
2549: $curroption = 'norequest';
2550: }
2551: foreach my $option (@options) {
2552: my $val = $option;
2553: if ($option eq 'norequest') {
2554: $val = 0;
2555: }
2556: my $checked = '';
2557: if ($option eq $curroption) {
2558: $checked = ' checked="checked"';
2559: }
2560: $datatable .= '<span class="LC_nobreak"><label>'.
2561: '<input type="radio" name="authorreq_default"'.
2562: ' value="'.$val.'"'.$checked.' />'.
2563: $titles{$option}.'</label></span> ';
2564: }
1.101 raeburn 2565: } else {
2566: my $checked = 'checked="checked" ';
2567: if (ref($settings) eq 'HASH') {
2568: if (ref($settings->{$item}) eq 'HASH') {
2569: if ($settings->{$item}->{'default'} == 0) {
2570: $checked = '';
2571: } elsif ($settings->{$item}->{'default'} == 1) {
2572: $checked = 'checked="checked" ';
2573: }
1.78 raeburn 2574: }
1.72 raeburn 2575: }
1.101 raeburn 2576: $datatable .= '<span class="LC_nobreak"><label>'.
2577: '<input type="checkbox" name="'.$context.'_'.$item.
2578: '" value="default" '.$checked.'/>'.$titles{$item}.
2579: '</label></span> ';
2580: }
2581: }
2582: if ($context eq 'requestcourses') {
2583: $datatable .= '</tr><tr>';
2584: foreach my $item (@usertools) {
1.106 raeburn 2585: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2586: }
1.101 raeburn 2587: $datatable .= '</tr></table>';
1.72 raeburn 2588: }
1.86 raeburn 2589: $datatable .= '</td>';
1.163 raeburn 2590: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2591: $datatable .= '<td class="LC_right_item">'.
2592: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2593: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2594: $defaultquota.'" size="5" /></span>'.(' ' x2).
2595: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2596: '<input type="text" name="authorquota" value="'.
2597: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2598: }
2599: $datatable .= '</tr>';
1.72 raeburn 2600: $typecount ++;
2601: $css_class = $typecount%2?' class="LC_odd_row"':'';
2602: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2603: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2604: if ($context eq 'requestcourses') {
1.109 raeburn 2605: $datatable .= &mt('(overrides affiliation, if set)').
2606: '</td>'.
2607: '<td class="LC_left_item">'.
2608: '<table><tr>';
1.101 raeburn 2609: } else {
1.109 raeburn 2610: $datatable .= &mt('(overrides affiliation, if checked)').
2611: '</td>'.
2612: '<td class="LC_left_item" colspan="2">'.
2613: '<br />';
1.101 raeburn 2614: }
2615: my %advcell;
1.72 raeburn 2616: foreach my $item (@usertools) {
1.101 raeburn 2617: if ($context eq 'requestcourses') {
2618: my ($curroption,$currlimit);
2619: if (ref($settings) eq 'HASH') {
2620: if (ref($settings->{$item}) eq 'HASH') {
2621: $curroption = $settings->{$item}->{'_LC_adv'};
2622: if ($curroption =~ /^autolimit=(\d*)$/) {
2623: $currlimit = $1;
2624: }
2625: }
2626: }
2627: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2628: my $checked = '';
2629: if ($curroption eq '') {
2630: $checked = ' checked="checked"';
2631: }
2632: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2633: '<input type="radio" name="crsreq_'.$item.
2634: '__LC_adv" value=""'.$checked.' />'.
2635: &mt('No override set').'</label></span> ';
1.101 raeburn 2636: foreach my $option (@options) {
2637: my $val = $option;
2638: if ($option eq 'norequest') {
2639: $val = 0;
2640: }
2641: if ($option eq 'validate') {
2642: my $canvalidate = 0;
2643: if (ref($validations{$item}) eq 'HASH') {
2644: if ($validations{$item}{'_LC_adv'}) {
2645: $canvalidate = 1;
2646: }
2647: }
2648: next if (!$canvalidate);
2649: }
2650: my $checked = '';
1.104 raeburn 2651: if ($val eq $curroption) {
1.101 raeburn 2652: $checked = ' checked="checked"';
2653: } elsif ($option eq 'autolimit') {
2654: if ($curroption =~ /^autolimit/) {
2655: $checked = ' checked="checked"';
2656: }
2657: }
2658: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2659: '<input type="radio" name="crsreq_'.$item.
2660: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2661: $titles{$option}.'</label>';
2662: if ($option eq 'autolimit') {
1.127 raeburn 2663: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2664: $item.'_limit__LC_adv" size="1" '.
2665: 'value="'.$currlimit.'" />';
2666: }
1.127 raeburn 2667: $advcell{$item} .= '</span> ';
1.104 raeburn 2668: if ($option eq 'autolimit') {
1.127 raeburn 2669: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2670: }
1.101 raeburn 2671: }
1.163 raeburn 2672: } elsif ($context eq 'requestauthor') {
2673: my $curroption;
2674: if (ref($settings) eq 'HASH') {
2675: $curroption = $settings->{'_LC_adv'};
2676: }
2677: my $checked = '';
2678: if ($curroption eq '') {
2679: $checked = ' checked="checked"';
2680: }
2681: $datatable .= '<span class="LC_nobreak"><label>'.
2682: '<input type="radio" name="authorreq__LC_adv"'.
2683: ' value=""'.$checked.' />'.
2684: &mt('No override set').'</label></span> ';
2685: foreach my $option (@options) {
2686: my $val = $option;
2687: if ($option eq 'norequest') {
2688: $val = 0;
2689: }
2690: my $checked = '';
2691: if ($val eq $curroption) {
2692: $checked = ' checked="checked"';
2693: }
2694: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2695: '<input type="radio" name="authorreq__LC_adv"'.
2696: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2697: $titles{$option}.'</label></span> ';
2698: }
1.101 raeburn 2699: } else {
2700: my $checked = 'checked="checked" ';
2701: if (ref($settings) eq 'HASH') {
2702: if (ref($settings->{$item}) eq 'HASH') {
2703: if ($settings->{$item}->{'_LC_adv'} == 0) {
2704: $checked = '';
2705: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2706: $checked = 'checked="checked" ';
2707: }
1.79 raeburn 2708: }
1.72 raeburn 2709: }
1.101 raeburn 2710: $datatable .= '<span class="LC_nobreak"><label>'.
2711: '<input type="checkbox" name="'.$context.'_'.$item.
2712: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2713: '</label></span> ';
2714: }
2715: }
2716: if ($context eq 'requestcourses') {
2717: $datatable .= '</tr><tr>';
2718: foreach my $item (@usertools) {
1.106 raeburn 2719: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2720: }
1.101 raeburn 2721: $datatable .= '</tr></table>';
1.72 raeburn 2722: }
1.98 raeburn 2723: $datatable .= '</td></tr>';
1.30 raeburn 2724: $$rowtotal += $typecount;
1.3 raeburn 2725: return $datatable;
2726: }
2727:
1.163 raeburn 2728: sub print_requestmail {
1.305 raeburn 2729: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2730: my ($now,$datatable,%currapp);
1.102 raeburn 2731: $now = time;
2732: if (ref($settings) eq 'HASH') {
2733: if (ref($settings->{'notify'}) eq 'HASH') {
2734: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2735: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2736: }
2737: }
2738: }
1.191 raeburn 2739: my $numinrow = 2;
1.224 raeburn 2740: my $css_class;
1.305 raeburn 2741: if ($$rowtotal%2) {
2742: $css_class = 'LC_odd_row';
2743: }
2744: if ($customcss) {
2745: $css_class .= " $customcss";
2746: }
2747: $css_class =~ s/^\s+//;
2748: if ($css_class) {
2749: $css_class = ' class="'.$css_class.'"';
2750: }
2751: if ($rowstyle) {
2752: $css_class .= ' style="'.$rowstyle.'"';
2753: }
1.163 raeburn 2754: my $text;
2755: if ($action eq 'requestcourses') {
2756: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2757: } elsif ($action eq 'requestauthor') {
2758: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2759: } else {
1.224 raeburn 2760: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2761: }
1.224 raeburn 2762: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2763: ' <td>'.$text.'</td>'.
1.102 raeburn 2764: ' <td class="LC_left_item">';
1.191 raeburn 2765: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2766: $action.'notifyapproval',%currapp);
1.191 raeburn 2767: if ($numdc > 0) {
2768: $datatable .= $table;
1.102 raeburn 2769: } else {
2770: $datatable .= &mt('There are no active Domain Coordinators');
2771: }
2772: $datatable .='</td></tr>';
2773: return $datatable;
2774: }
2775:
1.216 raeburn 2776: sub print_studentcode {
2777: my ($settings,$rowtotal) = @_;
2778: my $rownum = 0;
1.218 raeburn 2779: my ($output,%current);
1.325 raeburn 2780: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2781: if (ref($settings) eq 'HASH') {
2782: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2783: foreach my $type (@crstypes) {
2784: $current{$type} = $settings->{'uniquecode'}{$type};
2785: }
1.218 raeburn 2786: }
2787: }
2788: $output .= '<tr>'.
2789: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2790: '<td class="LC_left_item">';
2791: foreach my $type (@crstypes) {
2792: my $check = ' ';
2793: if ($current{$type}) {
2794: $check = ' checked="checked" ';
2795: }
2796: $output .= '<span class="LC_nobreak"><label>'.
2797: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2798: &mt($type).'</label></span>'.(' 'x2).' ';
2799: }
2800: $output .= '</td></tr>';
2801: $$rowtotal ++;
2802: return $output;
1.216 raeburn 2803: }
2804:
2805: sub print_textbookcourses {
1.242 raeburn 2806: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2807: my $rownum = 0;
2808: my $css_class;
2809: my $itemcount = 1;
2810: my $maxnum = 0;
2811: my $bookshash;
2812: if (ref($settings) eq 'HASH') {
1.242 raeburn 2813: $bookshash = $settings->{$type};
1.216 raeburn 2814: }
2815: my %ordered;
2816: if (ref($bookshash) eq 'HASH') {
2817: foreach my $item (keys(%{$bookshash})) {
2818: if (ref($bookshash->{$item}) eq 'HASH') {
2819: my $num = $bookshash->{$item}{'order'};
2820: $ordered{$num} = $item;
2821: }
2822: }
2823: }
2824: my $confname = $dom.'-domainconfig';
2825: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2826: my $maxnum = scalar(keys(%ordered));
2827: my $datatable;
1.216 raeburn 2828: if (keys(%ordered)) {
2829: my @items = sort { $a <=> $b } keys(%ordered);
2830: for (my $i=0; $i<@items; $i++) {
2831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2832: my $key = $ordered{$items[$i]};
2833: my %coursehash=&Apache::lonnet::coursedescription($key);
2834: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2835: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2836: if (ref($bookshash->{$key}) eq 'HASH') {
2837: $subject = $bookshash->{$key}->{'subject'};
2838: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2839: if ($type eq 'textbooks') {
1.243 raeburn 2840: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2841: $author = $bookshash->{$key}->{'author'};
2842: $image = $bookshash->{$key}->{'image'};
2843: if ($image ne '') {
2844: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2845: my $imagethumb = "$path/tn-".$imagefile;
2846: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2847: }
1.216 raeburn 2848: }
2849: }
1.242 raeburn 2850: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2851: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2852: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2853: for (my $k=0; $k<=$maxnum; $k++) {
2854: my $vpos = $k+1;
2855: my $selstr;
2856: if ($k == $i) {
2857: $selstr = ' selected="selected" ';
2858: }
2859: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2860: }
2861: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2862: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2863: &mt('Delete?').'</label></span></td>'.
2864: '<td colspan="2">'.
1.242 raeburn 2865: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2866: (' 'x2).
1.242 raeburn 2867: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2868: if ($type eq 'textbooks') {
2869: $datatable .= (' 'x2).
1.243 raeburn 2870: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2871: (' 'x2).
1.242 raeburn 2872: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2873: (' 'x2).
2874: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2875: if ($image) {
1.267 raeburn 2876: $datatable .= $imgsrc.
1.242 raeburn 2877: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2878: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2879: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2880: }
2881: if ($switchserver) {
2882: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2883: } else {
2884: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2885: }
1.216 raeburn 2886: }
1.242 raeburn 2887: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2888: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2889: $coursetitle.'</span></td></tr>'."\n";
2890: $itemcount ++;
2891: }
2892: }
2893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2894: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2895: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2896: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2897: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2898: for (my $k=0; $k<$maxnum+1; $k++) {
2899: my $vpos = $k+1;
2900: my $selstr;
2901: if ($k == $maxnum) {
2902: $selstr = ' selected="selected" ';
2903: }
2904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2905: }
2906: $datatable .= '</select> '."\n".
1.334 raeburn 2907: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2908: '<td colspan="2">'.
1.242 raeburn 2909: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2910: (' 'x2).
1.242 raeburn 2911: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2912: (' 'x2);
2913: if ($type eq 'textbooks') {
1.243 raeburn 2914: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2915: (' 'x2).
2916: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2917: (' 'x2).
2918: '<span class="LC_nobreak">'.&mt('Image:').' ';
2919: if ($switchserver) {
2920: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2921: } else {
2922: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2923: }
1.334 raeburn 2924: $datatable .= '</span>'."\n";
1.216 raeburn 2925: }
1.334 raeburn 2926: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2927: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2928: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2929: &Apache::loncommon::selectcourse_link
1.334 raeburn 2930: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2931: '</span></td>'."\n".
2932: '</tr>'."\n";
2933: $itemcount ++;
2934: return $datatable;
2935: }
2936:
1.217 raeburn 2937: sub textbookcourses_javascript {
1.242 raeburn 2938: my ($settings) = @_;
2939: return unless(ref($settings) eq 'HASH');
2940: my (%ordered,%total,%jstext);
2941: foreach my $type ('textbooks','templates') {
2942: $total{$type} = 0;
2943: if (ref($settings->{$type}) eq 'HASH') {
2944: foreach my $item (keys(%{$settings->{$type}})) {
2945: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2946: my $num = $settings->{$type}->{$item}{'order'};
2947: $ordered{$type}{$num} = $item;
2948: }
2949: }
2950: $total{$type} = scalar(keys(%{$settings->{$type}}));
2951: }
2952: my @jsarray = ();
2953: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2954: push(@jsarray,$ordered{$type}{$item});
2955: }
2956: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2957: }
2958: return <<"ENDSCRIPT";
2959: <script type="text/javascript">
2960: // <![CDATA[
1.242 raeburn 2961: function reorderBooks(form,item,caller) {
1.217 raeburn 2962: var changedVal;
1.242 raeburn 2963: $jstext{'textbooks'};
2964: $jstext{'templates'};
2965: var newpos;
2966: var maxh;
2967: if (caller == 'textbooks') {
2968: newpos = 'textbooks_addbook_pos';
2969: maxh = 1 + $total{'textbooks'};
2970: } else {
2971: newpos = 'templates_addbook_pos';
2972: maxh = 1 + $total{'templates'};
2973: }
1.217 raeburn 2974: var current = new Array;
2975: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2976: if (item == newpos) {
2977: changedVal = newitemVal;
2978: } else {
2979: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2980: current[newitemVal] = newpos;
2981: }
1.242 raeburn 2982: if (caller == 'textbooks') {
2983: for (var i=0; i<textbooks.length; i++) {
2984: var elementName = 'textbooks_'+textbooks[i];
2985: if (elementName != item) {
2986: if (form.elements[elementName]) {
2987: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2988: current[currVal] = elementName;
2989: }
2990: }
2991: }
2992: }
2993: if (caller == 'templates') {
2994: for (var i=0; i<templates.length; i++) {
2995: var elementName = 'templates_'+templates[i];
2996: if (elementName != item) {
2997: if (form.elements[elementName]) {
2998: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2999: current[currVal] = elementName;
3000: }
1.217 raeburn 3001: }
3002: }
3003: }
3004: var oldVal;
3005: for (var j=0; j<maxh; j++) {
3006: if (current[j] == undefined) {
3007: oldVal = j;
3008: }
3009: }
3010: if (oldVal < changedVal) {
3011: for (var k=oldVal+1; k<=changedVal ; k++) {
3012: var elementName = current[k];
3013: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3014: }
3015: } else {
3016: for (var k=changedVal; k<oldVal; k++) {
3017: var elementName = current[k];
3018: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3019: }
3020: }
3021: return;
3022: }
3023:
3024: // ]]>
3025: </script>
3026:
3027: ENDSCRIPT
3028: }
3029:
1.267 raeburn 3030: sub ltitools_javascript {
3031: my ($settings) = @_;
1.319 raeburn 3032: my $togglejs = <itools_toggle_js();
3033: unless (ref($settings) eq 'HASH') {
3034: return $togglejs;
3035: }
1.267 raeburn 3036: my (%ordered,$total,%jstext);
3037: $total = 0;
3038: foreach my $item (keys(%{$settings})) {
3039: if (ref($settings->{$item}) eq 'HASH') {
3040: my $num = $settings->{$item}{'order'};
3041: $ordered{$num} = $item;
3042: }
3043: }
3044: $total = scalar(keys(%{$settings}));
3045: my @jsarray = ();
3046: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3047: push(@jsarray,$ordered{$item});
3048: }
3049: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3050: return <<"ENDSCRIPT";
3051: <script type="text/javascript">
3052: // <![CDATA[
1.319 raeburn 3053: function reorderLTITools(form,item) {
1.267 raeburn 3054: var changedVal;
3055: $jstext
3056: var newpos = 'ltitools_add_pos';
3057: var maxh = 1 + $total;
3058: var current = new Array;
3059: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3060: if (item == newpos) {
3061: changedVal = newitemVal;
3062: } else {
3063: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3064: current[newitemVal] = newpos;
3065: }
3066: for (var i=0; i<ltitools.length; i++) {
3067: var elementName = 'ltitools_'+ltitools[i];
3068: if (elementName != item) {
3069: if (form.elements[elementName]) {
3070: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3071: current[currVal] = elementName;
3072: }
3073: }
3074: }
3075: var oldVal;
3076: for (var j=0; j<maxh; j++) {
3077: if (current[j] == undefined) {
3078: oldVal = j;
3079: }
3080: }
3081: if (oldVal < changedVal) {
3082: for (var k=oldVal+1; k<=changedVal ; k++) {
3083: var elementName = current[k];
3084: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3085: }
3086: } else {
3087: for (var k=changedVal; k<oldVal; k++) {
3088: var elementName = current[k];
3089: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3090: }
3091: }
3092: return;
3093: }
3094:
3095: // ]]>
3096: </script>
3097:
1.319 raeburn 3098: $togglejs
3099:
3100: ENDSCRIPT
3101: }
3102:
3103: sub ltitools_toggle_js {
3104: return <<"ENDSCRIPT";
3105: <script type="text/javascript">
3106: // <![CDATA[
3107:
3108: function toggleLTITools(form,setting,item) {
3109: var radioname = '';
3110: var divid = '';
3111: if ((setting == 'passback') || (setting == 'roster')) {
3112: radioname = 'ltitools_'+setting+'_'+item;
3113: divid = 'ltitools_'+setting+'time_'+item;
3114: var num = form.elements[radioname].length;
3115: if (num) {
3116: var setvis = '';
3117: for (var i=0; i<num; i++) {
3118: if (form.elements[radioname][i].checked) {
3119: if (form.elements[radioname][i].value == '1') {
3120: if (document.getElementById(divid)) {
3121: document.getElementById(divid).style.display = 'inline-block';
3122: }
3123: setvis = 1;
3124: }
3125: break;
3126: }
3127: }
3128: }
3129: if (!setvis) {
3130: if (document.getElementById(divid)) {
3131: document.getElementById(divid).style.display = 'none';
3132: }
3133: }
3134: }
1.324 raeburn 3135: if (setting == 'user') {
3136: divid = 'ltitools_'+setting+'_div_'+item;
3137: var checkid = 'ltitools_'+setting+'_field_'+item;
3138: if (document.getElementById(divid)) {
3139: if (document.getElementById(checkid)) {
3140: if (document.getElementById(checkid).checked) {
3141: document.getElementById(divid).style.display = 'inline-block';
3142: } else {
3143: document.getElementById(divid).style.display = 'none';
3144: }
3145: }
3146: }
3147: }
1.319 raeburn 3148: return;
3149: }
3150: // ]]>
3151: </script>
3152:
1.267 raeburn 3153: ENDSCRIPT
3154: }
3155:
1.381 raeburn 3156: sub wafproxy_javascript {
3157: my ($dom) = @_;
3158: return <<"ENDSCRIPT";
3159: <script type="text/javascript">
3160: // <![CDATA[
3161: function updateWAF() {
3162: if (document.getElementById('wafproxy_remoteip')) {
3163: var wafremote = 0;
3164: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3165: wafremote = 1;
3166: }
3167: var fields = new Array('header','trust');
3168: for (var i=0; i<fields.length; i++) {
3169: if (document.getElementById('wafproxy_'+fields[i])) {
3170: if (wafremote == 1) {
3171: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3172: }
3173: else {
3174: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3175: }
3176: }
3177: }
3178: if (document.getElementById('wafproxyranges_$dom')) {
3179: if (wafremote == 1) {
3180: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3181: } else {
3182: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3183: if (document.display.wafproxy_vpnaccess[i].checked) {
3184: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3185: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3186: }
3187: }
3188: }
3189: }
3190: }
3191: }
3192: return;
3193: }
3194:
3195: function checkWAF() {
3196: if (document.getElementById('wafproxy_remoteip')) {
3197: var wafvpn = 0;
3198: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3199: if (document.display.wafproxy_vpnaccess[i].checked) {
3200: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3201: wafvpn = 1;
3202: }
3203: break;
3204: }
3205: }
3206: var vpn = new Array('vpnint','vpnext');
3207: for (var i=0; i<vpn.length; i++) {
3208: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3209: if (wafvpn == 1) {
3210: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3211: }
3212: else {
3213: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3214: }
3215: }
3216: }
3217: if (document.getElementById('wafproxyranges_$dom')) {
3218: if (wafvpn == 1) {
3219: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3220: }
3221: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3222: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3223: }
3224: }
3225: }
3226: return;
3227: }
3228:
3229: function toggleWAF() {
3230: if (document.getElementById('wafproxy_table')) {
3231: var wafproxy = 0;
3232: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3233: if (document.display.wafproxy_${dom}[i].checked) {
3234: if (document.display.wafproxy_${dom}[i].value == 1) {
3235: wafproxy = 1;
3236: break;
3237: }
3238: }
3239: }
3240: if (wafproxy == 1) {
3241: document.getElementById('wafproxy_table').style.display='inline';
3242: }
3243: else {
3244: document.getElementById('wafproxy_table').style.display='none';
3245: }
3246: if (document.getElementById('wafproxyrow_${dom}')) {
3247: if (wafproxy == 1) {
3248: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3249: }
3250: else {
3251: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3252: }
3253: }
3254: if (document.getElementById('nowafproxyrow_$dom')) {
3255: if (wafproxy == 1) {
3256: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3257: }
3258: else {
3259: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3260: }
3261: }
3262: }
3263: return;
3264: }
3265: // ]]>
3266: </script>
3267:
3268: ENDSCRIPT
3269: }
3270:
1.372 raeburn 3271: sub proctoring_javascript {
3272: my ($settings) = @_;
3273: my (%ordered,$total,%jstext);
3274: $total = 0;
3275: if (ref($settings) eq 'HASH') {
3276: foreach my $item (keys(%{$settings})) {
3277: if (ref($settings->{$item}) eq 'HASH') {
3278: my $num = $settings->{$item}{'order'};
3279: $ordered{$num} = $item;
3280: }
3281: }
3282: $total = scalar(keys(%{$settings}));
3283: } else {
3284: %ordered = (
3285: 0 => 'proctorio',
3286: 1 => 'examity',
3287: );
3288: $total = 2;
3289: }
3290: my @jsarray = ();
3291: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3292: push(@jsarray,$ordered{$item});
3293: }
3294: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3295: return <<"ENDSCRIPT";
3296: <script type="text/javascript">
3297: // <![CDATA[
3298: function reorderProctoring(form,item) {
3299: var changedVal;
3300: $jstext
3301: var maxh = $total;
3302: var current = new Array;
3303: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3304: for (var i=0; i<proctors.length; i++) {
3305: var elementName = 'proctoring_pos_'+proctors[i];
3306: if (elementName != item) {
3307: if (form.elements[elementName]) {
3308: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3309: current[currVal] = elementName;
3310: }
3311: }
3312: }
3313: var oldVal;
3314: for (var j=0; j<maxh; j++) {
3315: if (current[j] == undefined) {
3316: oldVal = j;
3317: }
3318: }
3319: if (oldVal < changedVal) {
3320: for (var k=oldVal+1; k<=changedVal ; k++) {
3321: var elementName = current[k];
3322: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3323: }
3324: } else {
3325: for (var k=changedVal; k<oldVal; k++) {
3326: var elementName = current[k];
3327: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3328: }
3329: }
3330: return;
3331: }
3332:
3333: function toggleProctoring(form,item) {
3334: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3335: if (fieldsets.length) {
3336: var radioname = 'proctoring_available_'+item;
3337: var num = form.elements[radioname].length;
3338: if (num) {
3339: var setvis = '';
3340: for (var i=0; i<num; i++) {
3341: if (form.elements[radioname][i].checked) {
3342: if (form.elements[radioname][i].value == '1') {
3343: setvis = 1;
3344: break;
3345: }
3346: }
3347: }
3348: for (var j=0; j<fieldsets.length; j++) {
3349: if (setvis) {
3350: fieldsets[j].style.display = 'block';
3351: } else {
3352: fieldsets[j].style.display = 'none';
3353: }
3354: }
3355: }
3356: }
3357: return;
3358: }
3359:
3360: // ]]>
3361: </script>
3362:
3363: ENDSCRIPT
3364: }
3365:
3366:
1.320 raeburn 3367: sub lti_javascript {
3368: my ($settings) = @_;
3369: my $togglejs = <i_toggle_js();
3370: unless (ref($settings) eq 'HASH') {
3371: return $togglejs;
3372: }
3373: my (%ordered,$total,%jstext);
1.390 raeburn 3374: $total = scalar(keys(%{$settings}));
1.320 raeburn 3375: foreach my $item (keys(%{$settings})) {
3376: if (ref($settings->{$item}) eq 'HASH') {
3377: my $num = $settings->{$item}{'order'};
1.390 raeburn 3378: if ($num eq '') {
3379: $num = $total - 1;
3380: }
1.320 raeburn 3381: $ordered{$num} = $item;
3382: }
3383: }
3384: my @jsarray = ();
3385: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3386: push(@jsarray,$ordered{$item});
3387: }
3388: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3389: return <<"ENDSCRIPT";
3390: <script type="text/javascript">
3391: // <![CDATA[
3392: function reorderLTI(form,item) {
3393: var changedVal;
3394: $jstext
3395: var newpos = 'lti_pos_add';
3396: var maxh = 1 + $total;
3397: var current = new Array;
3398: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3399: if (item == newpos) {
3400: changedVal = newitemVal;
3401: } else {
3402: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3403: current[newitemVal] = newpos;
3404: }
3405: for (var i=0; i<lti.length; i++) {
3406: var elementName = 'lti_pos_'+lti[i];
3407: if (elementName != item) {
3408: if (form.elements[elementName]) {
3409: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3410: current[currVal] = elementName;
3411: }
3412: }
3413: }
3414: var oldVal;
3415: for (var j=0; j<maxh; j++) {
3416: if (current[j] == undefined) {
3417: oldVal = j;
3418: }
3419: }
3420: if (oldVal < changedVal) {
3421: for (var k=oldVal+1; k<=changedVal ; k++) {
3422: var elementName = current[k];
3423: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3424: }
3425: } else {
3426: for (var k=changedVal; k<oldVal; k++) {
3427: var elementName = current[k];
3428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3429: }
3430: }
3431: return;
3432: }
3433: // ]]>
3434: </script>
3435:
3436: $togglejs
3437:
3438: ENDSCRIPT
3439: }
3440:
3441: sub lti_toggle_js {
1.325 raeburn 3442: my %lcauthparmtext = &Apache::lonlocal::texthash (
3443: localauth => 'Local auth argument',
3444: krb => 'Kerberos domain',
3445: );
1.391 raeburn 3446: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3447: &js_escape(\$crsincalert);
1.320 raeburn 3448: return <<"ENDSCRIPT";
3449: <script type="text/javascript">
3450: // <![CDATA[
3451:
3452: function toggleLTI(form,setting,item) {
1.391 raeburn 3453: if ((setting == 'requser') || (setting == 'crsinc')) {
3454: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3455: var setvis = '';
3456: var radioname = 'lti_requser_'+item;
3457: var num = form.elements[radioname].length;
3458: if (num) {
3459: for (var i=0; i<num; i++) {
3460: if (form.elements[radioname][i].checked) {
3461: if (form.elements[radioname][i].value == '1') {
3462: setvis = 1;
3463: break;
3464: }
3465: }
3466: }
3467: }
3468: if (usrfieldsets.length) {
3469: for (var j=0; j<usrfieldsets.length; j++) {
3470: if (setvis) {
3471: usrfieldsets[j].style.display = 'block';
3472: } else {
3473: usrfieldsets[j].style.display = 'none';
3474: }
3475: }
3476: }
3477: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3478: if (crsfieldsets.length) {
3479: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3480: var num = form.elements[radioname].length;
3481: if (num) {
1.391 raeburn 3482: var crsvis = '';
1.345 raeburn 3483: for (var i=0; i<num; i++) {
3484: if (form.elements[radioname][i].checked) {
3485: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3486: if (setvis == '') {
3487: if (setting == 'crsinc'){
3488: alert("$crsincalert");
3489: form.elements[radioname][0].checked = true;
3490: }
3491: } else {
3492: crsvis = 1;
3493: }
3494: break;
1.345 raeburn 3495: }
3496: }
3497: }
1.391 raeburn 3498: setvis = crsvis;
3499: }
3500: for (var j=0; j<crsfieldsets.length; j++) {
3501: if (setvis) {
3502: crsfieldsets[j].style.display = 'block';
3503: } else {
3504: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3505: }
3506: }
3507: }
1.363 raeburn 3508: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3509: var radioname = '';
3510: var divid = '';
3511: if (setting == 'user') {
3512: radioname = 'lti_mapuser_'+item;
3513: divid = 'lti_userfield_'+item;
1.343 raeburn 3514: } else if (setting == 'crs') {
1.320 raeburn 3515: radioname = 'lti_mapcrs_'+item;
3516: divid = 'lti_crsfield_'+item;
1.363 raeburn 3517: } else if (setting == 'callback') {
3518: radioname = 'lti_callback_'+item;
3519: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3520: } else {
1.351 raeburn 3521: radioname = 'lti_passback_'+item;
1.337 raeburn 3522: divid = 'lti_passback_'+item;
1.320 raeburn 3523: }
3524: var num = form.elements[radioname].length;
3525: if (num) {
3526: var setvis = '';
3527: for (var i=0; i<num; i++) {
3528: if (form.elements[radioname][i].checked) {
1.363 raeburn 3529: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3530: if (form.elements[radioname][i].value == '1') {
3531: if (document.getElementById(divid)) {
3532: document.getElementById(divid).style.display = 'inline-block';
3533: }
3534: setvis = 1;
3535: break;
3536: }
3537: } else {
3538: if (form.elements[radioname][i].value == 'other') {
3539: if (document.getElementById(divid)) {
3540: document.getElementById(divid).style.display = 'inline-block';
3541: }
3542: setvis = 1;
3543: break;
1.320 raeburn 3544: }
3545: }
3546: }
3547: }
3548: if (!setvis) {
3549: if (document.getElementById(divid)) {
3550: document.getElementById(divid).style.display = 'none';
3551: }
3552: }
3553: }
3554: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3555: var numsec = form.elements['lti_crssec_'+item].length;
3556: if (numsec) {
3557: var setvis = '';
3558: for (var i=0; i<numsec; i++) {
3559: if (form.elements['lti_crssec_'+item][i].checked) {
3560: if (form.elements['lti_crssec_'+item][i].value == '1') {
3561: if (document.getElementById('lti_crssecfield_'+item)) {
3562: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3563: setvis = 1;
3564: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3565: if (numsrcsec) {
3566: var setsrcvis = '';
3567: for (var j=0; j<numsrcsec; j++) {
3568: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3569: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3570: if (document.getElementById('lti_secsrcfield_'+item)) {
3571: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3572: setsrcvis = 1;
3573: }
3574: }
3575: }
3576: }
3577: if (!setsrcvis) {
3578: if (document.getElementById('lti_secsrcfield_'+item)) {
3579: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3580: }
3581: }
3582: }
3583: }
3584: }
3585: }
3586: }
3587: if (!setvis) {
3588: if (document.getElementById('lti_crssecfield_'+item)) {
3589: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3590: }
3591: if (document.getElementById('lti_secsrcfield_'+item)) {
3592: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3593: }
3594: }
3595: }
1.325 raeburn 3596: } else if (setting == 'lcauth') {
3597: var numauth = form.elements['lti_lcauth_'+item].length;
3598: if (numauth) {
3599: for (var i=0; i<numauth; i++) {
3600: if (form.elements['lti_lcauth_'+item][i].checked) {
3601: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3602: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3603: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3604: } else {
3605: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3606: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3607: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3608: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3609: } else {
3610: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3611: }
3612: }
3613: }
3614: }
3615: }
3616: }
3617: }
1.326 raeburn 3618: } else if (setting == 'lcmenu') {
3619: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3620: var divid = 'lti_menufield_'+item;
3621: var setvis = '';
3622: for (var i=0; i<menus.length; i++) {
3623: var radioname = menus[i];
3624: var num = form.elements[radioname].length;
3625: if (num) {
3626: for (var j=0; j<num; j++) {
3627: if (form.elements[radioname][j].checked) {
3628: if (form.elements[radioname][j].value == '1') {
3629: if (document.getElementById(divid)) {
3630: document.getElementById(divid).style.display = 'inline-block';
3631: }
3632: setvis = 1;
3633: break;
3634: }
3635: }
3636: }
3637: }
3638: if (setvis == 1) {
3639: break;
3640: }
3641: }
3642: if (!setvis) {
3643: if (document.getElementById(divid)) {
3644: document.getElementById(divid).style.display = 'none';
3645: }
3646: }
1.320 raeburn 3647: }
3648: return;
3649: }
3650: // ]]>
3651: </script>
3652:
3653: ENDSCRIPT
3654: }
3655:
1.385 raeburn 3656: sub autoupdate_javascript {
3657: return <<"ENDSCRIPT";
3658: <script type="text/javascript">
3659: // <![CDATA[
3660: function toggleLastActiveDays(form) {
3661: var radioname = 'lastactive';
3662: var divid = 'lastactive_div';
3663: var num = form.elements[radioname].length;
3664: if (num) {
3665: var setvis = '';
3666: for (var i=0; i<num; i++) {
3667: if (form.elements[radioname][i].checked) {
3668: if (form.elements[radioname][i].value == '1') {
3669: if (document.getElementById(divid)) {
3670: document.getElementById(divid).style.display = 'inline-block';
3671: }
3672: setvis = 1;
3673: }
3674: break;
3675: }
3676: }
3677: if (!setvis) {
3678: if (document.getElementById(divid)) {
3679: document.getElementById(divid).style.display = 'none';
3680: }
3681: }
3682: }
3683: return;
3684: }
3685: // ]]>
3686: </script>
3687:
3688: ENDSCRIPT
3689: }
3690:
1.386 raeburn 3691: sub saml_javascript {
3692: return <<"ENDSCRIPT";
3693: <script type="text/javascript">
3694: // <![CDATA[
3695: function toggleSamlOptions(form,hostid) {
3696: var radioname = 'saml_'+hostid;
3697: var tablecellon = 'samloptionson_'+hostid;
3698: var tablecelloff = 'samloptionsoff_'+hostid;
3699: var num = form.elements[radioname].length;
3700: if (num) {
3701: var setvis = '';
3702: for (var i=0; i<num; i++) {
3703: if (form.elements[radioname][i].checked) {
3704: if (form.elements[radioname][i].value == '1') {
3705: if (document.getElementById(tablecellon)) {
3706: document.getElementById(tablecellon).style.display='';
3707: }
3708: if (document.getElementById(tablecelloff)) {
3709: document.getElementById(tablecelloff).style.display='none';
3710: }
3711: setvis = 1;
3712: }
3713: break;
3714: }
3715: }
3716: if (!setvis) {
3717: if (document.getElementById(tablecellon)) {
3718: document.getElementById(tablecellon).style.display='none';
3719: }
3720: if (document.getElementById(tablecelloff)) {
3721: document.getElementById(tablecelloff).style.display='';
3722: }
3723: }
3724: }
3725: return;
3726: }
3727: // ]]>
3728: </script>
3729:
3730: ENDSCRIPT
3731: }
3732:
1.394 raeburn 3733: sub ipaccess_javascript {
3734: my ($settings) = @_;
3735: my (%ordered,$total,%jstext);
3736: $total = 0;
3737: if (ref($settings) eq 'HASH') {
3738: foreach my $item (keys(%{$settings})) {
3739: if (ref($settings->{$item}) eq 'HASH') {
3740: my $num = $settings->{$item}{'order'};
3741: $ordered{$num} = $item;
3742: }
3743: }
3744: $total = scalar(keys(%{$settings}));
3745: }
3746: my @jsarray = ();
3747: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3748: push(@jsarray,$ordered{$item});
3749: }
3750: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3751: return <<"ENDSCRIPT";
3752: <script type="text/javascript">
3753: // <![CDATA[
3754: function reorderIPaccess(form,item) {
3755: var changedVal;
3756: $jstext
3757: var newpos = 'ipaccess_pos_add';
3758: var maxh = 1 + $total;
3759: var current = new Array;
3760: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3761: if (item == newpos) {
3762: changedVal = newitemVal;
3763: } else {
3764: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3765: current[newitemVal] = newpos;
3766: }
3767: for (var i=0; i<ipaccess.length; i++) {
3768: var elementName = 'ipaccess_pos_'+ipaccess[i];
3769: if (elementName != item) {
3770: if (form.elements[elementName]) {
3771: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3772: current[currVal] = elementName;
3773: }
3774: }
3775: }
3776: var oldVal;
3777: for (var j=0; j<maxh; j++) {
3778: if (current[j] == undefined) {
3779: oldVal = j;
3780: }
3781: }
3782: if (oldVal < changedVal) {
3783: for (var k=oldVal+1; k<=changedVal ; k++) {
3784: var elementName = current[k];
3785: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3786: }
3787: } else {
3788: for (var k=changedVal; k<oldVal; k++) {
3789: var elementName = current[k];
3790: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3791: }
3792: }
3793: return;
3794: }
3795: // ]]>
3796: </script>
3797:
3798: ENDSCRIPT
3799: }
3800:
1.3 raeburn 3801: sub print_autoenroll {
1.30 raeburn 3802: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3803: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3804: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3805: if (ref($settings) eq 'HASH') {
3806: if (exists($settings->{'run'})) {
3807: if ($settings->{'run'} eq '0') {
3808: $runoff = ' checked="checked" ';
3809: $runon = ' ';
3810: } else {
3811: $runon = ' checked="checked" ';
3812: $runoff = ' ';
3813: }
3814: } else {
3815: if ($autorun) {
3816: $runon = ' checked="checked" ';
3817: $runoff = ' ';
3818: } else {
3819: $runoff = ' checked="checked" ';
3820: $runon = ' ';
3821: }
3822: }
1.129 raeburn 3823: if (exists($settings->{'co-owners'})) {
3824: if ($settings->{'co-owners'} eq '0') {
3825: $coownersoff = ' checked="checked" ';
3826: $coownerson = ' ';
3827: } else {
3828: $coownerson = ' checked="checked" ';
3829: $coownersoff = ' ';
3830: }
3831: } else {
3832: $coownersoff = ' checked="checked" ';
3833: $coownerson = ' ';
3834: }
1.3 raeburn 3835: if (exists($settings->{'sender_domain'})) {
3836: $defdom = $settings->{'sender_domain'};
3837: }
1.274 raeburn 3838: if (exists($settings->{'autofailsafe'})) {
3839: $failsafe = $settings->{'autofailsafe'};
3840: }
1.14 raeburn 3841: } else {
3842: if ($autorun) {
3843: $runon = ' checked="checked" ';
3844: $runoff = ' ';
3845: } else {
3846: $runoff = ' checked="checked" ';
3847: $runon = ' ';
3848: }
1.3 raeburn 3849: }
3850: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3851: my $notif_sender;
3852: if (ref($settings) eq 'HASH') {
3853: $notif_sender = $settings->{'sender_uname'};
3854: }
1.3 raeburn 3855: my $datatable='<tr class="LC_odd_row">'.
3856: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3857: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3858: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3859: $runon.' value="1" />'.&mt('Yes').'</label> '.
3860: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3861: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3862: '</tr><tr>'.
3863: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3864: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3865: &mt('username').': '.
3866: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3867: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3868: ': '.$domform.'</span></td></tr>'.
3869: '<tr class="LC_odd_row">'.
3870: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3871: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3872: '<input type="radio" name="autoassign_coowners"'.
3873: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3874: '<label><input type="radio" name="autoassign_coowners"'.
3875: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3876: '</tr><tr>'.
3877: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3878: '<td class="LC_right_item"><span class="LC_nobreak">'.
3879: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3880: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3881: $$rowtotal += 4;
1.3 raeburn 3882: return $datatable;
3883: }
3884:
3885: sub print_autoupdate {
1.30 raeburn 3886: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 3887: my ($enable,$datatable);
1.3 raeburn 3888: if ($position eq 'top') {
1.385 raeburn 3889: my %choices = &Apache::lonlocal::texthash (
3890: run => 'Auto-update active?',
3891: classlists => 'Update information in classlists?',
3892: unexpired => 'Skip updates for users without active or future roles?',
3893: lastactive => 'Skip updates for inactive users?',
3894: );
3895: my $itemcount = 0;
1.3 raeburn 3896: my $updateon = ' ';
3897: my $updateoff = ' checked="checked" ';
3898: if (ref($settings) eq 'HASH') {
3899: if ($settings->{'run'} eq '1') {
3900: $updateon = $updateoff;
3901: $updateoff = ' ';
3902: }
3903: }
1.385 raeburn 3904: $enable = '<tr class="LC_odd_row">'.
3905: '<td>'.$choices{'run'}.'</td>'.
3906: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3907: '<input type="radio" name="autoupdate_run"'.
1.397 ! raeburn 3908: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3909: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 3910: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3911: '</tr>';
1.385 raeburn 3912: my @toggles = ('classlists','unexpired');
3913: my %defaultchecked = ('classlists' => 'off',
3914: 'unexpired' => 'off'
3915: );
3916: $$rowtotal ++;
3917: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3918: \%choices,$itemcount,'','','left','no');
3919: $datatable = $enable.$datatable;
3920: $$rowtotal += $itemcount;
3921: my $lastactiveon = ' ';
3922: my $lastactiveoff = ' checked="checked" ';
3923: my $lastactivestyle = 'none';
3924: my $lastactivedays;
3925: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3926: if (ref($settings) eq 'HASH') {
3927: if ($settings->{'lastactive'} =~ /^\d+$/) {
3928: $lastactiveon = $lastactiveoff;
3929: $lastactiveoff = ' ';
3930: $lastactivestyle = 'inline-block';
3931: $lastactivedays = $settings->{'lastactive'};
3932: }
3933: }
3934: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3935: $datatable .= '<tr'.$css_class.'>'.
3936: '<td>'.$choices{'lastactive'}.'</td>'.
3937: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3938: '<input type="radio" name="lastactive"'.
3939: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3940: ' <label>'.
3941: '<input type="radio" name="lastactive"'.
3942: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3943: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3944: ': '.&mt('inactive = no activity in last [_1] days',
3945: '<input type="text" size="5" name="lastactivedays" value="'.
3946: $lastactivedays.'" />').
3947: '</span></td>'.
3948: '</tr>';
3949: $$rowtotal ++;
1.131 raeburn 3950: } elsif ($position eq 'middle') {
3951: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3952: my $numinrow = 3;
3953: my $locknamesettings;
3954: $datatable .= &insttypes_row($settings,$types,$usertypes,
3955: $dom,$numinrow,$othertitle,
1.305 raeburn 3956: 'lockablenames',$rowtotal);
1.131 raeburn 3957: $$rowtotal ++;
1.3 raeburn 3958: } else {
1.44 raeburn 3959: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3960: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3961: 'permanentemail','id');
1.33 raeburn 3962: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3963: my $numrows = 0;
1.26 raeburn 3964: if (ref($types) eq 'ARRAY') {
3965: if (@{$types} > 0) {
3966: $datatable =
3967: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3968: \@fields,$types,\$numrows);
1.30 raeburn 3969: $$rowtotal += @{$types};
1.26 raeburn 3970: }
1.3 raeburn 3971: }
3972: $datatable .=
3973: &usertype_update_row($settings,{'default' => $othertitle},
3974: \%fieldtitles,\@fields,['default'],
3975: \$numrows);
1.30 raeburn 3976: $$rowtotal ++;
1.3 raeburn 3977: }
3978: return $datatable;
3979: }
3980:
1.125 raeburn 3981: sub print_autocreate {
3982: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3983: my (%createon,%createoff,%currhash);
1.125 raeburn 3984: my @types = ('xml','req');
3985: if (ref($settings) eq 'HASH') {
3986: foreach my $item (@types) {
3987: $createoff{$item} = ' checked="checked" ';
3988: $createon{$item} = ' ';
3989: if (exists($settings->{$item})) {
3990: if ($settings->{$item}) {
3991: $createon{$item} = ' checked="checked" ';
3992: $createoff{$item} = ' ';
3993: }
3994: }
3995: }
1.210 raeburn 3996: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3997: $currhash{$settings->{'xmldc'}} = 1;
3998: }
1.125 raeburn 3999: } else {
4000: foreach my $item (@types) {
4001: $createoff{$item} = ' checked="checked" ';
4002: $createon{$item} = ' ';
4003: }
4004: }
4005: $$rowtotal += 2;
1.191 raeburn 4006: my $numinrow = 2;
1.125 raeburn 4007: my $datatable='<tr class="LC_odd_row">'.
4008: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4009: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4010: '<input type="radio" name="autocreate_xml"'.
4011: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4012: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4013: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4014: '</td></tr><tr>'.
4015: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4016: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4017: '<input type="radio" name="autocreate_req"'.
4018: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4019: '<label><input type="radio" name="autocreate_req"'.
4020: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4021: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4022: 'autocreate_xmldc',%currhash);
1.247 raeburn 4023: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4024: if ($numdc > 1) {
1.247 raeburn 4025: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4026: '</td><td class="LC_left_item">';
1.125 raeburn 4027: } else {
1.247 raeburn 4028: $datatable .= &mt('Course creation processed as:').
4029: '</td><td class="LC_right_item">';
1.125 raeburn 4030: }
1.247 raeburn 4031: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4032: $$rowtotal += $rows;
1.125 raeburn 4033: return $datatable;
4034: }
4035:
1.23 raeburn 4036: sub print_directorysrch {
1.277 raeburn 4037: my ($position,$dom,$settings,$rowtotal) = @_;
4038: my $datatable;
4039: if ($position eq 'top') {
4040: my $instsrchon = ' ';
4041: my $instsrchoff = ' checked="checked" ';
4042: my ($exacton,$containson,$beginson);
4043: my $instlocalon = ' ';
4044: my $instlocaloff = ' checked="checked" ';
4045: if (ref($settings) eq 'HASH') {
4046: if ($settings->{'available'} eq '1') {
4047: $instsrchon = $instsrchoff;
4048: $instsrchoff = ' ';
4049: }
4050: if ($settings->{'localonly'} eq '1') {
4051: $instlocalon = $instlocaloff;
4052: $instlocaloff = ' ';
4053: }
4054: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4055: foreach my $type (@{$settings->{'searchtypes'}}) {
4056: if ($type eq 'exact') {
4057: $exacton = ' checked="checked" ';
4058: } elsif ($type eq 'contains') {
4059: $containson = ' checked="checked" ';
4060: } elsif ($type eq 'begins') {
4061: $beginson = ' checked="checked" ';
4062: }
4063: }
4064: } else {
4065: if ($settings->{'searchtypes'} eq 'exact') {
4066: $exacton = ' checked="checked" ';
4067: } elsif ($settings->{'searchtypes'} eq 'contains') {
4068: $containson = ' checked="checked" ';
4069: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4070: $exacton = ' checked="checked" ';
4071: $containson = ' checked="checked" ';
4072: }
4073: }
1.277 raeburn 4074: }
4075: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4076: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4077:
4078: my $numinrow = 4;
4079: my $cansrchrow = 0;
4080: $datatable='<tr class="LC_odd_row">'.
4081: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4082: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4083: '<input type="radio" name="dirsrch_available"'.
4084: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4085: '<label><input type="radio" name="dirsrch_available"'.
4086: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4087: '</tr><tr>'.
4088: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4089: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4090: '<input type="radio" name="dirsrch_instlocalonly"'.
4091: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4092: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4093: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4094: '</tr>';
4095: $$rowtotal += 2;
4096: if (ref($usertypes) eq 'HASH') {
4097: if (keys(%{$usertypes}) > 0) {
4098: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4099: $numinrow,$othertitle,'cansearch',
4100: $rowtotal);
1.277 raeburn 4101: $cansrchrow = 1;
1.25 raeburn 4102: }
1.23 raeburn 4103: }
1.277 raeburn 4104: if ($cansrchrow) {
4105: $$rowtotal ++;
4106: $datatable .= '<tr>';
4107: } else {
4108: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4109: }
1.277 raeburn 4110: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4111: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4112: foreach my $title (@{$titleorder}) {
4113: if (defined($searchtitles->{$title})) {
4114: my $check = ' ';
4115: if (ref($settings) eq 'HASH') {
4116: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4117: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4118: $check = ' checked="checked" ';
4119: }
1.39 raeburn 4120: }
1.25 raeburn 4121: }
1.277 raeburn 4122: $datatable .= '<td class="LC_left_item">'.
4123: '<span class="LC_nobreak"><label>'.
4124: '<input type="checkbox" name="searchby" '.
4125: 'value="'.$title.'"'.$check.'/>'.
4126: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4127: }
4128: }
1.277 raeburn 4129: $datatable .= '</tr></table></td></tr>';
4130: $$rowtotal ++;
4131: if ($cansrchrow) {
4132: $datatable .= '<tr class="LC_odd_row">';
4133: } else {
4134: $datatable .= '<tr>';
4135: }
4136: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4137: '<td class="LC_left_item" colspan="2">'.
4138: '<span class="LC_nobreak"><label>'.
4139: '<input type="checkbox" name="searchtypes" '.
4140: $exacton.' value="exact" />'.&mt('Exact match').
4141: '</label> '.
4142: '<label><input type="checkbox" name="searchtypes" '.
4143: $beginson.' value="begins" />'.&mt('Begins with').
4144: '</label> '.
4145: '<label><input type="checkbox" name="searchtypes" '.
4146: $containson.' value="contains" />'.&mt('Contains').
4147: '</label></span></td></tr>';
4148: $$rowtotal ++;
1.26 raeburn 4149: } else {
1.277 raeburn 4150: my $domsrchon = ' checked="checked" ';
4151: my $domsrchoff = ' ';
4152: my $domlocalon = ' ';
4153: my $domlocaloff = ' checked="checked" ';
4154: if (ref($settings) eq 'HASH') {
4155: if ($settings->{'lclocalonly'} eq '1') {
4156: $domlocalon = $domlocaloff;
4157: $domlocaloff = ' ';
4158: }
4159: if ($settings->{'lcavailable'} eq '0') {
4160: $domsrchoff = $domsrchon;
4161: $domsrchon = ' ';
4162: }
4163: }
4164: $datatable='<tr class="LC_odd_row">'.
4165: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4166: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4167: '<input type="radio" name="dirsrch_domavailable"'.
4168: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4169: '<label><input type="radio" name="dirsrch_domavailable"'.
4170: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4171: '</tr><tr>'.
4172: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4173: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4174: '<input type="radio" name="dirsrch_domlocalonly"'.
4175: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4176: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4177: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4178: '</tr>';
4179: $$rowtotal += 2;
1.26 raeburn 4180: }
1.25 raeburn 4181: return $datatable;
4182: }
4183:
1.28 raeburn 4184: sub print_contacts {
1.286 raeburn 4185: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4186: my $datatable;
4187: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4188: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4189: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4190: if ($position eq 'top') {
4191: if (ref($settings) eq 'HASH') {
4192: foreach my $item (@contacts) {
4193: if (exists($settings->{$item})) {
4194: $to{$item} = $settings->{$item};
4195: }
4196: }
4197: }
4198: } elsif ($position eq 'middle') {
4199: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4200: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4201: foreach my $type (@mailings) {
4202: $otheremails{$type} = '';
4203: }
1.340 raeburn 4204: } elsif ($position eq 'lower') {
4205: if (ref($settings) eq 'HASH') {
4206: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4207: %lonstatus = %{$settings->{'lonstatus'}};
4208: }
4209: }
1.286 raeburn 4210: } else {
4211: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4212: foreach my $type (@mailings) {
4213: $otheremails{$type} = '';
4214: }
1.286 raeburn 4215: $bccemails{'helpdeskmail'} = '';
4216: $bccemails{'otherdomsmail'} = '';
4217: $includestr{'helpdeskmail'} = '';
4218: $includestr{'otherdomsmail'} = '';
4219: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4220: }
1.28 raeburn 4221: if (ref($settings) eq 'HASH') {
1.340 raeburn 4222: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4223: foreach my $type (@mailings) {
4224: if (exists($settings->{$type})) {
4225: if (ref($settings->{$type}) eq 'HASH') {
4226: foreach my $item (@contacts) {
4227: if ($settings->{$type}{$item}) {
4228: $checked{$type}{$item} = ' checked="checked" ';
4229: }
4230: }
4231: $otheremails{$type} = $settings->{$type}{'others'};
4232: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4233: $bccemails{$type} = $settings->{$type}{'bcc'};
4234: if ($settings->{$type}{'include'} ne '') {
4235: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4236: $includestr{$type} = &unescape($includestr{$type});
4237: }
4238: }
4239: }
4240: } elsif ($type eq 'lonstatusmail') {
4241: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4242: }
1.28 raeburn 4243: }
4244: }
1.286 raeburn 4245: if ($position eq 'bottom') {
4246: foreach my $type (@mailings) {
4247: $bccemails{$type} = $settings->{$type}{'bcc'};
4248: if ($settings->{$type}{'include'} ne '') {
4249: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4250: $includestr{$type} = &unescape($includestr{$type});
4251: }
4252: }
4253: if (ref($settings->{'helpform'}) eq 'HASH') {
4254: if (ref($fields) eq 'ARRAY') {
4255: foreach my $field (@{$fields}) {
4256: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4257: }
1.286 raeburn 4258: }
4259: if (exists($settings->{'helpform'}{'maxsize'})) {
4260: $maxsize = $settings->{'helpform'}{'maxsize'};
4261: } else {
1.289 raeburn 4262: $maxsize = '1.0';
1.286 raeburn 4263: }
4264: } else {
4265: if (ref($fields) eq 'ARRAY') {
4266: foreach my $field (@{$fields}) {
4267: $currfield{$field} = 'yes';
1.134 raeburn 4268: }
1.28 raeburn 4269: }
1.286 raeburn 4270: $maxsize = '1.0';
1.28 raeburn 4271: }
4272: }
4273: } else {
1.286 raeburn 4274: if ($position eq 'top') {
4275: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4276: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4277: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4278: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4279: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4280: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4281: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4282: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4283: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4284: } elsif ($position eq 'bottom') {
4285: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4286: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4287: if (ref($fields) eq 'ARRAY') {
4288: foreach my $field (@{$fields}) {
4289: $currfield{$field} = 'yes';
4290: }
4291: }
4292: $maxsize = '1.0';
4293: }
1.28 raeburn 4294: }
4295: my ($titles,$short_titles) = &contact_titles();
4296: my $rownum = 0;
4297: my $css_class;
1.286 raeburn 4298: if ($position eq 'top') {
4299: foreach my $item (@contacts) {
4300: $css_class = $rownum%2?' class="LC_odd_row"':'';
4301: $datatable .= '<tr'.$css_class.'>'.
4302: '<td><span class="LC_nobreak">'.$titles->{$item}.
4303: '</span></td><td class="LC_right_item">'.
4304: '<input type="text" name="'.$item.'" value="'.
4305: $to{$item}.'" /></td></tr>';
4306: $rownum ++;
4307: }
1.315 raeburn 4308: } elsif ($position eq 'bottom') {
4309: $css_class = $rownum%2?' class="LC_odd_row"':'';
4310: $datatable .= '<tr'.$css_class.'>'.
4311: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4312: &mt('(e-mail, subject, and description always shown)').
4313: '</td><td class="LC_left_item">';
4314: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4315: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4316: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4317: foreach my $field (@{$fields}) {
4318: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4319: if (($field eq 'screenshot') || ($field eq 'cc')) {
4320: $datatable .= ' '.&mt('(logged-in users)');
4321: }
4322: $datatable .='</td><td>';
4323: my $clickaction;
4324: if ($field eq 'screenshot') {
4325: $clickaction = ' onclick="screenshotSize(this);"';
4326: }
4327: if (ref($possoptions->{$field}) eq 'ARRAY') {
4328: foreach my $option (@{$possoptions->{$field}}) {
4329: my $checked;
4330: if ($currfield{$field} eq $option) {
4331: $checked = ' checked="checked"';
4332: }
4333: $datatable .= '<span class="LC_nobreak"><label>'.
4334: '<input type="radio" name="helpform_'.$field.'" '.
4335: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4336: '</label></span>'.(' 'x2);
4337: }
4338: }
4339: if ($field eq 'screenshot') {
4340: my $display;
4341: if ($currfield{$field} eq 'no') {
4342: $display = ' style="display:none"';
4343: }
1.334 raeburn 4344: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4345: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4346: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4347: }
4348: $datatable .= '</td></tr>';
4349: }
4350: $datatable .= '</table>';
4351: }
4352: $datatable .= '</td></tr>'."\n";
4353: $rownum ++;
4354: }
1.340 raeburn 4355: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4356: foreach my $type (@mailings) {
4357: $css_class = $rownum%2?' class="LC_odd_row"':'';
4358: $datatable .= '<tr'.$css_class.'>'.
4359: '<td><span class="LC_nobreak">'.
4360: $titles->{$type}.': </span></td>'.
4361: '<td class="LC_left_item">';
4362: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4363: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4364: }
4365: $datatable .= '<span class="LC_nobreak">';
4366: foreach my $item (@contacts) {
4367: $datatable .= '<label>'.
4368: '<input type="checkbox" name="'.$type.'"'.
4369: $checked{$type}{$item}.
4370: ' value="'.$item.'" />'.$short_titles->{$item}.
4371: '</label> ';
4372: }
4373: $datatable .= '</span><br />'.&mt('Others').': '.
4374: '<input type="text" name="'.$type.'_others" '.
4375: 'value="'.$otheremails{$type}.'" />';
4376: my %locchecked;
4377: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4378: foreach my $loc ('s','b') {
4379: if ($includeloc{$type} eq $loc) {
4380: $locchecked{$loc} = ' checked="checked"';
4381: last;
4382: }
4383: }
4384: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4385: '<input type="text" name="'.$type.'_bcc" '.
4386: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4387: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4388: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4389: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4390: '<span class="LC_nobreak">'.&mt('Location:').' '.
4391: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4392: (' 'x2).
4393: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4394: '</span></fieldset>';
4395: }
4396: $datatable .= '</td></tr>'."\n";
4397: $rownum ++;
4398: }
1.28 raeburn 4399: }
1.286 raeburn 4400: if ($position eq 'middle') {
4401: my %choices;
1.340 raeburn 4402: my $corelink = &core_link_msu();
4403: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4404: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4405: $corelink);
4406: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4407: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4408: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4409: 'reportupdates' => 'on',
4410: 'reportstatus' => 'on');
1.286 raeburn 4411: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4412: \%choices,$rownum);
4413: $datatable .= $reports;
1.340 raeburn 4414: } elsif ($position eq 'lower') {
1.378 raeburn 4415: my (%current,%excluded,%weights);
1.340 raeburn 4416: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4417: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4418: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4419: } else {
1.378 raeburn 4420: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4421: }
4422: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4423: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4424: } else {
1.378 raeburn 4425: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4426: }
4427: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4428: foreach my $type ('E','W','N','U') {
1.340 raeburn 4429: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4430: $weights{$type} = $lonstatus{'weights'}{$type};
4431: } else {
4432: $weights{$type} = $defaults->{$type};
4433: }
4434: }
4435: } else {
1.341 raeburn 4436: foreach my $type ('E','W','N','U') {
1.340 raeburn 4437: $weights{$type} = $defaults->{$type};
4438: }
4439: }
4440: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4441: if (@{$lonstatus{'excluded'}} > 0) {
4442: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4443: }
4444: }
1.378 raeburn 4445: foreach my $item ('errorthreshold','errorsysmail') {
4446: $css_class = $rownum%2?' class="LC_odd_row"':'';
4447: $datatable .= '<tr'.$css_class.'>'.
4448: '<td class="LC_left_item"><span class="LC_nobreak">'.
4449: $titles->{$item}.
4450: '</span></td><td class="LC_left_item">'.
4451: '<input type="text" name="'.$item.'" value="'.
4452: $current{$item}.'" size="5" /></td></tr>';
4453: $rownum ++;
4454: }
1.340 raeburn 4455: $css_class = $rownum%2?' class="LC_odd_row"':'';
4456: $datatable .= '<tr'.$css_class.'>'.
4457: '<td class="LC_left_item">'.
4458: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4459: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4460: foreach my $type ('E','W','N','U') {
1.340 raeburn 4461: $datatable .= '<td>'.$names->{$type}.'<br />'.
4462: '<input type="text" name="errorweights_'.$type.'" value="'.
4463: $weights{$type}.'" size="5" /></td>';
4464: }
4465: $datatable .= '</tr></table></tr>';
4466: $rownum ++;
4467: $css_class = $rownum%2?' class="LC_odd_row"':'';
4468: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4469: $titles->{'errorexcluded'}.'</td>'.
4470: '<td class="LC_left_item"><table>';
4471: my $numinrow = 4;
4472: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4473: for (my $i=0; $i<@ids; $i++) {
4474: my $rem = $i%($numinrow);
4475: if ($rem == 0) {
4476: if ($i > 0) {
4477: $datatable .= '</tr>';
4478: }
4479: $datatable .= '<tr>';
4480: }
4481: my $check;
4482: if ($excluded{$ids[$i]}) {
4483: $check = ' checked="checked" ';
4484: }
4485: $datatable .= '<td class="LC_left_item">'.
4486: '<span class="LC_nobreak"><label>'.
4487: '<input type="checkbox" name="errorexcluded" '.
4488: 'value="'.$ids[$i].'"'.$check.' />'.
4489: $ids[$i].'</label></span></td>';
4490: }
4491: my $colsleft = $numinrow - @ids%($numinrow);
4492: if ($colsleft > 1 ) {
4493: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4494: ' </td>';
4495: } elsif ($colsleft == 1) {
4496: $datatable .= '<td class="LC_left_item"> </td>';
4497: }
4498: $datatable .= '</tr></table></td></tr>';
4499: $rownum ++;
1.286 raeburn 4500: } elsif ($position eq 'bottom') {
1.315 raeburn 4501: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4502: my (@posstypes,%usertypeshash);
4503: if (ref($types) eq 'ARRAY') {
4504: @posstypes = @{$types};
4505: }
4506: if (@posstypes) {
4507: if (ref($usertypes) eq 'HASH') {
4508: %usertypeshash = %{$usertypes};
4509: }
4510: my @overridden;
4511: my $numinrow = 4;
4512: if (ref($settings) eq 'HASH') {
4513: if (ref($settings->{'overrides'}) eq 'HASH') {
4514: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4515: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4516: push(@overridden,$key);
4517: foreach my $item (@contacts) {
4518: if ($settings->{'overrides'}{$key}{$item}) {
4519: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4520: }
4521: }
4522: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4523: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4524: $includeloc{'override_'.$key} = '';
4525: $includestr{'override_'.$key} = '';
4526: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4527: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4528: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4529: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4530: }
1.286 raeburn 4531: }
4532: }
4533: }
1.315 raeburn 4534: }
4535: my $customclass = 'LC_helpdesk_override';
4536: my $optionsprefix = 'LC_options_helpdesk_';
4537:
4538: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4539:
4540: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4541: $numinrow,$othertitle,'overrides',
4542: \$rownum,$onclicktypes,$customclass);
4543: $rownum ++;
4544: $usertypeshash{'default'} = $othertitle;
4545: foreach my $status (@posstypes) {
4546: my $css_class;
4547: if ($rownum%2) {
4548: $css_class = 'LC_odd_row ';
4549: }
4550: $css_class .= $customclass;
4551: my $rowid = $optionsprefix.$status;
4552: my $hidden = 1;
4553: my $currstyle = 'display:none';
4554: if (grep(/^\Q$status\E$/,@overridden)) {
4555: $currstyle = 'display:table-row';
4556: $hidden = 0;
4557: }
4558: my $key = 'override_'.$status;
4559: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4560: $includeloc{$key},$includestr{$key},$status,$rowid,
4561: $usertypeshash{$status},$css_class,$currstyle,
4562: \@contacts,$short_titles);
4563: unless ($hidden) {
4564: $rownum ++;
1.286 raeburn 4565: }
4566: }
1.134 raeburn 4567: }
1.28 raeburn 4568: }
1.30 raeburn 4569: $$rowtotal += $rownum;
1.28 raeburn 4570: return $datatable;
4571: }
4572:
1.340 raeburn 4573: sub core_link_msu {
4574: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4575: &mt('LON-CAPA core group - MSU'),600,500);
4576: }
4577:
1.315 raeburn 4578: sub overridden_helpdesk {
4579: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4580: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4581: my $class = 'LC_left_item';
4582: if ($css_class) {
4583: $css_class = ' class="'.$css_class.'"';
4584: }
4585: if ($rowid) {
4586: $rowid = ' id="'.$rowid.'"';
4587: }
4588: if ($rowstyle) {
4589: $rowstyle = ' style="'.$rowstyle.'"';
4590: }
4591: my ($output,$description);
4592: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4593: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4594: "<td>$description</td>\n".
4595: '<td class="'.$class.'" colspan="2">'.
4596: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4597: '<span class="LC_nobreak">';
4598: if (ref($contacts) eq 'ARRAY') {
4599: foreach my $item (@{$contacts}) {
4600: my $check;
4601: if (ref($checked) eq 'HASH') {
4602: $check = $checked->{$item};
4603: }
4604: my $title;
4605: if (ref($short_titles) eq 'HASH') {
4606: $title = $short_titles->{$item};
4607: }
4608: $output .= '<label>'.
4609: '<input type="checkbox" name="override_'.$type.'"'.$check.
4610: ' value="'.$item.'" />'.$title.'</label> ';
4611: }
4612: }
4613: $output .= '</span><br />'.&mt('Others').': '.
4614: '<input type="text" name="override_'.$type.'_others" '.
4615: 'value="'.$otheremails.'" />';
4616: my %locchecked;
4617: foreach my $loc ('s','b') {
4618: if ($includeloc eq $loc) {
4619: $locchecked{$loc} = ' checked="checked"';
4620: last;
4621: }
4622: }
4623: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4624: '<input type="text" name="override_'.$type.'_bcc" '.
4625: 'value="'.$bccemails.'" /></fieldset>'.
4626: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4627: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4628: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4629: '<span class="LC_nobreak">'.&mt('Location:').' '.
4630: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4631: (' 'x2).
4632: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4633: '</span></fieldset>'.
4634: '</td></tr>'."\n";
4635: return $output;
4636: }
4637:
1.286 raeburn 4638: sub contacts_javascript {
4639: return <<"ENDSCRIPT";
4640:
4641: <script type="text/javascript">
4642: // <![CDATA[
4643:
4644: function screenshotSize(field) {
4645: if (document.getElementById('help_screenshotsize')) {
4646: if (field.value == 'no') {
1.289 raeburn 4647: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4648: } else {
4649: document.getElementById('help_screenshotsize').style.display="";
4650: }
4651: }
4652: return;
4653: }
4654:
1.315 raeburn 4655: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4656: if (form.elements[checkbox].length != undefined) {
4657: var count = 0;
4658: if (docount) {
4659: for (var i=0; i<form.elements[checkbox].length; i++) {
4660: if (form.elements[checkbox][i].checked) {
4661: count ++;
4662: }
4663: }
4664: }
4665: for (var i=0; i<form.elements[checkbox].length; i++) {
4666: var type = form.elements[checkbox][i].value;
4667: if (document.getElementById(prefix+type)) {
4668: if (form.elements[checkbox][i].checked) {
4669: document.getElementById(prefix+type).style.display = 'table-row';
4670: if (count % 2 == 1) {
4671: document.getElementById(prefix+type).className = target+' LC_odd_row';
4672: } else {
4673: document.getElementById(prefix+type).className = target;
4674: }
4675: count ++;
4676: } else {
4677: document.getElementById(prefix+type).style.display = 'none';
4678: }
4679: }
4680: }
4681: }
4682: return;
4683: }
4684:
4685:
1.286 raeburn 4686: // ]]>
4687: </script>
4688:
4689: ENDSCRIPT
4690: }
4691:
1.118 jms 4692: sub print_helpsettings {
1.282 raeburn 4693: my ($position,$dom,$settings,$rowtotal) = @_;
4694: my $confname = $dom.'-domainconfig';
1.285 raeburn 4695: my $formname = 'display';
1.168 raeburn 4696: my ($datatable,$itemcount);
1.282 raeburn 4697: if ($position eq 'top') {
4698: $itemcount = 1;
4699: my (%choices,%defaultchecked,@toggles);
4700: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4701: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4702: &mt('LON-CAPA bug tracker'),600,500));
4703: %defaultchecked = ('submitbugs' => 'on');
4704: @toggles = ('submitbugs');
4705: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4706: \%choices,$itemcount);
4707: $$rowtotal ++;
4708: } else {
4709: my $css_class;
4710: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4711: my (%customroles,%ordered,%current);
1.301 raeburn 4712: if (ref($settings) eq 'HASH') {
4713: if (ref($settings->{'adhoc'}) eq 'HASH') {
4714: %current = %{$settings->{'adhoc'}};
4715: }
1.285 raeburn 4716: }
4717: my $count = 0;
4718: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4719: if ($key=~/^rolesdef\_(\w+)$/) {
4720: my $rolename = $1;
1.285 raeburn 4721: my (%privs,$order);
1.282 raeburn 4722: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4723: $customroles{$rolename} = \%privs;
1.285 raeburn 4724: if (ref($current{$rolename}) eq 'HASH') {
4725: $order = $current{$rolename}{'order'};
4726: }
4727: if ($order eq '') {
4728: $order = $count;
4729: }
4730: $ordered{$order} = $rolename;
4731: $count++;
4732: }
4733: }
4734: my $maxnum = scalar(keys(%ordered));
4735: my @roles_by_num = ();
4736: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4737: push(@roles_by_num,$item);
4738: }
4739: my $context = 'domprefs';
4740: my $crstype = 'Course';
4741: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4742: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4743: my ($numstatustypes,@jsarray);
4744: if (ref($types) eq 'ARRAY') {
4745: if (@{$types} > 0) {
4746: $numstatustypes = scalar(@{$types});
4747: push(@accesstypes,'status');
4748: @jsarray = ('bystatus');
1.282 raeburn 4749: }
4750: }
1.290 raeburn 4751: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4752: if (keys(%domhelpdesk)) {
4753: push(@accesstypes,('inc','exc'));
4754: push(@jsarray,('notinc','notexc'));
4755: }
4756: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4757: my $context = 'domprefs';
4758: my $crstype = 'Course';
1.285 raeburn 4759: my $prefix = 'helproles_';
4760: my $add_class = 'LC_hidden';
4761: foreach my $num (@roles_by_num) {
4762: my $role = $ordered{$num};
4763: my ($desc,$access,@statuses);
4764: if (ref($current{$role}) eq 'HASH') {
4765: $desc = $current{$role}{'desc'};
4766: $access = $current{$role}{'access'};
4767: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4768: @statuses = @{$current{$role}{'insttypes'}};
4769: }
4770: }
4771: if ($desc eq '') {
4772: $desc = $role;
4773: }
4774: my $identifier = 'custhelp'.$num;
1.282 raeburn 4775: my %full=();
4776: my %levels= (
4777: course => {},
4778: domain => {},
4779: system => {},
4780: );
4781: my %levelscurrent=(
4782: course => {},
4783: domain => {},
4784: system => {},
4785: );
4786: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4787: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4788: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4789: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4790: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4791: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4792: for (my $k=0; $k<=$maxnum; $k++) {
4793: my $vpos = $k+1;
4794: my $selstr;
4795: if ($k == $num) {
4796: $selstr = ' selected="selected" ';
4797: }
4798: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4799: }
4800: $datatable .= '</select>'.(' 'x2).
4801: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4802: '</td>'.
4803: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4804: &mt('Name shown to users:').
4805: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4806: '</fieldset>'.
4807: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4808: $othertitle,$usertypes,$types,\%domhelpdesk).
4809: '<fieldset>'.
4810: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4811: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4812: \%levelscurrent,$identifier,
4813: 'LC_hidden',$prefix.$num.'_privs').
4814: '</fieldset></td>';
1.282 raeburn 4815: $itemcount ++;
4816: }
4817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4818: my $newcust = 'custhelp'.$count;
4819: my (%privs,%levelscurrent);
4820: my %full=();
4821: my %levels= (
4822: course => {},
4823: domain => {},
4824: system => {},
4825: );
4826: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4827: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4828: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4829: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4830: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4831: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4832: for (my $k=0; $k<$maxnum+1; $k++) {
4833: my $vpos = $k+1;
4834: my $selstr;
4835: if ($k == $maxnum) {
4836: $selstr = ' selected="selected" ';
4837: }
4838: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4839: }
4840: $datatable .= '</select> '."\n".
1.282 raeburn 4841: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4842: '</label></span></td>'.
1.285 raeburn 4843: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4844: '<span class="LC_nobreak">'.
4845: &mt('Internal name:').
4846: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4847: '</span>'.(' 'x4).
4848: '<span class="LC_nobreak">'.
4849: &mt('Name shown to users:').
4850: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4851: '</span></fieldset>'.
4852: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4853: $usertypes,$types,\%domhelpdesk).
4854: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4855: &Apache::lonuserutils::custom_role_header($context,$crstype,
4856: \@templateroles,$newcust).
4857: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4858: \%levelscurrent,$newcust).
1.334 raeburn 4859: '</fieldset>'.
4860: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4861: '</td></tr>';
1.282 raeburn 4862: $count ++;
4863: $$rowtotal += $count;
4864: }
1.166 raeburn 4865: return $datatable;
1.121 raeburn 4866: }
4867:
1.285 raeburn 4868: sub adhocbutton {
4869: my ($prefix,$num,$field,$visibility) = @_;
4870: my %lt = &Apache::lonlocal::texthash(
4871: show => 'Show details',
4872: hide => 'Hide details',
4873: );
4874: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4875: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4876: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4877: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4878: }
4879:
4880: sub helpsettings_javascript {
4881: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4882: return unless(ref($roles_by_num) eq 'ARRAY');
4883: my %html_js_lt = &Apache::lonlocal::texthash(
4884: show => 'Show details',
4885: hide => 'Hide details',
4886: );
4887: &html_escape(\%html_js_lt);
4888: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4889: return <<"ENDSCRIPT";
4890: <script type="text/javascript">
4891: // <![CDATA[
4892:
4893: function reorderHelpRoles(form,item) {
4894: var changedVal;
4895: $jstext
4896: var newpos = 'helproles_${total}_pos';
4897: var maxh = 1 + $total;
4898: var current = new Array();
4899: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4900: if (item == newpos) {
4901: changedVal = newitemVal;
4902: } else {
4903: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4904: current[newitemVal] = newpos;
4905: }
4906: for (var i=0; i<helproles.length; i++) {
4907: var elementName = 'helproles_'+helproles[i]+'_pos';
4908: if (elementName != item) {
4909: if (form.elements[elementName]) {
4910: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4911: current[currVal] = elementName;
4912: }
4913: }
4914: }
4915: var oldVal;
4916: for (var j=0; j<maxh; j++) {
4917: if (current[j] == undefined) {
4918: oldVal = j;
4919: }
4920: }
4921: if (oldVal < changedVal) {
4922: for (var k=oldVal+1; k<=changedVal ; k++) {
4923: var elementName = current[k];
4924: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4925: }
4926: } else {
4927: for (var k=changedVal; k<oldVal; k++) {
4928: var elementName = current[k];
4929: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4930: }
4931: }
4932: return;
4933: }
4934:
4935: function helpdeskAccess(num) {
4936: var curraccess = null;
4937: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4938: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4939: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4940: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4941: }
4942: }
4943: }
4944: var shown = Array();
4945: var hidden = Array();
4946: if (curraccess == 'none') {
4947: hidden = Array('$hiddenstr');
4948: } else {
4949: if (curraccess == 'status') {
4950: shown = Array('bystatus');
4951: hidden = Array('notinc','notexc');
4952: } else {
4953: if (curraccess == 'exc') {
4954: shown = Array('notexc');
4955: hidden = Array('notinc','bystatus');
4956: }
4957: if (curraccess == 'inc') {
4958: shown = Array('notinc');
4959: hidden = Array('notexc','bystatus');
4960: }
1.293 raeburn 4961: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4962: hidden = Array('notinc','notexc','bystatus');
4963: }
4964: }
4965: }
4966: if (hidden.length > 0) {
4967: for (var i=0; i<hidden.length; i++) {
4968: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4969: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4970: }
4971: }
4972: }
4973: if (shown.length > 0) {
4974: for (var i=0; i<shown.length; i++) {
4975: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4976: if (shown[i] == 'privs') {
4977: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4978: } else {
4979: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4980: }
4981: }
4982: }
4983: }
4984: return;
4985: }
4986:
4987: function toggleHelpdeskItem(num,field) {
4988: if (document.getElementById('helproles_'+num+'_'+field)) {
4989: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4990: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4991: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4992: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4993: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4994: }
4995: } else {
4996: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4997: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4998: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4999: }
5000: }
5001: }
5002: return;
5003: }
5004:
5005: // ]]>
5006: </script>
5007:
5008: ENDSCRIPT
5009: }
5010:
5011: sub helpdeskroles_access {
5012: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5013: $usertypes,$types,$domhelpdesk) = @_;
5014: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5015: my %lt = &Apache::lonlocal::texthash(
5016: 'rou' => 'Role usage',
5017: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5018: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5019: 'dh' => 'All with domain helpdesk role',
5020: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5021: 'none' => 'None',
5022: 'status' => 'Determined based on institutional status',
5023: 'inc' => 'Include all, but exclude specific personnel',
5024: 'exc' => 'Exclude all, but include specific personnel',
5025: );
5026: my %usecheck = (
5027: all => ' checked="checked"',
5028: );
5029: my %displaydiv = (
5030: status => 'none',
5031: inc => 'none',
5032: exc => 'none',
5033: priv => 'block',
5034: );
5035: my $output;
5036: if (ref($current) eq 'HASH') {
5037: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5038: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5039: $usecheck{$current->{access}} = $usecheck{'all'};
5040: delete($usecheck{'all'});
5041: if ($current->{access} =~ /^(status|inc|exc)$/) {
5042: my $access = $1;
5043: $displaydiv{$access} = 'inline';
5044: } elsif ($current->{access} eq 'none') {
5045: $displaydiv{'priv'} = 'none';
5046: }
5047: }
5048: }
5049: }
5050: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5051: '<p>'.$lt{'whi'}.'</p>';
5052: foreach my $access (@{$accesstypes}) {
5053: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5054: ' onclick="helpdeskAccess('."'$num'".');" />'.
5055: $lt{$access}.'</label>';
5056: if ($access eq 'status') {
5057: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5058: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5059: $othertitle,$usertypes,$types).
5060: '</div>';
5061: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5062: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5063: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5064: '</div>';
5065: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5066: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5067: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5068: '</div>';
5069: }
5070: $output .= '</p>';
5071: }
5072: $output .= '</fieldset>';
5073: return $output;
5074: }
5075:
1.121 raeburn 5076: sub radiobutton_prefs {
1.192 raeburn 5077: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5078: $additional,$align,$firstval) = @_;
1.121 raeburn 5079: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5080: (ref($choices) eq 'HASH'));
5081:
1.170 raeburn 5082: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5083:
5084: foreach my $item (@{$toggles}) {
5085: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5086: $checkedon{$item} = ' checked="checked" ';
5087: $checkedoff{$item} = ' ';
1.121 raeburn 5088: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5089: $checkedoff{$item} = ' checked="checked" ';
5090: $checkedon{$item} = ' ';
5091: }
5092: }
5093: if (ref($settings) eq 'HASH') {
1.121 raeburn 5094: foreach my $item (@{$toggles}) {
1.118 jms 5095: if ($settings->{$item} eq '1') {
5096: $checkedon{$item} = ' checked="checked" ';
5097: $checkedoff{$item} = ' ';
5098: } elsif ($settings->{$item} eq '0') {
5099: $checkedoff{$item} = ' checked="checked" ';
5100: $checkedon{$item} = ' ';
5101: }
5102: }
1.121 raeburn 5103: }
1.192 raeburn 5104: if ($onclick) {
5105: $onclick = ' onclick="'.$onclick.'"';
5106: }
1.121 raeburn 5107: foreach my $item (@{$toggles}) {
1.118 jms 5108: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5109: $datatable .=
1.306 raeburn 5110: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5111: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5112: '</span></td>';
5113: if ($align eq 'left') {
5114: $datatable .= '<td class="LC_left_item">';
5115: } else {
5116: $datatable .= '<td class="LC_right_item">';
5117: }
1.385 raeburn 5118: $datatable .= '<span class="LC_nobreak">';
5119: if ($firstval eq 'no') {
5120: $datatable .=
5121: '<label><input type="radio" name="'.
5122: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5123: '</label> <label><input type="radio" name="'.$item.'" '.
5124: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5125: } else {
5126: $datatable .=
5127: '<label><input type="radio" name="'.
5128: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5129: '</label> <label><input type="radio" name="'.$item.'" '.
5130: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5131: }
5132: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5133: $itemcount ++;
1.121 raeburn 5134: }
5135: return ($datatable,$itemcount);
5136: }
5137:
1.267 raeburn 5138: sub print_ltitools {
5139: my ($dom,$settings,$rowtotal) = @_;
5140: my $rownum = 0;
5141: my $css_class;
5142: my $itemcount = 1;
5143: my $maxnum = 0;
5144: my %ordered;
5145: if (ref($settings) eq 'HASH') {
5146: foreach my $item (keys(%{$settings})) {
5147: if (ref($settings->{$item}) eq 'HASH') {
5148: my $num = $settings->{$item}{'order'};
5149: $ordered{$num} = $item;
5150: }
5151: }
5152: }
5153: my $confname = $dom.'-domainconfig';
5154: my $switchserver = &check_switchserver($dom,$confname);
5155: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 5156: my $datatable;
1.267 raeburn 5157: my %lt = <itools_names();
5158: my @courseroles = ('cc','in','ta','ep','st');
5159: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 5160: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 5161: if (keys(%ordered)) {
5162: my @items = sort { $a <=> $b } keys(%ordered);
5163: for (my $i=0; $i<@items; $i++) {
5164: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5165: my $item = $ordered{$items[$i]};
1.323 raeburn 5166: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 5167: if (ref($settings->{$item}) eq 'HASH') {
5168: $title = $settings->{$item}->{'title'};
5169: $url = $settings->{$item}->{'url'};
5170: $key = $settings->{$item}->{'key'};
5171: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 5172: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 5173: my $image = $settings->{$item}->{'image'};
5174: if ($image ne '') {
5175: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
5176: }
1.323 raeburn 5177: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
5178: $sigsel{'HMAC-256'} = ' selected="selected"';
5179: } else {
5180: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
5181: }
1.267 raeburn 5182: }
1.319 raeburn 5183: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 5184: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5185: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
5186: for (my $k=0; $k<=$maxnum; $k++) {
5187: my $vpos = $k+1;
5188: my $selstr;
5189: if ($k == $i) {
5190: $selstr = ' selected="selected" ';
5191: }
5192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5193: }
5194: $datatable .= '</select>'.(' 'x2).
5195: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
5196: &mt('Delete?').'</label></span></td>'.
5197: '<td colspan="2">'.
5198: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5199: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 5200: (' 'x2).
5201: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
5202: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5203: (' 'x2).
5204: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
5205: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5206: (' 'x2).
5207: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
5208: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
5209: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 5210: '<br /><br />'.
1.323 raeburn 5211: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 5212: ' value="'.$url.'" /></span>'.
5213: (' 'x2).
1.319 raeburn 5214: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 5215: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
5216: (' 'x2).
1.322 raeburn 5217: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
5218: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
5219: (' 'x2).
1.267 raeburn 5220: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5221: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
5222: '<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>'.
5223: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
5224: '</fieldset>'.
5225: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5226: '<span class="LC_nobreak">'.&mt('Display target:');
5227: my %currdisp;
5228: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
5229: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
5230: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 5231: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
5232: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 5233: } else {
5234: $currdisp{'iframe'} = ' checked="checked"';
5235: }
5236: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
5237: $currdisp{'width'} = $1;
5238: }
5239: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
5240: $currdisp{'height'} = $1;
5241: }
1.296 raeburn 5242: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
5243: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 5244: } else {
5245: $currdisp{'iframe'} = ' checked="checked"';
5246: }
1.298 raeburn 5247: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5248: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
5249: $lt{$disp}.'</label>'.(' 'x2);
5250: }
5251: $datatable .= (' 'x4);
5252: foreach my $dimen ('width','height') {
5253: $datatable .= '<label>'.$lt{$dimen}.' '.
5254: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
5255: (' 'x2);
5256: }
1.334 raeburn 5257: $datatable .= '</span><br />'.
1.296 raeburn 5258: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5259: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 5260: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5261: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
5262: '</textarea></div><div style=""></div><br />';
1.319 raeburn 5263: my %units = (
5264: 'passback' => 'days',
5265: 'roster' => 'seconds',
5266: );
1.267 raeburn 5267: foreach my $extra ('passback','roster') {
1.319 raeburn 5268: my $validsty = 'none';
5269: my $currvalid;
1.267 raeburn 5270: my $checkedon = '';
5271: my $checkedoff = ' checked="checked"';
5272: if ($settings->{$item}->{$extra}) {
5273: $checkedon = $checkedoff;
5274: $checkedoff = '';
1.319 raeburn 5275: $validsty = 'inline-block';
5276: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
5277: $currvalid = $settings->{$item}->{$extra.'valid'};
5278: }
5279: }
5280: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
5281: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5282: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
5283: &mt('No').'</label>'.(' 'x2).
5284: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
5285: &mt('Yes').'</label></span></div>'.
5286: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
5287: '<span class="LC_nobreak">'.
5288: &mt("at least [_1] $units{$extra} after launch",
5289: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
5290: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5291: }
1.319 raeburn 5292: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 5293: if ($imgsrc) {
5294: $datatable .= $imgsrc.
5295: '<label><input type="checkbox" name="ltitools_image_del"'.
5296: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
5297: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
5298: } else {
5299: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5300: }
5301: if ($switchserver) {
5302: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5303: } else {
5304: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
5305: }
5306: $datatable .= '</span></fieldset>';
1.324 raeburn 5307: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 5308: if (ref($settings->{$item}) eq 'HASH') {
5309: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
5310: %checkedfields = %{$settings->{$item}->{'fields'}};
5311: }
1.324 raeburn 5312: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 5313: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
5314: %rolemaps = %{$settings->{$item}->{'roles'}};
5315: $checkedfields{'roles'} = 1;
5316: }
5317: }
5318: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5319: '<span class="LC_nobreak">';
1.324 raeburn 5320: my $userfieldstyle = 'display:none;';
5321: my $seluserdom = '';
5322: my $unseluserdom = ' selected="selected"';
1.267 raeburn 5323: foreach my $field (@fields) {
1.324 raeburn 5324: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 5325: if ($checkedfields{$field}) {
5326: $checked = ' checked="checked"';
5327: }
1.324 raeburn 5328: if ($field eq 'user') {
5329: $id = ' id="ltitools_user_field_'.$i.'"';
5330: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
5331: if ($checked) {
5332: $userfieldstyle = 'display:inline-block';
5333: if ($userincdom) {
5334: $seluserdom = $unseluserdom;
5335: $unseluserdom = '';
5336: }
5337: }
5338: } else {
5339: $spacer = (' ' x2);
5340: }
1.267 raeburn 5341: $datatable .= '<label>'.
1.324 raeburn 5342: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5343: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5344: }
1.324 raeburn 5345: $datatable .= '</span>';
5346: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5347: '<span class="LC_nobreak"> : '.
5348: '<select name="ltitools_userincdom_'.$i.'">'.
5349: '<option value="">'.&mt('Select').'</option>'.
5350: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5351: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5352: '</select></span></div>';
5353: $datatable .= '</fieldset>'.
1.267 raeburn 5354: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5355: foreach my $role (@courseroles) {
5356: my ($selected,$selectnone);
5357: if (!$rolemaps{$role}) {
5358: $selectnone = ' selected="selected"';
5359: }
1.306 raeburn 5360: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5361: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5362: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5363: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5364: foreach my $ltirole (@ltiroles) {
5365: unless ($selectnone) {
5366: if ($rolemaps{$role} eq $ltirole) {
5367: $selected = ' selected="selected"';
5368: } else {
5369: $selected = '';
5370: }
5371: }
5372: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5373: }
5374: $datatable .= '</select></td>';
5375: }
1.273 raeburn 5376: $datatable .= '</tr></table></fieldset>';
5377: my %courseconfig;
5378: if (ref($settings->{$item}) eq 'HASH') {
5379: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5380: %courseconfig = %{$settings->{$item}->{'crsconf'}};
5381: }
5382: }
5383: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5384: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 5385: my $checked;
5386: if ($courseconfig{$item}) {
5387: $checked = ' checked="checked"';
5388: }
5389: $datatable .= '<label>'.
5390: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
1.372 raeburn 5391: $lt{'crs'.$item}.'</label> '."\n";
1.273 raeburn 5392: }
5393: $datatable .= '</span></fieldset>'.
1.267 raeburn 5394: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5395: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5396: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5397: my %custom = %{$settings->{$item}->{'custom'}};
5398: if (keys(%custom) > 0) {
5399: foreach my $key (sort(keys(%custom))) {
5400: $datatable .= '<tr><td><span class="LC_nobreak">'.
5401: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5402: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5403: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5404: ' value="'.$custom{$key}.'" /></td></tr>';
5405: }
5406: }
5407: }
5408: $datatable .= '<tr><td><span class="LC_nobreak">'.
5409: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5410: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5411: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5412: $datatable .= '</table></fieldset></td></tr>'."\n";
5413: $itemcount ++;
5414: }
5415: }
5416: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 5417: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 5418: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5419: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5420: '<select name="ltitools_add_pos"'.$chgstr.'>';
5421: for (my $k=0; $k<$maxnum+1; $k++) {
5422: my $vpos = $k+1;
5423: my $selstr;
5424: if ($k == $maxnum) {
5425: $selstr = ' selected="selected" ';
5426: }
5427: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5428: }
5429: $datatable .= '</select> '."\n".
1.334 raeburn 5430: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 5431: '<td colspan="2">'.
5432: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 5433: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 5434: (' 'x2).
5435: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5436: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5437: (' 'x2).
5438: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5439: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 5440: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5441: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5442: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 5443: '<br />'.
1.323 raeburn 5444: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 5445: (' 'x2).
5446: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5447: (' 'x2).
1.322 raeburn 5448: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5449: (' 'x2).
1.267 raeburn 5450: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5451: '<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".
5452: '</fieldset>'.
5453: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5454: '<span class="LC_nobreak">'.&mt('Display target:');
5455: my %defaultdisp;
5456: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 5457: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 5458: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5459: $lt{$disp}.'</label>'.(' 'x2);
5460: }
5461: $datatable .= (' 'x4);
5462: foreach my $dimen ('width','height') {
5463: $datatable .= '<label>'.$lt{$dimen}.' '.
5464: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5465: (' 'x2);
5466: }
1.334 raeburn 5467: $datatable .= '</span><br />'.
1.296 raeburn 5468: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 5469: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 5470: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 5471: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 5472: '</div><div style=""></div><br />';
1.319 raeburn 5473: my %units = (
5474: 'passback' => 'days',
5475: 'roster' => 'seconds',
5476: );
5477: my %defaulttimes = (
5478: 'passback' => '7',
1.322 raeburn 5479: 'roster' => '300',
1.319 raeburn 5480: );
1.267 raeburn 5481: foreach my $extra ('passback','roster') {
1.319 raeburn 5482: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
5483: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
5484: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
5485: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
5486: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
5487: &mt('Yes').'</label></span></div>'.
5488: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
5489: '<span class="LC_nobreak">'.
5490: &mt("at least [_1] $units{$extra} after launch",
5491: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
5492: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 5493: }
1.319 raeburn 5494: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 5495: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5496: if ($switchserver) {
5497: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5498: } else {
5499: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5500: }
5501: $datatable .= '</span></fieldset>'.
5502: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5503: '<span class="LC_nobreak">';
5504: foreach my $field (@fields) {
1.324 raeburn 5505: my ($id,$onclick,$spacer);
5506: if ($field eq 'user') {
5507: $id = ' id="ltitools_user_field_add"';
5508: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5509: } else {
5510: $spacer = (' ' x2);
5511: }
1.267 raeburn 5512: $datatable .= '<label>'.
1.324 raeburn 5513: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5514: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 5515: }
1.324 raeburn 5516: $datatable .= '</span>'.
5517: '<div style="display:none;" id="ltitools_user_div_add">'.
5518: '<span class="LC_nobreak"> : '.
5519: '<select name="ltitools_userincdom_add">'.
5520: '<option value="" selected="selected">'.&mt('Select').'</option>'.
5521: '<option value="0">'.&mt('username').'</option>'.
5522: '<option value="1">'.&mt('username:domain').'</option>'.
5523: '</select></span></div></fieldset>';
5524: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 5525: foreach my $role (@courseroles) {
5526: my ($checked,$checkednone);
1.306 raeburn 5527: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 5528: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5529: '<select name="ltitools_add_roles_'.$role.'">'.
5530: '<option value="" selected="selected">'.&mt('Select').'</option>';
5531: foreach my $ltirole (@ltiroles) {
5532: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5533: }
5534: $datatable .= '</select></td>';
5535: }
5536: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 5537: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 5538: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 5539: $datatable .= '<label>'.
5540: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5541: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 5542: }
5543: $datatable .= '</span></fieldset>'.
1.267 raeburn 5544: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5545: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5546: '<tr><td><span class="LC_nobreak">'.
5547: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5548: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5549: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 5550: '</table></fieldset>'."\n".
1.267 raeburn 5551: '</td>'."\n".
5552: '</tr>'."\n";
5553: $itemcount ++;
5554: return $datatable;
5555: }
5556:
5557: sub ltitools_names {
5558: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5559: 'title' => 'Title',
5560: 'version' => 'Version',
5561: 'msgtype' => 'Message Type',
1.323 raeburn 5562: 'sigmethod' => 'Signature Method',
1.296 raeburn 5563: 'url' => 'URL',
5564: 'key' => 'Key',
1.322 raeburn 5565: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5566: 'secret' => 'Secret',
5567: 'icon' => 'Icon',
1.324 raeburn 5568: 'user' => 'User',
1.296 raeburn 5569: 'fullname' => 'Full Name',
5570: 'firstname' => 'First Name',
5571: 'lastname' => 'Last Name',
5572: 'email' => 'E-mail',
5573: 'roles' => 'Role',
1.298 raeburn 5574: 'window' => 'Window',
5575: 'tab' => 'Tab',
1.296 raeburn 5576: 'iframe' => 'iFrame',
5577: 'height' => 'Height',
5578: 'width' => 'Width',
5579: 'linktext' => 'Default Link Text',
5580: 'explanation' => 'Default Explanation',
5581: 'passback' => 'Tool can return grades:',
5582: 'roster' => 'Tool can retrieve roster:',
5583: 'crstarget' => 'Display target',
5584: 'crslabel' => 'Course label',
5585: 'crstitle' => 'Course title',
5586: 'crslinktext' => 'Link Text',
5587: 'crsexplanation' => 'Explanation',
1.318 raeburn 5588: 'crsappend' => 'Provider URL',
1.267 raeburn 5589: );
5590: return %lt;
5591: }
5592:
1.372 raeburn 5593: sub print_proctoring {
5594: my ($dom,$settings,$rowtotal) = @_;
5595: my $itemcount = 1;
5596: my (%ordered,%providernames,%current,%currentdef);
5597: my $confname = $dom.'-domainconfig';
5598: my $switchserver = &check_switchserver($dom,$confname);
5599: if (ref($settings) eq 'HASH') {
5600: foreach my $item (keys(%{$settings})) {
5601: if (ref($settings->{$item}) eq 'HASH') {
5602: my $num = $settings->{$item}{'order'};
5603: $ordered{$num} = $item;
5604: }
5605: }
5606: } else {
5607: %ordered = (
5608: 1 => 'proctorio',
5609: 2 => 'examity',
5610: );
5611: }
5612: %providernames = &proctoring_providernames();
5613: my $maxnum = scalar(keys(%ordered));
5614: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5615: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5616: if (ref($requref) eq 'HASH') {
5617: %requserfields = %{$requref};
5618: }
5619: if (ref($opturef) eq 'HASH') {
5620: %optuserfields = %{$opturef};
5621: }
5622: if (ref($defref) eq 'HASH') {
5623: %defaults = %{$defref};
5624: }
5625: if (ref($extref) eq 'HASH') {
5626: %extended = %{$extref};
5627: }
5628: if (ref($crsref) eq 'HASH') {
5629: %crsconf = %{$crsref};
5630: }
5631: if (ref($rolesref) eq 'ARRAY') {
5632: @courseroles = @{$rolesref};
5633: }
5634: if (ref($ltiref) eq 'ARRAY') {
5635: @ltiroles = @{$ltiref};
5636: }
5637: my $datatable;
5638: my $css_class;
5639: if (keys(%ordered)) {
5640: my @items = sort { $a <=> $b } keys(%ordered);
5641: for (my $i=0; $i<@items; $i++) {
5642: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5643: my $provider = $ordered{$items[$i]};
5644: my $optionsty = 'none';
5645: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5646: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5647: if (ref($settings) eq 'HASH') {
5648: if (ref($settings->{$provider}) eq 'HASH') {
5649: %current = %{$settings->{$provider}};
5650: if ($current{'available'}) {
5651: $optionsty = 'block';
5652: $available = 1;
5653: }
5654: if ($current{'lifetime'} =~ /^\d+$/) {
5655: $lifetime = $current{'lifetime'};
5656: }
5657: if ($current{'version'} =~ /^\d+\.\d+$/) {
5658: $version = $current{'version'};
5659: }
5660: if ($current{'image'} ne '') {
5661: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5662: }
5663: if (ref($current{'fields'}) eq 'ARRAY') {
5664: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5665: }
5666: $userincdom = $current{'incdom'};
5667: if (ref($current{'roles'}) eq 'HASH') {
5668: %rolemaps = %{$current{'roles'}};
5669: $checkedfields{'roles'} = 1;
5670: }
5671: if (ref($current{'defaults'}) eq 'ARRAY') {
5672: foreach my $val (@{$current{'defaults'}}) {
5673: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5674: $inuse{$val} = 1;
5675: } else {
5676: foreach my $poss (keys(%{$extended{$provider}})) {
5677: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5678: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5679: $inuse{$poss} = $val;
5680: last;
5681: }
5682: }
5683: }
5684: }
5685: }
5686: } elsif (ref($current{'defaults'}) eq 'HASH') {
5687: foreach my $key (keys(%{$current{'defaults'}})) {
5688: my $currval = $current{'defaults'}{$key};
5689: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5690: $inuse{$key} = 1;
5691: } else {
5692: my $match;
5693: foreach my $poss (keys(%{$extended{$provider}})) {
5694: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5695: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5696: $inuse{$poss} = $key;
5697: last;
5698: }
5699: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5700: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5701: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5702: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5703: $currentdef{$inner} = $currval;
5704: $match = 1;
5705: last;
5706: }
5707: } elsif ($inner eq $key) {
5708: $currentdef{$key} = $currval;
5709: $match = 1;
5710: last;
5711: }
5712: }
5713: }
5714: last if ($match);
5715: }
5716: }
5717: }
5718: }
5719: if (ref($current{'crsconf'}) eq 'ARRAY') {
5720: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5721: }
5722: }
5723: }
5724: my %lt = &proctoring_titles($provider);
5725: my %fieldtitles = &proctoring_fieldtitles($provider);
5726: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5727: my %checkedavailable = (
5728: yes => '',
5729: no => ' checked="checked"',
5730: );
5731: if ($available) {
5732: $checkedavailable{'yes'} = $checkedavailable{'no'};
5733: $checkedavailable{'no'} = '';
5734: }
5735: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5736: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5737: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5738: for (my $k=0; $k<$maxnum; $k++) {
5739: my $vpos = $k+1;
5740: my $selstr;
5741: if ($k == $i) {
5742: $selstr = ' selected="selected" ';
5743: }
5744: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5745: }
5746: if ($version eq '') {
5747: if ($provider eq 'proctorio') {
5748: $version = '1.0';
5749: } elsif ($provider eq 'examity') {
5750: $version = '1.1';
5751: }
5752: }
5753: if ($lifetime eq '') {
5754: $lifetime = '300';
5755: }
5756: $datatable .=
5757: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5758: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5759: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5760: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5761: '</td>'.
5762: '<td colspan="2">'.
5763: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5764: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5765: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5766: (' 'x2).
5767: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5768: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5769: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5770: (' 'x2).
5771: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5772: '<br />'.
5773: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5774: '<br />'.
5775: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5776: (' 'x2).
5777: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5778: '<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";
5779: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5780: if ($imgsrc) {
5781: $datatable .= $imgsrc.
5782: '<label><input type="checkbox" name="proctoring_image_del"'.
5783: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5784: '<span class="LC_nobreak"> '.&mt('Replace:');
5785: }
5786: $datatable .= ' ';
5787: if ($switchserver) {
5788: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5789: } else {
5790: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5791: }
5792: unless ($imgsrc) {
5793: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5794: }
5795: $datatable .= '</fieldset>'."\n";
5796: if (ref($requserfields{$provider}) eq 'ARRAY') {
5797: if (@{$requserfields{$provider}} > 0) {
5798: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5799: foreach my $field (@{$requserfields{$provider}}) {
5800: $datatable .= '<span class="LC_nobreak">'.
5801: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5802: $lt{$field}.'</label>';
5803: if ($field eq 'user') {
5804: my $seluserdom = '';
5805: my $unseluserdom = ' selected="selected"';
5806: if ($userincdom) {
5807: $seluserdom = $unseluserdom;
5808: $unseluserdom = '';
5809: }
5810: $datatable .= ': '.
5811: '<select name="proctoring_userincdom_'.$provider.'">'.
5812: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5813: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5814: '</select> ';
5815: } else {
5816: $datatable .= ' ';
5817: if ($field eq 'roles') {
5818: $showroles = 1;
5819: }
5820: }
5821: $datatable .= '</span> ';
5822: }
5823: }
5824: $datatable .= '</fieldset>'."\n";
5825: }
5826: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5827: if (@{$optuserfields{$provider}} > 0) {
5828: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5829: foreach my $field (@{$optuserfields{$provider}}) {
5830: my $checked;
5831: if ($checkedfields{$field}) {
5832: $checked = ' checked="checked"';
5833: }
5834: $datatable .= '<span class="LC_nobreak">'.
5835: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5836: }
5837: $datatable .= '</fieldset>'."\n";
5838: }
5839: }
5840: if (ref($defaults{$provider}) eq 'ARRAY') {
5841: if (@{$defaults{$provider}}) {
5842: my (%options,@selectboxes);
5843: if (ref($extended{$provider}) eq 'HASH') {
5844: %options = %{$extended{$provider}};
5845: }
5846: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5847: my ($rem,$numinrow,$dropdowns);
5848: if ($provider eq 'proctorio') {
5849: $datatable .= '<table>';
5850: $numinrow = 4;
5851: }
5852: my $i = 0;
5853: foreach my $field (@{$defaults{$provider}}) {
5854: my $checked;
5855: if ($inuse{$field}) {
5856: $checked = ' checked="checked"';
5857: }
5858: if ($provider eq 'examity') {
5859: if ($field eq 'display') {
5860: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5861: foreach my $option ('iframe','tab','window') {
5862: my $checkdisp;
5863: if ($currentdef{'target'} eq $option) {
5864: $checkdisp = ' checked="checked"';
5865: }
5866: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5867: $fieldtitles{$option}.'</label>'.(' 'x2);
5868: }
5869: $datatable .= (' 'x4);
5870: foreach my $dimen ('width','height') {
5871: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5872: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5873: 'value="'.$currentdef{$dimen}.'" /></label>'.
5874: (' 'x2);
5875: }
5876: $datatable .= '</span><br />'.
5877: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5878: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5879: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5880: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5881: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5882: $currentdef{'explanation'}.
5883: '</textarea></div><div style=""></div><br />';
5884: }
5885: } else {
5886: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5887: my ($output,$selnone);
5888: unless ($checked) {
5889: $selnone = ' selected="selected"';
5890: }
5891: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5892: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5893: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5894: foreach my $option (@{$options{$field}}) {
5895: my $sel;
5896: if ($inuse{$field} eq $option) {
5897: $sel = ' selected="selected"';
5898: }
5899: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5900: }
5901: $output .= '</select></span>';
5902: push(@selectboxes,$output);
5903: } else {
5904: $rem = $i%($numinrow);
5905: if ($rem == 0) {
5906: if ($i > 0) {
5907: $datatable .= '</tr>';
5908: }
5909: $datatable .= '<tr>';
5910: }
5911: $datatable .= '<td class="LC_left_item">'.
5912: '<span class="LC_nobreak">'.
5913: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5914: $fieldtitles{$field}.'</label></span></td>';
5915: $i++;
5916: }
5917: }
5918: }
5919: if ($provider eq 'proctorio') {
5920: if ($numinrow) {
5921: $rem = $i%$numinrow;
5922: }
5923: my $colsleft = $numinrow - $rem;
5924: if ($colsleft > 1) {
5925: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5926: } else {
5927: $datatable .= '<td class="LC_left_item">';
5928: }
5929: $datatable .= ' '.
5930: '</td></tr></table>';
5931: if (@selectboxes) {
5932: $datatable .= '<hr /><table>';
5933: $numinrow = 2;
5934: for (my $i=0; $i<@selectboxes; $i++) {
5935: $rem = $i%($numinrow);
5936: if ($rem == 0) {
5937: if ($i > 0) {
5938: $datatable .= '</tr>';
5939: }
5940: $datatable .= '<tr>';
5941: }
5942: $datatable .= '<td class="LC_left_item">'.
5943: $selectboxes[$i].'</td>';
5944: }
5945: if ($numinrow) {
5946: $rem = $i%$numinrow;
5947: }
5948: $colsleft = $numinrow - $rem;
5949: if ($colsleft > 1) {
5950: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5951: } else {
5952: $datatable .= '<td class="LC_left_item">';
5953: }
5954: $datatable .= ' '.
5955: '</td></tr></table>';
5956: }
5957: }
5958: $datatable .= '</fieldset>';
5959: }
5960: if (ref($crsconf{$provider}) eq 'ARRAY') {
5961: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5962: '<legend>'.&mt('Configurable in course').'</legend>';
5963: my ($rem,$numinrow);
5964: if ($provider eq 'proctorio') {
5965: $datatable .= '<table>';
5966: $numinrow = 4;
5967: }
5968: my $i = 0;
5969: foreach my $item (@{$crsconf{$provider}}) {
5970: my $name;
5971: if ($provider eq 'examity') {
5972: $name = $lt{'crs'.$item};
5973: } elsif ($provider eq 'proctorio') {
5974: $name = $fieldtitles{$item};
5975: $rem = $i%($numinrow);
5976: if ($rem == 0) {
5977: if ($i > 0) {
5978: $datatable .= '</tr>';
5979: }
5980: $datatable .= '<tr>';
5981: }
5982: $datatable .= '<td class="LC_left_item>';
5983: }
5984: my $checked;
5985: if ($crsconfig{$item}) {
5986: $checked = ' checked="checked"';
5987: }
5988: $datatable .= '<span class="LC_nobreak"><label>'.
5989: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5990: $name.'</label></span>';
5991: if ($provider eq 'examity') {
5992: $datatable .= ' ';
5993: }
5994: $datatable .= "\n";
5995: $i++;
5996: }
5997: if ($provider eq 'proctorio') {
5998: if ($numinrow) {
5999: $rem = $i%$numinrow;
6000: }
6001: my $colsleft = $numinrow - $rem;
6002: if ($colsleft > 1) {
6003: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
6004: } else {
6005: $datatable .= '<td class="LC_left_item">';
6006: }
6007: $datatable .= ' '.
6008: '</td></tr></table>';
6009: }
6010: $datatable .= '</fieldset>';
6011: }
6012: if ($showroles) {
6013: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6014: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
6015: foreach my $role (@courseroles) {
6016: my ($selected,$selectnone);
6017: if (!$rolemaps{$role}) {
6018: $selectnone = ' selected="selected"';
6019: }
6020: $datatable .= '<td style="text-align: center">'.
6021: &Apache::lonnet::plaintext($role,'Course').'<br />'.
6022: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
6023: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6024: foreach my $ltirole (@ltiroles) {
6025: unless ($selectnone) {
6026: if ($rolemaps{$role} eq $ltirole) {
6027: $selected = ' selected="selected"';
6028: } else {
6029: $selected = '';
6030: }
6031: }
6032: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6033: }
6034: $datatable .= '</select></td>';
6035: }
6036: $datatable .= '</tr></table></fieldset>'.
6037: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6038: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6039: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6040: '<tr><td></td><td>lms</td>'.
6041: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6042: ' value="Loncapa" disabled="disabled"/></td></tr>';
6043: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6044: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6045: my %custom = %{$settings->{$provider}->{'custom'}};
6046: if (keys(%custom) > 0) {
6047: foreach my $key (sort(keys(%custom))) {
6048: next if ($key eq 'lms');
6049: $datatable .= '<tr><td><span class="LC_nobreak">'.
6050: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6051: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6052: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6053: ' value="'.$custom{$key}.'" /></td></tr>';
6054: }
6055: }
6056: }
6057: $datatable .= '<tr><td><span class="LC_nobreak">'.
6058: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6059: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6060: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6061: '</table></fieldset></td></tr>'."\n";
6062: }
6063: $datatable .= '</td></tr>';
6064: }
6065: $itemcount ++;
6066: }
6067: }
6068: return $datatable;
6069: }
6070:
6071: sub proctoring_data {
6072: my $requserfields = {
6073: proctorio => ['user'],
6074: examity => ['roles','user'],
6075: };
6076: my $optuserfields = {
6077: proctorio => ['fullname'],
6078: examity => ['fullname','firstname','lastname','email'],
6079: };
6080: my $defaults = {
6081: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6082: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6083: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6084: 'closetabs','onescreen','print','downloads','cache','rightclick',
6085: 'reentry','calculator','whiteboard'],
6086: examity => ['display'],
6087: };
6088: my $extended = {
6089: proctorio => {
6090: verifyid => ['verifyidauto','verifyidlive'],
6091: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6092: tabslinks => ['notabs','linksonly'],
6093: reentry => ['noreentry','agentreentry'],
6094: calculator => ['calculatorbasic','calculatorsci'],
6095: },
6096: examity => {
6097: display => {
6098: target => ['iframe','tab','window'],
6099: width => '',
6100: height => '',
6101: linktext => '',
6102: explanation => '',
6103: },
6104: },
6105: };
6106: my $crsconf = {
6107: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6108: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6109: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6110: 'closetabs','onescreen','print','downloads','cache','rightclick',
6111: 'reentry','calculator','whiteboard'],
6112: examity => ['label','title','target','linktext','explanation','append'],
6113: };
6114: my $courseroles = ['cc','in','ta','ep','st'];
6115: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6116: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6117: }
6118:
6119: sub proctoring_titles {
6120: my ($item) = @_;
6121: my (%common_lt,%custom_lt);
6122: %common_lt = &Apache::lonlocal::texthash (
6123: 'avai' => 'Available?',
6124: 'base' => 'Basic Settings',
6125: 'requ' => 'User data required to be sent on launch',
6126: 'optu' => 'User data optionally sent on launch',
6127: 'udsl' => 'User data sent on launch',
6128: 'defa' => 'Defaults for items configurable in course',
6129: 'sigmethod' => 'Signature Method',
6130: 'key' => 'Key',
6131: 'lifetime' => 'Nonce lifetime (s)',
6132: 'secret' => 'Secret',
6133: 'icon' => 'Icon',
6134: 'fullname' => 'Full Name',
6135: 'visible' => 'Visible input',
6136: 'username' => 'username',
6137: 'user' => 'User',
6138: );
6139: if ($item eq 'proctorio') {
6140: %custom_lt = &Apache::lonlocal::texthash (
6141: 'version' => 'OAuth version',
6142: 'url' => 'API URL',
6143: 'uname:dom' => 'username-domain',
6144: );
6145: } elsif ($item eq 'examity') {
6146: %custom_lt = &Apache::lonlocal::texthash (
6147: 'version' => 'LTI Version',
6148: 'url' => 'URL',
6149: 'uname:dom' => 'username:domain',
6150: 'msgtype' => 'Message Type',
6151: 'firstname' => 'First Name',
6152: 'lastname' => 'Last Name',
6153: 'email' => 'E-mail',
6154: 'roles' => 'Role',
6155: 'crstarget' => 'Display target',
6156: 'crslabel' => 'Course label',
6157: 'crstitle' => 'Course title',
6158: 'crslinktext' => 'Link Text',
6159: 'crsexplanation' => 'Explanation',
6160: 'crsappend' => 'Provider URL',
6161: );
6162: }
6163: my %lt = (%common_lt,%custom_lt);
6164: return %lt;
6165: }
6166:
6167: sub proctoring_fieldtitles {
6168: my ($item) = @_;
6169: if ($item eq 'proctorio') {
6170: return &Apache::lonlocal::texthash (
6171: 'recordvideo' => 'Record video',
6172: 'recordaudio' => 'Record audio',
6173: 'recordscreen' => 'Record screen',
6174: 'recordwebtraffic' => 'Record web traffic',
6175: 'recordroomstart' => 'Record room scan',
6176: 'verifyvideo' => 'Verify webcam',
6177: 'verifyaudio' => 'Verify microphone',
6178: 'verifydesktop' => 'Verify desktop recording',
6179: 'verifyid' => 'Photo ID verification',
6180: 'verifysignature' => 'Require signature',
6181: 'fullscreen' => 'Fullscreen',
6182: 'clipboard' => 'Disable copy/paste',
6183: 'tabslinks' => 'New tabs/windows',
6184: 'closetabs' => 'Close other tabs',
6185: 'onescreen' => 'Limit to single screen',
6186: 'print' => 'Disable Printing',
6187: 'downloads' => 'Disable Downloads',
6188: 'cache' => 'Empty cache after exam',
6189: 'rightclick' => 'Disable right click',
6190: 'reentry' => 'Re-entry to exam',
6191: 'calculator' => 'Onscreen calculator',
6192: 'whiteboard' => 'Onscreen whiteboard',
6193: 'verifyidauto' => 'Automated verification',
6194: 'verifyidlive' => 'Live agent verification',
6195: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6196: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6197: 'fullscreensever' => 'Forced, navigation away ends exam',
6198: 'notabs' => 'Disaallowed',
6199: 'linksonly' => 'Allowed from links in exam',
6200: 'noreentry' => 'Disallowed',
6201: 'agentreentry' => 'Agent required for re-entry',
6202: 'calculatorbasic' => 'Basic',
6203: 'calculatorsci' => 'Scientific',
6204: );
6205: } elsif ($item eq 'examity') {
6206: return &Apache::lonlocal::texthash (
6207: 'target' => 'Display target',
6208: 'window' => 'Window',
6209: 'tab' => 'Tab',
6210: 'iframe' => 'iFrame',
6211: 'height' => 'Height (pixels)',
6212: 'width' => 'Width (pixels)',
6213: 'linktext' => 'Default Link Text',
6214: 'explanation' => 'Default Explanation',
6215: 'append' => 'Provider URL',
6216: );
6217: }
6218: }
6219:
6220: sub proctoring_providernames {
6221: return (
6222: proctorio => 'Proctorio',
6223: examity => 'Examity',
6224: );
6225: }
6226:
1.320 raeburn 6227: sub print_lti {
6228: my ($dom,$settings,$rowtotal) = @_;
6229: my $itemcount = 1;
6230: my $maxnum = 0;
6231: my $css_class;
6232: my %ordered;
6233: if (ref($settings) eq 'HASH') {
6234: foreach my $item (keys(%{$settings})) {
6235: if (ref($settings->{$item}) eq 'HASH') {
6236: my $num = $settings->{$item}{'order'};
1.390 raeburn 6237: if ($num eq '') {
6238: $num = scalar(keys(%{$settings}));
6239: }
1.320 raeburn 6240: $ordered{$num} = $item;
6241: }
6242: }
6243: }
6244: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 6245: my $datatable;
1.320 raeburn 6246: my %lt = <i_names();
6247: if (keys(%ordered)) {
6248: my @items = sort { $a <=> $b } keys(%ordered);
6249: for (my $i=0; $i<@items; $i++) {
6250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6251: my $item = $ordered{$items[$i]};
1.391 raeburn 6252: my ($key,$secret,$lifetime,$consumer,$requser,$crsinc,$current);
1.320 raeburn 6253: if (ref($settings->{$item}) eq 'HASH') {
6254: $key = $settings->{$item}->{'key'};
6255: $secret = $settings->{$item}->{'secret'};
6256: $lifetime = $settings->{$item}->{'lifetime'};
6257: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 6258: $requser = $settings->{$item}->{'requser'};
1.391 raeburn 6259: $crsinc = $settings->{$item}->{'crsinc'};
1.320 raeburn 6260: $current = $settings->{$item};
6261: }
1.345 raeburn 6262: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6263: my %checkedrequser = (
6264: yes => ' checked="checked"',
6265: no => '',
6266: );
6267: if (!$requser) {
6268: $checkedrequser{'no'} = $checkedrequser{'yes'};
6269: $checkedrequser{'yes'} = '';
1.352 raeburn 6270: }
1.391 raeburn 6271: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6272: my %checkedcrsinc = (
6273: yes => ' checked="checked"',
6274: no => '',
6275: );
6276: if (!$crsinc) {
6277: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6278: $checkedcrsinc{'yes'} = '';
6279: }
1.320 raeburn 6280: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6281: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6282: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6283: for (my $k=0; $k<=$maxnum; $k++) {
6284: my $vpos = $k+1;
6285: my $selstr;
6286: if ($k == $i) {
6287: $selstr = ' selected="selected" ';
6288: }
6289: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6290: }
6291: $datatable .= '</select>'.(' 'x2).
6292: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6293: &mt('Delete?').'</label></span></td>'.
6294: '<td colspan="2">'.
6295: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6296: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6297: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 6298: (' 'x2).
6299: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6300: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6301: (' 'x2).
6302: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 6303: 'value="'.$lifetime.'" size="3" /></span>'.
6304: (' 'x2).
6305: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6306: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6307: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6308: '<br /><br />'.
1.391 raeburn 6309: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6310: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6311: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6312: (' 'x4).
1.320 raeburn 6313: '<span class="LC_nobreak">'.$lt{'key'}.
6314: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
6315: (' 'x2).
6316: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6317: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
6318: '<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>'.
6319: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 6320: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 6321: $itemcount ++;
6322: }
6323: }
6324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6325: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6326: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6327: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6328: '<select name="lti_pos_add"'.$chgstr.'>';
6329: for (my $k=0; $k<$maxnum+1; $k++) {
6330: my $vpos = $k+1;
6331: my $selstr;
6332: if ($k == $maxnum) {
6333: $selstr = ' selected="selected" ';
6334: }
6335: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6336: }
6337: $datatable .= '</select> '."\n".
1.334 raeburn 6338: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 6339: '<td colspan="2">'.
6340: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6341: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 6342: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 6343: (' 'x2).
6344: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6345: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6346: (' 'x2).
1.345 raeburn 6347: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
6348: (' 'x2).
6349: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6350: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6351: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 6352: '<br /><br />'.
1.391 raeburn 6353: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6354: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6355: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6356: (' 'x4).
1.320 raeburn 6357: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
6358: (' 'x2).
6359: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
6360: '<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 6361: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 6362: '</td>'."\n".
6363: '</tr>'."\n";
6364: $$rowtotal ++;
6365: return $datatable;;
6366: }
6367:
6368: sub lti_names {
6369: my %lt = &Apache::lonlocal::texthash(
6370: 'version' => 'LTI Version',
6371: 'url' => 'URL',
6372: 'key' => 'Key',
1.322 raeburn 6373: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6374: 'consumer' => 'Consumer',
1.320 raeburn 6375: 'secret' => 'Secret',
1.345 raeburn 6376: 'requser' => "User's identity sent",
1.391 raeburn 6377: 'crsinc' => "Course's identity sent",
1.320 raeburn 6378: 'email' => 'Email address',
6379: 'sourcedid' => 'User ID',
6380: 'other' => 'Other',
6381: 'passback' => 'Can return grades to Consumer:',
6382: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6383: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6384: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6385: );
6386: return %lt;
6387: }
6388:
6389: sub lti_options {
1.325 raeburn 6390: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6391: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6392: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6393: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6394: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6395: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6396: $checked{'mapcrstype'} = {};
6397: $checked{'makeuser'} = {};
6398: $checked{'selfenroll'} = {};
6399: $checked{'crssec'} = {};
6400: $checked{'crssecsrc'} = {};
1.325 raeburn 6401: $checked{'lcauth'} = {};
1.326 raeburn 6402: $checked{'menuitem'} = {};
1.325 raeburn 6403: if ($num eq 'add') {
6404: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6405: }
1.320 raeburn 6406: my $userfieldsty = 'none';
6407: my $crsfieldsty = 'none';
6408: my $crssecfieldsty = 'none';
6409: my $secsrcfieldsty = 'none';
1.363 raeburn 6410: my $callbacksty = 'none';
1.337 raeburn 6411: my $passbacksty = 'none';
1.345 raeburn 6412: my $optionsty = 'block';
1.391 raeburn 6413: my $crssty = 'block';
1.325 raeburn 6414: my $lcauthparm;
6415: my $lcauthparmstyle = 'display:none';
6416: my $lcauthparmtext;
1.326 raeburn 6417: my $menusty;
1.325 raeburn 6418: my $numinrow = 4;
1.326 raeburn 6419: my %menutitles = <imenu_titles();
1.320 raeburn 6420:
6421: if (ref($current) eq 'HASH') {
1.345 raeburn 6422: if (!$current->{'requser'}) {
6423: $optionsty = 'none';
1.391 raeburn 6424: $crssty = 'none';
6425: } elsif (!$current->{'crsinc'}) {
6426: $crssty = 'none';
1.345 raeburn 6427: }
1.320 raeburn 6428: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6429: $checked{'mapuser'}{'sourcedid'} = '';
6430: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6431: $checked{'mapuser'}{'email'} = ' checked="checked"';
6432: } else {
6433: $checked{'mapuser'}{'other'} = ' checked="checked"';
6434: $userfield = $current->{'mapuser'};
6435: $userfieldsty = 'inline-block';
6436: }
6437: }
6438: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6439: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6440: if ($current->{'mapcrs'} eq 'context_id') {
6441: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6442: } else {
6443: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6444: $cidfield = $current->{'mapcrs'};
6445: $crsfieldsty = 'inline-block';
6446: }
6447: }
6448: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6449: foreach my $type (@{$current->{'mapcrstype'}}) {
6450: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6451: }
6452: }
1.392 raeburn 6453: if (!$current->{'storecrs'}) {
6454: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6455: $checked{'storecrs'}{'Y'} = '';
6456: }
1.345 raeburn 6457: if ($current->{'makecrs'}) {
1.320 raeburn 6458: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6459: }
1.320 raeburn 6460: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6461: foreach my $role (@{$current->{'makeuser'}}) {
6462: $checked{'makeuser'}{$role} = ' checked="checked"';
6463: }
6464: }
1.325 raeburn 6465: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6466: $checked{'lcauth'}{$1} = ' checked="checked"';
6467: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6468: $lcauthparm = $current->{'lcauthparm'};
6469: $lcauthparmstyle = 'display:table-row';
6470: if ($current->{'lcauth'} eq 'localauth') {
6471: $lcauthparmtext = &mt('Local auth argument');
6472: } else {
6473: $lcauthparmtext = &mt('Kerberos domain');
6474: }
6475: }
6476: }
1.320 raeburn 6477: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6478: foreach my $role (@{$current->{'selfenroll'}}) {
6479: $checked{'selfenroll'}{$role} = ' checked="checked"';
6480: }
6481: }
6482: if (ref($current->{'maproles'}) eq 'HASH') {
6483: %rolemaps = %{$current->{'maproles'}};
6484: }
6485: if ($current->{'section'} ne '') {
6486: $checked{'crssec'}{'Y'} = ' checked="checked"';
6487: $crssecfieldsty = 'inline-block';
6488: if ($current->{'section'} eq 'course_section_sourcedid') {
6489: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6490: } else {
6491: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6492: $crssecsrc = $current->{'section'};
6493: $secsrcfieldsty = 'inline-block';
6494: }
6495: } else {
6496: $checked{'crssec'}{'N'} = ' checked="checked"';
6497: }
1.363 raeburn 6498: if ($current->{'callback'} ne '') {
6499: $callback = $current->{'callback'};
6500: $checked{'callback'}{'Y'} = ' checked="checked"';
6501: $callbacksty = 'inline-block';
6502: } else {
6503: $checked{'callback'}{'N'} = ' checked="checked"';
6504: }
1.326 raeburn 6505: if ($current->{'topmenu'}) {
6506: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6507: } else {
6508: $checked{'topmenu'}{'N'} = ' checked="checked"';
6509: }
6510: if ($current->{'inlinemenu'}) {
6511: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6512: } else {
6513: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6514: }
6515: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6516: $menusty = 'inline-block';
6517: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6518: foreach my $item (@{$current->{'lcmenu'}}) {
6519: if (exists($menutitles{$item})) {
6520: $checked{'menuitem'}{$item} = ' checked="checked"';
6521: }
6522: }
6523: }
6524: } else {
6525: $menusty = 'none';
6526: }
1.320 raeburn 6527: } else {
6528: $checked{'makecrs'}{'N'} = ' checked="checked"';
6529: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6530: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6531: $checked{'topmenu'}{'N'} = ' checked="checked"';
6532: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6533: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6534: $menusty = 'inline-block';
1.320 raeburn 6535: }
1.325 raeburn 6536: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6537: my %coursetypetitles = &Apache::lonlocal::texthash (
6538: official => 'Official',
6539: unofficial => 'Unofficial',
6540: community => 'Community',
6541: textbook => 'Textbook',
6542: placement => 'Placement Test',
1.325 raeburn 6543: lti => 'LTI Provider',
1.320 raeburn 6544: );
1.325 raeburn 6545: my @authtypes = ('internal','krb4','krb5','localauth');
6546: my %shortauth = (
6547: internal => 'int',
6548: krb4 => 'krb4',
6549: krb5 => 'krb5',
6550: localauth => 'loc'
6551: );
6552: my %authnames = &authtype_names();
1.320 raeburn 6553: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6554: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6555: my @courseroles = ('cc','in','ta','ep','st');
6556: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6557: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6558: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6559: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6560: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6561: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6562: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6563: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6564: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6565: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6566: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6567: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6568: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6569: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6570: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6571: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6572: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6573: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6574: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6575: foreach my $option ('sourcedid','email','other') {
6576: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6577: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6578: ($option eq 'other' ? '' : (' 'x2) );
6579: }
6580: $output .= '</span></div>'.
6581: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6582: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6583: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6584: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6585: foreach my $ltirole (@ltiroles) {
6586: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6587: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6588: }
6589: $output .= '</fieldset>'.
1.391 raeburn 6590: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6591: '<table>'.
6592: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6593: '</table>'.
6594: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6595: '<td class="LC_left_item">';
6596: foreach my $auth ('lti',@authtypes) {
6597: my $authtext;
6598: if ($auth eq 'lti') {
6599: $authtext = &mt('None');
6600: } else {
6601: $authtext = $authnames{$shortauth{$auth}};
6602: }
6603: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6604: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6605: $authtext.'</label></span> ';
6606: }
6607: $output .= '</td></tr>'.
6608: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6609: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6610: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6611: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6612: '</table></fieldset>'.
1.391 raeburn 6613: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6614: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6615: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6616: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6617: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6618: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6619: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6620: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6621: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6622: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6623: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6624: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6625: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6626: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6627: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6628: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6629: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6630: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6631: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6632: (' 'x2);
6633: }
6634: $output .= '</span></div></fieldset>'.
6635: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6636: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6637: &mt('Unique course identifier').': ';
6638: foreach my $option ('course_offering_sourcedid','context_id','other') {
6639: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6640: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6641: ($option eq 'other' ? '' : (' 'x2) );
6642: }
1.334 raeburn 6643: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6644: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6645: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6646: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6647: foreach my $type (@coursetypes) {
6648: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6649: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6650: (' 'x2);
6651: }
1.392 raeburn 6652: $output .= '</span><br /><br />'.
6653: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6654: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6655: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6656: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6657: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6658: '</fieldset>'.
1.391 raeburn 6659: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6660: foreach my $ltirole (@lticourseroles) {
6661: my ($selected,$selectnone);
6662: if ($rolemaps{$ltirole} eq '') {
6663: $selectnone = ' selected="selected"';
6664: }
6665: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6666: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6667: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6668: foreach my $role (@courseroles) {
6669: unless ($selectnone) {
6670: if ($rolemaps{$ltirole} eq $role) {
6671: $selected = ' selected="selected"';
6672: } else {
6673: $selected = '';
6674: }
6675: }
6676: $output .= '<option value="'.$role.'"'.$selected.'>'.
6677: &Apache::lonnet::plaintext($role,'Course').
6678: '</option>';
6679: }
6680: $output .= '</select></td>';
6681: }
6682: $output .= '</tr></table></fieldset>'.
6683: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6684: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6685: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6686: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6687: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6688: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6689: '</fieldset>'.
1.391 raeburn 6690: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6691: foreach my $lticrsrole (@lticourseroles) {
6692: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6693: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6694: }
6695: $output .= '</fieldset>'.
1.391 raeburn 6696: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6697: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6698: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6699: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6700: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6701: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6702: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6703: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6704: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6705: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6706: &mt('Standard field').'</label>'.(' 'x2).
6707: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6708: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6709: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6710: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6711: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6712: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6713: foreach my $extra ('roster','passback') {
1.320 raeburn 6714: my $checkedon = '';
6715: my $checkedoff = ' checked="checked"';
1.337 raeburn 6716: if ($extra eq 'passback') {
6717: $pb1p1chk = ' checked="checked"';
6718: $pb1p0chk = '';
6719: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6720: } else {
6721: $onclickpb = '';
6722: }
1.320 raeburn 6723: if (ref($current) eq 'HASH') {
6724: if (($current->{$extra})) {
6725: $checkedon = $checkedoff;
6726: $checkedoff = '';
1.337 raeburn 6727: if ($extra eq 'passback') {
6728: $passbacksty = 'inline-block';
6729: }
6730: if ($current->{'passbackformat'} eq '1.0') {
6731: $pb1p0chk = ' checked="checked"';
6732: $pb1p1chk = '';
6733: }
1.320 raeburn 6734: }
6735: }
6736: $output .= $lt{$extra}.' '.
1.337 raeburn 6737: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6738: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6739: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6740: &mt('Yes').'</label><br />';
6741: }
1.337 raeburn 6742: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6743: '<span class="LC_nobreak">'.&mt('Grade format').
6744: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6745: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6746: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6747: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6748: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6749: $output .= '</span></div></fieldset>';
1.320 raeburn 6750: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6751: #
6752: # $output .= '</fieldset>'.
6753: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6754: return $output;
6755: }
6756:
1.326 raeburn 6757: sub ltimenu_titles {
6758: return &Apache::lonlocal::texthash(
6759: fullname => 'Full name',
6760: coursetitle => 'Course title',
6761: role => 'Role',
6762: logout => 'Logout',
6763: grades => 'Grades',
6764: );
6765: }
6766:
1.121 raeburn 6767: sub print_coursedefaults {
1.139 raeburn 6768: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6769: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6770: my $itemcount = 1;
1.192 raeburn 6771: my %choices = &Apache::lonlocal::texthash (
6772: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6773: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6774: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6775: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6776: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6777: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 6778: texengine => 'Default method to display mathematics',
1.257 raeburn 6779: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6780: canclone => "People who may clone a course (besides course's owner and coordinators)",
6781: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 6782: );
1.198 raeburn 6783: my %staticdefaults = (
6784: anonsurvey_threshold => 10,
6785: uploadquota => 500,
1.257 raeburn 6786: postsubmit => 60,
1.276 raeburn 6787: mysqltables => 172800,
1.198 raeburn 6788: );
1.139 raeburn 6789: if ($position eq 'top') {
1.257 raeburn 6790: %defaultchecked = (
6791: 'canuse_pdfforms' => 'off',
6792: 'uselcmath' => 'on',
6793: 'usejsme' => 'on',
1.289 raeburn 6794: 'canclone' => 'none',
1.257 raeburn 6795: );
6796: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 6797: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6798: if (ref($settings) eq 'HASH') {
6799: if ($settings->{'texengine'}) {
6800: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6801: $deftex = $settings->{'texengine'};
6802: }
6803: }
6804: }
6805: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6806: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6807: '<span class="LC_nobreak">'.$choices{'texengine'}.
6808: '</span></td><td class="LC_right_item">'.
6809: '<select name="texengine">'."\n";
6810: my %texoptions = (
6811: MathJax => 'MathJax',
6812: mimetex => &mt('Convert to Images'),
6813: tth => &mt('TeX to HTML'),
6814: );
6815: foreach my $renderer ('MathJax','mimetex','tth') {
6816: my $selected = '';
6817: if ($renderer eq $deftex) {
6818: $selected = ' selected="selected"';
6819: }
6820: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6821: }
6822: $mathdisp .= '</select></td></tr>'."\n";
6823: $itemcount ++;
1.139 raeburn 6824: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6825: \%choices,$itemcount);
1.314 raeburn 6826: $datatable = $mathdisp.$datatable;
1.264 raeburn 6827: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6828: $datatable .=
1.306 raeburn 6829: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6830: '<span class="LC_nobreak">'.$choices{'canclone'}.
6831: '</span></td><td class="LC_left_item">';
6832: my $currcanclone = 'none';
6833: my $onclick;
6834: my @cloneoptions = ('none','domain');
1.380 raeburn 6835: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6836: none => 'No additional course requesters',
6837: domain => "Any course requester in course's domain",
6838: instcode => 'Course requests for official courses ...',
6839: );
6840: my (%codedefaults,@code_order,@posscodes);
6841: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6842: \@code_order) eq 'ok') {
6843: if (@code_order > 0) {
6844: push(@cloneoptions,'instcode');
6845: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6846: }
6847: }
6848: if (ref($settings) eq 'HASH') {
6849: if ($settings->{'canclone'}) {
6850: if (ref($settings->{'canclone'}) eq 'HASH') {
6851: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6852: if (@code_order > 0) {
6853: $currcanclone = 'instcode';
6854: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6855: }
6856: }
6857: } elsif ($settings->{'canclone'} eq 'domain') {
6858: $currcanclone = $settings->{'canclone'};
6859: }
6860: }
1.289 raeburn 6861: }
1.264 raeburn 6862: foreach my $option (@cloneoptions) {
6863: my ($checked,$additional);
6864: if ($currcanclone eq $option) {
6865: $checked = ' checked="checked"';
6866: }
6867: if ($option eq 'instcode') {
6868: if (@code_order) {
6869: my $show = 'none';
6870: if ($checked) {
6871: $show = 'block';
6872: }
1.317 raeburn 6873: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6874: &mt('Institutional codes for new and cloned course have identical:').
6875: '<br />';
6876: foreach my $item (@code_order) {
6877: my $codechk;
6878: if ($checked) {
6879: if (grep(/^\Q$item\E$/,@posscodes)) {
6880: $codechk = ' checked="checked"';
6881: }
6882: }
6883: $additional .= '<label>'.
6884: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6885: $item.'</label>';
6886: }
6887: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6888: }
6889: }
6890: $datatable .=
6891: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6892: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6893: '</label> '.$additional.'</span><br />';
6894: }
6895: $datatable .= '</td>'.
6896: '</tr>';
6897: $itemcount ++;
1.139 raeburn 6898: } else {
6899: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6900: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6901: my $currusecredits = 0;
1.257 raeburn 6902: my $postsubmitclient = 1;
1.271 raeburn 6903: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6904: if (ref($settings) eq 'HASH') {
6905: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6906: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6907: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6908: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6909: }
6910: }
1.192 raeburn 6911: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6912: foreach my $type (@types) {
6913: next if ($type eq 'community');
6914: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6915: if ($defcredits{$type} ne '') {
6916: $currusecredits = 1;
6917: }
6918: }
6919: }
6920: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6921: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6922: $postsubmitclient = 0;
6923: foreach my $type (@types) {
6924: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6925: }
6926: } else {
6927: foreach my $type (@types) {
6928: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6929: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 6930: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 6931: } else {
6932: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6933: }
6934: } else {
6935: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6936: }
6937: }
6938: }
6939: } else {
6940: foreach my $type (@types) {
6941: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 6942: }
6943: }
1.276 raeburn 6944: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6945: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6946: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6947: }
6948: } else {
6949: foreach my $type (@types) {
6950: $currmysql{$type} = $staticdefaults{'mysqltables'};
6951: }
6952: }
1.258 raeburn 6953: } else {
6954: foreach my $type (@types) {
6955: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6956: }
1.139 raeburn 6957: }
6958: if (!$currdefresponder) {
1.198 raeburn 6959: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6960: } elsif ($currdefresponder < 1) {
6961: $currdefresponder = 1;
6962: }
1.198 raeburn 6963: foreach my $type (@types) {
6964: if ($curruploadquota{$type} eq '') {
6965: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6966: }
6967: }
1.139 raeburn 6968: $datatable .=
1.192 raeburn 6969: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6970: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6971: '</span></td>'.
6972: '<td class="LC_right_item"><span class="LC_nobreak">'.
6973: '<input type="text" name="anonsurvey_threshold"'.
6974: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 6975: '</td></tr>'."\n";
6976: $itemcount ++;
6977: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6978: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6979: $choices{'uploadquota'}.
6980: '</span></td>'.
1.306 raeburn 6981: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 6982: '<table><tr>';
1.198 raeburn 6983: foreach my $type (@types) {
1.306 raeburn 6984: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 6985: '<input type="text" name="uploadquota_'.$type.'"'.
6986: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6987: }
6988: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 6989: $itemcount ++;
1.236 raeburn 6990: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 6991: my $display = 'none';
1.192 raeburn 6992: if ($currusecredits) {
6993: $display = 'block';
6994: }
6995: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 6996: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6997: foreach my $type (@types) {
6998: next if ($type eq 'community');
1.306 raeburn 6999: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7000: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7001: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7002: }
7003: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7004: %defaultchecked = ('coursecredits' => 'off');
7005: @toggles = ('coursecredits');
7006: my $current = {
7007: 'coursecredits' => $currusecredits,
7008: };
7009: (my $table,$itemcount) =
7010: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7011: \%choices,$itemcount,$onclick,$additional,'left');
7012: $datatable .= $table;
7013: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7014: my $display = 'none';
7015: if ($postsubmitclient) {
7016: $display = 'block';
7017: }
7018: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7019: &mt('Number of seconds submit is disabled').'<br />'.
7020: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7021: '<table><tr>';
1.257 raeburn 7022: foreach my $type (@types) {
1.306 raeburn 7023: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7024: '<input type="text" name="'.$type.'_timeout" value="'.
7025: $deftimeout{$type}.'" size="5" /></td>';
7026: }
7027: $additional .= '</tr></table></div>'."\n";
7028: %defaultchecked = ('postsubmit' => 'on');
7029: @toggles = ('postsubmit');
1.280 raeburn 7030: $current = {
7031: 'postsubmit' => $postsubmitclient,
7032: };
1.257 raeburn 7033: ($table,$itemcount) =
7034: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7035: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7036: $datatable .= $table;
1.276 raeburn 7037: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7038: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7039: $choices{'mysqltables'}.
7040: '</span></td>'.
1.306 raeburn 7041: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7042: '<table><tr>';
7043: foreach my $type (@types) {
1.306 raeburn 7044: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7045: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7046: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7047: }
7048: $datatable .= '</tr></table></td></tr>'."\n";
7049: $itemcount ++;
7050:
1.139 raeburn 7051: }
1.192 raeburn 7052: $$rowtotal += $itemcount;
1.121 raeburn 7053: return $datatable;
1.118 jms 7054: }
7055:
1.231 raeburn 7056: sub print_selfenrollment {
7057: my ($position,$dom,$settings,$rowtotal) = @_;
7058: my ($css_class,$datatable);
7059: my $itemcount = 1;
1.271 raeburn 7060: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7061: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7062: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7063: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7064: my @rows;
7065: my $key;
7066: if ($position eq 'top') {
7067: $key = 'admin';
7068: if (ref($rowsref) eq 'ARRAY') {
7069: @rows = @{$rowsref};
7070: }
7071: } elsif ($position eq 'middle') {
7072: $key = 'default';
7073: @rows = ('types','registered','approval','limit');
7074: }
7075: foreach my $row (@rows) {
7076: if (defined($titlesref->{$row})) {
7077: $itemcount ++;
7078: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7079: $datatable .= '<tr'.$css_class.'>'.
7080: '<td>'.$titlesref->{$row}.'</td>'.
7081: '<td class="LC_left_item">'.
7082: '<table><tr>';
7083: my (%current,%currentcap);
7084: if (ref($settings) eq 'HASH') {
7085: if (ref($settings->{$key}) eq 'HASH') {
7086: foreach my $type (@types) {
7087: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7088: $current{$type} = $settings->{$key}->{$type}->{$row};
7089: }
7090: if (($row eq 'limit') && ($key eq 'default')) {
7091: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7092: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7093: }
7094: }
7095: }
7096: }
7097: }
7098: my %roles = (
7099: '0' => &Apache::lonnet::plaintext('dc'),
7100: );
7101:
7102: foreach my $type (@types) {
7103: unless (($row eq 'registered') && ($key eq 'default')) {
7104: $datatable .= '<th>'.&mt($type).'</th>';
7105: }
7106: }
7107: unless (($row eq 'registered') && ($key eq 'default')) {
7108: $datatable .= '</tr><tr>';
7109: }
7110: foreach my $type (@types) {
7111: if ($type eq 'community') {
7112: $roles{'1'} = &mt('Community personnel');
7113: } else {
7114: $roles{'1'} = &mt('Course personnel');
7115: }
7116: $datatable .= '<td style="vertical-align: top">';
7117: if ($position eq 'top') {
7118: my %checked;
7119: if ($current{$type} eq '0') {
7120: $checked{'0'} = ' checked="checked"';
7121: } else {
7122: $checked{'1'} = ' checked="checked"';
7123: }
7124: foreach my $role ('1','0') {
7125: $datatable .= '<span class="LC_nobreak"><label>'.
7126: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7127: 'value="'.$role.'"'.$checked{$role}.' />'.
7128: $roles{$role}.'</label></span> ';
7129: }
7130: } else {
7131: if ($row eq 'types') {
7132: my %checked;
7133: if ($current{$type} =~ /^(all|dom)$/) {
7134: $checked{$1} = ' checked="checked"';
7135: } else {
7136: $checked{''} = ' checked="checked"';
7137: }
7138: foreach my $val ('','dom','all') {
7139: $datatable .= '<span class="LC_nobreak"><label>'.
7140: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7141: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7142: }
7143: } elsif ($row eq 'registered') {
7144: my %checked;
7145: if ($current{$type} eq '1') {
7146: $checked{'1'} = ' checked="checked"';
7147: } else {
7148: $checked{'0'} = ' checked="checked"';
7149: }
7150: foreach my $val ('0','1') {
7151: $datatable .= '<span class="LC_nobreak"><label>'.
7152: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7153: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7154: }
7155: } elsif ($row eq 'approval') {
7156: my %checked;
7157: if ($current{$type} =~ /^([12])$/) {
7158: $checked{$1} = ' checked="checked"';
7159: } else {
7160: $checked{'0'} = ' checked="checked"';
7161: }
7162: for my $val (0..2) {
7163: $datatable .= '<span class="LC_nobreak"><label>'.
7164: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7165: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7166: }
7167: } elsif ($row eq 'limit') {
7168: my %checked;
7169: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7170: $checked{$1} = ' checked="checked"';
7171: } else {
7172: $checked{'none'} = ' checked="checked"';
7173: }
7174: my $cap;
7175: if ($currentcap{$type} =~ /^\d+$/) {
7176: $cap = $currentcap{$type};
7177: }
7178: foreach my $val ('none','allstudents','selfenrolled') {
7179: $datatable .= '<span class="LC_nobreak"><label>'.
7180: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7181: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7182: }
7183: $datatable .= '<br />'.
7184: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7185: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7186: '</span>';
7187: }
7188: }
7189: $datatable .= '</td>';
7190: }
7191: $datatable .= '</tr>';
7192: }
7193: $datatable .= '</table></td></tr>';
7194: }
7195: } elsif ($position eq 'bottom') {
1.235 raeburn 7196: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7197: }
7198: $$rowtotal += $itemcount;
7199: return $datatable;
7200: }
7201:
7202: sub print_validation_rows {
7203: my ($caller,$dom,$settings,$rowtotal) = @_;
7204: my ($itemsref,$namesref,$fieldsref);
7205: if ($caller eq 'selfenroll') {
7206: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7207: } elsif ($caller eq 'requestcourses') {
7208: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7209: }
7210: my %currvalidation;
7211: if (ref($settings) eq 'HASH') {
7212: if (ref($settings->{'validation'}) eq 'HASH') {
7213: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7214: }
1.235 raeburn 7215: }
7216: my $datatable;
7217: my $itemcount = 0;
7218: foreach my $item (@{$itemsref}) {
7219: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7220: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7221: $namesref->{$item}.
7222: '</span></td>'.
7223: '<td class="LC_left_item">';
7224: if (($item eq 'url') || ($item eq 'button')) {
7225: $datatable .= '<span class="LC_nobreak">'.
7226: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7227: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7228: } elsif ($item eq 'fields') {
7229: my @currfields;
7230: if (ref($currvalidation{$item}) eq 'ARRAY') {
7231: @currfields = @{$currvalidation{$item}};
7232: }
7233: foreach my $field (@{$fieldsref}) {
7234: my $check = '';
7235: if (grep(/^\Q$field\E$/,@currfields)) {
7236: $check = ' checked="checked"';
7237: }
7238: $datatable .= '<span class="LC_nobreak"><label>'.
7239: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7240: ' value="'.$field.'"'.$check.' />'.$field.
7241: '</label></span> ';
7242: }
7243: } elsif ($item eq 'markup') {
1.334 raeburn 7244: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7245: $currvalidation{$item}.
1.231 raeburn 7246: '</textarea>';
1.235 raeburn 7247: }
7248: $datatable .= '</td></tr>'."\n";
7249: if (ref($rowtotal)) {
1.231 raeburn 7250: $itemcount ++;
7251: }
7252: }
1.235 raeburn 7253: if ($caller eq 'requestcourses') {
7254: my %currhash;
1.248 raeburn 7255: if (ref($settings) eq 'HASH') {
7256: if (ref($settings->{'validation'}) eq 'HASH') {
7257: if ($settings->{'validation'}{'dc'} ne '') {
7258: $currhash{$settings->{'validation'}{'dc'}} = 1;
7259: }
1.235 raeburn 7260: }
7261: }
7262: my $numinrow = 2;
7263: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7264: 'validationdc',%currhash);
1.247 raeburn 7265: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7266: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7267: if ($numdc > 1) {
1.247 raeburn 7268: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7269: } else {
1.247 raeburn 7270: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7271: }
1.247 raeburn 7272: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7273: $itemcount ++;
7274: }
7275: if (ref($rowtotal)) {
7276: $$rowtotal += $itemcount;
7277: }
1.231 raeburn 7278: return $datatable;
7279: }
7280:
1.357 raeburn 7281: sub print_privacy {
7282: my ($position,$dom,$settings,$rowtotal) = @_;
7283: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7284: my $itemcount = 0;
7285: unless ($position eq 'top') {
7286: @items = ('domain','author','course','community');
7287: %names = &Apache::lonlocal::texthash (
7288: domain => 'Assigned domain role(s)',
7289: author => 'Assigned co-author role(s)',
7290: course => 'Assigned course role(s)',
7291: community => 'Assigned community role',
7292: );
7293: $numinrow = 4;
7294: ($othertitle,$usertypes,$types) =
7295: &Apache::loncommon::sorted_inst_types($dom);
7296: }
7297: if (($position eq 'top') || ($position eq 'middle')) {
7298: my (%by_ip,%by_location,@intdoms,@instdoms);
7299: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7300: if ($position eq 'top') {
7301: my %curr;
7302: my @options = ('none','user','domain','auto');
7303: my %titles = &Apache::lonlocal::texthash (
7304: none => 'Not allowed',
7305: user => 'User authorizes',
7306: domain => 'DC authorizes',
7307: auto => 'Unrestricted',
7308: instdom => 'Other domain shares institution/provider',
7309: extdom => 'Other domain has different institution/provider',
7310: );
7311: my %names = &Apache::lonlocal::texthash (
7312: domain => 'Domain role',
7313: author => 'Co-author role',
7314: course => 'Course role',
7315: community => 'Community role',
7316: );
7317: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7318: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7319: foreach my $domtype ('instdom','extdom') {
7320: my (%checked,$skip);
7321: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7322: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7323: '<td class="LC_left_item">';
7324: if ($domtype eq 'instdom') {
7325: unless (@instdoms > 1) {
7326: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7327: $skip = 1;
7328: }
7329: } elsif ($domtype eq 'extdom') {
7330: if (keys(%by_location) == 0) {
7331: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7332: $skip = 1;
7333: }
7334: }
7335: unless ($skip) {
7336: foreach my $roletype ('domain','author','course','community') {
7337: $checked{'auto'} = ' checked="checked"';
7338: if (ref($settings) eq 'HASH') {
7339: if (ref($settings->{approval}) eq 'HASH') {
7340: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7341: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7342: $checked{$1} = ' checked="checked"';
7343: $checked{'auto'} = '';
7344: }
7345: }
7346: }
7347: }
7348: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7349: foreach my $option (@options) {
7350: $datatable .= '<span class="LC_nobreak"><label>'.
7351: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7352: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7353: '</label></span> ';
7354: }
7355: $datatable .= '</fieldset>';
7356: }
7357: }
7358: $datatable .= '</td></tr>';
7359: $itemcount ++;
7360: }
7361: } elsif ($position eq 'middle') {
7362: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7363: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7364: foreach my $item (@{$types}) {
7365: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7366: $numinrow,$itemcount,'','','','','',
7367: '',$usertypes->{$item});
7368: $itemcount ++;
7369: }
7370: }
7371: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7372: $numinrow,$itemcount,'','','','','',
7373: '',$othertitle);
7374: $itemcount ++;
7375: } else {
1.360 raeburn 7376: my (@insttypes,%insttitles);
7377: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7378: @insttypes = @{$types};
7379: %insttitles = %{$usertypes};
7380: }
7381: foreach my $item (@insttypes,'default') {
7382: my $title;
7383: if ($item eq 'default') {
7384: $title = $othertitle;
7385: } else {
7386: $title = $insttitles{$item};
7387: }
7388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7389: $datatable .= '<tr'.$css_class.'>'.
7390: '<td class="LC_left_item">'.$title.'</td>'.
7391: '<td class="LC_left_item">'.
7392: &mt('Nothing to set here, as there are no other domains').
7393: '</td></tr>';
7394: $itemcount ++;
7395: }
1.357 raeburn 7396: }
7397: }
7398: } else {
7399: my $prefix;
7400: if ($position eq 'lower') {
7401: $prefix = 'priv';
7402: } else {
7403: $prefix = 'unpriv';
7404: }
7405: foreach my $item (@items) {
7406: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7407: $numinrow,$itemcount,'','','','','',
7408: '',$names{$item});
7409: $itemcount ++;
7410: }
7411: }
7412: if (ref($rowtotal)) {
7413: $$rowtotal += $itemcount;
7414: }
7415: return $datatable;
7416: }
7417:
1.354 raeburn 7418: sub print_passwords {
7419: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7420: my ($datatable,$css_class);
7421: my $itemcount = 0;
7422: my %titles = &Apache::lonlocal::texthash (
7423: captcha => '"Forgot Password" CAPTCHA validation',
7424: link => 'Reset link expiration (hours)',
7425: case => 'Case-sensitive usernames/e-mail',
7426: prelink => 'Information required (form 1)',
7427: postlink => 'Information required (form 2)',
7428: emailsrc => 'LON-CAPA e-mail address type(s)',
7429: customtext => 'Domain specific text (HTML)',
7430: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7431: intauth_check => 'Check bcrypt cost if authenticated',
7432: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7433: permanent => 'Permanent e-mail address',
7434: critical => 'Critical notification address',
7435: notify => 'Notification address',
7436: min => 'Minimum password length',
7437: max => 'Maximum password length',
7438: chars => 'Required characters',
7439: expire => 'Password expiration (days)',
1.356 raeburn 7440: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7441: );
7442: if ($position eq 'top') {
7443: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7444: my $shownlinklife = 2;
7445: my $prelink = 'both';
7446: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7447: if (ref($settings) eq 'HASH') {
7448: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7449: $shownlinklife = $settings->{resetlink};
7450: }
7451: if (ref($settings->{resetcase}) eq 'ARRAY') {
7452: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7453: }
7454: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7455: $prelink = $settings->{resetprelink};
7456: }
7457: if (ref($settings->{resetpostlink}) eq 'HASH') {
7458: %postlink = %{$settings->{resetpostlink}};
7459: }
7460: if (ref($settings->{resetemail}) eq 'ARRAY') {
7461: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7462: }
7463: if ($settings->{resetremove}) {
7464: $nostdtext = 1;
7465: }
7466: if ($settings->{resetcustom}) {
7467: $customurl = $settings->{resetcustom};
7468: }
7469: } else {
7470: if (ref($types) eq 'ARRAY') {
7471: foreach my $item (@{$types}) {
7472: $casesens{$item} = 1;
7473: $postlink{$item} = ['username','email'];
7474: }
7475: }
7476: $casesens{'default'} = 1;
7477: $postlink{'default'} = ['username','email'];
7478: $prelink = 'both';
7479: %emailsrc = (
7480: permanent => 1,
7481: critical => 1,
7482: notify => 1,
7483: );
7484: }
7485: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7486: $itemcount ++;
7487: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7488: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7489: '<td class="LC_left_item">'.
7490: '<input type="textbox" value="'.$shownlinklife.'" '.
7491: 'name="passwords_link" size="3" /></td></tr>';
7492: $itemcount ++;
7493: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7494: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7495: '<td class="LC_left_item">';
7496: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7497: foreach my $item (@{$types}) {
7498: my $checkedcase;
7499: if ($casesens{$item}) {
7500: $checkedcase = ' checked="checked"';
7501: }
7502: $datatable .= '<span class="LC_nobreak"><label>'.
7503: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7504: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7505: '</span> ';
1.354 raeburn 7506: }
7507: }
7508: my $checkedcase;
7509: if ($casesens{'default'}) {
7510: $checkedcase = ' checked="checked"';
7511: }
7512: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7513: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7514: $othertitle.'</label></span></td>';
7515: $itemcount ++;
7516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7517: my %checkedpre = (
7518: both => ' checked="checked"',
7519: either => '',
7520: );
7521: if ($prelink eq 'either') {
7522: $checkedpre{either} = ' checked="checked"';
7523: $checkedpre{both} = '';
7524: }
7525: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7526: '<td class="LC_left_item"><span class="LC_nobreak">'.
7527: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7528: &mt('Both username and e-mail address').'</label></span> '.
7529: '<span class="LC_nobreak"><label>'.
7530: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7531: &mt('Either username or e-mail address').'</label></span></td></tr>';
7532: $itemcount ++;
7533: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7534: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7535: '<td class="LC_left_item">';
7536: my %postlinked;
7537: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7538: foreach my $item (@{$types}) {
7539: undef(%postlinked);
7540: $datatable .= '<fieldset style="display: inline-block;">'.
7541: '<legend>'.$usertypes->{$item}.'</legend>';
7542: if (ref($postlink{$item}) eq 'ARRAY') {
7543: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7544: }
7545: foreach my $field ('email','username') {
7546: my $checked;
7547: if ($postlinked{$field}) {
7548: $checked = ' checked="checked"';
7549: }
7550: $datatable .= '<span class="LC_nobreak"><label>'.
7551: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7552: $field.'"'.$checked.' />'.$field.'</label>'.
7553: '<span> ';
7554: }
7555: $datatable .= '</fieldset>';
7556: }
7557: }
7558: if (ref($postlink{'default'}) eq 'ARRAY') {
7559: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7560: }
7561: $datatable .= '<fieldset style="display: inline-block;">'.
7562: '<legend>'.$othertitle.'</legend>';
7563: foreach my $field ('email','username') {
7564: my $checked;
7565: if ($postlinked{$field}) {
7566: $checked = ' checked="checked"';
7567: }
7568: $datatable .= '<span class="LC_nobreak"><label>'.
7569: '<input type="checkbox" name="passwords_postlink_default" value="'.
7570: $field.'"'.$checked.' />'.$field.'</label>'.
7571: '<span> ';
7572: }
7573: $datatable .= '</fieldset></td></tr>';
7574: $itemcount ++;
7575: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7576: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7577: '<td class="LC_left_item">';
7578: foreach my $type ('permanent','critical','notify') {
7579: my $checkedemail;
7580: if ($emailsrc{$type}) {
7581: $checkedemail = ' checked="checked"';
7582: }
7583: $datatable .= '<span class="LC_nobreak"><label>'.
7584: '<input type="checkbox" name="passwords_emailsrc" value="'.
7585: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7586: '<span> ';
7587: }
7588: $datatable .= '</td></tr>';
7589: $itemcount ++;
7590: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7591: my $switchserver = &check_switchserver($dom,$confname);
7592: my ($showstd,$noshowstd);
7593: if ($nostdtext) {
7594: $noshowstd = ' checked="checked"';
7595: } else {
7596: $showstd = ' checked="checked"';
7597: }
7598: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7599: '<td class="LC_left_item"><span class="LC_nobreak">'.
7600: &mt('Retain standard text:').
7601: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7602: &mt('Yes').'</label>'.' '.
7603: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7604: &mt('No').'</label></span><br />'.
7605: '<span class="LC_fontsize_small">'.
7606: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7607: &mt('Include custom text:');
7608: if ($customurl) {
1.369 raeburn 7609: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7610: undef,undef,undef,undef,'background-color:#ffffff');
7611: $datatable .= '<span class="LC_nobreak"> '.$link.
7612: '<label><input type="checkbox" name="passwords_custom_del"'.
7613: ' value="1" />'.&mt('Delete?').'</label></span>'.
7614: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7615: }
7616: if ($switchserver) {
7617: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7618: } else {
7619: $datatable .='<span class="LC_nobreak"> '.
7620: '<input type="file" name="passwords_customfile" /></span>';
7621: }
7622: $datatable .= '</td></tr>';
7623: } elsif ($position eq 'middle') {
7624: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7625: my @items = ('intauth_cost','intauth_check','intauth_switch');
7626: my %defaults;
7627: if (ref($domconf{'defaults'}) eq 'HASH') {
7628: %defaults = %{$domconf{'defaults'}};
7629: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7630: $defaults{'intauth_cost'} = 10;
7631: }
7632: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7633: $defaults{'intauth_check'} = 0;
7634: }
7635: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7636: $defaults{'intauth_switch'} = 0;
7637: }
7638: } else {
7639: %defaults = (
7640: 'intauth_cost' => 10,
7641: 'intauth_check' => 0,
7642: 'intauth_switch' => 0,
7643: );
7644: }
7645: foreach my $item (@items) {
7646: if ($itemcount%2) {
7647: $css_class = '';
7648: } else {
7649: $css_class = ' class="LC_odd_row" ';
7650: }
7651: $datatable .= '<tr'.$css_class.'>'.
7652: '<td><span class="LC_nobreak">'.$titles{$item}.
7653: '</span></td><td class="LC_left_item" colspan="3">';
7654: if ($item eq 'intauth_switch') {
7655: my @options = (0,1,2);
7656: my %optiondesc = &Apache::lonlocal::texthash (
7657: 0 => 'No',
7658: 1 => 'Yes',
7659: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7660: );
7661: $datatable .= '<table width="100%">';
7662: foreach my $option (@options) {
7663: my $checked = ' ';
7664: if ($defaults{$item} eq $option) {
7665: $checked = ' checked="checked"';
7666: }
7667: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7668: '<label><input type="radio" name="'.$item.
7669: '" value="'.$option.'"'.$checked.' />'.
7670: $optiondesc{$option}.'</label></span></td></tr>';
7671: }
7672: $datatable .= '</table>';
7673: } elsif ($item eq 'intauth_check') {
7674: my @options = (0,1,2);
7675: my %optiondesc = &Apache::lonlocal::texthash (
7676: 0 => 'No',
7677: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7678: 2 => 'Yes, disallow login if stored cost is less than domain default',
7679: );
7680: $datatable .= '<table width="100%">';
7681: foreach my $option (@options) {
7682: my $checked = ' ';
7683: my $onclick;
7684: if ($defaults{$item} eq $option) {
7685: $checked = ' checked="checked"';
7686: }
7687: if ($option == 2) {
7688: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7689: }
7690: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7691: '<label><input type="radio" name="'.$item.
7692: '" value="'.$option.'"'.$checked.$onclick.' />'.
7693: $optiondesc{$option}.'</label></span></td></tr>';
7694: }
7695: $datatable .= '</table>';
7696: } else {
7697: $datatable .= '<input type="text" name="'.$item.'" value="'.
7698: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7699: }
7700: $datatable .= '</td></tr>';
7701: $itemcount ++;
7702: }
7703: } elsif ($position eq 'lower') {
1.356 raeburn 7704: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 7705: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 7706: if (ref($settings) eq 'HASH') {
7707: if ($settings->{min}) {
7708: $min = $settings->{min};
7709: }
7710: if ($settings->{max}) {
7711: $max = $settings->{max};
7712: }
7713: if (ref($settings->{chars}) eq 'ARRAY') {
7714: map { $chars{$_} = 1; } (@{$settings->{chars}});
7715: }
7716: if ($settings->{expire}) {
7717: $expire = $settings->{expire};
7718: }
1.358 raeburn 7719: if ($settings->{numsaved}) {
7720: $numsaved = $settings->{numsaved};
1.356 raeburn 7721: }
1.354 raeburn 7722: }
7723: my %rulenames = &Apache::lonlocal::texthash(
7724: uc => 'At least one upper case letter',
7725: lc => 'At least one lower case letter',
7726: num => 'At least one number',
7727: spec => 'At least one non-alphanumeric',
7728: );
7729: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7730: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7731: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7732: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
7733: 'onblur="javascript:warnIntPass(this);" />'.
7734: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 7735: '</span></td></tr>';
7736: $itemcount ++;
7737: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7738: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7739: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7740: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
7741: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7742: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7743: '</span></td></tr>';
7744: $itemcount ++;
7745: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7746: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7747: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7748: '</span></td>';
7749: my $numinrow = 2;
7750: my @possrules = ('uc','lc','num','spec');
7751: $datatable .= '<td class="LC_left_item"><table>';
7752: for (my $i=0; $i<@possrules; $i++) {
7753: my ($rem,$checked);
7754: if ($chars{$possrules[$i]}) {
7755: $checked = ' checked="checked"';
7756: }
7757: $rem = $i%($numinrow);
7758: if ($rem == 0) {
7759: if ($i > 0) {
7760: $datatable .= '</tr>';
7761: }
7762: $datatable .= '<tr>';
7763: }
7764: $datatable .= '<td><span class="LC_nobreak"><label>'.
7765: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7766: $rulenames{$possrules[$i]}.'</label></span></td>';
7767: }
7768: my $rem = @possrules%($numinrow);
7769: my $colsleft = $numinrow - $rem;
7770: if ($colsleft > 1 ) {
7771: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7772: ' </td>';
7773: } elsif ($colsleft == 1) {
7774: $datatable .= '<td class="LC_left_item"> </td>';
7775: }
7776: $datatable .='</table></td></tr>';
7777: $itemcount ++;
7778: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7779: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
7780: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 7781: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
7782: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 7783: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
7784: '</span></td></tr>';
1.356 raeburn 7785: $itemcount ++;
7786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7787: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7788: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367 raeburn 7789: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
7790: 'onblur="javascript:warnIntPass(this);" />'.
1.356 raeburn 7791: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7792: '</span></td></tr>';
1.354 raeburn 7793: } else {
1.359 raeburn 7794: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7795: my %ownerchg = (
7796: by => {},
7797: for => {},
7798: );
7799: my %ownertitles = &Apache::lonlocal::texthash (
7800: by => 'Course owner status(es) allowed',
7801: for => 'Student status(es) allowed',
7802: );
1.354 raeburn 7803: if (ref($settings) eq 'HASH') {
1.359 raeburn 7804: if (ref($settings->{crsownerchg}) eq 'HASH') {
7805: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7806: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7807: }
7808: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7809: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7810: }
1.354 raeburn 7811: }
7812: }
7813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7814: $datatable .= '<tr '.$css_class.'>'.
7815: '<td>'.
7816: &mt('Requirements').'<ul>'.
1.359 raeburn 7817: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7818: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7819: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7820: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7821: '</ul>'.
7822: '</td>'.
1.359 raeburn 7823: '<td class="LC_left_item">';
7824: foreach my $item ('by','for') {
7825: $datatable .= '<fieldset style="display: inline-block;">'.
7826: '<legend>'.$ownertitles{$item}.'</legend>';
7827: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7828: foreach my $type (@{$types}) {
7829: my $checked;
7830: if ($ownerchg{$item}{$type}) {
7831: $checked = ' checked="checked"';
7832: }
7833: $datatable .= '<span class="LC_nobreak"><label>'.
7834: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7835: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7836: '</span> ';
1.359 raeburn 7837: }
7838: }
7839: my $checked;
7840: if ($ownerchg{$item}{'default'}) {
7841: $checked = ' checked="checked"';
7842: }
7843: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7844: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7845: $othertitle.'</label></span></fieldset>';
7846: }
7847: $datatable .= '</td></tr>';
1.354 raeburn 7848: }
7849: return $datatable;
7850: }
7851:
1.373 raeburn 7852: sub print_wafproxy {
7853: my ($position,$dom,$settings,$rowtotal) = @_;
7854: my $css_class;
7855: my $itemcount = 0;
7856: my $datatable;
7857: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 7858: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 7859: my %lt = &wafproxy_titles();
1.373 raeburn 7860: foreach my $server (sort(keys(%servers))) {
7861: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 7862: next if ($serverhome eq '');
1.373 raeburn 7863: my $serverdom;
7864: if ($serverhome ne $server) {
7865: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 7866: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7867: $othercontrol{$server} = $serverdom;
7868: }
1.373 raeburn 7869: } else {
7870: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 7871: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 7872: if ($serverdom ne $dom) {
7873: $othercontrol{$server} = $serverdom;
7874: } else {
7875: $setdom = 1;
7876: if (ref($settings) eq 'HASH') {
7877: if (ref($settings->{'alias'}) eq 'HASH') {
7878: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 7879: if ($aliases{$dom} ne '') {
7880: $showdom = 1;
7881: }
1.373 raeburn 7882: }
1.388 raeburn 7883: if (ref($settings->{'saml'}) eq 'HASH') {
7884: $saml{$dom} = $settings->{'saml'};
7885: }
1.373 raeburn 7886: }
7887: }
7888: }
7889: }
1.381 raeburn 7890: if ($setdom) {
7891: %{$values{$dom}} = ();
7892: if (ref($settings) eq 'HASH') {
7893: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7894: $values{$dom}{$item} = $settings->{$item};
7895: }
7896: }
7897: }
1.373 raeburn 7898: if (keys(%othercontrol)) {
7899: %otherdoms = reverse(%othercontrol);
7900: foreach my $domain (keys(%otherdoms)) {
7901: %{$values{$domain}} = ();
7902: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 7903: if (ref($config{'wafproxy'}) eq 'HASH') {
7904: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 7905: if (exists($config{'wafproxy'}{'saml'})) {
7906: $saml{$domain} = $config{'wafproxy'}{'saml'};
7907: }
1.383 raeburn 7908: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7909: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 7910: }
7911: }
7912: }
7913: }
7914: if ($position eq 'top') {
7915: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 7916: my %aliasinfo;
1.373 raeburn 7917: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 7918: $itemcount ++;
7919: my $dom_in_effect;
7920: my $aliasrows = '<tr>'.
1.383 raeburn 7921: '<td class="LC_left_item" style="vertical-align: baseline;">'.
7922: &mt('Hostname').': '.
7923: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 7924: if ($othercontrol{$server}) {
1.381 raeburn 7925: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 7926: my ($current,$forsaml);
1.383 raeburn 7927: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7928: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 7929: }
1.388 raeburn 7930: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7931: if ($saml{$dom_in_effect}{$server}) {
7932: $forsaml = 1;
7933: }
7934: }
1.383 raeburn 7935: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7936: &mt('Alias').': ';
1.373 raeburn 7937: if ($current) {
1.381 raeburn 7938: $aliasrows .= $current;
1.388 raeburn 7939: if ($forsaml) {
1.396 raeburn 7940: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 7941: }
1.373 raeburn 7942: } else {
1.383 raeburn 7943: $aliasrows .= &mt('None');
1.373 raeburn 7944: }
1.383 raeburn 7945: $aliasrows .= ' <span class="LC_small">('.
7946: &mt('controlled by domain: [_1]',
7947: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 7948: } else {
1.381 raeburn 7949: $dom_in_effect = $dom;
1.388 raeburn 7950: my ($current,$samlon,$samloff);
7951: $samloff = ' checked="checked"';
1.373 raeburn 7952: if (ref($aliases{$dom}) eq 'HASH') {
7953: if ($aliases{$dom}{$server}) {
7954: $current = $aliases{$dom}{$server};
7955: }
7956: }
1.388 raeburn 7957: if (ref($saml{$dom}) eq 'HASH') {
7958: if ($saml{$dom}{$server}) {
7959: $samlon = $samloff;
7960: undef($samloff);
7961: }
7962: }
1.383 raeburn 7963: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7964: &mt('Alias').': '.
1.381 raeburn 7965: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 7966: 'value="'.$current.'" size="30" />'.
7967: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 7968: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 7969: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7970: &mt('No').'</label> <label>'.
7971: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7972: &mt('Yes').'</label></span>'.
7973: '</td>';
1.381 raeburn 7974: }
7975: $aliasrows .= '</tr>';
7976: $aliasinfo{$dom_in_effect} .= $aliasrows;
7977: }
7978: if ($aliasinfo{$dom}) {
7979: my ($onclick,$wafon,$wafoff,$showtable);
7980: $onclick = ' onclick="javascript:toggleWAF();"';
7981: $wafoff = ' checked="checked"';
7982: $showtable = ' style="display:none";';
7983: if ($showdom) {
7984: $wafon = $wafoff;
7985: $wafoff = '';
7986: $showtable = ' style="display:inline;"';
7987: }
7988: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7989: $datatable = '<tr'.$css_class.'>'.
7990: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7991: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7992: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7993: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7994: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7995: &mt('No').'</label></span></td>'.
7996: '<td class="LC_left_item">'.
7997: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7998: '</table></td></tr>';
7999: $itemcount++;
8000: }
1.383 raeburn 8001: if (keys(%otherdoms)) {
8002: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8003: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8004: $datatable .= '<tr'.$css_class.'>'.
8005: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8006: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8007: '</table></td></tr>';
1.381 raeburn 8008: $itemcount++;
1.373 raeburn 8009: }
8010: }
8011: } else {
1.383 raeburn 8012: my %ip_methods = &remoteip_methods();
1.373 raeburn 8013: if ($setdom) {
8014: $itemcount ++;
8015: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8016: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8017: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8018: $wafstyle = ' style="display:none;"';
8019: $nowafstyle = ' style="display:table-row;"';
8020: $currwafdisplay = ' style="display: none"';
8021: $wafrangestyle = ' style="display: none"';
8022: $curr_remotip = 'n';
1.382 raeburn 8023: $ssltossl = ' checked="checked"';
1.381 raeburn 8024: if ($showdom) {
8025: $wafstyle = ' style="display:table-row;"';
8026: $nowafstyle = ' style="display:none;"';
8027: if (keys(%{$values{$dom}})) {
8028: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8029: $curr_remotip = $values{$dom}{remoteip};
8030: }
8031: if ($curr_remotip eq 'h') {
8032: $currwafdisplay = ' style="display:table-row"';
8033: $wafrangestyle = ' style="display:inline-block;"';
8034: }
1.382 raeburn 8035: if ($values{$dom}{'sslopt'}) {
8036: $alltossl = ' checked="checked"';
8037: $ssltossl = '';
8038: }
1.381 raeburn 8039: }
8040: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8041: $vpndircheck = ' checked="checked"';
8042: $currwafvpn = ' style="display:table-row;"';
8043: $wafrangestyle = ' style="display:inline-block;"';
8044: } else {
8045: $vpnaliascheck = ' checked="checked"';
8046: $currwafvpn = ' style="display:none;"';
8047: }
8048: }
8049: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8050: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8051: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8052: '</tr>'.
8053: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8054: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8055: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8056: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8057: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8058: '<td class="LC_left_item"><table>'.
8059: '<tr>'.
8060: '<td valign="top">'.$lt{'remoteip'}.': '.
8061: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8062: foreach my $option ('m','h','n') {
8063: my $sel;
8064: if ($option eq $curr_remotip) {
8065: $sel = ' selected="selected"';
8066: }
8067: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8068: $ip_methods{$option}.'</option>';
8069: }
8070: $datatable .= '</select></td></tr>'."\n".
8071: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8072: $lt{'ipheader'}.': '.
8073: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8074: 'name="wafproxy_ipheader" />'.
8075: '</td></tr>'."\n".
8076: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8077: $lt{'trusted'}.':<br />'.
1.381 raeburn 8078: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8079: $values{$dom}{'trusted'}.'</textarea>'.
8080: '</td></tr>'."\n".
8081: '<tr><td><hr /></td></tr>'."\n".
8082: '<tr>'.
8083: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8084: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8085: $lt{'vpndirect'}.'</label>'.(' 'x2).
8086: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8087: $lt{'vpnaliased'}.'</label></span></td></tr>';
8088: foreach my $item ('vpnint','vpnext') {
8089: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8090: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8091: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8092: $values{$dom}{$item}.'</textarea>'.
8093: '</td></tr>'."\n";
1.373 raeburn 8094: }
1.382 raeburn 8095: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8096: '<tr>'.
8097: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8098: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8099: $lt{'alltossl'}.'</label>'.(' 'x2).
8100: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8101: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8102: '</table></td></tr>';
1.373 raeburn 8103: }
8104: if (keys(%otherdoms)) {
8105: foreach my $domain (sort(keys(%otherdoms))) {
8106: $itemcount ++;
8107: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8108: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8109: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8110: '<td class="LC_left_item"><table>';
1.382 raeburn 8111: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8112: my $showval = &mt('None');
1.382 raeburn 8113: if ($item eq 'ssl') {
8114: $showval = $lt{'ssltossl'};
8115: }
1.373 raeburn 8116: if ($values{$domain}{$item}) {
1.381 raeburn 8117: $showval = $values{$domain}{$item};
1.382 raeburn 8118: if ($item eq 'ssl') {
8119: $showval = $lt{'alltossl'};
1.383 raeburn 8120: } elsif ($item eq 'remoteip') {
8121: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8122: }
1.373 raeburn 8123: }
8124: $datatable .= '<tr>'.
8125: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8126: }
1.381 raeburn 8127: $datatable .= '</table></td></tr>';
1.373 raeburn 8128: }
8129: }
8130: }
8131: $$rowtotal += $itemcount;
8132: return $datatable;
8133: }
8134:
8135: sub wafproxy_titles {
8136: return &Apache::lonlocal::texthash(
1.381 raeburn 8137: remoteip => "Method for determining user's IP",
8138: ipheader => 'Request header containing remote IP',
8139: trusted => 'Trusted IP range(s)',
8140: vpnaccess => 'Access from institutional VPN',
8141: vpndirect => 'via regular hostname (no WAF)',
8142: vpnaliased => 'via aliased hostname (WAF)',
8143: vpnint => 'Internal IP Range(s) for VPN sessions',
8144: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8145: sslopt => 'Forwarding http/https',
1.381 raeburn 8146: alltossl => 'WAF forwards both http and https requests to https',
8147: ssltossl => 'WAF forwards http requests to http and https to https',
8148: );
8149: }
8150:
8151: sub remoteip_methods {
8152: return &Apache::lonlocal::texthash(
8153: m => 'Use Apache mod_remoteip',
8154: h => 'Use headers parsed by LON-CAPA',
8155: n => 'Not in use',
1.373 raeburn 8156: );
8157: }
8158:
1.137 raeburn 8159: sub print_usersessions {
8160: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8161: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8162: my (%by_ip,%by_location,@intdoms,@instdoms);
8163: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8164:
8165: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8166: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8167: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8168: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8169: if ($position eq 'top') {
1.152 raeburn 8170: if (keys(%serverhomes) > 1) {
1.145 raeburn 8171: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8172: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8173: if (ref($settings) eq 'HASH') {
8174: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8175: $curroffloadnow = $settings->{'offloadnow'};
8176: }
1.371 raeburn 8177: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8178: $curroffloadoth = $settings->{'offloadoth'};
8179: }
1.261 raeburn 8180: }
1.371 raeburn 8181: my $other_insts = scalar(keys(%by_location));
8182: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8183: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8184: } else {
1.140 raeburn 8185: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8186: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8187: '</td></tr>';
1.140 raeburn 8188: }
1.137 raeburn 8189: } else {
1.279 raeburn 8190: my %titles = &usersession_titles();
8191: my ($prefix,@types);
8192: if ($position eq 'bottom') {
8193: $prefix = 'remote';
8194: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8195: } else {
1.279 raeburn 8196: $prefix = 'hosted';
8197: @types = ('excludedomain','includedomain');
8198: }
8199: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8200: }
8201: $$rowtotal += $itemcount;
8202: return $datatable;
8203: }
8204:
8205: sub rules_by_location {
8206: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8207: my ($datatable,$itemcount,$css_class);
8208: if (keys(%{$by_location}) == 0) {
8209: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8210: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8211: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8212: '</td></tr>';
8213: $itemcount = 1;
8214: } else {
8215: $itemcount = 0;
8216: my $numinrow = 5;
8217: my (%current,%checkedon,%checkedoff);
8218: my @locations = sort(keys(%{$by_location}));
8219: foreach my $type (@{$types}) {
8220: $checkedon{$type} = '';
8221: $checkedoff{$type} = ' checked="checked"';
8222: }
8223: if (ref($settings) eq 'HASH') {
8224: if (ref($settings->{$prefix}) eq 'HASH') {
8225: foreach my $key (keys(%{$settings->{$prefix}})) {
8226: $current{$key} = $settings->{$prefix}{$key};
8227: if ($key eq 'version') {
8228: if ($current{$key} ne '') {
1.145 raeburn 8229: $checkedon{$key} = ' checked="checked"';
8230: $checkedoff{$key} = '';
8231: }
1.279 raeburn 8232: } elsif (ref($current{$key}) eq 'ARRAY') {
8233: $checkedon{$key} = ' checked="checked"';
8234: $checkedoff{$key} = '';
1.137 raeburn 8235: }
8236: }
8237: }
1.279 raeburn 8238: }
8239: foreach my $type (@{$types}) {
8240: next if ($type ne 'version' && !@locations);
8241: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8242: $datatable .= '<tr'.$css_class.'>
8243: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8244: <span class="LC_nobreak">
8245: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8246: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8247: if ($type eq 'version') {
8248: my @lcversions = &Apache::lonnet::all_loncaparevs();
8249: my $selector = '<select name="'.$prefix.'_version">';
8250: foreach my $version (@lcversions) {
8251: my $selected = '';
8252: if ($current{'version'} eq $version) {
8253: $selected = ' selected="selected"';
1.145 raeburn 8254: }
1.279 raeburn 8255: $selector .= ' <option value="'.$version.'"'.
8256: $selected.'>'.$version.'</option>';
8257: }
8258: $selector .= '</select> ';
8259: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8260: } else {
8261: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8262: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8263: ' />'.(' 'x2).
8264: '<input type="button" value="'.&mt('uncheck all').'" '.
8265: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8266: "\n".
8267: '</div><div><table>';
8268: my $rem;
8269: for (my $i=0; $i<@locations; $i++) {
8270: my ($showloc,$value,$checkedtype);
8271: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8272: my $ip = $by_location->{$locations[$i]}->[0];
8273: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8274: $value = join(':',@{$by_ip->{$ip}});
8275: $showloc = join(', ',@{$by_ip->{$ip}});
8276: if (ref($current{$type}) eq 'ARRAY') {
8277: foreach my $loc (@{$by_ip->{$ip}}) {
8278: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8279: $checkedtype = ' checked="checked"';
8280: last;
1.145 raeburn 8281: }
1.138 raeburn 8282: }
8283: }
8284: }
1.137 raeburn 8285: }
1.279 raeburn 8286: $rem = $i%($numinrow);
8287: if ($rem == 0) {
8288: if ($i > 0) {
8289: $datatable .= '</tr>';
8290: }
8291: $datatable .= '<tr>';
8292: }
8293: $datatable .= '<td class="LC_left_item">'.
8294: '<span class="LC_nobreak"><label>'.
8295: '<input type="checkbox" name="'.$prefix.'_'.$type.
8296: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8297: '</label></span></td>';
8298: }
8299: $rem = @locations%($numinrow);
8300: my $colsleft = $numinrow - $rem;
8301: if ($colsleft > 1 ) {
8302: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8303: ' </td>';
8304: } elsif ($colsleft == 1) {
8305: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8306: }
1.279 raeburn 8307: $datatable .= '</tr></table>';
1.137 raeburn 8308: }
1.279 raeburn 8309: $datatable .= '</td></tr>';
8310: $itemcount ++;
1.137 raeburn 8311: }
8312: }
1.279 raeburn 8313: return ($datatable,$itemcount);
1.137 raeburn 8314: }
8315:
1.275 raeburn 8316: sub print_ssl {
8317: my ($position,$dom,$settings,$rowtotal) = @_;
8318: my ($css_class,$datatable);
8319: my $itemcount = 1;
8320: if ($position eq 'top') {
1.281 raeburn 8321: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8322: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8323: my $same_institution;
8324: if ($intdom ne '') {
8325: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8326: if (ref($internet_names) eq 'ARRAY') {
8327: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8328: $same_institution = 1;
8329: }
8330: }
8331: }
1.275 raeburn 8332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8333: $datatable = '<tr'.$css_class.'><td colspan="2">';
8334: if ($same_institution) {
8335: my %domservers = &Apache::lonnet::get_servers($dom);
8336: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8337: } else {
8338: $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.");
8339: }
8340: $datatable .= '</td></tr>';
1.275 raeburn 8341: $itemcount ++;
8342: } else {
8343: my %titles = &ssl_titles();
8344: my (%by_ip,%by_location,@intdoms,@instdoms);
8345: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8346: my @alldoms = &Apache::lonnet::all_domains();
8347: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8348: my @domservers = &Apache::lonnet::get_servers($dom);
8349: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8350: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8351: if (($position eq 'connto') || ($position eq 'connfrom')) {
8352: my $legacy;
8353: unless (ref($settings) eq 'HASH') {
8354: my $name;
8355: if ($position eq 'connto') {
8356: $name = 'loncAllowInsecure';
8357: } else {
8358: $name = 'londAllowInsecure';
8359: }
8360: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8361: my @ids=&Apache::lonnet::current_machine_ids();
8362: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8363: my %what = (
8364: $name => 1,
8365: );
8366: my ($result,$returnhash) =
8367: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8368: if ($result eq 'ok') {
8369: if (ref($returnhash) eq 'HASH') {
8370: $legacy = $returnhash->{$name};
8371: }
8372: }
8373: } else {
8374: $legacy = $Apache::lonnet::perlvar{$name};
8375: }
8376: }
1.275 raeburn 8377: foreach my $type ('dom','intdom','other') {
8378: my %checked;
8379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8380: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8381: '<td class="LC_right_item">';
8382: my $skip;
8383: if ($type eq 'dom') {
8384: unless (keys(%servers) > 1) {
8385: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8386: $skip = 1;
8387: }
8388: }
8389: if ($type eq 'intdom') {
8390: unless (@instdoms > 1) {
8391: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8392: $skip = 1;
8393: }
8394: } elsif ($type eq 'other') {
8395: if (keys(%by_location) == 0) {
8396: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8397: $skip = 1;
8398: }
8399: }
8400: unless ($skip) {
8401: $checked{'yes'} = ' checked="checked"';
8402: if (ref($settings) eq 'HASH') {
1.293 raeburn 8403: if (ref($settings->{$position}) eq 'HASH') {
8404: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8405: $checked{$1} = $checked{'yes'};
8406: delete($checked{'yes'});
8407: }
8408: }
1.293 raeburn 8409: } else {
8410: if ($legacy == 0) {
8411: $checked{'req'} = $checked{'yes'};
8412: delete($checked{'yes'});
8413: }
1.275 raeburn 8414: }
8415: foreach my $option ('no','yes','req') {
8416: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8417: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8418: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8419: '</label></span>'.(' 'x2);
8420: }
8421: }
8422: $datatable .= '</td></tr>';
8423: $itemcount ++;
8424: }
8425: } else {
8426: my $prefix = 'replication';
8427: my @types = ('certreq','nocertreq');
1.279 raeburn 8428: if (keys(%by_location) == 0) {
8429: $datatable .= '<tr'.$css_class.'><td>'.
8430: &mt('Nothing to set here, as there are no other institutions').
8431: '</td></tr>';
8432: $itemcount ++;
1.275 raeburn 8433: } else {
1.279 raeburn 8434: ($datatable,$itemcount) =
8435: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8436: }
8437: }
8438: }
8439: $$rowtotal += $itemcount;
8440: return $datatable;
8441: }
8442:
8443: sub ssl_titles {
8444: return &Apache::lonlocal::texthash (
8445: dom => 'LON-CAPA servers/VMs from same domain',
8446: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8447: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8448: connto => 'Connections to other servers',
8449: connfrom => 'Connections from other servers',
1.275 raeburn 8450: replication => 'Replicating content to other institutions',
8451: certreq => 'Client certificate required, but specific domains exempt',
8452: nocertreq => 'No client certificate required, except for specific domains',
8453: no => 'SSL not used',
8454: yes => 'SSL Optional (used if available)',
8455: req => 'SSL Required',
8456: );
1.279 raeburn 8457: }
8458:
8459: sub print_trust {
8460: my ($prefix,$dom,$settings,$rowtotal) = @_;
8461: my ($css_class,$datatable,%checked,%choices);
8462: my (%by_ip,%by_location,@intdoms,@instdoms);
8463: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8464: my $itemcount = 1;
8465: my %titles = &trust_titles();
8466: my @types = ('exc','inc');
8467: if ($prefix eq 'top') {
8468: $prefix = 'content';
8469: } elsif ($prefix eq 'bottom') {
8470: $prefix = 'msg';
8471: }
8472: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8473: $$rowtotal += $itemcount;
8474: return $datatable;
8475: }
8476:
8477: sub trust_titles {
8478: return &Apache::lonlocal::texthash(
8479: content => "Access to this domain's content by others",
8480: shared => "Access to other domain's content by this domain",
8481: enroll => "Enrollment in this domain's courses by others",
8482: othcoau => "Co-author roles in this domain for others",
8483: coaurem => "Co-author roles for this domain's users elsewhere",
8484: domroles => "Domain roles in this domain assignable to others",
8485: catalog => "Course Catalog for this domain displayed elsewhere",
8486: reqcrs => "Requests for creation of courses in this domain by others",
8487: msg => "Users in other domains can send messages to this domain",
8488: exc => "Allow all, but exclude specific domains",
8489: inc => "Deny all, but include specific domains",
8490: );
1.275 raeburn 8491: }
8492:
1.138 raeburn 8493: sub build_location_hashes {
1.275 raeburn 8494: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8495: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8496: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8497: my %iphost = &Apache::lonnet::get_iphost();
8498: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8499: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8500: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8501: foreach my $id (@{$iphost{$primary_ip}}) {
8502: my $intdom = &Apache::lonnet::internet_dom($id);
8503: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8504: push(@{$intdoms},$intdom);
8505: }
8506: }
8507: }
8508: foreach my $ip (keys(%iphost)) {
8509: if (ref($iphost{$ip}) eq 'ARRAY') {
8510: foreach my $id (@{$iphost{$ip}}) {
8511: my $location = &Apache::lonnet::internet_dom($id);
8512: if ($location) {
1.275 raeburn 8513: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8514: my $dom = &Apache::lonnet::host_domain($id);
8515: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8516: push(@{$instdoms},$dom);
8517: }
8518: next;
8519: }
1.138 raeburn 8520: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8521: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8522: push(@{$by_ip->{$ip}},$location);
8523: }
8524: } else {
8525: $by_ip->{$ip} = [$location];
8526: }
8527: }
8528: }
8529: }
8530: }
8531: foreach my $ip (sort(keys(%{$by_ip}))) {
8532: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8533: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8534: my $first = $by_ip->{$ip}->[0];
8535: if (ref($by_location->{$first}) eq 'ARRAY') {
8536: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8537: push(@{$by_location->{$first}},$ip);
8538: }
8539: } else {
8540: $by_location->{$first} = [$ip];
8541: }
8542: }
8543: }
8544: return;
8545: }
8546:
1.145 raeburn 8547: sub current_offloads_to {
8548: my ($dom,$settings,$servers) = @_;
8549: my (%spareid,%otherdomconfigs);
1.152 raeburn 8550: if (ref($servers) eq 'HASH') {
1.145 raeburn 8551: foreach my $lonhost (sort(keys(%{$servers}))) {
8552: my $gotspares;
1.152 raeburn 8553: if (ref($settings) eq 'HASH') {
8554: if (ref($settings->{'spares'}) eq 'HASH') {
8555: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8556: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8557: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8558: $gotspares = 1;
8559: }
1.145 raeburn 8560: }
8561: }
8562: unless ($gotspares) {
8563: my $gotspares;
8564: my $serverhomeID =
8565: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8566: my $serverhomedom =
8567: &Apache::lonnet::host_domain($serverhomeID);
8568: if ($serverhomedom ne $dom) {
8569: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8570: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8571: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8572: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8573: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8574: $gotspares = 1;
8575: }
8576: }
8577: } else {
8578: $otherdomconfigs{$serverhomedom} =
8579: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8580: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8581: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8582: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8583: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8584: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8585: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8586: $gotspares = 1;
8587: }
8588: }
8589: }
8590: }
8591: }
8592: }
8593: }
8594: unless ($gotspares) {
8595: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8596: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8597: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8598: } else {
8599: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8600: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8601: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8602: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8603: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8604: } else {
1.150 raeburn 8605: my %what = (
8606: spareid => 1,
8607: );
8608: my ($result,$returnhash) =
8609: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8610: if ($result eq 'ok') {
8611: if (ref($returnhash) eq 'HASH') {
8612: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8613: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8614: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8615: }
8616: }
1.145 raeburn 8617: }
8618: }
8619: }
8620: }
8621: }
8622: }
8623: return %spareid;
8624: }
8625:
8626: sub spares_row {
1.371 raeburn 8627: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8628: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8629: my $css_class;
8630: my $numinrow = 4;
8631: my $itemcount = 1;
8632: my $datatable;
1.152 raeburn 8633: my %typetitles = &sparestype_titles();
8634: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8635: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8636: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8637: my ($othercontrol,$serverdom);
8638: if ($serverhome ne $server) {
8639: $serverdom = &Apache::lonnet::host_domain($serverhome);
8640: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8641: } else {
8642: $serverdom = &Apache::lonnet::host_domain($server);
8643: if ($serverdom ne $dom) {
8644: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8645: }
8646: }
8647: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8648: my ($checkednow,$checkedoth);
1.261 raeburn 8649: if (ref($curroffloadnow) eq 'HASH') {
8650: if ($curroffloadnow->{$server}) {
8651: $checkednow = ' checked="checked"';
8652: }
8653: }
1.371 raeburn 8654: if (ref($curroffloadoth) eq 'HASH') {
8655: if ($curroffloadoth->{$server}) {
8656: $checkedoth = ' checked="checked"';
8657: }
8658: }
1.145 raeburn 8659: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8660: $datatable .= '<tr'.$css_class.'>
8661: <td rowspan="2">
1.183 bisitz 8662: <span class="LC_nobreak">'.
8663: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8664: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8665: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8666: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8667: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8668: "\n";
1.371 raeburn 8669: if ($other_insts) {
8670: $datatable .= '<br />'.
8671: '<span class="LC_nobreak">'."\n".
8672: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8673: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8674: "\n";
8675: }
1.145 raeburn 8676: my (%current,%canselect);
1.152 raeburn 8677: my @choices =
8678: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8679: foreach my $type ('primary','default') {
8680: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8681: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8682: my @spares = @{$spareid->{$server}{$type}};
8683: if (@spares > 0) {
1.152 raeburn 8684: if ($othercontrol) {
8685: $current{$type} = join(', ',@spares);
8686: } else {
8687: $current{$type} .= '<table>';
8688: my $numspares = scalar(@spares);
8689: for (my $i=0; $i<@spares; $i++) {
8690: my $rem = $i%($numinrow);
8691: if ($rem == 0) {
8692: if ($i > 0) {
8693: $current{$type} .= '</tr>';
8694: }
8695: $current{$type} .= '<tr>';
1.145 raeburn 8696: }
1.152 raeburn 8697: $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'".');" /> '.
8698: $spareid->{$server}{$type}[$i].
8699: '</label></td>'."\n";
8700: }
8701: my $rem = @spares%($numinrow);
8702: my $colsleft = $numinrow - $rem;
8703: if ($colsleft > 1 ) {
8704: $current{$type} .= '<td colspan="'.$colsleft.
8705: '" class="LC_left_item">'.
8706: ' </td>';
8707: } elsif ($colsleft == 1) {
8708: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8709: }
1.152 raeburn 8710: $current{$type} .= '</tr></table>';
1.150 raeburn 8711: }
1.145 raeburn 8712: }
8713: }
8714: if ($current{$type} eq '') {
8715: $current{$type} = &mt('None specified');
8716: }
1.152 raeburn 8717: if ($othercontrol) {
8718: if ($type eq 'primary') {
8719: $canselect{$type} = $othercontrol;
8720: }
8721: } else {
8722: $canselect{$type} =
8723: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8724: '<select name="newspare_'.$type.'_'.$server.'" '.
8725: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8726: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8727: if (@choices > 0) {
8728: foreach my $lonhost (@choices) {
8729: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8730: }
8731: }
8732: $canselect{$type} .= '</select>'."\n";
8733: }
8734: } else {
8735: $current{$type} = &mt('Could not be determined');
8736: if ($type eq 'primary') {
8737: $canselect{$type} = $othercontrol;
8738: }
1.145 raeburn 8739: }
1.152 raeburn 8740: if ($type eq 'default') {
8741: $datatable .= '<tr'.$css_class.'>';
8742: }
8743: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8744: '<td>'.$current{$type}.'</td>'."\n".
8745: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8746: }
8747: $itemcount ++;
8748: }
8749: }
8750: $$rowtotal += $itemcount;
8751: return $datatable;
8752: }
8753:
1.152 raeburn 8754: sub possible_newspares {
8755: my ($server,$currspares,$serverhomes,$altids) = @_;
8756: my $serverhostname = &Apache::lonnet::hostname($server);
8757: my %excluded;
8758: if ($serverhostname ne '') {
8759: %excluded = (
8760: $serverhostname => 1,
8761: );
8762: }
8763: if (ref($currspares) eq 'HASH') {
8764: foreach my $type (keys(%{$currspares})) {
8765: if (ref($currspares->{$type}) eq 'ARRAY') {
8766: if (@{$currspares->{$type}} > 0) {
8767: foreach my $curr (@{$currspares->{$type}}) {
8768: my $hostname = &Apache::lonnet::hostname($curr);
8769: $excluded{$hostname} = 1;
8770: }
8771: }
8772: }
8773: }
8774: }
8775: my @choices;
8776: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8777: if (keys(%{$serverhomes}) > 1) {
8778: foreach my $name (sort(keys(%{$serverhomes}))) {
8779: unless ($excluded{$name}) {
8780: if (exists($altids->{$serverhomes->{$name}})) {
8781: push(@choices,$altids->{$serverhomes->{$name}});
8782: } else {
8783: push(@choices,$serverhomes->{$name});
1.145 raeburn 8784: }
8785: }
8786: }
8787: }
8788: }
1.152 raeburn 8789: return sort(@choices);
1.145 raeburn 8790: }
8791:
1.150 raeburn 8792: sub print_loadbalancing {
8793: my ($dom,$settings,$rowtotal) = @_;
8794: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8795: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8796: my $numinrow = 1;
8797: my $datatable;
8798: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8799: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8800: if (ref($settings) eq 'HASH') {
8801: %existing = %{$settings};
8802: }
8803: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8804: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8805: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8806: } else {
8807: return;
8808: }
8809: my ($othertitle,$usertypes,$types) =
8810: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8811: my $rownum = 8;
1.150 raeburn 8812: if (ref($types) eq 'ARRAY') {
8813: $rownum += scalar(@{$types});
8814: }
1.171 raeburn 8815: my @css_class = ('LC_odd_row','LC_even_row');
8816: my $balnum = 0;
8817: my $islast;
8818: my (@toshow,$disabledtext);
8819: if (keys(%currbalancer) > 0) {
8820: @toshow = sort(keys(%currbalancer));
8821: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8822: push(@toshow,'');
8823: }
8824: } else {
8825: @toshow = ('');
8826: $disabledtext = &mt('No existing load balancer');
8827: }
8828: foreach my $lonhost (@toshow) {
8829: if ($balnum == scalar(@toshow)-1) {
8830: $islast = 1;
8831: } else {
8832: $islast = 0;
8833: }
8834: my $cssidx = $balnum%2;
8835: my $targets_div_style = 'display: none';
8836: my $disabled_div_style = 'display: block';
8837: my $homedom_div_style = 'display: none';
8838: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 8839: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8840: '<p>';
8841: if ($lonhost eq '') {
1.210 raeburn 8842: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 8843: if (keys(%currbalancer) > 0) {
8844: $datatable .= &mt('Add balancer:');
8845: } else {
8846: $datatable .= &mt('Enable balancer:');
8847: }
8848: $datatable .= ' '.
8849: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8850: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8851: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8852: '<option value="" selected="selected">'.&mt('None').
8853: '</option>'."\n";
8854: foreach my $server (sort(keys(%servers))) {
8855: next if ($currbalancer{$server});
8856: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8857: }
1.210 raeburn 8858: $datatable .=
1.171 raeburn 8859: '</select>'."\n".
8860: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8861: } else {
8862: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8863: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8864: &mt('Stop balancing').'</label>'.
8865: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8866: $targets_div_style = 'display: block';
8867: $disabled_div_style = 'display: none';
8868: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8869: $homedom_div_style = 'display: block';
8870: }
8871: }
1.306 raeburn 8872: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 8873: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8874: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8875: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8876: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8877: my @sparestypes = ('primary','default');
8878: my %typetitles = &sparestype_titles();
1.284 raeburn 8879: my %hostherechecked = (
8880: no => ' checked="checked"',
8881: );
1.342 raeburn 8882: my %balcookiechecked = (
8883: no => ' checked="checked"',
8884: );
1.171 raeburn 8885: foreach my $sparetype (@sparestypes) {
8886: my $targettable;
8887: for (my $i=0; $i<$numspares; $i++) {
8888: my $checked;
8889: if (ref($currtargets{$lonhost}) eq 'HASH') {
8890: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8891: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8892: $checked = ' checked="checked"';
8893: }
8894: }
8895: }
8896: my ($chkboxval,$disabled);
8897: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8898: $chkboxval = $spares[$i];
8899: }
8900: if (exists($currbalancer{$spares[$i]})) {
8901: $disabled = ' disabled="disabled"';
8902: }
1.210 raeburn 8903: $targettable .=
1.253 raeburn 8904: '<td><span class="LC_nobreak"><label>'.
8905: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 8906: $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 8907: '</span></label></span></td>';
1.171 raeburn 8908: my $rem = $i%($numinrow);
8909: if ($rem == 0) {
8910: if (($i > 0) && ($i < $numspares-1)) {
8911: $targettable .= '</tr>';
8912: }
8913: if ($i < $numspares-1) {
8914: $targettable .= '<tr>';
1.150 raeburn 8915: }
8916: }
8917: }
1.171 raeburn 8918: if ($targettable ne '') {
8919: my $rem = $numspares%($numinrow);
8920: my $colsleft = $numinrow - $rem;
8921: if ($colsleft > 1 ) {
8922: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8923: ' </td>';
8924: } elsif ($colsleft == 1) {
8925: $targettable .= '<td class="LC_left_item"> </td>';
8926: }
8927: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8928: '<table><tr>'.$targettable.'</tr></table><br />';
8929: }
1.284 raeburn 8930: $hostherechecked{$sparetype} = '';
8931: if (ref($currtargets{$lonhost}) eq 'HASH') {
8932: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8933: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8934: $hostherechecked{$sparetype} = ' checked="checked"';
8935: $hostherechecked{'no'} = '';
8936: }
8937: }
8938: }
8939: }
1.342 raeburn 8940: if ($currcookies{$lonhost}) {
8941: %balcookiechecked = (
8942: yes => ' checked="checked"',
8943: );
8944: }
1.284 raeburn 8945: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8946: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8947: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8948: foreach my $sparetype (@sparestypes) {
8949: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8950: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8951: '</i></label><br />';
1.171 raeburn 8952: }
1.342 raeburn 8953: $datatable .= &mt('Use balancer cookie').'<br />'.
8954: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8955: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8956: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8957: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8958: '</div></td></tr>'.
1.171 raeburn 8959: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8960: $othertitle,$usertypes,$types,\%servers,
8961: \%currbalancer,$lonhost,
8962: $targets_div_style,$homedom_div_style,
8963: $css_class[$cssidx],$balnum,$islast);
8964: $$rowtotal += $rownum;
8965: $balnum ++;
8966: }
8967: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8968: return $datatable;
8969: }
8970:
8971: sub get_loadbalancers_config {
1.342 raeburn 8972: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 8973: return unless ((ref($servers) eq 'HASH') &&
8974: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 8975: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8976: (ref($currcookies) eq 'HASH'));
1.171 raeburn 8977: if (keys(%{$existing}) > 0) {
8978: my $oldlonhost;
8979: foreach my $key (sort(keys(%{$existing}))) {
8980: if ($key eq 'lonhost') {
8981: $oldlonhost = $existing->{'lonhost'};
8982: $currbalancer->{$oldlonhost} = 1;
8983: } elsif ($key eq 'targets') {
8984: if ($oldlonhost) {
8985: $currtargets->{$oldlonhost} = $existing->{'targets'};
8986: }
8987: } elsif ($key eq 'rules') {
8988: if ($oldlonhost) {
8989: $currrules->{$oldlonhost} = $existing->{'rules'};
8990: }
8991: } elsif (ref($existing->{$key}) eq 'HASH') {
8992: $currbalancer->{$key} = 1;
8993: $currtargets->{$key} = $existing->{$key}{'targets'};
8994: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 8995: if ($existing->{$key}{'cookie'}) {
8996: $currcookies->{$key} = 1;
8997: }
1.150 raeburn 8998: }
8999: }
1.171 raeburn 9000: } else {
9001: my ($balancerref,$targetsref) =
9002: &Apache::lonnet::get_lonbalancer_config($servers);
9003: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9004: foreach my $server (sort(keys(%{$balancerref}))) {
9005: $currbalancer->{$server} = 1;
9006: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9007: }
9008: }
9009: }
1.171 raeburn 9010: return;
1.150 raeburn 9011: }
9012:
9013: sub loadbalancing_rules {
9014: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9015: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9016: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9017: my $output;
1.171 raeburn 9018: my $num = 0;
1.210 raeburn 9019: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9020: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9021: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9022: foreach my $type (@{$alltypes}) {
1.171 raeburn 9023: $num ++;
1.150 raeburn 9024: my $current;
9025: if (ref($currrules) eq 'HASH') {
9026: $current = $currrules->{$type};
9027: }
1.253 raeburn 9028: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9029: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9030: $current = '';
9031: }
9032: }
9033: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9034: $servers,$currbalancer,$lonhost,$dom,
9035: $targets_div_style,$homedom_div_style,
9036: $css_class,$balnum,$num,$islast);
1.150 raeburn 9037: }
9038: }
9039: return $output;
9040: }
9041:
9042: sub loadbalancing_titles {
9043: my ($dom,$intdom,$usertypes,$types) = @_;
9044: my %othertypes = (
9045: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9046: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9047: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9048: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9049: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9050: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9051: );
1.209 raeburn 9052: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9053: my @available;
1.150 raeburn 9054: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9055: @available = @{$types};
1.150 raeburn 9056: }
1.302 raeburn 9057: unless (grep(/^default$/,@available)) {
9058: push(@available,'default');
9059: }
9060: unshift(@alltypes,@available);
1.150 raeburn 9061: my %titles;
9062: foreach my $type (@alltypes) {
9063: if ($type =~ /^_LC_/) {
9064: $titles{$type} = $othertypes{$type};
9065: } elsif ($type eq 'default') {
9066: $titles{$type} = &mt('All users from [_1]',$dom);
9067: if (ref($types) eq 'ARRAY') {
9068: if (@{$types} > 0) {
9069: $titles{$type} = &mt('Other users from [_1]',$dom);
9070: }
9071: }
9072: } elsif (ref($usertypes) eq 'HASH') {
9073: $titles{$type} = $usertypes->{$type};
9074: }
9075: }
9076: return (\@alltypes,\%othertypes,\%titles);
9077: }
9078:
9079: sub loadbalance_rule_row {
1.171 raeburn 9080: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9081: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9082: my @rulenames;
1.150 raeburn 9083: my %ruletitles = &offloadtype_text();
1.209 raeburn 9084: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9085: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9086: } else {
1.209 raeburn 9087: @rulenames = ('default','homeserver');
9088: if ($type eq '_LC_external') {
9089: push(@rulenames,'externalbalancer');
9090: } else {
9091: push(@rulenames,'specific');
9092: }
9093: push(@rulenames,'none');
1.150 raeburn 9094: }
9095: my $style = $targets_div_style;
1.253 raeburn 9096: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9097: $style = $homedom_div_style;
9098: }
1.171 raeburn 9099: my $space;
9100: if ($islast && $num == 1) {
1.317 raeburn 9101: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9102: }
1.210 raeburn 9103: my $output =
1.306 raeburn 9104: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9105: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9106: '<td valaign="top">'.$space.
9107: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9108: for (my $i=0; $i<@rulenames; $i++) {
9109: my $rule = $rulenames[$i];
9110: my ($checked,$extra);
9111: if ($rulenames[$i] eq 'default') {
9112: $rule = '';
9113: }
9114: if ($rulenames[$i] eq 'specific') {
9115: if (ref($servers) eq 'HASH') {
9116: my $default;
9117: if (($current ne '') && (exists($servers->{$current}))) {
9118: $checked = ' checked="checked"';
9119: }
9120: unless ($checked) {
9121: $default = ' selected="selected"';
9122: }
1.210 raeburn 9123: $extra =
1.171 raeburn 9124: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9125: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9126: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9127: '<option value=""'.$default.'></option>'."\n";
9128: foreach my $server (sort(keys(%{$servers}))) {
9129: if (ref($currbalancer) eq 'HASH') {
9130: next if (exists($currbalancer->{$server}));
9131: }
1.150 raeburn 9132: my $selected;
1.171 raeburn 9133: if ($server eq $current) {
1.150 raeburn 9134: $selected = ' selected="selected"';
9135: }
1.171 raeburn 9136: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9137: }
9138: $extra .= '</select>';
9139: }
9140: } elsif ($rule eq $current) {
9141: $checked = ' checked="checked"';
9142: }
9143: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9144: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9145: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9146: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9147: ')"'.$checked.' /> ';
9148: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9149: $output .= $ruletitles{'particular'};
9150: } else {
9151: $output .= $ruletitles{$rulenames[$i]};
9152: }
9153: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9154: }
9155: $output .= '</div></td></tr>'."\n";
9156: return $output;
9157: }
9158:
9159: sub offloadtype_text {
9160: my %ruletitles = &Apache::lonlocal::texthash (
9161: 'default' => 'Offloads to default destinations',
9162: 'homeserver' => "Offloads to user's home server",
9163: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9164: 'specific' => 'Offloads to specific server',
1.161 raeburn 9165: 'none' => 'No offload',
1.209 raeburn 9166: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9167: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9168: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9169: );
9170: return %ruletitles;
9171: }
9172:
9173: sub sparestype_titles {
9174: my %typestitles = &Apache::lonlocal::texthash (
9175: 'primary' => 'primary',
9176: 'default' => 'default',
9177: );
9178: return %typestitles;
9179: }
9180:
1.28 raeburn 9181: sub contact_titles {
9182: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9183: 'supportemail' => 'Support E-mail address',
9184: 'adminemail' => 'Default Server Admin E-mail address',
9185: 'errormail' => 'Error reports to be e-mailed to',
9186: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9187: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9188: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9189: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9190: 'requestsmail' => 'E-mail from course requests requiring approval',
9191: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9192: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9193: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9194: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9195: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9196: 'errorweights' => 'Weights used to compute error count',
9197: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9198: );
9199: my %short_titles = &Apache::lonlocal::texthash (
9200: adminemail => 'Admin E-mail address',
9201: supportemail => 'Support E-mail',
9202: );
9203: return (\%titles,\%short_titles);
9204: }
9205:
1.286 raeburn 9206: sub helpform_fields {
9207: my %titles = &Apache::lonlocal::texthash (
9208: 'username' => 'Name',
9209: 'user' => 'Username/domain',
9210: 'phone' => 'Phone',
9211: 'cc' => 'Cc e-mail',
9212: 'course' => 'Course Details',
9213: 'section' => 'Sections',
1.289 raeburn 9214: 'screenshot' => 'File upload',
1.286 raeburn 9215: );
9216: my @fields = ('username','phone','user','course','section','cc','screenshot');
9217: my %possoptions = (
9218: username => ['yes','no','req'],
1.289 raeburn 9219: phone => ['yes','no','req'],
1.286 raeburn 9220: user => ['yes','no'],
1.289 raeburn 9221: cc => ['yes','no'],
1.286 raeburn 9222: course => ['yes','no'],
9223: section => ['yes','no'],
9224: screenshot => ['yes','no'],
9225: );
9226: my %fieldoptions = &Apache::lonlocal::texthash (
9227: 'yes' => 'Optional',
9228: 'req' => 'Required',
9229: 'no' => "Not shown",
9230: );
9231: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9232: }
9233:
1.72 raeburn 9234: sub tool_titles {
9235: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9236: aboutme => 'Personal web page',
1.86 raeburn 9237: blog => 'Blog',
1.162 raeburn 9238: webdav => 'WebDAV',
1.86 raeburn 9239: portfolio => 'Portfolio',
1.88 bisitz 9240: official => 'Official courses (with institutional codes)',
9241: unofficial => 'Unofficial courses',
1.98 raeburn 9242: community => 'Communities',
1.216 raeburn 9243: textbook => 'Textbook courses',
1.271 raeburn 9244: placement => 'Placement tests',
1.86 raeburn 9245: );
1.72 raeburn 9246: return %titles;
9247: }
9248:
1.101 raeburn 9249: sub courserequest_titles {
9250: my %titles = &Apache::lonlocal::texthash (
9251: official => 'Official',
9252: unofficial => 'Unofficial',
9253: community => 'Communities',
1.216 raeburn 9254: textbook => 'Textbook',
1.271 raeburn 9255: placement => 'Placement tests',
1.325 raeburn 9256: lti => 'LTI Provider',
1.101 raeburn 9257: norequest => 'Not allowed',
1.325 raeburn 9258: approval => 'Approval by DC',
1.101 raeburn 9259: validate => 'With validation',
9260: autolimit => 'Numerical limit',
1.103 raeburn 9261: unlimited => '(blank for unlimited)',
1.101 raeburn 9262: );
9263: return %titles;
9264: }
9265:
1.163 raeburn 9266: sub authorrequest_titles {
9267: my %titles = &Apache::lonlocal::texthash (
9268: norequest => 'Not allowed',
9269: approval => 'Approval by Dom. Coord.',
9270: automatic => 'Automatic approval',
9271: );
9272: return %titles;
1.210 raeburn 9273: }
1.163 raeburn 9274:
1.101 raeburn 9275: sub courserequest_conditions {
9276: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9277: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9278: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9279: );
9280: return %conditions;
9281: }
9282:
9283:
1.27 raeburn 9284: sub print_usercreation {
1.30 raeburn 9285: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9286: my $numinrow = 4;
1.28 raeburn 9287: my $datatable;
9288: if ($position eq 'top') {
1.30 raeburn 9289: $$rowtotal ++;
1.34 raeburn 9290: my $rowcount = 0;
1.32 raeburn 9291: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9292: if (ref($rules) eq 'HASH') {
9293: if (keys(%{$rules}) > 0) {
1.32 raeburn 9294: $datatable .= &user_formats_row('username',$settings,$rules,
9295: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9296: $$rowtotal ++;
1.32 raeburn 9297: $rowcount ++;
9298: }
9299: }
9300: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9301: if (ref($idrules) eq 'HASH') {
9302: if (keys(%{$idrules}) > 0) {
9303: $datatable .= &user_formats_row('id',$settings,$idrules,
9304: $idruleorder,$numinrow,$rowcount);
9305: $$rowtotal ++;
9306: $rowcount ++;
1.28 raeburn 9307: }
9308: }
1.39 raeburn 9309: if ($rowcount == 0) {
9310: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9311: $$rowtotal ++;
9312: $rowcount ++;
9313: }
1.34 raeburn 9314: } elsif ($position eq 'middle') {
1.224 raeburn 9315: my @creators = ('author','course','requestcrs');
1.37 raeburn 9316: my ($rules,$ruleorder) =
9317: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9318: my %lt = &usercreation_types();
9319: my %checked;
9320: if (ref($settings) eq 'HASH') {
9321: if (ref($settings->{'cancreate'}) eq 'HASH') {
9322: foreach my $item (@creators) {
9323: $checked{$item} = $settings->{'cancreate'}{$item};
9324: }
9325: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9326: foreach my $item (@creators) {
9327: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9328: $checked{$item} = 'none';
9329: }
9330: }
9331: }
9332: }
9333: my $rownum = 0;
9334: foreach my $item (@creators) {
9335: $rownum ++;
1.224 raeburn 9336: if ($checked{$item} eq '') {
9337: $checked{$item} = 'any';
1.34 raeburn 9338: }
9339: my $css_class;
9340: if ($rownum%2) {
9341: $css_class = '';
9342: } else {
9343: $css_class = ' class="LC_odd_row" ';
9344: }
9345: $datatable .= '<tr'.$css_class.'>'.
9346: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9347: '</span></td><td style="text-align: right">';
1.224 raeburn 9348: my @options = ('any');
9349: if (ref($rules) eq 'HASH') {
9350: if (keys(%{$rules}) > 0) {
9351: push(@options,('official','unofficial'));
1.37 raeburn 9352: }
9353: }
1.224 raeburn 9354: push(@options,'none');
1.37 raeburn 9355: foreach my $option (@options) {
1.50 raeburn 9356: my $type = 'radio';
1.34 raeburn 9357: my $check = ' ';
1.224 raeburn 9358: if ($checked{$item} eq $option) {
9359: $check = ' checked="checked" ';
1.34 raeburn 9360: }
9361: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9362: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9363: $item.'" value="'.$option.'"'.$check.'/> '.
9364: $lt{$option}.'</label> </span>';
9365: }
9366: $datatable .= '</td></tr>';
9367: }
1.28 raeburn 9368: } else {
9369: my @contexts = ('author','course','domain');
1.325 raeburn 9370: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9371: my %checked;
9372: if (ref($settings) eq 'HASH') {
9373: if (ref($settings->{'authtypes'}) eq 'HASH') {
9374: foreach my $item (@contexts) {
9375: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9376: foreach my $auth (@authtypes) {
9377: if ($settings->{'authtypes'}{$item}{$auth}) {
9378: $checked{$item}{$auth} = ' checked="checked" ';
9379: }
9380: }
9381: }
9382: }
1.27 raeburn 9383: }
1.35 raeburn 9384: } else {
9385: foreach my $item (@contexts) {
1.36 raeburn 9386: foreach my $auth (@authtypes) {
1.35 raeburn 9387: $checked{$item}{$auth} = ' checked="checked" ';
9388: }
9389: }
1.27 raeburn 9390: }
1.28 raeburn 9391: my %title = &context_names();
9392: my %authname = &authtype_names();
9393: my $rownum = 0;
9394: my $css_class;
9395: foreach my $item (@contexts) {
9396: if ($rownum%2) {
9397: $css_class = '';
9398: } else {
9399: $css_class = ' class="LC_odd_row" ';
9400: }
1.30 raeburn 9401: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9402: '<td>'.$title{$item}.
9403: '</td><td class="LC_left_item">'.
9404: '<span class="LC_nobreak">';
9405: foreach my $auth (@authtypes) {
9406: $datatable .= '<label>'.
9407: '<input type="checkbox" name="'.$item.'_auth" '.
9408: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9409: $authname{$auth}.'</label> ';
9410: }
9411: $datatable .= '</span></td></tr>';
9412: $rownum ++;
1.27 raeburn 9413: }
1.30 raeburn 9414: $$rowtotal += $rownum;
1.27 raeburn 9415: }
9416: return $datatable;
9417: }
9418:
1.224 raeburn 9419: sub print_selfcreation {
9420: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9421: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9422: $emaildomain,$datatable);
1.224 raeburn 9423: if (ref($settings) eq 'HASH') {
9424: if (ref($settings->{'cancreate'}) eq 'HASH') {
9425: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9426: if (ref($createsettings) eq 'HASH') {
9427: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9428: @selfcreate = @{$createsettings->{'selfcreate'}};
9429: } elsif ($createsettings->{'selfcreate'} ne '') {
9430: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9431: @selfcreate = ('email','login','sso');
9432: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9433: @selfcreate = ($createsettings->{'selfcreate'});
9434: }
9435: }
9436: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9437: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9438: }
1.305 raeburn 9439: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9440: $emailoptions = $createsettings->{'emailoptions'};
9441: }
1.303 raeburn 9442: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9443: $emailverified = $createsettings->{'emailverified'};
9444: }
9445: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9446: $emaildomain = $createsettings->{'emaildomain'};
9447: }
1.224 raeburn 9448: }
9449: }
9450: }
9451: my %radiohash;
9452: my $numinrow = 4;
9453: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9454: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9455: if ($position eq 'top') {
9456: my %choices = &Apache::lonlocal::texthash (
9457: cancreate_login => 'Institutional Login',
9458: cancreate_sso => 'Institutional Single Sign On',
9459: );
9460: my @toggles = sort(keys(%choices));
9461: my %defaultchecked = (
9462: 'cancreate_login' => 'off',
9463: 'cancreate_sso' => 'off',
9464: );
1.228 raeburn 9465: my ($onclick,$itemcount);
1.224 raeburn 9466: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9467: \%choices,$itemcount,$onclick);
1.228 raeburn 9468: $$rowtotal += $itemcount;
9469:
1.224 raeburn 9470: if (ref($usertypes) eq 'HASH') {
9471: if (keys(%{$usertypes}) > 0) {
9472: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9473: $dom,$numinrow,$othertitle,
1.305 raeburn 9474: 'statustocreate',$rowtotal);
1.224 raeburn 9475: $$rowtotal ++;
9476: }
9477: }
1.240 raeburn 9478: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9479: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9480: $fieldtitles{'inststatus'} = &mt('Institutional status');
9481: my $rem;
9482: my $numperrow = 2;
9483: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9484: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9485: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9486: '<td class="LC_left_item">'."\n".
1.334 raeburn 9487: '<table>'."\n";
1.240 raeburn 9488: for (my $i=0; $i<@fields; $i++) {
9489: $rem = $i%($numperrow);
9490: if ($rem == 0) {
9491: if ($i > 0) {
9492: $datatable .= '</tr>';
9493: }
9494: $datatable .= '<tr>';
9495: }
9496: my $currval;
1.248 raeburn 9497: if (ref($createsettings) eq 'HASH') {
9498: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9499: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9500: }
1.240 raeburn 9501: }
9502: $datatable .= '<td class="LC_left_item">'.
9503: '<span class="LC_nobreak">'.
9504: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9505: 'value="'.$currval.'" size="10" /> '.
9506: $fieldtitles{$fields[$i]}.'</span></td>';
9507: }
9508: my $colsleft = $numperrow - $rem;
9509: if ($colsleft > 1 ) {
9510: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9511: ' </td>';
9512: } elsif ($colsleft == 1) {
9513: $datatable .= '<td class="LC_left_item"> </td>';
9514: }
9515: $datatable .= '</tr></table></td></tr>';
9516: $$rowtotal ++;
1.224 raeburn 9517: } elsif ($position eq 'middle') {
9518: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9519: my @posstypes;
1.224 raeburn 9520: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9521: @posstypes = @{$types};
9522: }
9523: unless (grep(/^default$/,@posstypes)) {
9524: push(@posstypes,'default');
9525: }
9526: my %usertypeshash;
9527: if (ref($usertypes) eq 'HASH') {
9528: %usertypeshash = %{$usertypes};
9529: }
9530: $usertypeshash{'default'} = $othertitle;
9531: foreach my $status (@posstypes) {
9532: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9533: $numinrow,$$rowtotal,\%usertypeshash);
9534: $$rowtotal ++;
1.224 raeburn 9535: }
9536: } else {
1.236 raeburn 9537: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9538: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9539: );
9540: my @toggles = sort(keys(%choices));
9541: my %defaultchecked = (
9542: 'cancreate_email' => 'off',
9543: );
1.305 raeburn 9544: my $customclass = 'LC_selfcreate_email';
9545: my $classprefix = 'LC_canmodify_emailusername_';
9546: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9547: my $display = 'none';
1.305 raeburn 9548: my $rowstyle = 'display:none';
1.236 raeburn 9549: if (grep(/^\Qemail\E$/,@selfcreate)) {
9550: $display = 'block';
1.305 raeburn 9551: $rowstyle = 'display:table-row';
1.236 raeburn 9552: }
1.305 raeburn 9553: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9554: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9555: \%choices,$$rowtotal,$onclick);
9556: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9557: $rowstyle);
9558: $$rowtotal ++;
9559: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9560: $rowstyle);
9561: $$rowtotal ++;
9562: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9563: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9564: my ($emailrules,$emailruleorder) =
9565: &Apache::lonnet::inst_userrules($dom,'email');
9566: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9567: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9568: if (ref($types) eq 'ARRAY') {
9569: @posstypes = @{$types};
9570: }
9571: if (@posstypes) {
9572: unless (grep(/^default$/,@posstypes)) {
9573: push(@posstypes,'default');
1.302 raeburn 9574: }
9575: if (ref($usertypes) eq 'HASH') {
9576: %usertypeshash = %{$usertypes};
9577: }
1.305 raeburn 9578: my $currassign;
9579: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9580: $currassign = {
9581: selfassign => $domdefaults{'inststatusguest'},
9582: };
9583: @ordered = @{$domdefaults{'inststatusguest'}};
9584: } else {
9585: $currassign = { selfassign => [] };
9586: }
9587: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9588: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9589: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9590: $numinrow,$othertitle,'selfassign',
9591: $rowtotal,$onclicktypes,$customclass,
9592: $rowstyle);
9593: $$rowtotal ++;
1.302 raeburn 9594: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9595: foreach my $status (@posstypes) {
9596: my $css_class;
9597: if ($$rowtotal%2) {
9598: $css_class = 'LC_odd_row ';
9599: }
9600: $css_class .= $customclass;
9601: my $rowid = $optionsprefix.$status;
9602: my $hidden = 1;
9603: my $currstyle = 'display:none';
9604: if (grep(/^\Q$status\E$/,@ordered)) {
9605: $currstyle = $rowstyle;
9606: $hidden = 0;
9607: }
9608: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9609: $emailrules,$emailruleorder,$settings,$status,$rowid,
9610: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9611: unless ($hidden) {
9612: $$rowtotal ++;
9613: }
1.224 raeburn 9614: }
1.302 raeburn 9615: } else {
1.305 raeburn 9616: my $css_class;
9617: if ($$rowtotal%2) {
9618: $css_class = 'LC_odd_row ';
9619: }
9620: $css_class .= $customclass;
1.302 raeburn 9621: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9622: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9623: $emailrules,$emailruleorder,$settings,'default','',
9624: $othertitle,$css_class,$rowstyle,$intdom);
9625: $$rowtotal ++;
1.224 raeburn 9626: }
9627: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9628: $numinrow = 1;
1.305 raeburn 9629: if (@posstypes) {
9630: foreach my $status (@posstypes) {
9631: my $rowid = $classprefix.$status;
9632: my $datarowstyle = 'display:none';
9633: if (grep(/^\Q$status\E$/,@ordered)) {
9634: $datarowstyle = $rowstyle;
9635: }
9636: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9637: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9638: $infotitles,$rowid,$customclass,$datarowstyle);
9639: unless ($datarowstyle eq 'display:none') {
9640: $$rowtotal ++;
9641: }
1.224 raeburn 9642: }
1.305 raeburn 9643: } else {
9644: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9645: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9646: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9647: }
9648: }
9649: return $datatable;
9650: }
9651:
1.305 raeburn 9652: sub selfcreate_javascript {
9653: return <<"ENDSCRIPT";
9654:
9655: <script type="text/javascript">
9656: // <![CDATA[
9657:
9658: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9659: var x = document.getElementsByClassName(target);
9660: var insttypes = 0;
9661: var insttypeRegExp = new RegExp(prefix);
9662: if ((x.length != undefined) && (x.length > 0)) {
9663: if (form.elements[radio].length != undefined) {
9664: for (var i=0; i<form.elements[radio].length; i++) {
9665: if (form.elements[radio][i].checked) {
9666: if (form.elements[radio][i].value == 1) {
9667: for (var j=0; j<x.length; j++) {
9668: if (x[j].id == 'undefined') {
9669: x[j].style.display = 'table-row';
9670: } else if (insttypeRegExp.test(x[j].id)) {
9671: insttypes ++;
9672: } else {
9673: x[j].style.display = 'table-row';
9674: }
9675: }
9676: } else {
9677: for (var j=0; j<x.length; j++) {
9678: x[j].style.display = 'none';
9679: }
1.236 raeburn 9680: }
1.305 raeburn 9681: break;
9682: }
9683: }
9684: if (insttypes > 0) {
9685: toggleDataRow(form,checkbox,target,altprefix);
9686: toggleDataRow(form,checkbox,target,prefix,1);
9687: }
9688: }
9689: }
9690: return;
9691: }
9692:
9693: function toggleDataRow(form,checkbox,target,prefix,docount) {
9694: if (form.elements[checkbox].length != undefined) {
9695: var count = 0;
9696: if (docount) {
9697: for (var i=0; i<form.elements[checkbox].length; i++) {
9698: if (form.elements[checkbox][i].checked) {
9699: count ++;
1.236 raeburn 9700: }
1.305 raeburn 9701: }
9702: }
9703: for (var i=0; i<form.elements[checkbox].length; i++) {
9704: var type = form.elements[checkbox][i].value;
9705: if (document.getElementById(prefix+type)) {
9706: if (form.elements[checkbox][i].checked) {
9707: document.getElementById(prefix+type).style.display = 'table-row';
9708: if (count % 2 == 1) {
9709: document.getElementById(prefix+type).className = target+' LC_odd_row';
9710: } else {
9711: document.getElementById(prefix+type).className = target;
1.236 raeburn 9712: }
1.305 raeburn 9713: count ++;
1.236 raeburn 9714: } else {
1.305 raeburn 9715: document.getElementById(prefix+type).style.display = 'none';
9716: }
9717: }
9718: }
9719: }
9720: return;
9721: }
9722:
9723: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9724: var caller = radio+'_'+status;
9725: if (form.elements[caller].length != undefined) {
9726: for (var i=0; i<form.elements[caller].length; i++) {
9727: if (form.elements[caller][i].checked) {
9728: if (document.getElementById(altprefix+'_inst_'+status)) {
9729: var curr = form.elements[caller][i].value;
9730: if (prefix) {
9731: document.getElementById(prefix+'_'+status).style.display = 'none';
9732: }
9733: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9734: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9735: if (curr == 'custom') {
9736: if (prefix) {
9737: document.getElementById(prefix+'_'+status).style.display = 'inline';
9738: }
9739: } else if (curr == 'inst') {
9740: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9741: } else if (curr == 'noninst') {
9742: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9743: }
1.305 raeburn 9744: break;
1.236 raeburn 9745: }
9746: }
9747: }
9748: }
9749: }
9750:
1.305 raeburn 9751: // ]]>
9752: </script>
9753:
9754: ENDSCRIPT
9755: }
9756:
9757: sub noninst_users {
9758: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9759: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9760: my $class = 'LC_left_item';
9761: if ($css_class) {
9762: $css_class = ' class="'.$css_class.'"';
9763: }
9764: if ($rowid) {
9765: $rowid = ' id="'.$rowid.'"';
9766: }
9767: if ($rowstyle) {
9768: $rowstyle = ' style="'.$rowstyle.'"';
9769: }
9770: my ($output,$description);
9771: if ($type eq 'default') {
9772: $description = &mt('Requests for: [_1]',$typetitle);
9773: } else {
9774: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9775: }
9776: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9777: "<td>$description</td>\n".
9778: '<td class="'.$class.'" colspan="2">'.
9779: '<table><tr>';
9780: my %headers = &Apache::lonlocal::texthash(
9781: approve => 'Processing',
9782: email => 'E-mail',
9783: username => 'Username',
9784: );
9785: foreach my $item ('approve','email','username') {
9786: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9787: }
1.305 raeburn 9788: $output .= '</tr><tr>';
9789: foreach my $item ('approve','email','username') {
1.306 raeburn 9790: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9791: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9792: if ($item eq 'approve') {
9793: %choices = &Apache::lonlocal::texthash (
9794: automatic => 'Automatically approved',
9795: approval => 'Queued for approval',
9796: );
9797: @options = ('automatic','approval');
9798: $hashref = $processing;
9799: $defoption = 'automatic';
9800: $name = 'cancreate_emailprocess_'.$type;
9801: } elsif ($item eq 'email') {
9802: %choices = &Apache::lonlocal::texthash (
9803: any => 'Any e-mail',
9804: inst => 'Institutional only',
9805: noninst => 'Non-institutional only',
9806: custom => 'Custom restrictions',
9807: );
9808: @options = ('any','inst','noninst');
9809: my $showcustom;
9810: if (ref($emailrules) eq 'HASH') {
9811: if (keys(%{$emailrules}) > 0) {
9812: push(@options,'custom');
9813: $showcustom = 'cancreate_emailrule';
9814: if (ref($settings) eq 'HASH') {
9815: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9816: foreach my $rule (@{$settings->{'email_rule'}}) {
9817: if (exists($emailrules->{$rule})) {
9818: $hascustom ++;
9819: }
9820: }
9821: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9822: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9823: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9824: if (exists($emailrules->{$rule})) {
9825: $hascustom ++;
9826: }
9827: }
9828: }
9829: }
9830: }
9831: }
9832: }
9833: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9834: "'cancreate_emaildomain','$type'".');"';
9835: $hashref = $emailoptions;
9836: $defoption = 'any';
9837: $name = 'cancreate_emailoptions_'.$type;
9838: } elsif ($item eq 'username') {
9839: %choices = &Apache::lonlocal::texthash (
9840: all => 'Same as e-mail',
9841: first => 'Omit @domain',
9842: free => 'Free to choose',
9843: );
9844: @options = ('all','first','free');
9845: $hashref = $emailverified;
9846: $defoption = 'all';
9847: $name = 'cancreate_usernameoptions_'.$type;
9848: }
9849: foreach my $option (@options) {
9850: my $checked;
9851: if (ref($hashref) eq 'HASH') {
9852: if ($type eq '') {
9853: if (!exists($hashref->{'default'})) {
9854: if ($option eq $defoption) {
9855: $checked = ' checked="checked"';
9856: }
9857: } else {
9858: if ($hashref->{'default'} eq $option) {
9859: $checked = ' checked="checked"';
9860: }
1.303 raeburn 9861: }
9862: } else {
1.305 raeburn 9863: if (!exists($hashref->{$type})) {
9864: if ($option eq $defoption) {
9865: $checked = ' checked="checked"';
9866: }
9867: } else {
9868: if ($hashref->{$type} eq $option) {
9869: $checked = ' checked="checked"';
9870: }
1.303 raeburn 9871: }
9872: }
1.305 raeburn 9873: } elsif (($item eq 'email') && ($hascustom)) {
9874: if ($option eq 'custom') {
9875: $checked = ' checked="checked"';
9876: }
9877: } elsif ($option eq $defoption) {
9878: $checked = ' checked="checked"';
9879: }
9880: $output .= '<span class="LC_nobreak"><label>'.
9881: '<input type="radio" name="'.$name.'"'.
9882: $checked.' value="'.$option.'"'.$onclick.' />'.
9883: $choices{$option}.'</label></span><br />';
9884: if ($item eq 'email') {
9885: if ($option eq 'custom') {
9886: my $id = 'cancreate_emailrule_'.$type;
9887: my $display = 'none';
9888: if ($checked) {
9889: $display = 'inline';
1.303 raeburn 9890: }
1.305 raeburn 9891: my $numinrow = 2;
9892: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9893: '<legend>'.&mt('Disallow').'</legend><table>'.
9894: &user_formats_row('email',$settings,$emailrules,
9895: $emailruleorder,$numinrow,'',$type);
9896: '</table></fieldset>';
9897: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9898: my %text = &Apache::lonlocal::texthash (
9899: inst => 'must end:',
9900: noninst => 'cannot end:',
9901: );
9902: my $value;
9903: if (ref($emaildomain) eq 'HASH') {
9904: if (ref($emaildomain->{$type}) eq 'HASH') {
9905: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 9906: }
9907: }
1.305 raeburn 9908: if ($value eq '') {
9909: $value = '@'.$intdom;
9910: }
9911: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9912: my $display = 'none';
9913: if ($checked) {
9914: $display = 'inline';
9915: }
9916: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9917: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9918: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9919: '</div>';
1.303 raeburn 9920: }
9921: }
9922: }
1.305 raeburn 9923: $output .= '</td>'."\n";
1.303 raeburn 9924: }
1.305 raeburn 9925: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 9926: return $output;
9927: }
9928:
1.165 raeburn 9929: sub captcha_choice {
1.305 raeburn 9930: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 9931: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
9932: $vertext,$currver);
1.165 raeburn 9933: my %lt = &captcha_phrases();
9934: $keyentry = 'hidden';
1.354 raeburn 9935: my $colspan=2;
1.165 raeburn 9936: if ($context eq 'cancreate') {
1.224 raeburn 9937: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 9938: } elsif ($context eq 'login') {
9939: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 9940: } elsif ($context eq 'passwords') {
9941: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9942: $colspan=1;
1.165 raeburn 9943: }
9944: if (ref($settings) eq 'HASH') {
9945: if ($settings->{'captcha'}) {
9946: $checked{$settings->{'captcha'}} = ' checked="checked"';
9947: } else {
9948: $checked{'original'} = ' checked="checked"';
9949: }
9950: if ($settings->{'captcha'} eq 'recaptcha') {
9951: $pubtext = $lt{'pub'};
9952: $privtext = $lt{'priv'};
9953: $keyentry = 'text';
1.269 raeburn 9954: $vertext = $lt{'ver'};
9955: $currver = $settings->{'recaptchaversion'};
9956: if ($currver ne '2') {
9957: $currver = 1;
9958: }
1.165 raeburn 9959: }
9960: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9961: $currpub = $settings->{'recaptchakeys'}{'public'};
9962: $currpriv = $settings->{'recaptchakeys'}{'private'};
9963: }
9964: } else {
9965: $checked{'original'} = ' checked="checked"';
9966: }
1.305 raeburn 9967: my $css_class;
9968: if ($itemcount%2) {
9969: $css_class = 'LC_odd_row';
9970: }
9971: if ($customcss) {
9972: $css_class .= " $customcss";
9973: }
9974: $css_class =~ s/^\s+//;
9975: if ($css_class) {
9976: $css_class = ' class="'.$css_class.'"';
9977: }
9978: if ($rowstyle) {
9979: $css_class .= ' style="'.$rowstyle.'"';
9980: }
1.169 raeburn 9981: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 9982: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 9983: '<table><tr><td>'."\n";
9984: foreach my $option ('original','recaptcha','notused') {
9985: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9986: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9987: $lt{$option}.'</label></span>';
9988: unless ($option eq 'notused') {
9989: $output .= (' 'x2)."\n";
9990: }
9991: }
9992: #
9993: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9994: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 9995: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 9996: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 9997: #
1.165 raeburn 9998: $output .= '</td></tr>'."\n".
1.305 raeburn 9999: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10000: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10001: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10002: $currpub.'" size="40" /></span><br />'."\n".
10003: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10004: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10005: $currpriv.'" size="40" /></span><br />'.
10006: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10007: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10008: $currver.'" size="3" /></span><br />'.
10009: '</td></tr></table>'."\n".
1.165 raeburn 10010: '</td></tr>';
10011: return $output;
10012: }
10013:
1.32 raeburn 10014: sub user_formats_row {
1.305 raeburn 10015: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10016: my $output;
10017: my %text = (
10018: 'username' => 'new usernames',
10019: 'id' => 'IDs',
10020: );
1.305 raeburn 10021: unless ($type eq 'email') {
10022: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10023: $output = '<tr '.$css_class.'>'.
10024: '<td><span class="LC_nobreak">'.
10025: &mt("Format rules to check for $text{$type}: ").
10026: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10027: }
1.27 raeburn 10028: my $rem;
10029: if (ref($ruleorder) eq 'ARRAY') {
10030: for (my $i=0; $i<@{$ruleorder}; $i++) {
10031: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10032: my $rem = $i%($numinrow);
10033: if ($rem == 0) {
10034: if ($i > 0) {
10035: $output .= '</tr>';
10036: }
10037: $output .= '<tr>';
10038: }
10039: my $check = ' ';
1.39 raeburn 10040: if (ref($settings) eq 'HASH') {
10041: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10042: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10043: $check = ' checked="checked" ';
10044: }
1.305 raeburn 10045: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10046: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10047: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10048: $check = ' checked="checked" ';
10049: }
10050: }
1.27 raeburn 10051: }
10052: }
1.305 raeburn 10053: my $name = $type.'_rule';
10054: if ($type eq 'email') {
10055: $name .= '_'.$status;
10056: }
1.27 raeburn 10057: $output .= '<td class="LC_left_item">'.
10058: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10059: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10060: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10061: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10062: }
10063: }
10064: $rem = @{$ruleorder}%($numinrow);
10065: }
1.305 raeburn 10066: my $colsleft;
10067: if ($rem) {
10068: $colsleft = $numinrow - $rem;
10069: }
1.27 raeburn 10070: if ($colsleft > 1 ) {
10071: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10072: ' </td>';
10073: } elsif ($colsleft == 1) {
10074: $output .= '<td class="LC_left_item"> </td>';
10075: }
1.305 raeburn 10076: $output .= '</tr></table>';
10077: unless ($type eq 'email') {
10078: $output .= '</td></tr>';
10079: }
1.27 raeburn 10080: return $output;
10081: }
10082:
1.34 raeburn 10083: sub usercreation_types {
10084: my %lt = &Apache::lonlocal::texthash (
10085: author => 'When adding a co-author',
10086: course => 'When adding a user to a course',
1.100 raeburn 10087: requestcrs => 'When requesting a course',
1.34 raeburn 10088: any => 'Any',
10089: official => 'Institutional only ',
10090: unofficial => 'Non-institutional only',
10091: none => 'None',
10092: );
10093: return %lt;
1.48 raeburn 10094: }
1.34 raeburn 10095:
1.224 raeburn 10096: sub selfcreation_types {
10097: my %lt = &Apache::lonlocal::texthash (
10098: selfcreate => 'User creates own account',
10099: any => 'Any',
10100: official => 'Institutional only ',
10101: unofficial => 'Non-institutional only',
10102: email => 'E-mail address',
10103: login => 'Institutional Login',
10104: sso => 'SSO',
10105: );
10106: }
10107:
1.28 raeburn 10108: sub authtype_names {
10109: my %lt = &Apache::lonlocal::texthash(
10110: int => 'Internal',
10111: krb4 => 'Kerberos 4',
10112: krb5 => 'Kerberos 5',
10113: loc => 'Local',
1.325 raeburn 10114: lti => 'LTI',
1.28 raeburn 10115: );
10116: return %lt;
10117: }
10118:
10119: sub context_names {
10120: my %context_title = &Apache::lonlocal::texthash(
10121: author => 'Creating users when an Author',
10122: course => 'Creating users when in a course',
10123: domain => 'Creating users when a Domain Coordinator',
10124: );
10125: return %context_title;
10126: }
10127:
1.33 raeburn 10128: sub print_usermodification {
10129: my ($position,$dom,$settings,$rowtotal) = @_;
10130: my $numinrow = 4;
10131: my ($context,$datatable,$rowcount);
10132: if ($position eq 'top') {
10133: $rowcount = 0;
10134: $context = 'author';
10135: foreach my $role ('ca','aa') {
10136: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10137: $numinrow,$rowcount);
10138: $$rowtotal ++;
10139: $rowcount ++;
10140: }
1.230 raeburn 10141: } elsif ($position eq 'bottom') {
1.33 raeburn 10142: $context = 'course';
10143: $rowcount = 0;
10144: foreach my $role ('st','ep','ta','in','cr') {
10145: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10146: $numinrow,$rowcount);
10147: $$rowtotal ++;
10148: $rowcount ++;
10149: }
10150: }
10151: return $datatable;
10152: }
10153:
1.43 raeburn 10154: sub print_defaults {
1.236 raeburn 10155: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10156: my $rownum = 0;
1.294 raeburn 10157: my ($datatable,$css_class,$titles);
10158: unless ($position eq 'bottom') {
10159: $titles = &defaults_titles($dom);
10160: }
1.236 raeburn 10161: if ($position eq 'top') {
10162: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10163: 'datelocale_def','portal_def');
10164: my %defaults;
10165: if (ref($settings) eq 'HASH') {
10166: %defaults = %{$settings};
1.43 raeburn 10167: } else {
1.236 raeburn 10168: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10169: foreach my $item (@items) {
10170: $defaults{$item} = $domdefaults{$item};
10171: }
1.43 raeburn 10172: }
1.236 raeburn 10173: foreach my $item (@items) {
10174: if ($rownum%2) {
10175: $css_class = '';
10176: } else {
10177: $css_class = ' class="LC_odd_row" ';
10178: }
10179: $datatable .= '<tr'.$css_class.'>'.
10180: '<td><span class="LC_nobreak">'.$titles->{$item}.
10181: '</span></td><td class="LC_right_item" colspan="3">';
10182: if ($item eq 'auth_def') {
1.325 raeburn 10183: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10184: my %shortauth = (
10185: internal => 'int',
10186: krb4 => 'krb4',
10187: krb5 => 'krb5',
1.325 raeburn 10188: localauth => 'loc',
10189: lti => 'lti',
1.236 raeburn 10190: );
10191: my %authnames = &authtype_names();
10192: foreach my $auth (@authtypes) {
10193: my $checked = ' ';
10194: if ($defaults{$item} eq $auth) {
10195: $checked = ' checked="checked" ';
10196: }
10197: $datatable .= '<label><input type="radio" name="'.$item.
10198: '" value="'.$auth.'"'.$checked.'/>'.
10199: $authnames{$shortauth{$auth}}.'</label> ';
10200: }
10201: } elsif ($item eq 'timezone_def') {
10202: my $includeempty = 1;
10203: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10204: } elsif ($item eq 'datelocale_def') {
10205: my $includeempty = 1;
10206: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10207: } elsif ($item eq 'lang_def') {
1.263 raeburn 10208: my $includeempty = 1;
10209: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 10210: } else {
10211: my $size;
10212: if ($item eq 'portal_def') {
10213: $size = ' size="25"';
10214: }
10215: $datatable .= '<input type="text" name="'.$item.'" value="'.
10216: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 10217: }
1.236 raeburn 10218: $datatable .= '</td></tr>';
10219: $rownum ++;
10220: }
1.354 raeburn 10221: } else {
1.294 raeburn 10222: my %defaults;
10223: if (ref($settings) eq 'HASH') {
1.354 raeburn 10224: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10225: my $maxnum = @{$settings->{'inststatusorder'}};
10226: for (my $i=0; $i<$maxnum; $i++) {
10227: $css_class = $rownum%2?' class="LC_odd_row"':'';
10228: my $item = $settings->{'inststatusorder'}->[$i];
10229: my $title = $settings->{'inststatustypes'}->{$item};
10230: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10231: $datatable .= '<tr'.$css_class.'>'.
10232: '<td><span class="LC_nobreak">'.
10233: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10234: for (my $k=0; $k<=$maxnum; $k++) {
10235: my $vpos = $k+1;
10236: my $selstr;
10237: if ($k == $i) {
10238: $selstr = ' selected="selected" ';
10239: }
10240: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10241: }
10242: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10243: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10244: &mt('delete').'</span></td>'.
1.380 raeburn 10245: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10246: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10247: '</span></td></tr>';
10248: }
10249: $css_class = $rownum%2?' class="LC_odd_row"':'';
10250: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10251: $datatable .= '<tr '.$css_class.'>'.
10252: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10253: for (my $k=0; $k<=$maxnum; $k++) {
10254: my $vpos = $k+1;
10255: my $selstr;
10256: if ($k == $maxnum) {
10257: $selstr = ' selected="selected" ';
10258: }
10259: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10260: }
10261: $datatable .= '</select> '.&mt('Internal ID:').
10262: '<input type="text" size="10" name="addinststatus" value="" />'.
10263: ' '.&mt('(new)').
10264: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10265: &mt('Name displayed').':'.
1.354 raeburn 10266: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10267: '</tr>'."\n";
10268: $rownum ++;
1.294 raeburn 10269: }
1.354 raeburn 10270: }
10271: }
10272: $$rowtotal += $rownum;
1.43 raeburn 10273: return $datatable;
10274: }
10275:
1.168 raeburn 10276: sub get_languages_hash {
10277: my %langchoices;
10278: foreach my $id (&Apache::loncommon::languageids()) {
10279: my $code = &Apache::loncommon::supportedlanguagecode($id);
10280: if ($code ne '') {
10281: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10282: }
10283: }
10284: return %langchoices;
10285: }
10286:
1.43 raeburn 10287: sub defaults_titles {
1.141 raeburn 10288: my ($dom) = @_;
1.43 raeburn 10289: my %titles = &Apache::lonlocal::texthash (
10290: 'auth_def' => 'Default authentication type',
10291: 'auth_arg_def' => 'Default authentication argument',
10292: 'lang_def' => 'Default language',
1.54 raeburn 10293: 'timezone_def' => 'Default timezone',
1.68 raeburn 10294: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10295: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 10296: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10297: 'intauth_check' => 'Check bcrypt cost if authenticated',
10298: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10299: );
1.141 raeburn 10300: if ($dom) {
10301: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10302: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10303: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10304: $protocol = 'http' if ($protocol ne 'https');
10305: if ($uint_dom) {
10306: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10307: $uint_dom);
10308: }
10309: }
1.43 raeburn 10310: return (\%titles);
10311: }
10312:
1.346 raeburn 10313: sub print_scantron {
10314: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10315: if ($position eq 'top') {
10316: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10317: } else {
10318: return &print_scantronconfig($dom,$settings,\$rowtotal);
10319: }
10320: }
10321:
10322: sub scantron_javascript {
10323: return <<"ENDSCRIPT";
10324:
10325: <script type="text/javascript">
10326: // <![CDATA[
10327:
10328: function toggleScantron(form) {
1.347 raeburn 10329: var csvfieldset = new Array();
1.346 raeburn 10330: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10331: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10332: }
10333: if (document.getElementById('scantroncsv_options')) {
10334: csvfieldset.push(document.getElementById('scantroncsv_options'));
10335: }
10336: if (csvfieldset.length) {
1.346 raeburn 10337: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10338: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10339: if (scantroncsv.checked) {
1.347 raeburn 10340: for (var i=0; i<csvfieldset.length; i++) {
10341: csvfieldset[i].style.display = 'block';
10342: }
1.346 raeburn 10343: } else {
1.347 raeburn 10344: for (var i=0; i<csvfieldset.length; i++) {
10345: csvfieldset[i].style.display = 'none';
10346: }
1.346 raeburn 10347: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10348: if (csvselects.length) {
10349: for (var j=0; j<csvselects.length; j++) {
10350: csvselects[j].selectedIndex = 0;
10351: }
10352: }
10353: }
10354: }
10355: }
10356: return;
10357: }
10358: // ]]>
10359: </script>
10360:
10361: ENDSCRIPT
10362:
10363: }
10364:
1.46 raeburn 10365: sub print_scantronformat {
10366: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10367: my $itemcount = 1;
1.60 raeburn 10368: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10369: %confhash);
1.46 raeburn 10370: my $switchserver = &check_switchserver($dom,$confname);
10371: my %lt = &Apache::lonlocal::texthash (
1.95 www 10372: default => 'Default bubblesheet format file error',
10373: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10374: );
10375: my %scantronfiles = (
10376: default => 'default.tab',
10377: custom => 'custom.tab',
10378: );
10379: foreach my $key (keys(%scantronfiles)) {
10380: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10381: .$scantronfiles{$key};
10382: }
10383: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10384: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10385: if (!$switchserver) {
10386: my $servadm = $r->dir_config('lonAdmEMail');
10387: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10388: if ($configuserok eq 'ok') {
10389: if ($author_ok eq 'ok') {
10390: my %legacyfile = (
1.346 raeburn 10391: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10392: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10393: );
10394: my %md5chk;
10395: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10396: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10397: chomp($md5chk{$type});
1.46 raeburn 10398: }
10399: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10400: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10401: ($scantronurls{$type},my $error) =
1.46 raeburn 10402: &legacy_scantronformat($r,$dom,$confname,
10403: $type,$legacyfile{$type},
10404: $scantronurls{$type},
10405: $scantronfiles{$type});
1.60 raeburn 10406: if ($error ne '') {
10407: $error{$type} = $error;
10408: }
10409: }
10410: if (keys(%error) == 0) {
10411: $is_custom = 1;
1.346 raeburn 10412: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10413: $scantronurls{'custom'};
1.346 raeburn 10414: my $putresult =
1.60 raeburn 10415: &Apache::lonnet::put_dom('configuration',
10416: \%confhash,$dom);
10417: if ($putresult ne 'ok') {
1.346 raeburn 10418: $error{'custom'} =
1.60 raeburn 10419: '<span class="LC_error">'.
10420: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10421: }
1.46 raeburn 10422: }
10423: } else {
1.60 raeburn 10424: ($scantronurls{'default'},my $error) =
1.46 raeburn 10425: &legacy_scantronformat($r,$dom,$confname,
10426: 'default',$legacyfile{'default'},
10427: $scantronurls{'default'},
10428: $scantronfiles{'default'});
1.60 raeburn 10429: if ($error eq '') {
10430: $confhash{'scantron'}{'scantronformat'} = '';
10431: my $putresult =
10432: &Apache::lonnet::put_dom('configuration',
10433: \%confhash,$dom);
10434: if ($putresult ne 'ok') {
10435: $error{'default'} =
10436: '<span class="LC_error">'.
10437: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10438: }
10439: } else {
10440: $error{'default'} = $error;
10441: }
1.46 raeburn 10442: }
10443: }
10444: }
10445: } else {
1.95 www 10446: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10447: }
10448: }
10449: if (ref($settings) eq 'HASH') {
10450: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10451: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10452: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10453: $scantronurl = '';
10454: } else {
10455: $scantronurl = $settings->{'scantronformat'};
10456: }
10457: $is_custom = 1;
10458: } else {
10459: $scantronurl = $scantronurls{'default'};
10460: }
10461: } else {
1.60 raeburn 10462: if ($is_custom) {
10463: $scantronurl = $scantronurls{'custom'};
10464: } else {
10465: $scantronurl = $scantronurls{'default'};
10466: }
1.46 raeburn 10467: }
10468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10469: $datatable .= '<tr'.$css_class.'>';
10470: if (!$is_custom) {
1.65 raeburn 10471: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10472: '<span class="LC_nobreak">';
1.46 raeburn 10473: if ($scantronurl) {
1.199 raeburn 10474: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10475: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10476: } else {
10477: $datatable = &mt('File unavailable for display');
10478: }
1.65 raeburn 10479: $datatable .= '</span></td>';
1.60 raeburn 10480: if (keys(%error) == 0) {
1.306 raeburn 10481: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10482: if (!$switchserver) {
10483: $datatable .= &mt('Upload:').'<br />';
10484: }
10485: } else {
10486: my $errorstr;
10487: foreach my $key (sort(keys(%error))) {
10488: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10489: }
10490: $datatable .= '<td>'.$errorstr;
10491: }
1.46 raeburn 10492: } else {
10493: if (keys(%error) > 0) {
10494: my $errorstr;
10495: foreach my $key (sort(keys(%error))) {
10496: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10497: }
1.60 raeburn 10498: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10499: } elsif ($scantronurl) {
1.199 raeburn 10500: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10501: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10502: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10503: $link.
10504: '<label><input type="checkbox" name="scantronformat_del"'.
10505: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10506: '<td><span class="LC_nobreak"> '.
10507: &mt('Replace:').'</span><br />';
1.46 raeburn 10508: }
10509: }
10510: if (keys(%error) == 0) {
10511: if ($switchserver) {
10512: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10513: } else {
1.65 raeburn 10514: $datatable .='<span class="LC_nobreak"> '.
10515: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10516: }
10517: }
10518: $datatable .= '</td></tr>';
10519: $$rowtotal ++;
10520: return $datatable;
10521: }
10522:
10523: sub legacy_scantronformat {
10524: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10525: my ($url,$error);
10526: my @statinfo = &Apache::lonnet::stat_file($newurl);
10527: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
10528: (my $result,$url) =
10529: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
10530: '','',$newfile);
10531: if ($result ne 'ok') {
1.130 raeburn 10532: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10533: }
10534: }
10535: return ($url,$error);
10536: }
1.43 raeburn 10537:
1.346 raeburn 10538: sub print_scantronconfig {
10539: my ($dom,$settings,$rowtotal) = @_;
10540: my $itemcount = 2;
10541: my $is_checked = ' checked="checked"';
1.347 raeburn 10542: my %optionson = (
10543: hdr => ' checked="checked"',
10544: pad => ' checked="checked"',
10545: rem => ' checked="checked"',
10546: );
10547: my %optionsoff = (
10548: hdr => '',
10549: pad => '',
10550: rem => '',
10551: );
1.346 raeburn 10552: my $currcsvsty = 'none';
1.347 raeburn 10553: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10554: my @fields = &scantroncsv_fields();
10555: my %titles = &scantronconfig_titles();
10556: if (ref($settings) eq 'HASH') {
10557: if (ref($settings->{config}) eq 'HASH') {
10558: if ($settings->{config}->{dat}) {
10559: $checked{'dat'} = $is_checked;
10560: }
10561: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10562: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10563: %csvfields = %{$settings->{config}->{csv}->{fields}};
10564: if (keys(%csvfields) > 0) {
10565: $checked{'csv'} = $is_checked;
10566: $currcsvsty = 'block';
10567: }
10568: }
10569: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10570: %csvoptions = %{$settings->{config}->{csv}->{options}};
10571: foreach my $option (keys(%optionson)) {
10572: unless ($csvoptions{$option}) {
10573: $optionsoff{$option} = $optionson{$option};
10574: $optionson{$option} = '';
10575: }
10576: }
1.346 raeburn 10577: }
10578: }
10579: } else {
10580: $checked{'dat'} = $is_checked;
10581: }
10582: } else {
10583: $checked{'dat'} = $is_checked;
10584: }
10585: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10586: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10587: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10588: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10589: foreach my $item ('dat','csv') {
10590: my $id;
10591: if ($item eq 'csv') {
10592: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10593: }
1.346 raeburn 10594: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10595: $titles{$item}.'</label>'.(' 'x3);
10596: if ($item eq 'csv') {
10597: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10598: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10599: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10600: foreach my $col (@fields) {
10601: my $selnone;
10602: if ($csvfields{$col} eq '') {
10603: $selnone = ' selected="selected"';
10604: }
10605: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10606: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10607: '<option value=""'.$selnone.'></option>';
10608: for (my $i=0; $i<20; $i++) {
10609: my $shown = $i+1;
10610: my $sel;
10611: unless ($selnone) {
10612: if (exists($csvfields{$col})) {
10613: if ($csvfields{$col} == $i) {
10614: $sel = ' selected="selected"';
10615: }
10616: }
10617: }
10618: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10619: }
10620: $datatable .= '</select></td></tr>';
10621: }
1.347 raeburn 10622: $datatable .= '</table></fieldset>'.
10623: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10624: '<legend>'.&mt('CSV Options').'</legend>';
10625: foreach my $option ('hdr','pad','rem') {
10626: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10627: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10628: &mt('Yes').'</label>'.(' 'x2)."\n".
10629: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10630: }
10631: $datatable .= '</fieldset>';
1.346 raeburn 10632: $itemcount ++;
10633: }
10634: }
10635: $datatable .= '</td></tr>';
10636: $$rowtotal ++;
10637: return $datatable;
10638: }
10639:
10640: sub scantronconfig_titles {
10641: return &Apache::lonlocal::texthash(
10642: dat => 'Standard format (.dat)',
10643: csv => 'Comma separated values (.csv)',
1.347 raeburn 10644: hdr => 'Remove first line in file (contains column titles)',
10645: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10646: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10647: CODE => 'CODE',
10648: ID => 'Student ID',
10649: PaperID => 'Paper ID',
10650: FirstName => 'First Name',
10651: LastName => 'Last Name',
10652: FirstQuestion => 'First Question Response',
10653: Section => 'Section',
10654: );
10655: }
10656:
10657: sub scantroncsv_fields {
10658: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10659: }
10660:
1.49 raeburn 10661: sub print_coursecategories {
1.57 raeburn 10662: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10663: my $datatable;
10664: if ($position eq 'top') {
1.238 raeburn 10665: my (%checked);
10666: my @catitems = ('unauth','auth');
10667: my @cattypes = ('std','domonly','codesrch','none');
10668: $checked{'unauth'} = 'std';
10669: $checked{'auth'} = 'std';
10670: if (ref($settings) eq 'HASH') {
10671: foreach my $type (@cattypes) {
10672: if ($type eq $settings->{'unauth'}) {
10673: $checked{'unauth'} = $type;
10674: }
10675: if ($type eq $settings->{'auth'}) {
10676: $checked{'auth'} = $type;
10677: }
10678: }
10679: }
10680: my %lt = &Apache::lonlocal::texthash (
10681: unauth => 'Catalog type for unauthenticated users',
10682: auth => 'Catalog type for authenticated users',
10683: none => 'No catalog',
10684: std => 'Standard catalog',
10685: domonly => 'Domain-only catalog',
10686: codesrch => "Code search form",
10687: );
10688: my $itemcount = 0;
10689: foreach my $item (@catitems) {
10690: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10691: $datatable .= '<tr '.$css_class.'>'.
10692: '<td>'.$lt{$item}.'</td>'.
10693: '<td class="LC_right_item"><span class="LC_nobreak">';
10694: foreach my $type (@cattypes) {
10695: my $ischecked;
10696: if ($checked{$item} eq $type) {
10697: $ischecked=' checked="checked"';
10698: }
10699: $datatable .= '<label>'.
10700: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10701: ' />'.$lt{$type}.'</label> ';
10702: }
1.327 raeburn 10703: $datatable .= '</span></td></tr>';
1.238 raeburn 10704: $itemcount ++;
10705: }
10706: $$rowtotal += $itemcount;
10707: } elsif ($position eq 'middle') {
1.57 raeburn 10708: my $toggle_cats_crs = ' ';
10709: my $toggle_cats_dom = ' checked="checked" ';
10710: my $can_cat_crs = ' ';
10711: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10712: my $toggle_catscomm_comm = ' ';
10713: my $toggle_catscomm_dom = ' checked="checked" ';
10714: my $can_catcomm_comm = ' ';
10715: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10716: my $toggle_catsplace_place = ' ';
10717: my $toggle_catsplace_dom = ' checked="checked" ';
10718: my $can_catplace_place = ' ';
10719: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10720:
1.57 raeburn 10721: if (ref($settings) eq 'HASH') {
10722: if ($settings->{'togglecats'} eq 'crs') {
10723: $toggle_cats_crs = $toggle_cats_dom;
10724: $toggle_cats_dom = ' ';
10725: }
10726: if ($settings->{'categorize'} eq 'crs') {
10727: $can_cat_crs = $can_cat_dom;
10728: $can_cat_dom = ' ';
10729: }
1.120 raeburn 10730: if ($settings->{'togglecatscomm'} eq 'comm') {
10731: $toggle_catscomm_comm = $toggle_catscomm_dom;
10732: $toggle_catscomm_dom = ' ';
10733: }
10734: if ($settings->{'categorizecomm'} eq 'comm') {
10735: $can_catcomm_comm = $can_catcomm_dom;
10736: $can_catcomm_dom = ' ';
10737: }
1.272 raeburn 10738: if ($settings->{'togglecatsplace'} eq 'place') {
10739: $toggle_catsplace_place = $toggle_catsplace_dom;
10740: $toggle_catsplace_dom = ' ';
10741: }
10742: if ($settings->{'categorizeplace'} eq 'place') {
10743: $can_catplace_place = $can_catplace_dom;
10744: $can_catplace_dom = ' ';
10745: }
1.57 raeburn 10746: }
10747: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10748: togglecats => 'Show/Hide a course in catalog',
10749: togglecatscomm => 'Show/Hide a community in catalog',
10750: togglecatsplace => 'Show/Hide a placement test in catalog',
10751: categorize => 'Assign a category to a course',
10752: categorizecomm => 'Assign a category to a community',
10753: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10754: );
10755: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10756: dom => 'Set in Domain',
10757: crs => 'Set in Course',
10758: comm => 'Set in Community',
10759: place => 'Set in Placement Test',
1.57 raeburn 10760: );
10761: $datatable = '<tr class="LC_odd_row">'.
10762: '<td>'.$title{'togglecats'}.'</td>'.
10763: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10764: '<input type="radio" name="togglecats"'.
10765: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10766: '<label><input type="radio" name="togglecats"'.
10767: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10768: '</tr><tr>'.
10769: '<td>'.$title{'categorize'}.'</td>'.
10770: '<td class="LC_right_item"><span class="LC_nobreak">'.
10771: '<label><input type="radio" name="categorize"'.
10772: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10773: '<label><input type="radio" name="categorize"'.
10774: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10775: '</tr><tr class="LC_odd_row">'.
10776: '<td>'.$title{'togglecatscomm'}.'</td>'.
10777: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10778: '<input type="radio" name="togglecatscomm"'.
10779: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10780: '<label><input type="radio" name="togglecatscomm"'.
10781: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10782: '</tr><tr>'.
10783: '<td>'.$title{'categorizecomm'}.'</td>'.
10784: '<td class="LC_right_item"><span class="LC_nobreak">'.
10785: '<label><input type="radio" name="categorizecomm"'.
10786: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10787: '<label><input type="radio" name="categorizecomm"'.
10788: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10789: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10790: '<td>'.$title{'togglecatsplace'}.'</td>'.
10791: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10792: '<input type="radio" name="togglecatsplace"'.
10793: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10794: '<label><input type="radio" name="togglecatscomm"'.
10795: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
10796: '</tr><tr>'.
10797: '<td>'.$title{'categorizeplace'}.'</td>'.
10798: '<td class="LC_right_item"><span class="LC_nobreak">'.
10799: '<label><input type="radio" name="categorizeplace"'.
10800: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10801: '<label><input type="radio" name="categorizeplace"'.
10802: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 10803: '</tr>';
1.272 raeburn 10804: $$rowtotal += 6;
1.57 raeburn 10805: } else {
10806: my $css_class;
10807: my $itemcount = 1;
10808: my $cathash;
10809: if (ref($settings) eq 'HASH') {
10810: $cathash = $settings->{'cats'};
10811: }
10812: if (ref($cathash) eq 'HASH') {
10813: my (@cats,@trails,%allitems,%idx,@jsarray);
10814: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10815: \%allitems,\%idx,\@jsarray);
10816: my $maxdepth = scalar(@cats);
10817: my $colattrib = '';
10818: if ($maxdepth > 2) {
10819: $colattrib = ' colspan="2" ';
10820: }
10821: my @path;
10822: if (@cats > 0) {
10823: if (ref($cats[0]) eq 'ARRAY') {
10824: my $numtop = @{$cats[0]};
10825: my $maxnum = $numtop;
1.120 raeburn 10826: my %default_names = (
10827: instcode => &mt('Official courses'),
10828: communities => &mt('Communities'),
1.272 raeburn 10829: placement => &mt('Placement Tests'),
1.120 raeburn 10830: );
10831:
10832: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10833: ($cathash->{'instcode::0'} eq '') ||
10834: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 10835: ($cathash->{'communities::0'} eq '') ||
10836: (!grep(/^placement$/,@{$cats[0]})) ||
10837: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 10838: $maxnum ++;
10839: }
10840: my $lastidx;
10841: for (my $i=0; $i<$numtop; $i++) {
10842: my $parent = $cats[0][$i];
10843: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10844: my $item = &escape($parent).'::0';
10845: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10846: $lastidx = $idx{$item};
10847: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10848: .'<select name="'.$item.'"'.$chgstr.'>';
10849: for (my $k=0; $k<=$maxnum; $k++) {
10850: my $vpos = $k+1;
10851: my $selstr;
10852: if ($k == $i) {
10853: $selstr = ' selected="selected" ';
10854: }
10855: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10856: }
1.214 raeburn 10857: $datatable .= '</select></span></td><td>';
1.272 raeburn 10858: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 10859: $datatable .= '<span class="LC_nobreak">'
10860: .$default_names{$parent}.'</span>';
10861: if ($parent eq 'instcode') {
10862: $datatable .= '<br /><span class="LC_nobreak">('
10863: .&mt('with institutional codes')
10864: .')</span></td><td'.$colattrib.'>';
10865: } else {
10866: $datatable .= '<table><tr><td>';
10867: }
10868: $datatable .= '<span class="LC_nobreak">'
10869: .'<label><input type="radio" name="'
10870: .$parent.'" value="1" checked="checked" />'
10871: .&mt('Display').'</label>';
10872: if ($parent eq 'instcode') {
10873: $datatable .= ' ';
10874: } else {
10875: $datatable .= '</span></td></tr><tr><td>'
10876: .'<span class="LC_nobreak">';
10877: }
10878: $datatable .= '<label><input type="radio" name="'
10879: .$parent.'" value="0" />'
10880: .&mt('Do not display').'</label></span>';
1.272 raeburn 10881: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 10882: $datatable .= '</td></tr></table>';
10883: }
10884: $datatable .= '</td>';
1.57 raeburn 10885: } else {
10886: $datatable .= $parent
1.214 raeburn 10887: .' <span class="LC_nobreak"><label>'
10888: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10889: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10890: }
10891: my $depth = 1;
10892: push(@path,$parent);
10893: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10894: pop(@path);
10895: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10896: $itemcount ++;
10897: }
1.48 raeburn 10898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10899: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10900: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10901: for (my $k=0; $k<=$maxnum; $k++) {
10902: my $vpos = $k+1;
10903: my $selstr;
1.57 raeburn 10904: if ($k == $numtop) {
1.48 raeburn 10905: $selstr = ' selected="selected" ';
10906: }
10907: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10908: }
1.59 bisitz 10909: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10910: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10911: .'</tr>'."\n";
1.48 raeburn 10912: $itemcount ++;
1.272 raeburn 10913: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 10914: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10915: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10916: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10917: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10918: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10919: for (my $k=0; $k<=$maxnum; $k++) {
10920: my $vpos = $k+1;
10921: my $selstr;
10922: if ($k == $maxnum) {
10923: $selstr = ' selected="selected" ';
10924: }
10925: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10926: }
1.120 raeburn 10927: $datatable .= '</select></span></td>'.
10928: '<td><span class="LC_nobreak">'.
10929: $default_names{$default}.'</span>';
10930: if ($default eq 'instcode') {
10931: $datatable .= '<br /><span class="LC_nobreak">('
10932: .&mt('with institutional codes').')</span>';
10933: }
10934: $datatable .= '</td>'
10935: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10936: .&mt('Display').'</label> '
10937: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10938: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10939: }
10940: }
10941: }
1.57 raeburn 10942: } else {
10943: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10944: }
10945: } else {
1.327 raeburn 10946: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10947: .&initialize_categories($itemcount);
1.48 raeburn 10948: }
1.57 raeburn 10949: $$rowtotal += $itemcount;
1.48 raeburn 10950: }
10951: return $datatable;
10952: }
10953:
1.69 raeburn 10954: sub print_serverstatuses {
10955: my ($dom,$settings,$rowtotal) = @_;
10956: my $datatable;
10957: my @pages = &serverstatus_pages();
10958: my (%namedaccess,%machineaccess);
10959: foreach my $type (@pages) {
10960: $namedaccess{$type} = '';
10961: $machineaccess{$type}= '';
10962: }
10963: if (ref($settings) eq 'HASH') {
10964: foreach my $type (@pages) {
10965: if (exists($settings->{$type})) {
10966: if (ref($settings->{$type}) eq 'HASH') {
10967: foreach my $key (keys(%{$settings->{$type}})) {
10968: if ($key eq 'namedusers') {
10969: $namedaccess{$type} = $settings->{$type}->{$key};
10970: } elsif ($key eq 'machines') {
10971: $machineaccess{$type} = $settings->{$type}->{$key};
10972: }
10973: }
10974: }
10975: }
10976: }
10977: }
1.81 raeburn 10978: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10979: my $rownum = 0;
10980: my $css_class;
10981: foreach my $type (@pages) {
10982: $rownum ++;
10983: $css_class = $rownum%2?' class="LC_odd_row"':'';
10984: $datatable .= '<tr'.$css_class.'>'.
10985: '<td><span class="LC_nobreak">'.
10986: $titles->{$type}.'</span></td>'.
10987: '<td class="LC_left_item">'.
10988: '<input type="text" name="'.$type.'_namedusers" '.
10989: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10990: '<td class="LC_right_item">'.
10991: '<span class="LC_nobreak">'.
10992: '<input type="text" name="'.$type.'_machines" '.
10993: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 10994: '</span></td></tr>'."\n";
1.69 raeburn 10995: }
10996: $$rowtotal += $rownum;
10997: return $datatable;
10998: }
10999:
11000: sub serverstatus_pages {
11001: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11002: 'checksums','clusterstatus','certstatus','metadata_keywords',
11003: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11004: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11005: }
11006:
1.236 raeburn 11007: sub defaults_javascript {
11008: my ($settings) = @_;
1.354 raeburn 11009: return unless (ref($settings) eq 'HASH');
1.236 raeburn 11010: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11011: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11012: if ($maxnum eq '') {
11013: $maxnum = 0;
11014: }
11015: $maxnum ++;
1.249 raeburn 11016: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11017: return <<"ENDSCRIPT";
11018: <script type="text/javascript">
11019: // <![CDATA[
11020: function reorderTypes(form,caller) {
11021: var changedVal;
11022: $jstext
11023: var newpos = 'addinststatus_pos';
11024: var current = new Array;
11025: var maxh = $maxnum;
11026: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11027: var oldVal;
11028: if (caller == newpos) {
11029: changedVal = newitemVal;
11030: } else {
11031: var curritem = 'inststatus_pos_'+caller;
11032: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11033: current[newitemVal] = newpos;
11034: }
11035: for (var i=0; i<inststatuses.length; i++) {
11036: if (inststatuses[i] != caller) {
11037: var elementName = 'inststatus_pos_'+inststatuses[i];
11038: if (form.elements[elementName]) {
11039: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11040: current[currVal] = elementName;
11041: }
11042: }
11043: }
11044: for (var j=0; j<maxh; j++) {
11045: if (current[j] == undefined) {
11046: oldVal = j;
11047: }
11048: }
11049: if (oldVal < changedVal) {
11050: for (var k=oldVal+1; k<=changedVal ; k++) {
11051: var elementName = current[k];
11052: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11053: }
11054: } else {
11055: for (var k=changedVal; k<oldVal; k++) {
11056: var elementName = current[k];
11057: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11058: }
11059: }
11060: return;
11061: }
11062:
11063: // ]]>
11064: </script>
11065:
11066: ENDSCRIPT
11067: }
1.354 raeburn 11068: return;
11069: }
11070:
11071: sub passwords_javascript {
1.365 raeburn 11072: my %intalert = &Apache::lonlocal::texthash (
11073: 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.',
11074: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11075: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11076: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11077: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11078: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11079: );
11080: &js_escape(\%intalert);
11081: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 11082: my $intauthjs = <<"ENDSCRIPT";
11083:
11084: function warnIntAuth(field) {
11085: if (field.name == 'intauth_check') {
11086: if (field.value == '2') {
1.365 raeburn 11087: alert('$intalert{authcheck}');
1.354 raeburn 11088: }
11089: }
11090: if (field.name == 'intauth_cost') {
11091: field.value.replace(/\s/g,'');
11092: if (field.value != '') {
11093: var regexdigit=/^\\d+\$/;
11094: if (!regexdigit.test(field.value)) {
1.365 raeburn 11095: alert('$intalert{authcost}');
11096: }
11097: }
11098: }
11099: return;
11100: }
11101:
11102: function warnIntPass(field) {
11103: field.value.replace(/^\s+/,'');
11104: field.value.replace(/\s+\$/,'');
11105: var regexdigit=/^\\d+\$/;
11106: if (field.name == 'passwords_min') {
11107: if (field.value == '') {
11108: alert('$intalert{passmin}');
11109: field.value = '$defmin';
11110: } else {
11111: if (!regexdigit.test(field.value)) {
11112: alert('$intalert{passmin}');
11113: field.value = '$defmin';
11114: }
1.366 raeburn 11115: var minval = parseInt(field.value,10);
1.365 raeburn 11116: if (minval < $defmin) {
11117: alert('$intalert{passmin}');
11118: field.value = '$defmin';
11119: }
11120: }
11121: } else {
11122: if (field.value == '0') {
11123: field.value = '';
11124: }
11125: if (field.value != '') {
11126: if (field.name == 'passwords_expire') {
11127: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11128: if (!regexpposnum.test(field.value)) {
11129: alert('$intalert{passexp}');
11130: field.value = '';
11131: } else {
11132: var expval = parseFloat(field.value);
11133: if (expval == 0) {
11134: alert('$intalert{passexp}');
11135: field.value = '';
11136: }
11137: }
11138: } else {
11139: if (!regexdigit.test(field.value)) {
11140: if (field.name == 'passwords_max') {
11141: alert('$intalert{passmax}');
11142: } else {
11143: if (field.name == 'passwords_numsaved') {
11144: alert('$intalert{passnum}');
11145: }
11146: }
1.370 raeburn 11147: field.value = '';
1.365 raeburn 11148: }
1.354 raeburn 11149: }
11150: }
11151: }
11152: return;
11153: }
11154:
11155: ENDSCRIPT
11156: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11157: }
11158:
1.49 raeburn 11159: sub coursecategories_javascript {
11160: my ($settings) = @_;
1.57 raeburn 11161: my ($output,$jstext,$cathash);
1.49 raeburn 11162: if (ref($settings) eq 'HASH') {
1.57 raeburn 11163: $cathash = $settings->{'cats'};
11164: }
11165: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11166: my (@cats,@jsarray,%idx);
1.57 raeburn 11167: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11168: if (@jsarray > 0) {
11169: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11170: for (my $i=0; $i<@jsarray; $i++) {
11171: if (ref($jsarray[$i]) eq 'ARRAY') {
11172: my $catstr = join('","',@{$jsarray[$i]});
11173: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11174: }
11175: }
11176: }
11177: } else {
11178: $jstext = ' var categories = Array(1);'."\n".
11179: ' categories[0] = Array("instcode_pos");'."\n";
11180: }
1.237 bisitz 11181: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11182: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11183: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11184: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11185: &js_escape(\$instcode_reserved);
11186: &js_escape(\$communities_reserved);
1.272 raeburn 11187: &js_escape(\$placement_reserved);
1.265 damieng 11188: &js_escape(\$choose_again);
1.49 raeburn 11189: $output = <<"ENDSCRIPT";
11190: <script type="text/javascript">
1.109 raeburn 11191: // <![CDATA[
1.49 raeburn 11192: function reorderCats(form,parent,item,idx) {
11193: var changedVal;
11194: $jstext
11195: var newpos = 'addcategory_pos';
11196: if (parent == '') {
11197: var has_instcode = 0;
11198: var maxtop = categories[idx].length;
11199: for (var j=0; j<maxtop; j++) {
11200: if (categories[idx][j] == 'instcode::0') {
11201: has_instcode == 1;
11202: }
11203: }
11204: if (has_instcode == 0) {
11205: categories[idx][maxtop] = 'instcode_pos';
11206: }
11207: } else {
11208: newpos += '_'+parent;
11209: }
11210: var maxh = 1 + categories[idx].length;
11211: var current = new Array;
11212: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11213: if (item == newpos) {
11214: changedVal = newitemVal;
11215: } else {
11216: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11217: current[newitemVal] = newpos;
11218: }
11219: for (var i=0; i<categories[idx].length; i++) {
11220: var elementName = categories[idx][i];
11221: if (elementName != item) {
11222: if (form.elements[elementName]) {
11223: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11224: current[currVal] = elementName;
11225: }
11226: }
11227: }
11228: var oldVal;
11229: for (var j=0; j<maxh; j++) {
11230: if (current[j] == undefined) {
11231: oldVal = j;
11232: }
11233: }
11234: if (oldVal < changedVal) {
11235: for (var k=oldVal+1; k<=changedVal ; k++) {
11236: var elementName = current[k];
11237: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11238: }
11239: } else {
11240: for (var k=changedVal; k<oldVal; k++) {
11241: var elementName = current[k];
11242: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11243: }
11244: }
11245: return;
11246: }
1.120 raeburn 11247:
11248: function categoryCheck(form) {
11249: if (form.elements['addcategory_name'].value == 'instcode') {
11250: alert('$instcode_reserved\\n$choose_again');
11251: return false;
11252: }
11253: if (form.elements['addcategory_name'].value == 'communities') {
11254: alert('$communities_reserved\\n$choose_again');
11255: return false;
11256: }
1.272 raeburn 11257: if (form.elements['addcategory_name'].value == 'placement') {
11258: alert('$placement_reserved\\n$choose_again');
11259: return false;
11260: }
1.120 raeburn 11261: return true;
11262: }
11263:
1.109 raeburn 11264: // ]]>
1.49 raeburn 11265: </script>
11266:
11267: ENDSCRIPT
11268: return $output;
11269: }
11270:
1.48 raeburn 11271: sub initialize_categories {
11272: my ($itemcount) = @_;
1.120 raeburn 11273: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11274: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11275: instcode => 'Official courses (with institutional codes)',
11276: communities => 'Communities',
1.272 raeburn 11277: placement => 'Placement Tests',
1.120 raeburn 11278: );
1.328 raeburn 11279: my %selnum = (
11280: instcode => '0',
11281: communities => '1',
11282: placement => '2',
11283: );
11284: my %selected;
1.272 raeburn 11285: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11286: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11287: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11288: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11289: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11290: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11291: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11292: .'<option value="0"'.$selected{'0'}.'>1</option>'
11293: .'<option value="1"'.$selected{'1'}.'>2</option>'
11294: .'<option value="2"'.$selected{'2'}.'>3</option>'
11295: .'<option value="3">4</option></select> '
1.120 raeburn 11296: .$default_names{$default}
11297: .'</span></td><td><span class="LC_nobreak">'
11298: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11299: .&mt('Display').'</label> <label>'
11300: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11301: .'</label></span></td></tr>';
1.120 raeburn 11302: $itemcount ++;
11303: }
1.48 raeburn 11304: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11305: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11306: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11307: .'<select name="addcategory_pos"'.$chgstr.'>'
11308: .'<option value="0">1</option>'
11309: .'<option value="1">2</option>'
1.328 raeburn 11310: .'<option value="2">3</option>'
11311: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11312: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11313: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11314: .'</td></tr>';
1.48 raeburn 11315: return $datatable;
11316: }
11317:
11318: sub build_category_rows {
1.49 raeburn 11319: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11320: my ($text,$name,$item,$chgstr);
1.48 raeburn 11321: if (ref($cats) eq 'ARRAY') {
11322: my $maxdepth = scalar(@{$cats});
11323: if (ref($cats->[$depth]) eq 'HASH') {
11324: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11325: my $numchildren = @{$cats->[$depth]{$parent}};
11326: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11327: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11328: my ($idxnum,$parent_name,$parent_item);
11329: my $higher = $depth - 1;
11330: if ($higher == 0) {
11331: $parent_name = &escape($parent).'::'.$higher;
11332: } else {
11333: if (ref($path) eq 'ARRAY') {
11334: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11335: }
11336: }
11337: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11338: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11339: if ($j < $numchildren) {
1.48 raeburn 11340: $name = $cats->[$depth]{$parent}[$j];
11341: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11342: $idxnum = $idx->{$item};
11343: } else {
11344: $name = $parent_name;
11345: $item = $parent_item;
1.48 raeburn 11346: }
1.49 raeburn 11347: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11348: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11349: for (my $i=0; $i<=$numchildren; $i++) {
11350: my $vpos = $i+1;
11351: my $selstr;
11352: if ($j == $i) {
11353: $selstr = ' selected="selected" ';
11354: }
11355: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11356: }
11357: $text .= '</select> ';
11358: if ($j < $numchildren) {
11359: my $deeper = $depth+1;
11360: $text .= $name.' '
11361: .'<label><input type="checkbox" name="deletecategory" value="'
11362: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11363: if(ref($path) eq 'ARRAY') {
11364: push(@{$path},$name);
1.49 raeburn 11365: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11366: pop(@{$path});
11367: }
11368: } else {
1.330 raeburn 11369: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11370: if ($j == $numchildren) {
11371: $text .= $name;
11372: } else {
11373: $text .= $item;
11374: }
11375: $text .= '" value="" />';
11376: }
11377: $text .= '</td></tr>';
11378: }
11379: $text .= '</table></td>';
11380: } else {
11381: my $higher = $depth-1;
11382: if ($higher == 0) {
11383: $name = &escape($parent).'::'.$higher;
11384: } else {
11385: if (ref($path) eq 'ARRAY') {
11386: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11387: }
11388: }
11389: my $colspan;
11390: if ($parent ne 'instcode') {
11391: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11392: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11393: }
11394: }
11395: }
11396: }
11397: return $text;
11398: }
11399:
1.33 raeburn 11400: sub modifiable_userdata_row {
1.305 raeburn 11401: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11402: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11403: my ($role,$rolename,$statustype);
11404: $role = $item;
1.224 raeburn 11405: if ($context eq 'cancreate') {
1.305 raeburn 11406: if ($item =~ /^(emailusername)_(.+)$/) {
11407: $role = $1;
11408: $statustype = $2;
1.228 raeburn 11409: if (ref($usertypes) eq 'HASH') {
11410: if ($usertypes->{$statustype}) {
11411: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11412: } else {
11413: $rolename = &mt('Data provided by user');
11414: }
11415: }
1.224 raeburn 11416: }
11417: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11418: if (ref($usertypes) eq 'HASH') {
11419: $rolename = $usertypes->{$role};
11420: } else {
11421: $rolename = $role;
11422: }
1.325 raeburn 11423: } elsif ($context eq 'lti') {
11424: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11425: } elsif ($context eq 'privacy') {
11426: $rolename = $itemdesc;
1.33 raeburn 11427: } else {
1.63 raeburn 11428: if ($role eq 'cr') {
11429: $rolename = &mt('Custom role');
11430: } else {
11431: $rolename = &Apache::lonnet::plaintext($role);
11432: }
1.33 raeburn 11433: }
1.224 raeburn 11434: my (@fields,%fieldtitles);
11435: if (ref($fieldsref) eq 'ARRAY') {
11436: @fields = @{$fieldsref};
11437: } else {
11438: @fields = ('lastname','firstname','middlename','generation',
11439: 'permanentemail','id');
11440: }
11441: if ((ref($titlesref) eq 'HASH')) {
11442: %fieldtitles = %{$titlesref};
11443: } else {
11444: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11445: }
1.33 raeburn 11446: my $output;
1.305 raeburn 11447: my $css_class;
11448: if ($rowcount%2) {
11449: $css_class = 'LC_odd_row';
11450: }
11451: if ($customcss) {
11452: $css_class .= " $customcss";
11453: }
11454: $css_class =~ s/^\s+//;
11455: if ($css_class) {
11456: $css_class = ' class="'.$css_class.'"';
11457: }
11458: if ($rowstyle) {
11459: $css_class .= ' style="'.$rowstyle.'"';
11460: }
11461: if ($rowid) {
11462: $rowid = ' id="'.$rowid.'"';
11463: }
11464: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11465: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11466: '<td class="LC_left_item" colspan="2"><table>';
11467: my $rem;
11468: my %checks;
1.325 raeburn 11469: my %current;
1.33 raeburn 11470: if (ref($settings) eq 'HASH') {
1.325 raeburn 11471: my $hashref;
11472: if ($context eq 'lti') {
11473: if (ref($settings) eq 'HASH') {
11474: $hashref = $settings->{'instdata'};
11475: }
1.357 raeburn 11476: } elsif ($context eq 'privacy') {
11477: my ($key,$inner) = split(/_/,$role);
11478: if (ref($settings) eq 'HASH') {
11479: if (ref($settings->{$key}) eq 'HASH') {
11480: $hashref = $settings->{$key}->{$inner};
11481: }
11482: }
1.325 raeburn 11483: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11484: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11485: $hashref = $settings->{'lti_instdata'};
11486: }
11487: if ($role eq 'emailusername') {
11488: if ($statustype) {
11489: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11490: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11491: }
1.325 raeburn 11492: }
11493: }
11494: }
11495: if (ref($hashref) eq 'HASH') {
11496: foreach my $field (@fields) {
11497: if ($hashref->{$field}) {
11498: if ($role eq 'emailusername') {
11499: $checks{$field} = $hashref->{$field};
11500: } else {
11501: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11502: }
11503: }
11504: }
11505: }
11506: }
1.305 raeburn 11507:
11508: my $total = scalar(@fields);
11509: for (my $i=0; $i<$total; $i++) {
11510: $rem = $i%($numinrow);
1.33 raeburn 11511: if ($rem == 0) {
11512: if ($i > 0) {
11513: $output .= '</tr>';
11514: }
11515: $output .= '<tr>';
11516: }
11517: my $check = ' ';
1.228 raeburn 11518: unless ($role eq 'emailusername') {
11519: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11520: $check = $checks{$fields[$i]};
1.357 raeburn 11521: } elsif ($context eq 'privacy') {
11522: if ($role =~ /^priv_(domain|course)$/) {
11523: if (ref($settings) ne 'HASH') {
11524: $check = ' checked="checked" ';
11525: }
11526: } elsif ($role =~ /^priv_(author|community)$/) {
11527: if (ref($settings) ne 'HASH') {
11528: unless ($fields[$i] eq 'id') {
11529: $check = ' checked="checked" ';
11530: }
11531: }
11532: } elsif ($role =~ /^(unpriv|othdom)_/) {
11533: if (ref($settings) ne 'HASH') {
11534: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11535: $check = ' checked="checked" ';
11536: }
11537: }
11538: }
1.325 raeburn 11539: } elsif ($context ne 'lti') {
1.228 raeburn 11540: if ($role eq 'st') {
11541: if (ref($settings) ne 'HASH') {
11542: $check = ' checked="checked" ';
11543: }
1.33 raeburn 11544: }
11545: }
11546: }
11547: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11548: '<span class="LC_nobreak">';
1.325 raeburn 11549: my $prefix = 'canmodify';
1.228 raeburn 11550: if ($role eq 'emailusername') {
11551: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11552: $checks{$fields[$i]} = 'omit';
11553: }
11554: foreach my $option ('required','optional','omit') {
11555: my $checked='';
11556: if ($checks{$fields[$i]} eq $option) {
11557: $checked='checked="checked" ';
11558: }
11559: $output .= '<label>'.
1.325 raeburn 11560: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11561: &mt($option).'</label>'.(' ' x2);
11562: }
11563: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11564: } else {
1.325 raeburn 11565: if ($context eq 'lti') {
11566: $prefix = 'lti';
1.357 raeburn 11567: } elsif ($context eq 'privacy') {
11568: $prefix = 'privacy';
1.325 raeburn 11569: }
1.228 raeburn 11570: $output .= '<label>'.
1.325 raeburn 11571: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11572: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11573: '</label>';
11574: }
11575: $output .= '</span></td>';
1.33 raeburn 11576: }
1.305 raeburn 11577: $rem = $total%$numinrow;
11578: my $colsleft;
11579: if ($rem) {
11580: $colsleft = $numinrow - $rem;
11581: }
11582: if ($colsleft > 1) {
1.33 raeburn 11583: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11584: ' </td>';
11585: } elsif ($colsleft == 1) {
11586: $output .= '<td class="LC_left_item"> </td>';
11587: }
11588: $output .= '</tr></table></td></tr>';
11589: return $output;
11590: }
1.28 raeburn 11591:
1.93 raeburn 11592: sub insttypes_row {
1.305 raeburn 11593: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11594: $customcss,$rowstyle) = @_;
1.93 raeburn 11595: my %lt = &Apache::lonlocal::texthash (
11596: cansearch => 'Users allowed to search',
11597: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11598: lockablenames => 'User preference to lock name',
1.305 raeburn 11599: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11600: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11601: );
11602: my $showdom;
11603: if ($context eq 'cansearch') {
11604: $showdom = ' ('.$dom.')';
11605: }
1.165 raeburn 11606: my $class = 'LC_left_item';
11607: if ($context eq 'statustocreate') {
11608: $class = 'LC_right_item';
11609: }
1.305 raeburn 11610: my $css_class;
11611: if ($$rowtotal%2) {
11612: $css_class = 'LC_odd_row';
11613: }
11614: if ($customcss) {
11615: $css_class .= ' '.$customcss;
11616: }
11617: $css_class =~ s/^\s+//;
11618: if ($css_class) {
11619: $css_class = ' class="'.$css_class.'"';
11620: }
11621: if ($rowstyle) {
11622: $css_class .= ' style="'.$rowstyle.'"';
11623: }
11624: if ($onclick) {
11625: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11626: }
11627: my $output = '<tr'.$css_class.'>'.
11628: '<td>'.$lt{$context}.$showdom.
11629: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11630: my $rem;
11631: if (ref($types) eq 'ARRAY') {
11632: for (my $i=0; $i<@{$types}; $i++) {
11633: if (defined($usertypes->{$types->[$i]})) {
11634: my $rem = $i%($numinrow);
11635: if ($rem == 0) {
11636: if ($i > 0) {
11637: $output .= '</tr>';
11638: }
11639: $output .= '<tr>';
1.23 raeburn 11640: }
1.26 raeburn 11641: my $check = ' ';
1.99 raeburn 11642: if (ref($settings) eq 'HASH') {
11643: if (ref($settings->{$context}) eq 'ARRAY') {
11644: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11645: $check = ' checked="checked" ';
11646: }
1.315 raeburn 11647: } elsif (ref($settings->{$context}) eq 'HASH') {
11648: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11649: $check = ' checked="checked" ';
11650: }
1.99 raeburn 11651: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11652: $check = ' checked="checked" ';
11653: }
1.23 raeburn 11654: }
1.26 raeburn 11655: $output .= '<td class="LC_left_item">'.
11656: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11657: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11658: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11659: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11660: }
11661: }
1.26 raeburn 11662: $rem = @{$types}%($numinrow);
1.23 raeburn 11663: }
11664: my $colsleft = $numinrow - $rem;
1.315 raeburn 11665: if ($context eq 'overrides') {
11666: if ($colsleft > 1) {
11667: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11668: } else {
11669: $output .= '<td class="LC_left_item">';
11670: }
11671: $output .= ' ';
1.23 raeburn 11672: } else {
1.334 raeburn 11673: if ($rem == 0) {
1.315 raeburn 11674: $output .= '<tr>';
11675: }
11676: if ($colsleft > 1) {
11677: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11678: } else {
11679: $output .= '<td class="LC_left_item">';
11680: }
11681: my $defcheck = ' ';
11682: if (ref($settings) eq 'HASH') {
11683: if (ref($settings->{$context}) eq 'ARRAY') {
11684: if (grep(/^default$/,@{$settings->{$context}})) {
11685: $defcheck = ' checked="checked" ';
11686: }
11687: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11688: $defcheck = ' checked="checked" ';
11689: }
1.26 raeburn 11690: }
1.315 raeburn 11691: $output .= '<span class="LC_nobreak"><label>'.
11692: '<input type="checkbox" name="'.$context.'" '.
11693: 'value="default"'.$defcheck.$onclick.' />'.
11694: $othertitle.'</label></span>';
1.23 raeburn 11695: }
1.315 raeburn 11696: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11697: return $output;
1.23 raeburn 11698: }
11699:
11700: sub sorted_searchtitles {
11701: my %searchtitles = &Apache::lonlocal::texthash(
11702: 'uname' => 'username',
11703: 'lastname' => 'last name',
11704: 'lastfirst' => 'last name, first name',
11705: );
11706: my @titleorder = ('uname','lastname','lastfirst');
11707: return (\%searchtitles,\@titleorder);
11708: }
11709:
1.25 raeburn 11710: sub sorted_searchtypes {
11711: my %srchtypes_desc = (
11712: exact => 'is exact match',
11713: contains => 'contains ..',
11714: begins => 'begins with ..',
11715: );
11716: my @srchtypeorder = ('exact','begins','contains');
11717: return (\%srchtypes_desc,\@srchtypeorder);
11718: }
11719:
1.3 raeburn 11720: sub usertype_update_row {
11721: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11722: my $datatable;
11723: my $numinrow = 4;
11724: foreach my $type (@{$types}) {
11725: if (defined($usertypes->{$type})) {
11726: $$rownums ++;
11727: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11728: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11729: '</td><td class="LC_left_item"><table>';
11730: for (my $i=0; $i<@{$fields}; $i++) {
11731: my $rem = $i%($numinrow);
11732: if ($rem == 0) {
11733: if ($i > 0) {
11734: $datatable .= '</tr>';
11735: }
11736: $datatable .= '<tr>';
11737: }
11738: my $check = ' ';
1.39 raeburn 11739: if (ref($settings) eq 'HASH') {
11740: if (ref($settings->{'fields'}) eq 'HASH') {
11741: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11742: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11743: $check = ' checked="checked" ';
11744: }
1.3 raeburn 11745: }
11746: }
11747: }
11748:
11749: if ($i == @{$fields}-1) {
11750: my $colsleft = $numinrow - $rem;
11751: if ($colsleft > 1) {
11752: $datatable .= '<td colspan="'.$colsleft.'">';
11753: } else {
11754: $datatable .= '<td>';
11755: }
11756: } else {
11757: $datatable .= '<td>';
11758: }
1.8 raeburn 11759: $datatable .= '<span class="LC_nobreak"><label>'.
11760: '<input type="checkbox" name="updateable_'.$type.
11761: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11762: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11763: }
11764: $datatable .= '</tr></table></td></tr>';
11765: }
11766: }
11767: return $datatable;
1.1 raeburn 11768: }
11769:
11770: sub modify_login {
1.205 raeburn 11771: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 11772: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 11773: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
11774: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.168 raeburn 11775: %title = ( coursecatalog => 'Display course catalog',
11776: adminmail => 'Display administrator E-mail address',
1.188 raeburn 11777: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 11778: newuser => 'Link for visitors to create a user account',
1.386 raeburn 11779: loginheader => 'Log-in box header',
11780: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 11781: @offon = ('off','on');
1.112 raeburn 11782: if (ref($domconfig{login}) eq 'HASH') {
11783: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11784: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11785: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11786: }
11787: }
1.386 raeburn 11788: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11789: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11790: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11791: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11792: $saml{$lonhost} = 1;
11793: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11794: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11795: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11796: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11797: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
11798: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11799: }
11800: }
11801: }
1.112 raeburn 11802: }
1.9 raeburn 11803: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11804: \%domconfig,\%loginhash);
1.188 raeburn 11805: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11806: foreach my $item (@toggles) {
11807: $loginhash{login}{$item} = $env{'form.'.$item};
11808: }
1.41 raeburn 11809: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11810: if (ref($colchanges{'login'}) eq 'HASH') {
11811: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11812: \%loginhash);
11813: }
1.110 raeburn 11814:
1.149 raeburn 11815: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 11816: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11817: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11818: if (keys(%servers) > 1) {
11819: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11820: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11821: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11822: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11823: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11824: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11825: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11826: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11827: $changes{'loginvia'}{$lonhost} = 1;
11828: } else {
11829: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11830: $changes{'loginvia'}{$lonhost} = 1;
11831: }
11832: } else {
11833: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11834: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11835: $changes{'loginvia'}{$lonhost} = 1;
11836: }
11837: }
11838: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11839: foreach my $item (@loginvia_attribs) {
11840: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11841: }
11842: } else {
11843: foreach my $item (@loginvia_attribs) {
11844: my $new = $env{'form.'.$lonhost.'_'.$item};
11845: if (($item eq 'serverpath') && ($new eq 'custom')) {
11846: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11847: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11848: $new = '/';
11849: }
11850: }
11851: if (($item eq 'custompath') &&
11852: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11853: $new = '';
11854: }
11855: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11856: $changes{'loginvia'}{$lonhost} = 1;
11857: }
11858: if ($item eq 'exempt') {
1.256 raeburn 11859: $new = &check_exempt_addresses($new);
1.128 raeburn 11860: }
11861: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11862: }
11863: }
1.112 raeburn 11864: } else {
1.128 raeburn 11865: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11866: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11867: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11868: foreach my $item (@loginvia_attribs) {
11869: my $new = $env{'form.'.$lonhost.'_'.$item};
11870: if (($item eq 'serverpath') && ($new eq 'custom')) {
11871: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11872: $new = '/';
11873: }
11874: }
11875: if (($item eq 'custompath') &&
11876: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11877: $new = '';
11878: }
11879: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11880: }
1.110 raeburn 11881: }
11882: }
11883: }
11884: }
1.119 raeburn 11885:
1.168 raeburn 11886: my $servadm = $r->dir_config('lonAdmEMail');
11887: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11888: if (ref($domconfig{'login'}) eq 'HASH') {
11889: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11890: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11891: if ($lang eq 'nolang') {
11892: push(@currlangs,$lang);
11893: } elsif (defined($langchoices{$lang})) {
11894: push(@currlangs,$lang);
11895: } else {
11896: next;
11897: }
11898: }
11899: }
11900: }
11901: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11902: if (@currlangs > 0) {
11903: foreach my $lang (@currlangs) {
11904: if (grep(/^\Q$lang\E$/,@delurls)) {
11905: $changes{'helpurl'}{$lang} = 1;
11906: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11907: $changes{'helpurl'}{$lang} = 1;
11908: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11909: push(@newlangs,$lang);
11910: } else {
11911: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11912: }
11913: }
11914: }
11915: unless (grep(/^nolang$/,@currlangs)) {
11916: if ($env{'form.loginhelpurl_nolang.filename'}) {
11917: $changes{'helpurl'}{'nolang'} = 1;
11918: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11919: push(@newlangs,'nolang');
11920: }
11921: }
11922: if ($env{'form.loginhelpurl_add_lang'}) {
11923: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11924: ($env{'form.loginhelpurl_add_file.filename'})) {
11925: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11926: $addedfile = $env{'form.loginhelpurl_add_lang'};
11927: }
11928: }
11929: if ((@newlangs > 0) || ($addedfile)) {
11930: my $error;
11931: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11932: if ($configuserok eq 'ok') {
11933: if ($switchserver) {
11934: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11935: } elsif ($author_ok eq 'ok') {
11936: my @allnew = @newlangs;
11937: if ($addedfile ne '') {
11938: push(@allnew,$addedfile);
11939: }
11940: foreach my $lang (@allnew) {
11941: my $formelem = 'loginhelpurl_'.$lang;
11942: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11943: $formelem = 'loginhelpurl_add_file';
11944: }
11945: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
11946: "help/$lang",'','',$newfile{$lang});
11947: if ($result eq 'ok') {
11948: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11949: $changes{'helpurl'}{$lang} = 1;
11950: } else {
11951: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11952: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 11953: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 11954: (!grep(/^\Q$lang\E$/,@delurls))) {
11955: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11956: }
11957: }
11958: }
11959: } else {
11960: $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);
11961: }
11962: } else {
11963: $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);
11964: }
11965: if ($error) {
11966: &Apache::lonnet::logthis($error);
11967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11968: }
11969: }
1.256 raeburn 11970:
11971: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11972: if (ref($domconfig{'login'}) eq 'HASH') {
11973: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11974: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11975: if ($domservers{$lonhost}) {
11976: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11977: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 11978: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 11979: }
11980: }
11981: }
11982: }
11983: }
11984: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11985: foreach my $lonhost (sort(keys(%domservers))) {
11986: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11987: $changes{'headtag'}{$lonhost} = 1;
11988: } else {
11989: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11990: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11991: }
11992: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11993: push(@newhosts,$lonhost);
11994: } elsif ($currheadtagurls{$lonhost}) {
11995: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11996: if ($currexempt{$lonhost}) {
1.289 raeburn 11997: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 11998: $changes{'headtag'}{$lonhost} = 1;
11999: }
12000: } elsif ($possexempt{$lonhost}) {
12001: $changes{'headtag'}{$lonhost} = 1;
12002: }
12003: if ($possexempt{$lonhost}) {
12004: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12005: }
12006: }
12007: }
12008: }
12009: if (@newhosts) {
12010: my $error;
12011: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12012: if ($configuserok eq 'ok') {
12013: if ($switchserver) {
12014: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12015: } elsif ($author_ok eq 'ok') {
12016: foreach my $lonhost (@newhosts) {
12017: my $formelem = 'loginheadtag_'.$lonhost;
12018: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12019: "login/headtag/$lonhost",'','',
12020: $env{'form.loginheadtag_'.$lonhost.'.filename'});
12021: if ($result eq 'ok') {
12022: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12023: $changes{'headtag'}{$lonhost} = 1;
12024: if ($possexempt{$lonhost}) {
12025: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12026: }
12027: } else {
12028: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12029: $newheadtagurls{$lonhost},$result);
12030: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12031: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12032: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12033: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12034: }
12035: }
12036: }
12037: } else {
12038: $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);
12039: }
12040: } else {
12041: $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);
12042: }
12043: if ($error) {
12044: &Apache::lonnet::logthis($error);
12045: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12046: }
12047: }
1.386 raeburn 12048: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12049: my @newsamlimgs;
12050: foreach my $lonhost (keys(%domservers)) {
12051: if ($env{'form.saml_'.$lonhost}) {
12052: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12053: push(@newsamlimgs,$lonhost);
12054: }
12055: foreach my $item ('text','alt','url','title','notsso') {
12056: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12057: }
12058: if ($saml{$lonhost}) {
12059: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12060: #FIXME Need to obsolete published image
12061: delete($currsaml{$lonhost}{'img'});
12062: $changes{'saml'}{$lonhost} = 1;
12063: }
12064: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12065: $changes{'saml'}{$lonhost} = 1;
12066: }
12067: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12068: $changes{'saml'}{$lonhost} = 1;
12069: }
12070: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12071: $changes{'saml'}{$lonhost} = 1;
12072: }
12073: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12074: $changes{'saml'}{$lonhost} = 1;
12075: }
12076: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12077: $changes{'saml'}{$lonhost} = 1;
12078: }
12079: } else {
12080: $changes{'saml'}{$lonhost} = 1;
12081: }
12082: foreach my $item ('text','alt','url','title','notsso') {
12083: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12084: }
12085: } else {
1.389 raeburn 12086: if ($saml{$lonhost}) {
12087: $changes{'saml'}{$lonhost} = 1;
12088: delete($currsaml{$lonhost});
12089: }
1.386 raeburn 12090: }
12091: }
12092: foreach my $posshost (keys(%currsaml)) {
12093: unless (exists($domservers{$posshost})) {
12094: delete($currsaml{$posshost});
12095: }
12096: }
12097: %{$loginhash{'login'}{'saml'}} = %currsaml;
12098: if (@newsamlimgs) {
12099: my $error;
12100: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12101: if ($configuserok eq 'ok') {
12102: if ($switchserver) {
12103: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12104: } elsif ($author_ok eq 'ok') {
12105: foreach my $lonhost (@newsamlimgs) {
12106: my $formelem = 'saml_img_'.$lonhost;
12107: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
12108: "login/saml/$lonhost",'','',
12109: $env{'form.saml_img_'.$lonhost.'.filename'});
12110: if ($result eq 'ok') {
12111: $currsaml{$lonhost}{'img'} = $imgurl;
12112: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12113: $changes{'saml'}{$lonhost} = 1;
12114: } else {
12115: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12116: $lonhost,$result);
12117: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12118: }
12119: }
12120: } else {
12121: $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);
12122: }
12123: } else {
12124: $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);
12125: }
12126: if ($error) {
12127: &Apache::lonnet::logthis($error);
12128: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12129: }
12130: }
1.169 raeburn 12131: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12132:
12133: my $defaulthelpfile = '/adm/loginproblems.html';
12134: my $defaulttext = &mt('Default in use');
12135:
1.1 raeburn 12136: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12137: $dom);
12138: if ($putresult eq 'ok') {
1.188 raeburn 12139: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12140: my %defaultchecked = (
12141: 'coursecatalog' => 'on',
1.188 raeburn 12142: 'helpdesk' => 'on',
1.42 raeburn 12143: 'adminmail' => 'off',
1.43 raeburn 12144: 'newuser' => 'off',
1.42 raeburn 12145: );
1.55 raeburn 12146: if (ref($domconfig{'login'}) eq 'HASH') {
12147: foreach my $item (@toggles) {
12148: if ($defaultchecked{$item} eq 'on') {
12149: if (($domconfig{'login'}{$item} eq '0') &&
12150: ($env{'form.'.$item} eq '1')) {
12151: $changes{$item} = 1;
12152: } elsif (($domconfig{'login'}{$item} eq '' ||
12153: $domconfig{'login'}{$item} eq '1') &&
12154: ($env{'form.'.$item} eq '0')) {
12155: $changes{$item} = 1;
12156: }
12157: } elsif ($defaultchecked{$item} eq 'off') {
12158: if (($domconfig{'login'}{$item} eq '1') &&
12159: ($env{'form.'.$item} eq '0')) {
12160: $changes{$item} = 1;
12161: } elsif (($domconfig{'login'}{$item} eq '' ||
12162: $domconfig{'login'}{$item} eq '0') &&
12163: ($env{'form.'.$item} eq '1')) {
12164: $changes{$item} = 1;
12165: }
1.42 raeburn 12166: }
12167: }
1.41 raeburn 12168: }
1.6 raeburn 12169: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12170: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12171: if (exists($changes{'saml'})) {
12172: my $hostid_in_use;
12173: my @hosts = &Apache::lonnet::current_machine_ids();
12174: if (@hosts > 1) {
12175: foreach my $hostid (@hosts) {
12176: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12177: $hostid_in_use = $hostid;
12178: last;
12179: }
12180: }
12181: } else {
12182: $hostid_in_use = $r->dir_config('lonHostID');
12183: }
12184: if (($hostid_in_use) &&
12185: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12186: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12187: }
12188: if (ref($lastactref) eq 'HASH') {
12189: if (ref($changes{'saml'}) eq 'HASH') {
12190: my %updates;
12191: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12192: $lastactref->{'samllanding'} = \%updates;
12193: }
12194: }
12195: }
1.212 raeburn 12196: if (ref($lastactref) eq 'HASH') {
12197: $lastactref->{'domainconfig'} = 1;
12198: }
1.1 raeburn 12199: $resulttext = &mt('Changes made:').'<ul>';
12200: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12201: if ($item eq 'loginvia') {
1.112 raeburn 12202: if (ref($changes{$item}) eq 'HASH') {
12203: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12204: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12205: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12206: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12207: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12208: $protocol = 'http' if ($protocol ne 'https');
12209: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12210:
12211: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12212: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12213: } else {
12214: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12215: }
12216: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12217: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12218: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12219: }
12220: $resulttext .= '</li>';
12221: } else {
12222: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12223: }
1.112 raeburn 12224: } else {
1.128 raeburn 12225: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12226: }
12227: }
1.128 raeburn 12228: $resulttext .= '</ul></li>';
1.112 raeburn 12229: }
1.168 raeburn 12230: } elsif ($item eq 'helpurl') {
12231: if (ref($changes{$item}) eq 'HASH') {
12232: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12233: if (grep(/^\Q$lang\E$/,@delurls)) {
12234: my ($chg,$link);
12235: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12236: if ($lang eq 'nolang') {
12237: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12238: } else {
12239: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12240: }
12241: $resulttext .= '<li>'.$chg.'</li>';
12242: } else {
12243: my $chg;
12244: if ($lang eq 'nolang') {
12245: $chg = &mt('custom log-in help file for no preferred language');
12246: } else {
12247: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12248: }
12249: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12250: $loginhash{'login'}{'helpurl'}{$lang}.
12251: '?inhibitmenu=yes',$chg,600,500).
12252: '</li>';
12253: }
12254: }
12255: }
1.256 raeburn 12256: } elsif ($item eq 'headtag') {
12257: if (ref($changes{$item}) eq 'HASH') {
12258: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12259: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12260: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12261: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12262: $resulttext .= '<li><a href="'.
12263: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12264: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12265: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12266: if ($possexempt{$lonhost}) {
12267: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12268: } else {
12269: $resulttext .= &mt('included for any client IP');
12270: }
12271: $resulttext .= '</li>';
12272: }
12273: }
12274: }
1.386 raeburn 12275: } elsif ($item eq 'saml') {
12276: if (ref($changes{$item}) eq 'HASH') {
12277: my %notlt = (
12278: text => 'Text for log-in by SSO',
12279: img => 'SSO button image',
12280: alt => 'Alt text for button image',
12281: url => 'SSO URL',
12282: title => 'Tooltip for SSO link',
12283: notsso => 'Text for non-SSO log-in',
12284: );
12285: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12286: if (ref($currsaml{$lonhost}) eq 'HASH') {
12287: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12288: '<ul>';
12289: foreach my $key ('text','img','alt','url','title','notsso') {
12290: if ($currsaml{$lonhost}{$key} eq '') {
12291: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12292: } else {
12293: my $value = "'$currsaml{$lonhost}{$key}'";
12294: if ($key eq 'img') {
12295: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
12296: }
12297: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12298: $value).'</li>';
12299: }
12300: }
12301: $resulttext .= '</ul></li>';
12302: } else {
12303: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12304: }
12305: }
12306: }
1.169 raeburn 12307: } elsif ($item eq 'captcha') {
12308: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12309: my $chgtxt;
1.169 raeburn 12310: if ($loginhash{'login'}{$item} eq 'notused') {
12311: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12312: } else {
12313: my %captchas = &captcha_phrases();
12314: if ($captchas{$loginhash{'login'}{$item}}) {
12315: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12316: } else {
12317: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12318: }
12319: }
12320: $resulttext .= '<li>'.$chgtxt.'</li>';
12321: }
12322: } elsif ($item eq 'recaptchakeys') {
12323: if (ref($loginhash{'login'}) eq 'HASH') {
12324: my ($privkey,$pubkey);
12325: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12326: $pubkey = $loginhash{'login'}{$item}{'public'};
12327: $privkey = $loginhash{'login'}{$item}{'private'};
12328: }
12329: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12330: if (!$pubkey) {
12331: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12332: } else {
12333: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12334: }
12335: if (!$privkey) {
12336: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12337: } else {
1.251 raeburn 12338: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12339: }
12340: $chgtxt .= '</ul>';
12341: $resulttext .= '<li>'.$chgtxt.'</li>';
12342: }
1.269 raeburn 12343: } elsif ($item eq 'recaptchaversion') {
12344: if (ref($loginhash{'login'}) eq 'HASH') {
12345: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12346: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12347: '</li>';
12348: }
12349: }
1.41 raeburn 12350: } else {
12351: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12352: }
1.1 raeburn 12353: }
1.6 raeburn 12354: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12355: } else {
12356: $resulttext = &mt('No changes made to log-in page settings');
12357: }
12358: } else {
1.11 albertel 12359: $resulttext = '<span class="LC_error">'.
12360: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12361: }
1.6 raeburn 12362: if ($errors) {
1.9 raeburn 12363: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12364: $errors.'</ul>';
12365: }
12366: return $resulttext;
12367: }
12368:
1.256 raeburn 12369: sub check_exempt_addresses {
12370: my ($iplist) = @_;
12371: $iplist =~ s/^\s+//;
12372: $iplist =~ s/\s+$//;
12373: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12374: my (@okips,$new);
12375: foreach my $ip (@poss_ips) {
12376: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12377: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12378: push(@okips,$ip);
12379: }
12380: }
12381: }
12382: if (@okips > 0) {
12383: $new = join(',',@okips);
12384: } else {
12385: $new = '';
12386: }
12387: return $new;
12388: }
12389:
1.6 raeburn 12390: sub color_font_choices {
12391: my %choices =
12392: &Apache::lonlocal::texthash (
12393: img => "Header",
12394: bgs => "Background colors",
12395: links => "Link colors",
1.55 raeburn 12396: images => "Images",
1.6 raeburn 12397: font => "Font color",
1.201 raeburn 12398: fontmenu => "Font menu",
1.76 raeburn 12399: pgbg => "Page",
1.6 raeburn 12400: tabbg => "Header",
12401: sidebg => "Border",
12402: link => "Link",
12403: alink => "Active link",
12404: vlink => "Visited link",
12405: );
12406: return %choices;
12407: }
12408:
1.394 raeburn 12409: sub modify_ipaccess {
12410: my ($dom,$lastactref,%domconfig) = @_;
12411: my (@allpos,%changes,%confhash,$errors,$resulttext);
12412: my (@items,%deletions,%itemids,@warnings);
12413: my ($typeorder,$types) = &commblocktype_text();
12414: if ($env{'form.ipaccess_add'}) {
12415: my $name = $env{'form.ipaccess_name_add'};
12416: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12417: if ($newid) {
12418: $itemids{'add'} = $newid;
12419: push(@items,'add');
12420: $changes{$newid} = 1;
12421: } else {
12422: $error = &mt('Failed to acquire unique ID for new IP access control item');
12423: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12424: }
12425: }
12426: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12427: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12428: if (@todelete) {
12429: map { $deletions{$_} = 1; } @todelete;
12430: }
12431: my $maxnum = $env{'form.ipaccess_maxnum'};
12432: for (my $i=0; $i<$maxnum; $i++) {
12433: my $itemid = $env{'form.ipaccess_id_'.$i};
12434: $itemid =~ s/\D+//g;
12435: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12436: if ($deletions{$itemid}) {
12437: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12438: } else {
12439: push(@items,$i);
12440: $itemids{$i} = $itemid;
12441: }
12442: }
12443: }
12444: }
12445: foreach my $idx (@items) {
12446: my $itemid = $itemids{$idx};
12447: next unless ($itemid);
12448: my %current;
12449: unless ($idx eq 'add') {
12450: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12451: %current = %{$domconfig{'ipaccess'}{$itemid}};
12452: }
12453: }
12454: my $position = $env{'form.ipaccess_pos_'.$itemid};
12455: $position =~ s/\D+//g;
12456: if ($position ne '') {
12457: $allpos[$position] = $itemid;
12458: }
12459: my $name = $env{'form.ipaccess_name_'.$idx};
12460: $name =~ s/^\s+|\s+$//g;
12461: $confhash{$itemid}{'name'} = $name;
12462: my $possrange = $env{'form.ipaccess_range_'.$idx};
12463: $possrange =~ s/^\s+|\s+$//g;
12464: unless ($possrange eq '') {
12465: $possrange =~ s/[\r\n]+/\s/g;
12466: $possrange =~ s/\s*-\s*/-/g;
12467: $possrange =~ s/\s+/,/g;
12468: $possrange =~ s/,+/,/g;
12469: if ($possrange ne '') {
12470: my (@ok,$count);
12471: $count = 0;
12472: foreach my $poss (split(/\,/,$possrange)) {
12473: $count ++;
12474: $poss = &validate_ip_pattern($poss);
12475: if ($poss ne '') {
12476: push(@ok,$poss);
12477: }
12478: }
12479: my $diff = $count - scalar(@ok);
12480: if ($diff) {
12481: $errors .= '<li><span class="LC_error">'.
12482: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12483: $diff,$name).
12484: '</span></li>';
12485: }
12486: if (@ok) {
12487: my @cidr_list;
12488: foreach my $item (@ok) {
12489: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
12490: }
12491: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
12492: }
12493: }
12494: }
12495: foreach my $field ('name','ip') {
12496: unless (($idx eq 'add') || ($changes{$itemid})) {
12497: if ($current{$field} ne $confhash{$itemid}{$field}) {
12498: $changes{$itemid} = 1;
12499: last;
12500: }
12501: }
12502: }
12503: $confhash{$itemid}{'commblocks'} = {};
12504:
12505: my %commblocks;
12506: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
12507: foreach my $type (@{$typeorder}) {
12508: if ($commblocks{$type}) {
12509: $confhash{$itemid}{'commblocks'}{$type} = 'on';
12510: }
12511: unless (($idx eq 'add') || ($changes{$itemid})) {
12512: if (ref($current{'commblocks'}) eq 'HASH') {
12513: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
12514: $changes{$itemid} = 1;
12515: }
12516: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
12517: $changes{$itemid} = 1;
12518: }
12519: }
12520: }
12521: $confhash{$itemid}{'courses'} = {};
12522: my %crsdeletions;
12523: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
12524: if (@delcrs) {
12525: map { $crsdeletions{$_} = 1; } @delcrs;
12526: }
12527: if (ref($current{'courses'}) eq 'HASH') {
12528: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
12529: if ($crsdeletions{$cid}) {
12530: $changes{$itemid} = 1;
12531: } else {
12532: $confhash{$itemid}{'courses'}{$cid} = 1;
12533: }
12534: }
12535: }
12536: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
12537: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
12538: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
12539: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
12540: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
12541: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
12542: $errors .= '<li><span class="LC_error">'.
12543: &mt('Invalid courseID [_1] omitted from list of allowed courses',
12544: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
12545: '</span></li>';
12546: } else {
12547: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
12548: $changes{$itemid} = 1;
12549: }
12550: }
12551: }
12552: if (@allpos > 0) {
12553: my $idx = 0;
12554: foreach my $itemid (@allpos) {
12555: if ($itemid ne '') {
12556: $confhash{$itemid}{'order'} = $idx;
12557: unless ($changes{$itemid}) {
12558: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12559: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12560: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
12561: $changes{$itemid} = 1;
12562: }
12563: }
12564: }
12565: }
12566: $idx ++;
12567: }
12568: }
12569: }
12570: if (keys(%changes)) {
12571: my %defaultshash = (
12572: ipaccess => \%confhash,
12573: );
12574: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12575: $dom);
12576: if ($putresult eq 'ok') {
12577: my $cachetime = 1800;
12578: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
12579: if (ref($lastactref) eq 'HASH') {
12580: $lastactref->{'ipaccess'} = 1;
12581: }
12582: $resulttext = &mt('Changes made:').'<ul>';
12583: my %bynum;
12584: foreach my $itemid (sort(keys(%changes))) {
12585: if (ref($confhash{$itemid}) eq 'HASH') {
12586: my $position = $confhash{$itemid}{'order'};
12587: if ($position =~ /^\d+$/) {
12588: $bynum{$position} = $itemid;
12589: }
12590: }
12591: }
12592: if (keys(%deletions)) {
12593: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
12594: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12595: }
12596: }
12597: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12598: my $itemid = $bynum{$pos};
12599: if (ref($confhash{$itemid}) eq 'HASH') {
12600: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
12601: my $position = $pos + 1;
12602: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12603: if ($confhash{$itemid}{'ip'} eq '') {
12604: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
12605: } else {
12606: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
12607: }
12608: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
12609: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
12610: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
12611: '</li>';
12612: } else {
12613: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
12614: }
12615: if (keys(%{$confhash{$itemid}{'courses'}})) {
12616: my @courses;
12617: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
12618: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
12619: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12620: }
12621: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12622: join('</li><li>',@courses).'</li></ul>';
12623: } else {
12624: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12625: }
1.395 raeburn 12626: $resulttext .= '</ul></li>';
1.394 raeburn 12627: }
12628: }
1.395 raeburn 12629: $resulttext .= '</ul>';
1.394 raeburn 12630: } else {
12631: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12632: }
12633: } else {
12634: $resulttext = &mt('No changes made');
12635: }
12636: if ($errors) {
12637: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12638: $errors.'</ul></p>';
12639: }
12640: return $resulttext;
12641: }
12642:
12643: sub get_ipaccess_id {
12644: my ($domain,$location) = @_;
12645: # get lock on ipaccess db
12646: my $lockhash = {
12647: lock => $env{'user.name'}.
12648: ':'.$env{'user.domain'},
12649: };
12650: my $tries = 0;
12651: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12652: my ($id,$error);
12653:
12654: while (($gotlock ne 'ok') && ($tries<10)) {
12655: $tries ++;
12656: sleep (0.1);
12657: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12658: }
12659: if ($gotlock eq 'ok') {
12660: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12661: if ($currids{'lock'}) {
12662: delete($currids{'lock'});
12663: if (keys(%currids)) {
12664: my @curr = sort { $a <=> $b } keys(%currids);
12665: if ($curr[-1] =~ /^\d+$/) {
12666: $id = 1 + $curr[-1];
12667: }
12668: } else {
12669: $id = 1;
12670: }
12671: if ($id) {
12672: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12673: $error = 'nostore';
12674: }
12675: } else {
12676: $error = 'nonumber';
12677: }
12678: }
12679: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12680: } else {
12681: $error = 'nolock';
12682: }
12683: return ($id,$error);
12684: }
12685:
1.6 raeburn 12686: sub modify_rolecolors {
1.205 raeburn 12687: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12688: my ($resulttext,%rolehash);
12689: $rolehash{'rolecolors'} = {};
1.55 raeburn 12690: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12691: if ($domconfig{'rolecolors'} eq '') {
12692: $domconfig{'rolecolors'} = {};
12693: }
12694: }
1.9 raeburn 12695: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12696: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12697: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12698: $dom);
12699: if ($putresult eq 'ok') {
12700: if (keys(%changes) > 0) {
1.41 raeburn 12701: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12702: if (ref($lastactref) eq 'HASH') {
12703: $lastactref->{'domainconfig'} = 1;
12704: }
1.6 raeburn 12705: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12706: $rolehash{'rolecolors'});
12707: } else {
12708: $resulttext = &mt('No changes made to default color schemes');
12709: }
12710: } else {
1.11 albertel 12711: $resulttext = '<span class="LC_error">'.
12712: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12713: }
12714: if ($errors) {
12715: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12716: $errors.'</ul>';
12717: }
12718: return $resulttext;
12719: }
12720:
12721: sub modify_colors {
1.9 raeburn 12722: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12723: my (%changes,%choices);
1.51 raeburn 12724: my @bgs;
1.6 raeburn 12725: my @links = ('link','alink','vlink');
1.41 raeburn 12726: my @logintext;
1.6 raeburn 12727: my @images;
12728: my $servadm = $r->dir_config('lonAdmEMail');
12729: my $errors;
1.200 raeburn 12730: my %defaults;
1.6 raeburn 12731: foreach my $role (@{$roles}) {
12732: if ($role eq 'login') {
1.12 raeburn 12733: %choices = &login_choices();
1.41 raeburn 12734: @logintext = ('textcol','bgcol');
1.12 raeburn 12735: } else {
12736: %choices = &color_font_choices();
12737: }
12738: if ($role eq 'login') {
1.41 raeburn 12739: @images = ('img','logo','domlogo','login');
1.51 raeburn 12740: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12741: } else {
12742: @images = ('img');
1.200 raeburn 12743: @bgs = ('pgbg','tabbg','sidebg');
12744: }
12745: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12746: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12747: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12748: }
12749: if ($role eq 'login') {
12750: foreach my $item (@logintext) {
1.234 raeburn 12751: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12752: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12753: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12754: }
12755: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 12756: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12757: }
12758: }
12759: } else {
1.234 raeburn 12760: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12761: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12762: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12763: }
12764: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 12765: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12766: }
1.6 raeburn 12767: }
1.200 raeburn 12768: foreach my $item (@bgs) {
1.234 raeburn 12769: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12770: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12771: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12772: }
12773: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 12774: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12775: }
12776: }
12777: foreach my $item (@links) {
1.234 raeburn 12778: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12779: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12780: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12781: }
12782: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 12783: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12784: }
1.6 raeburn 12785: }
1.46 raeburn 12786: my ($configuserok,$author_ok,$switchserver) =
12787: &config_check($dom,$confname,$servadm);
1.9 raeburn 12788: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12789: if (ref($domconfig->{$role}) ne 'HASH') {
12790: $domconfig->{$role} = {};
12791: }
1.8 raeburn 12792: foreach my $img (@images) {
1.70 raeburn 12793: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
12794: if (defined($env{'form.login_showlogo_'.$img})) {
12795: $confhash->{$role}{'showlogo'}{$img} = 1;
12796: } else {
12797: $confhash->{$role}{'showlogo'}{$img} = 0;
12798: }
12799: }
1.18 albertel 12800: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12801: && !defined($domconfig->{$role}{$img})
12802: && !$env{'form.'.$role.'_del_'.$img}
12803: && $env{'form.'.$role.'_import_'.$img}) {
12804: # import the old configured image from the .tab setting
12805: # if they haven't provided a new one
12806: $domconfig->{$role}{$img} =
12807: $env{'form.'.$role.'_import_'.$img};
12808: }
1.6 raeburn 12809: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12810: my $error;
1.6 raeburn 12811: if ($configuserok eq 'ok') {
1.9 raeburn 12812: if ($switchserver) {
1.12 raeburn 12813: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12814: } else {
12815: if ($author_ok eq 'ok') {
12816: my ($result,$logourl) =
12817: &publishlogo($r,'upload',$role.'_'.$img,
12818: $dom,$confname,$img,$width,$height);
12819: if ($result eq 'ok') {
12820: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12821: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12822: } else {
1.12 raeburn 12823: $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 12824: }
12825: } else {
1.46 raeburn 12826: $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 12827: }
12828: }
12829: } else {
1.46 raeburn 12830: $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 12831: }
12832: if ($error) {
1.8 raeburn 12833: &Apache::lonnet::logthis($error);
1.11 albertel 12834: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12835: }
12836: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12837: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12838: my $error;
12839: if ($configuserok eq 'ok') {
12840: # is confname an author?
12841: if ($switchserver eq '') {
12842: if ($author_ok eq 'ok') {
12843: my ($result,$logourl) =
12844: &publishlogo($r,'copy',$domconfig->{$role}{$img},
12845: $dom,$confname,$img,$width,$height);
12846: if ($result eq 'ok') {
12847: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12848: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 12849: }
12850: }
12851: }
12852: }
1.6 raeburn 12853: }
12854: }
12855: }
12856: if (ref($domconfig) eq 'HASH') {
12857: if (ref($domconfig->{$role}) eq 'HASH') {
12858: foreach my $img (@images) {
12859: if ($domconfig->{$role}{$img} ne '') {
12860: if ($env{'form.'.$role.'_del_'.$img}) {
12861: $confhash->{$role}{$img} = '';
1.12 raeburn 12862: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12863: } else {
1.9 raeburn 12864: if ($confhash->{$role}{$img} eq '') {
12865: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12866: }
1.6 raeburn 12867: }
12868: } else {
12869: if ($env{'form.'.$role.'_del_'.$img}) {
12870: $confhash->{$role}{$img} = '';
1.12 raeburn 12871: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12872: }
12873: }
1.70 raeburn 12874: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
12875: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12876: if ($confhash->{$role}{'showlogo'}{$img} ne
12877: $domconfig->{$role}{'showlogo'}{$img}) {
12878: $changes{$role}{'showlogo'}{$img} = 1;
12879: }
12880: } else {
12881: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12882: $changes{$role}{'showlogo'}{$img} = 1;
12883: }
12884: }
12885: }
12886: }
1.6 raeburn 12887: if ($domconfig->{$role}{'font'} ne '') {
12888: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12889: $changes{$role}{'font'} = 1;
12890: }
12891: } else {
12892: if ($confhash->{$role}{'font'}) {
12893: $changes{$role}{'font'} = 1;
12894: }
12895: }
1.107 raeburn 12896: if ($role ne 'login') {
12897: if ($domconfig->{$role}{'fontmenu'} ne '') {
12898: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12899: $changes{$role}{'fontmenu'} = 1;
12900: }
12901: } else {
12902: if ($confhash->{$role}{'fontmenu'}) {
12903: $changes{$role}{'fontmenu'} = 1;
12904: }
1.97 tempelho 12905: }
12906: }
1.6 raeburn 12907: foreach my $item (@bgs) {
12908: if ($domconfig->{$role}{$item} ne '') {
12909: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12910: $changes{$role}{'bgs'}{$item} = 1;
12911: }
12912: } else {
12913: if ($confhash->{$role}{$item}) {
12914: $changes{$role}{'bgs'}{$item} = 1;
12915: }
12916: }
12917: }
12918: foreach my $item (@links) {
12919: if ($domconfig->{$role}{$item} ne '') {
12920: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12921: $changes{$role}{'links'}{$item} = 1;
12922: }
12923: } else {
12924: if ($confhash->{$role}{$item}) {
12925: $changes{$role}{'links'}{$item} = 1;
12926: }
12927: }
12928: }
1.41 raeburn 12929: foreach my $item (@logintext) {
12930: if ($domconfig->{$role}{$item} ne '') {
12931: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12932: $changes{$role}{'logintext'}{$item} = 1;
12933: }
12934: } else {
12935: if ($confhash->{$role}{$item}) {
12936: $changes{$role}{'logintext'}{$item} = 1;
12937: }
12938: }
12939: }
1.6 raeburn 12940: } else {
12941: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12942: \@logintext,$confhash,\%changes);
1.6 raeburn 12943: }
12944: } else {
12945: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12946: \@logintext,$confhash,\%changes);
1.6 raeburn 12947: }
12948: }
12949: return ($errors,%changes);
12950: }
12951:
1.46 raeburn 12952: sub config_check {
12953: my ($dom,$confname,$servadm) = @_;
12954: my ($configuserok,$author_ok,$switchserver,%currroles);
12955: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12956: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12957: $confname,$servadm);
12958: if ($configuserok eq 'ok') {
12959: $switchserver = &check_switchserver($dom,$confname);
12960: if ($switchserver eq '') {
12961: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12962: }
12963: }
12964: return ($configuserok,$author_ok,$switchserver);
12965: }
12966:
1.6 raeburn 12967: sub default_change_checker {
1.41 raeburn 12968: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12969: foreach my $item (@{$links}) {
12970: if ($confhash->{$role}{$item}) {
12971: $changes->{$role}{'links'}{$item} = 1;
12972: }
12973: }
12974: foreach my $item (@{$bgs}) {
12975: if ($confhash->{$role}{$item}) {
12976: $changes->{$role}{'bgs'}{$item} = 1;
12977: }
12978: }
1.41 raeburn 12979: foreach my $item (@{$logintext}) {
12980: if ($confhash->{$role}{$item}) {
12981: $changes->{$role}{'logintext'}{$item} = 1;
12982: }
12983: }
1.6 raeburn 12984: foreach my $img (@{$images}) {
12985: if ($env{'form.'.$role.'_del_'.$img}) {
12986: $confhash->{$role}{$img} = '';
1.12 raeburn 12987: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12988: }
1.70 raeburn 12989: if ($role eq 'login') {
12990: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12991: $changes->{$role}{'showlogo'}{$img} = 1;
12992: }
12993: }
1.6 raeburn 12994: }
12995: if ($confhash->{$role}{'font'}) {
12996: $changes->{$role}{'font'} = 1;
12997: }
1.48 raeburn 12998: }
1.6 raeburn 12999:
13000: sub display_colorchgs {
13001: my ($dom,$changes,$roles,$confhash) = @_;
13002: my (%choices,$resulttext);
13003: if (!grep(/^login$/,@{$roles})) {
13004: $resulttext = &mt('Changes made:').'<br />';
13005: }
13006: foreach my $role (@{$roles}) {
13007: if ($role eq 'login') {
13008: %choices = &login_choices();
13009: } else {
13010: %choices = &color_font_choices();
13011: }
13012: if (ref($changes->{$role}) eq 'HASH') {
13013: if ($role ne 'login') {
13014: $resulttext .= '<h4>'.&mt($role).'</h4>';
13015: }
13016: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13017: if ($role ne 'login') {
13018: $resulttext .= '<ul>';
13019: }
13020: if (ref($changes->{$role}{$key}) eq 'HASH') {
13021: if ($role ne 'login') {
13022: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13023: }
13024: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13025: if (($role eq 'login') && ($key eq 'showlogo')) {
13026: if ($confhash->{$role}{$key}{$item}) {
13027: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13028: } else {
13029: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13030: }
13031: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13032: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13033: } else {
1.12 raeburn 13034: my $newitem = $confhash->{$role}{$item};
13035: if ($key eq 'images') {
1.306 raeburn 13036: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13037: }
13038: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13039: }
13040: }
13041: if ($role ne 'login') {
13042: $resulttext .= '</ul></li>';
13043: }
13044: } else {
13045: if ($confhash->{$role}{$key} eq '') {
13046: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13047: } else {
13048: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13049: }
13050: }
13051: if ($role ne 'login') {
13052: $resulttext .= '</ul>';
13053: }
13054: }
13055: }
13056: }
1.3 raeburn 13057: return $resulttext;
1.1 raeburn 13058: }
13059:
1.9 raeburn 13060: sub thumb_dimensions {
13061: return ('200','50');
13062: }
13063:
1.16 raeburn 13064: sub check_dimensions {
13065: my ($inputfile) = @_;
13066: my ($fullwidth,$fullheight);
13067: if ($inputfile =~ m|^[/\w.\-]+$|) {
13068: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13069: my $imageinfo = <PIPE>;
13070: if (!close(PIPE)) {
13071: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13072: }
13073: chomp($imageinfo);
13074: my ($fullsize) =
1.21 raeburn 13075: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13076: if ($fullsize) {
13077: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13078: }
13079: }
13080: }
13081: return ($fullwidth,$fullheight);
13082: }
13083:
1.9 raeburn 13084: sub check_configuser {
13085: my ($uhome,$dom,$confname,$servadm) = @_;
13086: my ($configuserok,%currroles);
13087: if ($uhome eq 'no_host') {
13088: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13089: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13090: $configuserok =
13091: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13092: $configpass,'','','','','',undef,$servadm);
13093: } else {
13094: $configuserok = 'ok';
13095: %currroles =
13096: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13097: }
13098: return ($configuserok,%currroles);
13099: }
13100:
13101: sub check_authorstatus {
13102: my ($dom,$confname,%currroles) = @_;
13103: my $author_ok;
1.40 raeburn 13104: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13105: my $start = time;
13106: my $end = 0;
13107: $author_ok =
13108: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13109: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13110: } else {
13111: $author_ok = 'ok';
13112: }
13113: return $author_ok;
13114: }
13115:
13116: sub publishlogo {
1.46 raeburn 13117: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 13118: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 13119: if ($action eq 'upload') {
13120: $fname=$env{'form.'.$formname.'.filename'};
13121: chop($env{'form.'.$formname});
13122: } else {
13123: ($fname) = ($formname =~ /([^\/]+)$/);
13124: }
1.46 raeburn 13125: if ($savefileas ne '') {
13126: $fname = $savefileas;
13127: }
1.9 raeburn 13128: $fname=&Apache::lonnet::clean_filename($fname);
13129: # See if there is anything left
13130: unless ($fname) { return ('error: no uploaded file'); }
13131: $fname="$subdir/$fname";
1.210 raeburn 13132: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 13133: my $filepath="$docroot/priv";
13134: my $relpath = "$dom/$confname";
1.9 raeburn 13135: my ($fnamepath,$file,$fetchthumb);
13136: $file=$fname;
13137: if ($fname=~m|/|) {
13138: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
13139: }
1.164 raeburn 13140: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 13141: my $count;
1.164 raeburn 13142: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 13143: $filepath.="/$parts[$count]";
13144: if ((-e $filepath)!=1) {
13145: mkdir($filepath,02770);
13146: }
13147: }
13148: # Check for bad extension and disallow upload
13149: if ($file=~/\.(\w+)$/ &&
13150: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
13151: $output =
1.207 bisitz 13152: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 13153: } elsif ($file=~/\.(\w+)$/ &&
13154: !defined(&Apache::loncommon::fileembstyle($1))) {
13155: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
13156: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 13157: $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 13158: } elsif (-d "$filepath/$file") {
1.195 bisitz 13159: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 13160: } else {
13161: my $source = $filepath.'/'.$file;
13162: my $logfile;
1.316 raeburn 13163: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 13164: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 13165: }
13166: print $logfile
13167: "\n================= Publish ".localtime()." ================\n".
13168: $env{'user.name'}.':'.$env{'user.domain'}."\n";
13169: # Save the file
1.316 raeburn 13170: if (!open(FH,">",$source)) {
1.9 raeburn 13171: &Apache::lonnet::logthis('Failed to create '.$source);
13172: return (&mt('Failed to create file'));
13173: }
13174: if ($action eq 'upload') {
13175: if (!print FH ($env{'form.'.$formname})) {
13176: &Apache::lonnet::logthis('Failed to write to '.$source);
13177: return (&mt('Failed to write file'));
13178: }
13179: } else {
13180: my $original = &Apache::lonnet::filelocation('',$formname);
13181: if(!copy($original,$source)) {
13182: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
13183: return (&mt('Failed to write file'));
13184: }
13185: }
13186: close(FH);
13187: chmod(0660, $source); # Permissions to rw-rw---.
13188:
13189: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
13190: my $copyfile=$targetdir.'/'.$file;
13191:
13192: my @parts=split(/\//,$targetdir);
13193: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
13194: for (my $count=5;$count<=$#parts;$count++) {
13195: $path.="/$parts[$count]";
13196: if (!-e $path) {
13197: print $logfile "\nCreating directory ".$path;
13198: mkdir($path,02770);
13199: }
13200: }
13201: my $versionresult;
13202: if (-e $copyfile) {
13203: $versionresult = &logo_versioning($targetdir,$file,$logfile);
13204: } else {
13205: $versionresult = 'ok';
13206: }
13207: if ($versionresult eq 'ok') {
13208: if (copy($source,$copyfile)) {
13209: print $logfile "\nCopied original source to ".$copyfile."\n";
13210: $output = 'ok';
13211: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 13212: push(@{$modified_urls},[$copyfile,$source]);
13213: my $metaoutput =
13214: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
13215: unless ($registered_cleanup) {
13216: my $handlers = $r->get_handlers('PerlCleanupHandler');
13217: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13218: $registered_cleanup=1;
13219: }
1.9 raeburn 13220: } else {
13221: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
13222: $output = &mt('Failed to copy file to RES space').", $!";
13223: }
13224: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
13225: my $inputfile = $filepath.'/'.$file;
13226: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 13227: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
13228: if ($fullwidth ne '' && $fullheight ne '') {
13229: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
13230: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 13231: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
13232: system({$args[0]} @args);
1.16 raeburn 13233: chmod(0660, $filepath.'/tn-'.$file);
13234: if (-e $outfile) {
13235: my $copyfile=$targetdir.'/tn-'.$file;
13236: if (copy($outfile,$copyfile)) {
13237: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 13238: my $thumb_metaoutput =
13239: &write_metadata($dom,$confname,$formname,
13240: $targetdir,'tn-'.$file,$logfile);
13241: push(@{$modified_urls},[$copyfile,$outfile]);
13242: unless ($registered_cleanup) {
13243: my $handlers = $r->get_handlers('PerlCleanupHandler');
13244: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13245: $registered_cleanup=1;
13246: }
1.267 raeburn 13247: $madethumb = 1;
1.16 raeburn 13248: } else {
13249: print $logfile "\nUnable to write ".$copyfile.
13250: ':'.$!."\n";
13251: }
13252: }
1.9 raeburn 13253: }
13254: }
13255: }
13256: } else {
13257: $output = $versionresult;
13258: }
13259: }
1.267 raeburn 13260: return ($output,$logourl,$madethumb);
1.9 raeburn 13261: }
13262:
13263: sub logo_versioning {
13264: my ($targetdir,$file,$logfile) = @_;
13265: my $target = $targetdir.'/'.$file;
13266: my ($maxversion,$fn,$extn,$output);
13267: $maxversion = 0;
13268: if ($file =~ /^(.+)\.(\w+)$/) {
13269: $fn=$1;
13270: $extn=$2;
13271: }
13272: opendir(DIR,$targetdir);
13273: while (my $filename=readdir(DIR)) {
13274: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
13275: $maxversion=($1>$maxversion)?$1:$maxversion;
13276: }
13277: }
13278: $maxversion++;
13279: print $logfile "\nCreating old version ".$maxversion."\n";
13280: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
13281: if (copy($target,$copyfile)) {
13282: print $logfile "Copied old target to ".$copyfile."\n";
13283: $copyfile=$copyfile.'.meta';
13284: if (copy($target.'.meta',$copyfile)) {
13285: print $logfile "Copied old target metadata to ".$copyfile."\n";
13286: $output = 'ok';
13287: } else {
13288: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
13289: $output = &mt('Failed to copy old meta').", $!, ";
13290: }
13291: } else {
13292: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
13293: $output = &mt('Failed to copy old target').", $!, ";
13294: }
13295: return $output;
13296: }
13297:
13298: sub write_metadata {
13299: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
13300: my (%metadatafields,%metadatakeys,$output);
13301: $metadatafields{'title'}=$formname;
13302: $metadatafields{'creationdate'}=time;
13303: $metadatafields{'lastrevisiondate'}=time;
13304: $metadatafields{'copyright'}='public';
13305: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
13306: $env{'user.domain'};
13307: $metadatafields{'authorspace'}=$confname.':'.$dom;
13308: $metadatafields{'domain'}=$dom;
13309: {
13310: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
13311: my $mfh;
1.316 raeburn 13312: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 13313: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 13314: unless ($_=~/\./) {
13315: my $unikey=$_;
13316: $unikey=~/^([A-Za-z]+)/;
13317: my $tag=$1;
13318: $tag=~tr/A-Z/a-z/;
13319: print $mfh "\n\<$tag";
13320: foreach (split(/\,/,$metadatakeys{$unikey})) {
13321: my $value=$metadatafields{$unikey.'.'.$_};
13322: $value=~s/\"/\'\'/g;
13323: print $mfh ' '.$_.'="'.$value.'"';
13324: }
13325: print $mfh '>'.
13326: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
13327: .'</'.$tag.'>';
13328: }
13329: }
13330: $output = 'ok';
13331: print $logfile "\nWrote metadata";
13332: close($mfh);
13333: } else {
13334: print $logfile "\nFailed to open metadata file";
1.9 raeburn 13335: $output = &mt('Could not write metadata');
13336: }
13337: }
1.155 raeburn 13338: return $output;
13339: }
13340:
13341: sub notifysubscribed {
13342: foreach my $targetsource (@{$modified_urls}){
13343: next unless (ref($targetsource) eq 'ARRAY');
13344: my ($target,$source)=@{$targetsource};
13345: if ($source ne '') {
1.316 raeburn 13346: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13347: print $logfh "\nCleanup phase: Notifications\n";
13348: my @subscribed=&subscribed_hosts($target);
13349: foreach my $subhost (@subscribed) {
13350: print $logfh "\nNotifying host ".$subhost.':';
13351: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13352: print $logfh $reply;
13353: }
13354: my @subscribedmeta=&subscribed_hosts("$target.meta");
13355: foreach my $subhost (@subscribedmeta) {
13356: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13357: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13358: $subhost);
13359: print $logfh $reply;
13360: }
13361: print $logfh "\n============ Done ============\n";
1.160 raeburn 13362: close($logfh);
1.155 raeburn 13363: }
13364: }
13365: }
13366: return OK;
13367: }
13368:
13369: sub subscribed_hosts {
13370: my ($target) = @_;
13371: my @subscribed;
1.316 raeburn 13372: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13373: while (my $subline=<$fh>) {
13374: if ($subline =~ /^($match_lonid):/) {
13375: my $host = $1;
13376: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13377: unless (grep(/^\Q$host\E$/,@subscribed)) {
13378: push(@subscribed,$host);
13379: }
13380: }
13381: }
13382: }
13383: }
13384: return @subscribed;
1.9 raeburn 13385: }
13386:
13387: sub check_switchserver {
13388: my ($dom,$confname) = @_;
13389: my ($allowed,$switchserver);
13390: my $home = &Apache::lonnet::homeserver($confname,$dom);
13391: if ($home eq 'no_host') {
13392: $home = &Apache::lonnet::domain($dom,'primary');
13393: }
13394: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13395: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13396: if (!$allowed) {
1.180 raeburn 13397: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13398: }
13399: return $switchserver;
13400: }
13401:
1.1 raeburn 13402: sub modify_quotas {
1.216 raeburn 13403: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13404: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13405: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13406: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13407: $validationfieldsref);
1.86 raeburn 13408: if ($action eq 'quotas') {
13409: $context = 'tools';
1.163 raeburn 13410: } else {
1.86 raeburn 13411: $context = $action;
13412: }
13413: if ($context eq 'requestcourses') {
1.325 raeburn 13414: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13415: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13416: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13417: %titles = &courserequest_titles();
13418: $toolregexp = join('|',@usertools);
13419: %conditions = &courserequest_conditions();
1.216 raeburn 13420: $confname = $dom.'-domainconfig';
13421: my $servadm = $r->dir_config('lonAdmEMail');
13422: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13423: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13424: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13425: } elsif ($context eq 'requestauthor') {
13426: @usertools = ('author');
13427: %titles = &authorrequest_titles();
1.86 raeburn 13428: } else {
1.162 raeburn 13429: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 13430: %titles = &tool_titles();
1.86 raeburn 13431: }
1.212 raeburn 13432: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13433: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13434: foreach my $key (keys(%env)) {
1.101 raeburn 13435: if ($context eq 'requestcourses') {
13436: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13437: my $item = $1;
13438: my $type = $2;
13439: if ($type =~ /^limit_(.+)/) {
13440: $limithash{$item}{$1} = $env{$key};
13441: } else {
13442: $confhash{$item}{$type} = $env{$key};
13443: }
13444: }
1.163 raeburn 13445: } elsif ($context eq 'requestauthor') {
13446: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13447: $confhash{$1} = $env{$key};
13448: }
1.101 raeburn 13449: } else {
1.86 raeburn 13450: if ($key =~ /^form\.quota_(.+)$/) {
13451: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13452: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13453: $confhash{'authorquota'}{$1} = $env{$key};
13454: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13455: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13456: }
1.72 raeburn 13457: }
13458: }
1.163 raeburn 13459: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 13460: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 13461: @approvalnotify = sort(@approvalnotify);
13462: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 13463: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 13464: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
13465: foreach my $type (@hasuniquecode) {
13466: if (grep(/^\Q$type\E$/,@crstypes)) {
13467: $confhash{'uniquecode'}{$type} = 1;
13468: }
1.216 raeburn 13469: }
1.242 raeburn 13470: my (%newbook,%allpos);
1.216 raeburn 13471: if ($context eq 'requestcourses') {
1.242 raeburn 13472: foreach my $type ('textbooks','templates') {
13473: @{$allpos{$type}} = ();
13474: my $invalid;
13475: if ($type eq 'textbooks') {
13476: $invalid = &mt('Invalid LON-CAPA course for textbook');
13477: } else {
13478: $invalid = &mt('Invalid LON-CAPA course for template');
13479: }
13480: if ($env{'form.'.$type.'_addbook'}) {
13481: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
13482: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
13483: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
13484: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
13485: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
13486: } else {
13487: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
13488: my $position = $env{'form.'.$type.'_addbook_pos'};
13489: $position =~ s/\D+//g;
13490: if ($position ne '') {
13491: $allpos{$type}[$position] = $newbook{$type};
13492: }
1.216 raeburn 13493: }
1.242 raeburn 13494: } else {
13495: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 13496: }
13497: }
1.242 raeburn 13498: }
1.216 raeburn 13499: }
1.102 raeburn 13500: if (ref($domconfig{$action}) eq 'HASH') {
13501: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
13502: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
13503: $changes{'notify'}{'approval'} = 1;
13504: }
13505: } else {
1.144 raeburn 13506: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13507: $changes{'notify'}{'approval'} = 1;
13508: }
13509: }
1.218 raeburn 13510: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
13511: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13512: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
13513: unless ($confhash{'uniquecode'}{$crstype}) {
13514: $changes{'uniquecode'} = 1;
13515: }
13516: }
13517: unless ($changes{'uniquecode'}) {
13518: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
13519: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
13520: $changes{'uniquecode'} = 1;
13521: }
13522: }
13523: }
13524: } else {
13525: $changes{'uniquecode'} = 1;
13526: }
13527: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
13528: $changes{'uniquecode'} = 1;
1.216 raeburn 13529: }
13530: if ($context eq 'requestcourses') {
1.242 raeburn 13531: foreach my $type ('textbooks','templates') {
13532: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13533: my %deletions;
13534: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
13535: if (@todelete) {
13536: map { $deletions{$_} = 1; } @todelete;
13537: }
13538: my %imgdeletions;
13539: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13540: if (@todeleteimages) {
13541: map { $imgdeletions{$_} = 1; } @todeleteimages;
13542: }
13543: my $maxnum = $env{'form.'.$type.'_maxnum'};
13544: for (my $i=0; $i<=$maxnum; $i++) {
13545: my $itemid = $env{'form.'.$type.'_id_'.$i};
13546: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13547: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13548: if ($deletions{$key}) {
13549: if ($domconfig{$action}{$type}{$key}{'image'}) {
13550: #FIXME need to obsolete item in RES space
13551: }
13552: next;
13553: } else {
13554: my $newpos = $env{'form.'.$itemid};
13555: $newpos =~ s/\D+//g;
1.243 raeburn 13556: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13557: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13558: ($type eq 'templates'));
1.242 raeburn 13559: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13560: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13561: $changes{$type}{$key} = 1;
13562: }
13563: }
13564: $allpos{$type}[$newpos] = $key;
13565: }
13566: if ($imgdeletions{$key}) {
13567: $changes{$type}{$key} = 1;
1.216 raeburn 13568: #FIXME need to obsolete item in RES space
1.242 raeburn 13569: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13570: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13571: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13572: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13573: } else {
13574: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13575: $cdom,$cnum,$type,$configuserok,
13576: $switchserver,$author_ok);
13577: if ($imgurl) {
13578: $confhash{$type}{$key}{'image'} = $imgurl;
13579: $changes{$type}{$key} = 1;
13580: }
13581: if ($error) {
13582: &Apache::lonnet::logthis($error);
13583: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13584: }
13585: }
1.242 raeburn 13586: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13587: $confhash{$type}{$key}{'image'} =
13588: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13589: }
13590: }
13591: }
13592: }
13593: }
13594: }
1.102 raeburn 13595: } else {
1.144 raeburn 13596: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13597: $changes{'notify'}{'approval'} = 1;
13598: }
1.218 raeburn 13599: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13600: $changes{'uniquecode'} = 1;
13601: }
13602: }
13603: if ($context eq 'requestcourses') {
1.242 raeburn 13604: foreach my $type ('textbooks','templates') {
13605: if ($newbook{$type}) {
13606: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13607: foreach my $item ('subject','title','publisher','author') {
13608: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13609: ($type eq 'template'));
1.242 raeburn 13610: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13611: if ($env{'form.'.$type.'_addbook_'.$item}) {
13612: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13613: }
13614: }
13615: if ($type eq 'textbooks') {
13616: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13617: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13618: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13619: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13620: } else {
13621: my ($imageurl,$error) =
13622: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13623: $configuserok,$switchserver,$author_ok);
13624: if ($imageurl) {
13625: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13626: }
13627: if ($error) {
13628: &Apache::lonnet::logthis($error);
13629: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13630: }
1.242 raeburn 13631: }
13632: }
1.216 raeburn 13633: }
13634: }
1.242 raeburn 13635: if (@{$allpos{$type}} > 0) {
13636: my $idx = 0;
13637: foreach my $item (@{$allpos{$type}}) {
13638: if ($item ne '') {
13639: $confhash{$type}{$item}{'order'} = $idx;
13640: if (ref($domconfig{$action}) eq 'HASH') {
13641: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13642: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13643: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13644: $changes{$type}{$item} = 1;
13645: }
1.216 raeburn 13646: }
13647: }
13648: }
1.242 raeburn 13649: $idx ++;
1.216 raeburn 13650: }
13651: }
13652: }
13653: }
1.235 raeburn 13654: if (ref($validationitemsref) eq 'ARRAY') {
13655: foreach my $item (@{$validationitemsref}) {
13656: if ($item eq 'fields') {
13657: my @changed;
13658: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13659: if (@{$confhash{'validation'}{$item}} > 0) {
13660: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13661: }
1.266 raeburn 13662: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13663: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13664: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13665: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13666: $domconfig{'requestcourses'}{'validation'}{$item});
13667: } else {
13668: @changed = @{$confhash{'validation'}{$item}};
13669: }
1.235 raeburn 13670: } else {
13671: @changed = @{$confhash{'validation'}{$item}};
13672: }
13673: } else {
13674: @changed = @{$confhash{'validation'}{$item}};
13675: }
13676: if (@changed) {
13677: if ($confhash{'validation'}{$item}) {
13678: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13679: } else {
13680: $changes{'validation'}{$item} = &mt('None');
13681: }
13682: }
13683: } else {
13684: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13685: if ($item eq 'markup') {
13686: if ($env{'form.requestcourses_validation_'.$item}) {
13687: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13688: }
13689: }
1.266 raeburn 13690: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13691: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13692: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13693: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13694: }
13695: } else {
13696: if ($confhash{'validation'}{$item} ne '') {
13697: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13698: }
1.235 raeburn 13699: }
13700: } else {
13701: if ($confhash{'validation'}{$item} ne '') {
13702: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13703: }
13704: }
13705: }
13706: }
13707: }
13708: if ($env{'form.validationdc'}) {
13709: my $newval = $env{'form.validationdc'};
1.285 raeburn 13710: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13711: if (exists($domcoords{$newval})) {
13712: $confhash{'validation'}{'dc'} = $newval;
13713: }
13714: }
13715: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13716: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13717: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13718: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13719: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13720: if ($confhash{'validation'}{'dc'} eq '') {
13721: $changes{'validation'}{'dc'} = &mt('None');
13722: } else {
13723: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13724: }
1.235 raeburn 13725: }
1.266 raeburn 13726: } elsif ($confhash{'validation'}{'dc'} ne '') {
13727: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13728: }
13729: } elsif ($confhash{'validation'}{'dc'} ne '') {
13730: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13731: }
13732: } elsif ($confhash{'validation'}{'dc'} ne '') {
13733: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13734: }
1.266 raeburn 13735: } else {
13736: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13737: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13738: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13739: $changes{'validation'}{'dc'} = &mt('None');
13740: }
13741: }
1.235 raeburn 13742: }
13743: }
1.102 raeburn 13744: }
13745: } else {
1.86 raeburn 13746: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13747: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13748: }
1.72 raeburn 13749: foreach my $item (@usertools) {
13750: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13751: my $unset;
1.101 raeburn 13752: if ($context eq 'requestcourses') {
1.104 raeburn 13753: $unset = '0';
13754: if ($type eq '_LC_adv') {
13755: $unset = '';
13756: }
1.101 raeburn 13757: if ($confhash{$item}{$type} eq 'autolimit') {
13758: $confhash{$item}{$type} .= '=';
13759: unless ($limithash{$item}{$type} =~ /\D/) {
13760: $confhash{$item}{$type} .= $limithash{$item}{$type};
13761: }
13762: }
1.163 raeburn 13763: } elsif ($context eq 'requestauthor') {
13764: $unset = '0';
13765: if ($type eq '_LC_adv') {
13766: $unset = '';
13767: }
1.72 raeburn 13768: } else {
1.101 raeburn 13769: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13770: $confhash{$item}{$type} = 1;
13771: } else {
13772: $confhash{$item}{$type} = 0;
13773: }
1.72 raeburn 13774: }
1.86 raeburn 13775: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13776: if ($action eq 'requestauthor') {
13777: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13778: $changes{$type} = 1;
13779: }
13780: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13781: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13782: $changes{$item}{$type} = 1;
13783: }
13784: } else {
13785: if ($context eq 'requestcourses') {
1.104 raeburn 13786: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13787: $changes{$item}{$type} = 1;
13788: }
13789: } else {
13790: if (!$confhash{$item}{$type}) {
13791: $changes{$item}{$type} = 1;
13792: }
13793: }
13794: }
13795: } else {
13796: if ($context eq 'requestcourses') {
1.104 raeburn 13797: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13798: $changes{$item}{$type} = 1;
13799: }
1.163 raeburn 13800: } elsif ($context eq 'requestauthor') {
13801: if ($confhash{$type} ne $unset) {
13802: $changes{$type} = 1;
13803: }
1.72 raeburn 13804: } else {
13805: if (!$confhash{$item}{$type}) {
13806: $changes{$item}{$type} = 1;
13807: }
13808: }
13809: }
1.1 raeburn 13810: }
13811: }
1.163 raeburn 13812: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13813: if (ref($domconfig{'quotas'}) eq 'HASH') {
13814: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13815: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13816: if (exists($confhash{'defaultquota'}{$key})) {
13817: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13818: $changes{'defaultquota'}{$key} = 1;
13819: }
13820: } else {
13821: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13822: }
13823: }
1.86 raeburn 13824: } else {
13825: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13826: if (exists($confhash{'defaultquota'}{$key})) {
13827: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13828: $changes{'defaultquota'}{$key} = 1;
13829: }
13830: } else {
13831: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13832: }
1.1 raeburn 13833: }
13834: }
1.197 raeburn 13835: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13836: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13837: if (exists($confhash{'authorquota'}{$key})) {
13838: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13839: $changes{'authorquota'}{$key} = 1;
13840: }
13841: } else {
13842: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13843: }
13844: }
13845: }
1.1 raeburn 13846: }
1.86 raeburn 13847: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13848: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13849: if (ref($domconfig{'quotas'}) eq 'HASH') {
13850: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13851: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13852: $changes{'defaultquota'}{$key} = 1;
13853: }
13854: } else {
13855: if (!exists($domconfig{'quotas'}{$key})) {
13856: $changes{'defaultquota'}{$key} = 1;
13857: }
1.72 raeburn 13858: }
13859: } else {
1.86 raeburn 13860: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13861: }
1.1 raeburn 13862: }
13863: }
1.197 raeburn 13864: if (ref($confhash{'authorquota'}) eq 'HASH') {
13865: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13866: if (ref($domconfig{'quotas'}) eq 'HASH') {
13867: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13868: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13869: $changes{'authorquota'}{$key} = 1;
13870: }
13871: } else {
13872: $changes{'authorquota'}{$key} = 1;
13873: }
13874: } else {
13875: $changes{'authorquota'}{$key} = 1;
13876: }
13877: }
13878: }
1.1 raeburn 13879: }
1.72 raeburn 13880:
1.163 raeburn 13881: if ($context eq 'requestauthor') {
13882: $domdefaults{'requestauthor'} = \%confhash;
13883: } else {
13884: foreach my $key (keys(%confhash)) {
1.242 raeburn 13885: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13886: $domdefaults{$key} = $confhash{$key};
13887: }
1.163 raeburn 13888: }
1.72 raeburn 13889: }
1.163 raeburn 13890:
1.1 raeburn 13891: my %quotahash = (
1.86 raeburn 13892: $action => { %confhash }
1.1 raeburn 13893: );
13894: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13895: $dom);
13896: if ($putresult eq 'ok') {
13897: if (keys(%changes) > 0) {
1.72 raeburn 13898: my $cachetime = 24*60*60;
13899: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13900: if (ref($lastactref) eq 'HASH') {
13901: $lastactref->{'domdefaults'} = 1;
13902: }
1.1 raeburn 13903: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 13904: unless (($context eq 'requestcourses') ||
1.163 raeburn 13905: ($context eq 'requestauthor')) {
1.86 raeburn 13906: if (ref($changes{'defaultquota'}) eq 'HASH') {
13907: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13908: foreach my $type (@{$types},'default') {
13909: if (defined($changes{'defaultquota'}{$type})) {
13910: my $typetitle = $usertypes->{$type};
13911: if ($type eq 'default') {
13912: $typetitle = $othertitle;
13913: }
1.213 raeburn 13914: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13915: }
13916: }
1.86 raeburn 13917: $resulttext .= '</ul></li>';
1.72 raeburn 13918: }
1.197 raeburn 13919: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 13920: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 13921: foreach my $type (@{$types},'default') {
13922: if (defined($changes{'authorquota'}{$type})) {
13923: my $typetitle = $usertypes->{$type};
13924: if ($type eq 'default') {
13925: $typetitle = $othertitle;
13926: }
1.213 raeburn 13927: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 13928: }
13929: }
13930: $resulttext .= '</ul></li>';
13931: }
1.72 raeburn 13932: }
1.80 raeburn 13933: my %newenv;
1.72 raeburn 13934: foreach my $item (@usertools) {
1.163 raeburn 13935: my (%haschgs,%inconf);
13936: if ($context eq 'requestauthor') {
13937: %haschgs = %changes;
1.210 raeburn 13938: %inconf = %confhash;
1.163 raeburn 13939: } else {
13940: if (ref($changes{$item}) eq 'HASH') {
13941: %haschgs = %{$changes{$item}};
13942: }
13943: if (ref($confhash{$item}) eq 'HASH') {
13944: %inconf = %{$confhash{$item}};
13945: }
13946: }
13947: if (keys(%haschgs) > 0) {
1.80 raeburn 13948: my $newacc =
13949: &Apache::lonnet::usertools_access($env{'user.name'},
13950: $env{'user.domain'},
1.86 raeburn 13951: $item,'reload',$context);
1.210 raeburn 13952: if (($context eq 'requestcourses') ||
1.163 raeburn 13953: ($context eq 'requestauthor')) {
1.108 raeburn 13954: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13955: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13956: }
13957: } else {
13958: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13959: $newenv{'environment.availabletools.'.$item} = $newacc;
13960: }
1.80 raeburn 13961: }
1.163 raeburn 13962: unless ($context eq 'requestauthor') {
13963: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13964: }
1.72 raeburn 13965: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 13966: if ($haschgs{$type}) {
1.72 raeburn 13967: my $typetitle = $usertypes->{$type};
13968: if ($type eq 'default') {
13969: $typetitle = $othertitle;
13970: } elsif ($type eq '_LC_adv') {
13971: $typetitle = 'LON-CAPA Advanced Users';
13972: }
1.163 raeburn 13973: if ($inconf{$type}) {
1.101 raeburn 13974: if ($context eq 'requestcourses') {
13975: my $cond;
1.163 raeburn 13976: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13977: if ($1 eq '') {
13978: $cond = &mt('(Automatic processing of any request).');
13979: } else {
13980: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13981: }
13982: } else {
1.163 raeburn 13983: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13984: }
13985: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 13986: } elsif ($context eq 'requestauthor') {
13987: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13988: $titles{$inconf{$type}},$typetitle);
13989:
1.101 raeburn 13990: } else {
13991: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13992: }
1.72 raeburn 13993: } else {
1.104 raeburn 13994: if ($type eq '_LC_adv') {
1.163 raeburn 13995: if ($inconf{$type} eq '0') {
1.104 raeburn 13996: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13997: } else {
13998: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13999: }
14000: } else {
14001: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14002: }
1.72 raeburn 14003: }
14004: }
1.26 raeburn 14005: }
1.163 raeburn 14006: unless ($context eq 'requestauthor') {
14007: $resulttext .= '</ul></li>';
14008: }
1.26 raeburn 14009: }
1.1 raeburn 14010: }
1.163 raeburn 14011: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14012: if (ref($changes{'notify'}) eq 'HASH') {
14013: if ($changes{'notify'}{'approval'}) {
14014: if (ref($confhash{'notify'}) eq 'HASH') {
14015: if ($confhash{'notify'}{'approval'}) {
14016: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14017: } else {
1.163 raeburn 14018: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14019: }
14020: }
14021: }
14022: }
14023: }
1.216 raeburn 14024: if ($action eq 'requestcourses') {
14025: my @offon = ('off','on');
14026: if ($changes{'uniquecode'}) {
1.218 raeburn 14027: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14028: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14029: $resulttext .= '<li>'.
14030: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14031: '</li>';
14032: } else {
14033: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14034: '</li>';
14035: }
1.216 raeburn 14036: }
1.242 raeburn 14037: foreach my $type ('textbooks','templates') {
14038: if (ref($changes{$type}) eq 'HASH') {
14039: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14040: foreach my $key (sort(keys(%{$changes{$type}}))) {
14041: my %coursehash = &Apache::lonnet::coursedescription($key);
14042: my $coursetitle = $coursehash{'description'};
14043: my $position = $confhash{$type}{$key}{'order'} + 1;
14044: $resulttext .= '<li>';
1.243 raeburn 14045: foreach my $item ('subject','title','publisher','author') {
14046: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14047: ($type eq 'templates'));
1.242 raeburn 14048: my $name = $item.':';
14049: $name =~ s/^(\w)/\U$1/;
14050: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14051: }
14052: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14053: if ($type eq 'textbooks') {
14054: if ($confhash{$type}{$key}{'image'}) {
14055: $resulttext .= ' '.&mt('Image: [_1]',
14056: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14057: ' alt="Textbook cover" />').'<br />';
14058: }
14059: }
14060: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14061: }
1.242 raeburn 14062: $resulttext .= '</ul></li>';
1.216 raeburn 14063: }
14064: }
1.235 raeburn 14065: if (ref($changes{'validation'}) eq 'HASH') {
14066: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14067: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14068: foreach my $item (@{$validationitemsref}) {
14069: if (exists($changes{'validation'}{$item})) {
14070: if ($item eq 'markup') {
14071: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14072: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14073: } else {
14074: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14075: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14076: }
14077: }
14078: }
14079: if (exists($changes{'validation'}{'dc'})) {
14080: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14081: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14082: }
14083: }
14084: }
1.216 raeburn 14085: }
1.1 raeburn 14086: $resulttext .= '</ul>';
1.80 raeburn 14087: if (keys(%newenv)) {
14088: &Apache::lonnet::appenv(\%newenv);
14089: }
1.1 raeburn 14090: } else {
1.86 raeburn 14091: if ($context eq 'requestcourses') {
14092: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14093: } elsif ($context eq 'requestauthor') {
14094: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14095: } else {
1.90 weissno 14096: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14097: }
1.1 raeburn 14098: }
14099: } else {
1.11 albertel 14100: $resulttext = '<span class="LC_error">'.
14101: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14102: }
1.216 raeburn 14103: if ($errors) {
14104: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14105: '<ul>'.$errors.'</ul></p>';
14106: }
1.3 raeburn 14107: return $resulttext;
1.1 raeburn 14108: }
14109:
1.216 raeburn 14110: sub process_textbook_image {
1.242 raeburn 14111: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14112: my $filename = $env{'form.'.$caller.'.filename'};
14113: my ($error,$url);
14114: my ($width,$height) = (50,50);
14115: if ($configuserok eq 'ok') {
14116: if ($switchserver) {
14117: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14118: $switchserver);
14119: } elsif ($author_ok eq 'ok') {
14120: my ($result,$imageurl) =
14121: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 14122: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 14123: if ($result eq 'ok') {
14124: $url = $imageurl;
14125: } else {
14126: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14127: }
14128: } else {
14129: $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);
14130: }
14131: } else {
14132: $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);
14133: }
14134: return ($url,$error);
14135: }
14136:
1.267 raeburn 14137: sub modify_ltitools {
14138: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14139: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 14140: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 14141: my $confname = $dom.'-domainconfig';
14142: my $servadm = $r->dir_config('lonAdmEMail');
14143: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14144: my (%posslti,%possfield);
14145: my @courseroles = ('cc','in','ta','ep','st');
14146: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
14147: map { $posslti{$_} = 1; } @ltiroles;
14148: my @allfields = ('fullname','firstname','lastname','email','user','roles');
14149: map { $possfield{$_} = 1; } @allfields;
14150: my %lt = <itools_names();
14151: if ($env{'form.ltitools_add'}) {
14152: my $title = $env{'form.ltitools_add_title'};
14153: $title =~ s/(`)/'/g;
14154: ($newid,my $error) = &get_ltitools_id($dom,$title);
14155: if ($newid) {
14156: my $position = $env{'form.ltitools_add_pos'};
14157: $position =~ s/\D+//g;
14158: if ($position ne '') {
14159: $allpos[$position] = $newid;
14160: }
14161: $changes{$newid} = 1;
1.322 raeburn 14162: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 14163: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 14164: if ($item eq 'lifetime') {
14165: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
14166: }
1.267 raeburn 14167: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 14168: if (($item eq 'key') || ($item eq 'secret')) {
14169: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14170: } else {
14171: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
14172: }
1.267 raeburn 14173: }
14174: }
14175: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
14176: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
14177: }
14178: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
14179: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
14180: }
1.323 raeburn 14181: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
14182: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
14183: } else {
14184: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
14185: }
1.296 raeburn 14186: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 14187: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
14188: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 14189: if (($item eq 'width') || ($item eq 'height')) {
14190: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
14191: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14192: }
14193: } else {
14194: if ($env{'form.ltitools_add_'.$item} ne '') {
14195: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
14196: }
1.267 raeburn 14197: }
14198: }
14199: if ($env{'form.ltitools_add_target'} eq 'window') {
14200: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 14201: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
14202: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 14203: } else {
14204: $confhash{$newid}{'display'}{'target'} = 'iframe';
14205: }
14206: foreach my $item ('passback','roster') {
1.319 raeburn 14207: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 14208: $confhash{$newid}{$item} = 1;
1.319 raeburn 14209: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
14210: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
14211: $lifetime =~ s/^\s+|\s+$//g;
14212: if ($lifetime =~ /^\d+\.?\d*$/) {
14213: $confhash{$newid}{$item.'valid'} = $lifetime;
14214: }
14215: }
1.267 raeburn 14216: }
14217: }
14218: if ($env{'form.ltitools_add_image.filename'} ne '') {
14219: my ($imageurl,$error) =
1.307 raeburn 14220: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 14221: $configuserok,$switchserver,$author_ok);
14222: if ($imageurl) {
14223: $confhash{$newid}{'image'} = $imageurl;
14224: }
14225: if ($error) {
14226: &Apache::lonnet::logthis($error);
14227: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14228: }
14229: }
14230: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
14231: foreach my $field (@fields) {
14232: if ($possfield{$field}) {
14233: if ($field eq 'roles') {
14234: foreach my $role (@courseroles) {
14235: my $choice = $env{'form.ltitools_add_roles_'.$role};
14236: if (($choice ne '') && ($posslti{$choice})) {
14237: $confhash{$newid}{'roles'}{$role} = $choice;
14238: if ($role eq 'cc') {
14239: $confhash{$newid}{'roles'}{'co'} = $choice;
14240: }
14241: }
14242: }
14243: } else {
14244: $confhash{$newid}{'fields'}{$field} = 1;
14245: }
14246: }
14247: }
1.324 raeburn 14248: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
14249: if ($confhash{$newid}{'fields'}{'user'}) {
14250: if ($env{'form.ltitools_userincdom_add'}) {
14251: $confhash{$newid}{'incdom'} = 1;
14252: }
14253: }
14254: }
1.273 raeburn 14255: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
14256: foreach my $item (@courseconfig) {
14257: $confhash{$newid}{'crsconf'}{$item} = 1;
14258: }
1.267 raeburn 14259: if ($env{'form.ltitools_add_custom'}) {
14260: my $name = $env{'form.ltitools_add_custom_name'};
14261: my $value = $env{'form.ltitools_add_custom_value'};
14262: $value =~ s/(`)/'/g;
14263: $name =~ s/(`)/'/g;
14264: $confhash{$newid}{'custom'}{$name} = $value;
14265: }
14266: } else {
14267: my $error = &mt('Failed to acquire unique ID for new external tool');
14268: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14269: }
14270: }
14271: if (ref($domconfig{$action}) eq 'HASH') {
14272: my %deletions;
14273: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
14274: if (@todelete) {
14275: map { $deletions{$_} = 1; } @todelete;
14276: }
14277: my %customadds;
14278: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
14279: if (@newcustom) {
14280: map { $customadds{$_} = 1; } @newcustom;
14281: }
14282: my %imgdeletions;
14283: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
14284: if (@todeleteimages) {
14285: map { $imgdeletions{$_} = 1; } @todeleteimages;
14286: }
14287: my $maxnum = $env{'form.ltitools_maxnum'};
14288: for (my $i=0; $i<=$maxnum; $i++) {
14289: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 14290: $itemid =~ s/\D+//g;
1.267 raeburn 14291: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14292: if ($deletions{$itemid}) {
14293: if ($domconfig{$action}{$itemid}{'image'}) {
14294: #FIXME need to obsolete item in RES space
14295: }
14296: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
14297: next;
14298: } else {
14299: my $newpos = $env{'form.ltitools_'.$itemid};
14300: $newpos =~ s/\D+//g;
1.322 raeburn 14301: foreach my $item ('title','url','lifetime') {
1.267 raeburn 14302: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14303: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
14304: $changes{$itemid} = 1;
14305: }
14306: }
1.297 raeburn 14307: foreach my $item ('key','secret') {
14308: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14309: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
14310: $changes{$itemid} = 1;
14311: }
14312: }
1.267 raeburn 14313: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
14314: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
14315: }
14316: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
14317: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
14318: }
1.323 raeburn 14319: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
14320: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
14321: } else {
14322: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
14323: }
14324: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
14325: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
14326: $changes{$itemid} = 1;
14327: }
14328: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
14329: $changes{$itemid} = 1;
14330: }
1.267 raeburn 14331: foreach my $size ('width','height') {
14332: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
14333: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
14334: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
14335: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
14336: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14337: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
14338: $changes{$itemid} = 1;
14339: }
14340: } else {
14341: $changes{$itemid} = 1;
14342: }
1.296 raeburn 14343: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14344: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
14345: $changes{$itemid} = 1;
14346: }
14347: }
14348: }
14349: foreach my $item ('linktext','explanation') {
14350: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
14351: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
14352: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
14353: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
14354: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14355: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
14356: $changes{$itemid} = 1;
14357: }
14358: } else {
14359: $changes{$itemid} = 1;
14360: }
14361: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14362: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
14363: $changes{$itemid} = 1;
14364: }
1.267 raeburn 14365: }
14366: }
14367: if ($env{'form.ltitools_target_'.$i} eq 'window') {
14368: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 14369: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
14370: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 14371: } else {
14372: $confhash{$itemid}{'display'}{'target'} = 'iframe';
14373: }
14374: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
14375: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
14376: $changes{$itemid} = 1;
14377: }
14378: } else {
14379: $changes{$itemid} = 1;
14380: }
14381: foreach my $extra ('passback','roster') {
14382: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
14383: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 14384: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 14385: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 14386: $lifetime =~ s/^\s+|\s+$//g;
14387: if ($lifetime =~ /^\d+\.?\d*$/) {
14388: $confhash{$itemid}{$extra.'valid'} = $lifetime;
14389: }
14390: }
1.267 raeburn 14391: }
14392: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
14393: $changes{$itemid} = 1;
14394: }
1.319 raeburn 14395: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
14396: $changes{$itemid} = 1;
14397: }
1.267 raeburn 14398: }
1.273 raeburn 14399: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 14400: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 14401: if (grep(/^\Q$item\E$/,@courseconfig)) {
14402: $confhash{$itemid}{'crsconf'}{$item} = 1;
14403: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
14404: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
14405: $changes{$itemid} = 1;
14406: }
14407: } else {
14408: $changes{$itemid} = 1;
14409: }
14410: }
14411: }
1.267 raeburn 14412: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
14413: foreach my $field (@fields) {
14414: if ($possfield{$field}) {
14415: if ($field eq 'roles') {
14416: foreach my $role (@courseroles) {
14417: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
14418: if (($choice ne '') && ($posslti{$choice})) {
14419: $confhash{$itemid}{'roles'}{$role} = $choice;
14420: if ($role eq 'cc') {
14421: $confhash{$itemid}{'roles'}{'co'} = $choice;
14422: }
14423: }
14424: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
14425: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
14426: $changes{$itemid} = 1;
14427: }
14428: } elsif ($confhash{$itemid}{'roles'}{$role}) {
14429: $changes{$itemid} = 1;
14430: }
14431: }
14432: } else {
14433: $confhash{$itemid}{'fields'}{$field} = 1;
14434: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
14435: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
14436: $changes{$itemid} = 1;
14437: }
14438: } else {
14439: $changes{$itemid} = 1;
14440: }
14441: }
14442: }
14443: }
1.324 raeburn 14444: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14445: if ($confhash{$itemid}{'fields'}{'user'}) {
14446: if ($env{'form.ltitools_userincdom_'.$i}) {
14447: $confhash{$itemid}{'incdom'} = 1;
14448: }
14449: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
14450: $changes{$itemid} = 1;
14451: }
14452: }
14453: }
1.267 raeburn 14454: $allpos[$newpos] = $itemid;
14455: }
14456: if ($imgdeletions{$itemid}) {
14457: $changes{$itemid} = 1;
14458: #FIXME need to obsolete item in RES space
14459: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
14460: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
14461: $itemid,$configuserok,$switchserver,
14462: $author_ok);
14463: if ($imgurl) {
14464: $confhash{$itemid}{'image'} = $imgurl;
14465: $changes{$itemid} = 1;
14466: }
14467: if ($error) {
14468: &Apache::lonnet::logthis($error);
14469: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14470: }
14471: } elsif ($domconfig{$action}{$itemid}{'image'}) {
14472: $confhash{$itemid}{'image'} =
14473: $domconfig{$action}{$itemid}{'image'};
14474: }
14475: if ($customadds{$i}) {
14476: my $name = $env{'form.ltitools_custom_name_'.$i};
14477: $name =~ s/(`)/'/g;
14478: $name =~ s/^\s+//;
14479: $name =~ s/\s+$//;
14480: my $value = $env{'form.ltitools_custom_value_'.$i};
14481: $value =~ s/(`)/'/g;
14482: $value =~ s/^\s+//;
14483: $value =~ s/\s+$//;
14484: if ($name ne '') {
14485: $confhash{$itemid}{'custom'}{$name} = $value;
14486: $changes{$itemid} = 1;
14487: }
14488: }
14489: my %customdels;
14490: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
14491: if (@customdeletions) {
14492: $changes{$itemid} = 1;
14493: }
14494: map { $customdels{$_} = 1; } @customdeletions;
14495: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
14496: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
14497: unless ($customdels{$key}) {
14498: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
14499: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
14500: }
14501: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
14502: $changes{$itemid} = 1;
14503: }
14504: }
14505: }
14506: }
14507: unless ($changes{$itemid}) {
14508: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
14509: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
14510: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14511: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
14512: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
14513: $changes{$itemid} = 1;
14514: last;
14515: }
14516: }
14517: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
14518: $changes{$itemid} = 1;
14519: }
14520: }
14521: last if ($changes{$itemid});
14522: }
14523: }
14524: }
14525: }
14526: }
14527: if (@allpos > 0) {
14528: my $idx = 0;
14529: foreach my $itemid (@allpos) {
14530: if ($itemid ne '') {
14531: $confhash{$itemid}{'order'} = $idx;
14532: if (ref($domconfig{$action}) eq 'HASH') {
14533: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14534: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14535: $changes{$itemid} = 1;
14536: }
14537: }
14538: }
14539: $idx ++;
14540: }
14541: }
14542: }
14543: my %ltitoolshash = (
14544: $action => { %confhash }
14545: );
14546: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
14547: $dom);
14548: if ($putresult eq 'ok') {
1.297 raeburn 14549: my %ltienchash = (
14550: $action => { %encconfig }
14551: );
1.384 raeburn 14552: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.267 raeburn 14553: if (keys(%changes) > 0) {
14554: my $cachetime = 24*60*60;
1.297 raeburn 14555: my %ltiall = %confhash;
14556: foreach my $id (keys(%ltiall)) {
14557: if (ref($encconfig{$id}) eq 'HASH') {
14558: foreach my $item ('key','secret') {
14559: $ltiall{$id}{$item} = $encconfig{$id}{$item};
14560: }
14561: }
14562: }
14563: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 14564: if (ref($lastactref) eq 'HASH') {
14565: $lastactref->{'ltitools'} = 1;
14566: }
14567: $resulttext = &mt('Changes made:').'<ul>';
14568: my %bynum;
14569: foreach my $itemid (sort(keys(%changes))) {
14570: my $position = $confhash{$itemid}{'order'};
14571: $bynum{$position} = $itemid;
14572: }
14573: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14574: my $itemid = $bynum{$pos};
14575: if (ref($confhash{$itemid}) ne 'HASH') {
14576: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14577: } else {
14578: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
14579: if ($confhash{$itemid}{'image'}) {
14580: $resulttext .= ' '.
14581: '<img src="'.$confhash{$itemid}{'image'}.'"'.
14582: ' alt="'.&mt('Tool Provider icon').'" />';
14583: }
14584: $resulttext .= '</li><ul>';
14585: my $position = $pos + 1;
14586: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 14587: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 14588: if ($confhash{$itemid}{$item} ne '') {
14589: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14590: }
14591: }
1.297 raeburn 14592: if ($encconfig{$itemid}{'key'} ne '') {
14593: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
14594: }
14595: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 14596: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 14597: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 14598: $resulttext .= ('*'x$num).'</li>';
14599: }
1.273 raeburn 14600: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 14601: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 14602: my $numconfig = 0;
14603: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
14604: foreach my $item (@possconfig) {
14605: if ($confhash{$itemid}{'crsconf'}{$item}) {
14606: $numconfig ++;
1.296 raeburn 14607: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 14608: }
14609: }
14610: }
14611: if (!$numconfig) {
1.372 raeburn 14612: $resulttext .= ' '.&mt('None');
1.273 raeburn 14613: }
14614: $resulttext .= '</li>';
1.267 raeburn 14615: foreach my $item ('passback','roster') {
14616: $resulttext .= '<li>'.$lt{$item}.' ';
14617: if ($confhash{$itemid}{$item}) {
14618: $resulttext .= &mt('Yes');
1.319 raeburn 14619: if ($confhash{$itemid}{$item.'valid'}) {
14620: if ($item eq 'passback') {
14621: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
14622: $confhash{$itemid}{$item.'valid'});
14623: } else {
14624: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
14625: $confhash{$itemid}{$item.'valid'});
14626: }
14627: }
1.267 raeburn 14628: } else {
14629: $resulttext .= &mt('No');
14630: }
14631: $resulttext .= '</li>';
14632: }
14633: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
14634: my $displaylist;
14635: if ($confhash{$itemid}{'display'}{'target'}) {
14636: $displaylist = &mt('Display target').': '.
14637: $confhash{$itemid}{'display'}{'target'}.',';
14638: }
14639: foreach my $size ('width','height') {
14640: if ($confhash{$itemid}{'display'}{$size}) {
14641: $displaylist .= (' 'x2).$lt{$size}.': '.
14642: $confhash{$itemid}{'display'}{$size}.',';
14643: }
14644: }
14645: if ($displaylist) {
14646: $displaylist =~ s/,$//;
14647: $resulttext .= '<li>'.$displaylist.'</li>';
14648: }
1.296 raeburn 14649: foreach my $item ('linktext','explanation') {
14650: if ($confhash{$itemid}{'display'}{$item}) {
14651: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
14652: }
14653: }
14654: }
1.267 raeburn 14655: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
14656: my $fieldlist;
14657: foreach my $field (@allfields) {
14658: if ($confhash{$itemid}{'fields'}{$field}) {
14659: $fieldlist .= (' 'x2).$lt{$field}.',';
14660: }
14661: }
14662: if ($fieldlist) {
14663: $fieldlist =~ s/,$//;
1.324 raeburn 14664: if ($confhash{$itemid}{'fields'}{'user'}) {
14665: if ($confhash{$itemid}{'incdom'}) {
14666: $fieldlist .= ' ('.&mt('username:domain').')';
14667: } else {
14668: $fieldlist .= ' ('.&mt('username').')';
14669: }
14670: }
1.267 raeburn 14671: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
14672: }
14673: }
14674: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
14675: my $rolemaps;
14676: foreach my $role (@courseroles) {
14677: if ($confhash{$itemid}{'roles'}{$role}) {
14678: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
14679: $confhash{$itemid}{'roles'}{$role}.',';
14680: }
14681: }
14682: if ($rolemaps) {
14683: $rolemaps =~ s/,$//;
14684: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14685: }
14686: }
14687: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
14688: my $customlist;
14689: if (keys(%{$confhash{$itemid}{'custom'}})) {
14690: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
14691: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
14692: }
14693: }
14694: if ($customlist) {
1.317 raeburn 14695: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 14696: }
14697: }
14698: $resulttext .= '</ul></li>';
14699: }
14700: }
14701: $resulttext .= '</ul>';
14702: } else {
14703: $resulttext = &mt('No changes made.');
14704: }
14705: } else {
14706: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14707: }
14708: if ($errors) {
14709: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14710: $errors.'</ul>';
14711: }
14712: return $resulttext;
14713: }
14714:
14715: sub process_ltitools_image {
14716: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
14717: my $filename = $env{'form.'.$caller.'.filename'};
14718: my ($error,$url);
14719: my ($width,$height) = (21,21);
14720: if ($configuserok eq 'ok') {
14721: if ($switchserver) {
14722: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
14723: $switchserver);
14724: } elsif ($author_ok eq 'ok') {
14725: my ($result,$imageurl,$madethumb) =
14726: &publishlogo($r,'upload',$caller,$dom,$confname,
14727: "ltitools/$itemid/icon",$width,$height);
14728: if ($result eq 'ok') {
14729: if ($madethumb) {
14730: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
14731: my $imagethumb = "$path/tn-".$imagefile;
14732: $url = $imagethumb;
14733: } else {
14734: $url = $imageurl;
14735: }
14736: } else {
14737: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14738: }
14739: } else {
14740: $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);
14741: }
14742: } else {
14743: $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);
14744: }
14745: return ($url,$error);
14746: }
14747:
14748: sub get_ltitools_id {
14749: my ($cdom,$title) = @_;
14750: # get lock on ltitools db
14751: my $lockhash = {
14752: lock => $env{'user.name'}.
14753: ':'.$env{'user.domain'},
14754: };
14755: my $tries = 0;
14756: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14757: my ($id,$error);
14758:
14759: while (($gotlock ne 'ok') && ($tries<10)) {
14760: $tries ++;
14761: sleep (0.1);
14762: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
14763: }
14764: if ($gotlock eq 'ok') {
14765: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
14766: if ($currids{'lock'}) {
14767: delete($currids{'lock'});
14768: if (keys(%currids)) {
14769: my @curr = sort { $a <=> $b } keys(%currids);
14770: if ($curr[-1] =~ /^\d+$/) {
14771: $id = 1 + $curr[-1];
14772: }
14773: } else {
14774: $id = 1;
14775: }
14776: if ($id) {
14777: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
14778: $error = 'nostore';
14779: }
14780: } else {
14781: $error = 'nonumber';
14782: }
14783: }
14784: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
14785: } else {
14786: $error = 'nolock';
14787: }
14788: return ($id,$error);
14789: }
14790:
1.372 raeburn 14791: sub modify_proctoring {
14792: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14793: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14794: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14795: my $confname = $dom.'-domainconfig';
14796: my $servadm = $r->dir_config('lonAdmEMail');
14797: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14798: my %providernames = &proctoring_providernames();
14799: my $maxnum = scalar(keys(%providernames));
14800:
14801: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14802: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14803: if (ref($requref) eq 'HASH') {
14804: %requserfields = %{$requref};
14805: }
14806: if (ref($opturef) eq 'HASH') {
14807: %optuserfields = %{$opturef};
14808: }
14809: if (ref($defref) eq 'HASH') {
14810: %defaults = %{$defref};
14811: }
14812: if (ref($extref) eq 'HASH') {
14813: %extended = %{$extref};
14814: }
14815: if (ref($crsref) eq 'HASH') {
14816: %crsconf = %{$crsref};
14817: }
14818: if (ref($rolesref) eq 'ARRAY') {
14819: @courseroles = @{$rolesref};
14820: }
14821: if (ref($ltiref) eq 'ARRAY') {
14822: @ltiroles = @{$ltiref};
14823: }
14824:
14825: if (ref($domconfig{$action}) eq 'HASH') {
14826: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14827: if (@todeleteimages) {
14828: map { $imgdeletions{$_} = 1; } @todeleteimages;
14829: }
14830: }
14831: my %customadds;
14832: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14833: if (@newcustom) {
14834: map { $customadds{$_} = 1; } @newcustom;
14835: }
14836: foreach my $provider (sort(keys(%providernames))) {
14837: $confhash{$provider} = {};
14838: my $pos = $env{'form.proctoring_pos_'.$provider};
14839: $pos =~ s/\D+//g;
14840: $allpos[$pos] = $provider;
14841: my (%current,%currentenc);
14842: my $showroles = 0;
14843: if (ref($domconfig{$action}) eq 'HASH') {
14844: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14845: %current = %{$domconfig{$action}{$provider}};
14846: foreach my $item ('key','secret') {
14847: $currentenc{$item} = $current{$item};
14848: delete($current{$item});
14849: }
14850: }
14851: }
14852: if ($env{'form.proctoring_available_'.$provider}) {
14853: $confhash{$provider}{'available'} = 1;
14854: unless ($current{'available'}) {
14855: $changes{$provider} = 1;
14856: }
14857: } else {
14858: %{$confhash{$provider}} = %current;
14859: %{$encconfhash{$provider}} = %currentenc;
14860: $confhash{$provider}{'available'} = 0;
14861: if ($current{'available'}) {
14862: $changes{$provider} = 1;
14863: }
14864: }
14865: if ($confhash{$provider}{'available'}) {
14866: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14867: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14868: if ($field eq 'lifetime') {
14869: if ($possval =~ /^\d+$/) {
14870: $confhash{$provider}{$field} = $possval;
14871: }
14872: } elsif ($field eq 'version') {
14873: if ($possval =~ /^\d+\.\d+$/) {
14874: $confhash{$provider}{$field} = $possval;
14875: }
14876: } elsif ($field eq 'sigmethod') {
14877: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14878: $confhash{$provider}{$field} = $possval;
14879: }
14880: } elsif ($field eq 'url') {
14881: $confhash{$provider}{$field} = $possval;
14882: } elsif (($field eq 'key') || ($field eq 'secret')) {
14883: $encconfhash{$provider}{$field} = $possval;
14884: unless ($currentenc{$field} eq $possval) {
14885: $changes{$provider} = 1;
14886: }
14887: }
14888: unless (($field eq 'key') || ($field eq 'secret')) {
14889: unless ($current{$field} eq $confhash{$provider}{$field}) {
14890: $changes{$provider} = 1;
14891: }
14892: }
14893: }
14894: if ($imgdeletions{$provider}) {
14895: $changes{$provider} = 1;
14896: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14897: my ($imageurl,$error) =
14898: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14899: $configuserok,$switchserver,$author_ok);
14900: if ($imageurl) {
14901: $confhash{$provider}{'image'} = $imageurl;
14902: $changes{$provider} = 1;
14903: }
14904: if ($error) {
14905: &Apache::lonnet::logthis($error);
14906: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14907: }
14908: } elsif (exists($current{'image'})) {
14909: $confhash{$provider}{'image'} = $current{'image'};
14910: }
14911: if (ref($requserfields{$provider}) eq 'ARRAY') {
14912: if (@{$requserfields{$provider}} > 0) {
14913: if (grep(/^user$/,@{$requserfields{$provider}})) {
14914: if ($env{'form.proctoring_userincdom_'.$provider}) {
14915: $confhash{$provider}{'incdom'} = 1;
14916: }
14917: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14918: $changes{$provider} = 1;
14919: }
14920: }
14921: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14922: $showroles = 1;
14923: }
14924: }
14925: }
14926: $confhash{$provider}{'fields'} = [];
14927: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14928: if (@{$optuserfields{$provider}} > 0) {
14929: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14930: foreach my $field (@{$optuserfields{$provider}}) {
14931: if (grep(/^\Q$field\E$/,@optfields)) {
14932: push(@{$confhash{$provider}{'fields'}},$field);
14933: }
14934: }
14935: }
14936: if (ref($current{'fields'}) eq 'ARRAY') {
14937: unless ($changes{$provider}) {
14938: my @new = sort(@{$confhash{$provider}{'fields'}});
14939: my @old = sort(@{$current{'fields'}});
14940: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14941: if (@diffs) {
14942: $changes{$provider} = 1;
14943: }
14944: }
14945: } elsif (@{$confhash{$provider}{'fields'}}) {
14946: $changes{$provider} = 1;
14947: }
14948: }
14949: if (ref($defaults{$provider}) eq 'ARRAY') {
14950: if (@{$defaults{$provider}} > 0) {
14951: my %options;
14952: if (ref($extended{$provider}) eq 'HASH') {
14953: %options = %{$extended{$provider}};
14954: }
14955: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14956: foreach my $field (@{$defaults{$provider}}) {
14957: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14958: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14959: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14960: push(@{$confhash{$provider}{'defaults'}},$poss);
14961: }
14962: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14963: foreach my $inner (keys(%{$options{$field}})) {
14964: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14965: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14966: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14967: $confhash{$provider}{'defaults'}{$inner} = $poss;
14968: }
14969: } else {
14970: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14971: }
14972: }
14973: } else {
14974: if (grep(/^\Q$field\E$/,@checked)) {
14975: push(@{$confhash{$provider}{'defaults'}},$field);
14976: }
14977: }
14978: }
14979: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14980: if (ref($current{'defaults'}) eq 'ARRAY') {
14981: unless ($changes{$provider}) {
14982: my @new = sort(@{$confhash{$provider}{'defaults'}});
14983: my @old = sort(@{$current{'defaults'}});
14984: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14985: if (@diffs) {
14986: $changes{$provider} = 1;
14987: }
14988: }
14989: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14990: if (@{$current{'defaults'}}) {
14991: $changes{$provider} = 1;
14992: }
14993: }
14994: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14995: if (ref($current{'defaults'}) eq 'HASH') {
14996: unless ($changes{$provider}) {
14997: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14998: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14999: $changes{$provider} = 1;
15000: last;
15001: }
15002: }
15003: }
15004: unless ($changes{$provider}) {
15005: foreach my $key (keys(%{$current{'defaults'}})) {
15006: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15007: $changes{$provider} = 1;
15008: last;
15009: }
15010: }
15011: }
15012: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15013: $changes{$provider} = 1;
15014: }
15015: }
15016: }
15017: }
15018: if (ref($crsconf{$provider}) eq 'ARRAY') {
15019: if (@{$crsconf{$provider}} > 0) {
15020: $confhash{$provider}{'crsconf'} = [];
15021: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15022: foreach my $crsfield (@{$crsconf{$provider}}) {
15023: if (grep(/^\Q$crsfield\E$/,@checked)) {
15024: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15025: }
15026: }
15027: if (ref($current{'crsconf'}) eq 'ARRAY') {
15028: unless ($changes{$provider}) {
15029: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15030: my @old = sort(@{$current{'crsconf'}});
15031: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15032: if (@diffs) {
15033: $changes{$provider} = 1;
15034: }
15035: }
15036: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15037: $changes{$provider} = 1;
15038: }
15039: }
15040: }
15041: if ($showroles) {
15042: $confhash{$provider}{'roles'} = {};
15043: foreach my $role (@courseroles) {
15044: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15045: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15046: $confhash{$provider}{'roles'}{$role} = $poss;
15047: }
15048: }
15049: unless ($changes{$provider}) {
15050: if (ref($current{'roles'}) eq 'HASH') {
15051: foreach my $role (keys(%{$current{'roles'}})) {
15052: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15053: $changes{$provider} = 1;
15054: last
15055: }
15056: }
15057: unless ($changes{$provider}) {
15058: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15059: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15060: $changes{$provider} = 1;
15061: last;
15062: }
15063: }
15064: }
15065: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15066: $changes{$provider} = 1;
15067: }
15068: }
15069: }
15070: if (ref($current{'custom'}) eq 'HASH') {
15071: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15072: foreach my $key (keys(%{$current{'custom'}})) {
15073: if (grep(/^\Q$key\E$/,@customdels)) {
15074: $changes{$provider} = 1;
15075: } else {
15076: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15077: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15078: $changes{$provider} = 1;
15079: }
15080: }
15081: }
15082: }
15083: if ($customadds{$provider}) {
15084: my $name = $env{'form.proctoring_custom_name_'.$provider};
15085: $name =~ s/(`)/'/g;
15086: $name =~ s/^\s+//;
15087: $name =~ s/\s+$//;
15088: my $value = $env{'form.proctoring_custom_value_'.$provider};
15089: $value =~ s/(`)/'/g;
15090: $value =~ s/^\s+//;
15091: $value =~ s/\s+$//;
15092: if ($name ne '') {
15093: $confhash{$provider}{'custom'}{$name} = $value;
15094: $changes{$provider} = 1;
15095: }
15096: }
15097: }
15098: }
15099: if (@allpos > 0) {
15100: my $idx = 0;
15101: foreach my $provider (@allpos) {
15102: if ($provider ne '') {
15103: $confhash{$provider}{'order'} = $idx;
15104: unless ($changes{$provider}) {
15105: if (ref($domconfig{$action}) eq 'HASH') {
15106: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15107: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15108: $changes{$provider} = 1;
15109: }
15110: }
15111: }
15112: }
15113: $idx ++;
15114: }
15115: }
15116: }
15117: my %proc_hash = (
15118: $action => { %confhash }
15119: );
15120: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15121: $dom);
15122: if ($putresult eq 'ok') {
15123: my %proc_enchash = (
15124: $action => { %encconfhash }
15125: );
1.384 raeburn 15126: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15127: if (keys(%changes) > 0) {
15128: my $cachetime = 24*60*60;
15129: my %procall = %confhash;
15130: foreach my $provider (keys(%procall)) {
15131: if (ref($encconfhash{$provider}) eq 'HASH') {
15132: foreach my $key ('key','secret') {
15133: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15134: }
15135: }
15136: }
15137: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15138: if (ref($lastactref) eq 'HASH') {
15139: $lastactref->{'proctoring'} = 1;
15140: }
15141: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15142: my %bynum;
15143: foreach my $provider (sort(keys(%changes))) {
15144: my $position = $confhash{$provider}{'order'};
15145: $bynum{$position} = $provider;
15146: }
15147: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15148: my $provider = $bynum{$pos};
15149: my %lt = &proctoring_titles($provider);
15150: my %fieldtitles = &proctoring_fieldtitles($provider);
15151: if (!$confhash{$provider}{'available'}) {
15152: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15153: } else {
15154: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15155: if ($confhash{$provider}{'image'}) {
15156: $resulttext .= ' '.
15157: '<img src="'.$confhash{$provider}{'image'}.'"'.
15158: ' alt="'.&mt('Proctoring icon').'" />';
15159: }
15160: $resulttext .= '<ul>';
15161: my $position = $pos + 1;
15162: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15163: foreach my $key ('version','sigmethod','url','lifetime') {
15164: if ($confhash{$provider}{$key} ne '') {
15165: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15166: }
15167: }
15168: if ($encconfhash{$provider}{'key'} ne '') {
15169: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15170: }
15171: if ($encconfhash{$provider}{'secret'} ne '') {
15172: $resulttext .= '<li>'.$lt{'secret'}.': ';
15173: my $num = length($encconfhash{$provider}{'secret'});
15174: $resulttext .= ('*'x$num).'</li>';
15175: }
15176: my (@fields,$showroles);
15177: if (ref($requserfields{$provider}) eq 'ARRAY') {
15178: push(@fields,@{$requserfields{$provider}});
15179: }
15180: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15181: push(@fields,@{$confhash{$provider}{'fields'}});
15182: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15183: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15184: }
15185: if (@fields) {
15186: if (grep(/^roles$/,@fields)) {
15187: $showroles = 1;
15188: }
15189: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15190: join('", "', map { $lt{$_}; } @fields).'"</li>';
15191: }
15192: if (ref($requserfields{$provider}) eq 'ARRAY') {
15193: if (grep(/^user$/,@{$requserfields{$provider}})) {
15194: if ($confhash{$provider}{'incdom'}) {
15195: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15196: } else {
15197: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15198: }
15199: }
15200: }
15201: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15202: if (@{$confhash{$provider}{'defaults'}} > 0) {
15203: $resulttext .= '<li>'.$lt{'defa'};
15204: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15205: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15206: }
15207: $resulttext =~ s/,$//;
15208: $resulttext .= '</li>';
15209: }
15210: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15211: if (keys(%{$confhash{$provider}{'defaults'}})) {
15212: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15213: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15214: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15215: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15216: }
15217: }
15218: $resulttext .= '</ul></li>';
15219: }
15220: }
15221: if (ref($crsconf{$provider}) eq 'ARRAY') {
15222: if (@{$crsconf{$provider}} > 0) {
15223: $resulttext .= '<li>'.&mt('Configurable in course:');
15224: my $numconfig = 0;
15225: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15226: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15227: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15228: $numconfig ++;
15229: if ($provider eq 'examity') {
15230: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15231: } else {
15232: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15233: }
15234: }
15235: $resulttext =~ s/,$//;
15236: }
15237: }
15238: if (!$numconfig) {
15239: $resulttext .= ' '.&mt('None');
15240: }
15241: $resulttext .= '</li>';
15242: }
15243: }
15244: if ($showroles) {
15245: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15246: my $rolemaps;
15247: foreach my $role (@courseroles) {
15248: if ($confhash{$provider}{'roles'}{$role}) {
15249: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15250: $confhash{$provider}{'roles'}{$role}.',';
15251: }
15252: }
15253: if ($rolemaps) {
15254: $rolemaps =~ s/,$//;
15255: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15256: }
15257: }
15258: }
15259: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15260: my $customlist;
15261: if (keys(%{$confhash{$provider}{'custom'}})) {
15262: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15263: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15264: }
15265: $customlist =~ s/,$//;
15266: }
15267: if ($customlist) {
15268: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15269: }
15270: }
15271: $resulttext .= '</ul></li>';
15272: }
15273: }
15274: $resulttext .= '</ul>';
15275: } else {
15276: $resulttext = &mt('No changes made.');
15277: }
15278: } else {
15279: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15280: }
15281: if ($errors) {
15282: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15283: $errors.'</ul>';
15284: }
15285: return $resulttext;
15286: }
15287:
15288: sub process_proctoring_image {
15289: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15290: my $filename = $env{'form.'.$caller.'.filename'};
15291: my ($error,$url);
15292: my ($width,$height) = (21,21);
15293: if ($configuserok eq 'ok') {
15294: if ($switchserver) {
15295: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15296: $switchserver);
15297: } elsif ($author_ok eq 'ok') {
15298: my ($result,$imageurl,$madethumb) =
15299: &publishlogo($r,'upload',$caller,$dom,$confname,
15300: "proctoring/$provider/icon",$width,$height);
15301: if ($result eq 'ok') {
15302: if ($madethumb) {
15303: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15304: my $imagethumb = "$path/tn-".$imagefile;
15305: $url = $imagethumb;
15306: } else {
15307: $url = $imageurl;
15308: }
15309: } else {
15310: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15311: }
15312: } else {
15313: $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);
15314: }
15315: } else {
15316: $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);
15317: }
15318: return ($url,$error);
15319: }
15320:
1.320 raeburn 15321: sub modify_lti {
15322: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15323: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15324: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
15325: my (%posslti,%posslticrs,%posscrstype);
15326: my @courseroles = ('cc','in','ta','ep','st');
15327: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15328: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15329: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15330: my %coursetypetitles = &Apache::lonlocal::texthash (
15331: official => 'Official',
15332: unofficial => 'Unofficial',
15333: community => 'Community',
15334: textbook => 'Textbook',
15335: placement => 'Placement Test',
1.392 raeburn 15336: lti => 'LTI Provider',
1.320 raeburn 15337: );
1.325 raeburn 15338: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15339: my %lt = <i_names();
15340: map { $posslti{$_} = 1; } @ltiroles;
15341: map { $posslticrs{$_} = 1; } @lticourseroles;
15342: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15343:
1.326 raeburn 15344: my %menutitles = <imenu_titles();
15345:
1.320 raeburn 15346: my (@items,%deletions,%itemids);
15347: if ($env{'form.lti_add'}) {
15348: my $consumer = $env{'form.lti_consumer_add'};
15349: $consumer =~ s/(`)/'/g;
15350: ($newid,my $error) = &get_lti_id($dom,$consumer);
15351: if ($newid) {
15352: $itemids{'add'} = $newid;
15353: push(@items,'add');
15354: $changes{$newid} = 1;
15355: } else {
15356: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15357: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15358: }
15359: }
15360: if (ref($domconfig{$action}) eq 'HASH') {
15361: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15362: if (@todelete) {
15363: map { $deletions{$_} = 1; } @todelete;
15364: }
15365: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15366: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15367: my $itemid = $env{'form.lti_id_'.$i};
15368: $itemid =~ s/\D+//g;
15369: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15370: if ($deletions{$itemid}) {
15371: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15372: } else {
1.390 raeburn 15373: push(@items,$i);
15374: $itemids{$i} = $itemid;
1.320 raeburn 15375: }
15376: }
15377: }
15378: }
15379: foreach my $idx (@items) {
15380: my $itemid = $itemids{$idx};
15381: next unless ($itemid);
1.390 raeburn 15382: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15383: $position =~ s/\D+//g;
15384: if ($position ne '') {
15385: $allpos[$position] = $itemid;
15386: }
1.391 raeburn 15387: foreach my $item ('consumer','key','secret','lifetime','requser','crsinc') {
1.320 raeburn 15388: my $formitem = 'form.lti_'.$item.'_'.$idx;
15389: $env{$formitem} =~ s/(`)/'/g;
15390: if ($item eq 'lifetime') {
15391: $env{$formitem} =~ s/[^\d.]//g;
15392: }
15393: if ($env{$formitem} ne '') {
15394: if (($item eq 'key') || ($item eq 'secret')) {
15395: $encconfig{$itemid}{$item} = $env{$formitem};
15396: } else {
15397: $confhash{$itemid}{$item} = $env{$formitem};
15398: unless (($idx eq 'add') || ($changes{$itemid})) {
15399: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
15400: $changes{$itemid} = 1;
15401: }
15402: }
15403: }
15404: }
15405: }
15406: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15407: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15408: }
1.345 raeburn 15409: if ($confhash{$itemid}{'requser'}) {
15410: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
15411: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
15412: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15413: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15414: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15415: my $mapuser = $env{'form.lti_customuser_'.$idx};
15416: $mapuser =~ s/(`)/'/g;
15417: $mapuser =~ s/^\s+|\s+$//g;
15418: $confhash{$itemid}{'mapuser'} = $mapuser;
15419: }
15420: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15421: my @makeuser;
15422: foreach my $ltirole (sort(@possmakeuser)) {
15423: if ($posslti{$ltirole}) {
15424: push(@makeuser,$ltirole);
15425: }
15426: }
15427: $confhash{$itemid}{'makeuser'} = \@makeuser;
15428: if (@makeuser) {
15429: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15430: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15431: $confhash{$itemid}{'lcauth'} = $lcauth;
15432: if ($lcauth ne 'internal') {
15433: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15434: $lcauthparm =~ s/^(\s+|\s+)$//g;
15435: $lcauthparm =~ s/`//g;
15436: if ($lcauthparm ne '') {
15437: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15438: }
15439: }
15440: } else {
15441: $confhash{$itemid}{'lcauth'} = 'lti';
15442: }
1.320 raeburn 15443: }
1.345 raeburn 15444: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15445: if (@possinstdata) {
15446: foreach my $field (@possinstdata) {
15447: if (exists($fieldtitles{$field})) {
15448: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15449: }
15450: }
15451: }
1.363 raeburn 15452: if ($env{'form.lti_callback_'.$idx}) {
15453: if ($env{'form.lti_callbackparam_'.$idx}) {
15454: my $callback = $env{'form.lti_callbackparam_'.$idx};
15455: $callback =~ s/^\s+|\s+$//g;
15456: $confhash{$itemid}{'callback'} = $callback;
15457: }
15458: }
1.391 raeburn 15459: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15460: if ($env{'form.lti_'.$field.'_'.$idx}) {
15461: $confhash{$itemid}{$field} = 1;
15462: }
1.320 raeburn 15463: }
1.345 raeburn 15464: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15465: $confhash{$itemid}{lcmenu} = [];
15466: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15467: foreach my $field (@possmenu) {
15468: if (exists($menutitles{$field})) {
15469: if ($field eq 'grades') {
15470: next unless ($env{'form.lti_inlinemenu_'.$idx});
15471: }
15472: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15473: }
15474: }
15475: }
1.391 raeburn 15476: if ($confhash{$itemid}{'crsinc'}) {
15477: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15478: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15479: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15480: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15481: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15482: $mapcrs =~ s/(`)/'/g;
15483: $mapcrs =~ s/^\s+|\s+$//g;
15484: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15485: }
15486: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15487: my @crstypes;
15488: foreach my $type (sort(@posstypes)) {
15489: if ($posscrstype{$type}) {
15490: push(@crstypes,$type);
15491: }
15492: }
15493: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15494: if ($env{'form.lti_storecrs_'.$idx}) {
15495: $confhash{$itemid}{'storecrs'} = 1;
15496: }
1.391 raeburn 15497: if ($env{'form.lti_makecrs_'.$idx}) {
15498: $confhash{$itemid}{'makecrs'} = 1;
15499: }
15500: foreach my $ltirole (@lticourseroles) {
15501: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15502: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15503: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15504: }
15505: }
15506: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15507: my @selfenroll;
15508: foreach my $type (sort(@possenroll)) {
15509: if ($posslticrs{$type}) {
15510: push(@selfenroll,$type);
15511: }
15512: }
15513: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15514: if ($env{'form.lti_crssec_'.$idx}) {
15515: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15516: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15517: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15518: my $section = $env{'form.lti_customsection_'.$idx};
15519: $section =~ s/(`)/'/g;
15520: $section =~ s/^\s+|\s+$//g;
15521: if ($section ne '') {
15522: $confhash{$itemid}{'section'} = $section;
15523: }
15524: }
15525: }
15526: foreach my $field ('passback','roster') {
15527: if ($env{'form.lti_'.$field.'_'.$idx}) {
15528: $confhash{$itemid}{$field} = 1;
15529: }
15530: }
15531: if ($env{'form.lti_passback_'.$idx}) {
15532: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15533: $confhash{$itemid}{'passbackformat'} = '1.0';
15534: } else {
15535: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15536: }
15537: }
1.391 raeburn 15538: }
15539: unless (($idx eq 'add') || ($changes{$itemid})) {
15540: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15541: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.391 raeburn 15542: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15543: $changes{$itemid} = 1;
15544: }
1.345 raeburn 15545: }
15546: unless ($changes{$itemid}) {
1.391 raeburn 15547: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
15548: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15549: $changes{$itemid} = 1;
15550: }
15551: }
1.345 raeburn 15552: }
1.391 raeburn 15553: foreach my $field ('mapcrstype','selfenroll') {
15554: unless ($changes{$itemid}) {
15555: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15556: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15557: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15558: $confhash{$itemid}{$field});
15559: if (@diffs) {
15560: $changes{$itemid} = 1;
15561: }
15562: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15563: $changes{$itemid} = 1;
15564: }
15565: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15566: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15567: $changes{$itemid} = 1;
15568: }
15569: }
1.391 raeburn 15570: }
15571: }
15572: unless ($changes{$itemid}) {
15573: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
15574: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15575: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
15576: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
15577: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15578: $changes{$itemid} = 1;
15579: last;
15580: }
15581: }
1.391 raeburn 15582: unless ($changes{$itemid}) {
15583: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15584: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
15585: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
15586: $changes{$itemid} = 1;
15587: last;
15588: }
15589: }
15590: }
15591: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
15592: $changes{$itemid} = 1;
1.345 raeburn 15593: }
1.391 raeburn 15594: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15595: unless ($changes{$itemid}) {
15596: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15597: $changes{$itemid} = 1;
15598: }
15599: }
15600: }
15601: }
15602: }
15603: unless ($changes{$itemid}) {
15604: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
15605: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15606: $changes{$itemid} = 1;
1.320 raeburn 15607: }
1.391 raeburn 15608: }
15609: unless ($changes{$itemid}) {
15610: foreach my $field ('makeuser','lcmenu') {
15611: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
15612: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15613: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
15614: $confhash{$itemid}{$field});
15615: if (@diffs) {
15616: $changes{$itemid} = 1;
15617: }
15618: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
15619: $changes{$itemid} = 1;
15620: }
15621: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15622: if (@{$confhash{$itemid}{$field}} > 0) {
15623: $changes{$itemid} = 1;
15624: }
1.345 raeburn 15625: }
1.320 raeburn 15626: }
15627: }
15628: }
15629: }
15630: }
15631: }
15632: if (@allpos > 0) {
15633: my $idx = 0;
15634: foreach my $itemid (@allpos) {
15635: if ($itemid ne '') {
15636: $confhash{$itemid}{'order'} = $idx;
15637: if (ref($domconfig{$action}) eq 'HASH') {
15638: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15639: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15640: $changes{$itemid} = 1;
15641: }
15642: }
15643: }
15644: $idx ++;
15645: }
15646: }
15647: }
15648: my %ltihash = (
15649: $action => { %confhash }
15650: );
15651: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
15652: $dom);
15653: if ($putresult eq 'ok') {
15654: my %ltienchash = (
15655: $action => { %encconfig }
15656: );
1.384 raeburn 15657: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.320 raeburn 15658: if (keys(%changes) > 0) {
15659: my $cachetime = 24*60*60;
15660: my %ltiall = %confhash;
15661: foreach my $id (keys(%ltiall)) {
15662: if (ref($encconfig{$id}) eq 'HASH') {
15663: foreach my $item ('key','secret') {
15664: $ltiall{$id}{$item} = $encconfig{$id}{$item};
15665: }
15666: }
15667: }
15668: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
15669: if (ref($lastactref) eq 'HASH') {
15670: $lastactref->{'lti'} = 1;
15671: }
15672: $resulttext = &mt('Changes made:').'<ul>';
15673: my %bynum;
15674: foreach my $itemid (sort(keys(%changes))) {
15675: my $position = $confhash{$itemid}{'order'};
15676: $bynum{$position} = $itemid;
15677: }
15678: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15679: my $itemid = $bynum{$pos};
15680: if (ref($confhash{$itemid}) ne 'HASH') {
15681: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
15682: } else {
1.390 raeburn 15683: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15684: my $position = $pos + 1;
15685: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15686: foreach my $item ('version','lifetime') {
15687: if ($confhash{$itemid}{$item} ne '') {
15688: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15689: }
15690: }
15691: if ($encconfig{$itemid}{'key'} ne '') {
15692: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
15693: }
15694: if ($encconfig{$itemid}{'secret'} ne '') {
15695: $resulttext .= '<li>'.$lt{'secret'}.': ';
15696: my $num = length($encconfig{$itemid}{'secret'});
15697: $resulttext .= ('*'x$num).'</li>';
15698: }
1.345 raeburn 15699: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15700: if ($confhash{$itemid}{'callback'}) {
15701: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15702: } else {
1.392 raeburn 15703: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15704: }
1.345 raeburn 15705: if ($confhash{$itemid}{'mapuser'}) {
15706: my $shownmapuser;
15707: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15708: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15709: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15710: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15711: } else {
15712: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15713: }
1.345 raeburn 15714: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15715: }
1.345 raeburn 15716: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15717: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15718: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15719: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15720: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15721: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15722: } else {
15723: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15724: $confhash{$itemid}{'lcauth'});
15725: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15726: $resulttext .= '; '.&mt('a randomly generated password will be created');
15727: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15728: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15729: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15730: }
15731: } else {
15732: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15733: }
15734: }
15735: $resulttext .= '</li>';
15736: } else {
15737: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15738: }
1.320 raeburn 15739: }
1.345 raeburn 15740: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15741: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15742: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15743: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15744: } else {
1.345 raeburn 15745: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15746: }
1.320 raeburn 15747: }
1.391 raeburn 15748: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15749: $resulttext .= '<li>'.$lt{$item}.': ';
15750: if ($confhash{$itemid}{$item}) {
15751: $resulttext .= &mt('Yes');
15752: } else {
15753: $resulttext .= &mt('No');
1.337 raeburn 15754: }
1.345 raeburn 15755: $resulttext .= '</li>';
1.320 raeburn 15756: }
1.345 raeburn 15757: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15758: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15759: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15760: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15761: } else {
15762: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15763: }
15764: }
15765: if ($confhash{$itemid}{'crsinc'}) {
15766: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15767: my $rolemaps;
15768: foreach my $role (@ltiroles) {
15769: if ($confhash{$itemid}{'maproles'}{$role}) {
15770: $rolemaps .= (' 'x2).$role.'='.
15771: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15772: 'Course').',';
15773: }
15774: }
15775: if ($rolemaps) {
15776: $rolemaps =~ s/,$//;
15777: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15778: }
15779: }
15780: if ($confhash{$itemid}{'mapcrs'}) {
15781: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15782: }
15783: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15784: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15785: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15786: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15787: '</li>';
15788: } else {
15789: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15790: }
15791: }
1.392 raeburn 15792: if ($confhash{$itemid}{'storecrs'}) {
15793: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
15794: }
1.391 raeburn 15795: if ($confhash{$itemid}{'makecrs'}) {
15796: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15797: } else {
15798: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15799: }
15800: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15801: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15802: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15803: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15804: '</li>';
15805: } else {
15806: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15807: }
15808: }
15809: if ($confhash{$itemid}{'section'}) {
15810: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15811: $resulttext .= '<li>'.&mt('User section from standard field:').
15812: ' (course_section_sourcedid)'.'</li>';
15813: } else {
15814: $resulttext .= '<li>'.&mt('User section from:').' '.
15815: $confhash{$itemid}{'section'}.'</li>';
15816: }
1.345 raeburn 15817: } else {
1.391 raeburn 15818: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15819: }
15820: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15821: $resulttext .= '<li>'.$lt{$item}.': ';
15822: if ($confhash{$itemid}{$item}) {
15823: $resulttext .= &mt('Yes');
15824: if ($item eq 'passback') {
15825: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15826: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15827: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15828: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15829: }
15830: }
15831: } else {
15832: $resulttext .= &mt('No');
15833: }
15834: $resulttext .= '</li>';
15835: }
15836: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15837: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15838: $resulttext .= '<li>'.&mt('Menu items:').' '.
15839: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15840: } else {
15841: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15842: }
1.345 raeburn 15843: }
1.326 raeburn 15844: }
15845: }
1.320 raeburn 15846: $resulttext .= '</ul></li>';
15847: }
15848: }
15849: $resulttext .= '</ul>';
15850: } else {
15851: $resulttext = &mt('No changes made.');
15852: }
15853: } else {
15854: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15855: }
15856: if ($errors) {
15857: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15858: $errors.'</ul>';
15859: }
15860: return $resulttext;
15861: }
15862:
15863: sub get_lti_id {
15864: my ($domain,$consumer) = @_;
15865: # get lock on lti db
15866: my $lockhash = {
15867: lock => $env{'user.name'}.
15868: ':'.$env{'user.domain'},
15869: };
15870: my $tries = 0;
15871: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15872: my ($id,$error);
15873:
15874: while (($gotlock ne 'ok') && ($tries<10)) {
15875: $tries ++;
15876: sleep (0.1);
15877: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15878: }
15879: if ($gotlock eq 'ok') {
15880: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15881: if ($currids{'lock'}) {
15882: delete($currids{'lock'});
15883: if (keys(%currids)) {
15884: my @curr = sort { $a <=> $b } keys(%currids);
15885: if ($curr[-1] =~ /^\d+$/) {
15886: $id = 1 + $curr[-1];
15887: }
15888: } else {
15889: $id = 1;
15890: }
15891: if ($id) {
15892: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15893: $error = 'nostore';
15894: }
15895: } else {
15896: $error = 'nonumber';
15897: }
15898: }
15899: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15900: } else {
15901: $error = 'nolock';
15902: }
15903: return ($id,$error);
15904: }
15905:
1.3 raeburn 15906: sub modify_autoenroll {
1.205 raeburn 15907: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15908: my ($resulttext,%changes);
15909: my %currautoenroll;
15910: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15911: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15912: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15913: }
15914: }
15915: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15916: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15917: sender => 'Sender for notification messages',
1.274 raeburn 15918: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
15919: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15920: my @offon = ('off','on');
1.17 raeburn 15921: my $sender_uname = $env{'form.sender_uname'};
15922: my $sender_domain = $env{'form.sender_domain'};
15923: if ($sender_domain eq '') {
15924: $sender_uname = '';
15925: } elsif ($sender_uname eq '') {
15926: $sender_domain = '';
15927: }
1.129 raeburn 15928: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 15929: my $failsafe = $env{'form.autoenroll_failsafe'};
15930: $failsafe =~ s{^\s+|\s+$}{}g;
15931: if ($failsafe =~ /\D/) {
15932: undef($failsafe);
15933: }
1.1 raeburn 15934: my %autoenrollhash = (
1.129 raeburn 15935: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15936: 'sender_uname' => $sender_uname,
15937: 'sender_domain' => $sender_domain,
15938: 'co-owners' => $coowners,
1.274 raeburn 15939: 'autofailsafe' => $failsafe,
1.1 raeburn 15940: }
15941: );
1.4 raeburn 15942: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15943: $dom);
1.1 raeburn 15944: if ($putresult eq 'ok') {
15945: if (exists($currautoenroll{'run'})) {
15946: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15947: $changes{'run'} = 1;
15948: }
15949: } elsif ($autorun) {
15950: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15951: $changes{'run'} = 1;
1.1 raeburn 15952: }
15953: }
1.17 raeburn 15954: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15955: $changes{'sender'} = 1;
15956: }
1.17 raeburn 15957: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15958: $changes{'sender'} = 1;
15959: }
1.129 raeburn 15960: if ($currautoenroll{'co-owners'} ne '') {
15961: if ($currautoenroll{'co-owners'} ne $coowners) {
15962: $changes{'coowners'} = 1;
15963: }
15964: } elsif ($coowners) {
15965: $changes{'coowners'} = 1;
1.274 raeburn 15966: }
15967: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
15968: $changes{'autofailsafe'} = 1;
15969: }
1.1 raeburn 15970: if (keys(%changes) > 0) {
15971: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15972: if ($changes{'run'}) {
1.1 raeburn 15973: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15974: }
15975: if ($changes{'sender'}) {
1.17 raeburn 15976: if ($sender_uname eq '' || $sender_domain eq '') {
15977: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15978: } else {
15979: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15980: }
1.1 raeburn 15981: }
1.129 raeburn 15982: if ($changes{'coowners'}) {
15983: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15984: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15985: if (ref($lastactref) eq 'HASH') {
15986: $lastactref->{'domainconfig'} = 1;
15987: }
1.129 raeburn 15988: }
1.274 raeburn 15989: if ($changes{'autofailsafe'}) {
15990: if ($failsafe ne '') {
1.299 raeburn 15991: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 15992: } else {
1.299 raeburn 15993: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 15994: }
15995: &Apache::lonnet::get_domain_defaults($dom,1);
15996: if (ref($lastactref) eq 'HASH') {
15997: $lastactref->{'domdefaults'} = 1;
15998: }
15999: }
1.1 raeburn 16000: $resulttext .= '</ul>';
16001: } else {
16002: $resulttext = &mt('No changes made to auto-enrollment settings');
16003: }
16004: } else {
1.11 albertel 16005: $resulttext = '<span class="LC_error">'.
16006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16007: }
1.3 raeburn 16008: return $resulttext;
1.1 raeburn 16009: }
16010:
16011: sub modify_autoupdate {
1.3 raeburn 16012: my ($dom,%domconfig) = @_;
1.1 raeburn 16013: my ($resulttext,%currautoupdate,%fields,%changes);
16014: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16015: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16016: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16017: }
16018: }
16019: my @offon = ('off','on');
16020: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16021: run => 'Auto-update:',
16022: classlists => 'Updates to user information in classlists?',
16023: unexpired => 'Skip updates for users without active or future roles?',
16024: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16025: );
1.44 raeburn 16026: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16027: my %fieldtitles = &Apache::lonlocal::texthash (
16028: id => 'Student/Employee ID',
1.20 raeburn 16029: permanentemail => 'E-mail address',
1.1 raeburn 16030: lastname => 'Last Name',
16031: firstname => 'First Name',
16032: middlename => 'Middle Name',
1.132 raeburn 16033: generation => 'Generation',
1.1 raeburn 16034: );
1.142 raeburn 16035: $othertitle = &mt('All users');
1.1 raeburn 16036: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16037: $othertitle = &mt('Other users');
1.1 raeburn 16038: }
16039: foreach my $key (keys(%env)) {
16040: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16041: my ($usertype,$item) = ($1,$2);
16042: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16043: if ($usertype eq 'default') {
16044: push(@{$fields{$1}},$2);
16045: } elsif (ref($types) eq 'ARRAY') {
16046: if (grep(/^\Q$usertype\E$/,@{$types})) {
16047: push(@{$fields{$1}},$2);
16048: }
16049: }
16050: }
1.1 raeburn 16051: }
16052: }
1.131 raeburn 16053: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16054: @lockablenames = sort(@lockablenames);
16055: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16056: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16057: if (@changed) {
16058: $changes{'lockablenames'} = 1;
16059: }
16060: } else {
16061: if (@lockablenames) {
16062: $changes{'lockablenames'} = 1;
16063: }
16064: }
1.1 raeburn 16065: my %updatehash = (
16066: autoupdate => { run => $env{'form.autoupdate_run'},
16067: classlists => $env{'form.classlists'},
1.385 raeburn 16068: unexpired => $env{'form.unexpired'},
1.1 raeburn 16069: fields => {%fields},
1.131 raeburn 16070: lockablenames => \@lockablenames,
1.1 raeburn 16071: }
16072: );
1.385 raeburn 16073: my $lastactivedays;
16074: if ($env{'form.lastactive'}) {
16075: $lastactivedays = $env{'form.lastactivedays'};
16076: $lastactivedays =~ s/^\s+|\s+$//g;
16077: unless ($lastactivedays =~ /^\d+$/) {
16078: undef($lastactivedays);
16079: $env{'form.lastactive'} = 0;
16080: }
16081: }
16082: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16083: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16084: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16085: if (exists($updatehash{autoupdate}{$key})) {
16086: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16087: $changes{$key} = 1;
16088: }
16089: }
16090: } elsif ($key eq 'fields') {
16091: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16092: foreach my $item (@{$types},'default') {
1.1 raeburn 16093: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16094: my $change = 0;
16095: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16096: if (!exists($fields{$item})) {
16097: $change = 1;
1.132 raeburn 16098: last;
1.1 raeburn 16099: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16100: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16101: $change = 1;
1.132 raeburn 16102: last;
1.1 raeburn 16103: }
16104: }
16105: }
16106: if ($change) {
16107: push(@{$changes{$key}},$item);
16108: }
1.26 raeburn 16109: }
1.1 raeburn 16110: }
16111: }
1.131 raeburn 16112: } elsif ($key eq 'lockablenames') {
16113: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16114: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16115: if (@changed) {
16116: $changes{'lockablenames'} = 1;
16117: }
16118: } else {
16119: if (@lockablenames) {
16120: $changes{'lockablenames'} = 1;
16121: }
16122: }
16123: }
16124: }
16125: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16126: if (@lockablenames) {
16127: $changes{'lockablenames'} = 1;
1.1 raeburn 16128: }
16129: }
1.385 raeburn 16130: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16131: if ($updatehash{'autoupdate'}{'unexpired'}) {
16132: $changes{'unexpired'} = 1;
16133: }
16134: }
16135: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16136: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16137: $changes{'lastactive'} = 1;
16138: }
16139: }
1.26 raeburn 16140: foreach my $item (@{$types},'default') {
16141: if (defined($fields{$item})) {
16142: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16143: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16144: my $change = 0;
16145: if (ref($fields{$item}) eq 'ARRAY') {
16146: foreach my $type (@{$fields{$item}}) {
16147: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16148: $change = 1;
16149: last;
16150: }
16151: }
16152: }
16153: if ($change) {
16154: push(@{$changes{'fields'}},$item);
16155: }
16156: } else {
1.26 raeburn 16157: push(@{$changes{'fields'}},$item);
16158: }
16159: } else {
16160: push(@{$changes{'fields'}},$item);
1.1 raeburn 16161: }
16162: }
16163: }
16164: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16165: $dom);
16166: if ($putresult eq 'ok') {
16167: if (keys(%changes) > 0) {
16168: $resulttext = &mt('Changes made:').'<ul>';
16169: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16170: if ($key eq 'lockablenames') {
16171: $resulttext .= '<li>';
16172: if (@lockablenames) {
16173: $usertypes->{'default'} = $othertitle;
16174: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16175: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16176: } else {
16177: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16178: }
16179: $resulttext .= '</li>';
16180: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16181: foreach my $item (@{$changes{$key}}) {
16182: my @newvalues;
16183: foreach my $type (@{$fields{$item}}) {
16184: push(@newvalues,$fieldtitles{$type});
16185: }
1.3 raeburn 16186: my $newvaluestr;
16187: if (@newvalues > 0) {
16188: $newvaluestr = join(', ',@newvalues);
16189: } else {
16190: $newvaluestr = &mt('none');
1.6 raeburn 16191: }
1.1 raeburn 16192: if ($item eq 'default') {
1.26 raeburn 16193: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16194: } else {
1.26 raeburn 16195: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16196: }
16197: }
16198: } else {
16199: my $newvalue;
16200: if ($key eq 'run') {
16201: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16202: } elsif ($key eq 'lastactive') {
16203: $newvalue = $offon[$env{'form.lastactive'}];
16204: unless ($lastactivedays eq '') {
16205: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16206: }
1.1 raeburn 16207: } else {
16208: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16209: }
1.1 raeburn 16210: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16211: }
16212: }
16213: $resulttext .= '</ul>';
16214: } else {
1.3 raeburn 16215: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16216: }
16217: } else {
1.11 albertel 16218: $resulttext = '<span class="LC_error">'.
16219: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16220: }
1.3 raeburn 16221: return $resulttext;
1.1 raeburn 16222: }
16223:
1.125 raeburn 16224: sub modify_autocreate {
16225: my ($dom,%domconfig) = @_;
16226: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16227: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16228: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16229: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16230: }
16231: }
16232: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16233: req => 'Auto-creation of validated requests for official courses',
16234: xmldc => 'Identity of course creator of courses from XML files',
16235: );
16236: my @types = ('xml','req');
16237: foreach my $item (@types) {
16238: $newvals{$item} = $env{'form.autocreate_'.$item};
16239: $newvals{$item} =~ s/\D//g;
16240: $newvals{$item} = 0 if ($newvals{$item} eq '');
16241: }
16242: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16243: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16244: unless (exists($domcoords{$newvals{'xmldc'}})) {
16245: $newvals{'xmldc'} = '';
16246: }
16247: %autocreatehash = (
16248: autocreate => { xml => $newvals{'xml'},
16249: req => $newvals{'req'},
16250: }
16251: );
16252: if ($newvals{'xmldc'} ne '') {
16253: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16254: }
16255: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16256: $dom);
16257: if ($putresult eq 'ok') {
16258: my @items = @types;
16259: if ($newvals{'xml'}) {
16260: push(@items,'xmldc');
16261: }
16262: foreach my $item (@items) {
16263: if (exists($currautocreate{$item})) {
16264: if ($currautocreate{$item} ne $newvals{$item}) {
16265: $changes{$item} = 1;
16266: }
16267: } elsif ($newvals{$item}) {
16268: $changes{$item} = 1;
16269: }
16270: }
16271: if (keys(%changes) > 0) {
16272: my @offon = ('off','on');
16273: $resulttext = &mt('Changes made:').'<ul>';
16274: foreach my $item (@types) {
16275: if ($changes{$item}) {
16276: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16277: $resulttext .= '<li>'.
16278: &mt("$title{$item} set to [_1]$newtxt [_2]",
16279: '<b>','</b>').
16280: '</li>';
1.125 raeburn 16281: }
16282: }
16283: if ($changes{'xmldc'}) {
16284: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16285: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16286: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16287: }
16288: $resulttext .= '</ul>';
16289: } else {
16290: $resulttext = &mt('No changes made to auto-creation settings');
16291: }
16292: } else {
16293: $resulttext = '<span class="LC_error">'.
16294: &mt('An error occurred: [_1]',$putresult).'</span>';
16295: }
16296: return $resulttext;
16297: }
16298:
1.23 raeburn 16299: sub modify_directorysrch {
1.295 raeburn 16300: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16301: my ($resulttext,%changes);
16302: my %currdirsrch;
16303: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16304: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16305: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16306: }
16307: }
1.277 raeburn 16308: my %title = ( available => 'Institutional directory search available',
16309: localonly => 'Other domains can search institution',
16310: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16311: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16312: searchby => 'Search types',
16313: searchtypes => 'Search latitude');
16314: my @offon = ('off','on');
1.24 raeburn 16315: my @otherdoms = ('Yes','No');
1.23 raeburn 16316:
1.25 raeburn 16317: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16318: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16319: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16320:
1.44 raeburn 16321: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16322: if (keys(%{$usertypes}) == 0) {
16323: @cansearch = ('default');
16324: } else {
16325: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16326: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16327: if (!grep(/^\Q$type\E$/,@cansearch)) {
16328: push(@{$changes{'cansearch'}},$type);
16329: }
1.23 raeburn 16330: }
1.26 raeburn 16331: foreach my $type (@cansearch) {
16332: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16333: push(@{$changes{'cansearch'}},$type);
16334: }
1.23 raeburn 16335: }
1.26 raeburn 16336: } else {
16337: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16338: }
16339: }
16340:
16341: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16342: foreach my $by (@{$currdirsrch{'searchby'}}) {
16343: if (!grep(/^\Q$by\E$/,@searchby)) {
16344: push(@{$changes{'searchby'}},$by);
16345: }
16346: }
16347: foreach my $by (@searchby) {
16348: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16349: push(@{$changes{'searchby'}},$by);
16350: }
16351: }
16352: } else {
16353: push(@{$changes{'searchby'}},@searchby);
16354: }
1.25 raeburn 16355:
16356: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16357: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16358: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16359: push(@{$changes{'searchtypes'}},$type);
16360: }
16361: }
16362: foreach my $type (@searchtypes) {
16363: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16364: push(@{$changes{'searchtypes'}},$type);
16365: }
16366: }
16367: } else {
16368: if (exists($currdirsrch{'searchtypes'})) {
16369: foreach my $type (@searchtypes) {
16370: if ($type ne $currdirsrch{'searchtypes'}) {
16371: push(@{$changes{'searchtypes'}},$type);
16372: }
16373: }
16374: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16375: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16376: }
16377: } else {
16378: push(@{$changes{'searchtypes'}},@searchtypes);
16379: }
16380: }
16381:
1.23 raeburn 16382: my %dirsrch_hash = (
16383: directorysrch => { available => $env{'form.dirsrch_available'},
16384: cansearch => \@cansearch,
1.277 raeburn 16385: localonly => $env{'form.dirsrch_instlocalonly'},
16386: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16387: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16388: searchby => \@searchby,
1.25 raeburn 16389: searchtypes => \@searchtypes,
1.23 raeburn 16390: }
16391: );
16392: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16393: $dom);
16394: if ($putresult eq 'ok') {
16395: if (exists($currdirsrch{'available'})) {
16396: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16397: $changes{'available'} = 1;
16398: }
16399: } else {
16400: if ($env{'form.dirsrch_available'} eq '1') {
16401: $changes{'available'} = 1;
16402: }
16403: }
1.277 raeburn 16404: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16405: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16406: $changes{'lcavailable'} = 1;
16407: }
1.277 raeburn 16408: } else {
16409: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16410: $changes{'lcavailable'} = 1;
16411: }
16412: }
1.24 raeburn 16413: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16414: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16415: $changes{'localonly'} = 1;
16416: }
1.24 raeburn 16417: } else {
1.277 raeburn 16418: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16419: $changes{'localonly'} = 1;
16420: }
16421: }
1.277 raeburn 16422: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16423: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16424: $changes{'lclocalonly'} = 1;
16425: }
1.277 raeburn 16426: } else {
16427: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16428: $changes{'lclocalonly'} = 1;
16429: }
16430: }
1.23 raeburn 16431: if (keys(%changes) > 0) {
16432: $resulttext = &mt('Changes made:').'<ul>';
16433: if ($changes{'available'}) {
16434: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16435: }
1.277 raeburn 16436: if ($changes{'lcavailable'}) {
16437: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16438: }
1.24 raeburn 16439: if ($changes{'localonly'}) {
1.277 raeburn 16440: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16441: }
1.277 raeburn 16442: if ($changes{'lclocalonly'}) {
16443: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16444: }
1.23 raeburn 16445: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16446: my $chgtext;
1.26 raeburn 16447: if (ref($usertypes) eq 'HASH') {
16448: if (keys(%{$usertypes}) > 0) {
16449: foreach my $type (@{$types}) {
16450: if (grep(/^\Q$type\E$/,@cansearch)) {
16451: $chgtext .= $usertypes->{$type}.'; ';
16452: }
16453: }
16454: if (grep(/^default$/,@cansearch)) {
16455: $chgtext .= $othertitle;
16456: } else {
16457: $chgtext =~ s/\; $//;
16458: }
1.210 raeburn 16459: $resulttext .=
1.178 raeburn 16460: '<li>'.
16461: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16462: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16463: '</li>';
1.23 raeburn 16464: }
16465: }
16466: }
16467: if (ref($changes{'searchby'}) eq 'ARRAY') {
16468: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16469: my $chgtext;
16470: foreach my $type (@{$titleorder}) {
16471: if (grep(/^\Q$type\E$/,@searchby)) {
16472: if (defined($searchtitles->{$type})) {
16473: $chgtext .= $searchtitles->{$type}.'; ';
16474: }
16475: }
16476: }
16477: $chgtext =~ s/\; $//;
16478: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16479: }
1.25 raeburn 16480: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16481: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16482: my $chgtext;
16483: foreach my $type (@{$srchtypeorder}) {
16484: if (grep(/^\Q$type\E$/,@searchtypes)) {
16485: if (defined($srchtypes_desc->{$type})) {
16486: $chgtext .= $srchtypes_desc->{$type}.'; ';
16487: }
16488: }
16489: }
16490: $chgtext =~ s/\; $//;
1.178 raeburn 16491: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16492: }
16493: $resulttext .= '</ul>';
1.295 raeburn 16494: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16495: if (ref($lastactref) eq 'HASH') {
16496: $lastactref->{'directorysrch'} = 1;
16497: }
1.23 raeburn 16498: } else {
1.277 raeburn 16499: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 16500: }
16501: } else {
16502: $resulttext = '<span class="LC_error">'.
1.27 raeburn 16503: &mt('An error occurred: [_1]',$putresult).'</span>';
16504: }
16505: return $resulttext;
16506: }
16507:
1.28 raeburn 16508: sub modify_contacts {
1.205 raeburn 16509: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 16510: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
16511: if (ref($domconfig{'contacts'}) eq 'HASH') {
16512: foreach my $key (keys(%{$domconfig{'contacts'}})) {
16513: $currsetting{$key} = $domconfig{'contacts'}{$key};
16514: }
16515: }
1.286 raeburn 16516: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 16517: my @contacts = ('supportemail','adminemail');
1.286 raeburn 16518: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 16519: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 16520: my @toggles = ('reporterrors','reportupdates','reportstatus');
16521: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 16522: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 16523: foreach my $type (@mailings) {
16524: @{$newsetting{$type}} =
16525: &Apache::loncommon::get_env_multiple('form.'.$type);
16526: foreach my $item (@contacts) {
16527: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
16528: $contacts_hash{contacts}{$type}{$item} = 1;
16529: } else {
16530: $contacts_hash{contacts}{$type}{$item} = 0;
16531: }
1.289 raeburn 16532: }
1.28 raeburn 16533: $others{$type} = $env{'form.'.$type.'_others'};
16534: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 16535: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16536: $bcc{$type} = $env{'form.'.$type.'_bcc'};
16537: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 16538: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
16539: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16540: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16541: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16542: }
1.134 raeburn 16543: }
1.28 raeburn 16544: }
16545: foreach my $item (@contacts) {
16546: $to{$item} = $env{'form.'.$item};
16547: $contacts_hash{'contacts'}{$item} = $to{$item};
16548: }
1.203 raeburn 16549: foreach my $item (@toggles) {
16550: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16551: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16552: }
16553: }
1.340 raeburn 16554: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16555: foreach my $item (@lonstatus) {
16556: if ($item eq 'excluded') {
16557: my (%serverhomes,@excluded);
16558: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16559: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16560: if (@possexcluded) {
16561: foreach my $id (sort(@possexcluded)) {
16562: if ($serverhomes{$id}) {
16563: push(@excluded,$id);
16564: }
16565: }
16566: }
16567: if (@excluded) {
16568: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16569: }
16570: } elsif ($item eq 'weights') {
1.377 raeburn 16571: foreach my $type ('E','W','N','U') {
1.340 raeburn 16572: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16573: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16574: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16575: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16576: $env{'form.error'.$item.'_'.$type};
16577: }
16578: }
16579: }
16580: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16581: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16582: if ($env{'form.error'.$item} =~ /^\d+$/) {
16583: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16584: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16585: }
16586: }
16587: }
16588: }
1.286 raeburn 16589: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16590: foreach my $field (@{$fields}) {
16591: if (ref($possoptions->{$field}) eq 'ARRAY') {
16592: my $value = $env{'form.helpform_'.$field};
16593: $value =~ s/^\s+|\s+$//g;
16594: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16595: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16596: if ($field eq 'screenshot') {
16597: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16598: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16599: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16600: }
16601: }
16602: }
16603: }
16604: }
16605: }
1.315 raeburn 16606: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16607: my (@statuses,%usertypeshash,@overrides);
16608: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16609: @statuses = @{$types};
16610: if (ref($usertypes) eq 'HASH') {
16611: %usertypeshash = %{$usertypes};
16612: }
16613: }
16614: if (@statuses) {
16615: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16616: foreach my $type (@possoverrides) {
16617: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16618: push(@overrides,$type);
16619: }
16620: }
16621: if (@overrides) {
16622: foreach my $type (@overrides) {
16623: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16624: foreach my $item (@contacts) {
16625: if (grep(/^\Q$item\E$/,@standard)) {
16626: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16627: $newsetting{'override_'.$type}{$item} = 1;
16628: } else {
16629: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16630: $newsetting{'override_'.$type}{$item} = 0;
16631: }
16632: }
16633: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16634: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16635: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16636: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16637: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16638: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16639: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16640: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16641: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16642: }
16643: }
16644: }
16645: }
1.28 raeburn 16646: if (keys(%currsetting) > 0) {
16647: foreach my $item (@contacts) {
16648: if ($to{$item} ne $currsetting{$item}) {
16649: $changes{$item} = 1;
16650: }
16651: }
16652: foreach my $type (@mailings) {
16653: foreach my $item (@contacts) {
16654: if (ref($currsetting{$type}) eq 'HASH') {
16655: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16656: push(@{$changes{$type}},$item);
16657: }
16658: } else {
16659: push(@{$changes{$type}},@{$newsetting{$type}});
16660: }
16661: }
16662: if ($others{$type} ne $currsetting{$type}{'others'}) {
16663: push(@{$changes{$type}},'others');
16664: }
1.289 raeburn 16665: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16666: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16667: push(@{$changes{$type}},'bcc');
16668: }
1.286 raeburn 16669: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16670: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16671: push(@{$changes{$type}},'include');
16672: }
16673: }
16674: }
16675: if (ref($fields) eq 'ARRAY') {
16676: if (ref($currsetting{'helpform'}) eq 'HASH') {
16677: foreach my $field (@{$fields}) {
16678: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16679: push(@{$changes{'helpform'}},$field);
16680: }
16681: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16682: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16683: push(@{$changes{'helpform'}},'maxsize');
16684: }
16685: }
16686: }
16687: } else {
16688: foreach my $field (@{$fields}) {
16689: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16690: push(@{$changes{'helpform'}},$field);
16691: }
16692: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16693: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16694: push(@{$changes{'helpform'}},'maxsize');
16695: }
16696: }
16697: }
1.134 raeburn 16698: }
1.28 raeburn 16699: }
1.315 raeburn 16700: if (@statuses) {
16701: if (ref($currsetting{'overrides'}) eq 'HASH') {
16702: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16703: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16704: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16705: foreach my $item (@contacts,'bcc','others','include') {
16706: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16707: push(@{$changes{'overrides'}},$key);
16708: last;
16709: }
16710: }
16711: } else {
16712: push(@{$changes{'overrides'}},$key);
16713: }
16714: }
16715: }
16716: foreach my $key (@overrides) {
16717: unless (exists($currsetting{'overrides'}{$key})) {
16718: push(@{$changes{'overrides'}},$key);
16719: }
16720: }
16721: } else {
16722: foreach my $key (@overrides) {
16723: push(@{$changes{'overrides'}},$key);
16724: }
16725: }
16726: }
1.340 raeburn 16727: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16728: foreach my $key ('excluded','weights','threshold','sysmail') {
16729: if ($key eq 'excluded') {
16730: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16731: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16732: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16733: (@{$currsetting{'lonstatus'}{$key}})) {
16734: my @diffs =
16735: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16736: $currsetting{'lonstatus'}{$key});
16737: if (@diffs) {
16738: push(@{$changes{'lonstatus'}},$key);
16739: }
16740: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16741: push(@{$changes{'lonstatus'}},$key);
16742: }
16743: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16744: (@{$currsetting{'lonstatus'}{$key}})) {
16745: push(@{$changes{'lonstatus'}},$key);
16746: }
16747: } elsif ($key eq 'weights') {
16748: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16749: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16750: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16751: foreach my $type ('E','W','N','U') {
1.340 raeburn 16752: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16753: $currsetting{'lonstatus'}{$key}{$type}) {
16754: push(@{$changes{'lonstatus'}},$key);
16755: last;
16756: }
16757: }
16758: } else {
1.341 raeburn 16759: foreach my $type ('E','W','N','U') {
1.340 raeburn 16760: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16761: push(@{$changes{'lonstatus'}},$key);
16762: last;
16763: }
16764: }
16765: }
16766: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16767: foreach my $type ('E','W','N','U') {
1.340 raeburn 16768: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16769: push(@{$changes{'lonstatus'}},$key);
16770: last;
16771: }
16772: }
16773: }
16774: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16775: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16776: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16777: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16778: push(@{$changes{'lonstatus'}},$key);
16779: }
16780: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16781: push(@{$changes{'lonstatus'}},$key);
16782: }
16783: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16784: push(@{$changes{'lonstatus'}},$key);
16785: }
16786: }
16787: }
16788: } else {
16789: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16790: foreach my $key ('excluded','weights','threshold','sysmail') {
16791: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16792: push(@{$changes{'lonstatus'}},$key);
16793: }
16794: }
16795: }
16796: }
1.28 raeburn 16797: } else {
16798: my %default;
16799: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16800: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16801: $default{'errormail'} = 'adminemail';
16802: $default{'packagesmail'} = 'adminemail';
16803: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16804: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16805: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16806: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16807: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16808: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16809: foreach my $item (@contacts) {
16810: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16811: $changes{$item} = 1;
1.203 raeburn 16812: }
1.28 raeburn 16813: }
16814: foreach my $type (@mailings) {
16815: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16816: push(@{$changes{$type}},@{$newsetting{$type}});
16817: }
16818: if ($others{$type} ne '') {
16819: push(@{$changes{$type}},'others');
1.134 raeburn 16820: }
1.286 raeburn 16821: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16822: if ($bcc{$type} ne '') {
16823: push(@{$changes{$type}},'bcc');
16824: }
1.286 raeburn 16825: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16826: push(@{$changes{$type}},'include');
16827: }
1.134 raeburn 16828: }
1.28 raeburn 16829: }
1.286 raeburn 16830: if (ref($fields) eq 'ARRAY') {
16831: foreach my $field (@{$fields}) {
16832: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16833: push(@{$changes{'helpform'}},$field);
16834: }
16835: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16836: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16837: push(@{$changes{'helpform'}},'maxsize');
16838: }
16839: }
16840: }
1.289 raeburn 16841: }
1.340 raeburn 16842: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16843: foreach my $key ('excluded','weights','threshold','sysmail') {
16844: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16845: push(@{$changes{'lonstatus'}},$key);
16846: }
16847: }
16848: }
1.28 raeburn 16849: }
1.203 raeburn 16850: foreach my $item (@toggles) {
16851: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16852: $changes{$item} = 1;
16853: } elsif ((!$env{'form.'.$item}) &&
16854: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16855: $changes{$item} = 1;
16856: }
16857: }
1.28 raeburn 16858: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16859: $dom);
16860: if ($putresult eq 'ok') {
16861: if (keys(%changes) > 0) {
1.205 raeburn 16862: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16863: if (ref($lastactref) eq 'HASH') {
16864: $lastactref->{'domainconfig'} = 1;
16865: }
1.28 raeburn 16866: my ($titles,$short_titles) = &contact_titles();
16867: $resulttext = &mt('Changes made:').'<ul>';
16868: foreach my $item (@contacts) {
16869: if ($changes{$item}) {
16870: $resulttext .= '<li>'.$titles->{$item}.
16871: &mt(' set to: ').
16872: '<span class="LC_cusr_emph">'.
16873: $to{$item}.'</span></li>';
16874: }
16875: }
16876: foreach my $type (@mailings) {
16877: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16878: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16879: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16880: } else {
16881: $resulttext .= '<li>'.$titles->{$type}.': ';
16882: }
1.28 raeburn 16883: my @text;
16884: foreach my $item (@{$newsetting{$type}}) {
16885: push(@text,$short_titles->{$item});
16886: }
16887: if ($others{$type} ne '') {
16888: push(@text,$others{$type});
16889: }
1.286 raeburn 16890: if (@text) {
16891: $resulttext .= '<span class="LC_cusr_emph">'.
16892: join(', ',@text).'</span>';
16893: }
16894: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16895: if ($bcc{$type} ne '') {
1.286 raeburn 16896: my $bcctext;
16897: if (@text) {
1.289 raeburn 16898: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16899: } else {
16900: $bcctext = '(Bcc)';
16901: }
16902: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16903: } elsif (!@text) {
16904: $resulttext .= &mt('No one');
16905: }
1.289 raeburn 16906: if ($includestr{$type} ne '') {
1.286 raeburn 16907: if ($includeloc{$type} eq 'b') {
16908: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16909: } elsif ($includeloc{$type} eq 's') {
16910: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16911: }
1.134 raeburn 16912: }
1.286 raeburn 16913: } elsif (!@text) {
16914: $resulttext .= &mt('No recipients');
1.134 raeburn 16915: }
16916: $resulttext .= '</li>';
1.28 raeburn 16917: }
16918: }
1.315 raeburn 16919: if (ref($changes{'overrides'}) eq 'ARRAY') {
16920: my @deletions;
16921: foreach my $type (@{$changes{'overrides'}}) {
16922: if ($usertypeshash{$type}) {
16923: if (grep(/^\Q$type\E/,@overrides)) {
16924: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16925: $usertypeshash{$type}).'<ul><li>';
16926: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16927: my @text;
16928: foreach my $item (@contacts) {
16929: if ($newsetting{'override_'.$type}{$item}) {
16930: push(@text,$short_titles->{$item});
16931: }
16932: }
16933: if ($newsetting{'override_'.$type}{'others'} ne '') {
16934: push(@text,$newsetting{'override_'.$type}{'others'});
16935: }
16936:
16937: if (@text) {
16938: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16939: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16940: }
16941: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16942: my $bcctext;
16943: if (@text) {
16944: $bcctext = ' '.&mt('with Bcc to');
16945: } else {
16946: $bcctext = '(Bcc)';
16947: }
16948: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16949: } elsif (!@text) {
16950: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16951: }
16952: $resulttext .= '</li>';
16953: if ($newsetting{'override_'.$type}{'include'} ne '') {
16954: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16955: if ($loc eq 'b') {
16956: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16957: } elsif ($loc eq 's') {
16958: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16959: }
16960: }
16961: }
16962: $resulttext .= '</li></ul></li>';
16963: } else {
16964: push(@deletions,$usertypeshash{$type});
16965: }
16966: }
16967: }
16968: if (@deletions) {
16969: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16970: join(', ',@deletions)).'</li>';
16971: }
16972: }
1.203 raeburn 16973: my @offon = ('off','on');
1.340 raeburn 16974: my $corelink = &core_link_msu();
1.203 raeburn 16975: if ($changes{'reporterrors'}) {
16976: $resulttext .= '<li>'.
16977: &mt('E-mail error reports to [_1] set to "'.
16978: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16979: $corelink).
1.203 raeburn 16980: '</li>';
16981: }
16982: if ($changes{'reportupdates'}) {
16983: $resulttext .= '<li>'.
16984: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
16985: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 16986: $corelink).
1.203 raeburn 16987: '</li>';
16988: }
1.340 raeburn 16989: if ($changes{'reportstatus'}) {
16990: $resulttext .= '<li>'.
16991: &mt('E-mail status if errors above threshold to [_1] set to "'.
16992: $offon[$env{'form.reportstatus'}].'".',
16993: $corelink).
16994: '</li>';
16995: }
16996: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
16997: $resulttext .= '<li>'.
16998: &mt('Nightly status check e-mail settings').':<ul>';
16999: my (%defval,%use_def,%shown);
17000: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17001: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17002: $defval{'weights'} =
1.341 raeburn 17003: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17004: $defval{'excluded'} = &mt('None');
17005: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17006: foreach my $item ('threshold','sysmail','weights','excluded') {
17007: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17008: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17009: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17010: } elsif ($item eq 'weights') {
17011: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17012: foreach my $type ('E','W','N','U') {
1.340 raeburn 17013: $shown{$item} .= $lonstatus_names->{$type}.'=';
17014: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17015: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17016: } else {
17017: $shown{$item} .= $lonstatus_defs->{$type};
17018: }
17019: $shown{$item} .= ', ';
17020: }
17021: $shown{$item} =~ s/, $//;
17022: } else {
17023: $shown{$item} = $defval{$item};
17024: }
17025: } elsif ($item eq 'excluded') {
17026: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17027: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17028: } else {
17029: $shown{$item} = $defval{$item};
17030: }
17031: }
17032: } else {
17033: $shown{$item} = $defval{$item};
17034: }
17035: }
17036: } else {
17037: foreach my $item ('threshold','weights','excluded','sysmail') {
17038: $shown{$item} = $defval{$item};
17039: }
17040: }
17041: foreach my $item ('threshold','weights','excluded','sysmail') {
17042: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17043: $shown{$item}).'</li>';
17044: }
17045: $resulttext .= '</ul></li>';
17046: }
1.286 raeburn 17047: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17048: my (@optional,@required,@unused,$maxsizechg);
17049: foreach my $field (@{$changes{'helpform'}}) {
17050: if ($field eq 'maxsize') {
17051: $maxsizechg = 1;
17052: next;
17053: }
17054: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17055: push(@optional,$field);
1.286 raeburn 17056: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17057: push(@unused,$field);
17058: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17059: push(@required,$field);
1.286 raeburn 17060: }
17061: }
17062: if (@optional) {
17063: $resulttext .= '<li>'.
17064: &mt('Help form fields changed to "Optional": [_1].',
17065: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17066: '</li>';
17067: }
17068: if (@required) {
17069: $resulttext .= '<li>'.
17070: &mt('Help form fields changed to "Required": [_1].',
17071: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17072: '</li>';
17073: }
17074: if (@unused) {
17075: $resulttext .= '<li>'.
17076: &mt('Help form fields changed to "Not shown": [_1].',
17077: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17078: '</li>';
17079: }
17080: if ($maxsizechg) {
17081: $resulttext .= '<li>'.
17082: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17083: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17084: '</li>';
17085: }
17086: }
1.28 raeburn 17087: $resulttext .= '</ul>';
17088: } else {
1.288 raeburn 17089: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17090: }
17091: } else {
17092: $resulttext = '<span class="LC_error">'.
17093: &mt('An error occurred: [_1].',$putresult).'</span>';
17094: }
17095: return $resulttext;
17096: }
17097:
1.357 raeburn 17098: sub modify_privacy {
17099: my ($dom,%domconfig) = @_;
17100: my ($resulttext,%current,%changes);
17101: if (ref($domconfig{'privacy'}) eq 'HASH') {
17102: %current = %{$domconfig{'privacy'}};
17103: }
17104: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17105: my @items = ('domain','author','course','community');
17106: my %names = &Apache::lonlocal::texthash (
17107: domain => 'Assigned domain role(s)',
17108: author => 'Assigned co-author role(s)',
17109: course => 'Assigned course role(s)',
17110: community => 'Assigned community role',
17111: );
17112: my %roles = &Apache::lonlocal::texthash (
17113: domain => 'Domain role',
17114: author => 'Co-author role',
17115: course => 'Course role',
17116: community => 'Community role',
17117: );
17118: my %titles = &Apache::lonlocal::texthash (
17119: approval => 'Approval for role in different domain',
17120: othdom => 'User information available in other domain',
17121: priv => 'Information viewable by privileged user in same domain',
17122: unpriv => 'Information viewable by unprivileged user in same domain',
17123: instdom => 'Other domain shares institution/provider',
17124: extdom => 'Other domain has different institution/provider',
17125: none => 'Not allowed',
17126: user => 'User authorizes',
17127: domain => 'Domain Coordinator authorizes',
17128: auto => 'Unrestricted',
17129: );
17130: my %fieldnames = &Apache::lonlocal::texthash (
17131: id => 'Student/Employee ID',
17132: permanentemail => 'E-mail address',
17133: lastname => 'Last Name',
17134: firstname => 'First Name',
17135: middlename => 'Middle Name',
17136: generation => 'Generation',
17137: );
17138: my ($othertitle,$usertypes,$types) =
17139: &Apache::loncommon::sorted_inst_types($dom);
17140: my (%by_ip,%by_location,@intdoms,@instdoms);
17141: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17142:
17143: my %privacyhash = (
17144: 'approval' => {
17145: instdom => {},
17146: extdom => {},
17147: },
17148: 'othdom' => {},
17149: 'priv' => {},
17150: 'unpriv' => {},
17151: );
17152: foreach my $item (@items) {
17153: if (@instdoms > 1) {
17154: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
17155: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17156: }
17157: if (ref($current{'approval'}) eq 'HASH') {
17158: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17159: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17160: $changes{'approval'} = 1;
17161: }
17162: }
17163: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17164: $changes{'approval'} = 1;
17165: }
17166: }
17167: if (keys(%by_location) > 0) {
17168: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17169: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17170: }
17171: if (ref($current{'approval'}) eq 'HASH') {
17172: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17173: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17174: $changes{'approval'} = 1;
17175: }
17176: }
17177: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17178: $changes{'approval'} = 1;
17179: }
17180: }
17181: foreach my $status ('priv','unpriv') {
17182: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17183: my @newvalues;
17184: foreach my $field (@possibles) {
17185: if (grep(/^\Q$field\E$/,@fields)) {
17186: $privacyhash{$status}{$item}{$field} = 1;
17187: push(@newvalues,$field);
17188: }
17189: }
17190: @newvalues = sort(@newvalues);
17191: if (ref($current{$status}) eq 'HASH') {
17192: if (ref($current{$status}{$item}) eq 'HASH') {
17193: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17194: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17195: if (@diffs > 0) {
17196: $changes{$status} = 1;
17197: }
17198: }
17199: } else {
17200: my @stdfields;
17201: foreach my $field (@fields) {
17202: if ($field eq 'id') {
17203: next if ($status eq 'unpriv');
17204: next if (($status eq 'priv') && ($item eq 'community'));
17205: }
17206: push(@stdfields,$field);
17207: }
17208: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17209: if (@diffs > 0) {
17210: $changes{$status} = 1;
17211: }
17212: }
17213: }
17214: }
17215: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17216: my @statuses;
17217: if (ref($types) eq 'ARRAY') {
17218: @statuses = @{$types};
17219: }
17220: foreach my $type (@statuses,'default') {
17221: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17222: my @newvalues;
17223: foreach my $field (sort(@possfields)) {
17224: if (grep(/^\Q$field\E$/,@fields)) {
17225: $privacyhash{'othdom'}{$type}{$field} = 1;
17226: push(@newvalues,$field);
17227: }
17228: }
17229: @newvalues = sort(@newvalues);
17230: if (ref($current{'othdom'}) eq 'HASH') {
17231: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17232: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17233: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17234: if (@diffs > 0) {
17235: $changes{'othdom'} = 1;
17236: }
17237: }
17238: } else {
17239: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17240: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17241: if (@diffs > 0) {
17242: $changes{'othdom'} = 1;
17243: }
17244: }
17245: }
17246: }
17247: my %confighash = (
17248: privacy => \%privacyhash,
17249: );
17250: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17251: if ($putresult eq 'ok') {
17252: if (keys(%changes) > 0) {
17253: $resulttext = &mt('Changes made: ').'<ul>';
17254: foreach my $key ('approval','othdom','priv','unpriv') {
17255: if ($changes{$key}) {
17256: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17257: if ($key eq 'approval') {
17258: if (keys(%{$privacyhash{$key}{instdom}})) {
17259: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17260: foreach my $item (@items) {
17261: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17262: }
17263: $resulttext .= '</ul></li>';
17264: }
17265: if (keys(%{$privacyhash{$key}{extdom}})) {
17266: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17267: foreach my $item (@items) {
17268: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17269: }
17270: $resulttext .= '</ul></li>';
17271: }
17272: } elsif ($key eq 'othdom') {
17273: my @statuses;
17274: if (ref($types) eq 'ARRAY') {
17275: @statuses = @{$types};
17276: }
17277: if (ref($privacyhash{$key}) eq 'HASH') {
17278: foreach my $status (@statuses,'default') {
17279: if ($status eq 'default') {
17280: $resulttext .= '<li>'.$othertitle.': ';
17281: } elsif (ref($usertypes) eq 'HASH') {
17282: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17283: } else {
17284: next;
17285: }
17286: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17287: if (keys(%{$privacyhash{$key}{$status}})) {
17288: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17289: } else {
17290: $resulttext .= &mt('none');
17291: }
17292: }
17293: $resulttext .= '</li>';
17294: }
17295: }
17296: } else {
17297: foreach my $item (@items) {
17298: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17299: $resulttext .= '<li>'.$names{$item}.': ';
17300: if (keys(%{$privacyhash{$key}{$item}})) {
17301: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17302: } else {
17303: $resulttext .= &mt('none');
17304: }
17305: $resulttext .= '</li>';
17306: }
17307: }
17308: }
17309: $resulttext .= '</ul></li>';
17310: }
17311: }
17312: } else {
17313: $resulttext = &mt('No changes made to user information settings');
17314: }
17315: } else {
17316: $resulttext = '<span class="LC_error">'.
17317: &mt('An error occurred: [_1]',$putresult).'</span>';
17318: }
17319: return $resulttext;
17320: }
17321:
1.354 raeburn 17322: sub modify_passwords {
17323: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17324: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17325: $updatedefaults,$updateconf);
1.354 raeburn 17326: my $customfn = 'resetpw.html';
17327: if (ref($domconfig{'passwords'}) eq 'HASH') {
17328: %current = %{$domconfig{'passwords'}};
17329: }
17330: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17331: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17332: if (ref($types) eq 'ARRAY') {
17333: @oktypes = @{$types};
17334: }
17335: push(@oktypes,'default');
17336:
17337: my %titles = &Apache::lonlocal::texthash (
17338: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17339: intauth_check => 'Check bcrypt cost if authenticated',
17340: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17341: permanent => 'Permanent e-mail address',
17342: critical => 'Critical notification address',
17343: notify => 'Notification address',
17344: min => 'Minimum password length',
17345: max => 'Maximum password length',
17346: chars => 'Required characters',
17347: expire => 'Password expiration (days)',
1.356 raeburn 17348: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17349: reset => 'Resetting Forgotten Password',
17350: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17351: rules => 'Rules for LON-CAPA Passwords',
17352: crsownerchg => 'Course Owner Changing Student Passwords',
17353: username => 'Username',
17354: email => 'E-mail address',
17355: );
17356:
17357: #
17358: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17359: #
17360: my (%curr_defaults,%save_defaults);
17361: if (ref($domconfig{'defaults'}) eq 'HASH') {
17362: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17363: if ($key =~ /^intauth_(cost|check|switch)$/) {
17364: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17365: } else {
17366: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17367: }
17368: }
17369: }
17370: my %staticdefaults = (
17371: 'resetlink' => 2,
17372: 'resetcase' => \@oktypes,
17373: 'resetprelink' => 'both',
17374: 'resetemail' => ['critical','notify','permanent'],
17375: 'intauth_cost' => 10,
17376: 'intauth_check' => 0,
17377: 'intauth_switch' => 0,
17378: );
1.365 raeburn 17379: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17380: foreach my $type (@oktypes) {
17381: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17382: }
17383: my $linklife = $env{'form.passwords_link'};
17384: $linklife =~ s/^\s+|\s+$//g;
17385: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17386: $newvalues{'resetlink'} = $linklife;
17387: if ($current{'resetlink'}) {
17388: if ($current{'resetlink'} ne $linklife) {
17389: $changes{'reset'} = 1;
17390: }
1.368 raeburn 17391: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17392: if ($staticdefaults{'resetlink'} ne $linklife) {
17393: $changes{'reset'} = 1;
17394: }
17395: }
17396: } elsif ($current{'resetlink'}) {
17397: $changes{'reset'} = 1;
17398: }
17399: my @casesens;
17400: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17401: foreach my $case (sort(@posscase)) {
17402: if (grep(/^\Q$case\E$/,@oktypes)) {
17403: push(@casesens,$case);
17404: }
17405: }
17406: $newvalues{'resetcase'} = \@casesens;
17407: if (ref($current{'resetcase'}) eq 'ARRAY') {
17408: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17409: if (@diffs > 0) {
17410: $changes{'reset'} = 1;
17411: }
1.368 raeburn 17412: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17413: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17414: if (@diffs > 0) {
17415: $changes{'reset'} = 1;
17416: }
17417: }
17418: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17419: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17420: if (exists($current{'resetprelink'})) {
17421: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17422: $changes{'reset'} = 1;
17423: }
1.368 raeburn 17424: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17425: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17426: $changes{'reset'} = 1;
17427: }
17428: }
17429: } elsif ($current{'resetprelink'}) {
17430: $changes{'reset'} = 1;
17431: }
17432: foreach my $type (@oktypes) {
17433: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17434: my @postlink;
17435: foreach my $item (sort(@possplink)) {
17436: if ($item =~ /^(email|username)$/) {
17437: push(@postlink,$item);
17438: }
17439: }
17440: $newvalues{'resetpostlink'}{$type} = \@postlink;
17441: unless ($changes{'reset'}) {
17442: if (ref($current{'resetpostlink'}) eq 'HASH') {
17443: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17444: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17445: if (@diffs > 0) {
17446: $changes{'reset'} = 1;
17447: }
17448: } else {
17449: $changes{'reset'} = 1;
17450: }
1.368 raeburn 17451: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17452: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17453: if (@diffs > 0) {
17454: $changes{'reset'} = 1;
17455: }
17456: }
17457: }
17458: }
17459: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
17460: my @resetemail;
17461: foreach my $item (sort(@possemailsrc)) {
17462: if ($item =~ /^(permanent|critical|notify)$/) {
17463: push(@resetemail,$item);
17464: }
17465: }
17466: $newvalues{'resetemail'} = \@resetemail;
17467: unless ($changes{'reset'}) {
17468: if (ref($current{'resetemail'}) eq 'ARRAY') {
17469: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
17470: if (@diffs > 0) {
17471: $changes{'reset'} = 1;
17472: }
1.368 raeburn 17473: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17474: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
17475: if (@diffs > 0) {
17476: $changes{'reset'} = 1;
17477: }
17478: }
17479: }
17480: if ($env{'form.passwords_stdtext'} == 0) {
17481: $newvalues{'resetremove'} = 1;
17482: unless ($current{'resetremove'}) {
17483: $changes{'reset'} = 1;
17484: }
17485: } elsif ($current{'resetremove'}) {
17486: $changes{'reset'} = 1;
17487: }
17488: if ($env{'form.passwords_customfile.filename'} ne '') {
17489: my $servadm = $r->dir_config('lonAdmEMail');
17490: my ($configuserok,$author_ok,$switchserver) =
17491: &config_check($dom,$confname,$servadm);
17492: my $error;
17493: if ($configuserok eq 'ok') {
17494: if ($switchserver) {
17495: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
17496: } else {
17497: if ($author_ok eq 'ok') {
17498: my ($result,$customurl) =
17499: &publishlogo($r,'upload','passwords_customfile',$dom,
17500: $confname,'customtext/resetpw','','',$customfn);
17501: if ($result eq 'ok') {
17502: $newvalues{'resetcustom'} = $customurl;
17503: $changes{'reset'} = 1;
17504: } else {
17505: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
17506: }
17507: } else {
17508: $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);
17509: }
17510: }
17511: } else {
17512: $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);
17513: }
17514: if ($error) {
17515: &Apache::lonnet::logthis($error);
17516: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17517: }
17518: } elsif ($current{'resetcustom'}) {
17519: if ($env{'form.passwords_custom_del'}) {
17520: $changes{'reset'} = 1;
17521: } else {
17522: $newvalues{'resetcustom'} = $current{'resetcustom'};
17523: }
17524: }
17525: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
17526: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
17527: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
17528: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
17529: $changes{'intauth'} = 1;
17530: }
17531: } else {
17532: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
17533: }
17534: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
17535: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
17536: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
17537: $changes{'intauth'} = 1;
17538: }
17539: } else {
17540: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17541: }
17542: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17543: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17544: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17545: $changes{'intauth'} = 1;
17546: }
17547: } else {
17548: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17549: }
17550: foreach my $item ('cost','check','switch') {
17551: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17552: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17553: $updatedefaults = 1;
17554: }
17555: }
1.356 raeburn 17556: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17557: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 17558: my $ruleok;
17559: if ($rule eq 'expire') {
1.365 raeburn 17560: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17561: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 17562: $ruleok = 1;
1.356 raeburn 17563: }
1.365 raeburn 17564: } elsif ($rule eq 'min') {
17565: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
17566: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
17567: $ruleok = 1;
17568: }
17569: }
17570: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
17571: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 17572: $ruleok = 1;
17573: }
17574: if ($ruleok) {
1.354 raeburn 17575: $newvalues{$rule} = $env{'form.passwords_'.$rule};
17576: if (exists($current{$rule})) {
17577: if ($newvalues{$rule} ne $current{$rule}) {
17578: $changes{'rules'} = 1;
17579: }
17580: } elsif ($rule eq 'min') {
17581: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
17582: $changes{'rules'} = 1;
17583: }
1.370 raeburn 17584: } else {
17585: $changes{'rules'} = 1;
1.354 raeburn 17586: }
17587: } elsif (exists($current{$rule})) {
17588: $changes{'rules'} = 1;
17589: }
17590: }
17591: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
17592: my @chars;
17593: foreach my $item (sort(@posschars)) {
17594: if ($item =~ /^(uc|lc|num|spec)$/) {
17595: push(@chars,$item);
17596: }
17597: }
17598: $newvalues{'chars'} = \@chars;
17599: unless ($changes{'rules'}) {
17600: if (ref($current{'chars'}) eq 'ARRAY') {
17601: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
17602: if (@diffs > 0) {
17603: $changes{'rules'} = 1;
17604: }
17605: } else {
17606: if (@chars > 0) {
17607: $changes{'rules'} = 1;
17608: }
17609: }
17610: }
1.359 raeburn 17611: my %crsownerchg = (
17612: by => [],
17613: for => [],
17614: );
17615: foreach my $item ('by','for') {
17616: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17617: foreach my $type (sort(@posstypes)) {
17618: if (grep(/^\Q$type\E$/,@oktypes)) {
17619: push(@{$crsownerchg{$item}},$type);
17620: }
17621: }
17622: }
17623: $newvalues{'crsownerchg'} = \%crsownerchg;
17624: if (ref($current{'crsownerchg'}) eq 'HASH') {
17625: foreach my $item ('by','for') {
17626: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17627: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17628: if (@diffs > 0) {
17629: $changes{'crsownerchg'} = 1;
17630: last;
17631: }
17632: }
17633: }
1.368 raeburn 17634: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17635: foreach my $item ('by','for') {
17636: if (@{$crsownerchg{$item}} > 0) {
17637: $changes{'crsownerchg'} = 1;
17638: last;
17639: }
1.354 raeburn 17640: }
17641: }
17642:
17643: my %confighash = (
17644: defaults => \%save_defaults,
17645: passwords => \%newvalues,
17646: );
17647: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17648:
17649: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17650: if ($putresult eq 'ok') {
17651: if (keys(%changes) > 0) {
17652: $resulttext = &mt('Changes made: ').'<ul>';
17653: foreach my $key ('reset','intauth','rules','crsownerchg') {
17654: if ($changes{$key}) {
1.355 raeburn 17655: unless ($key eq 'intauth') {
17656: $updateconf = 1;
17657: }
1.354 raeburn 17658: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17659: if ($key eq 'reset') {
17660: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17661: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17662: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17663: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17664: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17665: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17666: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17667: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17668: }
1.354 raeburn 17669: } else {
17670: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17671: }
17672: if ($confighash{'passwords'}{'resetlink'}) {
17673: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17674: } else {
17675: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17676: &mt('Will default to 2 hours').'</li>';
17677: }
17678: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17679: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17680: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17681: } else {
17682: my $casesens;
17683: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17684: if ($type eq 'default') {
17685: $casesens .= $othertitle.', ';
17686: } elsif ($usertypes->{$type} ne '') {
17687: $casesens .= $usertypes->{$type}.', ';
17688: }
17689: }
17690: $casesens =~ s/\Q, \E$//;
17691: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17692: }
17693: } else {
17694: $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>';
17695: }
17696: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17697: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17698: } else {
17699: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17700: }
17701: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17702: my $output;
17703: if (ref($types) eq 'ARRAY') {
17704: foreach my $type (@{$types}) {
17705: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17706: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17707: $output .= $usertypes->{$type}.' -- '.&mt('none');
17708: } else {
17709: $output .= $usertypes->{$type}.' -- '.
17710: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17711: }
17712: }
17713: }
17714: }
17715: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17716: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17717: $output .= $othertitle.' -- '.&mt('none');
17718: } else {
17719: $output .= $othertitle.' -- '.
17720: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17721: }
17722: }
17723: if ($output) {
17724: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17725: } else {
17726: $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>';
17727: }
17728: } else {
17729: $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>';
17730: }
17731: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17732: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17733: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17734: } else {
17735: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17736: }
17737: } else {
1.379 raeburn 17738: $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 17739: }
17740: if ($confighash{'passwords'}{'resetremove'}) {
17741: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17742: } else {
17743: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17744: }
17745: if ($confighash{'passwords'}{'resetcustom'}) {
17746: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17747: &mt('custom text'),600,500,undef,undef,
17748: undef,undef,'background-color:#ffffff');
17749: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17750: } else {
17751: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17752: }
17753: } elsif ($key eq 'intauth') {
17754: foreach my $item ('cost','switch','check') {
17755: my $value = $save_defaults{$key.'_'.$item};
17756: if ($item eq 'switch') {
17757: my %optiondesc = &Apache::lonlocal::texthash (
17758: 0 => 'No',
17759: 1 => 'Yes',
17760: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17761: );
17762: if ($value =~ /^(0|1|2)$/) {
17763: $value = $optiondesc{$value};
17764: } else {
17765: $value = &mt('none -- defaults to No');
17766: }
17767: } elsif ($item eq 'check') {
17768: my %optiondesc = &Apache::lonlocal::texthash (
17769: 0 => 'No',
17770: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17771: 2 => 'Yes, disallow login if stored cost is less than domain default',
17772: );
17773: if ($value =~ /^(0|1|2)$/) {
17774: $value = $optiondesc{$value};
17775: } else {
17776: $value = &mt('none -- defaults to No');
17777: }
17778: }
17779: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17780: }
17781: } elsif ($key eq 'rules') {
1.356 raeburn 17782: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17783: if ($confighash{'passwords'}{$rule} eq '') {
17784: if ($rule eq 'min') {
1.356 raeburn 17785: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17786: ' '.&mt('Default of [_1] will be used',
17787: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17788: } else {
17789: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17790: }
17791: } else {
17792: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17793: }
17794: }
1.370 raeburn 17795: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17796: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17797: my %rulenames = &Apache::lonlocal::texthash(
17798: uc => 'At least one upper case letter',
17799: lc => 'At least one lower case letter',
17800: num => 'At least one number',
17801: spec => 'At least one non-alphanumeric',
17802: );
17803: my $needed = '<ul><li>'.
17804: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17805: '</li></ul>';
17806: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17807: } else {
17808: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17809: }
17810: } else {
17811: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17812: }
1.354 raeburn 17813: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17814: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17815: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17816: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17817: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17818: } else {
17819: my %crsownerstr;
17820: foreach my $item ('by','for') {
17821: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17822: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17823: if ($type eq 'default') {
17824: $crsownerstr{$item} .= $othertitle.', ';
17825: } elsif ($usertypes->{$type} ne '') {
17826: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17827: }
17828: }
17829: $crsownerstr{$item} =~ s/\Q, \E$//;
17830: }
17831: }
17832: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17833: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17834: }
1.354 raeburn 17835: } else {
1.359 raeburn 17836: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17837: }
17838: }
17839: $resulttext .= '</ul></li>';
17840: }
17841: }
17842: $resulttext .= '</ul>';
17843: } else {
17844: $resulttext = &mt('No changes made to password settings');
17845: }
1.355 raeburn 17846: my $cachetime = 24*60*60;
1.354 raeburn 17847: if ($updatedefaults) {
17848: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17849: if (ref($lastactref) eq 'HASH') {
17850: $lastactref->{'domdefaults'} = 1;
17851: }
17852: }
1.355 raeburn 17853: if ($updateconf) {
17854: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17855: if (ref($lastactref) eq 'HASH') {
17856: $lastactref->{'passwdconf'} = 1;
17857: }
17858: }
1.354 raeburn 17859: } else {
17860: $resulttext = '<span class="LC_error">'.
17861: &mt('An error occurred: [_1]',$putresult).'</span>';
17862: }
17863: if ($errors) {
17864: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17865: $errors.'</ul></p>';
17866: }
17867: return $resulttext;
17868: }
17869:
1.28 raeburn 17870: sub modify_usercreation {
1.27 raeburn 17871: my ($dom,%domconfig) = @_;
1.224 raeburn 17872: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17873: my $warningmsg;
1.27 raeburn 17874: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17875: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17876: if ($key eq 'cancreate') {
17877: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17878: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17879: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17880: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17881: } else {
1.224 raeburn 17882: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17883: }
17884: }
17885: }
17886: } elsif ($key eq 'email_rule') {
17887: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17888: } else {
17889: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17890: }
1.27 raeburn 17891: }
17892: }
17893: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17894: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17895: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17896: foreach my $item(@contexts) {
1.224 raeburn 17897: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17898: }
1.34 raeburn 17899: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17900: foreach my $item (@contexts) {
1.224 raeburn 17901: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17902: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17903: }
1.27 raeburn 17904: }
1.34 raeburn 17905: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17906: foreach my $item (@contexts) {
1.43 raeburn 17907: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17908: if ($cancreate{$item} ne 'any') {
17909: push(@{$changes{'cancreate'}},$item);
17910: }
17911: } else {
17912: if ($cancreate{$item} ne 'none') {
17913: push(@{$changes{'cancreate'}},$item);
17914: }
1.27 raeburn 17915: }
17916: }
17917: } else {
1.43 raeburn 17918: foreach my $item (@contexts) {
1.34 raeburn 17919: push(@{$changes{'cancreate'}},$item);
17920: }
1.27 raeburn 17921: }
1.34 raeburn 17922:
1.27 raeburn 17923: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17924: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17925: if (!grep(/^\Q$type\E$/,@username_rule)) {
17926: push(@{$changes{'username_rule'}},$type);
17927: }
17928: }
17929: foreach my $type (@username_rule) {
17930: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17931: push(@{$changes{'username_rule'}},$type);
17932: }
17933: }
17934: } else {
17935: push(@{$changes{'username_rule'}},@username_rule);
17936: }
17937:
1.32 raeburn 17938: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
17939: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
17940: if (!grep(/^\Q$type\E$/,@id_rule)) {
17941: push(@{$changes{'id_rule'}},$type);
17942: }
17943: }
17944: foreach my $type (@id_rule) {
17945: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
17946: push(@{$changes{'id_rule'}},$type);
17947: }
17948: }
17949: } else {
17950: push(@{$changes{'id_rule'}},@id_rule);
17951: }
17952:
1.43 raeburn 17953: my @authen_contexts = ('author','course','domain');
1.325 raeburn 17954: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 17955: my %authhash;
1.43 raeburn 17956: foreach my $item (@authen_contexts) {
1.28 raeburn 17957: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
17958: foreach my $auth (@authtypes) {
17959: if (grep(/^\Q$auth\E$/,@authallowed)) {
17960: $authhash{$item}{$auth} = 1;
17961: } else {
17962: $authhash{$item}{$auth} = 0;
17963: }
17964: }
17965: }
17966: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 17967: foreach my $item (@authen_contexts) {
1.28 raeburn 17968: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
17969: foreach my $auth (@authtypes) {
17970: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
17971: push(@{$changes{'authtypes'}},$item);
17972: last;
17973: }
17974: }
17975: }
17976: }
17977: } else {
1.43 raeburn 17978: foreach my $item (@authen_contexts) {
1.28 raeburn 17979: push(@{$changes{'authtypes'}},$item);
17980: }
17981: }
17982:
1.224 raeburn 17983: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
17984: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
17985: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
17986: $save_usercreate{'id_rule'} = \@id_rule;
17987: $save_usercreate{'username_rule'} = \@username_rule,
17988: $save_usercreate{'authtypes'} = \%authhash;
17989:
1.27 raeburn 17990: my %usercreation_hash = (
1.224 raeburn 17991: usercreation => \%save_usercreate,
17992: );
1.27 raeburn 17993:
17994: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
17995: $dom);
1.50 raeburn 17996:
1.224 raeburn 17997: if ($putresult eq 'ok') {
17998: if (keys(%changes) > 0) {
17999: $resulttext = &mt('Changes made:').'<ul>';
18000: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18001: my %lt = &usercreation_types();
18002: foreach my $type (@{$changes{'cancreate'}}) {
18003: my $chgtext = $lt{$type}.', ';
18004: if ($cancreate{$type} eq 'none') {
18005: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18006: } elsif ($cancreate{$type} eq 'any') {
18007: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18008: } elsif ($cancreate{$type} eq 'official') {
18009: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18010: } elsif ($cancreate{$type} eq 'unofficial') {
18011: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18012: }
18013: $resulttext .= '<li>'.$chgtext.'</li>';
18014: }
18015: }
18016: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18017: my ($rules,$ruleorder) =
18018: &Apache::lonnet::inst_userrules($dom,'username');
18019: my $chgtext = '<ul>';
18020: foreach my $type (@username_rule) {
18021: if (ref($rules->{$type}) eq 'HASH') {
18022: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18023: }
18024: }
18025: $chgtext .= '</ul>';
18026: if (@username_rule > 0) {
18027: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18028: } else {
18029: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18030: }
18031: }
18032: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18033: my ($idrules,$idruleorder) =
18034: &Apache::lonnet::inst_userrules($dom,'id');
18035: my $chgtext = '<ul>';
18036: foreach my $type (@id_rule) {
18037: if (ref($idrules->{$type}) eq 'HASH') {
18038: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18039: }
18040: }
18041: $chgtext .= '</ul>';
18042: if (@id_rule > 0) {
18043: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18044: } else {
18045: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18046: }
18047: }
18048: my %authname = &authtype_names();
18049: my %context_title = &context_names();
18050: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18051: my $chgtext = '<ul>';
18052: foreach my $type (@{$changes{'authtypes'}}) {
18053: my @allowed;
18054: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18055: foreach my $auth (@authtypes) {
18056: if ($authhash{$type}{$auth}) {
18057: push(@allowed,$authname{$auth});
18058: }
18059: }
18060: if (@allowed > 0) {
18061: $chgtext .= join(', ',@allowed).'</li>';
18062: } else {
18063: $chgtext .= &mt('none').'</li>';
18064: }
18065: }
18066: $chgtext .= '</ul>';
18067: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18068: $resulttext .= '</li>';
18069: }
18070: $resulttext .= '</ul>';
18071: } else {
18072: $resulttext = &mt('No changes made to user creation settings');
18073: }
18074: } else {
18075: $resulttext = '<span class="LC_error">'.
18076: &mt('An error occurred: [_1]',$putresult).'</span>';
18077: }
18078: if ($warningmsg ne '') {
18079: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18080: }
18081: return $resulttext;
18082: }
18083:
18084: sub modify_selfcreation {
1.305 raeburn 18085: my ($dom,$lastactref,%domconfig) = @_;
18086: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18087: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18088: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18089: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18090: if (ref($typesref) eq 'ARRAY') {
18091: @types = @{$typesref};
18092: }
18093: if (ref($usertypesref) eq 'HASH') {
18094: %usertypes = %{$usertypesref};
1.228 raeburn 18095: }
1.303 raeburn 18096: $usertypes{'default'} = $othertitle;
1.224 raeburn 18097: #
18098: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18099: #
18100: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18101: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18102: if ($key eq 'cancreate') {
18103: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18104: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18105: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18106: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18107: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18108: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18109: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18110: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18111: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18112: } else {
18113: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18114: }
18115: }
18116: }
18117: } elsif ($key eq 'email_rule') {
18118: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18119: } else {
18120: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18121: }
18122: }
18123: }
18124: #
18125: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18126: #
18127: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18128: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18129: if ($key eq 'selfcreate') {
18130: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18131: } else {
18132: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18133: }
18134: }
18135: }
1.305 raeburn 18136: #
18137: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18138: #
18139: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18140: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18141: if ($key eq 'inststatusguest') {
18142: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18143: } else {
18144: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18145: }
18146: }
18147: }
1.224 raeburn 18148:
18149: my @contexts = ('selfcreate');
18150: @{$cancreate{'selfcreate'}} = ();
18151: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18152: if (@types) {
18153: @{$cancreate{'statustocreate'}} = ();
18154: }
1.236 raeburn 18155: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18156: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18157: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18158: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18159: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18160: my %selfcreatetypes = (
18161: sso => 'users authenticated by institutional single sign on',
18162: login => 'users authenticated by institutional log-in',
1.303 raeburn 18163: email => 'users verified by e-mail',
1.50 raeburn 18164: );
1.224 raeburn 18165: #
18166: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18167: # is permitted.
18168: #
1.305 raeburn 18169: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18170:
1.305 raeburn 18171: my (@statuses,%email_rule);
1.228 raeburn 18172: foreach my $item ('login','sso','email') {
1.224 raeburn 18173: if ($item eq 'email') {
1.236 raeburn 18174: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18175: if (@types) {
18176: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18177: foreach my $status (@poss_statuses) {
18178: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18179: push(@statuses,$status);
18180: }
18181: }
18182: $save_inststatus{'inststatusguest'} = \@statuses;
18183: } else {
18184: push(@statuses,'default');
18185: }
18186: if (@statuses) {
18187: my %curr_rule;
18188: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18189: foreach my $type (@statuses) {
18190: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18191: }
1.305 raeburn 18192: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18193: foreach my $type (@statuses) {
18194: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18195: }
18196: }
18197: push(@{$cancreate{'selfcreate'}},'email');
18198: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18199: my %curremaildom;
18200: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18201: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18202: }
18203: foreach my $type (@statuses) {
18204: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18205: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18206: }
18207: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18208: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18209: }
18210: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18211: #
18212: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18213: #
18214: my $chosen = $1;
18215: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18216: my $emaildom;
18217: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
18218: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
18219: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18220: if (ref($curremaildom{$type}) eq 'HASH') {
18221: if (exists($curremaildom{$type}{$chosen})) {
18222: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18223: push(@{$changes{'cancreate'}},'emaildomain');
18224: }
18225: } elsif ($emaildom ne '') {
18226: push(@{$changes{'cancreate'}},'emaildomain');
18227: }
18228: } elsif ($emaildom ne '') {
18229: push(@{$changes{'cancreate'}},'emaildomain');
18230: }
18231: }
18232: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18233: } elsif ($chosen eq 'custom') {
18234: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18235: $email_rule{$type} = [];
18236: if (ref($emailrules) eq 'HASH') {
18237: foreach my $rule (@possemail_rules) {
18238: if (exists($emailrules->{$rule})) {
18239: push(@{$email_rule{$type}},$rule);
18240: }
18241: }
18242: }
18243: if (@{$email_rule{$type}}) {
18244: $cancreate{'emailoptions'}{$type} = 'custom';
18245: if (ref($curr_rule{$type}) eq 'ARRAY') {
18246: if (@{$curr_rule{$type}} > 0) {
18247: foreach my $rule (@{$curr_rule{$type}}) {
18248: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18249: push(@{$changes{'email_rule'}},$type);
18250: }
18251: }
18252: }
18253: foreach my $type (@{$email_rule{$type}}) {
18254: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18255: push(@{$changes{'email_rule'}},$type);
18256: }
18257: }
18258: } else {
18259: push(@{$changes{'email_rule'}},$type);
18260: }
18261: }
18262: } else {
18263: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18264: }
18265: }
18266: }
18267: if (@types) {
18268: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18269: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18270: if (@changed) {
18271: push(@{$changes{'inststatus'}},'inststatusguest');
18272: }
18273: } else {
18274: push(@{$changes{'inststatus'}},'inststatusguest');
18275: }
18276: }
18277: } else {
18278: delete($env{'form.cancreate_email'});
18279: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18280: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18281: push(@{$changes{'inststatus'}},'inststatusguest');
18282: }
18283: }
18284: }
18285: } else {
18286: $save_inststatus{'inststatusguest'} = [];
18287: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18288: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18289: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18290: }
18291: }
1.224 raeburn 18292: }
18293: } else {
18294: if ($env{'form.cancreate_'.$item}) {
18295: push(@{$cancreate{'selfcreate'}},$item);
18296: }
18297: }
18298: }
1.305 raeburn 18299: my (%userinfo,%savecaptcha);
1.224 raeburn 18300: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18301: #
1.228 raeburn 18302: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18303: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18304: #
1.236 raeburn 18305:
1.244 raeburn 18306: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18307: push(@contexts,'emailusername');
1.305 raeburn 18308: if (@statuses) {
18309: foreach my $type (@statuses) {
1.228 raeburn 18310: if (ref($infofields) eq 'ARRAY') {
18311: foreach my $field (@{$infofields}) {
18312: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18313: $cancreate{'emailusername'}{$type}{$field} = $1;
18314: }
18315: }
1.224 raeburn 18316: }
18317: }
18318: }
18319: #
18320: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18321: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18322: #
18323:
18324: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18325: @approvalnotify = sort(@approvalnotify);
18326: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18327: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18328: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18329: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18330: push(@{$changes{'cancreate'}},'notify');
18331: }
18332: } else {
18333: if ($cancreate{'notify'}{'approval'}) {
18334: push(@{$changes{'cancreate'}},'notify');
18335: }
18336: }
18337: } elsif ($cancreate{'notify'}{'approval'}) {
18338: push(@{$changes{'cancreate'}},'notify');
18339: }
18340:
18341: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18342: }
18343: #
1.236 raeburn 18344: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18345: # institutional log-in.
18346: #
18347: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18348: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18349: ($domdefaults{'auth_def'} eq 'localauth'))) {
18350: $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.').' '.
18351: &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.');
18352: }
18353: }
18354: my @fields = ('lastname','firstname','middlename','generation',
18355: 'permanentemail','id');
1.240 raeburn 18356: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18357: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18358: #
18359: # Where usernames may created for institutional log-in and/or institutional single sign on:
18360: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18361: # may self-create accounts
18362: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18363: # which the user may supply, if institutional data is unavailable.
18364: #
18365: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18366: if (@types) {
1.305 raeburn 18367: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18368: push(@contexts,'statustocreate');
1.303 raeburn 18369: foreach my $type (@types) {
1.224 raeburn 18370: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18371: foreach my $field (@fields) {
18372: if (grep(/^\Q$field\E$/,@modifiable)) {
18373: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18374: } else {
18375: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18376: }
18377: }
18378: }
18379: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18380: foreach my $type (@types) {
1.224 raeburn 18381: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18382: foreach my $field (@fields) {
18383: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18384: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18385: push(@{$changes{'selfcreate'}},$type);
18386: last;
18387: }
18388: }
18389: }
18390: }
18391: } else {
1.303 raeburn 18392: foreach my $type (@types) {
1.224 raeburn 18393: push(@{$changes{'selfcreate'}},$type);
18394: }
18395: }
18396: }
1.240 raeburn 18397: foreach my $field (@shibfields) {
18398: if ($env{'form.shibenv_'.$field} ne '') {
18399: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18400: }
18401: }
18402: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18403: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18404: foreach my $field (@shibfields) {
18405: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18406: push(@{$changes{'cancreate'}},'shibenv');
18407: }
18408: }
18409: } else {
18410: foreach my $field (@shibfields) {
18411: if ($env{'form.shibenv_'.$field}) {
18412: push(@{$changes{'cancreate'}},'shibenv');
18413: last;
18414: }
18415: }
18416: }
18417: }
1.224 raeburn 18418: }
18419: foreach my $item (@contexts) {
18420: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18421: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18422: if (ref($cancreate{$item}) eq 'ARRAY') {
18423: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18424: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18425: push(@{$changes{'cancreate'}},$item);
18426: }
18427: }
18428: }
18429: }
18430: if (ref($cancreate{$item}) eq 'ARRAY') {
18431: foreach my $type (@{$cancreate{$item}}) {
18432: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18433: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18434: push(@{$changes{'cancreate'}},$item);
18435: }
18436: }
18437: }
18438: }
18439: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
18440: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 18441: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
18442: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18443: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
18444: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18445: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18446: push(@{$changes{'cancreate'}},$item);
18447: }
18448: }
18449: }
1.305 raeburn 18450: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18451: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18452: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18453: push(@{$changes{'cancreate'}},$item);
18454: }
1.224 raeburn 18455: }
18456: }
18457: }
1.305 raeburn 18458: foreach my $type (keys(%{$cancreate{$item}})) {
18459: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18460: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18461: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18462: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18463: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18464: push(@{$changes{'cancreate'}},$item);
18465: }
18466: }
18467: } else {
18468: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18469: push(@{$changes{'cancreate'}},$item);
18470: }
18471: }
18472: }
1.305 raeburn 18473: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18474: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18475: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18476: push(@{$changes{'cancreate'}},$item);
18477: }
1.224 raeburn 18478: }
18479: }
18480: }
18481: }
18482: } elsif ($curr_usercreation{'cancreate'}{$item}) {
18483: if (ref($cancreate{$item}) eq 'ARRAY') {
18484: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
18485: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18486: push(@{$changes{'cancreate'}},$item);
18487: }
18488: }
1.305 raeburn 18489: }
18490: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18491: if (ref($cancreate{$item}) eq 'HASH') {
18492: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18493: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 18494: }
18495: }
18496: } elsif ($item eq 'emailusername') {
1.228 raeburn 18497: if (ref($cancreate{$item}) eq 'HASH') {
18498: foreach my $type (keys(%{$cancreate{$item}})) {
18499: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18500: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18501: if ($cancreate{$item}{$type}{$field}) {
18502: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18503: push(@{$changes{'cancreate'}},$item);
18504: }
18505: last;
18506: }
18507: }
18508: }
18509: }
1.224 raeburn 18510: }
18511: }
18512: }
18513: #
18514: # Populate %save_usercreate hash with updates to self-creation configuration.
18515: #
18516: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
18517: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 18518: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 18519: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
18520: if (ref($cancreate{'notify'}) eq 'HASH') {
18521: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
18522: }
1.236 raeburn 18523: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
18524: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
18525: }
1.303 raeburn 18526: if (ref($cancreate{'emailverified'}) eq 'HASH') {
18527: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
18528: }
1.305 raeburn 18529: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
18530: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
18531: }
1.303 raeburn 18532: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
18533: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
18534: }
1.224 raeburn 18535: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18536: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
18537: }
1.240 raeburn 18538: if (ref($cancreate{'shibenv'}) eq 'HASH') {
18539: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18540: }
1.224 raeburn 18541: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18542: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18543:
18544: my %userconfig_hash = (
18545: usercreation => \%save_usercreate,
18546: usermodification => \%save_usermodify,
1.305 raeburn 18547: inststatus => \%save_inststatus,
1.224 raeburn 18548: );
1.305 raeburn 18549:
1.224 raeburn 18550: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18551: $dom);
18552: #
1.305 raeburn 18553: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18554: #
1.27 raeburn 18555: if ($putresult eq 'ok') {
18556: if (keys(%changes) > 0) {
18557: $resulttext = &mt('Changes made:').'<ul>';
18558: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18559: my %lt = &selfcreation_types();
1.34 raeburn 18560: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18561: my $chgtext = '';
1.45 raeburn 18562: if ($type eq 'selfcreate') {
1.50 raeburn 18563: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18564: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18565: } else {
1.224 raeburn 18566: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18567: '<ul>';
1.50 raeburn 18568: foreach my $case (@{$cancreate{$type}}) {
18569: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18570: }
18571: $chgtext .= '</ul>';
1.100 raeburn 18572: if (ref($cancreate{$type}) eq 'ARRAY') {
18573: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18574: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18575: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18576: $chgtext .= '<span class="LC_warning">'.
18577: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18578: '</span><br />';
18579: }
18580: }
18581: }
18582: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18583: if (!@statuses) {
18584: $chgtext .= '<span class="LC_warning">'.
18585: &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.").
18586: '</span><br />';
1.303 raeburn 18587:
1.100 raeburn 18588: }
18589: }
18590: }
1.43 raeburn 18591: }
1.240 raeburn 18592: } elsif ($type eq 'shibenv') {
18593: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18594: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18595: } else {
18596: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18597: '<ul>';
18598: foreach my $field (@shibfields) {
18599: next if ($cancreate{$type}{$field} eq '');
18600: if ($field eq 'inststatus') {
18601: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18602: } else {
18603: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18604: }
18605: }
18606: $chgtext .= '</ul>';
1.303 raeburn 18607: }
1.93 raeburn 18608: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18609: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18610: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18611: if (@{$cancreate{'selfcreate'}} > 0) {
18612: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18613: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18614: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18615: $chgtext .= '<br />'.
18616: '<span class="LC_warning">'.
18617: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18618: '</span>';
18619: }
1.303 raeburn 18620: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18621: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18622: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18623: } else {
18624: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18625: }
18626: $chgtext .= '<ul>';
18627: foreach my $case (@{$cancreate{$type}}) {
18628: if ($case eq 'default') {
18629: $chgtext .= '<li>'.$othertitle.'</li>';
18630: } else {
1.303 raeburn 18631: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18632: }
18633: }
1.100 raeburn 18634: $chgtext .= '</ul>';
18635: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18636: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18637: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18638: '</span>';
1.100 raeburn 18639: }
18640: }
18641: } else {
18642: if (@{$cancreate{$type}} == 0) {
18643: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18644: } else {
18645: $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 18646: }
18647: }
1.303 raeburn 18648: $chgtext .= '<br />';
1.93 raeburn 18649: }
1.236 raeburn 18650: } elsif ($type eq 'selfcreateprocessing') {
18651: my %choices = &Apache::lonlocal::texthash (
18652: automatic => 'Automatic approval',
18653: approval => 'Queued for approval',
18654: );
1.305 raeburn 18655: if (@types) {
18656: if (@statuses) {
1.303 raeburn 18657: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18658: '<ul>';
1.305 raeburn 18659: foreach my $status (@statuses) {
18660: if ($status eq 'default') {
18661: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18662: } else {
1.305 raeburn 18663: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18664: }
18665: }
18666: $chgtext .= '</ul>';
18667: }
18668: } else {
18669: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18670: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18671: }
18672: } elsif ($type eq 'emailverified') {
18673: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18674: all => 'Same as e-mail',
18675: first => 'Omit @domain',
18676: free => 'Free to choose',
1.303 raeburn 18677: );
1.305 raeburn 18678: if (@types) {
18679: if (@statuses) {
1.303 raeburn 18680: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18681: '<ul>';
1.305 raeburn 18682: foreach my $status (@statuses) {
1.362 raeburn 18683: if ($status eq 'default') {
1.305 raeburn 18684: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18685: } else {
1.305 raeburn 18686: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18687: }
18688: }
18689: $chgtext .= '</ul>';
18690: }
18691: } else {
1.305 raeburn 18692: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18693: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18694: }
1.305 raeburn 18695: } elsif ($type eq 'emailoptions') {
18696: my %options = &Apache::lonlocal::texthash (
18697: any => 'Any e-mail',
18698: inst => 'Institutional only',
18699: noninst => 'Non-institutional only',
18700: custom => 'Custom restrictions',
18701: );
18702: if (@types) {
18703: if (@statuses) {
18704: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18705: '<ul>';
18706: foreach my $status (@statuses) {
18707: if ($type eq 'default') {
18708: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18709: } else {
18710: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18711: }
18712: }
1.305 raeburn 18713: $chgtext .= '</ul>';
18714: }
18715: } else {
18716: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18717: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18718: } else {
18719: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18720: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18721: }
1.305 raeburn 18722: }
18723: } elsif ($type eq 'emaildomain') {
18724: my $output;
18725: if (@statuses) {
18726: foreach my $type (@statuses) {
18727: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18728: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18729: if ($type eq 'default') {
18730: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18731: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18732: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18733: } else {
18734: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18735: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18736: }
1.303 raeburn 18737: } else {
1.305 raeburn 18738: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18739: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18740: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18741: } else {
18742: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
18743: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18744: }
1.303 raeburn 18745: }
1.305 raeburn 18746: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18747: if ($type eq 'default') {
18748: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18749: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18750: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18751: } else {
18752: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18753: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18754: }
1.303 raeburn 18755: } else {
1.305 raeburn 18756: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18757: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18758: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18759: } else {
18760: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
18761: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18762: }
1.303 raeburn 18763: }
18764: }
18765: }
18766: }
1.305 raeburn 18767: }
18768: if ($output ne '') {
18769: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18770: '<ul>'.$output.'</ul>';
1.236 raeburn 18771: }
1.165 raeburn 18772: } elsif ($type eq 'captcha') {
1.224 raeburn 18773: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18774: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18775: } else {
18776: my %captchas = &captcha_phrases();
1.224 raeburn 18777: if ($captchas{$savecaptcha{$type}}) {
18778: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18779: } else {
1.210 raeburn 18780: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18781: }
18782: }
18783: } elsif ($type eq 'recaptchakeys') {
18784: my ($privkey,$pubkey);
1.224 raeburn 18785: if (ref($savecaptcha{$type}) eq 'HASH') {
18786: $pubkey = $savecaptcha{$type}{'public'};
18787: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18788: }
18789: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18790: if (!$pubkey) {
18791: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18792: } else {
18793: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18794: }
18795: if (!$privkey) {
18796: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18797: } else {
18798: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18799: }
18800: $chgtext .= '</ul>';
1.269 raeburn 18801: } elsif ($type eq 'recaptchaversion') {
18802: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18803: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18804: }
1.224 raeburn 18805: } elsif ($type eq 'emailusername') {
18806: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18807: if (@statuses) {
18808: foreach my $type (@statuses) {
1.228 raeburn 18809: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18810: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18811: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18812: '<ul>';
18813: foreach my $field (@{$infofields}) {
18814: if ($cancreate{'emailusername'}{$type}{$field}) {
18815: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18816: }
18817: }
1.245 raeburn 18818: $chgtext .= '</ul>';
18819: } else {
1.303 raeburn 18820: $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 18821: }
18822: } else {
1.303 raeburn 18823: $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 18824: }
18825: }
18826: }
18827: }
18828: } elsif ($type eq 'notify') {
1.303 raeburn 18829: my $numapprove = 0;
1.224 raeburn 18830: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18831: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18832: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18833: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18834: $numapprove ++;
1.224 raeburn 18835: }
18836: }
1.43 raeburn 18837: }
1.303 raeburn 18838: unless ($numapprove) {
18839: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18840: }
1.34 raeburn 18841: }
1.224 raeburn 18842: if ($chgtext) {
18843: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18844: }
18845: }
18846: }
1.305 raeburn 18847: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18848: my ($emailrules,$emailruleorder) =
18849: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18850: foreach my $type (@{$changes{'email_rule'}}) {
18851: if (ref($email_rule{$type}) eq 'ARRAY') {
18852: my $chgtext = '<ul>';
18853: foreach my $rule (@{$email_rule{$type}}) {
18854: if (ref($emailrules->{$rule}) eq 'HASH') {
18855: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18856: }
18857: }
18858: $chgtext .= '</ul>';
1.310 raeburn 18859: my $typename;
1.305 raeburn 18860: if (@types) {
18861: if ($type eq 'default') {
18862: $typename = $othertitle;
18863: } else {
18864: $typename = $usertypes{$type};
18865: }
18866: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18867: }
18868: if (@{$email_rule{$type}} > 0) {
18869: $resulttext .= '<li>'.
18870: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18871: $usertypes{$type}).
18872: $chgtext.
18873: '</li>';
18874: } else {
18875: $resulttext .= '<li>'.
1.310 raeburn 18876: &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 18877: '</li>'.
1.310 raeburn 18878: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18879: }
1.43 raeburn 18880: }
18881: }
1.305 raeburn 18882: }
18883: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18884: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18885: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18886: my $chgtext = '<ul>';
18887: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18888: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18889: }
18890: $chgtext .= '</ul>';
18891: $resulttext .= '<li>'.
18892: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18893: $chgtext.
18894: '</li>';
18895: } else {
18896: $resulttext .= '<li>'.
18897: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18898: '</li>';
18899: }
1.43 raeburn 18900: }
18901: }
1.224 raeburn 18902: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18903: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18904: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18905: foreach my $type (@{$changes{'selfcreate'}}) {
18906: my $typename = $type;
1.303 raeburn 18907: if (keys(%usertypes) > 0) {
18908: if ($usertypes{$type} ne '') {
18909: $typename = $usertypes{$type};
1.224 raeburn 18910: }
18911: }
18912: my @modifiable;
18913: $resulttext .= '<li>'.
18914: &mt('Self-creation of account by users with status: [_1]',
18915: '<span class="LC_cusr_emph">'.$typename.'</span>').
18916: ' - '.&mt('modifiable fields (if institutional data blank): ');
18917: foreach my $field (@fields) {
18918: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18919: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18920: }
18921: }
1.224 raeburn 18922: if (@modifiable > 0) {
18923: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18924: } else {
1.224 raeburn 18925: $resulttext .= &mt('none');
1.43 raeburn 18926: }
1.224 raeburn 18927: $resulttext .= '</li>';
1.28 raeburn 18928: }
1.224 raeburn 18929: $resulttext .= '</ul></li>';
1.28 raeburn 18930: }
1.27 raeburn 18931: $resulttext .= '</ul>';
1.305 raeburn 18932: my $cachetime = 24*60*60;
18933: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18934: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18935: if (ref($lastactref) eq 'HASH') {
18936: $lastactref->{'domdefaults'} = 1;
18937: }
1.27 raeburn 18938: } else {
1.224 raeburn 18939: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 18940: }
18941: } else {
18942: $resulttext = '<span class="LC_error">'.
1.23 raeburn 18943: &mt('An error occurred: [_1]',$putresult).'</span>';
18944: }
1.43 raeburn 18945: if ($warningmsg ne '') {
18946: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18947: }
1.23 raeburn 18948: return $resulttext;
18949: }
18950:
1.165 raeburn 18951: sub process_captcha {
1.369 raeburn 18952: my ($container,$changes,$newsettings,$currsettings) = @_;
18953: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 18954: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
18955: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
18956: $newsettings->{'captcha'} = 'original';
18957: }
1.369 raeburn 18958: my %current;
18959: if (ref($currsettings) eq 'HASH') {
18960: %current = %{$currsettings};
18961: }
18962: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 18963: if ($container eq 'cancreate') {
1.169 raeburn 18964: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
18965: push(@{$changes->{'cancreate'}},'captcha');
18966: } elsif (!defined($changes->{'cancreate'})) {
18967: $changes->{'cancreate'} = ['captcha'];
18968: }
1.368 raeburn 18969: } elsif ($container eq 'passwords') {
18970: $changes->{'reset'} = 1;
1.169 raeburn 18971: } else {
18972: $changes->{'captcha'} = 1;
1.165 raeburn 18973: }
18974: }
1.269 raeburn 18975: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 18976: if ($newsettings->{'captcha'} eq 'recaptcha') {
18977: $newpub = $env{'form.'.$container.'_recaptchapub'};
18978: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 18979: $newpub =~ s/[^\w\-]//g;
18980: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 18981: $newsettings->{'recaptchakeys'} = {
18982: public => $newpub,
18983: private => $newpriv,
18984: };
1.269 raeburn 18985: $newversion = $env{'form.'.$container.'_recaptchaversion'};
18986: $newversion =~ s/\D//g;
18987: if ($newversion ne '2') {
18988: $newversion = 1;
18989: }
18990: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 18991: }
1.369 raeburn 18992: if (ref($current{'recaptchakeys'}) eq 'HASH') {
18993: $currpub = $current{'recaptchakeys'}{'public'};
18994: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 18995: unless ($newsettings->{'captcha'} eq 'recaptcha') {
18996: $newsettings->{'recaptchakeys'} = {
18997: public => '',
18998: private => '',
18999: }
19000: }
1.165 raeburn 19001: }
1.369 raeburn 19002: if ($current{'captcha'} eq 'recaptcha') {
19003: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19004: if ($currversion ne '2') {
19005: $currversion = 1;
19006: }
19007: }
19008: if ($currversion ne $newversion) {
19009: if ($container eq 'cancreate') {
19010: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19011: push(@{$changes->{'cancreate'}},'recaptchaversion');
19012: } elsif (!defined($changes->{'cancreate'})) {
19013: $changes->{'cancreate'} = ['recaptchaversion'];
19014: }
1.368 raeburn 19015: } elsif ($container eq 'passwords') {
19016: $changes->{'reset'} = 1;
1.269 raeburn 19017: } else {
19018: $changes->{'recaptchaversion'} = 1;
19019: }
19020: }
1.165 raeburn 19021: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19022: if ($container eq 'cancreate') {
19023: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19024: push(@{$changes->{'cancreate'}},'recaptchakeys');
19025: } elsif (!defined($changes->{'cancreate'})) {
19026: $changes->{'cancreate'} = ['recaptchakeys'];
19027: }
1.368 raeburn 19028: } elsif ($container eq 'passwords') {
19029: $changes->{'reset'} = 1;
1.169 raeburn 19030: } else {
1.210 raeburn 19031: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19032: }
19033: }
19034: return;
19035: }
19036:
1.33 raeburn 19037: sub modify_usermodification {
19038: my ($dom,%domconfig) = @_;
1.224 raeburn 19039: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19040: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19041: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19042: if ($key eq 'selfcreate') {
19043: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19044: } else {
19045: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19046: }
1.33 raeburn 19047: }
19048: }
1.224 raeburn 19049: my @contexts = ('author','course');
1.33 raeburn 19050: my %context_title = (
19051: author => 'In author context',
19052: course => 'In course context',
19053: );
19054: my @fields = ('lastname','firstname','middlename','generation',
19055: 'permanentemail','id');
19056: my %roles = (
19057: author => ['ca','aa'],
19058: course => ['st','ep','ta','in','cr'],
19059: );
19060: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19061: foreach my $context (@contexts) {
19062: foreach my $role (@{$roles{$context}}) {
19063: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19064: foreach my $item (@fields) {
19065: if (grep(/^\Q$item\E$/,@modifiable)) {
19066: $modifyhash{$context}{$role}{$item} = 1;
19067: } else {
19068: $modifyhash{$context}{$role}{$item} = 0;
19069: }
19070: }
19071: }
19072: if (ref($curr_usermodification{$context}) eq 'HASH') {
19073: foreach my $role (@{$roles{$context}}) {
19074: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19075: foreach my $field (@fields) {
19076: if ($modifyhash{$context}{$role}{$field} ne
19077: $curr_usermodification{$context}{$role}{$field}) {
19078: push(@{$changes{$context}},$role);
19079: last;
19080: }
19081: }
19082: }
19083: }
19084: } else {
19085: foreach my $context (@contexts) {
19086: foreach my $role (@{$roles{$context}}) {
19087: push(@{$changes{$context}},$role);
19088: }
19089: }
19090: }
19091: }
19092: my %usermodification_hash = (
19093: usermodification => \%modifyhash,
19094: );
19095: my $putresult = &Apache::lonnet::put_dom('configuration',
19096: \%usermodification_hash,$dom);
19097: if ($putresult eq 'ok') {
19098: if (keys(%changes) > 0) {
19099: $resulttext = &mt('Changes made: ').'<ul>';
19100: foreach my $context (@contexts) {
19101: if (ref($changes{$context}) eq 'ARRAY') {
19102: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19103: if (ref($changes{$context}) eq 'ARRAY') {
19104: foreach my $role (@{$changes{$context}}) {
19105: my $rolename;
1.224 raeburn 19106: if ($role eq 'cr') {
19107: $rolename = &mt('Custom');
1.33 raeburn 19108: } else {
1.224 raeburn 19109: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19110: }
19111: my @modifiable;
1.224 raeburn 19112: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19113: foreach my $field (@fields) {
19114: if ($modifyhash{$context}{$role}{$field}) {
19115: push(@modifiable,$fieldtitles{$field});
19116: }
19117: }
19118: if (@modifiable > 0) {
19119: $resulttext .= join(', ',@modifiable);
19120: } else {
19121: $resulttext .= &mt('none');
19122: }
19123: $resulttext .= '</li>';
19124: }
19125: $resulttext .= '</ul></li>';
19126: }
19127: }
19128: }
19129: $resulttext .= '</ul>';
19130: } else {
19131: $resulttext = &mt('No changes made to user modification settings');
19132: }
19133: } else {
19134: $resulttext = '<span class="LC_error">'.
19135: &mt('An error occurred: [_1]',$putresult).'</span>';
19136: }
19137: return $resulttext;
19138: }
19139:
1.43 raeburn 19140: sub modify_defaults {
1.212 raeburn 19141: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19142: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19144: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19145: 'portal_def');
1.325 raeburn 19146: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19147: foreach my $item (@items) {
19148: $newvalues{$item} = $env{'form.'.$item};
19149: if ($item eq 'auth_def') {
19150: if ($newvalues{$item} ne '') {
19151: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19152: push(@errors,$item);
19153: }
19154: }
19155: } elsif ($item eq 'lang_def') {
19156: if ($newvalues{$item} ne '') {
19157: if ($newvalues{$item} =~ /^(\w+)/) {
19158: my $langcode = $1;
1.103 raeburn 19159: if ($langcode ne 'x_chef') {
19160: if (code2language($langcode) eq '') {
19161: push(@errors,$item);
19162: }
1.43 raeburn 19163: }
19164: } else {
19165: push(@errors,$item);
19166: }
19167: }
1.54 raeburn 19168: } elsif ($item eq 'timezone_def') {
19169: if ($newvalues{$item} ne '') {
1.62 raeburn 19170: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19171: push(@errors,$item);
19172: }
19173: }
1.68 raeburn 19174: } elsif ($item eq 'datelocale_def') {
19175: if ($newvalues{$item} ne '') {
19176: my @datelocale_ids = DateTime::Locale->ids();
19177: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19178: push(@errors,$item);
19179: }
19180: }
1.141 raeburn 19181: } elsif ($item eq 'portal_def') {
19182: if ($newvalues{$item} ne '') {
19183: 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])\/?$/) {
19184: push(@errors,$item);
19185: }
19186: }
1.43 raeburn 19187: }
19188: if (grep(/^\Q$item\E$/,@errors)) {
19189: $newvalues{$item} = $domdefaults{$item};
19190: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19191: $changes{$item} = 1;
19192: }
1.72 raeburn 19193: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19194: }
1.354 raeburn 19195: my %staticdefaults = (
19196: 'intauth_cost' => 10,
19197: 'intauth_check' => 0,
19198: 'intauth_switch' => 0,
19199: );
19200: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19201: if (exists($domdefaults{$item})) {
19202: $newvalues{$item} = $domdefaults{$item};
19203: } else {
19204: $newvalues{$item} = $staticdefaults{$item};
19205: }
19206: }
1.43 raeburn 19207: my %defaults_hash = (
1.72 raeburn 19208: defaults => \%newvalues,
19209: );
1.43 raeburn 19210: my $title = &defaults_titles();
1.236 raeburn 19211:
19212: my $currinststatus;
19213: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19214: $currinststatus = $domconfig{'inststatus'};
19215: } else {
19216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19217: $currinststatus = {
19218: inststatustypes => $usertypes,
19219: inststatusorder => $types,
19220: inststatusguest => [],
19221: };
19222: }
19223: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19224: my @allpos;
19225: my %alltypes;
1.305 raeburn 19226: my @inststatusguest;
19227: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19228: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19229: unless (grep(/^\Q$type\E$/,@todelete)) {
19230: push(@inststatusguest,$type);
19231: }
19232: }
19233: }
19234: my ($currtitles,$currorder);
1.236 raeburn 19235: if (ref($currinststatus) eq 'HASH') {
19236: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19237: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19238: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19239: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19240: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19241: }
19242: }
19243: unless (grep(/^\Q$type\E$/,@todelete)) {
19244: my $position = $env{'form.inststatus_pos_'.$type};
19245: $position =~ s/\D+//g;
19246: $allpos[$position] = $type;
19247: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19248: $alltypes{$type} =~ s/`//g;
19249: }
19250: }
19251: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19252: $currtitles =~ s/,$//;
19253: }
19254: }
19255: if ($env{'form.addinststatus'}) {
19256: my $newtype = $env{'form.addinststatus'};
19257: $newtype =~ s/\W//g;
19258: unless (exists($alltypes{$newtype})) {
19259: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19260: $alltypes{$newtype} =~ s/`//g;
19261: my $position = $env{'form.addinststatus_pos'};
19262: $position =~ s/\D+//g;
19263: if ($position ne '') {
19264: $allpos[$position] = $newtype;
19265: }
19266: }
19267: }
1.305 raeburn 19268: my @orderedstatus;
1.236 raeburn 19269: foreach my $type (@allpos) {
19270: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19271: push(@orderedstatus,$type);
19272: }
19273: }
19274: foreach my $type (keys(%alltypes)) {
19275: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19276: delete($alltypes{$type});
19277: }
19278: }
19279: $defaults_hash{'inststatus'} = {
19280: inststatustypes => \%alltypes,
19281: inststatusorder => \@orderedstatus,
1.305 raeburn 19282: inststatusguest => \@inststatusguest,
1.236 raeburn 19283: };
19284: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19285: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19286: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19287: }
19288: }
19289: if ($currorder ne join(',',@orderedstatus)) {
19290: $changes{'inststatus'}{'inststatusorder'} = 1;
19291: }
19292: my $newtitles;
19293: foreach my $item (@orderedstatus) {
19294: $newtitles .= $alltypes{$item}.',';
19295: }
19296: $newtitles =~ s/,$//;
19297: if ($currtitles ne $newtitles) {
19298: $changes{'inststatus'}{'inststatustypes'} = 1;
19299: }
1.43 raeburn 19300: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19301: $dom);
19302: if ($putresult eq 'ok') {
19303: if (keys(%changes) > 0) {
19304: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19305: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19306: 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";
19307: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19308: if ($item eq 'inststatus') {
19309: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19310: if (@orderedstatus) {
1.236 raeburn 19311: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19312: foreach my $type (@orderedstatus) {
19313: $resulttext .= $alltypes{$type}.', ';
19314: }
19315: $resulttext =~ s/, $//;
19316: $resulttext .= '</li>';
1.305 raeburn 19317: } else {
19318: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19319: }
19320: }
19321: } else {
19322: my $value = $env{'form.'.$item};
19323: if ($value eq '') {
19324: $value = &mt('none');
19325: } elsif ($item eq 'auth_def') {
19326: my %authnames = &authtype_names();
19327: my %shortauth = (
19328: internal => 'int',
19329: krb4 => 'krb4',
19330: krb5 => 'krb5',
19331: localauth => 'loc',
1.325 raeburn 19332: lti => 'lti',
1.236 raeburn 19333: );
19334: $value = $authnames{$shortauth{$value}};
19335: }
19336: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
19337: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 19338: }
19339: }
19340: $resulttext .= '</ul>';
19341: $mailmsgtext .= "\n";
19342: my $cachetime = 24*60*60;
1.72 raeburn 19343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19344: if (ref($lastactref) eq 'HASH') {
19345: $lastactref->{'domdefaults'} = 1;
19346: }
1.68 raeburn 19347: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 19348: my $notify = 1;
19349: if (ref($domconfig{'contacts'}) eq 'HASH') {
19350: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
19351: $notify = 0;
19352: }
19353: }
19354: if ($notify) {
19355: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
19356: "LON-CAPA Domain Settings Change - $dom",
19357: $mailmsgtext);
19358: }
1.54 raeburn 19359: }
1.43 raeburn 19360: } else {
1.54 raeburn 19361: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 19362: }
19363: } else {
19364: $resulttext = '<span class="LC_error">'.
19365: &mt('An error occurred: [_1]',$putresult).'</span>';
19366: }
19367: if (@errors > 0) {
19368: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
19369: foreach my $item (@errors) {
19370: $resulttext .= ' "'.$title->{$item}.'",';
19371: }
19372: $resulttext =~ s/,$//;
19373: }
19374: return $resulttext;
19375: }
19376:
1.46 raeburn 19377: sub modify_scantron {
1.205 raeburn 19378: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 19379: my ($resulttext,%confhash,%changes,$errors);
19380: my $custom = 'custom.tab';
19381: my $default = 'default.tab';
19382: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 19383: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 19384: &config_check($dom,$confname,$servadm);
19385: if ($env{'form.scantronformat.filename'} ne '') {
19386: my $error;
19387: if ($configuserok eq 'ok') {
19388: if ($switchserver) {
1.130 raeburn 19389: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 19390: } else {
19391: if ($author_ok eq 'ok') {
19392: my ($result,$scantronurl) =
19393: &publishlogo($r,'upload','scantronformat',$dom,
19394: $confname,'scantron','','',$custom);
19395: if ($result eq 'ok') {
19396: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 19397: $changes{'scantronformat'} = 1;
1.46 raeburn 19398: } else {
19399: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
19400: }
19401: } else {
19402: $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);
19403: }
19404: }
19405: } else {
19406: $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);
19407: }
19408: if ($error) {
19409: &Apache::lonnet::logthis($error);
19410: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
19411: }
19412: }
1.48 raeburn 19413: if (ref($domconfig{'scantron'}) eq 'HASH') {
19414: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
19415: if ($env{'form.scantronformat_del'}) {
19416: $confhash{'scantron'}{'scantronformat'} = '';
19417: $changes{'scantronformat'} = 1;
1.347 raeburn 19418: } else {
19419: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 19420: }
19421: }
19422: }
1.347 raeburn 19423: my @options = ('hdr','pad','rem');
1.346 raeburn 19424: my @fields = &scantroncsv_fields();
19425: my %titles = &scantronconfig_titles();
1.347 raeburn 19426: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 19427: my ($newdat,$currdat,%newcol,%currcol);
19428: if (grep(/^dat$/,@formats)) {
19429: $confhash{'scantron'}{config}{dat} = 1;
19430: $newdat = 1;
19431: } else {
19432: $newdat = 0;
19433: }
19434: if (grep(/^csv$/,@formats)) {
19435: my %bynum;
19436: foreach my $field (@fields) {
19437: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
19438: my $posscol = $1;
19439: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 19440: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 19441: $bynum{$posscol} = $field;
19442: $newcol{$field} = $posscol;
19443: }
19444: }
19445: }
1.347 raeburn 19446: if (keys(%newcol)) {
19447: foreach my $option (@options) {
19448: if ($env{'form.scantroncsv_'.$option}) {
19449: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
19450: }
19451: }
19452: }
1.346 raeburn 19453: }
19454: $currdat = 1;
19455: if (ref($domconfig{'scantron'}) eq 'HASH') {
19456: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 19457: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 19458: $currdat = 0;
19459: }
19460: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19461: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19462: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
19463: }
1.346 raeburn 19464: }
19465: }
19466: }
19467: if ($currdat != $newdat) {
19468: $changes{'config'} = 1;
19469: } else {
19470: foreach my $field (@fields) {
19471: if ($currcol{$field} ne '') {
19472: if ($currcol{$field} ne $newcol{$field}) {
19473: $changes{'config'} = 1;
19474: last;
1.347 raeburn 19475: }
1.346 raeburn 19476: } elsif ($newcol{$field} ne '') {
19477: $changes{'config'} = 1;
19478: last;
19479: }
19480: }
19481: }
1.46 raeburn 19482: if (keys(%confhash) > 0) {
19483: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
19484: $dom);
19485: if ($putresult eq 'ok') {
19486: if (keys(%changes) > 0) {
1.48 raeburn 19487: if (ref($confhash{'scantron'}) eq 'HASH') {
19488: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 19489: if ($changes{'scantronformat'}) {
19490: if ($confhash{'scantron'}{'scantronformat'} eq '') {
19491: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
19492: } else {
19493: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
19494: }
19495: }
1.347 raeburn 19496: if ($changes{'config'}) {
1.346 raeburn 19497: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
19498: if ($confhash{'scantron'}{'config'}{'dat'}) {
19499: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
19500: }
19501: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19502: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19503: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
19504: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
19505: foreach my $field (@fields) {
19506: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
19507: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
19508: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
19509: }
19510: }
19511: $resulttext .= '</ul></li>';
19512: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
19513: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
19514: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
19515: foreach my $option (@options) {
19516: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
19517: $resulttext .= '<li>'.$titles{$option}.'</li>';
19518: }
19519: }
19520: $resulttext .= '</ul></li>';
19521: }
1.346 raeburn 19522: }
19523: }
19524: }
19525: }
19526: } else {
19527: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
19528: }
1.46 raeburn 19529: }
1.48 raeburn 19530: $resulttext .= '</ul>';
19531: } else {
1.130 raeburn 19532: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 19533: }
19534: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 19535: if (ref($lastactref) eq 'HASH') {
19536: $lastactref->{'domainconfig'} = 1;
19537: }
1.46 raeburn 19538: } else {
1.346 raeburn 19539: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19540: }
19541: } else {
19542: $resulttext = '<span class="LC_error">'.
19543: &mt('An error occurred: [_1]',$putresult).'</span>';
19544: }
19545: } else {
1.130 raeburn 19546: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19547: }
19548: if ($errors) {
1.353 raeburn 19549: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19550: $errors.'</ul></p>';
1.46 raeburn 19551: }
19552: return $resulttext;
19553: }
19554:
1.48 raeburn 19555: sub modify_coursecategories {
1.239 raeburn 19556: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19557: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19558: $cathash);
1.48 raeburn 19559: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19560: my @catitems = ('unauth','auth');
19561: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19562: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19563: $cathash = $domconfig{'coursecategories'}{'cats'};
19564: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19565: $changes{'togglecats'} = 1;
19566: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19567: }
19568: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19569: $changes{'categorize'} = 1;
19570: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19571: }
1.120 raeburn 19572: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19573: $changes{'togglecatscomm'} = 1;
19574: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19575: }
19576: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19577: $changes{'categorizecomm'} = 1;
19578: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19579:
19580: }
19581: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19582: $changes{'togglecatsplace'} = 1;
19583: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19584: }
19585: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19586: $changes{'categorizeplace'} = 1;
19587: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19588: }
1.238 raeburn 19589: foreach my $item (@catitems) {
19590: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19591: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19592: $changes{$item} = 1;
19593: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19594: }
19595: }
19596: }
1.57 raeburn 19597: } else {
19598: $changes{'togglecats'} = 1;
19599: $changes{'categorize'} = 1;
1.124 raeburn 19600: $changes{'togglecatscomm'} = 1;
19601: $changes{'categorizecomm'} = 1;
1.272 raeburn 19602: $changes{'togglecatsplace'} = 1;
19603: $changes{'categorizeplace'} = 1;
1.87 raeburn 19604: $domconfig{'coursecategories'} = {
19605: togglecats => $env{'form.togglecats'},
19606: categorize => $env{'form.categorize'},
1.124 raeburn 19607: togglecatscomm => $env{'form.togglecatscomm'},
19608: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19609: togglecatsplace => $env{'form.togglecatsplace'},
19610: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19611: };
1.238 raeburn 19612: foreach my $item (@catitems) {
19613: if ($env{'form.coursecat_'.$item} ne 'std') {
19614: $changes{$item} = 1;
19615: }
19616: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19617: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19618: }
19619: }
1.57 raeburn 19620: }
19621: if (ref($cathash) eq 'HASH') {
19622: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19623: push (@deletecategory,'instcode::0');
19624: }
1.120 raeburn 19625: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19626: push(@deletecategory,'communities::0');
19627: }
1.272 raeburn 19628: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19629: push(@deletecategory,'placement::0');
19630: }
1.48 raeburn 19631: }
1.57 raeburn 19632: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19633: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19634: if (@deletecategory > 0) {
19635: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19636: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19637: foreach my $item (@deletecategory) {
1.57 raeburn 19638: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19639: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19640: $deletions{$item} = 1;
1.57 raeburn 19641: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19642: }
19643: }
19644: }
1.57 raeburn 19645: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19646: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19647: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19648: $reorderings{$item} = 1;
1.57 raeburn 19649: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19650: }
19651: if ($env{'form.addcategory_name_'.$item} ne '') {
19652: my $newcat = $env{'form.addcategory_name_'.$item};
19653: my $newdepth = $depth+1;
19654: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19655: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19656: $adds{$newitem} = 1;
19657: }
19658: if ($env{'form.subcat_'.$item} ne '') {
19659: my $newcat = $env{'form.subcat_'.$item};
19660: my $newdepth = $depth+1;
19661: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19662: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19663: $adds{$newitem} = 1;
19664: }
19665: }
19666: }
19667: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19668: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19669: my $newitem = 'instcode::0';
1.57 raeburn 19670: if ($cathash->{$newitem} eq '') {
19671: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19672: $adds{$newitem} = 1;
19673: }
19674: } else {
19675: my $newitem = 'instcode::0';
1.57 raeburn 19676: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19677: $adds{$newitem} = 1;
19678: }
19679: }
1.120 raeburn 19680: if ($env{'form.communities'} eq '1') {
19681: if (ref($cathash) eq 'HASH') {
19682: my $newitem = 'communities::0';
19683: if ($cathash->{$newitem} eq '') {
19684: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19685: $adds{$newitem} = 1;
19686: }
19687: } else {
19688: my $newitem = 'communities::0';
19689: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19690: $adds{$newitem} = 1;
19691: }
19692: }
1.272 raeburn 19693: if ($env{'form.placement'} eq '1') {
19694: if (ref($cathash) eq 'HASH') {
19695: my $newitem = 'placement::0';
19696: if ($cathash->{$newitem} eq '') {
19697: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19698: $adds{$newitem} = 1;
19699: }
19700: } else {
19701: my $newitem = 'placement::0';
19702: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19703: $adds{$newitem} = 1;
19704: }
19705: }
1.48 raeburn 19706: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19707: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19708: ($env{'form.addcategory_name'} ne 'communities') &&
19709: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19710: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19711: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19712: $adds{$newitem} = 1;
19713: }
1.48 raeburn 19714: }
1.57 raeburn 19715: my $putresult;
1.48 raeburn 19716: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19717: if (keys(%deletions) > 0) {
19718: foreach my $key (keys(%deletions)) {
19719: if ($predelallitems{$key} ne '') {
19720: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19721: }
19722: }
19723: }
19724: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19725: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19726: if (ref($chkcats[0]) eq 'ARRAY') {
19727: my $depth = 0;
19728: my $chg = 0;
19729: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19730: my $name = $chkcats[0][$i];
19731: my $item;
19732: if ($name eq '') {
19733: $chg ++;
19734: } else {
19735: $item = &escape($name).'::0';
19736: if ($chg) {
1.57 raeburn 19737: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19738: }
19739: $depth ++;
1.57 raeburn 19740: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19741: $depth --;
19742: }
19743: }
19744: }
1.57 raeburn 19745: }
19746: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19747: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19748: if ($putresult eq 'ok') {
1.57 raeburn 19749: my %title = (
1.120 raeburn 19750: togglecats => 'Show/Hide a course in catalog',
19751: categorize => 'Assign a category to a course',
19752: togglecatscomm => 'Show/Hide a community in catalog',
19753: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19754: );
19755: my %level = (
1.120 raeburn 19756: dom => 'set in Domain ("Modify Course/Community")',
19757: crs => 'set in Course ("Course Configuration")',
19758: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19759: none => 'No catalog',
19760: std => 'Standard catalog',
19761: domonly => 'Domain-only catalog',
19762: codesrch => 'Code search form',
1.57 raeburn 19763: );
1.48 raeburn 19764: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19765: if ($changes{'togglecats'}) {
19766: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19767: }
19768: if ($changes{'categorize'}) {
19769: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19770: }
1.120 raeburn 19771: if ($changes{'togglecatscomm'}) {
19772: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19773: }
19774: if ($changes{'categorizecomm'}) {
19775: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19776: }
1.238 raeburn 19777: if ($changes{'unauth'}) {
19778: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19779: }
19780: if ($changes{'auth'}) {
19781: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19782: }
1.57 raeburn 19783: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19784: my $cathash;
19785: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19786: $cathash = $domconfig{'coursecategories'}{'cats'};
19787: } else {
19788: $cathash = {};
19789: }
19790: my (@cats,@trails,%allitems);
19791: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19792: if (keys(%deletions) > 0) {
19793: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19794: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19795: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19796: }
19797: $resulttext .= '</ul></li>';
19798: }
19799: if (keys(%reorderings) > 0) {
19800: my %sort_by_trail;
19801: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19802: foreach my $key (keys(%reorderings)) {
19803: if ($allitems{$key} ne '') {
19804: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19805: }
1.48 raeburn 19806: }
1.57 raeburn 19807: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19808: $resulttext .= '<li>'.$trails[$trail].'</li>';
19809: }
19810: $resulttext .= '</ul></li>';
1.48 raeburn 19811: }
1.57 raeburn 19812: if (keys(%adds) > 0) {
19813: my %sort_by_trail;
19814: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19815: foreach my $key (keys(%adds)) {
19816: if ($allitems{$key} ne '') {
19817: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19818: }
19819: }
19820: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19821: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19822: }
1.57 raeburn 19823: $resulttext .= '</ul></li>';
1.48 raeburn 19824: }
1.364 raeburn 19825: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
19826: if (ref($lastactref) eq 'HASH') {
19827: $lastactref->{'cats'} = 1;
19828: }
1.48 raeburn 19829: }
19830: $resulttext .= '</ul>';
1.239 raeburn 19831: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 19832: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19833: if ($changes{'auth'}) {
19834: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
19835: }
19836: if ($changes{'unauth'}) {
19837: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
19838: }
19839: my $cachetime = 24*60*60;
19840: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 19841: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 19842: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 19843: }
19844: }
1.48 raeburn 19845: } else {
19846: $resulttext = '<span class="LC_error">'.
1.57 raeburn 19847: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 19848: }
19849: } else {
1.120 raeburn 19850: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 19851: }
19852: return $resulttext;
19853: }
19854:
1.69 raeburn 19855: sub modify_serverstatuses {
19856: my ($dom,%domconfig) = @_;
19857: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
19858: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
19859: %currserverstatus = %{$domconfig{'serverstatuses'}};
19860: }
19861: my @pages = &serverstatus_pages();
19862: foreach my $type (@pages) {
19863: $newserverstatus{$type}{'namedusers'} = '';
19864: $newserverstatus{$type}{'machines'} = '';
19865: if (defined($env{'form.'.$type.'_namedusers'})) {
19866: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
19867: my @okusers;
19868: foreach my $user (@users) {
19869: my ($uname,$udom) = split(/:/,$user);
19870: if (($udom =~ /^$match_domain$/) &&
19871: (&Apache::lonnet::domain($udom)) &&
19872: ($uname =~ /^$match_username$/)) {
19873: if (!grep(/^\Q$user\E/,@okusers)) {
19874: push(@okusers,$user);
19875: }
19876: }
19877: }
19878: if (@okusers > 0) {
19879: @okusers = sort(@okusers);
19880: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
19881: }
19882: }
19883: if (defined($env{'form.'.$type.'_machines'})) {
19884: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
19885: my @okmachines;
19886: foreach my $ip (@machines) {
19887: my @parts = split(/\./,$ip);
19888: next if (@parts < 4);
19889: my $badip = 0;
19890: for (my $i=0; $i<4; $i++) {
19891: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
19892: $badip = 1;
19893: last;
19894: }
19895: }
19896: if (!$badip) {
19897: push(@okmachines,$ip);
19898: }
19899: }
19900: @okmachines = sort(@okmachines);
19901: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
19902: }
19903: }
19904: my %serverstatushash = (
19905: serverstatuses => \%newserverstatus,
19906: );
19907: foreach my $type (@pages) {
1.83 raeburn 19908: foreach my $setting ('namedusers','machines') {
1.84 raeburn 19909: my (@current,@new);
1.83 raeburn 19910: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 19911: if ($currserverstatus{$type}{$setting} ne '') {
19912: @current = split(/,/,$currserverstatus{$type}{$setting});
19913: }
19914: }
19915: if ($newserverstatus{$type}{$setting} ne '') {
19916: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 19917: }
19918: if (@current > 0) {
19919: if (@new > 0) {
19920: foreach my $item (@current) {
19921: if (!grep(/^\Q$item\E$/,@new)) {
19922: $changes{$type}{$setting} = 1;
1.82 raeburn 19923: last;
19924: }
19925: }
1.84 raeburn 19926: foreach my $item (@new) {
19927: if (!grep(/^\Q$item\E$/,@current)) {
19928: $changes{$type}{$setting} = 1;
19929: last;
1.82 raeburn 19930: }
19931: }
19932: } else {
1.83 raeburn 19933: $changes{$type}{$setting} = 1;
1.69 raeburn 19934: }
1.83 raeburn 19935: } elsif (@new > 0) {
19936: $changes{$type}{$setting} = 1;
1.69 raeburn 19937: }
19938: }
19939: }
19940: if (keys(%changes) > 0) {
1.81 raeburn 19941: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 19942: my $putresult = &Apache::lonnet::put_dom('configuration',
19943: \%serverstatushash,$dom);
19944: if ($putresult eq 'ok') {
19945: $resulttext .= &mt('Changes made:').'<ul>';
19946: foreach my $type (@pages) {
1.84 raeburn 19947: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 19948: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 19949: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 19950: if ($newserverstatus{$type}{'namedusers'} eq '') {
19951: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
19952: } else {
19953: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
19954: }
1.84 raeburn 19955: }
19956: if ($changes{$type}{'machines'}) {
1.69 raeburn 19957: if ($newserverstatus{$type}{'machines'} eq '') {
19958: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
19959: } else {
19960: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
19961: }
19962:
19963: }
19964: $resulttext .= '</ul></li>';
19965: }
19966: }
19967: $resulttext .= '</ul>';
19968: } else {
19969: $resulttext = '<span class="LC_error">'.
19970: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
19971:
19972: }
19973: } else {
19974: $resulttext = &mt('No changes made to access to server status pages');
19975: }
19976: return $resulttext;
19977: }
19978:
1.118 jms 19979: sub modify_helpsettings {
1.285 raeburn 19980: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 19981: my ($resulttext,$errors,%changes,%helphash);
19982: my %defaultchecked = ('submitbugs' => 'on');
19983: my @offon = ('off','on');
1.118 jms 19984: my @toggles = ('submitbugs');
1.285 raeburn 19985: my %current = ('submitbugs' => '',
19986: 'adhoc' => {},
19987: );
1.118 jms 19988: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 19989: %current = %{$domconfig{'helpsettings'}};
19990: }
1.285 raeburn 19991: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 19992: foreach my $item (@toggles) {
19993: if ($defaultchecked{$item} eq 'on') {
19994: if ($current{$item} eq '') {
19995: if ($env{'form.'.$item} eq '0') {
19996: $changes{$item} = 1;
19997: }
19998: } elsif ($current{$item} ne $env{'form.'.$item}) {
19999: $changes{$item} = 1;
20000: }
20001: } elsif ($defaultchecked{$item} eq 'off') {
20002: if ($current{$item} eq '') {
20003: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20004: $changes{$item} = 1;
20005: }
1.282 raeburn 20006: } elsif ($current{$item} ne $env{'form.'.$item}) {
20007: $changes{$item} = 1;
20008: }
20009: }
20010: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20011: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20012: }
20013: }
1.285 raeburn 20014: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20015: my $confname = $dom.'-domainconfig';
20016: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20017: my (@allpos,%newsettings,%changedprivs,$newrole);
20018: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20019: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20020: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20021: my %lt = &Apache::lonlocal::texthash(
20022: s => 'system',
20023: d => 'domain',
20024: order => 'Display order',
20025: access => 'Role usage',
1.291 raeburn 20026: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20027: dh => 'All with domain helpdesk role',
20028: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20029: none => 'None',
20030: status => 'Determined based on institutional status',
20031: inc => 'Include all, but exclude specific personnel',
20032: exc => 'Exclude all, but include specific personnel',
20033: );
20034: for (my $num=0; $num<=$maxnum; $num++) {
20035: my ($prefix,$identifier,$rolename,%curr);
20036: if ($num == $maxnum) {
20037: next unless ($env{'form.newcusthelp'} == $maxnum);
20038: $identifier = 'custhelp'.$num;
20039: $prefix = 'helproles_'.$num;
20040: $rolename = $env{'form.custhelpname'.$num};
20041: $rolename=~s/[^A-Za-z0-9]//gs;
20042: next if ($rolename eq '');
20043: next if (exists($existing{'rolesdef_'.$rolename}));
20044: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20045: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20046: $newprivs{'c'},$confname,$dom);
20047: if ($result ne 'ok') {
20048: $errors .= '<li><span class="LC_error">'.
20049: &mt('An error occurred storing the new custom role: [_1]',
20050: $result).'</span></li>';
20051: next;
20052: } else {
20053: $changedprivs{$rolename} = \%newprivs;
20054: $newrole = $rolename;
20055: }
20056: } else {
20057: $prefix = 'helproles_'.$num;
20058: $rolename = $env{'form.'.$prefix};
20059: next if ($rolename eq '');
20060: next unless (exists($existing{'rolesdef_'.$rolename}));
20061: $identifier = 'custhelp'.$num;
20062: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20063: my %currprivs;
1.289 raeburn 20064: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20065: split(/\_/,$existing{'rolesdef_'.$rolename});
20066: foreach my $level ('c','d','s') {
20067: if ($newprivs{$level} ne $currprivs{$level}) {
20068: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20069: $newprivs{'c'},$confname,$dom);
20070: if ($result ne 'ok') {
20071: $errors .= '<li><span class="LC_error">'.
20072: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20073: $rolename,$result).'</span></li>';
20074: } else {
20075: $changedprivs{$rolename} = \%newprivs;
20076: }
20077: last;
20078: }
20079: }
20080: if (ref($current{'adhoc'}) eq 'HASH') {
20081: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20082: %curr = %{$current{'adhoc'}{$rolename}};
20083: }
20084: }
20085: }
20086: my $newpos = $env{'form.'.$prefix.'_pos'};
20087: $newpos =~ s/\D+//g;
20088: $allpos[$newpos] = $rolename;
20089: my $newdesc = $env{'form.'.$prefix.'_desc'};
20090: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20091: if ($curr{'desc'}) {
20092: if ($curr{'desc'} ne $newdesc) {
20093: $changes{'customrole'}{$rolename}{'desc'} = 1;
20094: $newsettings{$rolename}{'desc'} = $newdesc;
20095: }
20096: } elsif ($newdesc ne '') {
20097: $changes{'customrole'}{$rolename}{'desc'} = 1;
20098: $newsettings{$rolename}{'desc'} = $newdesc;
20099: }
20100: my $access = $env{'form.'.$prefix.'_access'};
20101: if (grep(/^\Q$access\E$/,@accesstypes)) {
20102: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20103: if ($access eq 'status') {
20104: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20105: if (scalar(@statuses) == 0) {
1.289 raeburn 20106: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20107: } else {
20108: my (@shownstatus,$numtypes);
20109: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20110: if (ref($types) eq 'ARRAY') {
20111: $numtypes = scalar(@{$types});
20112: foreach my $type (sort(@statuses)) {
20113: if ($type eq 'default') {
20114: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20115: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20116: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20117: push(@shownstatus,$usertypes->{$type});
20118: }
20119: }
20120: }
20121: if (grep(/^default$/,@statuses)) {
20122: push(@shownstatus,$othertitle);
20123: }
20124: if (scalar(@shownstatus) == 1+$numtypes) {
20125: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20126: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20127: } else {
20128: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20129: if (ref($curr{'status'}) eq 'ARRAY') {
20130: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20131: if (@diffs) {
20132: $changes{'customrole'}{$rolename}{$access} = 1;
20133: }
20134: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20135: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20136: }
1.166 raeburn 20137: }
20138: }
1.285 raeburn 20139: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20140: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20141: my @newspecstaff;
20142: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20143: foreach my $person (sort(@personnel)) {
20144: if ($domhelpdesk{$person}) {
20145: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20146: }
20147: }
20148: if (ref($curr{$access}) eq 'ARRAY') {
20149: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20150: if (@diffs) {
20151: $changes{'customrole'}{$rolename}{$access} = 1;
20152: }
20153: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20154: $changes{'customrole'}{$rolename}{$access} = 1;
20155: }
20156: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20157: my ($uname,$udom) = split(/:/,$person);
20158: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20159: }
20160: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20161: }
1.285 raeburn 20162: } else {
20163: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20164: }
20165: unless ($curr{'access'} eq $access) {
20166: $changes{'customrole'}{$rolename}{'access'} = 1;
20167: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20168: }
20169: }
1.285 raeburn 20170: if (@allpos > 0) {
20171: my $idx = 0;
20172: foreach my $rolename (@allpos) {
20173: if ($rolename ne '') {
20174: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20175: if (ref($current{'adhoc'}) eq 'HASH') {
20176: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20177: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20178: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20179: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20180: }
20181: }
1.282 raeburn 20182: }
1.285 raeburn 20183: $idx ++;
1.166 raeburn 20184: }
20185: }
1.118 jms 20186: }
1.123 jms 20187: my $putresult;
20188: if (keys(%changes) > 0) {
1.166 raeburn 20189: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20190: if ($putresult eq 'ok') {
1.285 raeburn 20191: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20192: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20193: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20194: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20195: }
20196: }
20197: my $cachetime = 24*60*60;
20198: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20199: if (ref($lastactref) eq 'HASH') {
20200: $lastactref->{'domdefaults'} = 1;
20201: }
20202: } else {
20203: $errors .= '<li><span class="LC_error">'.
20204: &mt('An error occurred storing the settings: [_1]',
20205: $putresult).'</span></li>';
20206: }
20207: }
20208: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20209: $resulttext = &mt('Changes made:').'<ul>';
20210: my (%shownprivs,@levelorder);
20211: @levelorder = ('c','d','s');
20212: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20213: foreach my $item (sort(keys(%changes))) {
20214: if ($item eq 'submitbugs') {
20215: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20216: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20217: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20218: } elsif ($item eq 'customrole') {
20219: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20220: my @keyorder = ('order','desc','access','status','exc','inc');
20221: my %keytext = &Apache::lonlocal::texthash(
20222: order => 'Order',
20223: desc => 'Role description',
20224: access => 'Role usage',
1.300 droeschl 20225: status => 'Allowed institutional types',
1.285 raeburn 20226: exc => 'Allowed personnel',
20227: inc => 'Disallowed personnel',
20228: );
1.282 raeburn 20229: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20230: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20231: if ($role eq $newrole) {
20232: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20233: $role).'<ul>';
20234: } else {
20235: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20236: $role).'<ul>';
20237: }
20238: foreach my $key (@keyorder) {
20239: if ($changes{'customrole'}{$role}{$key}) {
20240: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20241: $keytext{$key},$newsettings{$role}{$key}).
20242: '</li>';
20243: }
20244: }
20245: if (ref($changedprivs{$role}) eq 'HASH') {
20246: $shownprivs{$role} = 1;
20247: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20248: foreach my $level (@levelorder) {
20249: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20250: next if ($item eq '');
20251: my ($priv) = split(/\&/,$item,2);
20252: if (&Apache::lonnet::plaintext($priv)) {
20253: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20254: unless ($level eq 'c') {
20255: $resulttext .= ' ('.$lt{$level}.')';
20256: }
20257: $resulttext .= '</li>';
20258: }
20259: }
20260: }
20261: $resulttext .= '</ul>';
20262: }
20263: $resulttext .= '</ul></li>';
20264: }
20265: }
20266: }
20267: }
20268: }
20269: }
20270: if (keys(%changedprivs)) {
20271: foreach my $role (sort(keys(%changedprivs))) {
20272: unless ($shownprivs{$role}) {
20273: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20274: $role).'<ul>'.
20275: '<li>'.&mt('Privileges set to :').'<ul>';
20276: foreach my $level (@levelorder) {
20277: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20278: next if ($item eq '');
20279: my ($priv) = split(/\&/,$item,2);
20280: if (&Apache::lonnet::plaintext($priv)) {
20281: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20282: unless ($level eq 'c') {
20283: $resulttext .= ' ('.$lt{$level}.')';
20284: }
20285: $resulttext .= '</li>';
20286: }
1.282 raeburn 20287: }
20288: }
1.285 raeburn 20289: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20290: }
20291: }
20292: }
1.285 raeburn 20293: $resulttext .= '</ul>';
20294: } else {
20295: $resulttext = &mt('No changes made to help settings');
1.118 jms 20296: }
20297: if ($errors) {
1.168 raeburn 20298: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20299: $errors.'</ul>';
1.118 jms 20300: }
20301: return $resulttext;
20302: }
20303:
1.121 raeburn 20304: sub modify_coursedefaults {
1.212 raeburn 20305: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20306: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20307: my %defaultchecked = (
20308: 'canuse_pdfforms' => 'off',
20309: 'uselcmath' => 'on',
20310: 'usejsme' => 'on'
20311: );
20312: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 20313: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20314: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
20315: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
20316: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 20317: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 20318: my %staticdefaults = (
20319: anonsurvey_threshold => 10,
20320: uploadquota => 500,
1.257 raeburn 20321: postsubmit => 60,
1.276 raeburn 20322: mysqltables => 172800,
1.198 raeburn 20323: );
1.314 raeburn 20324: my %texoptions = (
20325: MathJax => 'MathJax',
20326: mimetex => &mt('Convert to Images'),
20327: tth => &mt('TeX to HTML'),
20328: );
1.121 raeburn 20329: $defaultshash{'coursedefaults'} = {};
20330:
20331: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
20332: if ($domconfig{'coursedefaults'} eq '') {
20333: $domconfig{'coursedefaults'} = {};
20334: }
20335: }
20336:
20337: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
20338: foreach my $item (@toggles) {
20339: if ($defaultchecked{$item} eq 'on') {
20340: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20341: ($env{'form.'.$item} eq '0')) {
20342: $changes{$item} = 1;
1.192 raeburn 20343: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 20344: $changes{$item} = 1;
20345: }
20346: } elsif ($defaultchecked{$item} eq 'off') {
20347: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20348: ($env{'form.'.$item} eq '1')) {
20349: $changes{$item} = 1;
20350: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
20351: $changes{$item} = 1;
20352: }
20353: }
20354: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
20355: }
1.198 raeburn 20356: foreach my $item (@numbers) {
20357: my ($currdef,$newdef);
1.208 raeburn 20358: $newdef = $env{'form.'.$item};
1.198 raeburn 20359: if ($item eq 'anonsurvey_threshold') {
20360: $currdef = $domconfig{'coursedefaults'}{$item};
20361: $newdef =~ s/\D//g;
20362: if ($newdef eq '' || $newdef < 1) {
20363: $newdef = 1;
20364: }
20365: $defaultshash{'coursedefaults'}{$item} = $newdef;
20366: } else {
1.276 raeburn 20367: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
20368: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
20369: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 20370: }
20371: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 20372: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 20373: }
20374: if ($currdef ne $newdef) {
20375: if ($item eq 'anonsurvey_threshold') {
20376: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
20377: $changes{$item} = 1;
20378: }
1.276 raeburn 20379: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 20380: my $setting = $1;
1.276 raeburn 20381: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
20382: $changes{$setting} = 1;
1.198 raeburn 20383: }
20384: }
1.139 raeburn 20385: }
20386: }
1.314 raeburn 20387: my $texengine;
20388: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
20389: $texengine = $env{'form.texengine'};
1.349 raeburn 20390: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
20391: if ($currdef eq '') {
20392: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 20393: $changes{'texengine'} = 1;
20394: }
1.349 raeburn 20395: } elsif ($currdef ne $texengine) {
1.314 raeburn 20396: $changes{'texengine'} = 1;
20397: }
20398: }
20399: if ($texengine ne '') {
20400: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
20401: }
1.264 raeburn 20402: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
20403: my @currclonecode;
20404: if (ref($currclone) eq 'HASH') {
20405: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
20406: @currclonecode = @{$currclone->{'instcode'}};
20407: }
20408: }
20409: my $newclone;
1.289 raeburn 20410: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 20411: $newclone = $env{'form.canclone'};
20412: }
20413: if ($newclone eq 'instcode') {
20414: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
20415: my (%codedefaults,@code_order,@clonecode);
20416: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
20417: \@code_order);
20418: foreach my $item (@code_order) {
20419: if (grep(/^\Q$item\E$/,@newcodes)) {
20420: push(@clonecode,$item);
20421: }
20422: }
20423: if (@clonecode) {
20424: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
20425: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
20426: if (@diffs) {
20427: $changes{'canclone'} = 1;
20428: }
20429: } else {
20430: $newclone eq '';
20431: }
20432: } elsif ($newclone ne '') {
1.289 raeburn 20433: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
20434: }
1.264 raeburn 20435: if ($newclone ne $currclone) {
20436: $changes{'canclone'} = 1;
20437: }
1.257 raeburn 20438: my %credits;
20439: foreach my $type (@types) {
20440: unless ($type eq 'community') {
20441: $credits{$type} = $env{'form.'.$type.'_credits'};
20442: $credits{$type} =~ s/[^\d.]+//g;
20443: }
20444: }
20445: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
20446: ($env{'form.coursecredits'} eq '1')) {
20447: $changes{'coursecredits'} = 1;
20448: foreach my $type (keys(%credits)) {
20449: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20450: }
20451: } else {
1.289 raeburn 20452: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 20453: foreach my $type (@types) {
20454: unless ($type eq 'community') {
1.289 raeburn 20455: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 20456: $changes{'coursecredits'} = 1;
20457: }
20458: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20459: }
20460: }
20461: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20462: foreach my $type (@types) {
20463: unless ($type eq 'community') {
20464: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
20465: $changes{'coursecredits'} = 1;
20466: last;
20467: }
20468: }
20469: }
20470: }
20471: }
20472: if ($env{'form.postsubmit'} eq '1') {
20473: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
20474: my %currtimeout;
20475: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20476: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
20477: $changes{'postsubmit'} = 1;
20478: }
20479: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20480: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
20481: }
20482: } else {
20483: $changes{'postsubmit'} = 1;
20484: }
20485: foreach my $type (@types) {
20486: my $timeout = $env{'form.'.$type.'_timeout'};
20487: $timeout =~ s/\D//g;
20488: if ($timeout == $staticdefaults{'postsubmit'}) {
20489: $timeout = '';
20490: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
20491: $timeout = '0';
20492: }
20493: unless ($timeout eq '') {
20494: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
20495: }
20496: if (exists($currtimeout{$type})) {
20497: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 20498: $changes{'postsubmit'} = 1;
1.257 raeburn 20499: }
20500: } elsif ($timeout ne '') {
20501: $changes{'postsubmit'} = 1;
20502: }
20503: }
20504: } else {
20505: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
20506: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20507: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
20508: $changes{'postsubmit'} = 1;
20509: }
20510: } else {
20511: $changes{'postsubmit'} = 1;
20512: }
1.192 raeburn 20513: }
1.121 raeburn 20514: }
20515: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20516: $dom);
20517: if ($putresult eq 'ok') {
20518: if (keys(%changes) > 0) {
1.213 raeburn 20519: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 20520: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 20521: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 20522: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
20523: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 20524: if ($changes{$item}) {
20525: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
20526: }
1.289 raeburn 20527: }
1.192 raeburn 20528: if ($changes{'coursecredits'}) {
20529: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 20530: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
20531: $domdefaults{$type.'credits'} =
20532: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
20533: }
20534: }
20535: }
20536: if ($changes{'postsubmit'}) {
20537: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20538: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
20539: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20540: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20541: $domdefaults{$type.'postsubtimeout'} =
20542: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20543: }
20544: }
1.192 raeburn 20545: }
20546: }
1.198 raeburn 20547: if ($changes{'uploadquota'}) {
20548: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20549: foreach my $type (@types) {
20550: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20551: }
20552: }
20553: }
1.264 raeburn 20554: if ($changes{'canclone'}) {
20555: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20556: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20557: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20558: if (@clonecodes) {
20559: $domdefaults{'canclone'} = join('+',@clonecodes);
20560: }
20561: }
20562: } else {
20563: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20564: }
20565: }
1.121 raeburn 20566: my $cachetime = 24*60*60;
20567: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20568: if (ref($lastactref) eq 'HASH') {
20569: $lastactref->{'domdefaults'} = 1;
20570: }
1.121 raeburn 20571: }
20572: $resulttext = &mt('Changes made:').'<ul>';
20573: foreach my $item (sort(keys(%changes))) {
20574: if ($item eq 'canuse_pdfforms') {
20575: if ($env{'form.'.$item} eq '1') {
20576: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20577: } else {
20578: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20579: }
1.257 raeburn 20580: } elsif ($item eq 'uselcmath') {
20581: if ($env{'form.'.$item} eq '1') {
20582: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20583: } else {
20584: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20585: }
20586: } elsif ($item eq 'usejsme') {
20587: if ($env{'form.'.$item} eq '1') {
20588: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20589: } else {
1.289 raeburn 20590: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20591: }
1.314 raeburn 20592: } elsif ($item eq 'texengine') {
20593: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20594: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20595: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20596: }
1.139 raeburn 20597: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20598: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20599: } elsif ($item eq 'uploadquota') {
20600: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20601: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20602: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20603: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20604: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20605: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20606: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20607: '</ul>'.
20608: '</li>';
20609: } else {
20610: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20611: }
1.276 raeburn 20612: } elsif ($item eq 'mysqltables') {
20613: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20614: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20615: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20616: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20617: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20618: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20619: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20620: '</ul>'.
20621: '</li>';
20622: } else {
20623: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20624: }
1.257 raeburn 20625: } elsif ($item eq 'postsubmit') {
20626: if ($domdefaults{'postsubmit'} eq 'off') {
20627: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20628: } else {
20629: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20630: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20631: $resulttext .= &mt('durations:').'<ul>';
20632: foreach my $type (@types) {
20633: $resulttext .= '<li>';
20634: my $timeout;
20635: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20636: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20637: }
20638: my $display;
20639: if ($timeout eq '0') {
20640: $display = &mt('unlimited');
20641: } elsif ($timeout eq '') {
20642: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20643: } else {
20644: $display = &mt('[quant,_1,second]',$timeout);
20645: }
20646: if ($type eq 'community') {
20647: $resulttext .= &mt('Communities');
20648: } elsif ($type eq 'official') {
20649: $resulttext .= &mt('Official courses');
20650: } elsif ($type eq 'unofficial') {
20651: $resulttext .= &mt('Unofficial courses');
20652: } elsif ($type eq 'textbook') {
20653: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20654: } elsif ($type eq 'placement') {
20655: $resulttext .= &mt('Placement tests');
1.257 raeburn 20656: }
20657: $resulttext .= ' -- '.$display.'</li>';
20658: }
20659: $resulttext .= '</ul>';
20660: }
1.289 raeburn 20661: $resulttext .= '</li>';
1.257 raeburn 20662: }
1.192 raeburn 20663: } elsif ($item eq 'coursecredits') {
20664: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20665: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20666: ($domdefaults{'unofficialcredits'} eq '') &&
20667: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20668: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20669: } else {
20670: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20671: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20672: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20673: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20674: '</ul>'.
20675: '</li>';
20676: }
20677: } else {
20678: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20679: }
1.264 raeburn 20680: } elsif ($item eq 'canclone') {
20681: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20682: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20683: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20684: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20685: }
20686: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20687: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20688: } else {
1.289 raeburn 20689: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20690: }
1.140 raeburn 20691: }
1.121 raeburn 20692: }
20693: $resulttext .= '</ul>';
20694: } else {
20695: $resulttext = &mt('No changes made to course defaults');
20696: }
20697: } else {
20698: $resulttext = '<span class="LC_error">'.
20699: &mt('An error occurred: [_1]',$putresult).'</span>';
20700: }
20701: return $resulttext;
20702: }
20703:
1.231 raeburn 20704: sub modify_selfenrollment {
20705: my ($dom,$lastactref,%domconfig) = @_;
20706: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20707: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20708: my %titles = &tool_titles();
1.232 raeburn 20709: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20710: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20711: $ordered{'default'} = ['types','registered','approval','limit'];
20712:
20713: my (%roles,%shown,%toplevel);
20714: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20715:
20716: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20717: if ($domconfig{'selfenrollment'} eq '') {
20718: $domconfig{'selfenrollment'} = {};
20719: }
20720: }
20721: %toplevel = (
20722: admin => 'Configuration Rights',
20723: default => 'Default settings',
20724: validation => 'Validation of self-enrollment requests',
20725: );
1.233 raeburn 20726: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 20727:
20728: if (ref($ordered{'admin'}) eq 'ARRAY') {
20729: foreach my $item (@{$ordered{'admin'}}) {
20730: foreach my $type (@types) {
20731: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
20732: $selfenrollhash{'admin'}{$type}{$item} = 1;
20733: } else {
20734: $selfenrollhash{'admin'}{$type}{$item} = 0;
20735: }
20736: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
20737: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
20738: if ($selfenrollhash{'admin'}{$type}{$item} ne
20739: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
20740: push(@{$changes{'admin'}{$type}},$item);
20741: }
20742: } else {
20743: if (!$selfenrollhash{'admin'}{$type}{$item}) {
20744: push(@{$changes{'admin'}{$type}},$item);
20745: }
20746: }
20747: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
20748: push(@{$changes{'admin'}{$type}},$item);
20749: }
20750: }
20751: }
20752: }
20753:
20754: foreach my $item (@{$ordered{'default'}}) {
20755: foreach my $type (@types) {
20756: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
20757: if ($item eq 'types') {
20758: unless (($value eq 'all') || ($value eq 'dom')) {
20759: $value = '';
20760: }
20761: } elsif ($item eq 'registered') {
20762: unless ($value eq '1') {
20763: $value = 0;
20764: }
20765: } elsif ($item eq 'approval') {
20766: unless ($value =~ /^[012]$/) {
20767: $value = 0;
20768: }
20769: } else {
20770: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20771: $value = 'none';
20772: }
20773: }
20774: $selfenrollhash{'default'}{$type}{$item} = $value;
20775: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
20776: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20777: if ($selfenrollhash{'default'}{$type}{$item} ne
20778: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
20779: push(@{$changes{'default'}{$type}},$item);
20780: }
20781: } else {
20782: push(@{$changes{'default'}{$type}},$item);
20783: }
20784: } else {
20785: push(@{$changes{'default'}{$type}},$item);
20786: }
20787: if ($item eq 'limit') {
20788: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
20789: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
20790: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
20791: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
20792: }
20793: } else {
20794: $selfenrollhash{'default'}{$type}{'cap'} = '';
20795: }
20796: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
20797: if ($selfenrollhash{'default'}{$type}{'cap'} ne
20798: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
20799: push(@{$changes{'default'}{$type}},'cap');
20800: }
20801: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
20802: push(@{$changes{'default'}{$type}},'cap');
20803: }
20804: }
20805: }
20806: }
20807:
20808: foreach my $item (@{$itemsref}) {
20809: if ($item eq 'fields') {
20810: my @changed;
20811: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
20812: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
20813: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
20814: }
20815: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20816: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
20817: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
20818: $domconfig{'selfenrollment'}{'validation'}{$item});
20819: } else {
20820: @changed = @{$selfenrollhash{'validation'}{$item}};
20821: }
20822: } else {
20823: @changed = @{$selfenrollhash{'validation'}{$item}};
20824: }
20825: if (@changed) {
20826: if ($selfenrollhash{'validation'}{$item}) {
20827: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
20828: } else {
20829: $changes{'validation'}{$item} = &mt('None');
20830: }
20831: }
20832: } else {
20833: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
20834: if ($item eq 'markup') {
20835: if ($env{'form.selfenroll_validation_'.$item}) {
20836: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
20837: }
20838: }
20839: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
20840: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
20841: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
20842: }
20843: }
20844: }
20845: }
20846:
20847: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
20848: $dom);
20849: if ($putresult eq 'ok') {
20850: if (keys(%changes) > 0) {
20851: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
20852: $resulttext = &mt('Changes made:').'<ul>';
20853: foreach my $key ('admin','default','validation') {
20854: if (ref($changes{$key}) eq 'HASH') {
20855: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
20856: if ($key eq 'validation') {
20857: foreach my $item (@{$itemsref}) {
20858: if (exists($changes{$key}{$item})) {
20859: if ($item eq 'markup') {
20860: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20861: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
20862: } else {
20863: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
20864: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
20865: }
20866: }
20867: }
20868: } else {
20869: foreach my $type (@types) {
20870: if ($type eq 'community') {
20871: $roles{'1'} = &mt('Community personnel');
20872: } else {
20873: $roles{'1'} = &mt('Course personnel');
20874: }
20875: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 20876: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20877: if ($key eq 'admin') {
20878: my @mgrdc = ();
20879: if (ref($ordered{$key}) eq 'ARRAY') {
20880: foreach my $item (@{$ordered{'admin'}}) {
20881: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
20882: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
20883: push(@mgrdc,$item);
20884: }
20885: }
20886: }
20887: if (@mgrdc) {
20888: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
20889: } else {
20890: delete($domdefaults{$type.'selfenrolladmdc'});
20891: }
20892: }
20893: } else {
20894: if (ref($ordered{$key}) eq 'ARRAY') {
20895: foreach my $item (@{$ordered{$key}}) {
20896: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20897: $domdefaults{$type.'selfenroll'.$item} =
20898: $selfenrollhash{$key}{$type}{$item};
20899: }
20900: }
20901: }
20902: }
20903: }
1.231 raeburn 20904: $resulttext .= '<li>'.$titles{$type}.'<ul>';
20905: foreach my $item (@{$ordered{$key}}) {
20906: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
20907: $resulttext .= '<li>';
20908: if ($key eq 'admin') {
20909: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
20910: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
20911: } else {
20912: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
20913: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
20914: }
20915: $resulttext .= '</li>';
20916: }
20917: }
20918: $resulttext .= '</ul></li>';
20919: }
20920: }
20921: $resulttext .= '</ul></li>';
20922: }
20923: }
1.305 raeburn 20924: }
20925: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
20926: my $cachetime = 24*60*60;
20927: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20928: if (ref($lastactref) eq 'HASH') {
20929: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 20930: }
1.231 raeburn 20931: }
20932: $resulttext .= '</ul>';
20933: } else {
20934: $resulttext = &mt('No changes made to self-enrollment settings');
20935: }
20936: } else {
20937: $resulttext = '<span class="LC_error">'.
20938: &mt('An error occurred: [_1]',$putresult).'</span>';
20939: }
20940: return $resulttext;
20941: }
20942:
1.373 raeburn 20943: sub modify_wafproxy {
20944: my ($dom,$action,$lastactref,%domconfig) = @_;
20945: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 20946: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
20947: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 20948: foreach my $server (sort(keys(%servers))) {
20949: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20950: if ($serverhome eq $server) {
20951: my $serverdom = &Apache::lonnet::host_domain($server);
20952: if ($serverdom eq $dom) {
20953: $canset{$server} = 1;
20954: }
20955: }
20956: }
1.381 raeburn 20957: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
20958: %{$values{$dom}} = ();
20959: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
20960: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
20961: }
1.388 raeburn 20962: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
20963: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
20964: }
1.382 raeburn 20965: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 20966: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
20967: }
20968: }
1.373 raeburn 20969: my $output;
20970: if (keys(%canset)) {
20971: %{$wafproxy{'alias'}} = ();
1.388 raeburn 20972: %{$wafproxy{'saml'}} = ();
1.373 raeburn 20973: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 20974: if ($env{'form.wafproxy_'.$dom}) {
20975: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
20976: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
20977: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
20978: $changes{'alias'} = 1;
20979: }
1.388 raeburn 20980: if ($env{'form.wafproxy_alias_saml_'.$key}) {
20981: $wafproxy{'saml'}{$key} = 1;
20982: }
20983: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
20984: $changes{'saml'} = 1;
20985: }
1.381 raeburn 20986: } else {
20987: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 20988: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 20989: if ($curralias{$key}) {
20990: $changes{'alias'} = 1;
20991: }
1.388 raeburn 20992: if ($currsaml{$key}) {
20993: $changes{'saml'} = 1;
20994: }
1.373 raeburn 20995: }
20996: if ($wafproxy{'alias'}{$key} eq '') {
20997: if ($curralias{$key}) {
20998: $expirecache{$key} = 1;
20999: }
21000: delete($wafproxy{'alias'}{$key});
21001: }
1.388 raeburn 21002: if ($wafproxy{'saml'}{$key} eq '') {
21003: if ($currsaml{$key}) {
21004: $expiresaml{$key} = 1;
21005: }
21006: delete($wafproxy{'saml'}{$key});
21007: }
1.373 raeburn 21008: }
21009: unless (keys(%{$wafproxy{'alias'}})) {
21010: delete($wafproxy{'alias'});
21011: }
1.388 raeburn 21012: unless (keys(%{$wafproxy{'saml'}})) {
21013: delete($wafproxy{'saml'});
21014: }
21015: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21016: my %warn = (
21017: trusted => 'trusted IP range(s)',
1.381 raeburn 21018: vpnint => 'internal IP range(s) for VPN sessions(s)',
21019: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21020: );
1.382 raeburn 21021: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21022: my $possible = $env{'form.wafproxy_'.$item};
21023: $possible =~ s/^\s+|\s+$//g;
21024: if ($possible ne '') {
1.381 raeburn 21025: if ($item eq 'remoteip') {
21026: if ($possible =~ /^[mhn]$/) {
21027: $wafproxy{$item} = $possible;
21028: }
21029: } elsif ($item eq 'ipheader') {
21030: if ($wafproxy{'remoteip'} eq 'h') {
21031: $wafproxy{$item} = $possible;
21032: }
1.382 raeburn 21033: } elsif ($item eq 'sslopt') {
21034: if ($possible =~ /^0|1$/) {
21035: $wafproxy{$item} = $possible;
21036: }
1.373 raeburn 21037: } else {
21038: my (@ok,$count);
1.381 raeburn 21039: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21040: unless ($env{'form.wafproxy_vpnaccess'}) {
21041: $possible = '';
21042: }
21043: } elsif ($item eq 'trusted') {
21044: unless ($wafproxy{'remoteip'} eq 'h') {
21045: $possible = '';
21046: }
21047: }
21048: unless ($possible eq '') {
21049: $possible =~ s/[\r\n]+/\s/g;
21050: $possible =~ s/\s*-\s*/-/g;
21051: $possible =~ s/\s+/,/g;
1.393 raeburn 21052: $possible =~ s/,+/,/g;
1.381 raeburn 21053: }
1.373 raeburn 21054: $count = 0;
1.381 raeburn 21055: if ($possible ne '') {
1.373 raeburn 21056: foreach my $poss (split(/\,/,$possible)) {
21057: $count ++;
1.393 raeburn 21058: $poss = &validate_ip_pattern($poss);
21059: if ($poss ne '') {
1.373 raeburn 21060: push(@ok,$poss);
21061: }
21062: }
21063: my $diff = $count - scalar(@ok);
21064: if ($diff) {
21065: push(@warnings,'<li>'.
21066: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21067: $diff,$warn{$item}).
21068: '</li>');
21069: }
1.393 raeburn 21070: if (@ok) {
21071: my @cidr_list;
21072: foreach my $item (@ok) {
21073: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21074: }
21075: $wafproxy{$item} = join(',',@cidr_list);
21076: }
1.373 raeburn 21077: }
21078: }
1.381 raeburn 21079: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21080: $changes{$item} = 1;
21081: }
1.381 raeburn 21082: } elsif ($currvalue{$item}) {
21083: $changes{$item} = 1;
21084: }
21085: }
21086: } else {
21087: if (keys(%curralias)) {
21088: $changes{'alias'} = 1;
1.388 raeburn 21089: }
21090: if (keys(%currsaml)) {
21091: $changes{'saml'} = 1;
1.381 raeburn 21092: }
21093: if (keys(%currvalue)) {
21094: foreach my $key (keys(%currvalue)) {
21095: $changes{$key} = 1;
1.373 raeburn 21096: }
21097: }
21098: }
21099: if (keys(%changes)) {
21100: my %defaultshash = (
21101: wafproxy => \%wafproxy,
21102: );
21103: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21104: $dom);
21105: if ($putresult eq 'ok') {
21106: my $cachetime = 24*60*60;
21107: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21108: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21109: if ($changes{$item}) {
21110: unless ($updatedomdefs) {
21111: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21112: $updatedomdefs = 1;
21113: }
21114: if ($wafproxy{$item}) {
21115: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21116: } elsif (exists($domdefaults{'waf_'.$item})) {
21117: delete($domdefaults{'waf_'.$item});
21118: }
21119: }
21120: }
21121: if ($updatedomdefs) {
21122: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21123: if (ref($lastactref) eq 'HASH') {
21124: $lastactref->{'domdefaults'} = 1;
21125: }
21126: }
21127: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21128: my %updates = %expirecache;
21129: foreach my $key (keys(%expirecache)) {
21130: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21131: }
21132: if (ref($wafproxy{'alias'}) eq 'HASH') {
21133: my $cachetime = 24*60*60;
21134: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21135: $updates{$key} = 1;
21136: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21137: $cachetime);
21138: }
21139: }
21140: if (ref($lastactref) eq 'HASH') {
21141: $lastactref->{'proxyalias'} = \%updates;
21142: }
21143: }
1.388 raeburn 21144: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21145: my %samlupdates = %expiresaml;
21146: foreach my $key (keys(%expiresaml)) {
21147: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21148: }
21149: if (ref($wafproxy{'saml'}) eq 'HASH') {
21150: my $cachetime = 24*60*60;
21151: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21152: $samlupdates{$key} = 1;
21153: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21154: $cachetime);
21155: }
21156: }
21157: if (ref($lastactref) eq 'HASH') {
21158: $lastactref->{'proxysaml'} = \%samlupdates;
21159: }
21160: }
1.373 raeburn 21161: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.382 raeburn 21162: foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21163: if ($changes{$item}) {
21164: if ($item eq 'alias') {
21165: my $numaliased = 0;
21166: if (ref($wafproxy{'alias'}) eq 'HASH') {
21167: my $shown;
21168: if (keys(%{$wafproxy{'alias'}})) {
21169: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21170: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21171: &Apache::lonnet::hostname($server),
21172: $wafproxy{'alias'}{$server}).'</li>';
21173: $numaliased ++;
21174: }
21175: if ($numaliased) {
21176: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21177: '<ul>'.$shown.'</ul>').'</li>';
21178: }
21179: }
21180: }
21181: unless ($numaliased) {
21182: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21183: }
1.388 raeburn 21184: } elsif ($item eq 'saml') {
21185: my $shown;
21186: if (ref($wafproxy{'saml'}) eq 'HASH') {
21187: if (keys(%{$wafproxy{'saml'}})) {
21188: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21189: }
21190: }
21191: if ($shown) {
1.396 raeburn 21192: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21193: $shown).'</li>';
21194: } else {
1.396 raeburn 21195: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21196: }
1.373 raeburn 21197: } else {
1.381 raeburn 21198: if ($item eq 'remoteip') {
21199: my %ip_methods = &remoteip_methods();
21200: if ($wafproxy{$item} =~ /^[mh]$/) {
21201: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
21202: $ip_methods{$wafproxy{$item}}).'</li>';
21203: } else {
21204: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
21205: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
21206: '</li>';
21207: } else {
21208: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
21209: }
21210: }
21211: } elsif ($item eq 'ipheader') {
1.373 raeburn 21212: if ($wafproxy{$item}) {
1.381 raeburn 21213: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 21214: $wafproxy{$item}).'</li>';
21215: } else {
1.381 raeburn 21216: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 21217: }
21218: } elsif ($item eq 'trusted') {
21219: if ($wafproxy{$item}) {
1.381 raeburn 21220: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 21221: $wafproxy{$item}).'</li>';
21222: } else {
21223: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
21224: }
1.381 raeburn 21225: } elsif ($item eq 'vpnint') {
21226: if ($wafproxy{$item}) {
21227: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
21228: $wafproxy{$item}).'</li>';
21229: } else {
21230: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
21231: }
21232: } elsif ($item eq 'vpnext') {
1.373 raeburn 21233: if ($wafproxy{$item}) {
1.381 raeburn 21234: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 21235: $wafproxy{$item}).'</li>';
21236: } else {
1.381 raeburn 21237: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 21238: }
1.382 raeburn 21239: } elsif ($item eq 'sslopt') {
21240: if ($wafproxy{$item}) {
21241: $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>';
21242: } else {
21243: $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>';
21244: }
1.373 raeburn 21245: }
21246: }
21247: }
21248: }
21249: } else {
21250: $output = '<span class="LC_error">'.
21251: &mt('An error occurred: [_1]',$putresult).'</span>';
21252: }
21253: } elsif (keys(%canset)) {
21254: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
21255: }
21256: if (@warnings) {
21257: $output .= '<br />'.&mt('Warnings:').'<ul>'.
21258: join("\n",@warnings).'</ul>';
21259: }
21260: return $output;
21261: }
21262:
21263: sub validate_ip_pattern {
21264: my ($pattern) = @_;
21265: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
21266: my ($start,$end) = ($1,$2);
21267: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 21268: if (($start !~ m{/}) && ($end !~ m{/})) {
21269: return $start.'-'.$end;
21270: }
21271: }
21272: } elsif ($pattern ne '') {
21273: $pattern = &Net::CIDR::cidrvalidate($pattern);
21274: if ($pattern ne '') {
21275: return $pattern;
1.373 raeburn 21276: }
21277: }
1.393 raeburn 21278: return;
1.373 raeburn 21279: }
21280:
1.137 raeburn 21281: sub modify_usersessions {
1.212 raeburn 21282: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 21283: my @hostingtypes = ('version','excludedomain','includedomain');
21284: my @offloadtypes = ('primary','default');
21285: my %types = (
21286: remote => \@hostingtypes,
21287: hosted => \@hostingtypes,
21288: spares => \@offloadtypes,
21289: );
21290: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 21291: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 21292: my (%by_ip,%by_location,@intdoms,@instdoms);
21293: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 21294: my @locations = sort(keys(%by_location));
1.137 raeburn 21295: my (%defaultshash,%changes);
21296: foreach my $prefix (@prefixes) {
21297: $defaultshash{'usersessions'}{$prefix} = {};
21298: }
1.212 raeburn 21299: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 21300: my $resulttext;
1.138 raeburn 21301: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 21302: foreach my $prefix (@prefixes) {
1.145 raeburn 21303: next if ($prefix eq 'spares');
21304: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 21305: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21306: if ($type eq 'version') {
21307: my $value = $env{'form.'.$prefix.'_'.$type};
21308: my $okvalue;
21309: if ($value ne '') {
21310: if (grep(/^\Q$value\E$/,@lcversions)) {
21311: $okvalue = $value;
21312: }
21313: }
21314: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21315: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21316: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
21317: if ($inuse == 0) {
21318: $changes{$prefix}{$type} = 1;
21319: } else {
21320: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
21321: $changes{$prefix}{$type} = 1;
21322: }
21323: if ($okvalue ne '') {
21324: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21325: }
21326: }
21327: } else {
21328: if (($inuse == 1) && ($okvalue ne '')) {
21329: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21330: $changes{$prefix}{$type} = 1;
21331: }
21332: }
21333: } else {
21334: if (($inuse == 1) && ($okvalue ne '')) {
21335: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21336: $changes{$prefix}{$type} = 1;
21337: }
21338: }
21339: } else {
21340: if (($inuse == 1) && ($okvalue ne '')) {
21341: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21342: $changes{$prefix}{$type} = 1;
21343: }
21344: }
21345: } else {
21346: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21347: my @okvals;
21348: foreach my $val (@vals) {
1.138 raeburn 21349: if ($val =~ /:/) {
21350: my @items = split(/:/,$val);
21351: foreach my $item (@items) {
21352: if (ref($by_location{$item}) eq 'ARRAY') {
21353: push(@okvals,$item);
21354: }
21355: }
21356: } else {
21357: if (ref($by_location{$val}) eq 'ARRAY') {
21358: push(@okvals,$val);
21359: }
1.137 raeburn 21360: }
21361: }
21362: @okvals = sort(@okvals);
21363: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21364: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21365: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21366: if ($inuse == 0) {
21367: $changes{$prefix}{$type} = 1;
21368: } else {
21369: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21370: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
21371: if (@changed > 0) {
21372: $changes{$prefix}{$type} = 1;
21373: }
21374: }
21375: } else {
21376: if ($inuse == 1) {
21377: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21378: $changes{$prefix}{$type} = 1;
21379: }
21380: }
21381: } else {
21382: if ($inuse == 1) {
21383: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21384: $changes{$prefix}{$type} = 1;
21385: }
21386: }
21387: } else {
21388: if ($inuse == 1) {
21389: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21390: $changes{$prefix}{$type} = 1;
21391: }
21392: }
21393: }
21394: }
21395: }
1.145 raeburn 21396:
21397: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 21398: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 21399: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
21400: my $savespares;
21401:
21402: foreach my $lonhost (sort(keys(%servers))) {
21403: my $serverhomeID =
21404: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 21405: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 21406: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
21407: my %spareschg;
21408: foreach my $type (@{$types{'spares'}}) {
21409: my @okspares;
21410: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
21411: foreach my $server (@checked) {
1.152 raeburn 21412: if (&Apache::lonnet::hostname($server) ne '') {
21413: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
21414: unless (grep(/^\Q$server\E$/,@okspares)) {
21415: push(@okspares,$server);
21416: }
1.145 raeburn 21417: }
21418: }
21419: }
21420: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
21421: my $newspare;
1.152 raeburn 21422: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
21423: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 21424: $newspare = $new;
21425: }
21426: }
1.152 raeburn 21427: my @spares;
21428: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
21429: @spares = sort(@okspares,$newspare);
21430: } else {
21431: @spares = sort(@okspares);
21432: }
21433: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 21434: if (ref($spareid{$lonhost}) eq 'HASH') {
21435: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 21436: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 21437: if (@diffs > 0) {
21438: $spareschg{$type} = 1;
21439: }
21440: }
21441: }
21442: }
21443: if (keys(%spareschg) > 0) {
21444: $changes{'spares'}{$lonhost} = \%spareschg;
21445: }
21446: }
1.261 raeburn 21447: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 21448: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 21449: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
21450: my @okoffload;
21451: if (@offloadnow) {
21452: foreach my $server (@offloadnow) {
21453: if (&Apache::lonnet::hostname($server) ne '') {
21454: unless (grep(/^\Q$server\E$/,@okoffload)) {
21455: push(@okoffload,$server);
21456: }
21457: }
21458: }
21459: if (@okoffload) {
21460: foreach my $lonhost (@okoffload) {
21461: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
21462: }
21463: }
21464: }
1.371 raeburn 21465: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
21466: my @okoffloadoth;
21467: if (@offloadoth) {
21468: foreach my $server (@offloadoth) {
21469: if (&Apache::lonnet::hostname($server) ne '') {
21470: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
21471: push(@okoffloadoth,$server);
21472: }
21473: }
21474: }
21475: if (@okoffloadoth) {
21476: foreach my $lonhost (@okoffloadoth) {
21477: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
21478: }
21479: }
21480: }
1.145 raeburn 21481: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21482: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
21483: if (ref($changes{'spares'}) eq 'HASH') {
21484: if (keys(%{$changes{'spares'}}) > 0) {
21485: $savespares = 1;
21486: }
21487: }
21488: } else {
21489: $savespares = 1;
21490: }
1.371 raeburn 21491: foreach my $offload ('offloadnow','offloadoth') {
21492: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
21493: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
21494: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
21495: $changes{$offload} = 1;
21496: last;
21497: }
1.261 raeburn 21498: }
1.371 raeburn 21499: unless ($changes{$offload}) {
21500: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
21501: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
21502: $changes{$offload} = 1;
21503: last;
21504: }
1.261 raeburn 21505: }
21506: }
1.371 raeburn 21507: } else {
21508: if (($offload eq 'offloadnow') && (@okoffload)) {
21509: $changes{'offloadnow'} = 1;
21510: }
21511: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
21512: $changes{'offloadoth'} = 1;
21513: }
21514: }
21515: }
21516: } else {
21517: if (@okoffload) {
1.261 raeburn 21518: $changes{'offloadnow'} = 1;
21519: }
1.371 raeburn 21520: if (@okoffloadoth) {
21521: $changes{'offloadoth'} = 1;
21522: }
1.145 raeburn 21523: }
1.147 raeburn 21524: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
21525: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 21526: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21527: $dom);
21528: if ($putresult eq 'ok') {
21529: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21530: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
21531: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
21532: }
21533: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
21534: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
21535: }
1.261 raeburn 21536: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21537: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
21538: }
1.371 raeburn 21539: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21540: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
21541: }
1.137 raeburn 21542: }
21543: my $cachetime = 24*60*60;
21544: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 21545: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 21546: if (ref($lastactref) eq 'HASH') {
21547: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 21548: $lastactref->{'usersessions'} = 1;
1.212 raeburn 21549: }
1.147 raeburn 21550: if (keys(%changes) > 0) {
21551: my %lt = &usersession_titles();
21552: $resulttext = &mt('Changes made:').'<ul>';
21553: foreach my $prefix (@prefixes) {
21554: if (ref($changes{$prefix}) eq 'HASH') {
21555: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21556: if ($prefix eq 'spares') {
21557: if (ref($changes{$prefix}) eq 'HASH') {
21558: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21559: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21560: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21561: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21562: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21563: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21564: foreach my $type (@{$types{$prefix}}) {
21565: if ($changes{$prefix}{$lonhost}{$type}) {
21566: my $offloadto = &mt('None');
21567: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21568: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21569: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21570: }
1.145 raeburn 21571: }
1.147 raeburn 21572: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21573: }
1.137 raeburn 21574: }
21575: }
1.147 raeburn 21576: $resulttext .= '</li>';
1.137 raeburn 21577: }
21578: }
1.147 raeburn 21579: } else {
21580: foreach my $type (@{$types{$prefix}}) {
21581: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21582: my ($newvalue,$notinuse);
1.147 raeburn 21583: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21584: if (ref($defaultshash{'usersessions'}{$prefix})) {
21585: if ($type eq 'version') {
21586: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21587: } else {
21588: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21589: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21590: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21591: }
21592: } else {
21593: $notinuse = 1;
1.147 raeburn 21594: }
1.145 raeburn 21595: }
21596: }
21597: }
1.147 raeburn 21598: if ($newvalue eq '') {
21599: if ($type eq 'version') {
21600: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21601: } elsif ($notinuse) {
21602: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21603: } else {
21604: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21605: }
1.145 raeburn 21606: } else {
1.147 raeburn 21607: if ($type eq 'version') {
1.344 raeburn 21608: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21609: }
21610: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21611: }
1.137 raeburn 21612: }
21613: }
21614: }
1.147 raeburn 21615: $resulttext .= '</ul>';
1.137 raeburn 21616: }
21617: }
1.261 raeburn 21618: if ($changes{'offloadnow'}) {
21619: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21620: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21621: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21622: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21623: $resulttext .= '<li>'.$lonhost.'</li>';
21624: }
21625: $resulttext .= '</ul>';
21626: } else {
1.371 raeburn 21627: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21628: }
21629: } else {
21630: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21631: }
21632: }
21633: if ($changes{'offloadoth'}) {
21634: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21635: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21636: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21637: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21638: $resulttext .= '<li>'.$lonhost.'</li>';
21639: }
21640: $resulttext .= '</ul>';
21641: } else {
21642: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21643: }
21644: } else {
1.371 raeburn 21645: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21646: }
21647: }
1.147 raeburn 21648: $resulttext .= '</ul>';
21649: } else {
21650: $resulttext = $nochgmsg;
1.137 raeburn 21651: }
21652: } else {
21653: $resulttext = '<span class="LC_error">'.
21654: &mt('An error occurred: [_1]',$putresult).'</span>';
21655: }
21656: } else {
1.147 raeburn 21657: $resulttext = $nochgmsg;
1.137 raeburn 21658: }
21659: return $resulttext;
21660: }
21661:
1.275 raeburn 21662: sub modify_ssl {
21663: my ($dom,$lastactref,%domconfig) = @_;
21664: my (%by_ip,%by_location,@intdoms,@instdoms);
21665: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21666: my @locations = sort(keys(%by_location));
21667: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21668: my (%defaultshash,%changes);
21669: my $action = 'ssl';
1.293 raeburn 21670: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21671: foreach my $prefix (@prefixes) {
21672: $defaultshash{$action}{$prefix} = {};
21673: }
21674: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21675: my $resulttext;
21676: my %iphost = &Apache::lonnet::get_iphost();
21677: my @reptypes = ('certreq','nocertreq');
21678: my @connecttypes = ('dom','intdom','other');
21679: my %types = (
1.293 raeburn 21680: connto => \@connecttypes,
21681: connfrom => \@connecttypes,
21682: replication => \@reptypes,
1.275 raeburn 21683: );
21684: foreach my $prefix (sort(keys(%types))) {
21685: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21686: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21687: my $value = 'yes';
21688: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21689: $value = $env{'form.'.$prefix.'_'.$type};
21690: }
1.335 raeburn 21691: if (ref($domconfig{$action}) eq 'HASH') {
21692: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21693: if ($domconfig{$action}{$prefix}{$type} ne '') {
21694: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21695: $changes{$prefix}{$type} = 1;
21696: }
21697: $defaultshash{$action}{$prefix}{$type} = $value;
21698: } else {
21699: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21700: $changes{$prefix}{$type} = 1;
21701: }
21702: } else {
21703: $defaultshash{$action}{$prefix}{$type} = $value;
21704: $changes{$prefix}{$type} = 1;
21705: }
21706: } else {
21707: $defaultshash{$action}{$prefix}{$type} = $value;
21708: $changes{$prefix}{$type} = 1;
21709: }
21710: if (($type eq 'dom') && (keys(%servers) == 1)) {
21711: delete($changes{$prefix}{$type});
21712: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21713: delete($changes{$prefix}{$type});
21714: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21715: delete($changes{$prefix}{$type});
21716: }
21717: } elsif ($prefix eq 'replication') {
21718: if (@locations > 0) {
21719: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21720: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21721: my @okvals;
21722: foreach my $val (@vals) {
21723: if ($val =~ /:/) {
21724: my @items = split(/:/,$val);
21725: foreach my $item (@items) {
21726: if (ref($by_location{$item}) eq 'ARRAY') {
21727: push(@okvals,$item);
21728: }
21729: }
21730: } else {
21731: if (ref($by_location{$val}) eq 'ARRAY') {
21732: push(@okvals,$val);
21733: }
21734: }
21735: }
21736: @okvals = sort(@okvals);
21737: if (ref($domconfig{$action}) eq 'HASH') {
21738: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21739: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
21740: if ($inuse == 0) {
21741: $changes{$prefix}{$type} = 1;
21742: } else {
21743: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21744: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
21745: if (@changed > 0) {
21746: $changes{$prefix}{$type} = 1;
21747: }
21748: }
21749: } else {
21750: if ($inuse == 1) {
21751: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21752: $changes{$prefix}{$type} = 1;
21753: }
21754: }
21755: } else {
21756: if ($inuse == 1) {
21757: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21758: $changes{$prefix}{$type} = 1;
21759: }
21760: }
21761: } else {
21762: if ($inuse == 1) {
21763: $defaultshash{$action}{$prefix}{$type} = \@okvals;
21764: $changes{$prefix}{$type} = 1;
21765: }
21766: }
21767: }
21768: }
21769: }
21770: }
1.336 raeburn 21771: if (keys(%changes)) {
21772: foreach my $prefix (keys(%changes)) {
21773: if (ref($changes{$prefix}) eq 'HASH') {
21774: if (scalar(keys(%{$changes{$prefix}})) == 0) {
21775: delete($changes{$prefix});
21776: }
21777: } else {
21778: delete($changes{$prefix});
21779: }
21780: }
21781: }
1.275 raeburn 21782: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
21783: if (keys(%changes) > 0) {
21784: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21785: $dom);
21786: if ($putresult eq 'ok') {
21787: if (ref($defaultshash{$action}) eq 'HASH') {
21788: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
21789: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
21790: }
1.293 raeburn 21791: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 21792: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 21793: }
21794: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 21795: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 21796: }
21797: }
21798: my $cachetime = 24*60*60;
21799: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21800: if (ref($lastactref) eq 'HASH') {
21801: $lastactref->{'domdefaults'} = 1;
21802: }
21803: if (keys(%changes) > 0) {
21804: my %titles = &ssl_titles();
21805: $resulttext = &mt('Changes made:').'<ul>';
21806: foreach my $prefix (@prefixes) {
21807: if (ref($changes{$prefix}) eq 'HASH') {
21808: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
21809: foreach my $type (@{$types{$prefix}}) {
21810: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21811: my ($newvalue,$notinuse);
1.275 raeburn 21812: if (ref($defaultshash{$action}) eq 'HASH') {
21813: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 21814: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21815: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 21816: } else {
21817: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
21818: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
21819: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
21820: }
21821: } else {
21822: $notinuse = 1;
1.275 raeburn 21823: }
21824: }
21825: }
1.344 raeburn 21826: if ($notinuse) {
21827: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
21828: } elsif ($newvalue eq '') {
1.275 raeburn 21829: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
21830: } else {
21831: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
21832: }
21833: }
21834: }
21835: }
21836: $resulttext .= '</ul>';
21837: }
21838: }
21839: } else {
21840: $resulttext = $nochgmsg;
21841: }
21842: } else {
21843: $resulttext = '<span class="LC_error">'.
21844: &mt('An error occurred: [_1]',$putresult).'</span>';
21845: }
21846: } else {
21847: $resulttext = $nochgmsg;
21848: }
21849: return $resulttext;
21850: }
21851:
1.279 raeburn 21852: sub modify_trust {
21853: my ($dom,$lastactref,%domconfig) = @_;
21854: my (%by_ip,%by_location,@intdoms,@instdoms);
21855: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21856: my @locations = sort(keys(%by_location));
21857: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
21858: my @types = ('exc','inc');
21859: my (%defaultshash,%changes);
21860: foreach my $prefix (@prefixes) {
21861: $defaultshash{'trust'}{$prefix} = {};
21862: }
21863: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21864: my $resulttext;
21865: foreach my $prefix (@prefixes) {
21866: foreach my $type (@types) {
21867: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21868: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21869: my @okvals;
21870: foreach my $val (@vals) {
21871: if ($val =~ /:/) {
21872: my @items = split(/:/,$val);
21873: foreach my $item (@items) {
21874: if (ref($by_location{$item}) eq 'ARRAY') {
21875: push(@okvals,$item);
21876: }
21877: }
21878: } else {
21879: if (ref($by_location{$val}) eq 'ARRAY') {
21880: push(@okvals,$val);
21881: }
21882: }
21883: }
21884: @okvals = sort(@okvals);
21885: if (ref($domconfig{'trust'}) eq 'HASH') {
21886: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
21887: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21888: if ($inuse == 0) {
21889: $changes{$prefix}{$type} = 1;
21890: } else {
21891: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21892: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
21893: if (@changed > 0) {
21894: $changes{$prefix}{$type} = 1;
21895: }
21896: }
21897: } else {
21898: if ($inuse == 1) {
21899: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21900: $changes{$prefix}{$type} = 1;
21901: }
21902: }
21903: } else {
21904: if ($inuse == 1) {
21905: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21906: $changes{$prefix}{$type} = 1;
21907: }
21908: }
21909: } else {
21910: if ($inuse == 1) {
21911: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
21912: $changes{$prefix}{$type} = 1;
21913: }
21914: }
21915: }
21916: }
21917: my $nochgmsg = &mt('No changes made to trust settings.');
21918: if (keys(%changes) > 0) {
21919: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21920: $dom);
21921: if ($putresult eq 'ok') {
21922: if (ref($defaultshash{'trust'}) eq 'HASH') {
21923: foreach my $prefix (@prefixes) {
21924: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
21925: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
21926: }
21927: }
21928: }
21929: my $cachetime = 24*60*60;
21930: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21931: if (ref($lastactref) eq 'HASH') {
21932: $lastactref->{'domdefaults'} = 1;
21933: }
21934: if (keys(%changes) > 0) {
21935: my %lt = &trust_titles();
21936: $resulttext = &mt('Changes made:').'<ul>';
21937: foreach my $prefix (@prefixes) {
21938: if (ref($changes{$prefix}) eq 'HASH') {
21939: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21940: foreach my $type (@types) {
21941: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21942: my ($newvalue,$notinuse);
1.279 raeburn 21943: if (ref($defaultshash{'trust'}) eq 'HASH') {
21944: if (ref($defaultshash{'trust'}{$prefix})) {
21945: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
21946: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
21947: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
21948: }
1.344 raeburn 21949: } else {
21950: $notinuse = 1;
1.279 raeburn 21951: }
21952: }
21953: }
1.344 raeburn 21954: if ($notinuse) {
21955: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
21956: } elsif ($newvalue eq '') {
1.279 raeburn 21957: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21958: } else {
21959: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
21960: }
21961: }
21962: }
21963: $resulttext .= '</ul>';
21964: }
21965: }
21966: $resulttext .= '</ul>';
21967: } else {
21968: $resulttext = $nochgmsg;
21969: }
21970: } else {
21971: $resulttext = '<span class="LC_error">'.
21972: &mt('An error occurred: [_1]',$putresult).'</span>';
21973: }
21974: } else {
21975: $resulttext = $nochgmsg;
21976: }
21977: return $resulttext;
21978: }
21979:
1.150 raeburn 21980: sub modify_loadbalancing {
21981: my ($dom,%domconfig) = @_;
21982: my $primary_id = &Apache::lonnet::domain($dom,'primary');
21983: my $intdom = &Apache::lonnet::internet_dom($primary_id);
21984: my ($othertitle,$usertypes,$types) =
21985: &Apache::loncommon::sorted_inst_types($dom);
21986: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 21987: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 21988: my @sparestypes = ('primary','default');
21989: my %typetitles = &sparestype_titles();
21990: my $resulttext;
1.342 raeburn 21991: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 21992: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
21993: %existing = %{$domconfig{'loadbalancing'}};
21994: }
21995: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 21996: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 21997: my ($saveloadbalancing,%defaultshash,%changes);
21998: my ($alltypes,$othertypes,$titles) =
21999: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22000: my %ruletitles = &offloadtype_text();
22001: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22002: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22003: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22004: if ($balancer eq '') {
22005: next;
22006: }
1.210 raeburn 22007: if (!exists($servers{$balancer})) {
1.171 raeburn 22008: if (exists($currbalancer{$balancer})) {
22009: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22010: }
1.171 raeburn 22011: next;
22012: }
22013: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22014: push(@{$changes{'delete'}},$balancer);
22015: next;
22016: }
22017: if (!exists($currbalancer{$balancer})) {
22018: push(@{$changes{'add'}},$balancer);
22019: }
22020: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22021: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22022: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22023: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22024: $saveloadbalancing = 1;
22025: }
22026: foreach my $sparetype (@sparestypes) {
22027: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22028: my @offloadto;
22029: foreach my $target (@targets) {
22030: if (($servers{$target}) && ($target ne $balancer)) {
22031: if ($sparetype eq 'default') {
22032: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22033: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22034: }
22035: }
1.171 raeburn 22036: unless(grep(/^\Q$target\E$/,@offloadto)) {
22037: push(@offloadto,$target);
22038: }
1.150 raeburn 22039: }
22040: }
1.284 raeburn 22041: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22042: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22043: push(@offloadto,$balancer);
22044: }
22045: }
22046: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22047: }
1.342 raeburn 22048: if ($env{'form.loadbalancing_cookie_'.$i}) {
22049: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
22050: if (exists($currbalancer{$balancer})) {
22051: unless ($currcookies{$balancer}) {
22052: $changes{'curr'}{$balancer}{'cookie'} = 1;
22053: }
22054: }
22055: } elsif (exists($currbalancer{$balancer})) {
22056: if ($currcookies{$balancer}) {
22057: $changes{'curr'}{$balancer}{'cookie'} = 1;
22058: }
22059: }
1.171 raeburn 22060: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22061: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22062: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22063: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22064: if (@targetdiffs > 0) {
1.171 raeburn 22065: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22066: }
1.171 raeburn 22067: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22068: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22069: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22070: }
22071: }
22072: }
22073: } else {
1.171 raeburn 22074: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22075: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22076: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22077: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22078: $changes{'curr'}{$balancer}{'targets'} = 1;
22079: }
1.150 raeburn 22080: }
22081: }
1.210 raeburn 22082: }
1.150 raeburn 22083: }
22084: my $ishomedom;
1.171 raeburn 22085: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22086: $ishomedom = 1;
1.150 raeburn 22087: }
22088: if (ref($alltypes) eq 'ARRAY') {
22089: foreach my $type (@{$alltypes}) {
22090: my $rule;
1.210 raeburn 22091: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22092: (!$ishomedom)) {
1.171 raeburn 22093: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22094: }
22095: if ($rule eq 'specific') {
1.255 raeburn 22096: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22097: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22098: $rule = $specifiedhost;
22099: }
1.150 raeburn 22100: }
1.171 raeburn 22101: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22102: if (ref($currrules{$balancer}) eq 'HASH') {
22103: if ($rule ne $currrules{$balancer}{$type}) {
22104: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22105: }
22106: } elsif ($rule ne '') {
1.171 raeburn 22107: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22108: }
22109: }
22110: }
1.171 raeburn 22111: }
22112: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22113: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22114: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22115: $defaultshash{'loadbalancing'} = {};
22116: }
22117: my $putresult = &Apache::lonnet::put_dom('configuration',
22118: \%defaultshash,$dom);
22119: if ($putresult eq 'ok') {
22120: if (keys(%changes) > 0) {
1.252 raeburn 22121: my %toupdate;
1.171 raeburn 22122: if (ref($changes{'delete'}) eq 'ARRAY') {
22123: foreach my $balancer (sort(@{$changes{'delete'}})) {
22124: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22125: $toupdate{$balancer} = 1;
1.150 raeburn 22126: }
1.171 raeburn 22127: }
22128: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22129: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22130: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22131: $toupdate{$balancer} = 1;
1.171 raeburn 22132: }
22133: }
22134: if (ref($changes{'curr'}) eq 'HASH') {
22135: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22136: $toupdate{$balancer} = 1;
1.171 raeburn 22137: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22138: if ($changes{'curr'}{$balancer}{'targets'}) {
22139: my %offloadstr;
22140: foreach my $sparetype (@sparestypes) {
22141: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22142: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22143: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22144: }
22145: }
1.150 raeburn 22146: }
1.171 raeburn 22147: if (keys(%offloadstr) == 0) {
22148: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22149: } else {
1.171 raeburn 22150: my $showoffload;
22151: foreach my $sparetype (@sparestypes) {
22152: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22153: if (defined($offloadstr{$sparetype})) {
22154: $showoffload .= $offloadstr{$sparetype};
22155: } else {
22156: $showoffload .= &mt('None');
22157: }
22158: $showoffload .= (' 'x3);
22159: }
22160: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22161: }
22162: }
22163: }
1.171 raeburn 22164: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22165: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22166: foreach my $type (@{$alltypes}) {
22167: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22168: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22169: my $balancetext;
22170: if ($rule eq '') {
22171: $balancetext = $ruletitles{'default'};
1.209 raeburn 22172: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22173: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22174: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22175: foreach my $sparetype (@sparestypes) {
22176: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22177: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22178: }
22179: }
1.253 raeburn 22180: foreach my $item (@{$alltypes}) {
22181: next if ($item =~ /^_LC_ipchange/);
22182: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22183: if ($hasrule eq 'homeserver') {
22184: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22185: } else {
22186: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22187: if ($servers{$hasrule}) {
22188: $toupdate{$hasrule} = 1;
22189: }
22190: }
22191: }
22192: }
1.254 raeburn 22193: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22194: $balancetext = $ruletitles{$rule};
22195: } else {
22196: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22197: $balancetext = $ruletitles{'particular'}.' '.$receiver;
22198: if ($receiver) {
22199: $toupdate{$receiver};
22200: }
22201: }
22202: } else {
22203: $balancetext = $ruletitles{$rule};
1.252 raeburn 22204: }
1.171 raeburn 22205: } else {
22206: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
22207: }
1.210 raeburn 22208: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 22209: }
22210: }
22211: }
22212: }
1.342 raeburn 22213: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 22214: if ($currcookies{$balancer}) {
22215: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
22216: $balancer).'</li>';
22217: } else {
22218: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
22219: $balancer).'</li>';
22220: }
1.342 raeburn 22221: }
1.375 raeburn 22222: }
22223: }
22224: if (keys(%toupdate)) {
22225: my %thismachine;
22226: my $updatedhere;
22227: my $cachetime = 60*60*24;
22228: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
22229: foreach my $lonhost (keys(%toupdate)) {
22230: if ($thismachine{$lonhost}) {
22231: unless ($updatedhere) {
22232: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
22233: $defaultshash{'loadbalancing'},
22234: $cachetime);
22235: $updatedhere = 1;
1.252 raeburn 22236: }
1.375 raeburn 22237: } else {
22238: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
22239: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 22240: }
1.150 raeburn 22241: }
1.171 raeburn 22242: }
22243: if ($resulttext ne '') {
22244: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 22245: } else {
22246: $resulttext = $nochgmsg;
22247: }
22248: } else {
1.171 raeburn 22249: $resulttext = $nochgmsg;
1.150 raeburn 22250: }
22251: } else {
1.171 raeburn 22252: $resulttext = '<span class="LC_error">'.
22253: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 22254: }
22255: } else {
1.171 raeburn 22256: $resulttext = $nochgmsg;
1.150 raeburn 22257: }
22258: return $resulttext;
22259: }
22260:
1.48 raeburn 22261: sub recurse_check {
22262: my ($chkcats,$categories,$depth,$name) = @_;
22263: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
22264: my $chg = 0;
22265: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
22266: my $category = $chkcats->[$depth]{$name}[$j];
22267: my $item;
22268: if ($category eq '') {
22269: $chg ++;
22270: } else {
22271: my $deeper = $depth + 1;
22272: $item = &escape($category).':'.&escape($name).':'.$depth;
22273: if ($chg) {
22274: $categories->{$item} -= $chg;
22275: }
22276: &recurse_check($chkcats,$categories,$deeper,$category);
22277: $deeper --;
22278: }
22279: }
22280: }
22281: return;
22282: }
22283:
22284: sub recurse_cat_deletes {
22285: my ($item,$coursecategories,$deletions) = @_;
22286: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
22287: my $subdepth = $depth + 1;
22288: if (ref($coursecategories) eq 'HASH') {
22289: foreach my $subitem (keys(%{$coursecategories})) {
22290: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
22291: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
22292: delete($coursecategories->{$subitem});
22293: $deletions->{$subitem} = 1;
22294: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 22295: }
1.48 raeburn 22296: }
22297: }
22298: return;
22299: }
22300:
1.125 raeburn 22301: sub active_dc_picker {
1.191 raeburn 22302: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 22303: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 22304: my @domcoord = keys(%domcoords);
22305: if (keys(%currhash)) {
22306: foreach my $dc (keys(%currhash)) {
22307: unless (exists($domcoords{$dc})) {
22308: push(@domcoord,$dc);
22309: }
22310: }
22311: }
22312: @domcoord = sort(@domcoord);
1.210 raeburn 22313: my $numdcs = scalar(@domcoord);
1.191 raeburn 22314: my $rows = 0;
22315: my $table;
1.125 raeburn 22316: if ($numdcs > 1) {
1.191 raeburn 22317: $table = '<table>';
22318: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 22319: my $rem = $i%($numinrow);
22320: if ($rem == 0) {
22321: if ($i > 0) {
1.191 raeburn 22322: $table .= '</tr>';
1.125 raeburn 22323: }
1.191 raeburn 22324: $table .= '<tr>';
22325: $rows ++;
1.125 raeburn 22326: }
1.191 raeburn 22327: my $check = '';
22328: if ($inputtype eq 'radio') {
22329: if (keys(%currhash) == 0) {
22330: if (!$i) {
22331: $check = ' checked="checked"';
22332: }
22333: } elsif (exists($currhash{$domcoord[$i]})) {
22334: $check = ' checked="checked"';
22335: }
22336: } else {
22337: if (exists($currhash{$domcoord[$i]})) {
22338: $check = ' checked="checked"';
1.125 raeburn 22339: }
22340: }
1.191 raeburn 22341: if ($i == @domcoord - 1) {
1.125 raeburn 22342: my $colsleft = $numinrow - $rem;
22343: if ($colsleft > 1) {
1.191 raeburn 22344: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 22345: } else {
1.191 raeburn 22346: $table .= '<td class="LC_left_item">';
1.125 raeburn 22347: }
22348: } else {
1.191 raeburn 22349: $table .= '<td class="LC_left_item">';
22350: }
22351: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
22352: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
22353: $table .= '<span class="LC_nobreak"><label>'.
22354: '<input type="'.$inputtype.'" name="'.$name.'"'.
22355: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
22356: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 22357: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 22358: }
1.219 raeburn 22359: $table .= '</label></span></td>';
1.191 raeburn 22360: }
22361: $table .= '</tr></table>';
22362: } elsif ($numdcs == 1) {
1.219 raeburn 22363: my ($dcname,$dcdom) = split(':',$domcoord[0]);
22364: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 22365: if ($inputtype eq 'radio') {
1.247 raeburn 22366: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 22367: if ($user ne $dcname.':'.$dcdom) {
22368: $table .= ' ('.$dcname.':'.$dcdom.')';
22369: }
1.191 raeburn 22370: } else {
22371: my $check;
22372: if (exists($currhash{$domcoord[0]})) {
22373: $check = ' checked="checked"';
1.125 raeburn 22374: }
1.247 raeburn 22375: $table = '<span class="LC_nobreak"><label>'.
22376: '<input type="checkbox" name="'.$name.'" '.
22377: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 22378: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 22379: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 22380: }
1.220 raeburn 22381: $table .= '</label></span>';
1.191 raeburn 22382: $rows ++;
1.125 raeburn 22383: }
22384: }
1.191 raeburn 22385: return ($numdcs,$table,$rows);
1.125 raeburn 22386: }
22387:
1.137 raeburn 22388: sub usersession_titles {
22389: return &Apache::lonlocal::texthash(
22390: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
22391: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 22392: spares => 'Servers offloaded to, when busy',
1.137 raeburn 22393: version => 'LON-CAPA version requirement',
1.138 raeburn 22394: excludedomain => 'Allow all, but exclude specific domains',
22395: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 22396: primary => 'Primary (checked first)',
1.154 raeburn 22397: default => 'Default',
1.137 raeburn 22398: );
22399: }
22400:
1.152 raeburn 22401: sub id_for_thisdom {
22402: my (%servers) = @_;
22403: my %altids;
22404: foreach my $server (keys(%servers)) {
22405: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22406: if ($serverhome ne $server) {
22407: $altids{$serverhome} = $server;
22408: }
22409: }
22410: return %altids;
22411: }
22412:
1.150 raeburn 22413: sub count_servers {
22414: my ($currbalancer,%servers) = @_;
22415: my (@spares,$numspares);
22416: foreach my $lonhost (sort(keys(%servers))) {
22417: next if ($currbalancer eq $lonhost);
22418: push(@spares,$lonhost);
22419: }
22420: if ($currbalancer) {
22421: $numspares = scalar(@spares);
22422: } else {
22423: $numspares = scalar(@spares) - 1;
22424: }
22425: return ($numspares,@spares);
22426: }
22427:
22428: sub lonbalance_targets_js {
1.171 raeburn 22429: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 22430: my $select = &mt('Select');
22431: my ($alltargets,$allishome,$allinsttypes,@alltypes);
22432: if (ref($servers) eq 'HASH') {
22433: $alltargets = join("','",sort(keys(%{$servers})));
22434: my @homedoms;
22435: foreach my $server (sort(keys(%{$servers}))) {
22436: if (&Apache::lonnet::host_domain($server) eq $dom) {
22437: push(@homedoms,'1');
22438: } else {
22439: push(@homedoms,'0');
22440: }
22441: }
22442: $allishome = join("','",@homedoms);
22443: }
22444: if (ref($types) eq 'ARRAY') {
22445: if (@{$types} > 0) {
22446: @alltypes = @{$types};
22447: }
22448: }
22449: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
22450: $allinsttypes = join("','",@alltypes);
1.342 raeburn 22451: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22452: if (ref($settings) eq 'HASH') {
22453: %existing = %{$settings};
22454: }
22455: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 22456: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 22457: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 22458: return <<"END";
22459:
22460: <script type="text/javascript">
22461: // <![CDATA[
22462:
1.171 raeburn 22463: currBalancers = new Array('$balancers');
22464:
22465: function toggleTargets(balnum) {
22466: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22467: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
22468: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
22469: var prevbalancer = prevhostitem.value;
22470: var baltotal = document.getElementById('loadbalancing_total').value;
22471: prevhostitem.value = balancer;
22472: if (prevbalancer != '') {
22473: var prevIdx = currBalancers.indexOf(prevbalancer);
22474: if (prevIdx != -1) {
22475: currBalancers.splice(prevIdx,1);
22476: }
22477: }
1.150 raeburn 22478: if (balancer == '') {
1.171 raeburn 22479: hideSpares(balnum);
1.150 raeburn 22480: } else {
1.171 raeburn 22481: var currIdx = currBalancers.indexOf(balancer);
22482: if (currIdx == -1) {
22483: currBalancers.push(balancer);
22484: }
1.150 raeburn 22485: var homedoms = new Array('$allishome');
1.171 raeburn 22486: var ishomedom = homedoms[lonhostitem.selectedIndex];
22487: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 22488: }
1.171 raeburn 22489: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 22490: return;
22491: }
22492:
1.171 raeburn 22493: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 22494: var alltargets = new Array('$alltargets');
22495: var insttypes = new Array('$allinsttypes');
1.151 raeburn 22496: var offloadtypes = new Array('primary','default');
22497:
1.171 raeburn 22498: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
22499: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 22500:
1.151 raeburn 22501: for (var i=0; i<offloadtypes.length; i++) {
22502: var count = 0;
22503: for (var j=0; j<alltargets.length; j++) {
22504: if (alltargets[j] != balancer) {
1.171 raeburn 22505: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
22506: item.value = alltargets[j];
22507: item.style.textAlign='left';
22508: item.style.textFace='normal';
22509: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
22510: if (currBalancers.indexOf(alltargets[j]) == -1) {
22511: item.disabled = '';
22512: } else {
22513: item.disabled = 'disabled';
22514: item.checked = false;
22515: }
1.151 raeburn 22516: count ++;
22517: }
1.150 raeburn 22518: }
22519: }
1.151 raeburn 22520: for (var k=0; k<insttypes.length; k++) {
22521: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 22522: if (ishomedom == 1) {
1.171 raeburn 22523: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22524: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22525: } else {
1.171 raeburn 22526: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22527: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 22528: }
22529: } else {
1.171 raeburn 22530: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22531: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22532: }
1.151 raeburn 22533: if ((insttypes[k] != '_LC_external') &&
22534: ((insttypes[k] != '_LC_internetdom') ||
22535: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 22536: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
22537: item.options.length = 0;
22538: item.options[0] = new Option("","",true,true);
1.210 raeburn 22539: var idx = 0;
1.151 raeburn 22540: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 22541: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
22542: idx ++;
22543: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 22544: }
22545: }
22546: }
22547: }
22548: return;
22549: }
22550:
1.171 raeburn 22551: function hideSpares(balnum) {
1.150 raeburn 22552: var alltargets = new Array('$alltargets');
22553: var insttypes = new Array('$allinsttypes');
22554: var offloadtypes = new Array('primary','default');
22555:
1.171 raeburn 22556: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22557: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22558:
22559: var total = alltargets.length - 1;
22560: for (var i=0; i<offloadtypes; i++) {
22561: for (var j=0; j<total; j++) {
1.171 raeburn 22562: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22563: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22564: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22565: }
1.150 raeburn 22566: }
22567: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22568: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22569: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22570: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22571: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22572: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22573: }
22574: }
22575: return;
22576: }
22577:
1.171 raeburn 22578: function checkOffloads(item,balnum,type) {
1.150 raeburn 22579: var alltargets = new Array('$alltargets');
22580: var offloadtypes = new Array('primary','default');
22581: if (item.checked) {
22582: var total = alltargets.length - 1;
22583: var other;
22584: if (type == offloadtypes[0]) {
1.151 raeburn 22585: other = offloadtypes[1];
1.150 raeburn 22586: } else {
1.151 raeburn 22587: other = offloadtypes[0];
1.150 raeburn 22588: }
22589: for (var i=0; i<total; i++) {
1.171 raeburn 22590: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22591: if (server == item.value) {
1.171 raeburn 22592: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22593: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22594: }
22595: }
22596: }
22597: }
22598: return;
22599: }
22600:
1.171 raeburn 22601: function singleServerToggle(balnum,type) {
22602: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22603: if (offloadtoSelIdx == 0) {
1.171 raeburn 22604: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22605: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22606:
22607: } else {
1.171 raeburn 22608: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22609: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22610: }
22611: return;
22612: }
22613:
1.171 raeburn 22614: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22615: if (type == '_LC_external') {
1.171 raeburn 22616: return;
1.150 raeburn 22617: }
1.171 raeburn 22618: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22619: for (var i=0; i<typesRules.length; i++) {
22620: if (formname.elements[typesRules[i]].checked) {
22621: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22622: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22623: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22624: } else {
1.171 raeburn 22625: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22626: }
22627: }
22628: }
22629: return;
22630: }
22631:
22632: function balancerDeleteChange(balnum) {
22633: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22634: var baltotal = document.getElementById('loadbalancing_total').value;
22635: var addtarget;
22636: var removetarget;
22637: var action = 'delete';
22638: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22639: var lonhost = hostitem.value;
22640: var currIdx = currBalancers.indexOf(lonhost);
22641: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22642: if (currIdx != -1) {
22643: currBalancers.splice(currIdx,1);
22644: }
22645: addtarget = lonhost;
22646: } else {
22647: if (currIdx == -1) {
22648: currBalancers.push(lonhost);
22649: }
22650: removetarget = lonhost;
22651: action = 'undelete';
22652: }
22653: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22654: }
22655: return;
22656: }
22657:
22658: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22659: if (baltotal > 1) {
22660: var offloadtypes = new Array('primary','default');
22661: var alltargets = new Array('$alltargets');
22662: var insttypes = new Array('$allinsttypes');
22663: for (var i=0; i<baltotal; i++) {
22664: if (i != balnum) {
22665: for (var j=0; j<offloadtypes.length; j++) {
22666: var total = alltargets.length - 1;
22667: for (var k=0; k<total; k++) {
22668: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22669: var server = serveritem.value;
22670: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22671: if (server == addtarget) {
22672: serveritem.disabled = '';
22673: }
22674: }
22675: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22676: if (server == removetarget) {
22677: serveritem.disabled = 'disabled';
22678: serveritem.checked = false;
22679: }
22680: }
22681: }
22682: }
22683: for (var j=0; j<insttypes.length; j++) {
22684: if (insttypes[j] != '_LC_external') {
22685: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22686: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22687: var currSel = singleserver.selectedIndex;
22688: var currVal = singleserver.options[currSel].value;
22689: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22690: var numoptions = singleserver.options.length;
22691: var needsnew = 1;
22692: for (var k=0; k<numoptions; k++) {
22693: if (singleserver.options[k] == addtarget) {
22694: needsnew = 0;
22695: break;
22696: }
22697: }
22698: if (needsnew == 1) {
22699: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22700: }
22701: }
22702: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22703: singleserver.options.length = 0;
22704: if ((currVal) && (currVal != removetarget)) {
22705: singleserver.options[0] = new Option("","",false,false);
22706: } else {
22707: singleserver.options[0] = new Option("","",true,true);
22708: }
22709: var idx = 0;
22710: for (var m=0; m<alltargets.length; m++) {
22711: if (currBalancers.indexOf(alltargets[m]) == -1) {
22712: idx ++;
22713: if (currVal == alltargets[m]) {
22714: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22715: } else {
22716: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22717: }
22718: }
22719: }
22720: }
22721: }
22722: }
22723: }
1.150 raeburn 22724: }
22725: }
22726: }
22727: return;
22728: }
22729:
1.152 raeburn 22730: // ]]>
22731: </script>
22732:
22733: END
22734: }
22735:
1.372 raeburn 22736:
1.152 raeburn 22737: sub new_spares_js {
22738: my @sparestypes = ('primary','default');
22739: my $types = join("','",@sparestypes);
22740: my $select = &mt('Select');
22741: return <<"END";
22742:
22743: <script type="text/javascript">
22744: // <![CDATA[
22745:
22746: function updateNewSpares(formname,lonhost) {
22747: var types = new Array('$types');
22748: var include = new Array();
22749: var exclude = new Array();
22750: for (var i=0; i<types.length; i++) {
22751: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
22752: for (var j=0; j<spareboxes.length; j++) {
22753: if (formname.elements[spareboxes[j]].checked) {
22754: exclude.push(formname.elements[spareboxes[j]].value);
22755: } else {
22756: include.push(formname.elements[spareboxes[j]].value);
22757: }
22758: }
22759: }
22760: for (var i=0; i<types.length; i++) {
22761: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
22762: var selIdx = newSpare.selectedIndex;
22763: var currnew = newSpare.options[selIdx].value;
22764: var okSpares = new Array();
22765: for (var j=0; j<newSpare.options.length; j++) {
22766: var possible = newSpare.options[j].value;
22767: if (possible != '') {
22768: if (exclude.indexOf(possible) == -1) {
22769: okSpares.push(possible);
22770: } else {
22771: if (currnew == possible) {
22772: selIdx = 0;
22773: }
22774: }
22775: }
22776: }
22777: for (var k=0; k<include.length; k++) {
22778: if (okSpares.indexOf(include[k]) == -1) {
22779: okSpares.push(include[k]);
22780: }
22781: }
22782: okSpares.sort();
22783: newSpare.options.length = 0;
22784: if (selIdx == 0) {
22785: newSpare.options[0] = new Option("$select","",true,true);
22786: } else {
22787: newSpare.options[0] = new Option("$select","",false,false);
22788: }
22789: for (var m=0; m<okSpares.length; m++) {
22790: var idx = m+1;
22791: var selThis = 0;
22792: if (selIdx != 0) {
22793: if (okSpares[m] == currnew) {
22794: selThis = 1;
22795: }
22796: }
22797: if (selThis == 1) {
22798: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
22799: } else {
22800: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
22801: }
22802: }
22803: }
22804: return;
22805: }
22806:
22807: function checkNewSpares(lonhost,type) {
22808: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
22809: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 22810: if (chosen != '') {
1.152 raeburn 22811: var othertype;
22812: var othernewSpare;
22813: if (type == 'primary') {
22814: othernewSpare = document.getElementById('newspare_default_'+lonhost);
22815: }
22816: if (type == 'default') {
22817: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
22818: }
22819: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
22820: othernewSpare.selectedIndex = 0;
22821: }
22822: }
22823: return;
22824: }
22825:
22826: // ]]>
22827: </script>
22828:
22829: END
22830:
22831: }
22832:
22833: sub common_domprefs_js {
22834: return <<"END";
22835:
22836: <script type="text/javascript">
22837: // <![CDATA[
22838:
1.150 raeburn 22839: function getIndicesByName(formname,item) {
1.152 raeburn 22840: var group = new Array();
1.150 raeburn 22841: for (var i=0;i<formname.elements.length;i++) {
22842: if (formname.elements[i].name == item) {
1.152 raeburn 22843: group.push(formname.elements[i].id);
1.150 raeburn 22844: }
22845: }
1.152 raeburn 22846: return group;
1.150 raeburn 22847: }
22848:
22849: // ]]>
22850: </script>
22851:
22852: END
1.152 raeburn 22853:
1.150 raeburn 22854: }
22855:
1.165 raeburn 22856: sub recaptcha_js {
22857: my %lt = &captcha_phrases();
22858: return <<"END";
22859:
22860: <script type="text/javascript">
22861: // <![CDATA[
22862:
22863: function updateCaptcha(caller,context) {
22864: var privitem;
22865: var pubitem;
22866: var privtext;
22867: var pubtext;
1.269 raeburn 22868: var versionitem;
22869: var versiontext;
1.165 raeburn 22870: if (document.getElementById(context+'_recaptchapub')) {
22871: pubitem = document.getElementById(context+'_recaptchapub');
22872: } else {
22873: return;
22874: }
22875: if (document.getElementById(context+'_recaptchapriv')) {
22876: privitem = document.getElementById(context+'_recaptchapriv');
22877: } else {
22878: return;
22879: }
22880: if (document.getElementById(context+'_recaptchapubtxt')) {
22881: pubtext = document.getElementById(context+'_recaptchapubtxt');
22882: } else {
22883: return;
22884: }
22885: if (document.getElementById(context+'_recaptchaprivtxt')) {
22886: privtext = document.getElementById(context+'_recaptchaprivtxt');
22887: } else {
22888: return;
22889: }
1.269 raeburn 22890: if (document.getElementById(context+'_recaptchaversion')) {
22891: versionitem = document.getElementById(context+'_recaptchaversion');
22892: } else {
22893: return;
22894: }
22895: if (document.getElementById(context+'_recaptchavertxt')) {
22896: versiontext = document.getElementById(context+'_recaptchavertxt');
22897: } else {
22898: return;
22899: }
1.165 raeburn 22900: if (caller.checked) {
22901: if (caller.value == 'recaptcha') {
22902: pubitem.type = 'text';
22903: privitem.type = 'text';
22904: pubitem.size = '40';
22905: privitem.size = '40';
22906: pubtext.innerHTML = "$lt{'pub'}";
22907: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 22908: versionitem.type = 'text';
22909: versionitem.size = '3';
1.289 raeburn 22910: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 22911: } else {
22912: pubitem.type = 'hidden';
22913: privitem.type = 'hidden';
1.269 raeburn 22914: versionitem.type = 'hidden';
1.165 raeburn 22915: pubtext.innerHTML = '';
22916: privtext.innerHTML = '';
1.269 raeburn 22917: versiontext.innerHTML = '';
1.165 raeburn 22918: }
22919: }
22920: return;
22921: }
22922:
22923: // ]]>
22924: </script>
22925:
22926: END
22927:
22928: }
22929:
1.236 raeburn 22930: sub toggle_display_js {
1.192 raeburn 22931: return <<"END";
22932:
22933: <script type="text/javascript">
22934: // <![CDATA[
22935:
1.236 raeburn 22936: function toggleDisplay(domForm,caller) {
22937: if (document.getElementById(caller)) {
22938: var divitem = document.getElementById(caller);
22939: var optionsElement = domForm.coursecredits;
1.264 raeburn 22940: var checkval = 1;
22941: var dispval = 'block';
1.303 raeburn 22942: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 22943: if (caller == 'emailoptions') {
1.372 raeburn 22944: optionsElement = domForm.cancreate_email;
1.236 raeburn 22945: }
1.257 raeburn 22946: if (caller == 'studentsubmission') {
22947: optionsElement = domForm.postsubmit;
22948: }
1.264 raeburn 22949: if (caller == 'cloneinstcode') {
22950: optionsElement = domForm.canclone;
22951: checkval = 'instcode';
22952: }
1.303 raeburn 22953: if (selfcreateRegExp.test(caller)) {
22954: optionsElement = domForm.elements[caller];
22955: checkval = 'other';
22956: dispval = 'inline'
22957: }
1.236 raeburn 22958: if (optionsElement.length) {
1.192 raeburn 22959: var currval;
1.236 raeburn 22960: for (var i=0; i<optionsElement.length; i++) {
22961: if (optionsElement[i].checked) {
22962: currval = optionsElement[i].value;
1.192 raeburn 22963: }
22964: }
1.264 raeburn 22965: if (currval == checkval) {
22966: divitem.style.display = dispval;
1.192 raeburn 22967: } else {
1.236 raeburn 22968: divitem.style.display = 'none';
1.192 raeburn 22969: }
22970: }
22971: }
22972: return;
22973: }
22974:
22975: // ]]>
22976: </script>
22977:
22978: END
22979:
22980: }
22981:
1.165 raeburn 22982: sub captcha_phrases {
22983: return &Apache::lonlocal::texthash (
22984: priv => 'Private key',
22985: pub => 'Public key',
22986: original => 'original (CAPTCHA)',
22987: recaptcha => 'successor (ReCAPTCHA)',
22988: notused => 'unused',
1.289 raeburn 22989: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 22990: );
22991: }
22992:
1.205 raeburn 22993: sub devalidate_remote_domconfs {
1.212 raeburn 22994: my ($dom,$cachekeys) = @_;
22995: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 22996: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22997: my %thismachine;
22998: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 22999: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23000: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
23001: 'ipaccess');
1.386 raeburn 23002: my %cache_by_lonhost;
23003: if (exists($cachekeys->{'samllanding'})) {
23004: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23005: my %landing = %{$cachekeys->{'samllanding'}};
23006: my %domservers = &Apache::lonnet::get_servers($dom);
23007: if (keys(%domservers)) {
23008: foreach my $server (keys(%domservers)) {
23009: my @cached;
23010: next if ($thismachine{$server});
23011: if ($landing{$server}) {
23012: push(@cached,&escape('samllanding').':'.&escape($server));
23013: }
23014: if (@cached) {
23015: $cache_by_lonhost{$server} = \@cached;
23016: }
23017: }
23018: }
23019: }
23020: }
1.260 raeburn 23021: if (keys(%servers)) {
1.205 raeburn 23022: foreach my $server (keys(%servers)) {
23023: next if ($thismachine{$server});
1.212 raeburn 23024: my @cached;
23025: foreach my $name (@posscached) {
23026: if ($cachekeys->{$name}) {
1.388 raeburn 23027: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23028: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23029: foreach my $key (keys(%{$cachekeys->{$name}})) {
23030: push(@cached,&escape($name).':'.&escape($key));
23031: }
23032: }
23033: } else {
23034: push(@cached,&escape($name).':'.&escape($dom));
23035: }
1.212 raeburn 23036: }
23037: }
1.386 raeburn 23038: if ((exists($cache_by_lonhost{$server})) &&
23039: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23040: push(@cached,@{$cache_by_lonhost{$server}});
23041: }
1.212 raeburn 23042: if (@cached) {
23043: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23044: }
1.205 raeburn 23045: }
23046: }
23047: return;
23048: }
23049:
1.3 raeburn 23050: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>