Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.5
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 5(raebur 4:2): # $Id: domainprefs.pm,v 1.160.6.118.2.4 2022/02/07 11:59:29 raeburn Exp $
1.160.6.40 raeburn 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.160.6.78 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: ###############################################################
30: ##############################################################
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.160.6.13 raeburn 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.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 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.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 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.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: 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.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 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.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.160.6.113 raeburn 177: use Net::CIDR;
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 220: 'requestauthor','selfenrollment','inststatus',
1.160.6.118.2 5(raebur 221:2): 'passwords','ltitools','ltisec','wafproxy','ipaccess'],$dom);
1(raebur 222:1): if (ref($domconfig{'ltitools'}) eq 'HASH') {
223:1): my %encconfig =
5(raebur 224:2): &Apache::lonnet::get_dom('encconfig',['ltitools','linkprot'],$dom,undef,1);
1(raebur 225:1): if (ref($encconfig{'ltitools'}) eq 'HASH') {
226:1): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
227:1): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
228:1): foreach my $item ('key','secret') {
229:1): $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
230:1): }
231:1): }
232:1): }
233:1): }
234:1): }
5(raebur 235:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
236:2): if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
237:2): if (ref($encconfig{'linkprot'}) eq 'HASH') {
238:2): foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
239:2): unless ($id =~ /^\d+$/) {
240:2): delete($domconfig{'ltisec'}{'linkprot'}{$id});
241:2): }
242:2): if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
243:2): (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
244:2): foreach my $item ('key','secret') {
245:2): $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
246:2): }
247:2): }
248:2): }
249:2): }
250:2): }
251:2): }
1.160.6.113 raeburn 252: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
253: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
254: 'contacts','usercreation','selfcreation','usermodification',
255: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 256: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2 5(raebur 257:2): 'ltitools','selfenrollment','usersessions','lti');
1.160.6.7 raeburn 258: my %existing;
259: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
260: %existing = %{$domconfig{'loadbalancing'}};
261: }
262: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 263: push(@prefs_order,'loadbalancing');
264: }
1.30 raeburn 265: my %prefs = (
266: 'rolecolors' =>
267: { text => 'Default color schemes',
1.67 raeburn 268: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 269: header => [{col1 => 'Student Settings',
270: col2 => '',},
271: {col1 => 'Coordinator Settings',
272: col2 => '',},
273: {col1 => 'Author Settings',
274: col2 => '',},
275: {col1 => 'Administrator Settings',
276: col2 => '',}],
1.160.6.37 raeburn 277: print => \&print_rolecolors,
278: modify => \&modify_rolecolors,
1.30 raeburn 279: },
1.110 raeburn 280: 'login' =>
1.30 raeburn 281: { text => 'Log-in page options',
1.67 raeburn 282: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 283: header => [{col1 => 'Log-in Page Items',
284: col2 => '',},
285: {col1 => 'Log-in Help',
1.160.6.56 raeburn 286: col2 => 'Value'},
287: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 288: col2 => 'Value'},
289: {col1 => 'SSO',
290: col2 => 'Dual login: SSO and non-SSO options'},
291: ],
1.160.6.37 raeburn 292: print => \&print_login,
293: modify => \&modify_login,
1.30 raeburn 294: },
1.43 raeburn 295: 'defaults' =>
1.160.6.40 raeburn 296: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 297: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 298: header => [{col1 => 'Setting',
1.160.6.40 raeburn 299: col2 => 'Value'},
300: {col1 => 'Institutional user types',
1.160.6.93 raeburn 301: col2 => 'Name displayed'}],
1.160.6.37 raeburn 302: print => \&print_defaults,
303: modify => \&modify_defaults,
1.43 raeburn 304: },
1.160.6.113 raeburn 305: 'wafproxy' =>
306: { text => 'Web Application Firewall/Reverse Proxy',
307: help => 'Domain_Configuration_WAF_Proxy',
308: header => [{col1 => 'Domain(s)',
309: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
310: },
311: {col1 => 'Domain(s)',
312: col2 => 'WAF Configuration',}],
313: print => \&print_wafproxy,
314: modify => \&modify_wafproxy,
315: },
1.160.6.98 raeburn 316: 'passwords' =>
317: { text => 'Passwords (Internal authentication)',
318: help => 'Domain_Configuration_Passwords',
319: header => [{col1 => 'Resetting Forgotten Password',
320: col2 => 'Settings'},
321: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
322: col2 => 'Settings'},
323: {col1 => 'Rules for LON-CAPA Passwords',
324: col2 => 'Settings'},
325: {col1 => 'Course Owner Changing Student Passwords',
326: col2 => 'Settings'}],
327: print => \&print_passwords,
328: modify => \&modify_passwords,
329: },
1.30 raeburn 330: 'quotas' =>
1.160.6.20 raeburn 331: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 332: help => 'Domain_Configuration_Quotas',
1.77 raeburn 333: header => [{col1 => 'User affiliation',
1.72 raeburn 334: col2 => 'Available tools',
1.160.6.28 raeburn 335: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 336: print => \&print_quotas,
337: modify => \&modify_quotas,
1.30 raeburn 338: },
339: 'autoenroll' =>
340: { text => 'Auto-enrollment settings',
1.67 raeburn 341: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 342: header => [{col1 => 'Configuration setting',
343: col2 => 'Value(s)'}],
1.160.6.37 raeburn 344: print => \&print_autoenroll,
345: modify => \&modify_autoenroll,
1.30 raeburn 346: },
347: 'autoupdate' =>
348: { text => 'Auto-update settings',
1.67 raeburn 349: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 350: header => [{col1 => 'Setting',
351: col2 => 'Value',},
1.131 raeburn 352: {col1 => 'Setting',
353: col2 => 'Affiliation'},
1.43 raeburn 354: {col1 => 'User population',
1.160.6.35 raeburn 355: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 356: print => \&print_autoupdate,
357: modify => \&modify_autoupdate,
1.30 raeburn 358: },
1.125 raeburn 359: 'autocreate' =>
360: { text => 'Auto-course creation settings',
361: help => 'Domain_Configuration_Auto_Creation',
362: header => [{col1 => 'Configuration Setting',
363: col2 => 'Value',}],
1.160.6.37 raeburn 364: print => \&print_autocreate,
365: modify => \&modify_autocreate,
1.125 raeburn 366: },
1.30 raeburn 367: 'directorysrch' =>
1.160.6.72 raeburn 368: { text => 'Directory searches',
1.67 raeburn 369: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 370: header => [{col1 => 'Institutional Directory Setting',
371: col2 => 'Value',},
372: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 373: col2 => 'Value',}],
1.160.6.37 raeburn 374: print => \&print_directorysrch,
375: modify => \&modify_directorysrch,
1.30 raeburn 376: },
377: 'contacts' =>
1.160.6.78 raeburn 378: { text => 'E-mail addresses and helpform',
1.67 raeburn 379: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 380: header => [{col1 => 'Default e-mail addresses',
381: col2 => 'Value',},
382: {col1 => 'Recipient(s) for notifications',
383: col2 => 'Value',},
1.160.6.107 raeburn 384: {col1 => 'Nightly status check e-mail',
385: col2 => 'Settings',},
1.160.6.78 raeburn 386: {col1 => 'Ask helpdesk form settings',
387: col2 => 'Value',},],
1.160.6.37 raeburn 388: print => \&print_contacts,
389: modify => \&modify_contacts,
1.30 raeburn 390: },
391: 'usercreation' =>
392: { text => 'User creation',
1.67 raeburn 393: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 394: header => [{col1 => 'Format rule type',
395: col2 => 'Format rules in force'},
1.34 raeburn 396: {col1 => 'User account creation',
397: col2 => 'Usernames which may be created',},
1.30 raeburn 398: {col1 => 'Context',
1.43 raeburn 399: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 400: print => \&print_usercreation,
401: modify => \&modify_usercreation,
1.30 raeburn 402: },
1.160.6.34 raeburn 403: 'selfcreation' =>
404: { text => 'Users self-creating accounts',
405: help => 'Domain_Configuration_Self_Creation',
406: header => [{col1 => 'Self-creation with institutional username',
407: col2 => 'Enabled?'},
408: {col1 => 'Institutional user type (login/SSO self-creation)',
409: col2 => 'Information user can enter'},
1.160.6.93 raeburn 410: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 411: col2 => 'Settings'}],
1.160.6.37 raeburn 412: print => \&print_selfcreation,
413: modify => \&modify_selfcreation,
1.160.6.34 raeburn 414: },
1.69 raeburn 415: 'usermodification' =>
1.33 raeburn 416: { text => 'User modification',
1.67 raeburn 417: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 418: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 419: col2 => 'User information updatable in author context'},
1.33 raeburn 420: {col1 => 'Target user has role',
1.160.6.35 raeburn 421: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 422: print => \&print_usermodification,
423: modify => \&modify_usermodification,
1.33 raeburn 424: },
1.69 raeburn 425: 'scantron' =>
1.160.6.97 raeburn 426: { text => 'Bubblesheet format',
1.67 raeburn 427: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 428: header => [ {col1 => 'Bubblesheet format file',
429: col2 => ''},
430: {col1 => 'Bubblesheet data upload formats',
431: col2 => 'Settings'}],
1.160.6.37 raeburn 432: print => \&print_scantron,
433: modify => \&modify_scantron,
1.46 raeburn 434: },
1.86 raeburn 435: 'requestcourses' =>
436: {text => 'Request creation of courses',
437: help => 'Domain_Configuration_Request_Courses',
438: header => [{col1 => 'User affiliation',
1.102 raeburn 439: col2 => 'Availability/Processing of requests',},
440: {col1 => 'Setting',
1.160.6.30 raeburn 441: col2 => 'Value'},
442: {col1 => 'Available textbooks',
1.160.6.39 raeburn 443: col2 => ''},
1.160.6.46 raeburn 444: {col1 => 'Available templates',
445: col2 => ''},
1.160.6.39 raeburn 446: {col1 => 'Validation (not official courses)',
447: col2 => 'Value'},],
1.160.6.37 raeburn 448: print => \&print_quotas,
449: modify => \&modify_quotas,
1.86 raeburn 450: },
1.160.6.5 raeburn 451: 'requestauthor' =>
1.160.6.34 raeburn 452: {text => 'Request Authoring Space',
1.160.6.5 raeburn 453: help => 'Domain_Configuration_Request_Author',
454: header => [{col1 => 'User affiliation',
455: col2 => 'Availability/Processing of requests',},
456: {col1 => 'Setting',
457: col2 => 'Value'}],
1.160.6.37 raeburn 458: print => \&print_quotas,
459: modify => \&modify_quotas,
1.160.6.5 raeburn 460: },
1.69 raeburn 461: 'coursecategories' =>
1.120 raeburn 462: { text => 'Cataloging of courses/communities',
1.67 raeburn 463: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 464: header => [{col1 => 'Catalog type/availability',
465: col2 => '',},
466: {col1 => 'Category settings for standard catalog',
1.57 raeburn 467: col2 => '',},
468: {col1 => 'Categories',
469: col2 => '',
470: }],
1.160.6.37 raeburn 471: print => \&print_coursecategories,
472: modify => \&modify_coursecategories,
1.69 raeburn 473: },
474: 'serverstatuses' =>
1.77 raeburn 475: {text => 'Access to server status pages',
1.69 raeburn 476: help => 'Domain_Configuration_Server_Status',
477: header => [{col1 => 'Status Page',
478: col2 => 'Other named users',
479: col3 => 'Specific IPs',
480: }],
1.160.6.37 raeburn 481: print => \&print_serverstatuses,
482: modify => \&modify_serverstatuses,
1.69 raeburn 483: },
1.160.6.73 raeburn 484: 'helpsettings' =>
485: {text => 'Support settings',
486: help => 'Domain_Configuration_Help_Settings',
487: header => [{col1 => 'Help Page Settings (logged-in users)',
488: col2 => 'Value'},
489: {col1 => 'Helpdesk Roles',
490: col2 => 'Settings'},],
491: print => \&print_helpsettings,
492: modify => \&modify_helpsettings,
493: },
1.160.6.39 raeburn 494: 'coursedefaults' =>
1.160.6.16 raeburn 495: {text => 'Course/Community defaults',
496: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 497: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
498: col2 => 'Value',},
499: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 500: col2 => 'Value',},],
1.160.6.37 raeburn 501: print => \&print_coursedefaults,
502: modify => \&modify_coursedefaults,
503: },
1.160.6.39 raeburn 504: 'selfenrollment' =>
1.160.6.37 raeburn 505: {text => 'Self-enrollment in Course/Community',
506: help => 'Domain_Configuration_Selfenrollment',
507: header => [{col1 => 'Configuration Rights',
508: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
509: {col1 => 'Defaults',
510: col2 => 'Value'},
511: {col1 => 'Self-enrollment validation (optional)',
512: col2 => 'Value'},],
513: print => \&print_selfenrollment,
514: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 515: },
1.141 raeburn 516: 'usersessions' =>
1.145 raeburn 517: {text => 'User session hosting/offloading',
1.137 raeburn 518: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 519: header => [{col1 => 'Domain server',
520: col2 => 'Servers to offload sessions to when busy'},
521: {col1 => 'Hosting of users from other domains',
1.137 raeburn 522: col2 => 'Rules'},
523: {col1 => "Hosting domain's own users elsewhere",
524: col2 => 'Rules'}],
1.160.6.37 raeburn 525: print => \&print_usersessions,
526: modify => \&modify_usersessions,
1.137 raeburn 527: },
1.160.6.78 raeburn 528: 'loadbalancing' =>
1.160.6.7 raeburn 529: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 530: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 531: header => [{col1 => 'Balancers',
1.150 raeburn 532: col2 => 'Default destinations',
1.160.6.13 raeburn 533: col3 => 'User affiliation',
1.150 raeburn 534: col4 => 'Overrides'},
535: ],
1.160.6.37 raeburn 536: print => \&print_loadbalancing,
537: modify => \&modify_loadbalancing,
1.150 raeburn 538: },
1.160.6.118.2 1(raebur 539:1): 'ltitools' =>
540:1): {text => 'External Tools (LTI)',
541:1): help => 'Domain_Configuration_LTI_Tools',
542:1): header => [{col1 => 'Setting',
543:1): col2 => 'Value',}],
544:1): print => \&print_ltitools,
545:1): modify => \&modify_ltitools,
546:1): },
5(raebur 547:2): 'lti' =>
548:2): {text => 'LTI Link Protection and LTI Consumers',
549:2): help => 'Domain_Configuration_LTI_Provider',
550:2): header => [{col1 => 'Encryption of shared secrets',
551:2): col2 => 'Settings'},
552:2): {col1 => 'Rules for shared secrets',
553:2): col2 => 'Settings'},
554:2): {col1 => 'Link Protectors',
555:2): col2 => 'Settings'},],
556:2): print => \&print_lti,
557:2): modify => \&modify_lti,
558:2): },
1.160.6.113 raeburn 559: 'ipaccess' =>
560: {text => 'IP-based access control',
561: help => 'Domain_Configuration_IP_Access',
562: header => [{col1 => 'Setting',
563: col2 => 'Value'},],
564: print => \&print_ipaccess,
565: modify => \&modify_ipaccess,
566: },
1.3 raeburn 567: );
1.110 raeburn 568: if (keys(%servers) > 1) {
569: $prefs{'login'} = { text => 'Log-in page options',
570: help => 'Domain_Configuration_Login_Page',
571: header => [{col1 => 'Log-in Service',
572: col2 => 'Server Setting',},
573: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 574:2): col2 => 'Settings'},
1.160.6.5 raeburn 575: {col1 => 'Log-in Help',
1.160.6.56 raeburn 576: col2 => 'Value'},
577: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 578: col2 => 'Value'},
579: {col1 => 'SSO',
580: col2 => 'Dual login: SSO and non-SSO options'},
581: ],
1.160.6.37 raeburn 582: print => \&print_login,
583: modify => \&modify_login,
1.110 raeburn 584: };
585: }
1.160.6.13 raeburn 586:
1.6 raeburn 587: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 588: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 589: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 590: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 591: text=>"Settings to display/modify"});
1.9 raeburn 592: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 593:
1.3 raeburn 594: if ($phase eq 'process') {
1.160.6.27 raeburn 595: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
596: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 597: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 598: $r->rflush();
1.160.6.27 raeburn 599: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 600: }
1.30 raeburn 601: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 602: my $js = &recaptcha_js().
1.160.6.40 raeburn 603: &toggle_display_js();
1.160.6.7 raeburn 604: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 605: my ($othertitle,$usertypes,$types) =
606: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 607: $js .= &lonbalance_targets_js($dom,$types,\%servers,
608: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 609: &new_spares_js().
610: &common_domprefs_js().
611: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 612: }
1.160.6.30 raeburn 613: if (grep(/^requestcourses$/,@actions)) {
614: my $javascript_validations;
615: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
616: $js .= <<END;
617: <script type="text/javascript">
618: $javascript_validations
619: </script>
620: $coursebrowserjs
621: END
1.160.6.113 raeburn 622: } elsif (grep(/^ipaccess$/,@actions)) {
623: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 624: }
1.160.6.93 raeburn 625: if (grep(/^selfcreation$/,@actions)) {
626: $js .= &selfcreate_javascript();
627: }
1.160.6.78 raeburn 628: if (grep(/^contacts$/,@actions)) {
629: $js .= &contacts_javascript();
630: }
1.160.6.97 raeburn 631: if (grep(/^scantron$/,@actions)) {
632: $js .= &scantron_javascript();
633: }
1.150 raeburn 634: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 635: } else {
1.160.6.11 raeburn 636: # check if domconfig user exists for the domain.
637: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 638: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 639: &config_check($dom,$confname,$servadm);
640: unless ($configuserok eq 'ok') {
641: &Apache::lonconfigsettings::print_header($r,$phase,$context);
642: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
643: $confname).
644: '<br />'
645: );
646: if ($switchserver) {
647: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
648: '<br />'.
649: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
650: '<br />'.
651: &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).
652: '<br />'.
653: &mt('To do that now, use the following link: [_1]',$switchserver)
654: );
655: } else {
656: $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.').
657: '<br />'.
658: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
659: );
660: }
661: $r->print(&Apache::loncommon::end_page());
662: return OK;
663: }
1.21 raeburn 664: if (keys(%domconfig) == 0) {
665: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 666: my @ids=&Apache::lonnet::current_machine_ids();
667: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 668: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 669: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 670: my $custom_img_count = 0;
671: foreach my $img (@loginimages) {
672: if ($designhash{$dom.'.login.'.$img} ne '') {
673: $custom_img_count ++;
674: }
675: }
676: foreach my $role (@roles) {
677: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
678: $custom_img_count ++;
679: }
680: }
681: if ($custom_img_count > 0) {
1.94 raeburn 682: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 683: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 684: $r->print(
685: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
686: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
687: &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 />'.
688: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
689: if ($switch_server) {
1.30 raeburn 690: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 691: }
1.91 raeburn 692: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 693: return OK;
694: }
695: }
696: }
1.91 raeburn 697: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 698: }
699: return OK;
700: }
701:
702: sub process_changes {
1.160.6.24 raeburn 703: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 704: my %domconfig;
705: if (ref($values) eq 'HASH') {
706: %domconfig = %{$values};
707: }
1.3 raeburn 708: my $output;
709: if ($action eq 'login') {
1.160.6.24 raeburn 710: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 711: } elsif ($action eq 'rolecolors') {
1.9 raeburn 712: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 713: $lastactref,%domconfig);
1.3 raeburn 714: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 715: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 716: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 717: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 718: } elsif ($action eq 'autoupdate') {
719: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 720: } elsif ($action eq 'autocreate') {
721: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 722: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 723: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 724: } elsif ($action eq 'usercreation') {
1.28 raeburn 725: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 726: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 727: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 728: } elsif ($action eq 'usermodification') {
729: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 730: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 731: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 732: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 733: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 734: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 735: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 736: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 737: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 738: } elsif ($action eq 'serverstatuses') {
739: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 740: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 741: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 742: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 743: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 744: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 745: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 746: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 747: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 748: } elsif ($action eq 'selfenrollment') {
749: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 750: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 751: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 752: } elsif ($action eq 'loadbalancing') {
753: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 5(raebur 754:2): } elsif ($action eq 'lti') {
755:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 756: } elsif ($action eq 'passwords') {
757: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.118.2 1(raebur 758:1): } elsif ($action eq 'ltitools') {
759:1): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.160.6.113 raeburn 760: } elsif ($action eq 'wafproxy') {
761: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
762: } elsif ($action eq 'ipaccess') {
763: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 764: }
765: return $output;
766: }
767:
768: sub print_config_box {
1.9 raeburn 769: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 770: my $rowtotal = 0;
1.49 raeburn 771: my $output;
772: if ($action eq 'coursecategories') {
773: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 774: } elsif ($action eq 'defaults') {
775: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 776: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 777:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 778: } elsif ($action eq 'helpsettings') {
779: my (%privs,%levelscurrent);
780: my %full=();
781: my %levels=(
782: course => {},
783: domain => {},
784: system => {},
785: );
786: my $context = 'domain';
787: my $crstype = 'Course';
788: my $formname = 'display';
789: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
790: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
791: $output =
792: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
793: \@templateroles);
1.160.6.118.2 1(raebur 794:1): } elsif ($action eq 'ltitools') {
795:1): $output .= <itools_javascript($settings);
5(raebur 796:2): } elsif ($action eq 'lti') {
797:2): $output .= &passwords_javascript('secrets')."\n".
798:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 799: } elsif ($action eq 'wafproxy') {
800: $output .= &wafproxy_javascript($dom);
801: } elsif ($action eq 'autoupdate') {
802: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 803: } elsif ($action eq 'autoenroll') {
804: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 805: } elsif ($action eq 'login') {
806: $output .= &saml_javascript();
807: } elsif ($action eq 'ipaccess') {
808: $output .= &ipaccess_javascript($settings);
1.91 raeburn 809: }
1.160.6.40 raeburn 810: $output .=
1.30 raeburn 811: '<table class="LC_nested_outer">
1.3 raeburn 812: <tr>
1.160.6.113 raeburn 813: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 814: &mt($item->{text}).' '.
815: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
816: '</tr>';
1.30 raeburn 817: $rowtotal ++;
1.110 raeburn 818: my $numheaders = 1;
819: if (ref($item->{'header'}) eq 'ARRAY') {
820: $numheaders = scalar(@{$item->{'header'}});
821: }
822: if ($numheaders > 1) {
1.64 raeburn 823: my $colspan = '';
1.145 raeburn 824: my $rightcolspan = '';
1.160.6.104 raeburn 825: my $leftnobr = '';
1.160.6.42 raeburn 826: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 827: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 828: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 829: $colspan = ' colspan="2"';
830: }
1.145 raeburn 831: if ($action eq 'usersessions') {
832: $rightcolspan = ' colspan="3"';
833: }
1.160.6.104 raeburn 834: if ($action eq 'passwords') {
835: $leftnobr = ' LC_nobreak';
836: }
1.30 raeburn 837: $output .= '
1.3 raeburn 838: <tr>
839: <td>
840: <table class="LC_nested">
841: <tr class="LC_info_row">
1.160.6.104 raeburn 842: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 843: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 844: </tr>';
1.69 raeburn 845: $rowtotal ++;
1.160.6.37 raeburn 846: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 847: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 848: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 5(raebur 849:2): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.160.6.37 raeburn 850: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 851: } elsif ($action eq 'passwords') {
852: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 853: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 854: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 855: } elsif ($action eq 'scantron') {
856: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 857: } elsif ($action eq 'login') {
1.160.6.113 raeburn 858: if ($numheaders == 5) {
1.160.6.5 raeburn 859: $colspan = ' colspan="2"';
860: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
861: } else {
862: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
863: }
1.160.6.37 raeburn 864: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 865: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 866: } elsif ($action eq 'rolecolors') {
1.30 raeburn 867: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 868: }
1.30 raeburn 869: $output .= '
1.6 raeburn 870: </table>
871: </td>
872: </tr>
873: <tr>
874: <td>
875: <table class="LC_nested">
876: <tr class="LC_info_row">
1.160.6.37 raeburn 877: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 878: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 879: </tr>';
880: $rowtotal ++;
1.160.6.37 raeburn 881: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
882: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 883: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 5(raebur 884:2): ($action eq 'contacts') || ($action eq 'passwords') || ($action eq 'lti')) {
1.160.6.42 raeburn 885: if ($action eq 'coursecategories') {
886: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
887: $colspan = ' colspan="2"';
1.160.6.98 raeburn 888: } elsif ($action eq 'passwords') {
889: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 890: } else {
891: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
892: }
893: $output .= '
1.63 raeburn 894: </table>
895: </td>
896: </tr>
897: <tr>
898: <td>
899: <table class="LC_nested">
900: <tr class="LC_info_row">
1.160.6.113 raeburn 901: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 902: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 903: </tr>'."\n";
904: if ($action eq 'coursecategories') {
905: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 906: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 907: if ($action eq 'passwords') {
908: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
909: } else {
910: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
911: }
912: $output .= '
1.160.6.98 raeburn 913: </tr>
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
1.160.6.113 raeburn 921: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 923: if ($action eq 'passwords') {
924: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
925: } else {
926: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
927: }
928: $output .= '
1.160.6.98 raeburn 929: </table>
930: </td>
931: </tr>
932: <tr>';
1.160.6.42 raeburn 933: } else {
934: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
935: }
1.63 raeburn 936: $rowtotal ++;
1.160.6.57 raeburn 937: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 938: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 939: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 940: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 941: } elsif ($action eq 'scantron') {
942: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 943: } elsif ($action eq 'login') {
1.160.6.113 raeburn 944: if ($numheaders == 5) {
1.160.6.5 raeburn 945: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
946: </table>
947: </td>
948: </tr>
949: <tr>
950: <td>
951: <table class="LC_nested">
952: <tr class="LC_info_row">
953: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 954: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 955: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
956: $rowtotal ++;
957: } else {
958: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
959: }
1.160.6.56 raeburn 960: $output .= '
961: </table>
962: </td>
963: </tr>
964: <tr>
965: <td>
966: <table class="LC_nested">
967: <tr class="LC_info_row">';
1.160.6.113 raeburn 968: if ($numheaders == 5) {
1.160.6.56 raeburn 969: $output .= '
970: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
971: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
972: </tr>';
973: } else {
974: $output .= '
975: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
976: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
977: </tr>';
978: }
979: $rowtotal ++;
1.160.6.113 raeburn 980: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
981: </table>
982: </td>
983: </tr>
984: <tr>
985: <td>
986: <table class="LC_nested">
987: <tr class="LC_info_row">';
988: if ($numheaders == 5) {
989: $output .= '
990: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
991: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
992: </tr>';
993: } else {
994: $output .= '
995: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
996: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
997: </tr>';
998: }
999: $rowtotal ++;
1000: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1001: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1002: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1003: $rowtotal ++;
1004: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1005: </table>
1006: </td>
1007: </tr>
1008: <tr>
1009: <td>
1010: <table class="LC_nested">
1011: <tr class="LC_info_row">
1012: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1013: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1014: &textbookcourses_javascript($settings).
1015: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1016: </table>
1017: </td>
1018: </tr>
1019: <tr>
1020: <td>
1021: <table class="LC_nested">
1022: <tr class="LC_info_row">
1023: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1024: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1025: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1026: </table>
1027: </td>
1028: </tr>
1029: <tr>
1030: <td>
1031: <table class="LC_nested">
1032: <tr class="LC_info_row">
1.160.6.46 raeburn 1033: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1034: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1035: </tr>'.
1036: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1037: } elsif ($action eq 'requestauthor') {
1038: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1039: $rowtotal ++;
1.122 jms 1040: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1041: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1042: </table>
1043: </td>
1044: </tr>
1045: <tr>
1046: <td>
1047: <table class="LC_nested">
1048: <tr class="LC_info_row">
1.69 raeburn 1049: <td class="LC_left_item"'.$colspan.' valign="top">'.
1050: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1051: <td class="LC_right_item" valign="top">'.
1052: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1053: </tr>'.
1.30 raeburn 1054: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1055: </table>
1056: </td>
1057: </tr>
1058: <tr>
1059: <td>
1060: <table class="LC_nested">
1061: <tr class="LC_info_row">
1.59 bisitz 1062: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1063: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1064: </tr>'.
1.30 raeburn 1065: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1066: $rowtotal += 2;
1.6 raeburn 1067: }
1.3 raeburn 1068: } else {
1.30 raeburn 1069: $output .= '
1.3 raeburn 1070: <tr>
1071: <td>
1072: <table class="LC_nested">
1.30 raeburn 1073: <tr class="LC_info_row">';
1.160.6.72 raeburn 1074: if ($action eq 'login') {
1.30 raeburn 1075: $output .= '
1.59 bisitz 1076: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1077: } elsif ($action eq 'serverstatuses') {
1078: $output .= '
1079: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1080: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1081:
1.6 raeburn 1082: } else {
1.30 raeburn 1083: $output .= '
1.69 raeburn 1084: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1085: }
1.72 raeburn 1086: if (defined($item->{'header'}->[0]->{'col3'})) {
1087: $output .= '<td class="LC_left_item" valign="top">'.
1088: &mt($item->{'header'}->[0]->{'col2'});
1089: if ($action eq 'serverstatuses') {
1090: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1091: }
1.69 raeburn 1092: } else {
1093: $output .= '<td class="LC_right_item" valign="top">'.
1094: &mt($item->{'header'}->[0]->{'col2'});
1095: }
1096: $output .= '</td>';
1097: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1098: if (defined($item->{'header'}->[0]->{'col4'})) {
1099: $output .= '<td class="LC_left_item" valign="top">'.
1100: &mt($item->{'header'}->[0]->{'col3'});
1101: } else {
1102: $output .= '<td class="LC_right_item" valign="top">'.
1103: &mt($item->{'header'}->[0]->{'col3'});
1104: }
1.69 raeburn 1105: if ($action eq 'serverstatuses') {
1106: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1107: }
1108: $output .= '</td>';
1.6 raeburn 1109: }
1.150 raeburn 1110: if ($item->{'header'}->[0]->{'col4'}) {
1111: $output .= '<td class="LC_right_item" valign="top">'.
1112: &mt($item->{'header'}->[0]->{'col4'});
1113: }
1.69 raeburn 1114: $output .= '</tr>';
1.48 raeburn 1115: $rowtotal ++;
1.160.6.5 raeburn 1116: if ($action eq 'quotas') {
1.86 raeburn 1117: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1118: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1119: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 1(raebur 1120:1): ($action eq 'ltitools') || ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1121: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1122: }
1.3 raeburn 1123: }
1.30 raeburn 1124: $output .= '
1.3 raeburn 1125: </table>
1126: </td>
1127: </tr>
1.30 raeburn 1128: </table><br />';
1129: return ($output,$rowtotal);
1.1 raeburn 1130: }
1131:
1.3 raeburn 1132: sub print_login {
1.160.6.5 raeburn 1133: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1134: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1135: my %choices = &login_choices();
1.160.6.113 raeburn 1136: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1137: %lt = &login_file_options();
1138: $switchserver = &check_switchserver($dom,$confname);
1139: }
1.110 raeburn 1140:
1.160.6.5 raeburn 1141: if ($caller eq 'service') {
1.149 raeburn 1142: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1143: my $choice = $choices{'disallowlogin'};
1144: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1145: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1146: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1147: '<th>'.$choices{'server'}.'</th>'.
1148: '<th>'.$choices{'serverpath'}.'</th>'.
1149: '<th>'.$choices{'custompath'}.'</th>'.
1150: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1151: my %disallowed;
1152: if (ref($settings) eq 'HASH') {
1153: if (ref($settings->{'loginvia'}) eq 'HASH') {
1154: %disallowed = %{$settings->{'loginvia'}};
1155: }
1156: }
1157: foreach my $lonhost (sort(keys(%servers))) {
1158: my $direct = 'selected="selected"';
1.128 raeburn 1159: if (ref($disallowed{$lonhost}) eq 'HASH') {
1160: if ($disallowed{$lonhost}{'server'} ne '') {
1161: $direct = '';
1162: }
1.110 raeburn 1163: }
1.115 raeburn 1164: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1165: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1166: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1167: '</option>';
1.160.6.13 raeburn 1168: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1169: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1170: my $selected = '';
1.128 raeburn 1171: if (ref($disallowed{$lonhost}) eq 'HASH') {
1172: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1173: $selected = 'selected="selected"';
1174: }
1.110 raeburn 1175: }
1176: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1177: $servers{$hostid}.'</option>';
1178: }
1.128 raeburn 1179: $datatable .= '</select></td>'.
1180: '<td><select name="'.$lonhost.'_serverpath">';
1181: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1182: my $pathname = $path;
1183: if ($path eq 'custom') {
1184: $pathname = &mt('Custom Path').' ->';
1185: }
1186: my $selected = '';
1187: if (ref($disallowed{$lonhost}) eq 'HASH') {
1188: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1189: $selected = 'selected="selected"';
1190: }
1191: } elsif ($path eq '') {
1192: $selected = 'selected="selected"';
1193: }
1194: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1195: }
1196: $datatable .= '</select></td>';
1197: my ($custom,$exempt);
1198: if (ref($disallowed{$lonhost}) eq 'HASH') {
1199: $custom = $disallowed{$lonhost}{'custompath'};
1200: $exempt = $disallowed{$lonhost}{'exempt'};
1201: }
1202: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1203: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1204: '</tr>';
1.110 raeburn 1205: }
1206: $datatable .= '</table></td></tr>';
1207: return $datatable;
1.160.6.5 raeburn 1208: } elsif ($caller eq 'page') {
1209: my %defaultchecked = (
1210: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1211: 'helpdesk' => 'on',
1.160.6.5 raeburn 1212: 'adminmail' => 'off',
1213: 'newuser' => 'off',
1214: );
1.160.6.14 raeburn 1215: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1216: my (%checkedon,%checkedoff);
1.42 raeburn 1217: foreach my $item (@toggles) {
1.160.6.5 raeburn 1218: if ($defaultchecked{$item} eq 'on') {
1219: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1220: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1221: } elsif ($defaultchecked{$item} eq 'off') {
1222: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1223: $checkedon{$item} = ' ';
1224: }
1.1 raeburn 1225: }
1.160.6.5 raeburn 1226: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1227:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1228: my @logintext = ('textcol','bgcol');
1229: my @bgs = ('pgbg','mainbg','sidebg');
1230: my @links = ('link','alink','vlink');
1231: my %designhash = &Apache::loncommon::get_domainconf($dom);
1232: my %defaultdesign = %Apache::loncommon::defaultdesign;
1233: my (%is_custom,%designs);
1234: my %defaults = (
1235: font => $defaultdesign{'login.font'},
1236: );
1.6 raeburn 1237: foreach my $item (@images) {
1.160.6.5 raeburn 1238: $defaults{$item} = $defaultdesign{'login.'.$item};
1239: $defaults{'showlogo'}{$item} = 1;
1240: }
1241: foreach my $item (@bgs) {
1242: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1243: }
1.41 raeburn 1244: foreach my $item (@logintext) {
1.160.6.5 raeburn 1245: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1246: }
1.160.6.5 raeburn 1247: foreach my $item (@links) {
1248: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1249: }
1.160.6.5 raeburn 1250: if (ref($settings) eq 'HASH') {
1251: foreach my $item (@toggles) {
1252: if ($settings->{$item} eq '1') {
1253: $checkedon{$item} = ' checked="checked" ';
1254: $checkedoff{$item} = ' ';
1255: } elsif ($settings->{$item} eq '0') {
1256: $checkedoff{$item} = ' checked="checked" ';
1257: $checkedon{$item} = ' ';
1258: }
1.6 raeburn 1259: }
1.160.6.5 raeburn 1260: foreach my $item (@images) {
1261: if (defined($settings->{$item})) {
1262: $designs{$item} = $settings->{$item};
1263: $is_custom{$item} = 1;
1264: }
1265: if (defined($settings->{'showlogo'}{$item})) {
1266: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1267: }
1268: }
1.160.6.118.2 2(raebur 1269:2): foreach my $item (@alttext) {
1270:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1271:2): if ($settings->{'alttext'}->{$item} ne '') {
1272:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1273:2): }
1274:2): }
1275:2): }
1.160.6.5 raeburn 1276: foreach my $item (@logintext) {
1277: if ($settings->{$item} ne '') {
1278: $designs{'logintext'}{$item} = $settings->{$item};
1279: $is_custom{$item} = 1;
1280: }
1281: }
1282: if ($settings->{'font'} ne '') {
1283: $designs{'font'} = $settings->{'font'};
1284: $is_custom{'font'} = 1;
1285: }
1286: foreach my $item (@bgs) {
1287: if ($settings->{$item} ne '') {
1288: $designs{'bgs'}{$item} = $settings->{$item};
1289: $is_custom{$item} = 1;
1290: }
1291: }
1292: foreach my $item (@links) {
1293: if ($settings->{$item} ne '') {
1294: $designs{'links'}{$item} = $settings->{$item};
1295: $is_custom{$item} = 1;
1296: }
1297: }
1298: } else {
1299: if ($designhash{$dom.'.login.font'} ne '') {
1300: $designs{'font'} = $designhash{$dom.'.login.font'};
1301: $is_custom{'font'} = 1;
1302: }
1303: foreach my $item (@images) {
1304: if ($designhash{$dom.'.login.'.$item} ne '') {
1305: $designs{$item} = $designhash{$dom.'.login.'.$item};
1306: $is_custom{$item} = 1;
1307: }
1308: }
1309: foreach my $item (@bgs) {
1310: if ($designhash{$dom.'.login.'.$item} ne '') {
1311: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1312: $is_custom{$item} = 1;
1313: }
1314: }
1315: foreach my $item (@links) {
1316: if ($designhash{$dom.'.login.'.$item} ne '') {
1317: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1318: $is_custom{$item} = 1;
1319: }
1.6 raeburn 1320: }
1321: }
1.160.6.5 raeburn 1322: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1323: logo => 'Institution Logo',
1324: domlogo => 'Domain Logo',
1325: login => 'Login box');
1326: my $itemcount = 1;
1327: foreach my $item (@toggles) {
1328: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1329: $datatable .=
1330: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1331: '</td><td>'.
1332: '<span class="LC_nobreak"><label><input type="radio" name="'.
1333: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1334: '</label> <label><input type="radio" name="'.$item.'"'.
1335: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1336: '</tr>';
1337: $itemcount ++;
1.6 raeburn 1338: }
1.160.6.5 raeburn 1339: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1340: $datatable .= '</tr></table></td></tr>';
1341: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1342: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1343: my $itemcount = 1;
1344: $defaulturl = '/adm/loginproblems.html';
1345: $defaulttype = 'default';
1346: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1347: my @currlangs;
1348: if (ref($settings) eq 'HASH') {
1349: if (ref($settings->{'helpurl'}) eq 'HASH') {
1350: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1351: next if ($settings->{'helpurl'}{$key} eq '');
1352: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1353: $type{$key} = 'custom';
1354: unless ($key eq 'nolang') {
1355: push(@currlangs,$key);
1356: }
1357: }
1358: } elsif ($settings->{'helpurl'} ne '') {
1359: $type{'nolang'} = 'custom';
1360: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1361: }
1362: }
1.160.6.5 raeburn 1363: foreach my $lang ('nolang',sort(@currlangs)) {
1364: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1365: $datatable .= '<tr'.$css_class.'>';
1366: if ($url{$lang} eq '') {
1367: $url{$lang} = $defaulturl;
1368: }
1369: if ($type{$lang} eq '') {
1370: $type{$lang} = $defaulttype;
1371: }
1372: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1373: if ($lang eq 'nolang') {
1374: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1375: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1376: } else {
1377: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1378: $langchoices{$lang},
1379: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1380: }
1381: $datatable .= '</span></td>'."\n".
1382: '<td class="LC_left_item">';
1383: if ($type{$lang} eq 'custom') {
1384: $datatable .= '<span class="LC_nobreak"><label>'.
1385: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1386: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1387: } else {
1388: $datatable .= $lt{'upl'};
1389: }
1390: $datatable .='<br />';
1391: if ($switchserver) {
1392: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1393: } else {
1394: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1395: }
1.160.6.5 raeburn 1396: $datatable .= '</td></tr>';
1397: $itemcount ++;
1.6 raeburn 1398: }
1.160.6.5 raeburn 1399: my @addlangs;
1400: foreach my $lang (sort(keys(%langchoices))) {
1401: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1402: push(@addlangs,$lang);
1403: }
1404: if (@addlangs > 0) {
1405: my %toadd;
1406: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1407: $toadd{''} = &mt('Select');
1408: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1409: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1410: &mt('Add log-in help page for a specific language:').' '.
1411: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1412: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1413: if ($switchserver) {
1414: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1415: } else {
1416: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1417: }
1.160.6.5 raeburn 1418: $datatable .= '</td></tr>';
1419: $itemcount ++;
1.6 raeburn 1420: }
1.160.6.5 raeburn 1421: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1422: } elsif ($caller eq 'headtag') {
1423: my %domservers = &Apache::lonnet::get_servers($dom);
1424: my $choice = $choices{'headtag'};
1425: $css_class = ' class="LC_odd_row"';
1426: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1427: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1428: '<th>'.$choices{'current'}.'</th>'.
1429: '<th>'.$choices{'action'}.'</th>'.
1430: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1431: my (%currurls,%currexempt);
1432: if (ref($settings) eq 'HASH') {
1433: if (ref($settings->{'headtag'}) eq 'HASH') {
1434: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1435: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1436: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1437: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1438: }
1439: }
1440: }
1441: }
1442: foreach my $lonhost (sort(keys(%domservers))) {
1443: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1444: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1445: if ($currurls{$lonhost}) {
1446: $datatable .= '<td class="LC_right_item"><a href="'.
1447: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1448: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1449: '">'.$lt{'curr'}.'</a></td>'.
1450: '<td><span class="LC_nobreak"><label>'.
1451: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1452: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1453: } else {
1454: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1455: }
1456: $datatable .='<br />';
1457: if ($switchserver) {
1458: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1459: } else {
1460: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1461: }
1.160.6.87 raeburn 1462: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1463: }
1464: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1465: } elsif ($caller eq 'saml') {
1466: my %domservers = &Apache::lonnet::get_servers($dom);
1467: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1468: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1469: '<th>'.$choices{'samllanding'}.'</th>'.
1470: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1471: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1472: foreach my $lonhost (keys(%domservers)) {
1473: $samlurl{$lonhost} = '/adm/sso';
1474: $styleon{$lonhost} = 'display:none';
1475: $styleoff{$lonhost} = '';
1476: }
1477: if (ref($settings->{'saml'}) eq 'HASH') {
1478: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1479: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1480: $saml{$lonhost} = 1;
1481: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1482: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1483: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1484: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1485: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1486: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1487: $styleon{$lonhost} = '';
1488: $styleoff{$lonhost} = 'display:none';
1489: } else {
1490: $styleon{$lonhost} = 'display:none';
1491: $styleoff{$lonhost} = '';
1492: }
1493: }
1494: }
1495: my $itemcount = 1;
1496: foreach my $lonhost (sort(keys(%domservers))) {
1497: my $samlon = ' ';
1498: my $samloff = ' checked="checked" ';
1499: if ($saml{$lonhost}) {
1500: $samlon = $samloff;
1501: $samloff = ' ';
1502: }
1503: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1504: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1505: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1506: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1507: &mt('No').'</label>'.(' 'x2).
1508: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1509: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1510: &mt('Yes').'</label></span></td>'.
1511: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1512: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1513: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1514: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1515: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1516: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1517: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1518: $samltext{$lonhost}.'" /></td><td>';
1519: if ($samlimg{$lonhost}) {
1520: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1521: '<span class="LC_nobreak"><label>'.
1522: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1523: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1524: } else {
1525: $datatable .= $lt{'upl'};
1526: }
1527: $datatable .='<br />';
1528: if ($switchserver) {
1529: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1530: } else {
1531: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1532: }
1533: $datatable .= '</td>'.
1534: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1535: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1536: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1537: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1538: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1539: $samltitle{$lonhost}.'</textarea></td>'.
1540: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1541: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1542: '</table></td>'.
1543: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1544: $itemcount ++;
1545: }
1546: $datatable .= '</table></td></tr>';
1.1 raeburn 1547: }
1.6 raeburn 1548: return $datatable;
1549: }
1550:
1551: sub login_choices {
1552: my %choices =
1553: &Apache::lonlocal::texthash (
1.116 bisitz 1554: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1555: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1556: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1557: disallowlogin => "Login page requests redirected",
1558: hostid => "Server",
1.128 raeburn 1559: server => "Redirect to:",
1560: serverpath => "Path",
1561: custompath => "Custom",
1562: exempt => "Exempt IP(s)",
1.110 raeburn 1563: directlogin => "No redirect",
1564: newuser => "Link to create a user account",
1565: img => "Header",
1566: logo => "Main Logo",
1567: domlogo => "Domain Logo",
1568: login => "Log-in Header",
1569: textcol => "Text color",
1570: bgcol => "Box color",
1571: bgs => "Background colors",
1572: links => "Link colors",
1573: font => "Font color",
1574: pgbg => "Header",
1575: mainbg => "Page",
1576: sidebg => "Login box",
1577: link => "Link",
1578: alink => "Active link",
1579: vlink => "Visited link",
1.160.6.56 raeburn 1580: headtag => "Custom markup",
1581: action => "Action",
1582: current => "Current",
1.160.6.113 raeburn 1583: samllanding => "Dual login?",
1584: samloptions => "Options",
1.160.6.118.2 2(raebur 1585:2): alttext => "Alt text",
1.6 raeburn 1586: );
1587: return %choices;
1588: }
1589:
1.160.6.113 raeburn 1590: sub login_file_options {
1591: return &Apache::lonlocal::texthash(
1592: del => 'Delete?',
1593: rep => 'Replace:',
1594: upl => 'Upload:',
1595: curr => 'View contents',
1596: default => 'Default',
1597: custom => 'Custom',
1598: none => 'None',
1599: );
1600: }
1601:
1602: sub print_ipaccess {
1603: my ($dom,$settings,$rowtotal) = @_;
1604: my $css_class;
1605: my $itemcount = 0;
1606: my $datatable;
1607: my %ordered;
1608: if (ref($settings) eq 'HASH') {
1609: foreach my $item (keys(%{$settings})) {
1610: if (ref($settings->{$item}) eq 'HASH') {
1611: my $num = $settings->{$item}{'order'};
1612: if ($num eq '') {
1613: $num = scalar(keys(%{$settings}));
1614: }
1615: $ordered{$num} = $item;
1616: }
1617: }
1618: }
1619: my $maxnum = scalar(keys(%ordered));
1620: if (keys(%ordered)) {
1621: my @items = sort { $a <=> $b } keys(%ordered);
1622: for (my $i=0; $i<@items; $i++) {
1623: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1624: my $item = $ordered{$items[$i]};
1625: my ($name,$ipranges,%commblocks,%courses);
1626: if (ref($settings->{$item}) eq 'HASH') {
1627: $name = $settings->{$item}->{'name'};
1628: $ipranges = $settings->{$item}->{'ip'};
1629: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1630: %commblocks = %{$settings->{$item}->{'commblocks'}};
1631: }
1632: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1633: %courses = %{$settings->{$item}->{'courses'}};
1634: }
1635: }
1636: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1637: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1638: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1639: for (my $k=0; $k<=$maxnum; $k++) {
1640: my $vpos = $k+1;
1641: my $selstr;
1642: if ($k == $i) {
1643: $selstr = ' selected="selected" ';
1644: }
1645: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1646: }
1647: $datatable .= '</select>'.(' 'x2).
1648: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1649: &mt('Delete?').'</label></span></td>'.
1650: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1651: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1652: '</td></tr>';
1653: $itemcount ++;
1654: }
1655: }
1656: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1657: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1658: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1659: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1660: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1661: for (my $k=0; $k<$maxnum+1; $k++) {
1662: my $vpos = $k+1;
1663: my $selstr;
1664: if ($k == $maxnum) {
1665: $selstr = ' selected="selected" ';
1666: }
1667: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1668: }
1669: $datatable .= '</select> '."\n".
1670: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1671: '<td colspan="2">'.
1672: &ipaccess_options('add',$itemcount,$dom).
1673: '</td>'."\n".
1674: '</tr>'."\n";
1675: $$rowtotal ++;
1676: return $datatable;
1677: }
1678:
1679: sub ipaccess_options {
1680: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1681: my (%currblocks,%currcourses,$output);
1682: if (ref($blocksref) eq 'HASH') {
1683: %currblocks = %{$blocksref};
1684: }
1685: if (ref($coursesref) eq 'HASH') {
1686: %currcourses = %{$coursesref};
1687: }
1688: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1689: '<span class="LC_nobreak">'.&mt('Name').': '.
1690: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1691: '</span></fieldset>'.
1692: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1693: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1694: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1695: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1696: $ipranges.'</textarea></fieldset>'.
1697: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1698: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1699: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1700: '<table>';
1701: foreach my $cid (sort(keys(%currcourses))) {
1702: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1703: $output .= '<tr><td><span class="LC_nobreak">'.
1704: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1705: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1706: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1707: }
1708: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1709: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1710: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1711: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1712: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1713: '</span></td></tr></table>'."\n".
1714: '</fieldset>';
1715: return $output;
1716: }
1717:
1718: sub blocker_checkboxes {
1719: my ($num,$blocks) = @_;
1720: my ($typeorder,$types) = &commblocktype_text();
1721: my $numinrow = 6;
1722: my $output = '<table>';
1723: for (my $i=0; $i<@{$typeorder}; $i++) {
1724: my $block = $typeorder->[$i];
1725: my $blockstatus;
1726: if (ref($blocks) eq 'HASH') {
1727: if ($blocks->{$block} eq 'on') {
1728: $blockstatus = 'checked="checked"';
1729: }
1730: }
1731: my $rem = $i%($numinrow);
1732: if ($rem == 0) {
1733: if ($i > 0) {
1734: $output .= '</tr>';
1735: }
1736: $output .= '<tr>';
1737: }
1738: if ($i == scalar(@{$typeorder})-1) {
1739: my $colsleft = $numinrow-$rem;
1740: if ($colsleft > 1) {
1741: $output .= '<td colspan="'.$colsleft.'">';
1742: } else {
1743: $output .= '<td>';
1744: }
1745: } else {
1746: $output .= '<td>';
1747: }
1748: my $item = 'ipaccess_block_'.$num;
1749: if ($blockstatus) {
1750: $blockstatus = ' '.$blockstatus;
1751: }
1752: $output .= '<span class="LC_nobreak"><label>'."\n".
1753: '<input type="checkbox" name="'.$item.'"'.
1754: $blockstatus.' value="'.$block.'"'.' />'.
1755: $types->{$block}.'</label></span>'."\n".
1756: '<br /></td>';
1757: }
1758: $output .= '</tr></table>';
1759: return $output;
1760: }
1761:
1762: sub commblocktype_text {
1763: my %types = &Apache::lonlocal::texthash(
1764: 'com' => 'Messaging',
1765: 'chat' => 'Chat Room',
1766: 'boards' => 'Discussion',
1767: 'port' => 'Portfolio',
1768: 'groups' => 'Groups',
1769: 'blogs' => 'Blogs',
1770: 'about' => 'User Information',
1771: 'printout' => 'Printouts',
1772: 'passwd' => 'Change Password',
1773: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1774: 'search' => 'Course search',
1775: 'wishlist' => 'Stored links',
1776: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1777: );
1.160.6.115 raeburn 1778: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1779: return ($typeorder,\%types);
1780: }
1781:
1.6 raeburn 1782: sub print_rolecolors {
1.30 raeburn 1783: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1784: my %choices = &color_font_choices();
1785: my @bgs = ('pgbg','tabbg','sidebg');
1786: my @links = ('link','alink','vlink');
1787: my @images = ('img');
1788: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1789: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1790: my %defaultdesign = %Apache::loncommon::defaultdesign;
1791: my (%is_custom,%designs);
1.160.6.22 raeburn 1792: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1793: if (ref($settings) eq 'HASH') {
1794: if (ref($settings->{$role}) eq 'HASH') {
1795: if ($settings->{$role}->{'img'} ne '') {
1796: $designs{'img'} = $settings->{$role}->{'img'};
1797: $is_custom{'img'} = 1;
1798: }
1799: if ($settings->{$role}->{'font'} ne '') {
1800: $designs{'font'} = $settings->{$role}->{'font'};
1801: $is_custom{'font'} = 1;
1802: }
1.97 tempelho 1803: if ($settings->{$role}->{'fontmenu'} ne '') {
1804: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1805: $is_custom{'fontmenu'} = 1;
1806: }
1.6 raeburn 1807: foreach my $item (@bgs) {
1808: if ($settings->{$role}->{$item} ne '') {
1809: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1810: $is_custom{$item} = 1;
1811: }
1812: }
1813: foreach my $item (@links) {
1814: if ($settings->{$role}->{$item} ne '') {
1815: $designs{'links'}{$item} = $settings->{$role}->{$item};
1816: $is_custom{$item} = 1;
1817: }
1818: }
1819: }
1820: } else {
1821: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1822: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1823: $is_custom{'img'} = 1;
1824: }
1.97 tempelho 1825: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1826: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1827: $is_custom{'fontmenu'} = 1;
1828: }
1.6 raeburn 1829: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1830: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1831: $is_custom{'font'} = 1;
1832: }
1833: foreach my $item (@bgs) {
1834: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1835: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1836: $is_custom{$item} = 1;
1837:
1838: }
1839: }
1840: foreach my $item (@links) {
1841: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1842: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1843: $is_custom{$item} = 1;
1844: }
1845: }
1846: }
1847: my $itemcount = 1;
1.30 raeburn 1848: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1849: $datatable .= '</tr></table></td></tr>';
1850: return $datatable;
1851: }
1852:
1.160.6.22 raeburn 1853: sub role_defaults {
1854: my ($role,$bgs,$links,$images,$logintext) = @_;
1855: my %defaults;
1856: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1857: return %defaults;
1858: }
1859: my %defaultdesign = %Apache::loncommon::defaultdesign;
1860: if ($role eq 'login') {
1861: %defaults = (
1862: font => $defaultdesign{$role.'.font'},
1863: );
1864: if (ref($logintext) eq 'ARRAY') {
1865: foreach my $item (@{$logintext}) {
1866: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1867: }
1868: }
1869: foreach my $item (@{$images}) {
1870: $defaults{'showlogo'}{$item} = 1;
1871: }
1872: } else {
1873: %defaults = (
1874: img => $defaultdesign{$role.'.img'},
1875: font => $defaultdesign{$role.'.font'},
1876: fontmenu => $defaultdesign{$role.'.fontmenu'},
1877: );
1878: }
1879: foreach my $item (@{$bgs}) {
1880: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1881: }
1882: foreach my $item (@{$links}) {
1883: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1884: }
1885: foreach my $item (@{$images}) {
1886: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1887: }
1888: return %defaults;
1889: }
1890:
1.6 raeburn 1891: sub display_color_options {
1.9 raeburn 1892: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1893: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1894: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1895: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1896: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1897: '<td>'.$choices->{'font'}.'</td>';
1898: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1899: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1900: } else {
1901: $datatable .= '<td> </td>';
1902: }
1.160.6.9 raeburn 1903: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1904:
1.8 raeburn 1905: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1906: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1907: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1908: ' </span></td></tr>';
1.107 raeburn 1909: unless ($role eq 'login') {
1910: $datatable .= '<tr'.$css_class.'>'.
1911: '<td>'.$choices->{'fontmenu'}.'</td>';
1912: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1913: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1914: } else {
1915: $datatable .= '<td> </td>';
1916: }
1.160.6.22 raeburn 1917: $current_color = $designs->{'fontmenu'} ?
1918: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1919: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1920: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1921: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1922: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1923: ' </span></td></tr>';
1.97 tempelho 1924: }
1.9 raeburn 1925: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1926: foreach my $img (@{$images}) {
1.18 albertel 1927: $itemcount ++;
1.6 raeburn 1928: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1929: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1930: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 1931:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1932: if ($role eq 'login') {
1933: if ($img eq 'login') {
1934: $login_hdr_pick =
1.135 bisitz 1935: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1936: $logincolors =
1937: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1938: $designs,$defaults);
1.160.6.118.2 2(raebur 1939:2): } else {
1940:2): if ($img ne 'domlogo') {
1941:2): $datatable.= &logo_display_options($img,$defaults,$designs);
1942:2): }
1943:2): if (ref($designs->{'alttext'}) eq 'HASH') {
1944:2): $alttext = $designs->{'alttext'}{$img};
1945:2): }
1.70 raeburn 1946: }
1947: }
1948: $datatable .= '</td>';
1.6 raeburn 1949: if ($designs->{$img} ne '') {
1950: $imgfile = $designs->{$img};
1.18 albertel 1951: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1952: } else {
1953: $imgfile = $defaults->{$img};
1954: }
1955: if ($imgfile) {
1.9 raeburn 1956: my ($showfile,$fullsize);
1957: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1958: my $urldir = $1;
1959: my $filename = $2;
1960: my @info = &Apache::lonnet::stat_file($designs->{$img});
1961: if (@info) {
1962: my $thumbfile = 'tn-'.$filename;
1963: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1964: if (@thumb) {
1965: $showfile = $urldir.'/'.$thumbfile;
1966: } else {
1967: $showfile = $imgfile;
1968: }
1969: } else {
1970: $showfile = '';
1971: }
1972: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1973: $showfile = $imgfile;
1.6 raeburn 1974: my $imgdir = $1;
1975: my $filename = $2;
1.159 raeburn 1976: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1977: $showfile = "/$imgdir/tn-".$filename;
1978: } else {
1.159 raeburn 1979: my $input = $londocroot.$imgfile;
1980: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1981: if (!-e $output) {
1.9 raeburn 1982: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1983: my ($fullwidth,$fullheight) = &check_dimensions($input);
1984: if ($fullwidth ne '' && $fullheight ne '') {
1985: if ($fullwidth > $width && $fullheight > $height) {
1986: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1987: my @args = ('convert','-sample',$size,$input,$output);
1988: system({$args[0]} @args);
1.159 raeburn 1989: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1990: }
1991: }
1.6 raeburn 1992: }
1993: }
1.16 raeburn 1994: }
1.6 raeburn 1995: if ($showfile) {
1.40 raeburn 1996: if ($showfile =~ m{^/(adm|res)/}) {
1997: if ($showfile =~ m{^/res/}) {
1998: my $local_showfile =
1999: &Apache::lonnet::filelocation('',$showfile);
2000: &Apache::lonnet::repcopy($local_showfile);
2001: }
2002: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2003: }
2004: if ($imgfile) {
2005: if ($imgfile =~ m{^/(adm|res)/}) {
2006: if ($imgfile =~ m{^/res/}) {
2007: my $local_imgfile =
2008: &Apache::lonnet::filelocation('',$imgfile);
2009: &Apache::lonnet::repcopy($local_imgfile);
2010: }
2011: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2012: } else {
2013: $fullsize = $imgfile;
2014: }
2015: }
1.41 raeburn 2016: $datatable .= '<td>';
2017: if ($img eq 'login') {
1.135 bisitz 2018: $datatable .= $login_hdr_pick;
2019: }
1.41 raeburn 2020: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2021: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2022: } else {
1.160.6.22 raeburn 2023: $datatable .= '<td> </td><td class="LC_left_item">'.
2024: &mt('Upload:').'<br />';
1.6 raeburn 2025: }
2026: } else {
1.160.6.22 raeburn 2027: $datatable .= '<td> </td><td class="LC_left_item">'.
2028: &mt('Upload:').'<br />';
1.6 raeburn 2029: }
1.9 raeburn 2030: if ($switchserver) {
2031: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2032: } else {
1.135 bisitz 2033: if ($img ne 'login') { # suppress file selection for Log-in header
2034: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2035: }
1.9 raeburn 2036: }
1.160.6.118.2 2(raebur 2037:2): if (($role eq 'login') && ($img ne 'login')) {
2038:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2039:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2040:2): '</label></span>';
2041:2): }
1.9 raeburn 2042: $datatable .= '</td></tr>';
1.6 raeburn 2043: }
2044: $itemcount ++;
2045: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2046: $datatable .= '<tr'.$css_class.'>'.
2047: '<td>'.$choices->{'bgs'}.'</td>';
2048: my $bgs_def;
2049: foreach my $item (@{$bgs}) {
2050: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2051: $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 2052: }
2053: }
2054: if ($bgs_def) {
1.8 raeburn 2055: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2056: } else {
2057: $datatable .= '<td> </td>';
2058: }
2059: $datatable .= '<td class="LC_right_item">'.
2060: '<table border="0"><tr>';
1.160.6.13 raeburn 2061:
1.6 raeburn 2062: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2063: $datatable .= '<td align="center">'.$choices->{$item};
2064: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2065: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2066: $datatable .= ' ';
1.6 raeburn 2067: }
1.160.6.9 raeburn 2068: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2069: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2070: }
2071: $datatable .= '</tr></table></td></tr>';
2072: $itemcount ++;
2073: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2074: $datatable .= '<tr'.$css_class.'>'.
2075: '<td>'.$choices->{'links'}.'</td>';
2076: my $links_def;
2077: foreach my $item (@{$links}) {
2078: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2079: $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 2080: }
2081: }
2082: if ($links_def) {
1.8 raeburn 2083: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2084: } else {
2085: $datatable .= '<td> </td>';
2086: }
2087: $datatable .= '<td class="LC_right_item">'.
2088: '<table border="0"><tr>';
2089: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2090: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2091: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2092: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2093: $datatable.=' ';
1.6 raeburn 2094: }
1.160.6.9 raeburn 2095: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2096: '" /></td>';
2097: }
1.30 raeburn 2098: $$rowtotal += $itemcount;
1.3 raeburn 2099: return $datatable;
2100: }
2101:
1.70 raeburn 2102: sub logo_display_options {
2103: my ($img,$defaults,$designs) = @_;
2104: my $checkedon;
2105: if (ref($defaults) eq 'HASH') {
2106: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2107: if ($defaults->{'showlogo'}{$img}) {
2108: $checkedon = 'checked="checked" ';
2109: }
2110: }
2111: }
2112: if (ref($designs) eq 'HASH') {
2113: if (ref($designs->{'showlogo'}) eq 'HASH') {
2114: if (defined($designs->{'showlogo'}{$img})) {
2115: if ($designs->{'showlogo'}{$img} == 0) {
2116: $checkedon = '';
2117: } elsif ($designs->{'showlogo'}{$img} == 1) {
2118: $checkedon = 'checked="checked" ';
2119: }
2120: }
2121: }
2122: }
2123: return '<br /><label> <input type="checkbox" name="'.
2124: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2125: &mt('show').'</label>'."\n";
2126: }
2127:
1.41 raeburn 2128: sub login_header_options {
1.135 bisitz 2129: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2130: my $output = '';
1.41 raeburn 2131: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2132: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2133: if (!$is_custom->{'textcol'}) {
2134: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2135: ' ';
2136: }
2137: if (!$is_custom->{'bgcol'}) {
2138: $output .= $choices->{'bgcol'}.': '.
2139: '<span id="css_'.$role.'_font" style="background-color: '.
2140: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2141: }
2142: $output .= '<br />';
2143: }
2144: $output .='<br />';
2145: return $output;
2146: }
2147:
2148: sub login_text_colors {
1.160.6.22 raeburn 2149: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2150: my $color_menu = '<table border="0"><tr>';
2151: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2152: $color_menu .= '<td align="center">'.$choices->{$item};
2153: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2154: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2155: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2156: }
2157: $color_menu .= '</tr></table><br />';
2158: return $color_menu;
2159: }
2160:
2161: sub image_changes {
2162: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2163: my $output;
1.135 bisitz 2164: if ($img eq 'login') {
1.160.6.87 raeburn 2165: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2166: } elsif (!$is_custom) {
1.70 raeburn 2167: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2168: $output = &mt('Default image:').'<br />';
1.41 raeburn 2169: } else {
1.160.6.87 raeburn 2170: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2171: }
2172: }
1.160.6.87 raeburn 2173: if ($img ne 'login') {
1.135 bisitz 2174: if ($img_import) {
2175: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2176: }
2177: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2178: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2179: if ($is_custom) {
2180: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2181: '<input type="checkbox" name="'.
2182: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2183: '</label> '.&mt('Replace:').'</span><br />';
2184: } else {
1.160.6.22 raeburn 2185: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2186: }
1.41 raeburn 2187: }
2188: return $output;
2189: }
2190:
1.3 raeburn 2191: sub print_quotas {
1.86 raeburn 2192: my ($dom,$settings,$rowtotal,$action) = @_;
2193: my $context;
2194: if ($action eq 'quotas') {
2195: $context = 'tools';
2196: } else {
2197: $context = $action;
2198: }
1.160.6.20 raeburn 2199: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2200: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2201: my $typecount = 0;
1.101 raeburn 2202: my ($css_class,%titles);
1.86 raeburn 2203: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2204: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2205: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2206: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2207: %titles = &courserequest_titles();
1.160.6.5 raeburn 2208: } elsif ($context eq 'requestauthor') {
2209: @usertools = ('author');
2210: @options = ('norequest','approval','automatic');
2211: %titles = &authorrequest_titles();
1.86 raeburn 2212: } else {
1.160.6.4 raeburn 2213: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2214: %titles = &tool_titles();
1.86 raeburn 2215: }
1.26 raeburn 2216: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2217: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2218: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2219: unless (($context eq 'requestcourses') ||
2220: ($context eq 'requestauthor')) {
1.86 raeburn 2221: if (ref($settings) eq 'HASH') {
2222: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2223: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2224: } else {
2225: $currdefquota = $settings->{$type};
2226: }
1.160.6.20 raeburn 2227: if (ref($settings->{authorquota}) eq 'HASH') {
2228: $currauthorquota = $settings->{authorquota}->{$type};
2229: }
1.78 raeburn 2230: }
1.72 raeburn 2231: }
1.3 raeburn 2232: if (defined($usertypes->{$type})) {
2233: $typecount ++;
2234: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2235: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2236: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2237: '<td class="LC_left_item">';
1.101 raeburn 2238: if ($context eq 'requestcourses') {
2239: $datatable .= '<table><tr>';
2240: }
2241: my %cell;
1.72 raeburn 2242: foreach my $item (@usertools) {
1.101 raeburn 2243: if ($context eq 'requestcourses') {
2244: my ($curroption,$currlimit);
2245: if (ref($settings) eq 'HASH') {
2246: if (ref($settings->{$item}) eq 'HASH') {
2247: $curroption = $settings->{$item}->{$type};
2248: if ($curroption =~ /^autolimit=(\d*)$/) {
2249: $currlimit = $1;
2250: }
2251: }
2252: }
2253: if (!$curroption) {
2254: $curroption = 'norequest';
2255: }
2256: $datatable .= '<th>'.$titles{$item}.'</th>';
2257: foreach my $option (@options) {
2258: my $val = $option;
2259: if ($option eq 'norequest') {
2260: $val = 0;
2261: }
2262: if ($option eq 'validate') {
2263: my $canvalidate = 0;
2264: if (ref($validations{$item}) eq 'HASH') {
2265: if ($validations{$item}{$type}) {
2266: $canvalidate = 1;
2267: }
2268: }
2269: next if (!$canvalidate);
2270: }
2271: my $checked = '';
2272: if ($option eq $curroption) {
2273: $checked = ' checked="checked"';
2274: } elsif ($option eq 'autolimit') {
2275: if ($curroption =~ /^autolimit/) {
2276: $checked = ' checked="checked"';
2277: }
2278: }
2279: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2280: '<input type="radio" name="crsreq_'.$item.
2281: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2282: $titles{$option}.'</label>';
1.101 raeburn 2283: if ($option eq 'autolimit') {
1.127 raeburn 2284: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2285: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2286: 'value="'.$currlimit.'" />';
1.101 raeburn 2287: }
1.127 raeburn 2288: $cell{$item} .= '</span> ';
1.103 raeburn 2289: if ($option eq 'autolimit') {
1.127 raeburn 2290: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2291: }
1.101 raeburn 2292: }
1.160.6.5 raeburn 2293: } elsif ($context eq 'requestauthor') {
2294: my $curroption;
2295: if (ref($settings) eq 'HASH') {
2296: $curroption = $settings->{$type};
2297: }
2298: if (!$curroption) {
2299: $curroption = 'norequest';
2300: }
2301: foreach my $option (@options) {
2302: my $val = $option;
2303: if ($option eq 'norequest') {
2304: $val = 0;
2305: }
2306: my $checked = '';
2307: if ($option eq $curroption) {
2308: $checked = ' checked="checked"';
2309: }
2310: $datatable .= '<span class="LC_nobreak"><label>'.
2311: '<input type="radio" name="authorreq_'.$type.
2312: '" value="'.$val.'"'.$checked.' />'.
2313: $titles{$option}.'</label></span> ';
2314: }
1.101 raeburn 2315: } else {
2316: my $checked = 'checked="checked" ';
2317: if (ref($settings) eq 'HASH') {
2318: if (ref($settings->{$item}) eq 'HASH') {
2319: if ($settings->{$item}->{$type} == 0) {
2320: $checked = '';
2321: } elsif ($settings->{$item}->{$type} == 1) {
2322: $checked = 'checked="checked" ';
2323: }
1.78 raeburn 2324: }
1.72 raeburn 2325: }
1.101 raeburn 2326: $datatable .= '<span class="LC_nobreak"><label>'.
2327: '<input type="checkbox" name="'.$context.'_'.$item.
2328: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2329: '</label></span> ';
1.72 raeburn 2330: }
1.101 raeburn 2331: }
2332: if ($context eq 'requestcourses') {
2333: $datatable .= '</tr><tr>';
2334: foreach my $item (@usertools) {
1.106 raeburn 2335: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2336: }
2337: $datatable .= '</tr></table>';
1.72 raeburn 2338: }
1.86 raeburn 2339: $datatable .= '</td>';
1.160.6.5 raeburn 2340: unless (($context eq 'requestcourses') ||
2341: ($context eq 'requestauthor')) {
1.86 raeburn 2342: $datatable .=
1.160.6.20 raeburn 2343: '<td class="LC_right_item">'.
2344: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2345: '<input type="text" name="quota_'.$type.
1.72 raeburn 2346: '" value="'.$currdefquota.
1.160.6.20 raeburn 2347: '" size="5" /></span>'.(' ' x 2).
2348: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2349: '<input type="text" name="authorquota_'.$type.
2350: '" value="'.$currauthorquota.
2351: '" size="5" /></span></td>';
1.86 raeburn 2352: }
2353: $datatable .= '</tr>';
1.3 raeburn 2354: }
2355: }
2356: }
1.160.6.5 raeburn 2357: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2358: $defaultquota = '20';
1.160.6.20 raeburn 2359: $authorquota = '500';
1.86 raeburn 2360: if (ref($settings) eq 'HASH') {
2361: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2362: $defaultquota = $settings->{'defaultquota'}->{'default'};
2363: } elsif (defined($settings->{'default'})) {
2364: $defaultquota = $settings->{'default'};
2365: }
1.160.6.20 raeburn 2366: if (ref($settings->{'authorquota'}) eq 'HASH') {
2367: $authorquota = $settings->{'authorquota'}->{'default'};
2368: }
1.3 raeburn 2369: }
2370: }
2371: $typecount ++;
2372: $css_class = $typecount%2?' class="LC_odd_row"':'';
2373: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2374: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2375: '<td class="LC_left_item">';
1.101 raeburn 2376: if ($context eq 'requestcourses') {
2377: $datatable .= '<table><tr>';
2378: }
2379: my %defcell;
1.72 raeburn 2380: foreach my $item (@usertools) {
1.101 raeburn 2381: if ($context eq 'requestcourses') {
2382: my ($curroption,$currlimit);
2383: if (ref($settings) eq 'HASH') {
2384: if (ref($settings->{$item}) eq 'HASH') {
2385: $curroption = $settings->{$item}->{'default'};
2386: if ($curroption =~ /^autolimit=(\d*)$/) {
2387: $currlimit = $1;
2388: }
2389: }
2390: }
2391: if (!$curroption) {
2392: $curroption = 'norequest';
2393: }
2394: $datatable .= '<th>'.$titles{$item}.'</th>';
2395: foreach my $option (@options) {
2396: my $val = $option;
2397: if ($option eq 'norequest') {
2398: $val = 0;
2399: }
2400: if ($option eq 'validate') {
2401: my $canvalidate = 0;
2402: if (ref($validations{$item}) eq 'HASH') {
2403: if ($validations{$item}{'default'}) {
2404: $canvalidate = 1;
2405: }
2406: }
2407: next if (!$canvalidate);
2408: }
2409: my $checked = '';
2410: if ($option eq $curroption) {
2411: $checked = ' checked="checked"';
2412: } elsif ($option eq 'autolimit') {
2413: if ($curroption =~ /^autolimit/) {
2414: $checked = ' checked="checked"';
2415: }
2416: }
2417: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2418: '<input type="radio" name="crsreq_'.$item.
2419: '_default" value="'.$val.'"'.$checked.' />'.
2420: $titles{$option}.'</label>';
2421: if ($option eq 'autolimit') {
1.127 raeburn 2422: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2423: $item.'_limit_default" size="1" '.
2424: 'value="'.$currlimit.'" />';
2425: }
1.127 raeburn 2426: $defcell{$item} .= '</span> ';
1.104 raeburn 2427: if ($option eq 'autolimit') {
1.127 raeburn 2428: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2429: }
1.101 raeburn 2430: }
1.160.6.5 raeburn 2431: } elsif ($context eq 'requestauthor') {
2432: my $curroption;
2433: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2434: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2435: }
2436: if (!$curroption) {
2437: $curroption = 'norequest';
2438: }
2439: foreach my $option (@options) {
2440: my $val = $option;
2441: if ($option eq 'norequest') {
2442: $val = 0;
2443: }
2444: my $checked = '';
2445: if ($option eq $curroption) {
2446: $checked = ' checked="checked"';
2447: }
2448: $datatable .= '<span class="LC_nobreak"><label>'.
2449: '<input type="radio" name="authorreq_default"'.
2450: ' value="'.$val.'"'.$checked.' />'.
2451: $titles{$option}.'</label></span> ';
2452: }
1.101 raeburn 2453: } else {
2454: my $checked = 'checked="checked" ';
2455: if (ref($settings) eq 'HASH') {
2456: if (ref($settings->{$item}) eq 'HASH') {
2457: if ($settings->{$item}->{'default'} == 0) {
2458: $checked = '';
2459: } elsif ($settings->{$item}->{'default'} == 1) {
2460: $checked = 'checked="checked" ';
2461: }
1.78 raeburn 2462: }
1.72 raeburn 2463: }
1.101 raeburn 2464: $datatable .= '<span class="LC_nobreak"><label>'.
2465: '<input type="checkbox" name="'.$context.'_'.$item.
2466: '" value="default" '.$checked.'/>'.$titles{$item}.
2467: '</label></span> ';
2468: }
2469: }
2470: if ($context eq 'requestcourses') {
2471: $datatable .= '</tr><tr>';
2472: foreach my $item (@usertools) {
1.106 raeburn 2473: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2474: }
1.101 raeburn 2475: $datatable .= '</tr></table>';
1.72 raeburn 2476: }
1.86 raeburn 2477: $datatable .= '</td>';
1.160.6.5 raeburn 2478: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2479: $datatable .= '<td class="LC_right_item">'.
2480: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2481: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2482: $defaultquota.'" size="5" /></span>'.(' ' x2).
2483: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2484: '<input type="text" name="authorquota" value="'.
2485: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2486: }
2487: $datatable .= '</tr>';
1.72 raeburn 2488: $typecount ++;
2489: $css_class = $typecount%2?' class="LC_odd_row"':'';
2490: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2491: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2492: if ($context eq 'requestcourses') {
1.109 raeburn 2493: $datatable .= &mt('(overrides affiliation, if set)').
2494: '</td>'.
2495: '<td class="LC_left_item">'.
2496: '<table><tr>';
1.101 raeburn 2497: } else {
1.109 raeburn 2498: $datatable .= &mt('(overrides affiliation, if checked)').
2499: '</td>'.
2500: '<td class="LC_left_item" colspan="2">'.
2501: '<br />';
1.101 raeburn 2502: }
2503: my %advcell;
1.72 raeburn 2504: foreach my $item (@usertools) {
1.101 raeburn 2505: if ($context eq 'requestcourses') {
2506: my ($curroption,$currlimit);
2507: if (ref($settings) eq 'HASH') {
2508: if (ref($settings->{$item}) eq 'HASH') {
2509: $curroption = $settings->{$item}->{'_LC_adv'};
2510: if ($curroption =~ /^autolimit=(\d*)$/) {
2511: $currlimit = $1;
2512: }
2513: }
2514: }
2515: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2516: my $checked = '';
2517: if ($curroption eq '') {
2518: $checked = ' checked="checked"';
2519: }
2520: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2521: '<input type="radio" name="crsreq_'.$item.
2522: '__LC_adv" value=""'.$checked.' />'.
2523: &mt('No override set').'</label></span> ';
1.101 raeburn 2524: foreach my $option (@options) {
2525: my $val = $option;
2526: if ($option eq 'norequest') {
2527: $val = 0;
2528: }
2529: if ($option eq 'validate') {
2530: my $canvalidate = 0;
2531: if (ref($validations{$item}) eq 'HASH') {
2532: if ($validations{$item}{'_LC_adv'}) {
2533: $canvalidate = 1;
2534: }
2535: }
2536: next if (!$canvalidate);
2537: }
2538: my $checked = '';
1.104 raeburn 2539: if ($val eq $curroption) {
1.101 raeburn 2540: $checked = ' checked="checked"';
2541: } elsif ($option eq 'autolimit') {
2542: if ($curroption =~ /^autolimit/) {
2543: $checked = ' checked="checked"';
2544: }
2545: }
2546: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2547: '<input type="radio" name="crsreq_'.$item.
2548: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2549: $titles{$option}.'</label>';
2550: if ($option eq 'autolimit') {
1.127 raeburn 2551: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2552: $item.'_limit__LC_adv" size="1" '.
2553: 'value="'.$currlimit.'" />';
2554: }
1.127 raeburn 2555: $advcell{$item} .= '</span> ';
1.104 raeburn 2556: if ($option eq 'autolimit') {
1.127 raeburn 2557: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2558: }
1.101 raeburn 2559: }
1.160.6.5 raeburn 2560: } elsif ($context eq 'requestauthor') {
2561: my $curroption;
2562: if (ref($settings) eq 'HASH') {
2563: $curroption = $settings->{'_LC_adv'};
2564: }
2565: my $checked = '';
2566: if ($curroption eq '') {
2567: $checked = ' checked="checked"';
2568: }
2569: $datatable .= '<span class="LC_nobreak"><label>'.
2570: '<input type="radio" name="authorreq__LC_adv"'.
2571: ' value=""'.$checked.' />'.
2572: &mt('No override set').'</label></span> ';
2573: foreach my $option (@options) {
2574: my $val = $option;
2575: if ($option eq 'norequest') {
2576: $val = 0;
2577: }
2578: my $checked = '';
2579: if ($val eq $curroption) {
2580: $checked = ' checked="checked"';
2581: }
2582: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2583: '<input type="radio" name="authorreq__LC_adv"'.
2584: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2585: $titles{$option}.'</label></span> ';
2586: }
1.101 raeburn 2587: } else {
2588: my $checked = 'checked="checked" ';
2589: if (ref($settings) eq 'HASH') {
2590: if (ref($settings->{$item}) eq 'HASH') {
2591: if ($settings->{$item}->{'_LC_adv'} == 0) {
2592: $checked = '';
2593: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2594: $checked = 'checked="checked" ';
2595: }
1.79 raeburn 2596: }
1.72 raeburn 2597: }
1.101 raeburn 2598: $datatable .= '<span class="LC_nobreak"><label>'.
2599: '<input type="checkbox" name="'.$context.'_'.$item.
2600: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2601: '</label></span> ';
2602: }
2603: }
2604: if ($context eq 'requestcourses') {
2605: $datatable .= '</tr><tr>';
2606: foreach my $item (@usertools) {
1.106 raeburn 2607: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2608: }
1.101 raeburn 2609: $datatable .= '</tr></table>';
1.72 raeburn 2610: }
1.98 raeburn 2611: $datatable .= '</td></tr>';
1.30 raeburn 2612: $$rowtotal += $typecount;
1.3 raeburn 2613: return $datatable;
2614: }
2615:
1.160.6.5 raeburn 2616: sub print_requestmail {
1.160.6.93 raeburn 2617: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2618: my ($now,$datatable,%currapp);
1.102 raeburn 2619: $now = time;
2620: if (ref($settings) eq 'HASH') {
2621: if (ref($settings->{'notify'}) eq 'HASH') {
2622: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2623: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2624: }
2625: }
2626: }
1.160.6.16 raeburn 2627: my $numinrow = 2;
1.160.6.34 raeburn 2628: my $css_class;
1.160.6.93 raeburn 2629: if ($$rowtotal%2) {
2630: $css_class = 'LC_odd_row';
2631: }
2632: if ($customcss) {
2633: $css_class .= " $customcss";
2634: }
2635: $css_class =~ s/^\s+//;
2636: if ($css_class) {
2637: $css_class = ' class="'.$css_class.'"';
2638: }
2639: if ($rowstyle) {
2640: $css_class .= ' style="'.$rowstyle.'"';
2641: }
1.160.6.5 raeburn 2642: my $text;
2643: if ($action eq 'requestcourses') {
2644: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2645: } elsif ($action eq 'requestauthor') {
2646: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2647: } else {
1.160.6.34 raeburn 2648: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2649: }
1.160.6.34 raeburn 2650: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2651: ' <td>'.$text.'</td>'.
1.102 raeburn 2652: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2653: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2654: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2655: if ($numdc > 0) {
2656: $datatable .= $table;
1.102 raeburn 2657: } else {
2658: $datatable .= &mt('There are no active Domain Coordinators');
2659: }
2660: $datatable .='</td></tr>';
2661: return $datatable;
2662: }
2663:
1.160.6.30 raeburn 2664: sub print_studentcode {
2665: my ($settings,$rowtotal) = @_;
2666: my $rownum = 0;
2667: my ($output,%current);
2668: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2669: if (ref($settings) eq 'HASH') {
2670: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2671: foreach my $type (@crstypes) {
2672: $current{$type} = $settings->{'uniquecode'}{$type};
2673: }
1.160.6.30 raeburn 2674: }
2675: }
2676: $output .= '<tr>'.
2677: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2678: '<td class="LC_left_item">';
2679: foreach my $type (@crstypes) {
2680: my $check = ' ';
2681: if ($current{$type}) {
2682: $check = ' checked="checked" ';
2683: }
2684: $output .= '<span class="LC_nobreak"><label>'.
2685: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2686: &mt($type).'</label></span>'.(' 'x2).' ';
2687: }
2688: $output .= '</td></tr>';
2689: $$rowtotal ++;
2690: return $output;
2691: }
2692:
2693: sub print_textbookcourses {
1.160.6.46 raeburn 2694: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2695: my $rownum = 0;
2696: my $css_class;
2697: my $itemcount = 1;
2698: my $maxnum = 0;
2699: my $bookshash;
2700: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2701: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2702: }
2703: my %ordered;
2704: if (ref($bookshash) eq 'HASH') {
2705: foreach my $item (keys(%{$bookshash})) {
2706: if (ref($bookshash->{$item}) eq 'HASH') {
2707: my $num = $bookshash->{$item}{'order'};
2708: $ordered{$num} = $item;
2709: }
2710: }
2711: }
2712: my $confname = $dom.'-domainconfig';
2713: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2714: my $maxnum = scalar(keys(%ordered));
2715: my $datatable;
1.160.6.30 raeburn 2716: if (keys(%ordered)) {
2717: my @items = sort { $a <=> $b } keys(%ordered);
2718: for (my $i=0; $i<@items; $i++) {
2719: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2720: my $key = $ordered{$items[$i]};
2721: my %coursehash=&Apache::lonnet::coursedescription($key);
2722: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2723: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2724: if (ref($bookshash->{$key}) eq 'HASH') {
2725: $subject = $bookshash->{$key}->{'subject'};
2726: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2727: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2728: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2729: $author = $bookshash->{$key}->{'author'};
2730: $image = $bookshash->{$key}->{'image'};
2731: if ($image ne '') {
2732: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2733: my $imagethumb = "$path/tn-".$imagefile;
2734: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2735: }
1.160.6.30 raeburn 2736: }
2737: }
1.160.6.46 raeburn 2738: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2739: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2740: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2741: for (my $k=0; $k<=$maxnum; $k++) {
2742: my $vpos = $k+1;
2743: my $selstr;
2744: if ($k == $i) {
2745: $selstr = ' selected="selected" ';
2746: }
2747: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2748: }
2749: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2750: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2751: &mt('Delete?').'</label></span></td>'.
2752: '<td colspan="2">'.
1.160.6.46 raeburn 2753: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2754: (' 'x2).
1.160.6.46 raeburn 2755: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2756: if ($type eq 'textbooks') {
2757: $datatable .= (' 'x2).
1.160.6.47 raeburn 2758: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2759: (' 'x2).
1.160.6.46 raeburn 2760: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2761: (' 'x2).
2762: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2763: if ($image) {
1.160.6.114 raeburn 2764: $datatable .= $imgsrc.
1.160.6.46 raeburn 2765: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2766: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2767: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2768: }
2769: if ($switchserver) {
2770: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2771: } else {
2772: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2773: }
1.160.6.30 raeburn 2774: }
1.160.6.46 raeburn 2775: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2776: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2777: $coursetitle.'</span></td></tr>'."\n";
2778: $itemcount ++;
2779: }
2780: }
2781: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2782: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2783: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2784: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2785: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2786: for (my $k=0; $k<$maxnum+1; $k++) {
2787: my $vpos = $k+1;
2788: my $selstr;
2789: if ($k == $maxnum) {
2790: $selstr = ' selected="selected" ';
2791: }
2792: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2793: }
2794: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2795: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2796: '<td colspan="2">'.
1.160.6.46 raeburn 2797: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2798: (' 'x2).
1.160.6.46 raeburn 2799: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2800: (' 'x2);
2801: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2802: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2803: (' 'x2).
2804: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2805: (' 'x2).
2806: '<span class="LC_nobreak">'.&mt('Image:').' ';
2807: if ($switchserver) {
2808: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2809: } else {
2810: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2811: }
1.160.6.87 raeburn 2812: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2813: }
1.160.6.87 raeburn 2814: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2815: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2816: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2817: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2818: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2819: '</span></td>'."\n".
2820: '</tr>'."\n";
2821: $itemcount ++;
2822: return $datatable;
2823: }
2824:
2825: sub textbookcourses_javascript {
1.160.6.46 raeburn 2826: my ($settings) = @_;
2827: return unless(ref($settings) eq 'HASH');
2828: my (%ordered,%total,%jstext);
2829: foreach my $type ('textbooks','templates') {
2830: $total{$type} = 0;
2831: if (ref($settings->{$type}) eq 'HASH') {
2832: foreach my $item (keys(%{$settings->{$type}})) {
2833: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2834: my $num = $settings->{$type}->{$item}{'order'};
2835: $ordered{$type}{$num} = $item;
2836: }
2837: }
2838: $total{$type} = scalar(keys(%{$settings->{$type}}));
2839: }
2840: my @jsarray = ();
2841: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2842: push(@jsarray,$ordered{$type}{$item});
2843: }
2844: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2845: }
2846: return <<"ENDSCRIPT";
2847: <script type="text/javascript">
2848: // <![CDATA[
1.160.6.46 raeburn 2849: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2850: var changedVal;
1.160.6.46 raeburn 2851: $jstext{'textbooks'};
2852: $jstext{'templates'};
2853: var newpos;
2854: var maxh;
2855: if (caller == 'textbooks') {
2856: newpos = 'textbooks_addbook_pos';
2857: maxh = 1 + $total{'textbooks'};
2858: } else {
2859: newpos = 'templates_addbook_pos';
2860: maxh = 1 + $total{'templates'};
2861: }
1.160.6.30 raeburn 2862: var current = new Array;
2863: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2864: if (item == newpos) {
2865: changedVal = newitemVal;
2866: } else {
2867: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2868: current[newitemVal] = newpos;
2869: }
1.160.6.46 raeburn 2870: if (caller == 'textbooks') {
2871: for (var i=0; i<textbooks.length; i++) {
2872: var elementName = 'textbooks_'+textbooks[i];
2873: if (elementName != item) {
2874: if (form.elements[elementName]) {
2875: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2876: current[currVal] = elementName;
2877: }
2878: }
2879: }
2880: }
2881: if (caller == 'templates') {
2882: for (var i=0; i<templates.length; i++) {
2883: var elementName = 'templates_'+templates[i];
2884: if (elementName != item) {
2885: if (form.elements[elementName]) {
2886: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2887: current[currVal] = elementName;
2888: }
1.160.6.30 raeburn 2889: }
2890: }
2891: }
2892: var oldVal;
2893: for (var j=0; j<maxh; j++) {
2894: if (current[j] == undefined) {
2895: oldVal = j;
2896: }
2897: }
2898: if (oldVal < changedVal) {
2899: for (var k=oldVal+1; k<=changedVal ; k++) {
2900: var elementName = current[k];
2901: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2902: }
2903: } else {
2904: for (var k=changedVal; k<oldVal; k++) {
2905: var elementName = current[k];
2906: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2907: }
2908: }
2909: return;
2910: }
2911:
2912: // ]]>
2913: </script>
2914:
2915: ENDSCRIPT
2916: }
2917:
1.160.6.118.2 1(raebur 2918:1): sub ltitools_javascript {
2919:1): my ($settings) = @_;
2920:1): my $togglejs = <itools_toggle_js();
2921:1): unless (ref($settings) eq 'HASH') {
2922:1): return $togglejs;
2923:1): }
2924:1): my (%ordered,$total,%jstext);
2925:1): $total = 0;
2926:1): foreach my $item (keys(%{$settings})) {
2927:1): if (ref($settings->{$item}) eq 'HASH') {
2928:1): my $num = $settings->{$item}{'order'};
2929:1): $ordered{$num} = $item;
2930:1): }
2931:1): }
2932:1): $total = scalar(keys(%{$settings}));
2933:1): my @jsarray = ();
2934:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2935:1): push(@jsarray,$ordered{$item});
2936:1): }
2937:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2938:1): return <<"ENDSCRIPT";
2939:1): <script type="text/javascript">
2940:1): // <![CDATA[
2941:1): function reorderLTITools(form,item) {
2942:1): var changedVal;
2943:1): $jstext
2944:1): var newpos = 'ltitools_add_pos';
2945:1): var maxh = 1 + $total;
2946:1): var current = new Array;
2947:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2948:1): if (item == newpos) {
2949:1): changedVal = newitemVal;
2950:1): } else {
2951:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2952:1): current[newitemVal] = newpos;
2953:1): }
2954:1): for (var i=0; i<ltitools.length; i++) {
2955:1): var elementName = 'ltitools_'+ltitools[i];
2956:1): if (elementName != item) {
2957:1): if (form.elements[elementName]) {
2958:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2959:1): current[currVal] = elementName;
2960:1): }
2961:1): }
2962:1): }
2963:1): var oldVal;
2964:1): for (var j=0; j<maxh; j++) {
2965:1): if (current[j] == undefined) {
2966:1): oldVal = j;
2967:1): }
2968:1): }
2969:1): if (oldVal < changedVal) {
2970:1): for (var k=oldVal+1; k<=changedVal ; k++) {
2971:1): var elementName = current[k];
2972:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2973:1): }
2974:1): } else {
2975:1): for (var k=changedVal; k<oldVal; k++) {
2976:1): var elementName = current[k];
2977:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2978:1): }
2979:1): }
2980:1): return;
2981:1): }
2982:1):
2983:1): // ]]>
2984:1): </script>
2985:1):
2986:1): $togglejs
2987:1):
2988:1): ENDSCRIPT
2989:1): }
2990:1):
2991:1): sub ltitools_toggle_js {
2992:1): return <<"ENDSCRIPT";
2993:1): <script type="text/javascript">
2994:1): // <![CDATA[
2995:1):
2996:1): function toggleLTITools(form,setting,item) {
2997:1): var radioname = '';
2998:1): var divid = '';
2999:1): if (setting == 'user') {
3000:1): divid = 'ltitools_'+setting+'_div_'+item;
3001:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3002:1): if (document.getElementById(divid)) {
3003:1): if (document.getElementById(checkid)) {
3004:1): if (document.getElementById(checkid).checked) {
3005:1): document.getElementById(divid).style.display = 'inline-block';
3006:1): } else {
3007:1): document.getElementById(divid).style.display = 'none';
3008:1): }
3009:1): }
3010:1): }
3011:1): }
3012:1): return;
3013:1): }
3014:1): // ]]>
3015:1): </script>
3016:1):
3017:1): ENDSCRIPT
3018:1): }
3019:1):
1.160.6.113 raeburn 3020: sub wafproxy_javascript {
3021: my ($dom) = @_;
3022: return <<"ENDSCRIPT";
3023: <script type="text/javascript">
3024: // <![CDATA[
3025: function updateWAF() {
3026: if (document.getElementById('wafproxy_remoteip')) {
3027: var wafremote = 0;
3028: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3029: wafremote = 1;
3030: }
3031: var fields = new Array('header','trust');
3032: for (var i=0; i<fields.length; i++) {
3033: if (document.getElementById('wafproxy_'+fields[i])) {
3034: if (wafremote == 1) {
3035: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3036: }
3037: else {
3038: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3039: }
3040: }
3041: }
3042: if (document.getElementById('wafproxyranges_$dom')) {
3043: if (wafremote == 1) {
3044: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3045: } else {
3046: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3047: if (document.display.wafproxy_vpnaccess[i].checked) {
3048: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3049: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3050: }
3051: }
3052: }
3053: }
3054: }
3055: }
3056: return;
3057: }
3058:
3059: function checkWAF() {
3060: if (document.getElementById('wafproxy_remoteip')) {
3061: var wafvpn = 0;
3062: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3063: if (document.display.wafproxy_vpnaccess[i].checked) {
3064: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3065: wafvpn = 1;
3066: }
3067: break;
3068: }
3069: }
3070: var vpn = new Array('vpnint','vpnext');
3071: for (var i=0; i<vpn.length; i++) {
3072: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3073: if (wafvpn == 1) {
3074: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3075: }
3076: else {
3077: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3078: }
3079: }
3080: }
3081: if (document.getElementById('wafproxyranges_$dom')) {
3082: if (wafvpn == 1) {
3083: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3084: }
3085: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3086: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3087: }
3088: }
3089: }
3090: return;
3091: }
3092:
3093: function toggleWAF() {
3094: if (document.getElementById('wafproxy_table')) {
3095: var wafproxy = 0;
3096: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3097: if (document.display.wafproxy_${dom}[i].checked) {
3098: if (document.display.wafproxy_${dom}[i].value == 1) {
3099: wafproxy = 1;
3100: break;
3101: }
3102: }
3103: }
3104: if (wafproxy == 1) {
3105: document.getElementById('wafproxy_table').style.display='inline';
3106: }
3107: else {
3108: document.getElementById('wafproxy_table').style.display='none';
3109: }
3110: if (document.getElementById('wafproxyrow_${dom}')) {
3111: if (wafproxy == 1) {
3112: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3113: }
3114: else {
3115: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3116: }
3117: }
3118: if (document.getElementById('nowafproxyrow_$dom')) {
3119: if (wafproxy == 1) {
3120: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3121: }
3122: else {
3123: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3124: }
3125: }
3126: }
3127: return;
3128: }
3129: // ]]>
3130: </script>
3131:
3132: ENDSCRIPT
3133: }
3134:
1.160.6.118.2 5(raebur 3135:2): sub lti_javascript {
3136:2): my ($dom,$settings) = @_;
3137:2): my $togglejs = <i_toggle_js($dom);
3138:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
3139:2): return <<"ENDSCRIPT";
3140:2): <script type="text/javascript">
3141:2): // <![CDATA[
3142:2):
3143:2): $linkprot_js
3144:2):
3145:2): // ]]>
3146:2): </script>
3147:2):
3148:2): $togglejs
3149:2):
3150:2): ENDSCRIPT
3151:2): }
3152:2):
3153:2): sub lti_toggle_js {
3154:2): my ($dom) = @_;
3155:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3156:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3157:2): my $course_servers = "'".join("','",keys(%servers))."'";
3158:2): function toggleLTIEncKey(form) {
3159:2): var shownhosts = new Array();
3160:2): var hiddenhosts = new Array();
3161:2): var forcourse = new Array($course_servers);
3162:2): var fromdomain = '$primary';
3163:2): var crsradio = form.elements['ltisec_crslinkprot'];
3164:2): if (crsradio.length) {
3165:2): for (var i=0; i<crsradio.length; i++) {
3166:2): if (crsradio[i].checked) {
3167:2): if (crsradio[i].value == 1) {
3168:2): if (forcourse.length > 0) {
3169:2): for (var j=0; j<forcourse.length; j++) {
3170:2): if (!shownhosts.includes(forcourse[j])) {
3171:2): shownhosts.push(forcourse[j]);
3172:2): }
3173:2): }
3174:2): }
3175:2): } else {
3176:2): if (forcourse.length > 0) {
3177:2): for (var j=0; j<forcourse.length; j++) {
3178:2): if (!hiddenhosts.includes(forcourse[j])) {
3179:2): hiddenhosts.push(forcourse[j]);
3180:2): }
3181:2): }
3182:2): }
3183:2): }
3184:2): }
3185:2): }
3186:2): }
3187:2): var domradio = form.elements['ltisec_domlinkprot'];
3188:2): if (domradio.length) {
3189:2): for (var i=0; i<domradio.length; i++) {
3190:2): if (domradio[i].checked) {
3191:2): if (domradio[i].value == 1) {
3192:2): if (!shownhosts.includes(fromdomain)) {
3193:2): shownhosts.push(fromdomain);
3194:2): }
3195:2): } else {
3196:2): if (!hiddenhosts.includes(fromdomain)) {
3197:2): hiddenhosts.push(fromdomain);
3198:2): }
3199:2): }
3200:2): }
3201:2): }
3202:2): }
3203:2): if (shownhosts.length > 0) {
3204:2): for (var i=0; i<shownhosts.length; i++) {
3205:2): if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3206:2): document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3207:2): }
3208:2): }
3209:2): if (document.getElementById('ltisec_noprivkey')) {
3210:2): document.getElementById('ltisec_noprivkey').style.display = 'none';
3211:2): }
3212:2): } else {
3213:2): if (document.getElementById('ltisec_noprivkey')) {
3214:2): document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3215:2): }
3216:2): }
3217:2): if (hiddenhosts.length > 0) {
3218:2): for (var i=0; i<hiddenhosts.length; i++) {
3219:2): if (!shownhosts.includes(hiddenhosts[i])) {
3220:2): if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3221:2): document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3222:2): }
3223:2): }
3224:2): }
3225:2): }
3226:2): return;
3227:2): }
3228:2):
3229:2): function togglePrivKey(form,hostid) {
3230:2): var radioname = '';
3231:2): var currdivid = '';
3232:2): var newdivid = '';
3233:2): if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3234:2): (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3235:2): currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3236:2): newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3237:2): radioname = form.elements['ltisec_changeprivkey_'+hostid];
3238:2): if (radioname) {
3239:2): if (radioname.length > 0) {
3240:2): var setvis;
3241:2): for (var i=0; i<radioname.length; i++) {
3242:2): if (radioname[i].checked == true) {
3243:2): if (radioname[i].value == 1) {
3244:2): newdivid.style.display = 'inline-block';
3245:2): currdivid.style.display = 'none';
3246:2): setvis = 1;
3247:2): }
3248:2): break;
3249:2): }
3250:2): }
3251:2): if (!setvis) {
3252:2): newdivid.style.display = 'none';
3253:2): currdivid.style.display = 'inline-block';
3254:2): }
3255:2): }
3256:2): }
3257:2): }
3258:2): }
3259:2):
3260:2): // ]]>
3261:2): </script>
3262:2):
3263:2): ENDSCRIPT
3264:2): }
3265:2):
1.160.6.113 raeburn 3266: sub autoupdate_javascript {
3267: return <<"ENDSCRIPT";
3268: <script type="text/javascript">
3269: // <![CDATA[
3270: function toggleLastActiveDays(form) {
3271: var radioname = 'lastactive';
3272: var divid = 'lastactive_div';
3273: var num = form.elements[radioname].length;
3274: if (num) {
3275: var setvis = '';
3276: for (var i=0; i<num; i++) {
3277: if (form.elements[radioname][i].checked) {
3278: if (form.elements[radioname][i].value == '1') {
3279: if (document.getElementById(divid)) {
3280: document.getElementById(divid).style.display = 'inline-block';
3281: }
3282: setvis = 1;
3283: }
3284: break;
3285: }
3286: }
3287: if (!setvis) {
3288: if (document.getElementById(divid)) {
3289: document.getElementById(divid).style.display = 'none';
3290: }
3291: }
3292: }
3293: return;
3294: }
3295: // ]]>
3296: </script>
3297:
3298: ENDSCRIPT
3299: }
3300:
1.160.6.116 raeburn 3301: sub autoenroll_javascript {
3302: return <<"ENDSCRIPT";
3303: <script type="text/javascript">
3304: // <![CDATA[
3305: function toggleFailsafe(form) {
3306: var radioname = 'autoenroll_failsafe';
3307: var divid = 'autoenroll_failsafe_div';
3308: var num = form.elements[radioname].length;
3309: if (num) {
3310: var setvis = '';
3311: for (var i=0; i<num; i++) {
3312: if (form.elements[radioname][i].checked) {
3313: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3314: if (document.getElementById(divid)) {
3315: document.getElementById(divid).style.display = 'inline-block';
3316: }
3317: setvis = 1;
3318: }
3319: break;
3320: }
3321: }
3322: if (!setvis) {
3323: if (document.getElementById(divid)) {
3324: document.getElementById(divid).style.display = 'none';
3325: }
3326: }
3327: }
3328: return;
3329: }
3330: // ]]>
3331: </script>
3332:
3333: ENDSCRIPT
3334: }
3335:
1.160.6.113 raeburn 3336: sub saml_javascript {
3337: return <<"ENDSCRIPT";
3338: <script type="text/javascript">
3339: // <![CDATA[
3340: function toggleSamlOptions(form,hostid) {
3341: var radioname = 'saml_'+hostid;
3342: var tablecellon = 'samloptionson_'+hostid;
3343: var tablecelloff = 'samloptionsoff_'+hostid;
3344: var num = form.elements[radioname].length;
3345: if (num) {
3346: var setvis = '';
3347: for (var i=0; i<num; i++) {
3348: if (form.elements[radioname][i].checked) {
3349: if (form.elements[radioname][i].value == '1') {
3350: if (document.getElementById(tablecellon)) {
3351: document.getElementById(tablecellon).style.display='';
3352: }
3353: if (document.getElementById(tablecelloff)) {
3354: document.getElementById(tablecelloff).style.display='none';
3355: }
3356: setvis = 1;
3357: }
3358: break;
3359: }
3360: }
3361: if (!setvis) {
3362: if (document.getElementById(tablecellon)) {
3363: document.getElementById(tablecellon).style.display='none';
3364: }
3365: if (document.getElementById(tablecelloff)) {
3366: document.getElementById(tablecelloff).style.display='';
3367: }
3368: }
3369: }
3370: return;
3371: }
3372: // ]]>
3373: </script>
3374:
3375: ENDSCRIPT
3376: }
3377:
3378: sub ipaccess_javascript {
3379: my ($settings) = @_;
3380: my (%ordered,$total,%jstext);
3381: $total = 0;
3382: if (ref($settings) eq 'HASH') {
3383: foreach my $item (keys(%{$settings})) {
3384: if (ref($settings->{$item}) eq 'HASH') {
3385: my $num = $settings->{$item}{'order'};
3386: $ordered{$num} = $item;
3387: }
3388: }
3389: $total = scalar(keys(%{$settings}));
3390: }
3391: my @jsarray = ();
3392: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3393: push(@jsarray,$ordered{$item});
3394: }
3395: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3396: return <<"ENDSCRIPT";
3397: <script type="text/javascript">
3398: // <![CDATA[
3399: function reorderIPaccess(form,item) {
3400: var changedVal;
3401: $jstext
3402: var newpos = 'ipaccess_pos_add';
3403: var maxh = 1 + $total;
3404: var current = new Array;
3405: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3406: if (item == newpos) {
3407: changedVal = newitemVal;
3408: } else {
3409: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3410: current[newitemVal] = newpos;
3411: }
3412: for (var i=0; i<ipaccess.length; i++) {
3413: var elementName = 'ipaccess_pos_'+ipaccess[i];
3414: if (elementName != item) {
3415: if (form.elements[elementName]) {
3416: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3417: current[currVal] = elementName;
3418: }
3419: }
3420: }
3421: var oldVal;
3422: for (var j=0; j<maxh; j++) {
3423: if (current[j] == undefined) {
3424: oldVal = j;
3425: }
3426: }
3427: if (oldVal < changedVal) {
3428: for (var k=oldVal+1; k<=changedVal ; k++) {
3429: var elementName = current[k];
3430: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3431: }
3432: } else {
3433: for (var k=changedVal; k<oldVal; k++) {
3434: var elementName = current[k];
3435: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3436: }
3437: }
3438: return;
3439: }
3440: // ]]>
3441: </script>
3442:
3443: ENDSCRIPT
3444: }
3445:
1.3 raeburn 3446: sub print_autoenroll {
1.30 raeburn 3447: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3448: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3449: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3450: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3451: $failsafesty = 'none';
3452: %failsafechecked = (
3453: off => ' checked="checked"',
3454: );
1.3 raeburn 3455: if (ref($settings) eq 'HASH') {
3456: if (exists($settings->{'run'})) {
3457: if ($settings->{'run'} eq '0') {
3458: $runoff = ' checked="checked" ';
3459: $runon = ' ';
3460: } else {
3461: $runon = ' checked="checked" ';
3462: $runoff = ' ';
3463: }
3464: } else {
3465: if ($autorun) {
3466: $runon = ' checked="checked" ';
3467: $runoff = ' ';
3468: } else {
3469: $runoff = ' checked="checked" ';
3470: $runon = ' ';
3471: }
3472: }
1.129 raeburn 3473: if (exists($settings->{'co-owners'})) {
3474: if ($settings->{'co-owners'} eq '0') {
3475: $coownersoff = ' checked="checked" ';
3476: $coownerson = ' ';
3477: } else {
3478: $coownerson = ' checked="checked" ';
3479: $coownersoff = ' ';
3480: }
3481: } else {
3482: $coownersoff = ' checked="checked" ';
3483: $coownerson = ' ';
3484: }
1.3 raeburn 3485: if (exists($settings->{'sender_domain'})) {
3486: $defdom = $settings->{'sender_domain'};
3487: }
1.160.6.116 raeburn 3488: if (exists($settings->{'failsafe'})) {
3489: $failsafe = $settings->{'failsafe'};
3490: if ($failsafe eq 'zero') {
3491: $failsafechecked{'zero'} = ' checked="checked"';
3492: $failsafechecked{'off'} = '';
3493: $failsafesty = 'inline-block';
3494: } elsif ($failsafe eq 'any') {
3495: $failsafechecked{'any'} = ' checked="checked"';
3496: $failsafechecked{'off'} = '';
3497: }
3498: $autofailsafe = $settings->{'autofailsafe'};
3499: } elsif (exists($settings->{'autofailsafe'})) {
3500: $autofailsafe = $settings->{'autofailsafe'};
3501: if ($autofailsafe ne '') {
3502: $failsafechecked{'zero'} = ' checked="checked"';
3503: $failsafe = 'zero';
3504: $failsafechecked{'off'} = '';
3505: }
1.160.6.68 raeburn 3506: }
1.14 raeburn 3507: } else {
3508: if ($autorun) {
3509: $runon = ' checked="checked" ';
3510: $runoff = ' ';
3511: } else {
3512: $runoff = ' checked="checked" ';
3513: $runon = ' ';
3514: }
1.3 raeburn 3515: }
3516: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3517: my $notif_sender;
3518: if (ref($settings) eq 'HASH') {
3519: $notif_sender = $settings->{'sender_uname'};
3520: }
1.3 raeburn 3521: my $datatable='<tr class="LC_odd_row">'.
3522: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3523: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3524: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3525: $runon.' value="1" />'.&mt('Yes').'</label> '.
3526: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3527: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3528: '</tr><tr>'.
3529: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3530: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3531: &mt('username').': '.
3532: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3533: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3534: ': '.$domform.'</span></td></tr>'.
3535: '<tr class="LC_odd_row">'.
3536: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3537: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3538: '<input type="radio" name="autoassign_coowners"'.
3539: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3540: '<label><input type="radio" name="autoassign_coowners"'.
3541: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3542: '</tr><tr>'.
3543: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3544: '<td class="LC_left_item"><span class="LC_nobreak">'.
3545: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3546: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3547: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
3548: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3549: '<span class="LC_nobreak">'.
3550: &mt('Threshold for number of students in section to drop: [_1]',
3551: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3552: '</span></div></td></tr>';
1.160.6.68 raeburn 3553: $$rowtotal += 4;
1.3 raeburn 3554: return $datatable;
3555: }
3556:
3557: sub print_autoupdate {
1.30 raeburn 3558: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3559: my ($enable,$datatable);
1.3 raeburn 3560: if ($position eq 'top') {
1.160.6.113 raeburn 3561: my %choices = &Apache::lonlocal::texthash (
3562: run => 'Auto-update active?',
3563: classlists => 'Update information in classlists?',
3564: unexpired => 'Skip updates for users without active or future roles?',
3565: lastactive => 'Skip updates for inactive users?',
3566: );
3567: my $itemcount = 0;
1.3 raeburn 3568: my $updateon = ' ';
3569: my $updateoff = ' checked="checked" ';
3570: if (ref($settings) eq 'HASH') {
3571: if ($settings->{'run'} eq '1') {
3572: $updateon = $updateoff;
3573: $updateoff = ' ';
3574: }
3575: }
1.160.6.113 raeburn 3576: $enable = '<tr class="LC_odd_row">'.
3577: '<td>'.&mt($choices{'run'}).'</td>'.
3578: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3579: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3580: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3581: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3582: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3583: '</tr>';
1.160.6.113 raeburn 3584: my @toggles = ('classlists','unexpired');
3585: my %defaultchecked = ('classlists' => 'off',
3586: 'unexpired' => 'off'
3587: );
3588: $$rowtotal ++;
3589: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3590: \%choices,$itemcount,'','','left','no');
3591: $datatable = $enable.$datatable;
3592: $$rowtotal += $itemcount;
3593: my $lastactiveon = ' ';
3594: my $lastactiveoff = ' checked="checked" ';
3595: my $lastactivestyle = 'none';
3596: my $lastactivedays;
3597: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3598: if (ref($settings) eq 'HASH') {
3599: if ($settings->{'lastactive'} =~ /^\d+$/) {
3600: $lastactiveon = $lastactiveoff;
3601: $lastactiveoff = ' ';
3602: $lastactivestyle = 'inline-block';
3603: $lastactivedays = $settings->{'lastactive'};
3604: }
3605: }
3606: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3607: $datatable .= '<tr'.$css_class.'>'.
3608: '<td>'.$choices{'lastactive'}.'</td>'.
3609: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3610: '<input type="radio" name="lastactive"'.
3611: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3612: ' <label>'.
3613: '<input type="radio" name="lastactive"'.
3614: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3615: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3616: ': '.&mt('inactive = no activity in last [_1] days',
3617: '<input type="text" size="5" name="lastactivedays" value="'.
3618: $lastactivedays.'" />').
3619: '</span></td>'.
3620: '</tr>';
3621: $$rowtotal ++;
1.131 raeburn 3622: } elsif ($position eq 'middle') {
3623: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3624: my $numinrow = 3;
3625: my $locknamesettings;
3626: $datatable .= &insttypes_row($settings,$types,$usertypes,
3627: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3628: 'lockablenames',$rowtotal);
1.131 raeburn 3629: $$rowtotal ++;
1.3 raeburn 3630: } else {
1.44 raeburn 3631: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3632: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3633: 'permanentemail','id');
1.33 raeburn 3634: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3635: my $numrows = 0;
1.26 raeburn 3636: if (ref($types) eq 'ARRAY') {
3637: if (@{$types} > 0) {
3638: $datatable =
3639: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3640: \@fields,$types,\$numrows);
1.30 raeburn 3641: $$rowtotal += @{$types};
1.26 raeburn 3642: }
1.3 raeburn 3643: }
3644: $datatable .=
3645: &usertype_update_row($settings,{'default' => $othertitle},
3646: \%fieldtitles,\@fields,['default'],
3647: \$numrows);
1.30 raeburn 3648: $$rowtotal ++;
1.3 raeburn 3649: }
3650: return $datatable;
3651: }
3652:
1.125 raeburn 3653: sub print_autocreate {
3654: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3655: my (%createon,%createoff,%currhash);
1.125 raeburn 3656: my @types = ('xml','req');
3657: if (ref($settings) eq 'HASH') {
3658: foreach my $item (@types) {
3659: $createoff{$item} = ' checked="checked" ';
3660: $createon{$item} = ' ';
3661: if (exists($settings->{$item})) {
3662: if ($settings->{$item}) {
3663: $createon{$item} = ' checked="checked" ';
3664: $createoff{$item} = ' ';
3665: }
3666: }
3667: }
1.160.6.16 raeburn 3668: if ($settings->{'xmldc'} ne '') {
3669: $currhash{$settings->{'xmldc'}} = 1;
3670: }
1.125 raeburn 3671: } else {
3672: foreach my $item (@types) {
3673: $createoff{$item} = ' checked="checked" ';
3674: $createon{$item} = ' ';
3675: }
3676: }
3677: $$rowtotal += 2;
1.160.6.16 raeburn 3678: my $numinrow = 2;
1.125 raeburn 3679: my $datatable='<tr class="LC_odd_row">'.
3680: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3681: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3682: '<input type="radio" name="autocreate_xml"'.
3683: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3684: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3685: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3686: '</td></tr><tr>'.
3687: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3688: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3689: '<input type="radio" name="autocreate_req"'.
3690: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3691: '<label><input type="radio" name="autocreate_req"'.
3692: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3693: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3694: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3695: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3696: if ($numdc > 1) {
1.160.6.50 raeburn 3697: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3698: '</td><td class="LC_left_item">';
1.125 raeburn 3699: } else {
1.160.6.50 raeburn 3700: $datatable .= &mt('Course creation processed as:').
3701: '</td><td class="LC_right_item">';
1.125 raeburn 3702: }
1.160.6.50 raeburn 3703: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3704: $$rowtotal += $rows;
1.125 raeburn 3705: return $datatable;
3706: }
3707:
1.23 raeburn 3708: sub print_directorysrch {
1.160.6.72 raeburn 3709: my ($position,$dom,$settings,$rowtotal) = @_;
3710: my $datatable;
3711: if ($position eq 'top') {
3712: my $instsrchon = ' ';
3713: my $instsrchoff = ' checked="checked" ';
3714: my ($exacton,$containson,$beginson);
3715: my $instlocalon = ' ';
3716: my $instlocaloff = ' checked="checked" ';
3717: if (ref($settings) eq 'HASH') {
3718: if ($settings->{'available'} eq '1') {
3719: $instsrchon = $instsrchoff;
3720: $instsrchoff = ' ';
3721: }
3722: if ($settings->{'localonly'} eq '1') {
3723: $instlocalon = $instlocaloff;
3724: $instlocaloff = ' ';
3725: }
3726: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3727: foreach my $type (@{$settings->{'searchtypes'}}) {
3728: if ($type eq 'exact') {
3729: $exacton = ' checked="checked" ';
3730: } elsif ($type eq 'contains') {
3731: $containson = ' checked="checked" ';
3732: } elsif ($type eq 'begins') {
3733: $beginson = ' checked="checked" ';
3734: }
3735: }
3736: } else {
3737: if ($settings->{'searchtypes'} eq 'exact') {
3738: $exacton = ' checked="checked" ';
3739: } elsif ($settings->{'searchtypes'} eq 'contains') {
3740: $containson = ' checked="checked" ';
3741: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3742: $exacton = ' checked="checked" ';
3743: $containson = ' checked="checked" ';
3744: }
3745: }
1.23 raeburn 3746: }
1.160.6.72 raeburn 3747: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3748: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3749:
1.160.6.72 raeburn 3750: my $numinrow = 4;
3751: my $cansrchrow = 0;
3752: $datatable='<tr class="LC_odd_row">'.
3753: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3754: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3755: '<input type="radio" name="dirsrch_available"'.
3756: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3757: '<label><input type="radio" name="dirsrch_available"'.
3758: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3759: '</tr><tr>'.
3760: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3761: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3762: '<input type="radio" name="dirsrch_instlocalonly"'.
3763: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3764: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3765: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3766: '</tr>';
3767: $$rowtotal += 2;
3768: if (ref($usertypes) eq 'HASH') {
3769: if (keys(%{$usertypes}) > 0) {
3770: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3771: $numinrow,$othertitle,'cansearch',
3772: $rowtotal);
1.160.6.72 raeburn 3773: $cansrchrow = 1;
3774: }
1.26 raeburn 3775: }
1.160.6.72 raeburn 3776: if ($cansrchrow) {
3777: $$rowtotal ++;
3778: $datatable .= '<tr>';
3779: } else {
3780: $datatable .= '<tr class="LC_odd_row">';
3781: }
3782: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3783: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3784: foreach my $title (@{$titleorder}) {
3785: if (defined($searchtitles->{$title})) {
3786: my $check = ' ';
3787: if (ref($settings) eq 'HASH') {
3788: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3789: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3790: $check = ' checked="checked" ';
3791: }
1.39 raeburn 3792: }
1.25 raeburn 3793: }
1.160.6.72 raeburn 3794: $datatable .= '<td class="LC_left_item">'.
3795: '<span class="LC_nobreak"><label>'.
3796: '<input type="checkbox" name="searchby" '.
3797: 'value="'.$title.'"'.$check.'/>'.
3798: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3799: }
3800: }
1.160.6.72 raeburn 3801: $datatable .= '</tr></table></td></tr>';
3802: $$rowtotal ++;
3803: if ($cansrchrow) {
3804: $datatable .= '<tr class="LC_odd_row">';
3805: } else {
3806: $datatable .= '<tr>';
3807: }
3808: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3809: '<td class="LC_left_item" colspan="2">'.
3810: '<span class="LC_nobreak"><label>'.
3811: '<input type="checkbox" name="searchtypes" '.
3812: $exacton.' value="exact" />'.&mt('Exact match').
3813: '</label> '.
3814: '<label><input type="checkbox" name="searchtypes" '.
3815: $beginson.' value="begins" />'.&mt('Begins with').
3816: '</label> '.
3817: '<label><input type="checkbox" name="searchtypes" '.
3818: $containson.' value="contains" />'.&mt('Contains').
3819: '</label></span></td></tr>';
3820: $$rowtotal ++;
1.26 raeburn 3821: } else {
1.160.6.72 raeburn 3822: my $domsrchon = ' checked="checked" ';
3823: my $domsrchoff = ' ';
3824: my $domlocalon = ' ';
3825: my $domlocaloff = ' checked="checked" ';
3826: if (ref($settings) eq 'HASH') {
3827: if ($settings->{'lclocalonly'} eq '1') {
3828: $domlocalon = $domlocaloff;
3829: $domlocaloff = ' ';
3830: }
3831: if ($settings->{'lcavailable'} eq '0') {
3832: $domsrchoff = $domsrchon;
3833: $domsrchon = ' ';
3834: }
3835: }
3836: $datatable='<tr class="LC_odd_row">'.
3837: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3838: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3839: '<input type="radio" name="dirsrch_domavailable"'.
3840: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3841: '<label><input type="radio" name="dirsrch_domavailable"'.
3842: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3843: '</tr><tr>'.
3844: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3845: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3846: '<input type="radio" name="dirsrch_domlocalonly"'.
3847: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3848: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3849: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3850: '</tr>';
3851: $$rowtotal += 2;
1.26 raeburn 3852: }
1.25 raeburn 3853: return $datatable;
3854: }
3855:
1.28 raeburn 3856: sub print_contacts {
1.160.6.78 raeburn 3857: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3858: my $datatable;
3859: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3860: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3861: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3862: if ($position eq 'top') {
3863: if (ref($settings) eq 'HASH') {
3864: foreach my $item (@contacts) {
3865: if (exists($settings->{$item})) {
3866: $to{$item} = $settings->{$item};
3867: }
1.28 raeburn 3868: }
3869: }
1.160.6.78 raeburn 3870: } elsif ($position eq 'middle') {
3871: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3872: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3873: foreach my $type (@mailings) {
1.160.6.78 raeburn 3874: $otheremails{$type} = '';
3875: }
1.160.6.107 raeburn 3876: } elsif ($position eq 'lower') {
3877: if (ref($settings) eq 'HASH') {
3878: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3879: %lonstatus = %{$settings->{'lonstatus'}};
3880: }
3881: }
1.160.6.78 raeburn 3882: } else {
3883: @mailings = ('helpdeskmail','otherdomsmail');
3884: foreach my $type (@mailings) {
3885: $otheremails{$type} = '';
3886: }
3887: $bccemails{'helpdeskmail'} = '';
3888: $bccemails{'otherdomsmail'} = '';
3889: $includestr{'helpdeskmail'} = '';
3890: $includestr{'otherdomsmail'} = '';
3891: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3892: }
3893: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3894: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3895: foreach my $type (@mailings) {
3896: if (exists($settings->{$type})) {
3897: if (ref($settings->{$type}) eq 'HASH') {
3898: foreach my $item (@contacts) {
3899: if ($settings->{$type}{$item}) {
3900: $checked{$type}{$item} = ' checked="checked" ';
3901: }
1.28 raeburn 3902: }
1.160.6.78 raeburn 3903: $otheremails{$type} = $settings->{$type}{'others'};
3904: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3905: $bccemails{$type} = $settings->{$type}{'bcc'};
3906: if ($settings->{$type}{'include'} ne '') {
3907: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3908: $includestr{$type} = &unescape($includestr{$type});
3909: }
3910: }
3911: }
3912: } elsif ($type eq 'lonstatusmail') {
3913: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3914: }
3915: }
3916: }
3917: if ($position eq 'bottom') {
3918: foreach my $type (@mailings) {
3919: $bccemails{$type} = $settings->{$type}{'bcc'};
3920: if ($settings->{$type}{'include'} ne '') {
3921: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3922: $includestr{$type} = &unescape($includestr{$type});
3923: }
3924: }
3925: if (ref($settings->{'helpform'}) eq 'HASH') {
3926: if (ref($fields) eq 'ARRAY') {
3927: foreach my $field (@{$fields}) {
3928: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3929: }
1.160.6.78 raeburn 3930: }
3931: if (exists($settings->{'helpform'}{'maxsize'})) {
3932: $maxsize = $settings->{'helpform'}{'maxsize'};
3933: } else {
3934: $maxsize = '1.0';
3935: }
3936: } else {
3937: if (ref($fields) eq 'ARRAY') {
3938: foreach my $field (@{$fields}) {
3939: $currfield{$field} = 'yes';
1.134 raeburn 3940: }
1.28 raeburn 3941: }
1.160.6.78 raeburn 3942: $maxsize = '1.0';
1.28 raeburn 3943: }
3944: }
3945: } else {
1.160.6.78 raeburn 3946: if ($position eq 'top') {
3947: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3948: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3949: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3950: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3951: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3952: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3953: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3954: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3955: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3956: } elsif ($position eq 'bottom') {
3957: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3958: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3959: if (ref($fields) eq 'ARRAY') {
3960: foreach my $field (@{$fields}) {
3961: $currfield{$field} = 'yes';
3962: }
3963: }
3964: $maxsize = '1.0';
3965: }
1.28 raeburn 3966: }
3967: my ($titles,$short_titles) = &contact_titles();
3968: my $rownum = 0;
3969: my $css_class;
1.160.6.78 raeburn 3970: if ($position eq 'top') {
3971: foreach my $item (@contacts) {
3972: $css_class = $rownum%2?' class="LC_odd_row"':'';
3973: $datatable .= '<tr'.$css_class.'>'.
3974: '<td><span class="LC_nobreak">'.$titles->{$item}.
3975: '</span></td><td class="LC_right_item">'.
3976: '<input type="text" name="'.$item.'" value="'.
3977: $to{$item}.'" /></td></tr>';
3978: $rownum ++;
3979: }
1.160.6.101 raeburn 3980: } elsif ($position eq 'bottom') {
3981: $css_class = $rownum%2?' class="LC_odd_row"':'';
3982: $datatable .= '<tr'.$css_class.'>'.
3983: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3984: &mt('(e-mail, subject, and description always shown)').
3985: '</td><td class="LC_left_item">';
3986: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3987: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3988: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3989: foreach my $field (@{$fields}) {
3990: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3991: if (($field eq 'screenshot') || ($field eq 'cc')) {
3992: $datatable .= ' '.&mt('(logged-in users)');
3993: }
3994: $datatable .='</td><td>';
3995: my $clickaction;
3996: if ($field eq 'screenshot') {
3997: $clickaction = ' onclick="screenshotSize(this);"';
3998: }
3999: if (ref($possoptions->{$field}) eq 'ARRAY') {
4000: foreach my $option (@{$possoptions->{$field}}) {
4001: my $checked;
4002: if ($currfield{$field} eq $option) {
4003: $checked = ' checked="checked"';
4004: }
4005: $datatable .= '<span class="LC_nobreak"><label>'.
4006: '<input type="radio" name="helpform_'.$field.'" '.
4007: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4008: '</label></span>'.(' 'x2);
4009: }
4010: }
4011: if ($field eq 'screenshot') {
4012: my $display;
4013: if ($currfield{$field} eq 'no') {
4014: $display = ' style="display:none"';
4015: }
4016: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4017: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4018: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4019: }
4020: $datatable .= '</td></tr>';
4021: }
4022: $datatable .= '</table>';
4023: }
4024: $datatable .= '</td></tr>'."\n";
4025: $rownum ++;
4026: }
1.160.6.107 raeburn 4027: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4028: foreach my $type (@mailings) {
4029: $css_class = $rownum%2?' class="LC_odd_row"':'';
4030: $datatable .= '<tr'.$css_class.'>'.
4031: '<td><span class="LC_nobreak">'.
4032: $titles->{$type}.': </span></td>'.
4033: '<td class="LC_left_item">';
4034: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4035: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4036: }
4037: $datatable .= '<span class="LC_nobreak">';
4038: foreach my $item (@contacts) {
4039: $datatable .= '<label>'.
4040: '<input type="checkbox" name="'.$type.'"'.
4041: $checked{$type}{$item}.
4042: ' value="'.$item.'" />'.$short_titles->{$item}.
4043: '</label> ';
4044: }
4045: $datatable .= '</span><br />'.&mt('Others').': '.
4046: '<input type="text" name="'.$type.'_others" '.
4047: 'value="'.$otheremails{$type}.'" />';
4048: my %locchecked;
4049: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4050: foreach my $loc ('s','b') {
4051: if ($includeloc{$type} eq $loc) {
4052: $locchecked{$loc} = ' checked="checked"';
4053: last;
4054: }
4055: }
4056: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4057: '<input type="text" name="'.$type.'_bcc" '.
4058: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4059: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4060: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4061: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4062: '<span class="LC_nobreak">'.&mt('Location:').' '.
4063: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4064: (' 'x2).
4065: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4066: '</span></fieldset>';
4067: }
4068: $datatable .= '</td></tr>'."\n";
4069: $rownum ++;
4070: }
1.28 raeburn 4071: }
1.160.6.78 raeburn 4072: if ($position eq 'middle') {
4073: my %choices;
1.160.6.107 raeburn 4074: my $corelink = &core_link_msu();
4075: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4076: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4077: $corelink);
4078: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4079: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4080: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4081: 'reportupdates' => 'on',
4082: 'reportstatus' => 'on');
1.160.6.78 raeburn 4083: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4084: \%choices,$rownum);
4085: $datatable .= $reports;
1.160.6.107 raeburn 4086: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4087: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4088: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4089: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4090: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4091: } else {
1.160.6.109 raeburn 4092: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4093: }
4094: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4095: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4096: } else {
1.160.6.109 raeburn 4097: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4098: }
4099: if (ref($lonstatus{'weights'}) eq 'HASH') {
4100: foreach my $type ('E','W','N','U') {
4101: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4102: $weights{$type} = $lonstatus{'weights'}{$type};
4103: } else {
4104: $weights{$type} = $defaults->{$type};
4105: }
4106: }
4107: } else {
4108: foreach my $type ('E','W','N','U') {
4109: $weights{$type} = $defaults->{$type};
4110: }
4111: }
4112: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4113: if (@{$lonstatus{'excluded'}} > 0) {
4114: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4115: }
4116: }
1.160.6.109 raeburn 4117: foreach my $item ('errorthreshold','errorsysmail') {
4118: $css_class = $rownum%2?' class="LC_odd_row"':'';
4119: $datatable .= '<tr'.$css_class.'>'.
4120: '<td class="LC_left_item"><span class="LC_nobreak">'.
4121: $titles->{$item}.
4122: '</span></td><td class="LC_left_item">'.
4123: '<input type="text" name="'.$item.'" value="'.
4124: $current{$item}.'" size="5" /></td></tr>';
4125: $rownum ++;
4126: }
1.160.6.107 raeburn 4127: $css_class = $rownum%2?' class="LC_odd_row"':'';
4128: $datatable .= '<tr'.$css_class.'>'.
4129: '<td class="LC_left_item">'.
4130: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4131: '</span></td><td class="LC_left_item"><table><tr>';
4132: foreach my $type ('E','W','N','U') {
4133: $datatable .= '<td>'.$names->{$type}.'<br />'.
4134: '<input type="text" name="errorweights_'.$type.'" value="'.
4135: $weights{$type}.'" size="5" /></td>';
4136: }
4137: $datatable .= '</tr></table></tr>';
4138: $rownum ++;
4139: $css_class = $rownum%2?' class="LC_odd_row"':'';
4140: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4141: $titles->{'errorexcluded'}.'</td>'.
4142: '<td class="LC_left_item"><table>';
4143: my $numinrow = 4;
4144: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4145: for (my $i=0; $i<@ids; $i++) {
4146: my $rem = $i%($numinrow);
4147: if ($rem == 0) {
4148: if ($i > 0) {
4149: $datatable .= '</tr>';
4150: }
4151: $datatable .= '<tr>';
4152: }
4153: my $check;
4154: if ($excluded{$ids[$i]}) {
4155: $check = ' checked="checked" ';
4156: }
4157: $datatable .= '<td class="LC_left_item">'.
4158: '<span class="LC_nobreak"><label>'.
4159: '<input type="checkbox" name="errorexcluded" '.
4160: 'value="'.$ids[$i].'"'.$check.' />'.
4161: $ids[$i].'</label></span></td>';
4162: }
4163: my $colsleft = $numinrow - @ids%($numinrow);
4164: if ($colsleft > 1 ) {
4165: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4166: ' </td>';
4167: } elsif ($colsleft == 1) {
4168: $datatable .= '<td class="LC_left_item"> </td>';
4169: }
4170: $datatable .= '</tr></table></td></tr>';
4171: $rownum ++;
1.160.6.78 raeburn 4172: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4173: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4174: my (@posstypes,%usertypeshash);
4175: if (ref($types) eq 'ARRAY') {
4176: @posstypes = @{$types};
4177: }
4178: if (@posstypes) {
4179: if (ref($usertypes) eq 'HASH') {
4180: %usertypeshash = %{$usertypes};
4181: }
4182: my @overridden;
4183: my $numinrow = 4;
4184: if (ref($settings) eq 'HASH') {
4185: if (ref($settings->{'overrides'}) eq 'HASH') {
4186: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4187: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4188: push(@overridden,$key);
4189: foreach my $item (@contacts) {
4190: if ($settings->{'overrides'}{$key}{$item}) {
4191: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4192: }
4193: }
4194: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4195: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4196: $includeloc{'override_'.$key} = '';
4197: $includestr{'override_'.$key} = '';
4198: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4199: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4200: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4201: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4202: }
1.160.6.78 raeburn 4203: }
4204: }
4205: }
1.160.6.101 raeburn 4206: }
4207: my $customclass = 'LC_helpdesk_override';
4208: my $optionsprefix = 'LC_options_helpdesk_';
4209:
4210: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4211:
4212: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4213: $numinrow,$othertitle,'overrides',
4214: \$rownum,$onclicktypes,$customclass);
4215: $rownum ++;
4216: $usertypeshash{'default'} = $othertitle;
4217: foreach my $status (@posstypes) {
4218: my $css_class;
4219: if ($rownum%2) {
4220: $css_class = 'LC_odd_row ';
4221: }
4222: $css_class .= $customclass;
4223: my $rowid = $optionsprefix.$status;
4224: my $hidden = 1;
4225: my $currstyle = 'display:none';
4226: if (grep(/^\Q$status\E$/,@overridden)) {
4227: $currstyle = 'display:table-row';
4228: $hidden = 0;
4229: }
4230: my $key = 'override_'.$status;
4231: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4232: $includeloc{$key},$includestr{$key},$status,$rowid,
4233: $usertypeshash{$status},$css_class,$currstyle,
4234: \@contacts,$short_titles);
4235: unless ($hidden) {
4236: $rownum ++;
1.160.6.78 raeburn 4237: }
4238: }
1.134 raeburn 4239: }
1.28 raeburn 4240: }
1.30 raeburn 4241: $$rowtotal += $rownum;
1.28 raeburn 4242: return $datatable;
4243: }
4244:
1.160.6.107 raeburn 4245: sub core_link_msu {
4246: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4247: &mt('LON-CAPA core group - MSU'),600,500);
4248: }
4249:
1.160.6.101 raeburn 4250: sub overridden_helpdesk {
4251: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4252: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4253: my $class = 'LC_left_item';
4254: if ($css_class) {
4255: $css_class = ' class="'.$css_class.'"';
4256: }
4257: if ($rowid) {
4258: $rowid = ' id="'.$rowid.'"';
4259: }
4260: if ($rowstyle) {
4261: $rowstyle = ' style="'.$rowstyle.'"';
4262: }
4263: my ($output,$description);
4264: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4265: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4266: "<td>$description</td>\n".
4267: '<td class="'.$class.'" colspan="2">'.
4268: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4269: '<span class="LC_nobreak">';
4270: if (ref($contacts) eq 'ARRAY') {
4271: foreach my $item (@{$contacts}) {
4272: my $check;
4273: if (ref($checked) eq 'HASH') {
4274: $check = $checked->{$item};
4275: }
4276: my $title;
4277: if (ref($short_titles) eq 'HASH') {
4278: $title = $short_titles->{$item};
4279: }
4280: $output .= '<label>'.
4281: '<input type="checkbox" name="override_'.$type.'"'.$check.
4282: ' value="'.$item.'" />'.$title.'</label> ';
4283: }
4284: }
4285: $output .= '</span><br />'.&mt('Others').': '.
4286: '<input type="text" name="override_'.$type.'_others" '.
4287: 'value="'.$otheremails.'" />';
4288: my %locchecked;
4289: foreach my $loc ('s','b') {
4290: if ($includeloc eq $loc) {
4291: $locchecked{$loc} = ' checked="checked"';
4292: last;
4293: }
4294: }
4295: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4296: '<input type="text" name="override_'.$type.'_bcc" '.
4297: 'value="'.$bccemails.'" /></fieldset>'.
4298: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4299: &mt('Text automatically added to e-mail:').' '.
4300: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4301: '<span class="LC_nobreak">'.&mt('Location:').' '.
4302: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4303: (' 'x2).
4304: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4305: '</span></fieldset>'.
4306: '</td></tr>'."\n";
4307: return $output;
4308: }
4309:
1.160.6.78 raeburn 4310: sub contacts_javascript {
4311: return <<"ENDSCRIPT";
4312:
4313: <script type="text/javascript">
4314: // <![CDATA[
4315:
4316: function screenshotSize(field) {
4317: if (document.getElementById('help_screenshotsize')) {
4318: if (field.value == 'no') {
4319: document.getElementById('help_screenshotsize').style.display="none";
4320: } else {
4321: document.getElementById('help_screenshotsize').style.display="";
4322: }
4323: }
4324: return;
4325: }
4326:
1.160.6.101 raeburn 4327: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4328: if (form.elements[checkbox].length != undefined) {
4329: var count = 0;
4330: if (docount) {
4331: for (var i=0; i<form.elements[checkbox].length; i++) {
4332: if (form.elements[checkbox][i].checked) {
4333: count ++;
4334: }
4335: }
4336: }
4337: for (var i=0; i<form.elements[checkbox].length; i++) {
4338: var type = form.elements[checkbox][i].value;
4339: if (document.getElementById(prefix+type)) {
4340: if (form.elements[checkbox][i].checked) {
4341: document.getElementById(prefix+type).style.display = 'table-row';
4342: if (count % 2 == 1) {
4343: document.getElementById(prefix+type).className = target+' LC_odd_row';
4344: } else {
4345: document.getElementById(prefix+type).className = target;
4346: }
4347: count ++;
4348: } else {
4349: document.getElementById(prefix+type).style.display = 'none';
4350: }
4351: }
4352: }
4353: }
4354: return;
4355: }
4356:
1.160.6.78 raeburn 4357: // ]]>
4358: </script>
4359:
4360: ENDSCRIPT
4361: }
4362:
1.118 jms 4363: sub print_helpsettings {
1.160.6.73 raeburn 4364: my ($position,$dom,$settings,$rowtotal) = @_;
4365: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4366: my $formname = 'display';
1.160.6.5 raeburn 4367: my ($datatable,$itemcount);
1.160.6.73 raeburn 4368: if ($position eq 'top') {
4369: $itemcount = 1;
4370: my (%choices,%defaultchecked,@toggles);
4371: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4372: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4373: &mt('LON-CAPA bug tracker'),600,500));
4374: %defaultchecked = ('submitbugs' => 'on');
4375: @toggles = ('submitbugs');
4376: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4377: \%choices,$itemcount);
4378: $$rowtotal ++;
4379: } else {
4380: my $css_class;
4381: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4382: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4383: if (ref($settings) eq 'HASH') {
4384: if (ref($settings->{'adhoc'}) eq 'HASH') {
4385: %current = %{$settings->{'adhoc'}};
4386: }
1.160.6.77 raeburn 4387: }
4388: my $count = 0;
4389: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4390: if ($key=~/^rolesdef\_(\w+)$/) {
4391: my $rolename = $1;
1.160.6.77 raeburn 4392: my (%privs,$order);
1.160.6.73 raeburn 4393: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4394: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4395: if (ref($current{$rolename}) eq 'HASH') {
4396: $order = $current{$rolename}{'order'};
4397: }
4398: if ($order eq '') {
4399: $order = $count;
4400: }
4401: $ordered{$order} = $rolename;
4402: $count++;
1.160.6.73 raeburn 4403: }
4404: }
1.160.6.77 raeburn 4405: my $maxnum = scalar(keys(%ordered));
4406: my @roles_by_num = ();
4407: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4408: push(@roles_by_num,$item);
4409: }
4410: my $context = 'domprefs';
4411: my $crstype = 'Course';
4412: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4413: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4414: my ($numstatustypes,@jsarray);
4415: if (ref($types) eq 'ARRAY') {
4416: if (@{$types} > 0) {
4417: $numstatustypes = scalar(@{$types});
4418: push(@accesstypes,'status');
4419: @jsarray = ('bystatus');
4420: }
4421: }
1.160.6.86 raeburn 4422: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4423: if (keys(%domhelpdesk)) {
4424: push(@accesstypes,('inc','exc'));
4425: push(@jsarray,('notinc','notexc'));
4426: }
4427: my $hiddenstr = join("','",@jsarray);
4428: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4429: my $context = 'domprefs';
4430: my $crstype = 'Course';
1.160.6.77 raeburn 4431: my $prefix = 'helproles_';
4432: my $add_class = 'LC_hidden';
4433: foreach my $num (@roles_by_num) {
4434: my $role = $ordered{$num};
4435: my ($desc,$access,@statuses);
4436: if (ref($current{$role}) eq 'HASH') {
4437: $desc = $current{$role}{'desc'};
4438: $access = $current{$role}{'access'};
4439: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4440: @statuses = @{$current{$role}{'insttypes'}};
4441: }
4442: }
4443: if ($desc eq '') {
4444: $desc = $role;
4445: }
4446: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4447: my %full=();
4448: my %levels= (
4449: course => {},
4450: domain => {},
4451: system => {},
4452: );
4453: my %levelscurrent=(
4454: course => {},
4455: domain => {},
4456: system => {},
4457: );
4458: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4459: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4461: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4462: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4463: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4464: for (my $k=0; $k<=$maxnum; $k++) {
4465: my $vpos = $k+1;
4466: my $selstr;
4467: if ($k == $num) {
4468: $selstr = ' selected="selected" ';
4469: }
4470: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4471: }
4472: $datatable .= '</select>'.(' 'x2).
4473: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4474: '</td>'.
4475: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4476: &mt('Name shown to users:').
4477: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4478: '</fieldset>'.
4479: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4480: $othertitle,$usertypes,$types,\%domhelpdesk).
4481: '<fieldset>'.
4482: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4483: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4484: \%levelscurrent,$identifier,
4485: 'LC_hidden',$prefix.$num.'_privs').
4486: '</fieldset></td>';
1.160.6.73 raeburn 4487: $itemcount ++;
4488: }
4489: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4490: my $newcust = 'custhelp'.$count;
4491: my (%privs,%levelscurrent);
4492: my %full=();
4493: my %levels= (
4494: course => {},
4495: domain => {},
4496: system => {},
4497: );
4498: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4499: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4500: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4501: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4502: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4503: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4504: for (my $k=0; $k<$maxnum+1; $k++) {
4505: my $vpos = $k+1;
4506: my $selstr;
4507: if ($k == $maxnum) {
4508: $selstr = ' selected="selected" ';
4509: }
4510: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4511: }
4512: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4513: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4514: '</label></span></td>'.
1.160.6.77 raeburn 4515: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4516: '<span class="LC_nobreak">'.
4517: &mt('Internal name:').
4518: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4519: '</span>'.(' 'x4).
4520: '<span class="LC_nobreak">'.
4521: &mt('Name shown to users:').
4522: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4523: '</span></fieldset>'.
4524: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4525: $usertypes,$types,\%domhelpdesk).
4526: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4527: &Apache::lonuserutils::custom_role_header($context,$crstype,
4528: \@templateroles,$newcust).
4529: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4530: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4531: '</fieldset>'.
4532: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4533: '</td></tr>';
1.160.6.73 raeburn 4534: $count ++;
4535: $$rowtotal += $count;
4536: }
1.160.6.5 raeburn 4537: return $datatable;
1.121 raeburn 4538: }
4539:
1.160.6.77 raeburn 4540: sub adhocbutton {
4541: my ($prefix,$num,$field,$visibility) = @_;
4542: my %lt = &Apache::lonlocal::texthash(
4543: show => 'Show details',
4544: hide => 'Hide details',
4545: );
4546: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4547: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4548: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4549: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4550: }
4551:
4552: sub helpsettings_javascript {
4553: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4554: return unless(ref($roles_by_num) eq 'ARRAY');
4555: my %html_js_lt = &Apache::lonlocal::texthash(
4556: show => 'Show details',
4557: hide => 'Hide details',
4558: );
4559: &html_escape(\%html_js_lt);
4560: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4561: return <<"ENDSCRIPT";
4562: <script type="text/javascript">
4563: // <![CDATA[
4564:
4565: function reorderHelpRoles(form,item) {
4566: var changedVal;
4567: $jstext
4568: var newpos = 'helproles_${total}_pos';
4569: var maxh = 1 + $total;
4570: var current = new Array();
4571: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4572: if (item == newpos) {
4573: changedVal = newitemVal;
4574: } else {
4575: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4576: current[newitemVal] = newpos;
4577: }
4578: for (var i=0; i<helproles.length; i++) {
4579: var elementName = 'helproles_'+helproles[i]+'_pos';
4580: if (elementName != item) {
4581: if (form.elements[elementName]) {
4582: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4583: current[currVal] = elementName;
4584: }
4585: }
4586: }
4587: var oldVal;
4588: for (var j=0; j<maxh; j++) {
4589: if (current[j] == undefined) {
4590: oldVal = j;
4591: }
4592: }
4593: if (oldVal < changedVal) {
4594: for (var k=oldVal+1; k<=changedVal ; k++) {
4595: var elementName = current[k];
4596: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4597: }
4598: } else {
4599: for (var k=changedVal; k<oldVal; k++) {
4600: var elementName = current[k];
4601: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4602: }
4603: }
4604: return;
4605: }
4606:
4607: function helpdeskAccess(num) {
4608: var curraccess = null;
4609: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4610: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4611: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4612: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4613: }
4614: }
4615: }
4616: var shown = Array();
4617: var hidden = Array();
4618: if (curraccess == 'none') {
4619: hidden = Array('$hiddenstr');
4620: } else {
4621: if (curraccess == 'status') {
4622: shown = Array('bystatus');
4623: hidden = Array('notinc','notexc');
4624: } else {
4625: if (curraccess == 'exc') {
4626: shown = Array('notexc');
4627: hidden = Array('notinc','bystatus');
4628: }
4629: if (curraccess == 'inc') {
4630: shown = Array('notinc');
4631: hidden = Array('notexc','bystatus');
4632: }
1.160.6.79 raeburn 4633: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4634: hidden = Array('notinc','notexc','bystatus');
4635: }
4636: }
4637: }
4638: if (hidden.length > 0) {
4639: for (var i=0; i<hidden.length; i++) {
4640: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4641: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4642: }
4643: }
4644: }
4645: if (shown.length > 0) {
4646: for (var i=0; i<shown.length; i++) {
4647: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4648: if (shown[i] == 'privs') {
4649: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4650: } else {
4651: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4652: }
4653: }
4654: }
4655: }
4656: return;
4657: }
4658:
4659: function toggleHelpdeskItem(num,field) {
4660: if (document.getElementById('helproles_'+num+'_'+field)) {
4661: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4662: document.getElementById('helproles_'+num+'_'+field).className =
4663: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4664: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4665: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4666: }
4667: } else {
4668: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4669: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4670: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4671: }
4672: }
4673: }
4674: return;
4675: }
4676:
4677: // ]]>
4678: </script>
4679:
4680: ENDSCRIPT
4681: }
4682:
4683: sub helpdeskroles_access {
4684: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4685: $usertypes,$types,$domhelpdesk) = @_;
4686: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4687: my %lt = &Apache::lonlocal::texthash(
4688: 'rou' => 'Role usage',
4689: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4690: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4691: 'dh' => 'All with domain helpdesk role',
4692: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4693: 'none' => 'None',
4694: 'status' => 'Determined based on institutional status',
4695: 'inc' => 'Include all, but exclude specific personnel',
4696: 'exc' => 'Exclude all, but include specific personnel',
4697: );
4698: my %usecheck = (
4699: all => ' checked="checked"',
4700: );
4701: my %displaydiv = (
4702: status => 'none',
4703: inc => 'none',
4704: exc => 'none',
4705: priv => 'block',
4706: );
4707: my $output;
4708: if (ref($current) eq 'HASH') {
4709: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4710: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4711: $usecheck{$current->{access}} = $usecheck{'all'};
4712: delete($usecheck{'all'});
4713: if ($current->{access} =~ /^(status|inc|exc)$/) {
4714: my $access = $1;
4715: $displaydiv{$access} = 'inline';
4716: } elsif ($current->{access} eq 'none') {
4717: $displaydiv{'priv'} = 'none';
4718: }
4719: }
4720: }
4721: }
4722: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4723: '<p>'.$lt{'whi'}.'</p>';
4724: foreach my $access (@{$accesstypes}) {
4725: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4726: ' onclick="helpdeskAccess('."'$num'".');" />'.
4727: $lt{$access}.'</label>';
4728: if ($access eq 'status') {
4729: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4730: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4731: $othertitle,$usertypes,$types).
4732: '</div>';
4733: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4734: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4735: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4736: '</div>';
4737: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4738: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4739: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4740: '</div>';
4741: }
4742: $output .= '</p>';
4743: }
4744: $output .= '</fieldset>';
4745: return $output;
4746: }
4747:
1.121 raeburn 4748: sub radiobutton_prefs {
1.160.6.16 raeburn 4749: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4750: $additional,$align,$firstval) = @_;
1.121 raeburn 4751: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4752: (ref($choices) eq 'HASH'));
4753:
4754: my (%checkedon,%checkedoff,$datatable,$css_class);
4755:
4756: foreach my $item (@{$toggles}) {
4757: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4758: $checkedon{$item} = ' checked="checked" ';
4759: $checkedoff{$item} = ' ';
1.121 raeburn 4760: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4761: $checkedoff{$item} = ' checked="checked" ';
4762: $checkedon{$item} = ' ';
4763: }
4764: }
4765: if (ref($settings) eq 'HASH') {
1.121 raeburn 4766: foreach my $item (@{$toggles}) {
1.118 jms 4767: if ($settings->{$item} eq '1') {
4768: $checkedon{$item} = ' checked="checked" ';
4769: $checkedoff{$item} = ' ';
4770: } elsif ($settings->{$item} eq '0') {
4771: $checkedoff{$item} = ' checked="checked" ';
4772: $checkedon{$item} = ' ';
4773: }
4774: }
1.121 raeburn 4775: }
1.160.6.16 raeburn 4776: if ($onclick) {
4777: $onclick = ' onclick="'.$onclick.'"';
4778: }
1.121 raeburn 4779: foreach my $item (@{$toggles}) {
1.118 jms 4780: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4781: $datatable .=
1.160.6.16 raeburn 4782: '<tr'.$css_class.'><td valign="top">'.
4783: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4784: '</span></td>';
4785: if ($align eq 'left') {
4786: $datatable .= '<td class="LC_left_item">';
4787: } else {
4788: $datatable .= '<td class="LC_right_item">';
4789: }
1.160.6.113 raeburn 4790: $datatable .= '<span class="LC_nobreak">';
4791: if ($firstval eq 'no') {
4792: $datatable .=
4793: '<label><input type="radio" name="'.
4794: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4795: '</label> <label><input type="radio" name="'.$item.'" '.
4796: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4797: } else {
4798: $datatable .=
1.118 jms 4799: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4800: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4801: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4802: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4803: }
4804: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4805: $itemcount ++;
1.121 raeburn 4806: }
4807: return ($datatable,$itemcount);
4808: }
4809:
1.160.6.118.2 1(raebur 4810:1): sub print_ltitools {
4811:1): my ($dom,$settings,$rowtotal) = @_;
4812:1): my $rownum = 0;
4813:1): my $css_class;
4814:1): my $itemcount = 1;
4815:1): my $maxnum = 0;
4816:1): my %ordered;
4817:1): if (ref($settings) eq 'HASH') {
4818:1): foreach my $item (keys(%{$settings})) {
4819:1): if (ref($settings->{$item}) eq 'HASH') {
4820:1): my $num = $settings->{$item}{'order'};
4821:1): $ordered{$num} = $item;
4822:1): }
4823:1): }
4824:1): }
4825:1): my $confname = $dom.'-domainconfig';
4826:1): my $switchserver = &check_switchserver($dom,$confname);
4827:1): my $maxnum = scalar(keys(%ordered));
4828:1): my $datatable;
4829:1): my %lt = <itools_names();
4830:1): my @courseroles = ('cc','in','ta','ep','st');
4831:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4832:1): my @fields = ('fullname','firstname','lastname','email','roles','user');
4833:1): if (keys(%ordered)) {
4834:1): my @items = sort { $a <=> $b } keys(%ordered);
4835:1): for (my $i=0; $i<@items; $i++) {
4836:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4837:1): my $item = $ordered{$items[$i]};
4838:1): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
4839:1): if (ref($settings->{$item}) eq 'HASH') {
4840:1): $title = $settings->{$item}->{'title'};
4841:1): $url = $settings->{$item}->{'url'};
4842:1): $key = $settings->{$item}->{'key'};
4843:1): $secret = $settings->{$item}->{'secret'};
4844:1): $lifetime = $settings->{$item}->{'lifetime'};
4845:1): my $image = $settings->{$item}->{'image'};
4846:1): if ($image ne '') {
4847:1): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4848:1): }
4849:1): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4850:1): $sigsel{'HMAC-256'} = ' selected="selected"';
4851:1): } else {
4852:1): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4853:1): }
4854:1): }
4855:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
4856:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4857:1): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4858:1): for (my $k=0; $k<=$maxnum; $k++) {
4859:1): my $vpos = $k+1;
4860:1): my $selstr;
4861:1): if ($k == $i) {
4862:1): $selstr = ' selected="selected" ';
4863:1): }
4864:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4865:1): }
4866:1): $datatable .= '</select>'.(' 'x2).
4867:1): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4868:1): &mt('Delete?').'</label></span></td>'.
4869:1): '<td colspan="2">'.
4870:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4871:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4872:1): (' 'x2).
4873:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4874:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4875:1): (' 'x2).
4876:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4877:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4878:1): (' 'x2).
4879:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4880:1): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4881:1): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4882:1): '<br /><br />'.
4883:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4884:1): ' value="'.$url.'" /></span>'.
4885:1): (' 'x2).
4886:1): '<span class="LC_nobreak">'.$lt{'key'}.':'.
4887:1): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4888:1): (' 'x2).
4889:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4890:1): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4891:1): (' 'x2).
4892:1): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4893:1): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4894:1): '<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>'.
4895:1): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4896:1): '</fieldset>'.
4897:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4898:1): '<span class="LC_nobreak">'.&mt('Display target:');
4899:1): my %currdisp;
4900:1): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4901:1): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4902:1): $currdisp{'window'} = ' checked="checked"';
4903:1): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4904:1): $currdisp{'tab'} = ' checked="checked"';
4905:1): } else {
4906:1): $currdisp{'iframe'} = ' checked="checked"';
4907:1): }
4908:1): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4909:1): $currdisp{'width'} = $1;
4910:1): }
4911:1): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4912:1): $currdisp{'height'} = $1;
4913:1): }
4914:1): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4915:1): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4916:1): } else {
4917:1): $currdisp{'iframe'} = ' checked="checked"';
4918:1): }
4919:1): foreach my $disp ('iframe','tab','window') {
4920:1): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4921:1): $lt{$disp}.'</label>'.(' 'x2);
4922:1): }
4923:1): $datatable .= (' 'x4);
4924:1): foreach my $dimen ('width','height') {
4925:1): $datatable .= '<label>'.$lt{$dimen}.' '.
4926:1): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4927:1): (' 'x2);
4928:1): }
4929:1): $datatable .= '</span><br />'.
4930:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4931:1): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4932:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4933:1): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4934:1): '</textarea></div><div style=""></div>'.
4935:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4936:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4937:1): if ($imgsrc) {
4938:1): $datatable .= $imgsrc.
4939:1): '<label><input type="checkbox" name="ltitools_image_del"'.
4940:1): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4941:1): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4942:1): } else {
4943:1): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4944:1): }
4945:1): if ($switchserver) {
4946:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4947:1): } else {
4948:1): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4949:1): }
4950:1): $datatable .= '</span></fieldset>';
4951:1): my (%checkedfields,%rolemaps,$userincdom);
4952:1): if (ref($settings->{$item}) eq 'HASH') {
4953:1): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4954:1): %checkedfields = %{$settings->{$item}->{'fields'}};
4955:1): }
4956:1): $userincdom = $settings->{$item}->{'incdom'};
4957:1): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4958:1): %rolemaps = %{$settings->{$item}->{'roles'}};
4959:1): $checkedfields{'roles'} = 1;
4960:1): }
4961:1): }
4962:1): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4963:1): '<span class="LC_nobreak">';
4964:1): my $userfieldstyle = 'display:none;';
4965:1): my $seluserdom = '';
4966:1): my $unseluserdom = ' selected="selected"';
4967:1): foreach my $field (@fields) {
4968:1): my ($checked,$onclick,$id,$spacer);
4969:1): if ($checkedfields{$field}) {
4970:1): $checked = ' checked="checked"';
4971:1): }
4972:1): if ($field eq 'user') {
4973:1): $id = ' id="ltitools_user_field_'.$i.'"';
4974:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4975:1): if ($checked) {
4976:1): $userfieldstyle = 'display:inline-block';
4977:1): if ($userincdom) {
4978:1): $seluserdom = $unseluserdom;
4979:1): $unseluserdom = '';
4980:1): }
4981:1): }
4982:1): } else {
4983:1): $spacer = (' ' x2);
4984:1): }
4985:1): $datatable .= '<label>'.
4986:1): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4987:1): $lt{$field}.'</label>'.$spacer;
4988:1): }
4989:1): $datatable .= '</span>';
4990:1): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4991:1): '<span class="LC_nobreak"> : '.
4992:1): '<select name="ltitools_userincdom_'.$i.'">'.
4993:1): '<option value="">'.&mt('Select').'</option>'.
4994:1): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4995:1): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4996:1): '</select></span></div>';
4997:1): $datatable .= '</fieldset>'.
4998:1): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4999:1): foreach my $role (@courseroles) {
5000:1): my ($selected,$selectnone);
5001:1): if (!$rolemaps{$role}) {
5002:1): $selectnone = ' selected="selected"';
5003:1): }
5004:1): $datatable .= '<td align="center">'.
5005:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5006:1): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5007:1): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5008:1): foreach my $ltirole (@ltiroles) {
5009:1): unless ($selectnone) {
5010:1): if ($rolemaps{$role} eq $ltirole) {
5011:1): $selected = ' selected="selected"';
5012:1): } else {
5013:1): $selected = '';
5014:1): }
5015:1): }
5016:1): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5017:1): }
5018:1): $datatable .= '</select></td>';
5019:1): }
5020:1): $datatable .= '</tr></table></fieldset>';
5021:1): my %courseconfig;
5022:1): if (ref($settings->{$item}) eq 'HASH') {
5023:1): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5024:1): %courseconfig = %{$settings->{$item}->{'crsconf'}};
5025:1): }
5026:1): }
5027:1): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5028:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5029:1): my $checked;
5030:1): if ($courseconfig{$item}) {
5031:1): $checked = ' checked="checked"';
5032:1): }
5033:1): $datatable .= '<label>'.
5034:1): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
5035:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5036:1): }
5037:1): $datatable .= '</span></fieldset>'.
5038:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5039:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5040:1): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5041:1): my %custom = %{$settings->{$item}->{'custom'}};
5042:1): if (keys(%custom) > 0) {
5043:1): foreach my $key (sort(keys(%custom))) {
5044:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5045:1): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5046:1): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5047:1): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5048:1): ' value="'.$custom{$key}.'" /></td></tr>';
5049:1): }
5050:1): }
5051:1): }
5052:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5053:1): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5054:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5055:1): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5056:1): $datatable .= '</table></fieldset></td></tr>'."\n";
5057:1): $itemcount ++;
5058:1): }
5059:1): }
5060:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5061:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
5062:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5063:1): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5064:1): '<select name="ltitools_add_pos"'.$chgstr.'>';
5065:1): for (my $k=0; $k<$maxnum+1; $k++) {
5066:1): my $vpos = $k+1;
5067:1): my $selstr;
5068:1): if ($k == $maxnum) {
5069:1): $selstr = ' selected="selected" ';
5070:1): }
5071:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5072:1): }
5073:1): $datatable .= '</select> '."\n".
5074:1): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5075:1): '<td colspan="2">'.
5076:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5077:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
5078:1): (' 'x2).
5079:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5080:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5081:1): (' 'x2).
5082:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5083:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5084:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5085:1): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5086:1): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5087:1): '<br />'.
5088:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
5089:1): (' 'x2).
5090:1): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5091:1): (' 'x2).
5092:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5093:1): (' 'x2).
5094:1): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5095:1): '<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".
5096:1): '</fieldset>'.
5097:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5098:1): '<span class="LC_nobreak">'.&mt('Display target:');
5099:1): my %defaultdisp;
5100:1): $defaultdisp{'iframe'} = ' checked="checked"';
5101:1): foreach my $disp ('iframe','tab','window') {
5102:1): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5103:1): $lt{$disp}.'</label>'.(' 'x2);
5104:1): }
5105:1): $datatable .= (' 'x4);
5106:1): foreach my $dimen ('width','height') {
5107:1): $datatable .= '<label>'.$lt{$dimen}.' '.
5108:1): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5109:1): (' 'x2);
5110:1): }
5111:1): $datatable .= '</span><br />'.
5112:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5113:1): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
5114:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5115:1): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
5116:1): '</div><div style=""></div>'.
5117:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
5118:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
5119:1): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5120:1): if ($switchserver) {
5121:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5122:1): } else {
5123:1): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5124:1): }
5125:1): $datatable .= '</span></fieldset>'.
5126:1): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5127:1): '<span class="LC_nobreak">';
5128:1): foreach my $field (@fields) {
5129:1): my ($id,$onclick,$spacer);
5130:1): if ($field eq 'user') {
5131:1): $id = ' id="ltitools_user_field_add"';
5132:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5133:1): } else {
5134:1): $spacer = (' ' x2);
5135:1): }
5136:1): $datatable .= '<label>'.
5137:1): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5138:1): $lt{$field}.'</label>'.$spacer;
5139:1): }
5140:1): $datatable .= '</span>'.
5141:1): '<div style="display:none;" id="ltitools_user_div_add">'.
5142:1): '<span class="LC_nobreak"> : '.
5143:1): '<select name="ltitools_userincdom_add">'.
5144:1): '<option value="" selected="selected">'.&mt('Select').'</option>'.
5145:1): '<option value="0">'.&mt('username').'</option>'.
5146:1): '<option value="1">'.&mt('username:domain').'</option>'.
5147:1): '</select></span></div></fieldset>';
5148:1): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5149:1): foreach my $role (@courseroles) {
5150:1): my ($checked,$checkednone);
5151:1): $datatable .= '<td align="center">'.
5152:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5153:1): '<select name="ltitools_add_roles_'.$role.'">'.
5154:1): '<option value="" selected="selected">'.&mt('Select').'</option>';
5155:1): foreach my $ltirole (@ltiroles) {
5156:1): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5157:1): }
5158:1): $datatable .= '</select></td>';
5159:1): }
5160:1): $datatable .= '</tr></table></fieldset>'.
5161:1): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5162:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5163:1): $datatable .= '<label>'.
5164:1): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5165:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5166:1): }
5167:1): $datatable .= '</span></fieldset>'.
5168:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5169:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5170:1): '<tr><td><span class="LC_nobreak">'.
5171:1): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5172:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5173:1): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5174:1): '</table></fieldset>'."\n".
5175:1): '</td>'."\n".
5176:1): '</tr>'."\n";
5177:1): $itemcount ++;
5178:1): return $datatable;
5179:1): }
5180:1):
5181:1): sub ltitools_names {
5182:1): my %lt = &Apache::lonlocal::texthash(
5183:1): 'title' => 'Title',
5184:1): 'version' => 'Version',
5185:1): 'msgtype' => 'Message Type',
5186:1): 'sigmethod' => 'Signature Method',
5187:1): 'url' => 'URL',
5188:1): 'key' => 'Key',
5189:1): 'lifetime' => 'Nonce lifetime (s)',
5190:1): 'secret' => 'Secret',
5191:1): 'icon' => 'Icon',
5192:1): 'user' => 'User',
5193:1): 'fullname' => 'Full Name',
5194:1): 'firstname' => 'First Name',
5195:1): 'lastname' => 'Last Name',
5196:1): 'email' => 'E-mail',
5197:1): 'roles' => 'Role',
5198:1): 'window' => 'Window',
5199:1): 'tab' => 'Tab',
5200:1): 'iframe' => 'iFrame',
5201:1): 'height' => 'Height',
5202:1): 'width' => 'Width',
5203:1): 'linktext' => 'Default Link Text',
5204:1): 'explanation' => 'Default Explanation',
5205:1): 'crstarget' => 'Display target',
5206:1): 'crslabel' => 'Course label',
5207:1): 'crstitle' => 'Course title',
5208:1): 'crslinktext' => 'Link Text',
5209:1): 'crsexplanation' => 'Explanation',
5210:1): 'crsappend' => 'Provider URL',
5211:1): );
5212:1):
5213:1): return %lt;
5214:1): }
5215:1):
5(raebur 5216:2): sub print_lti {
5217:2): my ($position,$dom,$settings,$rowtotal) = @_;
5218:2): my $itemcount = 1;
5219:2): my ($datatable,$css_class);
5220:2): my (%rules,%encrypt,%privkeys,%linkprot);
5221:2): if (ref($settings) eq 'HASH') {
5222:2): if ($position eq 'top') {
5223:2): if (exists($settings->{'encrypt'})) {
5224:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5225:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5226:2): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5227:2): }
5228:2): }
5229:2): }
5230:2): if (exists($settings->{'private'})) {
5231:2): if (ref($settings->{'private'}) eq 'HASH') {
5232:2): if (ref($settings->{'private'}) eq 'HASH') {
5233:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5234:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5235:2): }
5236:2): }
5237:2): }
5238:2): }
5239:2): } elsif ($position eq 'middle') {
5240:2): if (exists($settings->{'rules'})) {
5241:2): if (ref($settings->{'rules'}) eq 'HASH') {
5242:2): %rules = %{$settings->{'rules'}};
5243:2): }
5244:2): }
5245:2): } elsif ($position eq 'bottom') {
5246:2): if (exists($settings->{'linkprot'})) {
5247:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5248:2): %linkprot = %{$settings->{'linkprot'}};
5249:2): if ($linkprot{'lock'}) {
5250:2): delete($linkprot{'lock'});
5251:2): }
5252:2): }
5253:2): }
5254:2): }
5255:2): }
5256:2): if ($position eq 'top') {
5257:2): my @ids=&Apache::lonnet::current_machine_ids();
5258:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
5259:2): my $primary = &Apache::lonnet::domain($dom,'primary');
5260:2): my ($extra,$numshown);
5261:2): foreach my $hostid (sort(keys(%servers))) {
5262:2): my ($showextra,$divsty,$switch);
5263:2): if ($hostid eq $primary) {
5264:2): if ($encrypt{'ltisec_domlinkprot'}) {
5265:2): $showextra = 1;
5266:2): }
5267:2): }
5268:2): if ($encrypt{'ltisec_crslinkprot'}) {
5269:2): $showextra = 1;
5270:2): }
5271:2): unless (grep(/^\Q$hostid\E$/,@ids)) {
5272:2): $switch = 1;
5273:2): }
5274:2): if ($showextra) {
5275:2): $numshown ++;
5276:2): $divsty = 'display:inline-block';
5277:2): } else {
5278:2): $divsty = 'display:none';
5279:2): }
5280:2): $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
5281:2): '<legend>'.$hostid.'</legend>';
5282:2): if ($switch) {
5283:2): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5284:2): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5285:2): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5286:2): if (exists($privkeys{$hostid})) {
5287:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5288:2): '<span class="LC_nobreak">'.
5289:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5290:2): '<span class="LC_nobreak">'.&mt('Change?').
5291:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5292:2): (' 'x2).
5293:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5294:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5295:2): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5296:2): '</span></div>';
5297:2): } else {
5298:2): $extra .= '<span class="LC_nobreak">'.
5299:2): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5300:2): '</span>'."\n";
5301:2): }
5302:2): } elsif (exists($privkeys{$hostid})) {
5303:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5304:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5305:2): '<span class="LC_nobreak">'.&mt('Change?').
5306:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5307:2): (' 'x2).
5308:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5309:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5310:2): '<span class="LC_nobreak">'.&mt('New Key').':'.
5311:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5312:2): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5313:2): '</span></div>';
5314:2): } else {
5315:2): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5316:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5317:2): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5318:2): }
5319:2): $extra .= '</fieldset>';
5320:2): }
5321:2): my %choices = &Apache::lonlocal::texthash (
5322:2): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5323:2): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5324:2): );
5325:2): my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot);
5326:2): my %defaultchecked = (
5327:2): 'ltisec_crslinkprot' => 'off',
5328:2): 'ltisec_domlinkprot' => 'off',
5329:2): );
5330:2): my ($onclick,$itemcount);
5331:2): $onclick = 'javascript:toggleLTIEncKey(this.form);';
5332:2): ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
5333:2): \%choices,$itemcount,$onclick,'','left','no');
5334:2):
5335:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5336:2): my $noprivkeysty = 'display:inline-block';
5337:2): if ($numshown) {
5338:2): $noprivkeysty = 'display:none';
5339:2): }
5340:2): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5341:2): '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
5342:2): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5343:2): $extra.
5344:2): '</td></tr>';
5345:2): $itemcount ++;
5346:2): $$rowtotal += $itemcount;
5347:2): } elsif ($position eq 'middle') {
5348:2): $datatable = &password_rules('secrets',\$itemcount,\%rules);
5349:2): $$rowtotal += $itemcount;
5350:2): } elsif ($position eq 'bottom') {
5351:2): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5352:2): }
5353:2): return $datatable;
5354:2): }
5355:2):
1.121 raeburn 5356: sub print_coursedefaults {
1.139 raeburn 5357: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5358: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5359: my $itemcount = 1;
1.160.6.16 raeburn 5360: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5361: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 5362: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5363: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5364: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5365: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5366: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5367: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5368: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5369: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5370: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 5371: );
1.160.6.118.2 5(raebur 5372:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.160.6.21 raeburn 5373: my %staticdefaults = (
5374: anonsurvey_threshold => 10,
5375: uploadquota => 500,
1.160.6.57 raeburn 5376: postsubmit => 60,
1.160.6.70 raeburn 5377: mysqltables => 172800,
1.160.6.21 raeburn 5378: );
1.139 raeburn 5379: if ($position eq 'top') {
1.160.6.57 raeburn 5380: %defaultchecked = (
5381: 'uselcmath' => 'on',
5382: 'usejsme' => 'on',
1.160.6.115 raeburn 5383: 'inline_chem' => 'on',
1.160.6.64 raeburn 5384: 'canclone' => 'none',
1.160.6.57 raeburn 5385: );
1.160.6.115 raeburn 5386: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5387: my $deftex = $Apache::lonnet::deftex;
5388: if (ref($settings) eq 'HASH') {
5389: if ($settings->{'texengine'}) {
5390: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5391: $deftex = $settings->{'texengine'};
5392: }
5393: }
5394: }
5395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5396: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5397: '<span class="LC_nobreak">'.$choices{'texengine'}.
5398: '</span></td><td class="LC_right_item">'.
5399: '<select name="texengine">'."\n";
5400: my %texoptions = (
5401: MathJax => 'MathJax',
5402: mimetex => &mt('Convert to Images'),
5403: tth => &mt('TeX to HTML'),
5404: );
5405: foreach my $renderer ('MathJax','mimetex','tth') {
5406: my $selected = '';
5407: if ($renderer eq $deftex) {
5408: $selected = ' selected="selected"';
5409: }
5410: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5411: }
5412: $mathdisp .= '</select></td></tr>'."\n";
5413: $itemcount ++;
1.139 raeburn 5414: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5415: \%choices,$itemcount);
1.160.6.90 raeburn 5416: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5418: $datatable .=
5419: '<tr'.$css_class.'><td valign="top">'.
5420: '<span class="LC_nobreak">'.$choices{'canclone'}.
5421: '</span></td><td class="LC_left_item">';
5422: my $currcanclone = 'none';
5423: my $onclick;
5424: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5425: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5426: none => 'No additional course requesters',
5427: domain => "Any course requester in course's domain",
5428: instcode => 'Course requests for official courses ...',
5429: );
5430: my (%codedefaults,@code_order,@posscodes);
5431: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5432: \@code_order) eq 'ok') {
5433: if (@code_order > 0) {
5434: push(@cloneoptions,'instcode');
5435: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5436: }
5437: }
5438: if (ref($settings) eq 'HASH') {
5439: if ($settings->{'canclone'}) {
5440: if (ref($settings->{'canclone'}) eq 'HASH') {
5441: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5442: if (@code_order > 0) {
5443: $currcanclone = 'instcode';
5444: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5445: }
5446: }
5447: } elsif ($settings->{'canclone'} eq 'domain') {
5448: $currcanclone = $settings->{'canclone'};
5449: }
5450: }
5451: }
5452: foreach my $option (@cloneoptions) {
5453: my ($checked,$additional);
5454: if ($currcanclone eq $option) {
5455: $checked = ' checked="checked"';
5456: }
5457: if ($option eq 'instcode') {
5458: if (@code_order) {
5459: my $show = 'none';
5460: if ($checked) {
5461: $show = 'block';
5462: }
5463: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5464: &mt('Institutional codes for new and cloned course have identical:').
5465: '<br />';
5466: foreach my $item (@code_order) {
5467: my $codechk;
5468: if ($checked) {
5469: if (grep(/^\Q$item\E$/,@posscodes)) {
5470: $codechk = ' checked="checked"';
5471: }
5472: }
5473: $additional .= '<label>'.
5474: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5475: $item.'</label>';
5476: }
5477: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5478: }
5479: }
5480: $datatable .=
5481: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5482: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5483: '</label> '.$additional.'</span><br />';
5484: }
5485: $datatable .= '</td>'.
5486: '</tr>';
5487: $itemcount ++;
1.139 raeburn 5488: } else {
5489: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 5490: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 5491: my $currusecredits = 0;
1.160.6.57 raeburn 5492: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 5493:2): my $ltiauth = 0;
1.160.6.30 raeburn 5494: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 5495: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 5496:2): if ($settings->{'ltiauth'}) {
5497:2): $ltiauth = 1;
5498:2): }
1.139 raeburn 5499: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 5500: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5501: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5502: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5503: }
5504: }
1.160.6.16 raeburn 5505: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 5506: foreach my $type (@types) {
5507: next if ($type eq 'community');
5508: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5509: if ($defcredits{$type} ne '') {
5510: $currusecredits = 1;
5511: }
5512: }
5513: }
5514: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5515: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5516: $postsubmitclient = 0;
5517: foreach my $type (@types) {
5518: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5519: }
5520: } else {
5521: foreach my $type (@types) {
5522: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5523: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5524: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5525: } else {
5526: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5527: }
5528: } else {
5529: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5530: }
5531: }
5532: }
5533: } else {
5534: foreach my $type (@types) {
5535: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 5536: }
5537: }
1.160.6.70 raeburn 5538: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5539: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5540: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5541: }
5542: } else {
5543: foreach my $type (@types) {
5544: $currmysql{$type} = $staticdefaults{'mysqltables'};
5545: }
5546: }
1.160.6.58 raeburn 5547: } else {
5548: foreach my $type (@types) {
5549: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5550: }
1.139 raeburn 5551: }
5552: if (!$currdefresponder) {
1.160.6.21 raeburn 5553: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5554: } elsif ($currdefresponder < 1) {
5555: $currdefresponder = 1;
5556: }
1.160.6.21 raeburn 5557: foreach my $type (@types) {
5558: if ($curruploadquota{$type} eq '') {
5559: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5560: }
5561: }
1.139 raeburn 5562: $datatable .=
1.160.6.16 raeburn 5563: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5564: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5565: '</span></td>'.
5566: '<td class="LC_right_item"><span class="LC_nobreak">'.
5567: '<input type="text" name="anonsurvey_threshold"'.
5568: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 5569: '</td></tr>'."\n";
5570: $itemcount ++;
5571: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5572: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5573: $choices{'uploadquota'}.
5574: '</span></td>'.
5575: '<td align="right" class="LC_right_item">'.
5576: '<table><tr>';
1.160.6.21 raeburn 5577: foreach my $type (@types) {
5578: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5579: '<input type="text" name="uploadquota_'.$type.'"'.
5580: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5581: }
5582: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 5583: $itemcount ++;
1.160.6.40 raeburn 5584: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 5585: my $display = 'none';
5586: if ($currusecredits) {
5587: $display = 'block';
5588: }
5589: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 5590: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5591: foreach my $type (@types) {
5592: next if ($type eq 'community');
5593: $additional .= '<td align="center">'.&mt($type).'<br />'.
5594: '<input type="text" name="'.$type.'_credits"'.
5595: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5596: }
5597: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 5598: %defaultchecked = ('coursecredits' => 'off');
5599: @toggles = ('coursecredits');
5600: my $current = {
5601: 'coursecredits' => $currusecredits,
5602: };
5603: (my $table,$itemcount) =
5604: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5605: \%choices,$itemcount,$onclick,$additional,'left');
5606: $datatable .= $table;
5607: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5608: my $display = 'none';
5609: if ($postsubmitclient) {
5610: $display = 'block';
5611: }
5612: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 5613: &mt('Number of seconds submit is disabled').'<br />'.
5614: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5615: '<table><tr>';
1.160.6.57 raeburn 5616: foreach my $type (@types) {
5617: $additional .= '<td align="center">'.&mt($type).'<br />'.
5618: '<input type="text" name="'.$type.'_timeout" value="'.
5619: $deftimeout{$type}.'" size="5" /></td>';
5620: }
5621: $additional .= '</tr></table></div>'."\n";
5622: %defaultchecked = ('postsubmit' => 'on');
5623: @toggles = ('postsubmit');
1.160.6.70 raeburn 5624: $current = {
5625: 'postsubmit' => $postsubmitclient,
5626: };
1.160.6.57 raeburn 5627: ($table,$itemcount) =
5628: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5629: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 5630: $datatable .= $table;
1.160.6.70 raeburn 5631: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5632: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5633: $choices{'mysqltables'}.
5634: '</span></td>'.
5635: '<td align="right" class="LC_right_item">'.
5636: '<table><tr>';
5637: foreach my $type (@types) {
5638: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5639: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 5640: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 5641: }
5642: $datatable .= '</tr></table></td></tr>'."\n";
5643: $itemcount ++;
1.160.6.118.2 4(raebur 5644:2): %defaultchecked = ('ltiauth' => 'off');
5645:2): @toggles = ('ltiauth');
5646:2): $current = {
5647:2): 'ltiauth' => $ltiauth,
5648:2): };
5649:2): ($table,$itemcount) =
5650:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5651:2): \%choices,$itemcount,undef,undef,'left');
5652:2): $datatable .= $table;
5653:2): $itemcount ++;
1.160.6.37 raeburn 5654: }
5655: $$rowtotal += $itemcount;
5656: return $datatable;
5657: }
5658:
5659: sub print_selfenrollment {
5660: my ($position,$dom,$settings,$rowtotal) = @_;
5661: my ($css_class,$datatable);
5662: my $itemcount = 1;
5663: my @types = ('official','unofficial','community','textbook');
5664: if (($position eq 'top') || ($position eq 'middle')) {
5665: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5666: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5667: my @rows;
5668: my $key;
5669: if ($position eq 'top') {
5670: $key = 'admin';
5671: if (ref($rowsref) eq 'ARRAY') {
5672: @rows = @{$rowsref};
5673: }
5674: } elsif ($position eq 'middle') {
5675: $key = 'default';
5676: @rows = ('types','registered','approval','limit');
5677: }
5678: foreach my $row (@rows) {
5679: if (defined($titlesref->{$row})) {
5680: $itemcount ++;
5681: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5682: $datatable .= '<tr'.$css_class.'>'.
5683: '<td>'.$titlesref->{$row}.'</td>'.
5684: '<td class="LC_left_item">'.
5685: '<table><tr>';
5686: my (%current,%currentcap);
5687: if (ref($settings) eq 'HASH') {
5688: if (ref($settings->{$key}) eq 'HASH') {
5689: foreach my $type (@types) {
5690: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5691: $current{$type} = $settings->{$key}->{$type}->{$row};
5692: }
5693: if (($row eq 'limit') && ($key eq 'default')) {
5694: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5695: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5696: }
5697: }
5698: }
5699: }
5700: }
5701: my %roles = (
5702: '0' => &Apache::lonnet::plaintext('dc'),
5703: );
5704:
5705: foreach my $type (@types) {
5706: unless (($row eq 'registered') && ($key eq 'default')) {
5707: $datatable .= '<th>'.&mt($type).'</th>';
5708: }
5709: }
5710: unless (($row eq 'registered') && ($key eq 'default')) {
5711: $datatable .= '</tr><tr>';
5712: }
5713: foreach my $type (@types) {
5714: if ($type eq 'community') {
5715: $roles{'1'} = &mt('Community personnel');
5716: } else {
5717: $roles{'1'} = &mt('Course personnel');
5718: }
5719: $datatable .= '<td style="vertical-align: top">';
5720: if ($position eq 'top') {
5721: my %checked;
5722: if ($current{$type} eq '0') {
5723: $checked{'0'} = ' checked="checked"';
5724: } else {
5725: $checked{'1'} = ' checked="checked"';
5726: }
5727: foreach my $role ('1','0') {
5728: $datatable .= '<span class="LC_nobreak"><label>'.
5729: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5730: 'value="'.$role.'"'.$checked{$role}.' />'.
5731: $roles{$role}.'</label></span> ';
5732: }
5733: } else {
5734: if ($row eq 'types') {
5735: my %checked;
5736: if ($current{$type} =~ /^(all|dom)$/) {
5737: $checked{$1} = ' checked="checked"';
5738: } else {
5739: $checked{''} = ' checked="checked"';
5740: }
5741: foreach my $val ('','dom','all') {
5742: $datatable .= '<span class="LC_nobreak"><label>'.
5743: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5744: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5745: }
5746: } elsif ($row eq 'registered') {
5747: my %checked;
5748: if ($current{$type} eq '1') {
5749: $checked{'1'} = ' checked="checked"';
5750: } else {
5751: $checked{'0'} = ' checked="checked"';
5752: }
5753: foreach my $val ('0','1') {
5754: $datatable .= '<span class="LC_nobreak"><label>'.
5755: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5756: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5757: }
5758: } elsif ($row eq 'approval') {
5759: my %checked;
5760: if ($current{$type} =~ /^([12])$/) {
5761: $checked{$1} = ' checked="checked"';
5762: } else {
5763: $checked{'0'} = ' checked="checked"';
5764: }
5765: for my $val (0..2) {
5766: $datatable .= '<span class="LC_nobreak"><label>'.
5767: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5768: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5769: }
5770: } elsif ($row eq 'limit') {
5771: my %checked;
5772: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5773: $checked{$1} = ' checked="checked"';
5774: } else {
5775: $checked{'none'} = ' checked="checked"';
5776: }
5777: my $cap;
5778: if ($currentcap{$type} =~ /^\d+$/) {
5779: $cap = $currentcap{$type};
5780: }
5781: foreach my $val ('none','allstudents','selfenrolled') {
5782: $datatable .= '<span class="LC_nobreak"><label>'.
5783: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5784: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5785: }
5786: $datatable .= '<br />'.
5787: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5788: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5789: '</span>';
5790: }
5791: }
5792: $datatable .= '</td>';
5793: }
5794: $datatable .= '</tr>';
5795: }
5796: $datatable .= '</table></td></tr>';
5797: }
5798: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 5799: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5800: }
5801: $$rowtotal += $itemcount;
5802: return $datatable;
5803: }
5804:
5805: sub print_validation_rows {
5806: my ($caller,$dom,$settings,$rowtotal) = @_;
5807: my ($itemsref,$namesref,$fieldsref);
5808: if ($caller eq 'selfenroll') {
5809: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5810: } elsif ($caller eq 'requestcourses') {
5811: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5812: }
5813: my %currvalidation;
5814: if (ref($settings) eq 'HASH') {
5815: if (ref($settings->{'validation'}) eq 'HASH') {
5816: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 5817: }
1.160.6.39 raeburn 5818: }
5819: my $datatable;
5820: my $itemcount = 0;
5821: foreach my $item (@{$itemsref}) {
5822: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5823: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5824: $namesref->{$item}.
5825: '</span></td>'.
5826: '<td class="LC_left_item">';
5827: if (($item eq 'url') || ($item eq 'button')) {
5828: $datatable .= '<span class="LC_nobreak">'.
5829: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5830: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5831: } elsif ($item eq 'fields') {
5832: my @currfields;
5833: if (ref($currvalidation{$item}) eq 'ARRAY') {
5834: @currfields = @{$currvalidation{$item}};
5835: }
5836: foreach my $field (@{$fieldsref}) {
5837: my $check = '';
5838: if (grep(/^\Q$field\E$/,@currfields)) {
5839: $check = ' checked="checked"';
5840: }
5841: $datatable .= '<span class="LC_nobreak"><label>'.
5842: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5843: ' value="'.$field.'"'.$check.' />'.$field.
5844: '</label></span> ';
5845: }
5846: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 5847: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 5848: $currvalidation{$item}.
1.160.6.37 raeburn 5849: '</textarea>';
1.160.6.39 raeburn 5850: }
5851: $datatable .= '</td></tr>'."\n";
5852: if (ref($rowtotal)) {
1.160.6.37 raeburn 5853: $itemcount ++;
5854: }
1.139 raeburn 5855: }
1.160.6.39 raeburn 5856: if ($caller eq 'requestcourses') {
5857: my %currhash;
1.160.6.51 raeburn 5858: if (ref($settings) eq 'HASH') {
5859: if (ref($settings->{'validation'}) eq 'HASH') {
5860: if ($settings->{'validation'}{'dc'} ne '') {
5861: $currhash{$settings->{'validation'}{'dc'}} = 1;
5862: }
1.160.6.39 raeburn 5863: }
5864: }
5865: my $numinrow = 2;
5866: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5867: 'validationdc',%currhash);
1.160.6.50 raeburn 5868: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5869: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5870: if ($numdc > 1) {
1.160.6.50 raeburn 5871: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5872: } else {
1.160.6.50 raeburn 5873: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5874: }
1.160.6.50 raeburn 5875: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5876: $itemcount ++;
5877: }
5878: if (ref($rowtotal)) {
5879: $$rowtotal += $itemcount;
5880: }
1.121 raeburn 5881: return $datatable;
1.118 jms 5882: }
5883:
1.160.6.98 raeburn 5884: sub print_passwords {
5885: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5886: my ($datatable,$css_class);
5887: my $itemcount = 0;
5888: my %titles = &Apache::lonlocal::texthash (
5889: captcha => '"Forgot Password" CAPTCHA validation',
5890: link => 'Reset link expiration (hours)',
5891: case => 'Case-sensitive usernames/e-mail',
5892: prelink => 'Information required (form 1)',
5893: postlink => 'Information required (form 2)',
5894: emailsrc => 'LON-CAPA e-mail address type(s)',
5895: customtext => 'Domain specific text (HTML)',
5896: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5897: intauth_check => 'Check bcrypt cost if authenticated',
5898: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5899: permanent => 'Permanent e-mail address',
5900: critical => 'Critical notification address',
5901: notify => 'Notification address',
5902: min => 'Minimum password length',
5903: max => 'Maximum password length',
5904: chars => 'Required characters',
5905: numsaved => 'Number of previous passwords to save and disallow reuse',
5906: );
5907: if ($position eq 'top') {
5908: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5909: my $shownlinklife = 2;
5910: my $prelink = 'both';
5911: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5912: if (ref($settings) eq 'HASH') {
5913: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5914: $shownlinklife = $settings->{resetlink};
5915: }
5916: if (ref($settings->{resetcase}) eq 'ARRAY') {
5917: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5918: }
5919: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5920: $prelink = $settings->{resetprelink};
5921: }
5922: if (ref($settings->{resetpostlink}) eq 'HASH') {
5923: %postlink = %{$settings->{resetpostlink}};
5924: }
5925: if (ref($settings->{resetemail}) eq 'ARRAY') {
5926: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5927: }
5928: if ($settings->{resetremove}) {
5929: $nostdtext = 1;
5930: }
5931: if ($settings->{resetcustom}) {
5932: $customurl = $settings->{resetcustom};
5933: }
5934: } else {
5935: if (ref($types) eq 'ARRAY') {
5936: foreach my $item (@{$types}) {
5937: $casesens{$item} = 1;
5938: $postlink{$item} = ['username','email'];
5939: }
5940: }
5941: $casesens{'default'} = 1;
5942: $postlink{'default'} = ['username','email'];
5943: $prelink = 'both';
5944: %emailsrc = (
5945: permanent => 1,
5946: critical => 1,
5947: notify => 1,
5948: );
5949: }
5950: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5951: $itemcount ++;
5952: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5953: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5954: '<td class="LC_left_item">'.
5955: '<input type="textbox" value="'.$shownlinklife.'" '.
5956: 'name="passwords_link" size="3" /></td></tr>';
5957: $itemcount ++;
5958: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5959: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5960: '<td class="LC_left_item">';
5961: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5962: foreach my $item (@{$types}) {
5963: my $checkedcase;
5964: if ($casesens{$item}) {
5965: $checkedcase = ' checked="checked"';
5966: }
5967: $datatable .= '<span class="LC_nobreak"><label>'.
5968: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5969: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5970: '</span> ';
1.160.6.98 raeburn 5971: }
5972: }
5973: my $checkedcase;
5974: if ($casesens{'default'}) {
5975: $checkedcase = ' checked="checked"';
5976: }
5977: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5978: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5979: $othertitle.'</label></span></td>';
5980: $itemcount ++;
5981: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5982: my %checkedpre = (
5983: both => ' checked="checked"',
5984: either => '',
5985: );
5986: if ($prelink eq 'either') {
5987: $checkedpre{either} = ' checked="checked"';
5988: $checkedpre{both} = '';
5989: }
5990: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5991: '<td class="LC_left_item"><span class="LC_nobreak">'.
5992: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5993: &mt('Both username and e-mail address').'</label></span> '.
5994: '<span class="LC_nobreak"><label>'.
5995: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5996: &mt('Either username or e-mail address').'</label></span></td></tr>';
5997: $itemcount ++;
5998: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5999: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6000: '<td class="LC_left_item">';
6001: my %postlinked;
6002: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6003: foreach my $item (@{$types}) {
6004: undef(%postlinked);
6005: $datatable .= '<fieldset style="display: inline-block;">'.
6006: '<legend>'.$usertypes->{$item}.'</legend>';
6007: if (ref($postlink{$item}) eq 'ARRAY') {
6008: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6009: }
6010: foreach my $field ('email','username') {
6011: my $checked;
6012: if ($postlinked{$field}) {
6013: $checked = ' checked="checked"';
6014: }
6015: $datatable .= '<span class="LC_nobreak"><label>'.
6016: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6017: $field.'"'.$checked.' />'.$field.'</label>'.
6018: '<span> ';
6019: }
6020: $datatable .= '</fieldset>';
6021: }
6022: }
6023: if (ref($postlink{'default'}) eq 'ARRAY') {
6024: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6025: }
6026: $datatable .= '<fieldset style="display: inline-block;">'.
6027: '<legend>'.$othertitle.'</legend>';
6028: foreach my $field ('email','username') {
6029: my $checked;
6030: if ($postlinked{$field}) {
6031: $checked = ' checked="checked"';
6032: }
6033: $datatable .= '<span class="LC_nobreak"><label>'.
6034: '<input type="checkbox" name="passwords_postlink_default" value="'.
6035: $field.'"'.$checked.' />'.$field.'</label>'.
6036: '<span> ';
6037: }
6038: $datatable .= '</fieldset></td></tr>';
6039: $itemcount ++;
6040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6041: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6042: '<td class="LC_left_item">';
6043: foreach my $type ('permanent','critical','notify') {
6044: my $checkedemail;
6045: if ($emailsrc{$type}) {
6046: $checkedemail = ' checked="checked"';
6047: }
6048: $datatable .= '<span class="LC_nobreak"><label>'.
6049: '<input type="checkbox" name="passwords_emailsrc" value="'.
6050: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6051: '<span> ';
6052: }
6053: $datatable .= '</td></tr>';
6054: $itemcount ++;
6055: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6056: my $switchserver = &check_switchserver($dom,$confname);
6057: my ($showstd,$noshowstd);
6058: if ($nostdtext) {
6059: $noshowstd = ' checked="checked"';
6060: } else {
6061: $showstd = ' checked="checked"';
6062: }
6063: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6064: '<td class="LC_left_item"><span class="LC_nobreak">'.
6065: &mt('Retain standard text:').
6066: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6067: &mt('Yes').'</label>'.' '.
6068: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6069: &mt('No').'</label></span><br />'.
6070: '<span class="LC_fontsize_small">'.
6071: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6072: &mt('Include custom text:');
6073: if ($customurl) {
1.160.6.104 raeburn 6074: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 6075: undef,undef,undef,undef,'background-color:#ffffff');
6076: $datatable .= '<span class="LC_nobreak"> '.$link.
6077: '<label><input type="checkbox" name="passwords_custom_del"'.
6078: ' value="1" />'.&mt('Delete?').'</label></span>'.
6079: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6080: }
6081: if ($switchserver) {
6082: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6083: } else {
6084: $datatable .='<span class="LC_nobreak"> '.
6085: '<input type="file" name="passwords_customfile" /></span>';
6086: }
6087: $datatable .= '</td></tr>';
6088: } elsif ($position eq 'middle') {
6089: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6090: my @items = ('intauth_cost','intauth_check','intauth_switch');
6091: my %defaults;
6092: if (ref($domconf{'defaults'}) eq 'HASH') {
6093: %defaults = %{$domconf{'defaults'}};
6094: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6095: $defaults{'intauth_cost'} = 10;
6096: }
6097: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6098: $defaults{'intauth_check'} = 0;
6099: }
6100: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6101: $defaults{'intauth_switch'} = 0;
6102: }
6103: } else {
6104: %defaults = (
6105: 'intauth_cost' => 10,
6106: 'intauth_check' => 0,
6107: 'intauth_switch' => 0,
6108: );
6109: }
6110: foreach my $item (@items) {
6111: if ($itemcount%2) {
6112: $css_class = '';
6113: } else {
6114: $css_class = ' class="LC_odd_row" ';
6115: }
6116: $datatable .= '<tr'.$css_class.'>'.
6117: '<td><span class="LC_nobreak">'.$titles{$item}.
6118: '</span></td><td class="LC_left_item" colspan="3">';
6119: if ($item eq 'intauth_switch') {
6120: my @options = (0,1,2);
6121: my %optiondesc = &Apache::lonlocal::texthash (
6122: 0 => 'No',
6123: 1 => 'Yes',
6124: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6125: );
6126: $datatable .= '<table width="100%">';
6127: foreach my $option (@options) {
6128: my $checked = ' ';
6129: if ($defaults{$item} eq $option) {
6130: $checked = ' checked="checked"';
6131: }
6132: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6133: '<label><input type="radio" name="'.$item.
6134: '" value="'.$option.'"'.$checked.' />'.
6135: $optiondesc{$option}.'</label></span></td></tr>';
6136: }
6137: $datatable .= '</table>';
6138: } elsif ($item eq 'intauth_check') {
6139: my @options = (0,1,2);
6140: my %optiondesc = &Apache::lonlocal::texthash (
6141: 0 => 'No',
6142: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6143: 2 => 'Yes, disallow login if stored cost is less than domain default',
6144: );
6145: $datatable .= '<table width="100%">';
6146: foreach my $option (@options) {
6147: my $checked = ' ';
6148: my $onclick;
6149: if ($defaults{$item} eq $option) {
6150: $checked = ' checked="checked"';
6151: }
6152: if ($option == 2) {
6153: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6154: }
6155: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6156: '<label><input type="radio" name="'.$item.
6157: '" value="'.$option.'"'.$checked.$onclick.' />'.
6158: $optiondesc{$option}.'</label></span></td></tr>';
6159: }
6160: $datatable .= '</table>';
6161: } else {
6162: $datatable .= '<input type="text" name="'.$item.'" value="'.
6163: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6164: }
6165: $datatable .= '</td></tr>';
6166: $itemcount ++;
6167: }
6168: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 6169:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 6170: } else {
6171: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6172: my %ownerchg = (
6173: by => {},
6174: for => {},
6175: );
6176: my %ownertitles = &Apache::lonlocal::texthash (
6177: by => 'Course owner status(es) allowed',
6178: for => 'Student status(es) allowed',
6179: );
6180: if (ref($settings) eq 'HASH') {
6181: if (ref($settings->{crsownerchg}) eq 'HASH') {
6182: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6183: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6184: }
6185: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6186: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6187: }
6188: }
6189: }
6190: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6191: $datatable .= '<tr '.$css_class.'>'.
6192: '<td>'.
6193: &mt('Requirements').'<ul>'.
6194: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6195: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6196: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6197: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6198: '</ul>'.
6199: '</td>'.
6200: '<td class="LC_left_item">';
6201: foreach my $item ('by','for') {
6202: $datatable .= '<fieldset style="display: inline-block;">'.
6203: '<legend>'.$ownertitles{$item}.'</legend>';
6204: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6205: foreach my $type (@{$types}) {
6206: my $checked;
6207: if ($ownerchg{$item}{$type}) {
6208: $checked = ' checked="checked"';
6209: }
6210: $datatable .= '<span class="LC_nobreak"><label>'.
6211: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6212: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 6213: '</span> ';
1.160.6.98 raeburn 6214: }
6215: }
6216: my $checked;
6217: if ($ownerchg{$item}{'default'}) {
6218: $checked = ' checked="checked"';
6219: }
6220: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6221: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6222: $othertitle.'</label></span></fieldset>';
6223: }
6224: $datatable .= '</td></tr>';
6225: }
6226: return $datatable;
6227: }
6228:
1.160.6.118.2 5(raebur 6229:2): sub password_rules {
6230:2): my ($prefix,$itemcountref,$settings) = @_;
6231:2): my ($min,$max,%chars,$numsaved,$numinrow);
6232:2): my %titles;
6233:2): if ($prefix eq 'passwords') {
6234:2): %titles = &Apache::lonlocal::texthash (
6235:2): min => 'Minimum password length',
6236:2): max => 'Maximum password length',
6237:2): chars => 'Required characters',
6238:2): );
6239:2): } elsif ($prefix eq 'secrets') {
6240:2): %titles = &Apache::lonlocal::texthash (
6241:2): min => 'Minimum secret length',
6242:2): max => 'Maximum secret length',
6243:2): chars => 'Required characters',
6244:2): );
6245:2): }
6246:2): $min = $Apache::lonnet::passwdmin;
6247:2): my $datatable;
6248:2): my $itemcount;
6249:2): if (ref($itemcountref)) {
6250:2): $itemcount = $$itemcountref;
6251:2): }
6252:2): if (ref($settings) eq 'HASH') {
6253:2): if ($settings->{min}) {
6254:2): $min = $settings->{min};
6255:2): }
6256:2): if ($settings->{max}) {
6257:2): $max = $settings->{max};
6258:2): }
6259:2): if (ref($settings->{chars}) eq 'ARRAY') {
6260:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
6261:2): }
6262:2): if ($prefix eq 'passwords') {
6263:2): if ($settings->{numsaved}) {
6264:2): $numsaved = $settings->{numsaved};
6265:2): }
6266:2): }
6267:2): }
6268:2): my %rulenames = &Apache::lonlocal::texthash(
6269:2): uc => 'At least one upper case letter',
6270:2): lc => 'At least one lower case letter',
6271:2): num => 'At least one number',
6272:2): spec => 'At least one non-alphanumeric',
6273:2): );
6274:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6275:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6276:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6277:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6278:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6279:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6280:2): '</span></td></tr>';
6281:2): $itemcount ++;
6282:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6283:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6284:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6285:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6286:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6287:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6288:2): '</span></td></tr>';
6289:2): $itemcount ++;
6290:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6291:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6292:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6293:2): '</span></td>';
6294:2): my $numinrow = 2;
6295:2): my @possrules = ('uc','lc','num','spec');
6296:2): $datatable .= '<td class="LC_left_item"><table>';
6297:2): for (my $i=0; $i<@possrules; $i++) {
6298:2): my ($rem,$checked);
6299:2): if ($chars{$possrules[$i]}) {
6300:2): $checked = ' checked="checked"';
6301:2): }
6302:2): $rem = $i%($numinrow);
6303:2): if ($rem == 0) {
6304:2): if ($i > 0) {
6305:2): $datatable .= '</tr>';
6306:2): }
6307:2): $datatable .= '<tr>';
6308:2): }
6309:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
6310:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6311:2): $rulenames{$possrules[$i]}.'</label></span></td>';
6312:2): }
6313:2): my $rem = @possrules%($numinrow);
6314:2): my $colsleft = $numinrow - $rem;
6315:2): if ($colsleft > 1 ) {
6316:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6317:2): ' </td>';
6318:2): } elsif ($colsleft == 1) {
6319:2): $datatable .= '<td class="LC_left_item"> </td>';
6320:2): }
6321:2): $datatable .='</table></td></tr>';
6322:2): $itemcount ++;
6323:2): if ($prefix eq 'passwords') {
6324:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6325:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6326:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6327:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6328:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6329:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6330:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6331:2): '</span></td></tr>';
6332:2): $itemcount ++;
6333:2): }
6334:2): if (ref($itemcountref)) {
6335:2): $$itemcountref += $itemcount;
6336:2): }
6337:2): return $datatable;
6338:2): }
6339:2):
1.160.6.113 raeburn 6340: sub print_wafproxy {
6341: my ($position,$dom,$settings,$rowtotal) = @_;
6342: my $css_class;
6343: my $itemcount = 0;
6344: my $datatable;
6345: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6346: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6347: my %lt = &wafproxy_titles();
6348: foreach my $server (sort(keys(%servers))) {
6349: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6350: next if ($serverhome eq '');
6351: my $serverdom;
6352: if ($serverhome ne $server) {
6353: $serverdom = &Apache::lonnet::host_domain($serverhome);
6354: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6355: $othercontrol{$server} = $serverdom;
6356: }
6357: } else {
6358: $serverdom = &Apache::lonnet::host_domain($server);
6359: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6360: if ($serverdom ne $dom) {
6361: $othercontrol{$server} = $serverdom;
6362: } else {
6363: $setdom = 1;
6364: if (ref($settings) eq 'HASH') {
6365: if (ref($settings->{'alias'}) eq 'HASH') {
6366: $aliases{$dom} = $settings->{'alias'};
6367: if ($aliases{$dom} ne '') {
6368: $showdom = 1;
6369: }
6370: }
6371: if (ref($settings->{'saml'}) eq 'HASH') {
6372: $saml{$dom} = $settings->{'saml'};
6373: }
6374: }
6375: }
6376: }
6377: }
6378: if ($setdom) {
6379: %{$values{$dom}} = ();
6380: if (ref($settings) eq 'HASH') {
6381: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6382: $values{$dom}{$item} = $settings->{$item};
6383: }
6384: }
6385: }
6386: if (keys(%othercontrol)) {
6387: %otherdoms = reverse(%othercontrol);
6388: foreach my $domain (keys(%otherdoms)) {
6389: %{$values{$domain}} = ();
6390: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6391: if (ref($config{'wafproxy'}) eq 'HASH') {
6392: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6393: if (exists($config{'wafproxy'}{'saml'})) {
6394: $saml{$domain} = $config{'wafproxy'}{'saml'};
6395: }
6396: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6397: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6398: }
6399: }
6400: }
6401: }
6402: if ($position eq 'top') {
6403: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6404: my %aliasinfo;
6405: foreach my $server (sort(keys(%servers))) {
6406: $itemcount ++;
6407: my $dom_in_effect;
6408: my $aliasrows = '<tr>'.
6409: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6410: &mt('Hostname').': '.
6411: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6412: if ($othercontrol{$server}) {
6413: $dom_in_effect = $othercontrol{$server};
6414: my ($current,$forsaml);
6415: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6416: $current = $aliases{$dom_in_effect}{$server};
6417: }
6418: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6419: if ($saml{$dom_in_effect}{$server}) {
6420: $forsaml = 1;
6421: }
6422: }
6423: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6424: &mt('Alias').': ';
6425: if ($current) {
6426: $aliasrows .= $current;
6427: if ($forsaml) {
6428: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6429: }
6430: } else {
6431: $aliasrows .= &mt('None');
6432: }
6433: $aliasrows .= ' <span class="LC_small">('.
6434: &mt('controlled by domain: [_1]',
6435: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6436: } else {
6437: $dom_in_effect = $dom;
6438: my ($current,$samlon,$samloff);
6439: $samloff = ' checked="checked"';
6440: if (ref($aliases{$dom}) eq 'HASH') {
6441: if ($aliases{$dom}{$server}) {
6442: $current = $aliases{$dom}{$server};
6443: }
6444: }
6445: if (ref($saml{$dom}) eq 'HASH') {
6446: if ($saml{$dom}{$server}) {
6447: $samlon = $samloff;
6448: undef($samloff);
6449: }
6450: }
6451: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6452: &mt('Alias').': '.
6453: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6454: 'value="'.$current.'" size="30" />'.
6455: (' 'x2).'<span class="LC_nobreak">'.
6456: &mt('Alias used for SSO Auth').': <label>'.
6457: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6458: &mt('No').'</label> <label>'.
6459: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6460: &mt('Yes').'</label></span>'.
6461: '</td>';
6462: }
6463: $aliasrows .= '</tr>';
6464: $aliasinfo{$dom_in_effect} .= $aliasrows;
6465: }
6466: if ($aliasinfo{$dom}) {
6467: my ($onclick,$wafon,$wafoff,$showtable);
6468: $onclick = ' onclick="javascript:toggleWAF();"';
6469: $wafoff = ' checked="checked"';
6470: $showtable = ' style="display:none";';
6471: if ($showdom) {
6472: $wafon = $wafoff;
6473: $wafoff = '';
6474: $showtable = ' style="display:inline;"';
6475: }
6476: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6477: $datatable = '<tr'.$css_class.'>'.
6478: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6479: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6480: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6481: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6482: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6483: &mt('No').'</label></span></td>'.
6484: '<td class="LC_left_item">'.
6485: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6486: '</table></td></tr>';
6487: $itemcount++;
6488: }
6489: if (keys(%otherdoms)) {
6490: foreach my $key (sort(keys(%otherdoms))) {
6491: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6492: $datatable .= '<tr'.$css_class.'>'.
6493: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6494: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6495: '</table></td></tr>';
6496: $itemcount++;
6497: }
6498: }
6499: } else {
6500: my %ip_methods = &remoteip_methods();
6501: if ($setdom) {
6502: $itemcount ++;
6503: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6504: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6505: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6506: $wafstyle = ' style="display:none;"';
6507: $nowafstyle = ' style="display:table-row;"';
6508: $currwafdisplay = ' style="display: none"';
6509: $wafrangestyle = ' style="display: none"';
6510: $curr_remotip = 'n';
6511: $ssltossl = ' checked="checked"';
6512: if ($showdom) {
6513: $wafstyle = ' style="display:table-row;"';
6514: $nowafstyle = ' style="display:none;"';
6515: if (keys(%{$values{$dom}})) {
6516: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6517: $curr_remotip = $values{$dom}{remoteip};
6518: }
6519: if ($curr_remotip eq 'h') {
6520: $currwafdisplay = ' style="display:table-row"';
6521: $wafrangestyle = ' style="display:inline-block;"';
6522: }
6523: if ($values{$dom}{'sslopt'}) {
6524: $alltossl = ' checked="checked"';
6525: $ssltossl = '';
6526: }
6527: }
6528: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6529: $vpndircheck = ' checked="checked"';
6530: $currwafvpn = ' style="display:table-row;"';
6531: $wafrangestyle = ' style="display:inline-block;"';
6532: } else {
6533: $vpnaliascheck = ' checked="checked"';
6534: $currwafvpn = ' style="display:none;"';
6535: }
6536: }
6537: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6538: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6539: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6540: '</tr>'.
6541: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6542: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6543: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6544: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6545: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6546: '<td class="LC_left_item"><table>'.
6547: '<tr>'.
6548: '<td valign="top">'.$lt{'remoteip'}.': '.
6549: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6550: foreach my $option ('m','h','n') {
6551: my $sel;
1.160.6.114 raeburn 6552: if ($option eq $curr_remotip) {
6553: $sel = ' selected="selected"';
6554: }
6555: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6556: $ip_methods{$option}.'</option>';
6557: }
6558: $datatable .= '</select></td></tr>'."\n".
6559: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6560: $lt{'ipheader'}.': '.
6561: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6562: 'name="wafproxy_ipheader" />'.
6563: '</td></tr>'."\n".
6564: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6565: $lt{'trusted'}.':<br />'.
6566: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6567: $values{$dom}{'trusted'}.'</textarea>'.
6568: '</td></tr>'."\n".
6569: '<tr><td><hr /></td></tr>'."\n".
6570: '<tr>'.
1.160.6.113 raeburn 6571: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6572: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6573: $lt{'vpndirect'}.'</label>'.(' 'x2).
6574: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6575: $lt{'vpnaliased'}.'</label></span></td></tr>';
6576: foreach my $item ('vpnint','vpnext') {
6577: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6578: '<td valign="top">'.$lt{$item}.':<br />'.
6579: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6580: $values{$dom}{$item}.'</textarea>'.
6581: '</td></tr>'."\n";
6582: }
6583: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6584: '<tr>'.
6585: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6586: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6587: $lt{'alltossl'}.'</label>'.(' 'x2).
6588: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6589: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6590: '</table></td></tr>';
6591: }
6592: if (keys(%otherdoms)) {
6593: foreach my $domain (sort(keys(%otherdoms))) {
6594: $itemcount ++;
6595: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6596: $datatable .= '<tr'.$css_class.'>'.
6597: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6598: '<td class="LC_left_item"><table>';
6599: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6600: my $showval = &mt('None');
6601: if ($item eq 'ssl') {
6602: $showval = $lt{'ssltossl'};
6603: }
6604: if ($values{$domain}{$item}) {
6605: $showval = $values{$domain}{$item};
6606: if ($item eq 'ssl') {
6607: $showval = $lt{'alltossl'};
6608: } elsif ($item eq 'remoteip') {
6609: $showval = $ip_methods{$values{$domain}{$item}};
6610: }
6611: }
6612: $datatable .= '<tr>'.
6613: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6614: }
6615: $datatable .= '</table></td></tr>';
6616: }
6617: }
6618: }
6619: $$rowtotal += $itemcount;
6620: return $datatable;
6621: }
6622:
6623: sub wafproxy_titles {
6624: return &Apache::lonlocal::texthash(
6625: remoteip => "Method for determining user's IP",
6626: ipheader => 'Request header containing remote IP',
6627: trusted => 'Trusted IP range(s)',
6628: vpnaccess => 'Access from institutional VPN',
6629: vpndirect => 'via regular hostname (no WAF)',
6630: vpnaliased => 'via aliased hostname (WAF)',
6631: vpnint => 'Internal IP Range(s) for VPN sessions',
6632: vpnext => 'IP Range(s) for backend WAF connections',
6633: sslopt => 'Forwarding http/https',
6634: alltossl => 'WAF forwards both http and https requests to https',
6635: ssltossl => 'WAF forwards http requests to http and https to https',
6636: );
6637: }
6638:
6639: sub remoteip_methods {
6640: return &Apache::lonlocal::texthash(
6641: m => 'Use Apache mod_remoteip',
6642: h => 'Use headers parsed by LON-CAPA',
6643: n => 'Not in use',
6644: );
6645: }
6646:
1.137 raeburn 6647: sub print_usersessions {
6648: my ($position,$dom,$settings,$rowtotal) = @_;
6649: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 6650: my (%by_ip,%by_location,@intdoms);
6651: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 6652:
6653: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6654: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6655: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6656: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6657: my $itemcount = 1;
6658: if ($position eq 'top') {
1.152 raeburn 6659: if (keys(%serverhomes) > 1) {
1.145 raeburn 6660: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 6661: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 6662: if (ref($settings) eq 'HASH') {
6663: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6664: $curroffloadnow = $settings->{'offloadnow'};
6665: }
1.160.6.105 raeburn 6666: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6667: $curroffloadoth = $settings->{'offloadoth'};
6668: }
1.160.6.61 raeburn 6669: }
1.160.6.105 raeburn 6670: my $other_insts = scalar(keys(%by_location));
6671: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6672: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 6673: } else {
1.140 raeburn 6674: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6675: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 6676: }
1.137 raeburn 6677: } else {
1.145 raeburn 6678: if (keys(%by_location) == 0) {
6679: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6680: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 6681: } else {
6682: my %lt = &usersession_titles();
6683: my $numinrow = 5;
6684: my $prefix;
6685: my @types;
6686: if ($position eq 'bottom') {
6687: $prefix = 'remote';
6688: @types = ('version','excludedomain','includedomain');
6689: } else {
6690: $prefix = 'hosted';
6691: @types = ('excludedomain','includedomain');
6692: }
6693: my (%current,%checkedon,%checkedoff);
6694: my @lcversions = &Apache::lonnet::all_loncaparevs();
6695: my @locations = sort(keys(%by_location));
6696: foreach my $type (@types) {
6697: $checkedon{$type} = '';
6698: $checkedoff{$type} = ' checked="checked"';
6699: }
6700: if (ref($settings) eq 'HASH') {
6701: if (ref($settings->{$prefix}) eq 'HASH') {
6702: foreach my $key (keys(%{$settings->{$prefix}})) {
6703: $current{$key} = $settings->{$prefix}{$key};
6704: if ($key eq 'version') {
6705: if ($current{$key} ne '') {
6706: $checkedon{$key} = ' checked="checked"';
6707: $checkedoff{$key} = '';
6708: }
6709: } elsif (ref($current{$key}) eq 'ARRAY') {
6710: $checkedon{$key} = ' checked="checked"';
6711: $checkedoff{$key} = '';
6712: }
1.137 raeburn 6713: }
6714: }
6715: }
1.145 raeburn 6716: foreach my $type (@types) {
6717: next if ($type ne 'version' && !@locations);
6718: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6719: $datatable .= '<tr'.$css_class.'>
6720: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6721: <span class="LC_nobreak">
6722: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6723: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6724: if ($type eq 'version') {
6725: my $selector = '<select name="'.$prefix.'_version">';
6726: foreach my $version (@lcversions) {
6727: my $selected = '';
6728: if ($current{'version'} eq $version) {
6729: $selected = ' selected="selected"';
6730: }
6731: $selector .= ' <option value="'.$version.'"'.
6732: $selected.'>'.$version.'</option>';
6733: }
6734: $selector .= '</select> ';
6735: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6736: } else {
6737: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6738: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6739: ' />'.(' 'x2).
6740: '<input type="button" value="'.&mt('uncheck all').'" '.
6741: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6742: "\n".
6743: '</div><div><table>';
6744: my $rem;
6745: for (my $i=0; $i<@locations; $i++) {
6746: my ($showloc,$value,$checkedtype);
6747: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6748: my $ip = $by_location{$locations[$i]}->[0];
6749: if (ref($by_ip{$ip}) eq 'ARRAY') {
6750: $value = join(':',@{$by_ip{$ip}});
6751: $showloc = join(', ',@{$by_ip{$ip}});
6752: if (ref($current{$type}) eq 'ARRAY') {
6753: foreach my $loc (@{$by_ip{$ip}}) {
6754: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6755: $checkedtype = ' checked="checked"';
6756: last;
6757: }
6758: }
1.138 raeburn 6759: }
6760: }
6761: }
1.145 raeburn 6762: $rem = $i%($numinrow);
6763: if ($rem == 0) {
6764: if ($i > 0) {
6765: $datatable .= '</tr>';
6766: }
6767: $datatable .= '<tr>';
6768: }
6769: $datatable .= '<td class="LC_left_item">'.
6770: '<span class="LC_nobreak"><label>'.
6771: '<input type="checkbox" name="'.$prefix.'_'.$type.
6772: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6773: '</label></span></td>';
1.137 raeburn 6774: }
1.145 raeburn 6775: $rem = @locations%($numinrow);
6776: my $colsleft = $numinrow - $rem;
6777: if ($colsleft > 1 ) {
6778: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6779: ' </td>';
6780: } elsif ($colsleft == 1) {
6781: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6782: }
1.145 raeburn 6783: $datatable .= '</tr></table>';
1.137 raeburn 6784: }
1.145 raeburn 6785: $datatable .= '</td></tr>';
6786: $itemcount ++;
1.137 raeburn 6787: }
6788: }
6789: }
6790: $$rowtotal += $itemcount;
6791: return $datatable;
6792: }
6793:
1.138 raeburn 6794: sub build_location_hashes {
6795: my ($intdoms,$by_ip,$by_location) = @_;
6796: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6797: (ref($by_location) eq 'HASH'));
6798: my %iphost = &Apache::lonnet::get_iphost();
6799: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6800: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6801: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6802: foreach my $id (@{$iphost{$primary_ip}}) {
6803: my $intdom = &Apache::lonnet::internet_dom($id);
6804: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6805: push(@{$intdoms},$intdom);
6806: }
6807: }
6808: }
6809: foreach my $ip (keys(%iphost)) {
6810: if (ref($iphost{$ip}) eq 'ARRAY') {
6811: foreach my $id (@{$iphost{$ip}}) {
6812: my $location = &Apache::lonnet::internet_dom($id);
6813: if ($location) {
6814: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6815: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6816: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6817: push(@{$by_ip->{$ip}},$location);
6818: }
6819: } else {
6820: $by_ip->{$ip} = [$location];
6821: }
6822: }
6823: }
6824: }
6825: }
6826: foreach my $ip (sort(keys(%{$by_ip}))) {
6827: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6828: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6829: my $first = $by_ip->{$ip}->[0];
6830: if (ref($by_location->{$first}) eq 'ARRAY') {
6831: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6832: push(@{$by_location->{$first}},$ip);
6833: }
6834: } else {
6835: $by_location->{$first} = [$ip];
6836: }
6837: }
6838: }
6839: return;
6840: }
6841:
1.145 raeburn 6842: sub current_offloads_to {
6843: my ($dom,$settings,$servers) = @_;
6844: my (%spareid,%otherdomconfigs);
1.152 raeburn 6845: if (ref($servers) eq 'HASH') {
1.145 raeburn 6846: foreach my $lonhost (sort(keys(%{$servers}))) {
6847: my $gotspares;
1.152 raeburn 6848: if (ref($settings) eq 'HASH') {
6849: if (ref($settings->{'spares'}) eq 'HASH') {
6850: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6851: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6852: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6853: $gotspares = 1;
6854: }
1.145 raeburn 6855: }
6856: }
6857: unless ($gotspares) {
6858: my $gotspares;
6859: my $serverhomeID =
6860: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6861: my $serverhomedom =
6862: &Apache::lonnet::host_domain($serverhomeID);
6863: if ($serverhomedom ne $dom) {
6864: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6865: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6866: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6867: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6868: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6869: $gotspares = 1;
6870: }
6871: }
6872: } else {
6873: $otherdomconfigs{$serverhomedom} =
6874: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6875: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6876: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6877: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6878: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6879: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6880: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6881: $gotspares = 1;
6882: }
6883: }
6884: }
6885: }
6886: }
6887: }
6888: }
6889: unless ($gotspares) {
6890: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6891: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6892: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6893: } else {
6894: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6895: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6896: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6897: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6898: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6899: } else {
1.150 raeburn 6900: my %what = (
6901: spareid => 1,
6902: );
6903: my ($result,$returnhash) =
6904: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6905: if ($result eq 'ok') {
6906: if (ref($returnhash) eq 'HASH') {
6907: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6908: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6909: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6910: }
6911: }
1.145 raeburn 6912: }
6913: }
6914: }
6915: }
6916: }
6917: }
6918: return %spareid;
6919: }
6920:
6921: sub spares_row {
1.160.6.105 raeburn 6922: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6923: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6924: my $css_class;
6925: my $numinrow = 4;
6926: my $itemcount = 1;
6927: my $datatable;
1.152 raeburn 6928: my %typetitles = &sparestype_titles();
6929: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6930: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6931: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6932: my ($othercontrol,$serverdom);
6933: if ($serverhome ne $server) {
6934: $serverdom = &Apache::lonnet::host_domain($serverhome);
6935: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6936: } else {
6937: $serverdom = &Apache::lonnet::host_domain($server);
6938: if ($serverdom ne $dom) {
6939: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6940: }
6941: }
6942: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6943: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6944: if (ref($curroffloadnow) eq 'HASH') {
6945: if ($curroffloadnow->{$server}) {
6946: $checkednow = ' checked="checked"';
6947: }
6948: }
1.160.6.105 raeburn 6949: if (ref($curroffloadoth) eq 'HASH') {
6950: if ($curroffloadoth->{$server}) {
6951: $checkedoth = ' checked="checked"';
6952: }
6953: }
1.145 raeburn 6954: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6955: $datatable .= '<tr'.$css_class.'>
6956: <td rowspan="2">
1.160.6.13 raeburn 6957: <span class="LC_nobreak">'.
6958: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6959: ,'<b>'.$server.'</b>').'</span><br />'.
6960: '<span class="LC_nobreak">'."\n".
6961: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6962: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6963: "\n";
1.160.6.105 raeburn 6964: if ($other_insts) {
6965: $datatable .= '<br />'.
6966: '<span class="LC_nobreak">'."\n".
6967: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6968: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6969: "\n";
6970: }
1.145 raeburn 6971: my (%current,%canselect);
1.152 raeburn 6972: my @choices =
6973: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6974: foreach my $type ('primary','default') {
6975: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6976: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6977: my @spares = @{$spareid->{$server}{$type}};
6978: if (@spares > 0) {
1.152 raeburn 6979: if ($othercontrol) {
6980: $current{$type} = join(', ',@spares);
6981: } else {
6982: $current{$type} .= '<table>';
6983: my $numspares = scalar(@spares);
6984: for (my $i=0; $i<@spares; $i++) {
6985: my $rem = $i%($numinrow);
6986: if ($rem == 0) {
6987: if ($i > 0) {
6988: $current{$type} .= '</tr>';
6989: }
6990: $current{$type} .= '<tr>';
1.145 raeburn 6991: }
1.152 raeburn 6992: $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'".');" /> '.
6993: $spareid->{$server}{$type}[$i].
6994: '</label></td>'."\n";
6995: }
6996: my $rem = @spares%($numinrow);
6997: my $colsleft = $numinrow - $rem;
6998: if ($colsleft > 1 ) {
6999: $current{$type} .= '<td colspan="'.$colsleft.
7000: '" class="LC_left_item">'.
7001: ' </td>';
7002: } elsif ($colsleft == 1) {
7003: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7004: }
1.152 raeburn 7005: $current{$type} .= '</tr></table>';
1.150 raeburn 7006: }
1.145 raeburn 7007: }
7008: }
7009: if ($current{$type} eq '') {
7010: $current{$type} = &mt('None specified');
7011: }
1.152 raeburn 7012: if ($othercontrol) {
7013: if ($type eq 'primary') {
7014: $canselect{$type} = $othercontrol;
7015: }
7016: } else {
7017: $canselect{$type} =
7018: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7019: '<select name="newspare_'.$type.'_'.$server.'" '.
7020: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7021: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7022: if (@choices > 0) {
7023: foreach my $lonhost (@choices) {
7024: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7025: }
7026: }
7027: $canselect{$type} .= '</select>'."\n";
7028: }
7029: } else {
7030: $current{$type} = &mt('Could not be determined');
7031: if ($type eq 'primary') {
7032: $canselect{$type} = $othercontrol;
7033: }
1.145 raeburn 7034: }
1.152 raeburn 7035: if ($type eq 'default') {
7036: $datatable .= '<tr'.$css_class.'>';
7037: }
7038: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7039: '<td>'.$current{$type}.'</td>'."\n".
7040: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7041: }
7042: $itemcount ++;
7043: }
7044: }
7045: $$rowtotal += $itemcount;
7046: return $datatable;
7047: }
7048:
1.152 raeburn 7049: sub possible_newspares {
7050: my ($server,$currspares,$serverhomes,$altids) = @_;
7051: my $serverhostname = &Apache::lonnet::hostname($server);
7052: my %excluded;
7053: if ($serverhostname ne '') {
7054: %excluded = (
7055: $serverhostname => 1,
7056: );
7057: }
7058: if (ref($currspares) eq 'HASH') {
7059: foreach my $type (keys(%{$currspares})) {
7060: if (ref($currspares->{$type}) eq 'ARRAY') {
7061: if (@{$currspares->{$type}} > 0) {
7062: foreach my $curr (@{$currspares->{$type}}) {
7063: my $hostname = &Apache::lonnet::hostname($curr);
7064: $excluded{$hostname} = 1;
7065: }
7066: }
7067: }
7068: }
7069: }
7070: my @choices;
7071: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7072: if (keys(%{$serverhomes}) > 1) {
7073: foreach my $name (sort(keys(%{$serverhomes}))) {
7074: unless ($excluded{$name}) {
7075: if (exists($altids->{$serverhomes->{$name}})) {
7076: push(@choices,$altids->{$serverhomes->{$name}});
7077: } else {
7078: push(@choices,$serverhomes->{$name});
1.145 raeburn 7079: }
7080: }
7081: }
7082: }
7083: }
1.152 raeburn 7084: return sort(@choices);
1.145 raeburn 7085: }
7086:
1.150 raeburn 7087: sub print_loadbalancing {
7088: my ($dom,$settings,$rowtotal) = @_;
7089: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7090: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7091: my $numinrow = 1;
7092: my $datatable;
7093: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 7094: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 7095: if (ref($settings) eq 'HASH') {
7096: %existing = %{$settings};
7097: }
7098: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7099: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 7100: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7101: } else {
7102: return;
7103: }
7104: my ($othertitle,$usertypes,$types) =
7105: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 7106: my $rownum = 8;
1.150 raeburn 7107: if (ref($types) eq 'ARRAY') {
7108: $rownum += scalar(@{$types});
7109: }
1.160.6.7 raeburn 7110: my @css_class = ('LC_odd_row','LC_even_row');
7111: my $balnum = 0;
7112: my $islast;
7113: my (@toshow,$disabledtext);
7114: if (keys(%currbalancer) > 0) {
7115: @toshow = sort(keys(%currbalancer));
7116: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7117: push(@toshow,'');
7118: }
7119: } else {
7120: @toshow = ('');
7121: $disabledtext = &mt('No existing load balancer');
7122: }
7123: foreach my $lonhost (@toshow) {
7124: if ($balnum == scalar(@toshow)-1) {
7125: $islast = 1;
7126: } else {
7127: $islast = 0;
7128: }
7129: my $cssidx = $balnum%2;
7130: my $targets_div_style = 'display: none';
7131: my $disabled_div_style = 'display: block';
7132: my $homedom_div_style = 'display: none';
7133: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7134: '<td rowspan="'.$rownum.'" valign="top">'.
7135: '<p>';
7136: if ($lonhost eq '') {
7137: $datatable .= '<span class="LC_nobreak">';
7138: if (keys(%currbalancer) > 0) {
7139: $datatable .= &mt('Add balancer:');
7140: } else {
7141: $datatable .= &mt('Enable balancer:');
7142: }
7143: $datatable .= ' '.
7144: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7145: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7146: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7147: '<option value="" selected="selected">'.&mt('None').
7148: '</option>'."\n";
7149: foreach my $server (sort(keys(%servers))) {
7150: next if ($currbalancer{$server});
7151: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7152: }
7153: $datatable .=
7154: '</select>'."\n".
7155: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7156: } else {
7157: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7158: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7159: &mt('Stop balancing').'</label>'.
7160: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7161: $targets_div_style = 'display: block';
7162: $disabled_div_style = 'display: none';
7163: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7164: $homedom_div_style = 'display: block';
7165: }
7166: }
7167: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7168: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7169: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7170: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7171: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7172: my @sparestypes = ('primary','default');
7173: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 7174: my %hostherechecked = (
7175: no => ' checked="checked"',
7176: );
1.160.6.94 raeburn 7177: my %balcookiechecked = (
7178: no => ' checked="checked"',
7179: );
1.160.6.7 raeburn 7180: foreach my $sparetype (@sparestypes) {
7181: my $targettable;
7182: for (my $i=0; $i<$numspares; $i++) {
7183: my $checked;
7184: if (ref($currtargets{$lonhost}) eq 'HASH') {
7185: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7186: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7187: $checked = ' checked="checked"';
7188: }
7189: }
7190: }
7191: my ($chkboxval,$disabled);
7192: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7193: $chkboxval = $spares[$i];
7194: }
7195: if (exists($currbalancer{$spares[$i]})) {
7196: $disabled = ' disabled="disabled"';
7197: }
7198: $targettable .=
1.160.6.55 raeburn 7199: '<td><span class="LC_nobreak"><label>'.
7200: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 7201: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 7202: '</span></label></span></td>';
1.160.6.7 raeburn 7203: my $rem = $i%($numinrow);
7204: if ($rem == 0) {
7205: if (($i > 0) && ($i < $numspares-1)) {
7206: $targettable .= '</tr>';
7207: }
7208: if ($i < $numspares-1) {
7209: $targettable .= '<tr>';
1.150 raeburn 7210: }
7211: }
7212: }
1.160.6.7 raeburn 7213: if ($targettable ne '') {
7214: my $rem = $numspares%($numinrow);
7215: my $colsleft = $numinrow - $rem;
7216: if ($colsleft > 1 ) {
7217: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7218: ' </td>';
7219: } elsif ($colsleft == 1) {
7220: $targettable .= '<td class="LC_left_item"> </td>';
7221: }
7222: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7223: '<table><tr>'.$targettable.'</tr></table><br />';
7224: }
1.160.6.76 raeburn 7225: $hostherechecked{$sparetype} = '';
7226: if (ref($currtargets{$lonhost}) eq 'HASH') {
7227: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7228: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7229: $hostherechecked{$sparetype} = ' checked="checked"';
7230: $hostherechecked{'no'} = '';
7231: }
7232: }
7233: }
7234: }
1.160.6.94 raeburn 7235: if ($currcookies{$lonhost}) {
7236: %balcookiechecked = (
7237: yes => ' checked="checked"',
7238: );
7239: }
1.160.6.76 raeburn 7240: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7241: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7242: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7243: foreach my $sparetype (@sparestypes) {
7244: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7245: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7246: '</i></label><br />';
1.160.6.7 raeburn 7247: }
1.160.6.94 raeburn 7248: $datatable .= &mt('Use balancer cookie').'<br />'.
7249: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7250: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7251: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7252: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7253: '</div></td></tr>'.
1.160.6.7 raeburn 7254: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7255: $othertitle,$usertypes,$types,\%servers,
7256: \%currbalancer,$lonhost,
7257: $targets_div_style,$homedom_div_style,
7258: $css_class[$cssidx],$balnum,$islast);
7259: $$rowtotal += $rownum;
7260: $balnum ++;
7261: }
7262: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7263: return $datatable;
7264: }
7265:
7266: sub get_loadbalancers_config {
1.160.6.94 raeburn 7267: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 7268: return unless ((ref($servers) eq 'HASH') &&
7269: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 7270: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7271: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 7272: if (keys(%{$existing}) > 0) {
7273: my $oldlonhost;
7274: foreach my $key (sort(keys(%{$existing}))) {
7275: if ($key eq 'lonhost') {
7276: $oldlonhost = $existing->{'lonhost'};
7277: $currbalancer->{$oldlonhost} = 1;
7278: } elsif ($key eq 'targets') {
7279: if ($oldlonhost) {
7280: $currtargets->{$oldlonhost} = $existing->{'targets'};
7281: }
7282: } elsif ($key eq 'rules') {
7283: if ($oldlonhost) {
7284: $currrules->{$oldlonhost} = $existing->{'rules'};
7285: }
7286: } elsif (ref($existing->{$key}) eq 'HASH') {
7287: $currbalancer->{$key} = 1;
7288: $currtargets->{$key} = $existing->{$key}{'targets'};
7289: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 7290: if ($existing->{$key}{'cookie'}) {
7291: $currcookies->{$key} = 1;
7292: }
1.150 raeburn 7293: }
7294: }
1.160.6.7 raeburn 7295: } else {
7296: my ($balancerref,$targetsref) =
7297: &Apache::lonnet::get_lonbalancer_config($servers);
7298: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7299: foreach my $server (sort(keys(%{$balancerref}))) {
7300: $currbalancer->{$server} = 1;
7301: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7302: }
7303: }
7304: }
1.160.6.7 raeburn 7305: return;
1.150 raeburn 7306: }
7307:
7308: sub loadbalancing_rules {
7309: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 7310: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7311: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7312: my $output;
1.160.6.7 raeburn 7313: my $num = 0;
7314: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7315: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7316: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7317: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 7318: $num ++;
1.150 raeburn 7319: my $current;
7320: if (ref($currrules) eq 'HASH') {
7321: $current = $currrules->{$type};
7322: }
1.160.6.55 raeburn 7323: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 7324: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7325: $current = '';
7326: }
7327: }
7328: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 7329: $servers,$currbalancer,$lonhost,$dom,
7330: $targets_div_style,$homedom_div_style,
7331: $css_class,$balnum,$num,$islast);
1.150 raeburn 7332: }
7333: }
7334: return $output;
7335: }
7336:
7337: sub loadbalancing_titles {
7338: my ($dom,$intdom,$usertypes,$types) = @_;
7339: my %othertypes = (
7340: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7341: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7342: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7343: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 7344: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7345: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7346: );
1.160.6.26 raeburn 7347: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 7348: my @available;
1.150 raeburn 7349: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7350: @available = @{$types};
1.150 raeburn 7351: }
1.160.6.89 raeburn 7352: unless (grep(/^default$/,@available)) {
7353: push(@available,'default');
7354: }
7355: unshift(@alltypes,@available);
1.150 raeburn 7356: my %titles;
7357: foreach my $type (@alltypes) {
7358: if ($type =~ /^_LC_/) {
7359: $titles{$type} = $othertypes{$type};
7360: } elsif ($type eq 'default') {
7361: $titles{$type} = &mt('All users from [_1]',$dom);
7362: if (ref($types) eq 'ARRAY') {
7363: if (@{$types} > 0) {
7364: $titles{$type} = &mt('Other users from [_1]',$dom);
7365: }
7366: }
7367: } elsif (ref($usertypes) eq 'HASH') {
7368: $titles{$type} = $usertypes->{$type};
7369: }
7370: }
7371: return (\@alltypes,\%othertypes,\%titles);
7372: }
7373:
7374: sub loadbalance_rule_row {
1.160.6.7 raeburn 7375: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7376: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 7377: my @rulenames;
1.150 raeburn 7378: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 7379: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 7380: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7381: } else {
1.160.6.26 raeburn 7382: @rulenames = ('default','homeserver');
7383: if ($type eq '_LC_external') {
7384: push(@rulenames,'externalbalancer');
7385: } else {
7386: push(@rulenames,'specific');
7387: }
7388: push(@rulenames,'none');
1.150 raeburn 7389: }
7390: my $style = $targets_div_style;
1.160.6.55 raeburn 7391: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7392: $style = $homedom_div_style;
7393: }
1.160.6.7 raeburn 7394: my $space;
7395: if ($islast && $num == 1) {
7396: $space = '<div display="inline-block"> </div>';
7397: }
7398: my $output =
7399: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7400: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7401: '<td valaign="top">'.$space.
7402: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7403: for (my $i=0; $i<@rulenames; $i++) {
7404: my $rule = $rulenames[$i];
7405: my ($checked,$extra);
7406: if ($rulenames[$i] eq 'default') {
7407: $rule = '';
7408: }
7409: if ($rulenames[$i] eq 'specific') {
7410: if (ref($servers) eq 'HASH') {
7411: my $default;
7412: if (($current ne '') && (exists($servers->{$current}))) {
7413: $checked = ' checked="checked"';
7414: }
7415: unless ($checked) {
7416: $default = ' selected="selected"';
7417: }
1.160.6.7 raeburn 7418: $extra =
7419: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7420: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7421: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7422: '<option value=""'.$default.'></option>'."\n";
7423: foreach my $server (sort(keys(%{$servers}))) {
7424: if (ref($currbalancer) eq 'HASH') {
7425: next if (exists($currbalancer->{$server}));
7426: }
1.150 raeburn 7427: my $selected;
1.160.6.7 raeburn 7428: if ($server eq $current) {
1.150 raeburn 7429: $selected = ' selected="selected"';
7430: }
1.160.6.7 raeburn 7431: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7432: }
7433: $extra .= '</select>';
7434: }
7435: } elsif ($rule eq $current) {
7436: $checked = ' checked="checked"';
7437: }
7438: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 7439: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7440: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7441: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 7442: ')"'.$checked.' /> ';
1.160.6.56 raeburn 7443: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 7444: $output .= $ruletitles{'particular'};
7445: } else {
7446: $output .= $ruletitles{$rulenames[$i]};
7447: }
7448: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7449: }
7450: $output .= '</div></td></tr>'."\n";
7451: return $output;
7452: }
7453:
7454: sub offloadtype_text {
7455: my %ruletitles = &Apache::lonlocal::texthash (
7456: 'default' => 'Offloads to default destinations',
7457: 'homeserver' => "Offloads to user's home server",
7458: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7459: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 7460: 'none' => 'No offload',
1.160.6.26 raeburn 7461: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7462: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 7463: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7464: );
7465: return %ruletitles;
7466: }
7467:
7468: sub sparestype_titles {
7469: my %typestitles = &Apache::lonlocal::texthash (
7470: 'primary' => 'primary',
7471: 'default' => 'default',
7472: );
7473: return %typestitles;
7474: }
7475:
1.28 raeburn 7476: sub contact_titles {
7477: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 7478: 'supportemail' => 'Support E-mail address',
7479: 'adminemail' => 'Default Server Admin E-mail address',
7480: 'errormail' => 'Error reports to be e-mailed to',
7481: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 7482: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7483: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 7484: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7485: 'requestsmail' => 'E-mail from course requests requiring approval',
7486: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 7487: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 7488: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 7489: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7490: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 7491: 'errorweights' => 'Weights used to compute error count',
7492: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7493: );
7494: my %short_titles = &Apache::lonlocal::texthash (
7495: adminemail => 'Admin E-mail address',
7496: supportemail => 'Support E-mail',
7497: );
7498: return (\%titles,\%short_titles);
7499: }
7500:
1.160.6.78 raeburn 7501: sub helpform_fields {
7502: my %titles = &Apache::lonlocal::texthash (
7503: 'username' => 'Name',
7504: 'user' => 'Username/domain',
7505: 'phone' => 'Phone',
7506: 'cc' => 'Cc e-mail',
7507: 'course' => 'Course Details',
7508: 'section' => 'Sections',
7509: 'screenshot' => 'File upload',
7510: );
7511: my @fields = ('username','phone','user','course','section','cc','screenshot');
7512: my %possoptions = (
7513: username => ['yes','no','req'],
7514: phone => ['yes','no','req'],
7515: user => ['yes','no'],
7516: cc => ['yes','no'],
7517: course => ['yes','no'],
7518: section => ['yes','no'],
7519: screenshot => ['yes','no'],
7520: );
7521: my %fieldoptions = &Apache::lonlocal::texthash (
7522: 'yes' => 'Optional',
7523: 'req' => 'Required',
7524: 'no' => "Not shown",
7525: );
7526: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7527: }
7528:
1.72 raeburn 7529: sub tool_titles {
7530: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 7531: aboutme => 'Personal web page',
1.86 raeburn 7532: blog => 'Blog',
1.160.6.4 raeburn 7533: webdav => 'WebDAV',
1.86 raeburn 7534: portfolio => 'Portfolio',
1.88 bisitz 7535: official => 'Official courses (with institutional codes)',
7536: unofficial => 'Unofficial courses',
1.98 raeburn 7537: community => 'Communities',
1.160.6.30 raeburn 7538: textbook => 'Textbook courses',
1.86 raeburn 7539: );
1.72 raeburn 7540: return %titles;
7541: }
7542:
1.101 raeburn 7543: sub courserequest_titles {
7544: my %titles = &Apache::lonlocal::texthash (
7545: official => 'Official',
7546: unofficial => 'Unofficial',
7547: community => 'Communities',
1.160.6.30 raeburn 7548: textbook => 'Textbook',
1.101 raeburn 7549: norequest => 'Not allowed',
1.104 raeburn 7550: approval => 'Approval by Dom. Coord.',
1.101 raeburn 7551: validate => 'With validation',
7552: autolimit => 'Numerical limit',
1.103 raeburn 7553: unlimited => '(blank for unlimited)',
1.101 raeburn 7554: );
7555: return %titles;
7556: }
7557:
1.160.6.5 raeburn 7558: sub authorrequest_titles {
7559: my %titles = &Apache::lonlocal::texthash (
7560: norequest => 'Not allowed',
7561: approval => 'Approval by Dom. Coord.',
7562: automatic => 'Automatic approval',
7563: );
7564: return %titles;
7565: }
7566:
1.101 raeburn 7567: sub courserequest_conditions {
7568: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7569: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 7570: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7571: );
7572: return %conditions;
7573: }
7574:
7575:
1.27 raeburn 7576: sub print_usercreation {
1.30 raeburn 7577: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7578: my $numinrow = 4;
1.28 raeburn 7579: my $datatable;
7580: if ($position eq 'top') {
1.30 raeburn 7581: $$rowtotal ++;
1.34 raeburn 7582: my $rowcount = 0;
1.32 raeburn 7583: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7584: if (ref($rules) eq 'HASH') {
7585: if (keys(%{$rules}) > 0) {
1.32 raeburn 7586: $datatable .= &user_formats_row('username',$settings,$rules,
7587: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7588: $$rowtotal ++;
1.32 raeburn 7589: $rowcount ++;
7590: }
7591: }
7592: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7593: if (ref($idrules) eq 'HASH') {
7594: if (keys(%{$idrules}) > 0) {
7595: $datatable .= &user_formats_row('id',$settings,$idrules,
7596: $idruleorder,$numinrow,$rowcount);
7597: $$rowtotal ++;
7598: $rowcount ++;
1.28 raeburn 7599: }
7600: }
1.39 raeburn 7601: if ($rowcount == 0) {
7602: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7603: $$rowtotal ++;
7604: $rowcount ++;
7605: }
1.34 raeburn 7606: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 7607: my @creators = ('author','course','requestcrs');
1.37 raeburn 7608: my ($rules,$ruleorder) =
7609: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7610: my %lt = &usercreation_types();
7611: my %checked;
7612: if (ref($settings) eq 'HASH') {
7613: if (ref($settings->{'cancreate'}) eq 'HASH') {
7614: foreach my $item (@creators) {
7615: $checked{$item} = $settings->{'cancreate'}{$item};
7616: }
7617: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7618: foreach my $item (@creators) {
7619: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7620: $checked{$item} = 'none';
7621: }
7622: }
7623: }
7624: }
7625: my $rownum = 0;
7626: foreach my $item (@creators) {
7627: $rownum ++;
1.160.6.34 raeburn 7628: if ($checked{$item} eq '') {
7629: $checked{$item} = 'any';
1.34 raeburn 7630: }
7631: my $css_class;
7632: if ($rownum%2) {
7633: $css_class = '';
7634: } else {
7635: $css_class = ' class="LC_odd_row" ';
7636: }
7637: $datatable .= '<tr'.$css_class.'>'.
7638: '<td><span class="LC_nobreak">'.$lt{$item}.
7639: '</span></td><td align="right">';
1.160.6.34 raeburn 7640: my @options = ('any');
7641: if (ref($rules) eq 'HASH') {
7642: if (keys(%{$rules}) > 0) {
7643: push(@options,('official','unofficial'));
1.37 raeburn 7644: }
7645: }
1.160.6.34 raeburn 7646: push(@options,'none');
1.37 raeburn 7647: foreach my $option (@options) {
1.50 raeburn 7648: my $type = 'radio';
1.34 raeburn 7649: my $check = ' ';
1.160.6.34 raeburn 7650: if ($checked{$item} eq $option) {
7651: $check = ' checked="checked" ';
1.34 raeburn 7652: }
7653: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7654: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7655: $item.'" value="'.$option.'"'.$check.'/> '.
7656: $lt{$option}.'</label> </span>';
7657: }
7658: $datatable .= '</td></tr>';
7659: }
1.28 raeburn 7660: } else {
7661: my @contexts = ('author','course','domain');
7662: my @authtypes = ('int','krb4','krb5','loc');
7663: my %checked;
7664: if (ref($settings) eq 'HASH') {
7665: if (ref($settings->{'authtypes'}) eq 'HASH') {
7666: foreach my $item (@contexts) {
7667: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7668: foreach my $auth (@authtypes) {
7669: if ($settings->{'authtypes'}{$item}{$auth}) {
7670: $checked{$item}{$auth} = ' checked="checked" ';
7671: }
7672: }
7673: }
7674: }
1.27 raeburn 7675: }
1.35 raeburn 7676: } else {
7677: foreach my $item (@contexts) {
1.36 raeburn 7678: foreach my $auth (@authtypes) {
1.35 raeburn 7679: $checked{$item}{$auth} = ' checked="checked" ';
7680: }
7681: }
1.27 raeburn 7682: }
1.28 raeburn 7683: my %title = &context_names();
7684: my %authname = &authtype_names();
7685: my $rownum = 0;
7686: my $css_class;
7687: foreach my $item (@contexts) {
7688: if ($rownum%2) {
7689: $css_class = '';
7690: } else {
7691: $css_class = ' class="LC_odd_row" ';
7692: }
1.30 raeburn 7693: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7694: '<td>'.$title{$item}.
7695: '</td><td class="LC_left_item">'.
7696: '<span class="LC_nobreak">';
7697: foreach my $auth (@authtypes) {
7698: $datatable .= '<label>'.
7699: '<input type="checkbox" name="'.$item.'_auth" '.
7700: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7701: $authname{$auth}.'</label> ';
7702: }
7703: $datatable .= '</span></td></tr>';
7704: $rownum ++;
1.27 raeburn 7705: }
1.30 raeburn 7706: $$rowtotal += $rownum;
1.27 raeburn 7707: }
7708: return $datatable;
7709: }
7710:
1.160.6.34 raeburn 7711: sub print_selfcreation {
7712: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 7713: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7714: $emaildomain,$datatable);
1.160.6.34 raeburn 7715: if (ref($settings) eq 'HASH') {
7716: if (ref($settings->{'cancreate'}) eq 'HASH') {
7717: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 7718: if (ref($createsettings) eq 'HASH') {
7719: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7720: @selfcreate = @{$createsettings->{'selfcreate'}};
7721: } elsif ($createsettings->{'selfcreate'} ne '') {
7722: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7723: @selfcreate = ('email','login','sso');
7724: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7725: @selfcreate = ($createsettings->{'selfcreate'});
7726: }
7727: }
7728: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7729: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 7730: }
1.160.6.93 raeburn 7731: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7732: $emailoptions = $createsettings->{'emailoptions'};
7733: }
7734: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7735: $emailverified = $createsettings->{'emailverified'};
7736: }
7737: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7738: $emaildomain = $createsettings->{'emaildomain'};
7739: }
1.160.6.34 raeburn 7740: }
7741: }
7742: }
7743: my %radiohash;
7744: my $numinrow = 4;
7745: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 7746: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 7747: if ($position eq 'top') {
7748: my %choices = &Apache::lonlocal::texthash (
7749: cancreate_login => 'Institutional Login',
7750: cancreate_sso => 'Institutional Single Sign On',
7751: );
7752: my @toggles = sort(keys(%choices));
7753: my %defaultchecked = (
7754: 'cancreate_login' => 'off',
7755: 'cancreate_sso' => 'off',
7756: );
1.160.6.35 raeburn 7757: my ($onclick,$itemcount);
1.160.6.34 raeburn 7758: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7759: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 7760: $$rowtotal += $itemcount;
1.160.6.34 raeburn 7761:
7762: if (ref($usertypes) eq 'HASH') {
7763: if (keys(%{$usertypes}) > 0) {
7764: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7765: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 7766: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 7767: $$rowtotal ++;
7768: }
7769: }
1.160.6.44 raeburn 7770: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7771: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7772: $fieldtitles{'inststatus'} = &mt('Institutional status');
7773: my $rem;
7774: my $numperrow = 2;
7775: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7776: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 7777: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 7778: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 7779: '<table>'."\n";
1.160.6.44 raeburn 7780: for (my $i=0; $i<@fields; $i++) {
7781: $rem = $i%($numperrow);
7782: if ($rem == 0) {
7783: if ($i > 0) {
7784: $datatable .= '</tr>';
7785: }
7786: $datatable .= '<tr>';
7787: }
7788: my $currval;
1.160.6.51 raeburn 7789: if (ref($createsettings) eq 'HASH') {
7790: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7791: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7792: }
1.160.6.44 raeburn 7793: }
7794: $datatable .= '<td class="LC_left_item">'.
7795: '<span class="LC_nobreak">'.
7796: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7797: 'value="'.$currval.'" size="10" /> '.
7798: $fieldtitles{$fields[$i]}.'</span></td>';
7799: }
7800: my $colsleft = $numperrow - $rem;
7801: if ($colsleft > 1 ) {
7802: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7803: ' </td>';
7804: } elsif ($colsleft == 1) {
7805: $datatable .= '<td class="LC_left_item"> </td>';
7806: }
7807: $datatable .= '</tr></table></td></tr>';
7808: $$rowtotal ++;
1.160.6.34 raeburn 7809: } elsif ($position eq 'middle') {
7810: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 7811: my @posstypes;
1.160.6.34 raeburn 7812: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7813: @posstypes = @{$types};
7814: }
7815: unless (grep(/^default$/,@posstypes)) {
7816: push(@posstypes,'default');
7817: }
7818: my %usertypeshash;
7819: if (ref($usertypes) eq 'HASH') {
7820: %usertypeshash = %{$usertypes};
7821: }
7822: $usertypeshash{'default'} = $othertitle;
7823: foreach my $status (@posstypes) {
7824: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7825: $numinrow,$$rowtotal,\%usertypeshash);
7826: $$rowtotal ++;
1.160.6.34 raeburn 7827: }
7828: } else {
1.160.6.40 raeburn 7829: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 7830: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 7831: );
7832: my @toggles = sort(keys(%choices));
7833: my %defaultchecked = (
7834: 'cancreate_email' => 'off',
7835: );
1.160.6.93 raeburn 7836: my $customclass = 'LC_selfcreate_email';
7837: my $classprefix = 'LC_canmodify_emailusername_';
7838: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 7839: my $display = 'none';
1.160.6.93 raeburn 7840: my $rowstyle = 'display:none';
1.160.6.40 raeburn 7841: if (grep(/^\Qemail\E$/,@selfcreate)) {
7842: $display = 'block';
1.160.6.93 raeburn 7843: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 7844: }
1.160.6.93 raeburn 7845: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7846: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7847: \%choices,$$rowtotal,$onclick);
7848: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7849: $rowstyle);
7850: $$rowtotal ++;
7851: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7852: $rowstyle);
7853: $$rowtotal ++;
7854: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 7855: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 7856: my ($emailrules,$emailruleorder) =
7857: &Apache::lonnet::inst_userrules($dom,'email');
7858: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7859: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7860: if (ref($types) eq 'ARRAY') {
7861: @posstypes = @{$types};
7862: }
7863: if (@posstypes) {
7864: unless (grep(/^default$/,@posstypes)) {
7865: push(@posstypes,'default');
1.160.6.89 raeburn 7866: }
7867: if (ref($usertypes) eq 'HASH') {
7868: %usertypeshash = %{$usertypes};
7869: }
1.160.6.93 raeburn 7870: my $currassign;
7871: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7872: $currassign = {
7873: selfassign => $domdefaults{'inststatusguest'},
7874: };
7875: @ordered = @{$domdefaults{'inststatusguest'}};
7876: } else {
7877: $currassign = { selfassign => [] };
7878: }
7879: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7880: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7881: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7882: $numinrow,$othertitle,'selfassign',
7883: $rowtotal,$onclicktypes,$customclass,
7884: $rowstyle);
7885: $$rowtotal ++;
1.160.6.89 raeburn 7886: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7887: foreach my $status (@posstypes) {
7888: my $css_class;
7889: if ($$rowtotal%2) {
7890: $css_class = 'LC_odd_row ';
7891: }
7892: $css_class .= $customclass;
7893: my $rowid = $optionsprefix.$status;
7894: my $hidden = 1;
7895: my $currstyle = 'display:none';
7896: if (grep(/^\Q$status\E$/,@ordered)) {
7897: $currstyle = $rowstyle;
7898: $hidden = 0;
7899: }
7900: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7901: $emailrules,$emailruleorder,$settings,$status,$rowid,
7902: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7903: unless ($hidden) {
7904: $$rowtotal ++;
7905: }
1.160.6.89 raeburn 7906: }
7907: } else {
1.160.6.93 raeburn 7908: my $css_class;
7909: if ($$rowtotal%2) {
7910: $css_class = 'LC_odd_row ';
7911: }
7912: $css_class .= $customclass;
1.160.6.89 raeburn 7913: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7914: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7915: $emailrules,$emailruleorder,$settings,'default','',
7916: $othertitle,$css_class,$rowstyle,$intdom);
7917: $$rowtotal ++;
1.160.6.34 raeburn 7918: }
1.160.6.35 raeburn 7919: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7920: $numinrow = 1;
1.160.6.93 raeburn 7921: if (@posstypes) {
7922: foreach my $status (@posstypes) {
7923: my $rowid = $classprefix.$status;
7924: my $datarowstyle = 'display:none';
7925: if (grep(/^\Q$status\E$/,@ordered)) {
7926: $datarowstyle = $rowstyle;
7927: }
7928: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7929: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7930: $infotitles,$rowid,$customclass,$datarowstyle);
7931: unless ($datarowstyle eq 'display:none') {
7932: $$rowtotal ++;
7933: }
1.160.6.34 raeburn 7934: }
1.160.6.93 raeburn 7935: } else {
7936: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7937: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7938: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7939: }
7940: }
7941: return $datatable;
7942: }
7943:
1.160.6.93 raeburn 7944: sub selfcreate_javascript {
7945: return <<"ENDSCRIPT";
7946:
7947: <script type="text/javascript">
7948: // <![CDATA[
7949:
7950: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7951: var x = document.getElementsByClassName(target);
7952: var insttypes = 0;
7953: var insttypeRegExp = new RegExp(prefix);
7954: if ((x.length != undefined) && (x.length > 0)) {
7955: if (form.elements[radio].length != undefined) {
7956: for (var i=0; i<form.elements[radio].length; i++) {
7957: if (form.elements[radio][i].checked) {
7958: if (form.elements[radio][i].value == 1) {
7959: for (var j=0; j<x.length; j++) {
7960: if (x[j].id == 'undefined') {
7961: x[j].style.display = 'table-row';
7962: } else if (insttypeRegExp.test(x[j].id)) {
7963: insttypes ++;
7964: } else {
7965: x[j].style.display = 'table-row';
7966: }
7967: }
7968: } else {
7969: for (var j=0; j<x.length; j++) {
7970: x[j].style.display = 'none';
7971: }
1.160.6.40 raeburn 7972: }
1.160.6.93 raeburn 7973: break;
7974: }
7975: }
7976: if (insttypes > 0) {
7977: toggleDataRow(form,checkbox,target,altprefix);
7978: toggleDataRow(form,checkbox,target,prefix,1);
7979: }
7980: }
7981: }
7982: return;
7983: }
7984:
7985: function toggleDataRow(form,checkbox,target,prefix,docount) {
7986: if (form.elements[checkbox].length != undefined) {
7987: var count = 0;
7988: if (docount) {
7989: for (var i=0; i<form.elements[checkbox].length; i++) {
7990: if (form.elements[checkbox][i].checked) {
7991: count ++;
7992: }
7993: }
7994: }
7995: for (var i=0; i<form.elements[checkbox].length; i++) {
7996: var type = form.elements[checkbox][i].value;
7997: if (document.getElementById(prefix+type)) {
7998: if (form.elements[checkbox][i].checked) {
7999: document.getElementById(prefix+type).style.display = 'table-row';
8000: if (count % 2 == 1) {
8001: document.getElementById(prefix+type).className = target+' LC_odd_row';
8002: } else {
8003: document.getElementById(prefix+type).className = target;
8004: }
8005: count ++;
1.160.6.40 raeburn 8006: } else {
1.160.6.93 raeburn 8007: document.getElementById(prefix+type).style.display = 'none';
8008: }
8009: }
8010: }
8011: }
8012: return;
8013: }
8014:
8015: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8016: var caller = radio+'_'+status;
8017: if (form.elements[caller].length != undefined) {
8018: for (var i=0; i<form.elements[caller].length; i++) {
8019: if (form.elements[caller][i].checked) {
8020: if (document.getElementById(altprefix+'_inst_'+status)) {
8021: var curr = form.elements[caller][i].value;
8022: if (prefix) {
8023: document.getElementById(prefix+'_'+status).style.display = 'none';
8024: }
8025: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8026: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8027: if (curr == 'custom') {
8028: if (prefix) {
8029: document.getElementById(prefix+'_'+status).style.display = 'inline';
8030: }
8031: } else if (curr == 'inst') {
8032: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8033: } else if (curr == 'noninst') {
8034: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 8035: }
1.160.6.93 raeburn 8036: break;
1.160.6.40 raeburn 8037: }
1.160.6.93 raeburn 8038: }
8039: }
8040: }
8041: }
8042:
8043: // ]]>
8044: </script>
8045:
8046: ENDSCRIPT
8047: }
8048:
8049: sub noninst_users {
8050: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8051: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8052: my $class = 'LC_left_item';
8053: if ($css_class) {
8054: $css_class = ' class="'.$css_class.'"';
8055: }
8056: if ($rowid) {
8057: $rowid = ' id="'.$rowid.'"';
8058: }
8059: if ($rowstyle) {
8060: $rowstyle = ' style="'.$rowstyle.'"';
8061: }
8062: my ($output,$description);
8063: if ($type eq 'default') {
8064: $description = &mt('Requests for: [_1]',$typetitle);
8065: } else {
8066: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8067: }
8068: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8069: "<td>$description</td>\n".
8070: '<td class="'.$class.'" colspan="2">'.
8071: '<table><tr>';
8072: my %headers = &Apache::lonlocal::texthash(
8073: approve => 'Processing',
8074: email => 'E-mail',
8075: username => 'Username',
8076: );
8077: foreach my $item ('approve','email','username') {
8078: $output .= '<th>'.$headers{$item}.'</th>';
8079: }
8080: $output .= '</tr><tr>';
8081: foreach my $item ('approve','email','username') {
8082: $output .= '<td valign="top">';
8083: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8084: if ($item eq 'approve') {
8085: %choices = &Apache::lonlocal::texthash (
8086: automatic => 'Automatically approved',
8087: approval => 'Queued for approval',
8088: );
8089: @options = ('automatic','approval');
8090: $hashref = $processing;
8091: $defoption = 'automatic';
8092: $name = 'cancreate_emailprocess_'.$type;
8093: } elsif ($item eq 'email') {
8094: %choices = &Apache::lonlocal::texthash (
8095: any => 'Any e-mail',
8096: inst => 'Institutional only',
8097: noninst => 'Non-institutional only',
8098: custom => 'Custom restrictions',
8099: );
8100: @options = ('any','inst','noninst');
8101: my $showcustom;
8102: if (ref($emailrules) eq 'HASH') {
8103: if (keys(%{$emailrules}) > 0) {
8104: push(@options,'custom');
8105: $showcustom = 'cancreate_emailrule';
8106: if (ref($settings) eq 'HASH') {
8107: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8108: foreach my $rule (@{$settings->{'email_rule'}}) {
8109: if (exists($emailrules->{$rule})) {
8110: $hascustom ++;
8111: }
8112: }
8113: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8114: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8115: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8116: if (exists($emailrules->{$rule})) {
8117: $hascustom ++;
8118: }
8119: }
8120: }
8121: }
8122: }
8123: }
8124: }
8125: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8126: "'cancreate_emaildomain','$type'".');"';
8127: $hashref = $emailoptions;
8128: $defoption = 'any';
8129: $name = 'cancreate_emailoptions_'.$type;
8130: } elsif ($item eq 'username') {
8131: %choices = &Apache::lonlocal::texthash (
8132: all => 'Same as e-mail',
8133: first => 'Omit @domain',
8134: free => 'Free to choose',
8135: );
8136: @options = ('all','first','free');
8137: $hashref = $emailverified;
8138: $defoption = 'all';
8139: $name = 'cancreate_usernameoptions_'.$type;
8140: }
8141: foreach my $option (@options) {
8142: my $checked;
8143: if (ref($hashref) eq 'HASH') {
8144: if ($type eq '') {
8145: if (!exists($hashref->{'default'})) {
8146: if ($option eq $defoption) {
8147: $checked = ' checked="checked"';
8148: }
8149: } else {
8150: if ($hashref->{'default'} eq $option) {
8151: $checked = ' checked="checked"';
8152: }
1.160.6.40 raeburn 8153: }
8154: } else {
1.160.6.93 raeburn 8155: if (!exists($hashref->{$type})) {
8156: if ($option eq $defoption) {
8157: $checked = ' checked="checked"';
8158: }
8159: } else {
8160: if ($hashref->{$type} eq $option) {
8161: $checked = ' checked="checked"';
8162: }
1.160.6.40 raeburn 8163: }
8164: }
1.160.6.93 raeburn 8165: } elsif (($item eq 'email') && ($hascustom)) {
8166: if ($option eq 'custom') {
8167: $checked = ' checked="checked"';
8168: }
8169: } elsif ($option eq $defoption) {
8170: $checked = ' checked="checked"';
8171: }
8172: $output .= '<span class="LC_nobreak"><label>'.
8173: '<input type="radio" name="'.$name.'"'.
8174: $checked.' value="'.$option.'"'.$onclick.' />'.
8175: $choices{$option}.'</label></span><br />';
8176: if ($item eq 'email') {
8177: if ($option eq 'custom') {
8178: my $id = 'cancreate_emailrule_'.$type;
8179: my $display = 'none';
8180: if ($checked) {
8181: $display = 'inline';
8182: }
8183: my $numinrow = 2;
8184: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8185: '<legend>'.&mt('Disallow').'</legend><table>'.
8186: &user_formats_row('email',$settings,$emailrules,
8187: $emailruleorder,$numinrow,'',$type);
8188: '</table></fieldset>';
8189: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8190: my %text = &Apache::lonlocal::texthash (
8191: inst => 'must end:',
8192: noninst => 'cannot end:',
8193: );
8194: my $value;
8195: if (ref($emaildomain) eq 'HASH') {
8196: if (ref($emaildomain->{$type}) eq 'HASH') {
8197: $value = $emaildomain->{$type}->{$option};
8198: }
8199: }
8200: if ($value eq '') {
8201: $value = '@'.$intdom;
8202: }
8203: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8204: my $display = 'none';
8205: if ($checked) {
8206: $display = 'inline';
8207: }
8208: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8209: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8210: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8211: '</div>';
8212: }
1.160.6.40 raeburn 8213: }
8214: }
1.160.6.93 raeburn 8215: $output .= '</td>'."\n";
1.160.6.40 raeburn 8216: }
1.160.6.93 raeburn 8217: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 8218: return $output;
8219: }
8220:
1.160.6.5 raeburn 8221: sub captcha_choice {
1.160.6.93 raeburn 8222: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 8223: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8224: $vertext,$currver);
1.160.6.5 raeburn 8225: my %lt = &captcha_phrases();
8226: $keyentry = 'hidden';
1.160.6.98 raeburn 8227: my $colspan=2;
1.160.6.5 raeburn 8228: if ($context eq 'cancreate') {
1.160.6.34 raeburn 8229: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 8230: } elsif ($context eq 'login') {
8231: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 8232: } elsif ($context eq 'passwords') {
8233: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8234: $colspan=1;
1.160.6.5 raeburn 8235: }
8236: if (ref($settings) eq 'HASH') {
8237: if ($settings->{'captcha'}) {
8238: $checked{$settings->{'captcha'}} = ' checked="checked"';
8239: } else {
8240: $checked{'original'} = ' checked="checked"';
8241: }
8242: if ($settings->{'captcha'} eq 'recaptcha') {
8243: $pubtext = $lt{'pub'};
8244: $privtext = $lt{'priv'};
8245: $keyentry = 'text';
1.160.6.69 raeburn 8246: $vertext = $lt{'ver'};
8247: $currver = $settings->{'recaptchaversion'};
8248: if ($currver ne '2') {
8249: $currver = 1;
8250: }
1.160.6.5 raeburn 8251: }
8252: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8253: $currpub = $settings->{'recaptchakeys'}{'public'};
8254: $currpriv = $settings->{'recaptchakeys'}{'private'};
8255: }
8256: } else {
8257: $checked{'original'} = ' checked="checked"';
8258: }
1.160.6.93 raeburn 8259: my $css_class;
8260: if ($itemcount%2) {
8261: $css_class = 'LC_odd_row';
8262: }
8263: if ($customcss) {
8264: $css_class .= " $customcss";
8265: }
8266: $css_class =~ s/^\s+//;
8267: if ($css_class) {
8268: $css_class = ' class="'.$css_class.'"';
8269: }
8270: if ($rowstyle) {
8271: $css_class .= ' style="'.$rowstyle.'"';
8272: }
1.160.6.5 raeburn 8273: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 8274: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 8275: '<table><tr><td>'."\n";
8276: foreach my $option ('original','recaptcha','notused') {
8277: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8278: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8279: $lt{$option}.'</label></span>';
8280: unless ($option eq 'notused') {
8281: $output .= (' 'x2)."\n";
8282: }
8283: }
8284: #
8285: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8286: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8287: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8288: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8289: #
8290: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 8291: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 8292: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8293: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8294: $currpub.'" size="40" /></span><br />'."\n".
8295: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8296: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 8297: $currpriv.'" size="40" /></span><br />'.
8298: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8299: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8300: $currver.'" size="3" /></span><br />'.
8301: '</td></tr></table>'."\n".
1.160.6.5 raeburn 8302: '</td></tr>';
8303: return $output;
8304: }
8305:
1.32 raeburn 8306: sub user_formats_row {
1.160.6.93 raeburn 8307: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8308: my $output;
8309: my %text = (
8310: 'username' => 'new usernames',
8311: 'id' => 'IDs',
8312: );
1.160.6.93 raeburn 8313: unless ($type eq 'email') {
8314: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8315: $output = '<tr '.$css_class.'>'.
8316: '<td><span class="LC_nobreak">'.
8317: &mt("Format rules to check for $text{$type}: ").
8318: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8319: }
1.27 raeburn 8320: my $rem;
8321: if (ref($ruleorder) eq 'ARRAY') {
8322: for (my $i=0; $i<@{$ruleorder}; $i++) {
8323: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8324: my $rem = $i%($numinrow);
8325: if ($rem == 0) {
8326: if ($i > 0) {
8327: $output .= '</tr>';
8328: }
8329: $output .= '<tr>';
8330: }
8331: my $check = ' ';
1.39 raeburn 8332: if (ref($settings) eq 'HASH') {
8333: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8334: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8335: $check = ' checked="checked" ';
8336: }
1.160.6.93 raeburn 8337: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8338: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8339: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8340: $check = ' checked="checked" ';
8341: }
8342: }
1.27 raeburn 8343: }
8344: }
1.160.6.93 raeburn 8345: my $name = $type.'_rule';
8346: if ($type eq 'email') {
8347: $name .= '_'.$status;
8348: }
1.27 raeburn 8349: $output .= '<td class="LC_left_item">'.
8350: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 8351: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8352: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8353: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8354: }
8355: }
8356: $rem = @{$ruleorder}%($numinrow);
8357: }
1.160.6.93 raeburn 8358: my $colsleft;
8359: if ($rem) {
8360: $colsleft = $numinrow - $rem;
8361: }
1.27 raeburn 8362: if ($colsleft > 1 ) {
8363: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8364: ' </td>';
8365: } elsif ($colsleft == 1) {
8366: $output .= '<td class="LC_left_item"> </td>';
8367: }
1.160.6.93 raeburn 8368: $output .= '</tr></table>';
8369: unless ($type eq 'email') {
8370: $output .= '</td></tr>';
8371: }
1.27 raeburn 8372: return $output;
8373: }
8374:
1.34 raeburn 8375: sub usercreation_types {
8376: my %lt = &Apache::lonlocal::texthash (
8377: author => 'When adding a co-author',
8378: course => 'When adding a user to a course',
1.100 raeburn 8379: requestcrs => 'When requesting a course',
1.34 raeburn 8380: any => 'Any',
8381: official => 'Institutional only ',
8382: unofficial => 'Non-institutional only',
8383: none => 'None',
8384: );
8385: return %lt;
1.48 raeburn 8386: }
1.34 raeburn 8387:
1.160.6.34 raeburn 8388: sub selfcreation_types {
8389: my %lt = &Apache::lonlocal::texthash (
8390: selfcreate => 'User creates own account',
8391: any => 'Any',
8392: official => 'Institutional only ',
8393: unofficial => 'Non-institutional only',
8394: email => 'E-mail address',
8395: login => 'Institutional Login',
8396: sso => 'SSO',
8397: );
8398: }
8399:
1.28 raeburn 8400: sub authtype_names {
8401: my %lt = &Apache::lonlocal::texthash(
8402: int => 'Internal',
8403: krb4 => 'Kerberos 4',
8404: krb5 => 'Kerberos 5',
8405: loc => 'Local',
8406: );
8407: return %lt;
8408: }
8409:
8410: sub context_names {
8411: my %context_title = &Apache::lonlocal::texthash(
8412: author => 'Creating users when an Author',
8413: course => 'Creating users when in a course',
8414: domain => 'Creating users when a Domain Coordinator',
8415: );
8416: return %context_title;
8417: }
8418:
1.33 raeburn 8419: sub print_usermodification {
8420: my ($position,$dom,$settings,$rowtotal) = @_;
8421: my $numinrow = 4;
8422: my ($context,$datatable,$rowcount);
8423: if ($position eq 'top') {
8424: $rowcount = 0;
8425: $context = 'author';
8426: foreach my $role ('ca','aa') {
8427: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8428: $numinrow,$rowcount);
8429: $$rowtotal ++;
8430: $rowcount ++;
8431: }
1.160.6.37 raeburn 8432: } elsif ($position eq 'bottom') {
1.33 raeburn 8433: $context = 'course';
8434: $rowcount = 0;
8435: foreach my $role ('st','ep','ta','in','cr') {
8436: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8437: $numinrow,$rowcount);
8438: $$rowtotal ++;
8439: $rowcount ++;
8440: }
8441: }
8442: return $datatable;
8443: }
8444:
1.43 raeburn 8445: sub print_defaults {
1.160.6.40 raeburn 8446: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8447: my $rownum = 0;
1.160.6.80 raeburn 8448: my ($datatable,$css_class,$titles);
8449: unless ($position eq 'bottom') {
8450: $titles = &defaults_titles($dom);
8451: }
1.160.6.40 raeburn 8452: if ($position eq 'top') {
8453: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8454: 'datelocale_def','portal_def');
8455: my %defaults;
8456: if (ref($settings) eq 'HASH') {
8457: %defaults = %{$settings};
1.43 raeburn 8458: } else {
1.160.6.40 raeburn 8459: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8460: foreach my $item (@items) {
8461: $defaults{$item} = $domdefaults{$item};
8462: }
1.43 raeburn 8463: }
1.160.6.40 raeburn 8464: foreach my $item (@items) {
8465: if ($rownum%2) {
8466: $css_class = '';
8467: } else {
8468: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 8469: }
1.160.6.40 raeburn 8470: $datatable .= '<tr'.$css_class.'>'.
8471: '<td><span class="LC_nobreak">'.$titles->{$item}.
8472: '</span></td><td class="LC_right_item" colspan="3">';
8473: if ($item eq 'auth_def') {
8474: my @authtypes = ('internal','krb4','krb5','localauth');
8475: my %shortauth = (
8476: internal => 'int',
8477: krb4 => 'krb4',
8478: krb5 => 'krb5',
8479: localauth => 'loc'
8480: );
8481: my %authnames = &authtype_names();
8482: foreach my $auth (@authtypes) {
8483: my $checked = ' ';
8484: if ($defaults{$item} eq $auth) {
8485: $checked = ' checked="checked" ';
8486: }
8487: $datatable .= '<label><input type="radio" name="'.$item.
8488: '" value="'.$auth.'"'.$checked.'/>'.
8489: $authnames{$shortauth{$auth}}.'</label> ';
8490: }
8491: } elsif ($item eq 'timezone_def') {
8492: my $includeempty = 1;
8493: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8494: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 8495: my $includeempty = 1;
8496: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8497: } elsif ($item eq 'lang_def') {
8498: my $includeempty = 1;
8499: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 8500: } else {
1.160.6.98 raeburn 8501: my $size;
8502: if ($item eq 'portal_def') {
8503: $size = ' size="25"';
8504: }
1.160.6.80 raeburn 8505: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 8506: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 8507: }
8508: $datatable .= '</td></tr>';
8509: $rownum ++;
8510: }
1.160.6.40 raeburn 8511: } else {
1.160.6.80 raeburn 8512: my %defaults;
1.160.6.40 raeburn 8513: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 8514: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 8515: my $maxnum = @{$settings->{'inststatusorder'}};
8516: for (my $i=0; $i<$maxnum; $i++) {
8517: $css_class = $rownum%2?' class="LC_odd_row"':'';
8518: my $item = $settings->{'inststatusorder'}->[$i];
8519: my $title = $settings->{'inststatustypes'}->{$item};
8520: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8521: $datatable .= '<tr'.$css_class.'>'.
8522: '<td><span class="LC_nobreak">'.
8523: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8524: for (my $k=0; $k<=$maxnum; $k++) {
8525: my $vpos = $k+1;
8526: my $selstr;
8527: if ($k == $i) {
8528: $selstr = ' selected="selected" ';
8529: }
8530: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8531: }
8532: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8533: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8534: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 8535: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 8536: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 8537: '</span></td></tr>';
1.160.6.40 raeburn 8538: }
8539: $css_class = $rownum%2?' class="LC_odd_row"':'';
8540: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8541: $datatable .= '<tr '.$css_class.'>'.
8542: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8543: for (my $k=0; $k<=$maxnum; $k++) {
8544: my $vpos = $k+1;
8545: my $selstr;
8546: if ($k == $maxnum) {
8547: $selstr = ' selected="selected" ';
8548: }
8549: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8550: }
8551: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 8552: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 8553: ' '.&mt('(new)').
8554: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 8555: &mt('Name displayed').':'.
1.160.6.40 raeburn 8556: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8557: '</tr>'."\n";
8558: $rownum ++;
1.141 raeburn 8559: }
1.43 raeburn 8560: }
8561: }
8562: $$rowtotal += $rownum;
8563: return $datatable;
8564: }
8565:
1.160.6.5 raeburn 8566: sub get_languages_hash {
8567: my %langchoices;
8568: foreach my $id (&Apache::loncommon::languageids()) {
8569: my $code = &Apache::loncommon::supportedlanguagecode($id);
8570: if ($code ne '') {
8571: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8572: }
8573: }
8574: return %langchoices;
8575: }
8576:
1.43 raeburn 8577: sub defaults_titles {
1.141 raeburn 8578: my ($dom) = @_;
1.43 raeburn 8579: my %titles = &Apache::lonlocal::texthash (
8580: 'auth_def' => 'Default authentication type',
8581: 'auth_arg_def' => 'Default authentication argument',
8582: 'lang_def' => 'Default language',
1.54 raeburn 8583: 'timezone_def' => 'Default timezone',
1.68 raeburn 8584: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8585: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 8586: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8587: 'intauth_check' => 'Check bcrypt cost if authenticated',
8588: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8589: );
1.141 raeburn 8590: if ($dom) {
8591: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8592: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8593: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8594: $protocol = 'http' if ($protocol ne 'https');
8595: if ($uint_dom) {
8596: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8597: $uint_dom);
8598: }
8599: }
1.43 raeburn 8600: return (\%titles);
8601: }
8602:
1.160.6.97 raeburn 8603: sub print_scantron {
8604: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8605: if ($position eq 'top') {
8606: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8607: } else {
8608: return &print_scantronconfig($dom,$settings,\$rowtotal);
8609: }
8610: }
8611:
8612: sub scantron_javascript {
8613: return <<"ENDSCRIPT";
8614:
8615: <script type="text/javascript">
8616: // <![CDATA[
8617:
8618: function toggleScantron(form) {
8619: var csvfieldset = new Array();
8620: if (document.getElementById('scantroncsv_cols')) {
8621: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8622: }
8623: if (document.getElementById('scantroncsv_options')) {
8624: csvfieldset.push(document.getElementById('scantroncsv_options'));
8625: }
8626: if (csvfieldset.length) {
8627: if (document.getElementById('scantronconfcsv')) {
8628: var scantroncsv = document.getElementById('scantronconfcsv');
8629: if (scantroncsv.checked) {
8630: for (var i=0; i<csvfieldset.length; i++) {
8631: csvfieldset[i].style.display = 'block';
8632: }
8633: } else {
8634: for (var i=0; i<csvfieldset.length; i++) {
8635: csvfieldset[i].style.display = 'none';
8636: }
8637: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8638: if (csvselects.length) {
8639: for (var j=0; j<csvselects.length; j++) {
8640: csvselects[j].selectedIndex = 0;
8641: }
8642: }
8643: }
8644: }
8645: }
8646: return;
8647: }
8648: // ]]>
8649: </script>
8650:
8651: ENDSCRIPT
8652:
8653: }
8654:
1.46 raeburn 8655: sub print_scantronformat {
8656: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8657: my $itemcount = 1;
1.60 raeburn 8658: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8659: %confhash);
1.46 raeburn 8660: my $switchserver = &check_switchserver($dom,$confname);
8661: my %lt = &Apache::lonlocal::texthash (
1.95 www 8662: default => 'Default bubblesheet format file error',
8663: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8664: );
8665: my %scantronfiles = (
8666: default => 'default.tab',
8667: custom => 'custom.tab',
8668: );
8669: foreach my $key (keys(%scantronfiles)) {
8670: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8671: .$scantronfiles{$key};
8672: }
8673: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8674: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8675: if (!$switchserver) {
8676: my $servadm = $r->dir_config('lonAdmEMail');
8677: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8678: if ($configuserok eq 'ok') {
8679: if ($author_ok eq 'ok') {
8680: my %legacyfile = (
1.160.6.97 raeburn 8681: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8682: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8683: );
8684: my %md5chk;
8685: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8686: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8687: chomp($md5chk{$type});
1.46 raeburn 8688: }
8689: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8690: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 8691: ($scantronurls{$type},my $error) =
1.46 raeburn 8692: &legacy_scantronformat($r,$dom,$confname,
8693: $type,$legacyfile{$type},
8694: $scantronurls{$type},
8695: $scantronfiles{$type});
1.60 raeburn 8696: if ($error ne '') {
8697: $error{$type} = $error;
8698: }
8699: }
8700: if (keys(%error) == 0) {
8701: $is_custom = 1;
1.160.6.97 raeburn 8702: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8703: $scantronurls{'custom'};
1.160.6.97 raeburn 8704: my $putresult =
1.60 raeburn 8705: &Apache::lonnet::put_dom('configuration',
8706: \%confhash,$dom);
8707: if ($putresult ne 'ok') {
1.160.6.97 raeburn 8708: $error{'custom'} =
1.60 raeburn 8709: '<span class="LC_error">'.
8710: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8711: }
1.46 raeburn 8712: }
8713: } else {
1.60 raeburn 8714: ($scantronurls{'default'},my $error) =
1.46 raeburn 8715: &legacy_scantronformat($r,$dom,$confname,
8716: 'default',$legacyfile{'default'},
8717: $scantronurls{'default'},
8718: $scantronfiles{'default'});
1.60 raeburn 8719: if ($error eq '') {
8720: $confhash{'scantron'}{'scantronformat'} = '';
8721: my $putresult =
8722: &Apache::lonnet::put_dom('configuration',
8723: \%confhash,$dom);
8724: if ($putresult ne 'ok') {
8725: $error{'default'} =
8726: '<span class="LC_error">'.
8727: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8728: }
8729: } else {
8730: $error{'default'} = $error;
8731: }
1.46 raeburn 8732: }
8733: }
8734: }
8735: } else {
1.95 www 8736: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8737: }
8738: }
8739: if (ref($settings) eq 'HASH') {
8740: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8741: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8742: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8743: $scantronurl = '';
8744: } else {
8745: $scantronurl = $settings->{'scantronformat'};
8746: }
8747: $is_custom = 1;
8748: } else {
8749: $scantronurl = $scantronurls{'default'};
8750: }
8751: } else {
1.60 raeburn 8752: if ($is_custom) {
8753: $scantronurl = $scantronurls{'custom'};
8754: } else {
8755: $scantronurl = $scantronurls{'default'};
8756: }
1.46 raeburn 8757: }
8758: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8759: $datatable .= '<tr'.$css_class.'>';
8760: if (!$is_custom) {
1.65 raeburn 8761: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8762: '<span class="LC_nobreak">';
1.46 raeburn 8763: if ($scantronurl) {
1.160.6.21 raeburn 8764: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8765: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8766: } else {
8767: $datatable = &mt('File unavailable for display');
8768: }
1.65 raeburn 8769: $datatable .= '</span></td>';
1.60 raeburn 8770: if (keys(%error) == 0) {
8771: $datatable .= '<td valign="bottom">';
8772: if (!$switchserver) {
8773: $datatable .= &mt('Upload:').'<br />';
8774: }
8775: } else {
8776: my $errorstr;
8777: foreach my $key (sort(keys(%error))) {
8778: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8779: }
8780: $datatable .= '<td>'.$errorstr;
8781: }
1.46 raeburn 8782: } else {
8783: if (keys(%error) > 0) {
8784: my $errorstr;
8785: foreach my $key (sort(keys(%error))) {
8786: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8787: }
1.60 raeburn 8788: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8789: } elsif ($scantronurl) {
1.160.6.26 raeburn 8790: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 8791: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8792: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 8793: $link.
8794: '<label><input type="checkbox" name="scantronformat_del"'.
8795: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8796: '<td><span class="LC_nobreak"> '.
8797: &mt('Replace:').'</span><br />';
1.46 raeburn 8798: }
8799: }
8800: if (keys(%error) == 0) {
8801: if ($switchserver) {
8802: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8803: } else {
1.65 raeburn 8804: $datatable .='<span class="LC_nobreak"> '.
8805: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8806: }
8807: }
8808: $datatable .= '</td></tr>';
8809: $$rowtotal ++;
8810: return $datatable;
8811: }
8812:
8813: sub legacy_scantronformat {
8814: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8815: my ($url,$error);
8816: my @statinfo = &Apache::lonnet::stat_file($newurl);
8817: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8818: (my $result,$url) =
8819: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8820: '','',$newfile);
8821: if ($result ne 'ok') {
1.130 raeburn 8822: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8823: }
8824: }
8825: return ($url,$error);
8826: }
1.43 raeburn 8827:
1.160.6.97 raeburn 8828: sub print_scantronconfig {
8829: my ($dom,$settings,$rowtotal) = @_;
8830: my $itemcount = 2;
8831: my $is_checked = ' checked="checked"';
8832: my %optionson = (
8833: hdr => ' checked="checked"',
8834: pad => ' checked="checked"',
8835: rem => ' checked="checked"',
8836: );
8837: my %optionsoff = (
8838: hdr => '',
8839: pad => '',
8840: rem => '',
8841: );
8842: my $currcsvsty = 'none';
8843: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8844: my @fields = &scantroncsv_fields();
8845: my %titles = &scantronconfig_titles();
8846: if (ref($settings) eq 'HASH') {
8847: if (ref($settings->{config}) eq 'HASH') {
8848: if ($settings->{config}->{dat}) {
8849: $checked{'dat'} = $is_checked;
8850: }
8851: if (ref($settings->{config}->{csv}) eq 'HASH') {
8852: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8853: %csvfields = %{$settings->{config}->{csv}->{fields}};
8854: if (keys(%csvfields) > 0) {
8855: $checked{'csv'} = $is_checked;
8856: $currcsvsty = 'block';
8857: }
8858: }
8859: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8860: %csvoptions = %{$settings->{config}->{csv}->{options}};
8861: foreach my $option (keys(%optionson)) {
8862: unless ($csvoptions{$option}) {
8863: $optionsoff{$option} = $optionson{$option};
8864: $optionson{$option} = '';
8865: }
8866: }
8867: }
8868: }
8869: } else {
8870: $checked{'dat'} = $is_checked;
8871: }
8872: } else {
8873: $checked{'dat'} = $is_checked;
8874: }
8875: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8876: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8877: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8878: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8879: foreach my $item ('dat','csv') {
8880: my $id;
8881: if ($item eq 'csv') {
8882: $id = 'id="scantronconfcsv" ';
8883: }
8884: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8885: $titles{$item}.'</label>'.(' 'x3);
8886: if ($item eq 'csv') {
8887: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8888: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8889: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8890: foreach my $col (@fields) {
8891: my $selnone;
8892: if ($csvfields{$col} eq '') {
8893: $selnone = ' selected="selected"';
8894: }
8895: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8896: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8897: '<option value=""'.$selnone.'></option>';
8898: for (my $i=0; $i<20; $i++) {
8899: my $shown = $i+1;
8900: my $sel;
8901: unless ($selnone) {
8902: if (exists($csvfields{$col})) {
8903: if ($csvfields{$col} == $i) {
8904: $sel = ' selected="selected"';
8905: }
8906: }
8907: }
8908: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8909: }
8910: $datatable .= '</select></td></tr>';
8911: }
8912: $datatable .= '</table></fieldset>'.
8913: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8914: '<legend>'.&mt('CSV Options').'</legend>';
8915: foreach my $option ('hdr','pad','rem') {
8916: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8917: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8918: &mt('Yes').'</label>'.(' 'x2)."\n".
8919: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8920: }
8921: $datatable .= '</fieldset>';
8922: $itemcount ++;
8923: }
8924: }
8925: $datatable .= '</td></tr>';
8926: $$rowtotal ++;
8927: return $datatable;
8928: }
8929:
8930: sub scantronconfig_titles {
8931: return &Apache::lonlocal::texthash(
8932: dat => 'Standard format (.dat)',
8933: csv => 'Comma separated values (.csv)',
8934: hdr => 'Remove first line in file (contains column titles)',
8935: pad => 'Prepend 0s to PaperID',
8936: rem => 'Remove leading spaces (except Question Response columns)',
8937: CODE => 'CODE',
8938: ID => 'Student ID',
8939: PaperID => 'Paper ID',
8940: FirstName => 'First Name',
8941: LastName => 'Last Name',
8942: FirstQuestion => 'First Question Response',
8943: Section => 'Section',
8944: );
8945: }
8946:
8947: sub scantroncsv_fields {
8948: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8949: }
8950:
1.49 raeburn 8951: sub print_coursecategories {
1.57 raeburn 8952: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8953: my $datatable;
8954: if ($position eq 'top') {
1.160.6.42 raeburn 8955: my (%checked);
8956: my @catitems = ('unauth','auth');
8957: my @cattypes = ('std','domonly','codesrch','none');
8958: $checked{'unauth'} = 'std';
8959: $checked{'auth'} = 'std';
8960: if (ref($settings) eq 'HASH') {
8961: foreach my $type (@cattypes) {
8962: if ($type eq $settings->{'unauth'}) {
8963: $checked{'unauth'} = $type;
8964: }
8965: if ($type eq $settings->{'auth'}) {
8966: $checked{'auth'} = $type;
8967: }
8968: }
8969: }
8970: my %lt = &Apache::lonlocal::texthash (
8971: unauth => 'Catalog type for unauthenticated users',
8972: auth => 'Catalog type for authenticated users',
8973: none => 'No catalog',
8974: std => 'Standard catalog',
8975: domonly => 'Domain-only catalog',
8976: codesrch => "Code search form",
8977: );
8978: my $itemcount = 0;
8979: foreach my $item (@catitems) {
8980: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8981: $datatable .= '<tr '.$css_class.'>'.
8982: '<td>'.$lt{$item}.'</td>'.
8983: '<td class="LC_right_item"><span class="LC_nobreak">';
8984: foreach my $type (@cattypes) {
8985: my $ischecked;
8986: if ($checked{$item} eq $type) {
8987: $ischecked=' checked="checked"';
8988: }
8989: $datatable .= '<label>'.
8990: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8991: ' />'.$lt{$type}.'</label> ';
8992: }
1.160.6.87 raeburn 8993: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8994: $itemcount ++;
8995: }
8996: $$rowtotal += $itemcount;
8997: } elsif ($position eq 'middle') {
1.57 raeburn 8998: my $toggle_cats_crs = ' ';
8999: my $toggle_cats_dom = ' checked="checked" ';
9000: my $can_cat_crs = ' ';
9001: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9002: my $toggle_catscomm_comm = ' ';
9003: my $toggle_catscomm_dom = ' checked="checked" ';
9004: my $can_catcomm_comm = ' ';
9005: my $can_catcomm_dom = ' checked="checked" ';
9006:
1.57 raeburn 9007: if (ref($settings) eq 'HASH') {
9008: if ($settings->{'togglecats'} eq 'crs') {
9009: $toggle_cats_crs = $toggle_cats_dom;
9010: $toggle_cats_dom = ' ';
9011: }
9012: if ($settings->{'categorize'} eq 'crs') {
9013: $can_cat_crs = $can_cat_dom;
9014: $can_cat_dom = ' ';
9015: }
1.120 raeburn 9016: if ($settings->{'togglecatscomm'} eq 'comm') {
9017: $toggle_catscomm_comm = $toggle_catscomm_dom;
9018: $toggle_catscomm_dom = ' ';
9019: }
9020: if ($settings->{'categorizecomm'} eq 'comm') {
9021: $can_catcomm_comm = $can_catcomm_dom;
9022: $can_catcomm_dom = ' ';
9023: }
1.57 raeburn 9024: }
9025: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 9026: togglecats => 'Show/Hide a course in catalog',
9027: togglecatscomm => 'Show/Hide a community in catalog',
9028: categorize => 'Assign a category to a course',
9029: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9030: );
9031: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 9032: dom => 'Set in Domain',
9033: crs => 'Set in Course',
9034: comm => 'Set in Community',
1.57 raeburn 9035: );
9036: $datatable = '<tr class="LC_odd_row">'.
9037: '<td>'.$title{'togglecats'}.'</td>'.
9038: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9039: '<input type="radio" name="togglecats"'.
9040: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9041: '<label><input type="radio" name="togglecats"'.
9042: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9043: '</tr><tr>'.
9044: '<td>'.$title{'categorize'}.'</td>'.
9045: '<td class="LC_right_item"><span class="LC_nobreak">'.
9046: '<label><input type="radio" name="categorize"'.
9047: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9048: '<label><input type="radio" name="categorize"'.
9049: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9050: '</tr><tr class="LC_odd_row">'.
9051: '<td>'.$title{'togglecatscomm'}.'</td>'.
9052: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9053: '<input type="radio" name="togglecatscomm"'.
9054: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9055: '<label><input type="radio" name="togglecatscomm"'.
9056: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9057: '</tr><tr>'.
9058: '<td>'.$title{'categorizecomm'}.'</td>'.
9059: '<td class="LC_right_item"><span class="LC_nobreak">'.
9060: '<label><input type="radio" name="categorizecomm"'.
9061: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9062: '<label><input type="radio" name="categorizecomm"'.
9063: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 9064: '</tr>';
1.120 raeburn 9065: $$rowtotal += 4;
1.57 raeburn 9066: } else {
9067: my $css_class;
9068: my $itemcount = 1;
9069: my $cathash;
9070: if (ref($settings) eq 'HASH') {
9071: $cathash = $settings->{'cats'};
9072: }
9073: if (ref($cathash) eq 'HASH') {
9074: my (@cats,@trails,%allitems,%idx,@jsarray);
9075: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9076: \%allitems,\%idx,\@jsarray);
9077: my $maxdepth = scalar(@cats);
9078: my $colattrib = '';
9079: if ($maxdepth > 2) {
9080: $colattrib = ' colspan="2" ';
9081: }
9082: my @path;
9083: if (@cats > 0) {
9084: if (ref($cats[0]) eq 'ARRAY') {
9085: my $numtop = @{$cats[0]};
9086: my $maxnum = $numtop;
1.120 raeburn 9087: my %default_names = (
9088: instcode => &mt('Official courses'),
9089: communities => &mt('Communities'),
9090: );
9091:
9092: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9093: ($cathash->{'instcode::0'} eq '') ||
9094: (!grep(/^communities$/,@{$cats[0]})) ||
9095: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 9096: $maxnum ++;
9097: }
9098: my $lastidx;
9099: for (my $i=0; $i<$numtop; $i++) {
9100: my $parent = $cats[0][$i];
9101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9102: my $item = &escape($parent).'::0';
9103: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9104: $lastidx = $idx{$item};
9105: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9106: .'<select name="'.$item.'"'.$chgstr.'>';
9107: for (my $k=0; $k<=$maxnum; $k++) {
9108: my $vpos = $k+1;
9109: my $selstr;
9110: if ($k == $i) {
9111: $selstr = ' selected="selected" ';
9112: }
9113: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9114: }
1.160.6.29 raeburn 9115: $datatable .= '</select></span></td><td>';
1.120 raeburn 9116: if ($parent eq 'instcode' || $parent eq 'communities') {
9117: $datatable .= '<span class="LC_nobreak">'
9118: .$default_names{$parent}.'</span>';
9119: if ($parent eq 'instcode') {
9120: $datatable .= '<br /><span class="LC_nobreak">('
9121: .&mt('with institutional codes')
9122: .')</span></td><td'.$colattrib.'>';
9123: } else {
9124: $datatable .= '<table><tr><td>';
9125: }
9126: $datatable .= '<span class="LC_nobreak">'
9127: .'<label><input type="radio" name="'
9128: .$parent.'" value="1" checked="checked" />'
9129: .&mt('Display').'</label>';
9130: if ($parent eq 'instcode') {
9131: $datatable .= ' ';
9132: } else {
9133: $datatable .= '</span></td></tr><tr><td>'
9134: .'<span class="LC_nobreak">';
9135: }
9136: $datatable .= '<label><input type="radio" name="'
9137: .$parent.'" value="0" />'
9138: .&mt('Do not display').'</label></span>';
9139: if ($parent eq 'communities') {
9140: $datatable .= '</td></tr></table>';
9141: }
9142: $datatable .= '</td>';
1.57 raeburn 9143: } else {
9144: $datatable .= $parent
1.160.6.29 raeburn 9145: .' <span class="LC_nobreak"><label>'
9146: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9147: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9148: }
9149: my $depth = 1;
9150: push(@path,$parent);
9151: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9152: pop(@path);
9153: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9154: $itemcount ++;
9155: }
1.48 raeburn 9156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9157: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9158: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9159: for (my $k=0; $k<=$maxnum; $k++) {
9160: my $vpos = $k+1;
9161: my $selstr;
1.57 raeburn 9162: if ($k == $numtop) {
1.48 raeburn 9163: $selstr = ' selected="selected" ';
9164: }
9165: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9166: }
1.59 bisitz 9167: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9168: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9169: .'</tr>'."\n";
1.48 raeburn 9170: $itemcount ++;
1.120 raeburn 9171: foreach my $default ('instcode','communities') {
9172: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9173: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9174: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9175: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9176: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9177: for (my $k=0; $k<=$maxnum; $k++) {
9178: my $vpos = $k+1;
9179: my $selstr;
9180: if ($k == $maxnum) {
9181: $selstr = ' selected="selected" ';
9182: }
9183: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9184: }
1.120 raeburn 9185: $datatable .= '</select></span></td>'.
9186: '<td><span class="LC_nobreak">'.
9187: $default_names{$default}.'</span>';
9188: if ($default eq 'instcode') {
9189: $datatable .= '<br /><span class="LC_nobreak">('
9190: .&mt('with institutional codes').')</span>';
9191: }
9192: $datatable .= '</td>'
9193: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9194: .&mt('Display').'</label> '
9195: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9196: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9197: }
9198: }
9199: }
1.57 raeburn 9200: } else {
9201: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9202: }
9203: } else {
1.160.6.87 raeburn 9204: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9205: .&initialize_categories($itemcount);
1.48 raeburn 9206: }
1.57 raeburn 9207: $$rowtotal += $itemcount;
1.48 raeburn 9208: }
9209: return $datatable;
9210: }
9211:
1.69 raeburn 9212: sub print_serverstatuses {
9213: my ($dom,$settings,$rowtotal) = @_;
9214: my $datatable;
9215: my @pages = &serverstatus_pages();
9216: my (%namedaccess,%machineaccess);
9217: foreach my $type (@pages) {
9218: $namedaccess{$type} = '';
9219: $machineaccess{$type}= '';
9220: }
9221: if (ref($settings) eq 'HASH') {
9222: foreach my $type (@pages) {
9223: if (exists($settings->{$type})) {
9224: if (ref($settings->{$type}) eq 'HASH') {
9225: foreach my $key (keys(%{$settings->{$type}})) {
9226: if ($key eq 'namedusers') {
9227: $namedaccess{$type} = $settings->{$type}->{$key};
9228: } elsif ($key eq 'machines') {
9229: $machineaccess{$type} = $settings->{$type}->{$key};
9230: }
9231: }
9232: }
9233: }
9234: }
9235: }
1.81 raeburn 9236: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9237: my $rownum = 0;
9238: my $css_class;
9239: foreach my $type (@pages) {
9240: $rownum ++;
9241: $css_class = $rownum%2?' class="LC_odd_row"':'';
9242: $datatable .= '<tr'.$css_class.'>'.
9243: '<td><span class="LC_nobreak">'.
9244: $titles->{$type}.'</span></td>'.
9245: '<td class="LC_left_item">'.
9246: '<input type="text" name="'.$type.'_namedusers" '.
9247: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9248: '<td class="LC_right_item">'.
9249: '<span class="LC_nobreak">'.
9250: '<input type="text" name="'.$type.'_machines" '.
9251: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 9252: '</span></td></tr>'."\n";
1.69 raeburn 9253: }
9254: $$rowtotal += $rownum;
9255: return $datatable;
9256: }
9257:
9258: sub serverstatus_pages {
9259: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 9260: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 9261: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 9262: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9263: }
9264:
1.160.6.40 raeburn 9265: sub defaults_javascript {
9266: my ($settings) = @_;
1.160.6.98 raeburn 9267: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 9268: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9269: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9270: if ($maxnum eq '') {
9271: $maxnum = 0;
9272: }
9273: $maxnum ++;
1.160.6.51 raeburn 9274: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 9275: return <<"ENDSCRIPT";
9276: <script type="text/javascript">
9277: // <![CDATA[
9278: function reorderTypes(form,caller) {
9279: var changedVal;
9280: $jstext
9281: var newpos = 'addinststatus_pos';
9282: var current = new Array;
9283: var maxh = $maxnum;
9284: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9285: var oldVal;
9286: if (caller == newpos) {
9287: changedVal = newitemVal;
9288: } else {
9289: var curritem = 'inststatus_pos_'+caller;
9290: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9291: current[newitemVal] = newpos;
9292: }
9293: for (var i=0; i<inststatuses.length; i++) {
9294: if (inststatuses[i] != caller) {
9295: var elementName = 'inststatus_pos_'+inststatuses[i];
9296: if (form.elements[elementName]) {
9297: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9298: current[currVal] = elementName;
9299: }
9300: }
9301: }
9302: for (var j=0; j<maxh; j++) {
9303: if (current[j] == undefined) {
9304: oldVal = j;
9305: }
9306: }
9307: if (oldVal < changedVal) {
9308: for (var k=oldVal+1; k<=changedVal ; k++) {
9309: var elementName = current[k];
9310: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9311: }
9312: } else {
9313: for (var k=changedVal; k<oldVal; k++) {
9314: var elementName = current[k];
9315: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9316: }
9317: }
9318: return;
9319: }
9320:
9321: // ]]>
9322: </script>
9323:
9324: ENDSCRIPT
9325: }
9326: }
9327:
1.160.6.98 raeburn 9328: sub passwords_javascript {
1.160.6.118.2 5(raebur 9329:2): my ($prefix) = @_;
9330:2): my %intalert;
9331:2): if ($prefix eq 'passwords') {
9332:2): %intalert = &Apache::lonlocal::texthash (
9333:2): 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.',
9334:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
9335:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
9336:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
9337:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
9338:2): );
9339:2): } elsif ($prefix eq 'secrets') {
9340:2): %intalert = &Apache::lonlocal::texthash (
9341:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
9342:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
9343:2): );
9344:2): }
1.160.6.99 raeburn 9345: &js_escape(\%intalert);
9346: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 9347:2): my $intauthjs;
9348:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 9349:
9350: function warnIntAuth(field) {
9351: if (field.name == 'intauth_check') {
9352: if (field.value == '2') {
1.160.6.99 raeburn 9353: alert('$intalert{authcheck}');
1.160.6.98 raeburn 9354: }
9355: }
9356: if (field.name == 'intauth_cost') {
9357: field.value.replace(/\s/g,'');
9358: if (field.value != '') {
9359: var regexdigit=/^\\d+\$/;
9360: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 9361: alert('$intalert{authcost}');
9362: }
9363: }
9364: }
9365: return;
9366: }
9367:
1.160.6.118.2 5(raebur 9368:2): ENDSCRIPT
9369:2):
9370:2): }
9371:2):
9372:2): $intauthjs .= <<"ENDSCRIPT";
9373:2):
9374:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 9375: field.value.replace(/^\s+/,'');
9376: field.value.replace(/\s+\$/,'');
9377: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 9378:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 9379: if (field.value == '') {
9380: alert('$intalert{passmin}');
9381: field.value = '$defmin';
9382: } else {
9383: if (!regexdigit.test(field.value)) {
9384: alert('$intalert{passmin}');
9385: field.value = '$defmin';
9386: }
9387: var minval = parseInt(field.value,10);
9388: if (minval < $defmin) {
9389: alert('$intalert{passmin}');
9390: field.value = '$defmin';
9391: }
9392: }
9393: } else {
9394: if (field.value == '0') {
9395: field.value = '';
9396: }
9397: if (field.value != '') {
1.160.6.118.2 5(raebur 9398:2): if (!regexdigit.test(field.value)) {
9399:2): if (field.name == '${prefix}_max') {
9400:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 9401: } else {
1.160.6.118.2 5(raebur 9402:2): if (field.name == '${prefix}_numsaved') {
9403:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 9404: }
9405: }
1.160.6.118.2 5(raebur 9406:2): field.value = '';
1.160.6.98 raeburn 9407: }
9408: }
9409: }
9410: return;
9411: }
9412:
9413: ENDSCRIPT
9414: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9415: }
9416:
1.49 raeburn 9417: sub coursecategories_javascript {
9418: my ($settings) = @_;
1.57 raeburn 9419: my ($output,$jstext,$cathash);
1.49 raeburn 9420: if (ref($settings) eq 'HASH') {
1.57 raeburn 9421: $cathash = $settings->{'cats'};
9422: }
9423: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9424: my (@cats,@jsarray,%idx);
1.57 raeburn 9425: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9426: if (@jsarray > 0) {
9427: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9428: for (my $i=0; $i<@jsarray; $i++) {
9429: if (ref($jsarray[$i]) eq 'ARRAY') {
9430: my $catstr = join('","',@{$jsarray[$i]});
9431: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9432: }
9433: }
9434: }
9435: } else {
9436: $jstext = ' var categories = Array(1);'."\n".
9437: ' categories[0] = Array("instcode_pos");'."\n";
9438: }
1.160.6.42 raeburn 9439: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9440: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 9441: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9442: &js_escape(\$instcode_reserved);
9443: &js_escape(\$communities_reserved);
9444: &js_escape(\$choose_again);
1.49 raeburn 9445: $output = <<"ENDSCRIPT";
9446: <script type="text/javascript">
1.109 raeburn 9447: // <![CDATA[
1.49 raeburn 9448: function reorderCats(form,parent,item,idx) {
9449: var changedVal;
9450: $jstext
9451: var newpos = 'addcategory_pos';
9452: if (parent == '') {
9453: var has_instcode = 0;
9454: var maxtop = categories[idx].length;
9455: for (var j=0; j<maxtop; j++) {
9456: if (categories[idx][j] == 'instcode::0') {
9457: has_instcode == 1;
9458: }
9459: }
9460: if (has_instcode == 0) {
9461: categories[idx][maxtop] = 'instcode_pos';
9462: }
9463: } else {
9464: newpos += '_'+parent;
9465: }
9466: var maxh = 1 + categories[idx].length;
9467: var current = new Array;
9468: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9469: if (item == newpos) {
9470: changedVal = newitemVal;
9471: } else {
9472: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9473: current[newitemVal] = newpos;
9474: }
9475: for (var i=0; i<categories[idx].length; i++) {
9476: var elementName = categories[idx][i];
9477: if (elementName != item) {
9478: if (form.elements[elementName]) {
9479: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9480: current[currVal] = elementName;
9481: }
9482: }
9483: }
9484: var oldVal;
9485: for (var j=0; j<maxh; j++) {
9486: if (current[j] == undefined) {
9487: oldVal = j;
9488: }
9489: }
9490: if (oldVal < changedVal) {
9491: for (var k=oldVal+1; k<=changedVal ; k++) {
9492: var elementName = current[k];
9493: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9494: }
9495: } else {
9496: for (var k=changedVal; k<oldVal; k++) {
9497: var elementName = current[k];
9498: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9499: }
9500: }
9501: return;
9502: }
1.120 raeburn 9503:
9504: function categoryCheck(form) {
9505: if (form.elements['addcategory_name'].value == 'instcode') {
9506: alert('$instcode_reserved\\n$choose_again');
9507: return false;
9508: }
9509: if (form.elements['addcategory_name'].value == 'communities') {
9510: alert('$communities_reserved\\n$choose_again');
9511: return false;
9512: }
9513: return true;
9514: }
9515:
1.109 raeburn 9516: // ]]>
1.49 raeburn 9517: </script>
9518:
9519: ENDSCRIPT
9520: return $output;
9521: }
9522:
1.48 raeburn 9523: sub initialize_categories {
9524: my ($itemcount) = @_;
1.120 raeburn 9525: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 9526: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 9527: instcode => 'Official courses (with institutional codes)',
9528: communities => 'Communities',
9529: );
9530: my $select0 = ' selected="selected"';
9531: my $select1 = '';
9532: foreach my $default ('instcode','communities') {
9533: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 9534: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 9535: if ($default eq 'communities') {
9536: $select1 = $select0;
9537: $select0 = '';
9538: }
9539: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9540: .'<select name="'.$default.'_pos">'
9541: .'<option value="0"'.$select0.'>1</option>'
9542: .'<option value="1"'.$select1.'>2</option>'
9543: .'<option value="2">3</option></select> '
9544: .$default_names{$default}
9545: .'</span></td><td><span class="LC_nobreak">'
9546: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9547: .&mt('Display').'</label> <label>'
9548: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9549: .'</label></span></td></tr>';
1.120 raeburn 9550: $itemcount ++;
9551: }
1.48 raeburn 9552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9553: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9554: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9555: .'<select name="addcategory_pos"'.$chgstr.'>'
9556: .'<option value="0">1</option>'
9557: .'<option value="1">2</option>'
9558: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 9559: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 9560: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9561: .'</td></tr>';
1.48 raeburn 9562: return $datatable;
9563: }
9564:
9565: sub build_category_rows {
1.49 raeburn 9566: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9567: my ($text,$name,$item,$chgstr);
1.48 raeburn 9568: if (ref($cats) eq 'ARRAY') {
9569: my $maxdepth = scalar(@{$cats});
9570: if (ref($cats->[$depth]) eq 'HASH') {
9571: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9572: my $numchildren = @{$cats->[$depth]{$parent}};
9573: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 9574: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9575: my ($idxnum,$parent_name,$parent_item);
9576: my $higher = $depth - 1;
9577: if ($higher == 0) {
9578: $parent_name = &escape($parent).'::'.$higher;
9579: } else {
9580: if (ref($path) eq 'ARRAY') {
9581: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9582: }
9583: }
9584: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9585: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9586: if ($j < $numchildren) {
1.48 raeburn 9587: $name = $cats->[$depth]{$parent}[$j];
9588: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9589: $idxnum = $idx->{$item};
9590: } else {
9591: $name = $parent_name;
9592: $item = $parent_item;
1.48 raeburn 9593: }
1.49 raeburn 9594: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9595: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9596: for (my $i=0; $i<=$numchildren; $i++) {
9597: my $vpos = $i+1;
9598: my $selstr;
9599: if ($j == $i) {
9600: $selstr = ' selected="selected" ';
9601: }
9602: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9603: }
9604: $text .= '</select> ';
9605: if ($j < $numchildren) {
9606: my $deeper = $depth+1;
9607: $text .= $name.' '
9608: .'<label><input type="checkbox" name="deletecategory" value="'
9609: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9610: if(ref($path) eq 'ARRAY') {
9611: push(@{$path},$name);
1.49 raeburn 9612: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9613: pop(@{$path});
9614: }
9615: } else {
1.160.6.87 raeburn 9616: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9617: if ($j == $numchildren) {
9618: $text .= $name;
9619: } else {
9620: $text .= $item;
9621: }
9622: $text .= '" value="" />';
9623: }
9624: $text .= '</td></tr>';
9625: }
9626: $text .= '</table></td>';
9627: } else {
9628: my $higher = $depth-1;
9629: if ($higher == 0) {
9630: $name = &escape($parent).'::'.$higher;
9631: } else {
9632: if (ref($path) eq 'ARRAY') {
9633: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9634: }
9635: }
9636: my $colspan;
9637: if ($parent ne 'instcode') {
9638: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 9639: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9640: }
9641: }
9642: }
9643: }
9644: return $text;
9645: }
9646:
1.33 raeburn 9647: sub modifiable_userdata_row {
1.160.6.93 raeburn 9648: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9649: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 9650: my ($role,$rolename,$statustype);
9651: $role = $item;
1.160.6.34 raeburn 9652: if ($context eq 'cancreate') {
1.160.6.93 raeburn 9653: if ($item =~ /^(emailusername)_(.+)$/) {
9654: $role = $1;
9655: $statustype = $2;
1.160.6.35 raeburn 9656: if (ref($usertypes) eq 'HASH') {
9657: if ($usertypes->{$statustype}) {
9658: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9659: } else {
9660: $rolename = &mt('Data provided by user');
9661: }
9662: }
1.160.6.34 raeburn 9663: }
9664: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9665: if (ref($usertypes) eq 'HASH') {
9666: $rolename = $usertypes->{$role};
9667: } else {
9668: $rolename = $role;
9669: }
1.33 raeburn 9670: } else {
1.63 raeburn 9671: if ($role eq 'cr') {
9672: $rolename = &mt('Custom role');
9673: } else {
9674: $rolename = &Apache::lonnet::plaintext($role);
9675: }
1.33 raeburn 9676: }
1.160.6.34 raeburn 9677: my (@fields,%fieldtitles);
9678: if (ref($fieldsref) eq 'ARRAY') {
9679: @fields = @{$fieldsref};
9680: } else {
9681: @fields = ('lastname','firstname','middlename','generation',
9682: 'permanentemail','id');
9683: }
9684: if ((ref($titlesref) eq 'HASH')) {
9685: %fieldtitles = %{$titlesref};
9686: } else {
9687: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9688: }
1.33 raeburn 9689: my $output;
1.160.6.93 raeburn 9690: my $css_class;
9691: if ($rowcount%2) {
9692: $css_class = 'LC_odd_row';
9693: }
9694: if ($customcss) {
9695: $css_class .= " $customcss";
9696: }
9697: $css_class =~ s/^\s+//;
9698: if ($css_class) {
9699: $css_class = ' class="'.$css_class.'"';
9700: }
9701: if ($rowstyle) {
9702: $css_class .= ' style="'.$rowstyle.'"';
9703: }
9704: if ($rowid) {
9705: $rowid = ' id="'.$rowid.'"';
9706: }
9707:
9708: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9709: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9710: '<td class="LC_left_item" colspan="2"><table>';
9711: my $rem;
9712: my %checks;
9713: if (ref($settings) eq 'HASH') {
9714: if (ref($settings->{$context}) eq 'HASH') {
9715: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 9716: my $hashref = $settings->{$context}->{$role};
9717: if ($role eq 'emailusername') {
9718: if ($statustype) {
9719: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9720: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 9721: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 9722: foreach my $field (@fields) {
9723: if ($hashref->{$field}) {
9724: $checks{$field} = $hashref->{$field};
9725: }
9726: }
9727: }
9728: }
9729: }
9730: } else {
9731: if (ref($hashref) eq 'HASH') {
9732: foreach my $field (@fields) {
9733: if ($hashref->{$field}) {
9734: $checks{$field} = ' checked="checked" ';
9735: }
9736: }
1.33 raeburn 9737: }
9738: }
9739: }
9740: }
9741: }
1.160.6.93 raeburn 9742:
9743: my $total = scalar(@fields);
9744: for (my $i=0; $i<$total; $i++) {
9745: $rem = $i%($numinrow);
1.33 raeburn 9746: if ($rem == 0) {
9747: if ($i > 0) {
9748: $output .= '</tr>';
9749: }
9750: $output .= '<tr>';
9751: }
9752: my $check = ' ';
1.160.6.35 raeburn 9753: unless ($role eq 'emailusername') {
9754: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 9755: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 9756: } else {
9757: if ($role eq 'st') {
9758: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 9759: $check = ' checked="checked" ';
1.160.6.35 raeburn 9760: }
1.33 raeburn 9761: }
9762: }
9763: }
9764: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 9765: '<span class="LC_nobreak">';
9766: if ($role eq 'emailusername') {
9767: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9768: $checks{$fields[$i]} = 'omit';
9769: }
9770: foreach my $option ('required','optional','omit') {
9771: my $checked='';
9772: if ($checks{$fields[$i]} eq $option) {
9773: $checked='checked="checked" ';
9774: }
9775: $output .= '<label>'.
9776: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9777: &mt($option).'</label>'.(' ' x2);
9778: }
9779: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9780: } else {
9781: $output .= '<label>'.
9782: '<input type="checkbox" name="canmodify_'.$role.'" '.
9783: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9784: '</label>';
9785: }
9786: $output .= '</span></td>';
1.33 raeburn 9787: }
1.160.6.93 raeburn 9788: $rem = $total%$numinrow;
9789: my $colsleft;
9790: if ($rem) {
9791: $colsleft = $numinrow - $rem;
9792: }
9793: if ($colsleft > 1) {
1.33 raeburn 9794: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9795: ' </td>';
9796: } elsif ($colsleft == 1) {
9797: $output .= '<td class="LC_left_item"> </td>';
9798: }
9799: $output .= '</tr></table></td></tr>';
9800: return $output;
9801: }
1.28 raeburn 9802:
1.93 raeburn 9803: sub insttypes_row {
1.160.6.93 raeburn 9804: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9805: $customcss,$rowstyle) = @_;
1.93 raeburn 9806: my %lt = &Apache::lonlocal::texthash (
9807: cansearch => 'Users allowed to search',
9808: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9809: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 9810: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 9811: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9812: );
9813: my $showdom;
9814: if ($context eq 'cansearch') {
9815: $showdom = ' ('.$dom.')';
9816: }
1.160.6.5 raeburn 9817: my $class = 'LC_left_item';
9818: if ($context eq 'statustocreate') {
9819: $class = 'LC_right_item';
9820: }
1.160.6.93 raeburn 9821: my $css_class;
9822: if ($$rowtotal%2) {
9823: $css_class = 'LC_odd_row';
9824: }
9825: if ($customcss) {
9826: $css_class .= ' '.$customcss;
9827: }
9828: $css_class =~ s/^\s+//;
9829: if ($css_class) {
9830: $css_class = ' class="'.$css_class.'"';
9831: }
9832: if ($rowstyle) {
9833: $css_class .= ' style="'.$rowstyle.'"';
9834: }
9835: if ($onclick) {
9836: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 9837: }
9838: my $output = '<tr'.$css_class.'>'.
9839: '<td>'.$lt{$context}.$showdom.
9840: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9841: my $rem;
9842: if (ref($types) eq 'ARRAY') {
9843: for (my $i=0; $i<@{$types}; $i++) {
9844: if (defined($usertypes->{$types->[$i]})) {
9845: my $rem = $i%($numinrow);
9846: if ($rem == 0) {
9847: if ($i > 0) {
9848: $output .= '</tr>';
9849: }
9850: $output .= '<tr>';
1.23 raeburn 9851: }
1.26 raeburn 9852: my $check = ' ';
1.99 raeburn 9853: if (ref($settings) eq 'HASH') {
9854: if (ref($settings->{$context}) eq 'ARRAY') {
9855: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9856: $check = ' checked="checked" ';
9857: }
1.160.6.101 raeburn 9858: } elsif (ref($settings->{$context}) eq 'HASH') {
9859: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9860: $check = ' checked="checked" ';
9861: }
1.99 raeburn 9862: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9863: $check = ' checked="checked" ';
9864: }
1.23 raeburn 9865: }
1.26 raeburn 9866: $output .= '<td class="LC_left_item">'.
9867: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9868: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9869: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9870: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9871: }
9872: }
1.26 raeburn 9873: $rem = @{$types}%($numinrow);
1.23 raeburn 9874: }
9875: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9876: if ($context eq 'overrides') {
9877: if ($colsleft > 1) {
9878: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9879: } else {
9880: $output .= '<td class="LC_left_item">';
9881: }
9882: $output .= ' ';
1.23 raeburn 9883: } else {
1.160.6.101 raeburn 9884: if ($rem == 0) {
9885: $output .= '<tr>';
9886: }
9887: if ($colsleft > 1) {
9888: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9889: } else {
9890: $output .= '<td class="LC_left_item">';
9891: }
9892: my $defcheck = ' ';
9893: if (ref($settings) eq 'HASH') {
9894: if (ref($settings->{$context}) eq 'ARRAY') {
9895: if (grep(/^default$/,@{$settings->{$context}})) {
9896: $defcheck = ' checked="checked" ';
9897: }
9898: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9899: $defcheck = ' checked="checked" ';
9900: }
1.26 raeburn 9901: }
1.160.6.101 raeburn 9902: $output .= '<span class="LC_nobreak"><label>'.
9903: '<input type="checkbox" name="'.$context.'" '.
9904: 'value="default"'.$defcheck.$onclick.' />'.
9905: $othertitle.'</label></span>';
1.23 raeburn 9906: }
1.160.6.101 raeburn 9907: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9908: return $output;
1.23 raeburn 9909: }
9910:
9911: sub sorted_searchtitles {
9912: my %searchtitles = &Apache::lonlocal::texthash(
9913: 'uname' => 'username',
9914: 'lastname' => 'last name',
9915: 'lastfirst' => 'last name, first name',
9916: );
9917: my @titleorder = ('uname','lastname','lastfirst');
9918: return (\%searchtitles,\@titleorder);
9919: }
9920:
1.25 raeburn 9921: sub sorted_searchtypes {
9922: my %srchtypes_desc = (
9923: exact => 'is exact match',
9924: contains => 'contains ..',
9925: begins => 'begins with ..',
9926: );
9927: my @srchtypeorder = ('exact','begins','contains');
9928: return (\%srchtypes_desc,\@srchtypeorder);
9929: }
9930:
1.3 raeburn 9931: sub usertype_update_row {
9932: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9933: my $datatable;
9934: my $numinrow = 4;
9935: foreach my $type (@{$types}) {
9936: if (defined($usertypes->{$type})) {
9937: $$rownums ++;
9938: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9939: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9940: '</td><td class="LC_left_item"><table>';
9941: for (my $i=0; $i<@{$fields}; $i++) {
9942: my $rem = $i%($numinrow);
9943: if ($rem == 0) {
9944: if ($i > 0) {
9945: $datatable .= '</tr>';
9946: }
9947: $datatable .= '<tr>';
9948: }
9949: my $check = ' ';
1.39 raeburn 9950: if (ref($settings) eq 'HASH') {
9951: if (ref($settings->{'fields'}) eq 'HASH') {
9952: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9953: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9954: $check = ' checked="checked" ';
9955: }
1.3 raeburn 9956: }
9957: }
9958: }
9959:
9960: if ($i == @{$fields}-1) {
9961: my $colsleft = $numinrow - $rem;
9962: if ($colsleft > 1) {
9963: $datatable .= '<td colspan="'.$colsleft.'">';
9964: } else {
9965: $datatable .= '<td>';
9966: }
9967: } else {
9968: $datatable .= '<td>';
9969: }
1.8 raeburn 9970: $datatable .= '<span class="LC_nobreak"><label>'.
9971: '<input type="checkbox" name="updateable_'.$type.
9972: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9973: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9974: }
9975: $datatable .= '</tr></table></td></tr>';
9976: }
9977: }
9978: return $datatable;
1.1 raeburn 9979: }
9980:
9981: sub modify_login {
1.160.6.24 raeburn 9982: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9983: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9984: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9985: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9986: %title = ( coursecatalog => 'Display course catalog',
9987: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9988: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9989: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9990: loginheader => 'Log-in box header',
9991: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9992: @offon = ('off','on');
1.112 raeburn 9993: if (ref($domconfig{login}) eq 'HASH') {
9994: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9995: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9996: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9997: }
9998: }
1.160.6.113 raeburn 9999: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10000: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10001: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10002: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10003: $saml{$lonhost} = 1;
10004: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10005: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10006: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10007: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10008: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
10009: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10010: }
10011: }
10012: }
1.112 raeburn 10013: }
1.9 raeburn 10014: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10015: \%domconfig,\%loginhash);
1.160.6.14 raeburn 10016: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10017: foreach my $item (@toggles) {
10018: $loginhash{login}{$item} = $env{'form.'.$item};
10019: }
1.41 raeburn 10020: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10021: if (ref($colchanges{'login'}) eq 'HASH') {
10022: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10023: \%loginhash);
10024: }
1.110 raeburn 10025:
1.149 raeburn 10026: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 10027: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10028: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10029: if (keys(%servers) > 1) {
10030: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10031: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10032: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10033: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10034: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10035: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10036: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10037: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10038: $changes{'loginvia'}{$lonhost} = 1;
10039: } else {
10040: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10041: $changes{'loginvia'}{$lonhost} = 1;
10042: }
10043: } else {
10044: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10045: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10046: $changes{'loginvia'}{$lonhost} = 1;
10047: }
10048: }
10049: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10050: foreach my $item (@loginvia_attribs) {
10051: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10052: }
10053: } else {
10054: foreach my $item (@loginvia_attribs) {
10055: my $new = $env{'form.'.$lonhost.'_'.$item};
10056: if (($item eq 'serverpath') && ($new eq 'custom')) {
10057: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10058: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10059: $new = '/';
10060: }
10061: }
10062: if (($item eq 'custompath') &&
10063: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10064: $new = '';
10065: }
10066: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10067: $changes{'loginvia'}{$lonhost} = 1;
10068: }
10069: if ($item eq 'exempt') {
1.160.6.56 raeburn 10070: $new = &check_exempt_addresses($new);
1.128 raeburn 10071: }
10072: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10073: }
10074: }
1.112 raeburn 10075: } else {
1.128 raeburn 10076: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10077: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10078: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10079: foreach my $item (@loginvia_attribs) {
10080: my $new = $env{'form.'.$lonhost.'_'.$item};
10081: if (($item eq 'serverpath') && ($new eq 'custom')) {
10082: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10083: $new = '/';
10084: }
10085: }
10086: if (($item eq 'custompath') &&
10087: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10088: $new = '';
10089: }
10090: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10091: }
1.110 raeburn 10092: }
10093: }
10094: }
10095: }
1.119 raeburn 10096:
1.160.6.5 raeburn 10097: my $servadm = $r->dir_config('lonAdmEMail');
10098: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10099: if (ref($domconfig{'login'}) eq 'HASH') {
10100: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10101: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10102: if ($lang eq 'nolang') {
10103: push(@currlangs,$lang);
10104: } elsif (defined($langchoices{$lang})) {
10105: push(@currlangs,$lang);
10106: } else {
10107: next;
10108: }
10109: }
10110: }
10111: }
10112: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10113: if (@currlangs > 0) {
10114: foreach my $lang (@currlangs) {
10115: if (grep(/^\Q$lang\E$/,@delurls)) {
10116: $changes{'helpurl'}{$lang} = 1;
10117: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10118: $changes{'helpurl'}{$lang} = 1;
10119: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10120: push(@newlangs,$lang);
10121: } else {
10122: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10123: }
10124: }
10125: }
10126: unless (grep(/^nolang$/,@currlangs)) {
10127: if ($env{'form.loginhelpurl_nolang.filename'}) {
10128: $changes{'helpurl'}{'nolang'} = 1;
10129: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10130: push(@newlangs,'nolang');
10131: }
10132: }
10133: if ($env{'form.loginhelpurl_add_lang'}) {
10134: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10135: ($env{'form.loginhelpurl_add_file.filename'})) {
10136: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10137: $addedfile = $env{'form.loginhelpurl_add_lang'};
10138: }
10139: }
10140: if ((@newlangs > 0) || ($addedfile)) {
10141: my $error;
10142: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10143: if ($configuserok eq 'ok') {
10144: if ($switchserver) {
10145: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10146: } elsif ($author_ok eq 'ok') {
10147: my @allnew = @newlangs;
10148: if ($addedfile ne '') {
10149: push(@allnew,$addedfile);
10150: }
10151: foreach my $lang (@allnew) {
10152: my $formelem = 'loginhelpurl_'.$lang;
10153: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10154: $formelem = 'loginhelpurl_add_file';
10155: }
10156: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10157: "help/$lang",'','',$newfile{$lang});
10158: if ($result eq 'ok') {
10159: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10160: $changes{'helpurl'}{$lang} = 1;
10161: } else {
10162: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10163: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10164: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10165: (!grep(/^\Q$lang\E$/,@delurls))) {
10166: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10167: }
10168: }
10169: }
10170: } else {
10171: $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);
10172: }
10173: } else {
10174: $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);
10175: }
10176: if ($error) {
10177: &Apache::lonnet::logthis($error);
10178: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10179: }
10180: }
1.160.6.56 raeburn 10181:
10182: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10183: if (ref($domconfig{'login'}) eq 'HASH') {
10184: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10185: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10186: if ($domservers{$lonhost}) {
10187: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10188: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 10189: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 10190: }
10191: }
10192: }
10193: }
10194: }
10195: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10196: foreach my $lonhost (sort(keys(%domservers))) {
10197: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10198: $changes{'headtag'}{$lonhost} = 1;
10199: } else {
10200: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10201: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10202: }
10203: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10204: push(@newhosts,$lonhost);
10205: } elsif ($currheadtagurls{$lonhost}) {
10206: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10207: if ($currexempt{$lonhost}) {
10208: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10209: $changes{'headtag'}{$lonhost} = 1;
10210: }
10211: } elsif ($possexempt{$lonhost}) {
10212: $changes{'headtag'}{$lonhost} = 1;
10213: }
10214: if ($possexempt{$lonhost}) {
10215: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10216: }
10217: }
10218: }
10219: }
10220: if (@newhosts) {
10221: my $error;
10222: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10223: if ($configuserok eq 'ok') {
10224: if ($switchserver) {
10225: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10226: } elsif ($author_ok eq 'ok') {
10227: foreach my $lonhost (@newhosts) {
10228: my $formelem = 'loginheadtag_'.$lonhost;
10229: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10230: "login/headtag/$lonhost",'','',
10231: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10232: if ($result eq 'ok') {
1.160.6.113 raeburn 10233: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10234: $changes{'headtag'}{$lonhost} = 1;
10235: if ($possexempt{$lonhost}) {
10236: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10237: }
10238: } else {
10239: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10240: $newheadtagurls{$lonhost},$result);
10241: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10242: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10243: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10244: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10245: }
10246: }
10247: }
10248: } else {
10249: $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);
10250: }
10251: } else {
10252: $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);
10253: }
10254: if ($error) {
10255: &Apache::lonnet::logthis($error);
10256: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10257: }
10258: }
10259: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10260: my @newsamlimgs;
10261: foreach my $lonhost (keys(%domservers)) {
10262: if ($env{'form.saml_'.$lonhost}) {
10263: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10264: push(@newsamlimgs,$lonhost);
10265: }
10266: foreach my $item ('text','alt','url','title','notsso') {
10267: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10268: }
10269: if ($saml{$lonhost}) {
10270: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
10271: #FIXME Need to obsolete published image
10272: delete($currsaml{$lonhost}{'img'});
10273: $changes{'saml'}{$lonhost} = 1;
10274: }
10275: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
10276: $changes{'saml'}{$lonhost} = 1;
10277: }
10278: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
10279: $changes{'saml'}{$lonhost} = 1;
10280: }
10281: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
10282: $changes{'saml'}{$lonhost} = 1;
10283: }
10284: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
10285: $changes{'saml'}{$lonhost} = 1;
10286: }
10287: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
10288: $changes{'saml'}{$lonhost} = 1;
10289: }
10290: } else {
10291: $changes{'saml'}{$lonhost} = 1;
10292: }
10293: foreach my $item ('text','alt','url','title','notsso') {
10294: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
10295: }
10296: } else {
10297: if ($saml{$lonhost}) {
10298: $changes{'saml'}{$lonhost} = 1;
10299: delete($currsaml{$lonhost});
10300: }
10301: }
10302: }
10303: foreach my $posshost (keys(%currsaml)) {
10304: unless (exists($domservers{$posshost})) {
10305: delete($currsaml{$posshost});
10306: }
10307: }
10308: %{$loginhash{'login'}{'saml'}} = %currsaml;
10309: if (@newsamlimgs) {
10310: my $error;
10311: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10312: if ($configuserok eq 'ok') {
10313: if ($switchserver) {
10314: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
10315: } elsif ($author_ok eq 'ok') {
10316: foreach my $lonhost (@newsamlimgs) {
10317: my $formelem = 'saml_img_'.$lonhost;
10318: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10319: "login/saml/$lonhost",'','',
10320: $env{'form.saml_img_'.$lonhost.'.filename'});
10321: if ($result eq 'ok') {
10322: $currsaml{$lonhost}{'img'} = $imgurl;
10323: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
10324: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 10325: } else {
1.160.6.113 raeburn 10326: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
10327: $lonhost,$result);
1.160.6.56 raeburn 10328: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10329: }
10330: }
10331: } else {
1.160.6.113 raeburn 10332: $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);
1.160.6.56 raeburn 10333: }
10334: } else {
1.160.6.113 raeburn 10335: $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);
1.160.6.56 raeburn 10336: }
10337: if ($error) {
10338: &Apache::lonnet::logthis($error);
10339: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10340: }
10341: }
1.160.6.5 raeburn 10342: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
10343:
10344: my $defaulthelpfile = '/adm/loginproblems.html';
10345: my $defaulttext = &mt('Default in use');
10346:
1.1 raeburn 10347: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10348: $dom);
10349: if ($putresult eq 'ok') {
1.160.6.14 raeburn 10350: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10351: my %defaultchecked = (
10352: 'coursecatalog' => 'on',
1.160.6.14 raeburn 10353: 'helpdesk' => 'on',
1.42 raeburn 10354: 'adminmail' => 'off',
1.43 raeburn 10355: 'newuser' => 'off',
1.42 raeburn 10356: );
1.55 raeburn 10357: if (ref($domconfig{'login'}) eq 'HASH') {
10358: foreach my $item (@toggles) {
10359: if ($defaultchecked{$item} eq 'on') {
10360: if (($domconfig{'login'}{$item} eq '0') &&
10361: ($env{'form.'.$item} eq '1')) {
10362: $changes{$item} = 1;
10363: } elsif (($domconfig{'login'}{$item} eq '' ||
10364: $domconfig{'login'}{$item} eq '1') &&
10365: ($env{'form.'.$item} eq '0')) {
10366: $changes{$item} = 1;
10367: }
10368: } elsif ($defaultchecked{$item} eq 'off') {
10369: if (($domconfig{'login'}{$item} eq '1') &&
10370: ($env{'form.'.$item} eq '0')) {
10371: $changes{$item} = 1;
10372: } elsif (($domconfig{'login'}{$item} eq '' ||
10373: $domconfig{'login'}{$item} eq '0') &&
10374: ($env{'form.'.$item} eq '1')) {
10375: $changes{$item} = 1;
10376: }
1.42 raeburn 10377: }
10378: }
1.41 raeburn 10379: }
1.6 raeburn 10380: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10381: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 10382: if (exists($changes{'saml'})) {
10383: my $hostid_in_use;
10384: my @hosts = &Apache::lonnet::current_machine_ids();
10385: if (@hosts > 1) {
10386: foreach my $hostid (@hosts) {
10387: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10388: $hostid_in_use = $hostid;
10389: last;
10390: }
10391: }
10392: } else {
10393: $hostid_in_use = $r->dir_config('lonHostID');
10394: }
10395: if (($hostid_in_use) &&
10396: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10397: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10398: }
10399: if (ref($lastactref) eq 'HASH') {
10400: if (ref($changes{'saml'}) eq 'HASH') {
10401: my %updates;
10402: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10403: $lastactref->{'samllanding'} = \%updates;
10404: }
10405: }
10406: }
1.160.6.27 raeburn 10407: if (ref($lastactref) eq 'HASH') {
10408: $lastactref->{'domainconfig'} = 1;
10409: }
1.1 raeburn 10410: $resulttext = &mt('Changes made:').'<ul>';
10411: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10412: if ($item eq 'loginvia') {
1.112 raeburn 10413: if (ref($changes{$item}) eq 'HASH') {
10414: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10415: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10416: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10417: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10418: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10419: $protocol = 'http' if ($protocol ne 'https');
10420: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10421:
10422: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10423: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10424: } else {
10425: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10426: }
10427: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10428: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10429: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10430: }
10431: $resulttext .= '</li>';
10432: } else {
10433: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10434: }
1.112 raeburn 10435: } else {
1.128 raeburn 10436: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10437: }
10438: }
1.128 raeburn 10439: $resulttext .= '</ul></li>';
1.112 raeburn 10440: }
1.160.6.5 raeburn 10441: } elsif ($item eq 'helpurl') {
10442: if (ref($changes{$item}) eq 'HASH') {
10443: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10444: if (grep(/^\Q$lang\E$/,@delurls)) {
10445: my ($chg,$link);
10446: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10447: if ($lang eq 'nolang') {
10448: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10449: } else {
10450: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10451: }
10452: $resulttext .= '<li>'.$chg.'</li>';
10453: } else {
10454: my $chg;
10455: if ($lang eq 'nolang') {
10456: $chg = &mt('custom log-in help file for no preferred language');
10457: } else {
10458: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10459: }
10460: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10461: $loginhash{'login'}{'helpurl'}{$lang}.
10462: '?inhibitmenu=yes',$chg,600,500).
10463: '</li>';
10464: }
10465: }
10466: }
1.160.6.56 raeburn 10467: } elsif ($item eq 'headtag') {
10468: if (ref($changes{$item}) eq 'HASH') {
10469: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10470: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10471: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10472: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10473: $resulttext .= '<li><a href="'.
10474: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10475: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10476: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10477: if ($possexempt{$lonhost}) {
10478: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10479: } else {
10480: $resulttext .= &mt('included for any client IP');
10481: }
10482: $resulttext .= '</li>';
10483: }
10484: }
10485: }
1.160.6.113 raeburn 10486: } elsif ($item eq 'saml') {
10487: if (ref($changes{$item}) eq 'HASH') {
10488: my %notlt = (
10489: text => 'Text for log-in by SSO',
10490: img => 'SSO button image',
10491: alt => 'Alt text for button image',
10492: url => 'SSO URL',
10493: title => 'Tooltip for SSO link',
10494: notsso => 'Text for non-SSO log-in',
10495: );
10496: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10497: if (ref($currsaml{$lonhost}) eq 'HASH') {
10498: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10499: '<ul>';
10500: foreach my $key ('text','img','alt','url','title','notsso') {
10501: if ($currsaml{$lonhost}{$key} eq '') {
10502: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10503: } else {
10504: my $value = "'$currsaml{$lonhost}{$key}'";
10505: if ($key eq 'img') {
10506: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
10507: }
10508: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10509: $value).'</li>';
10510: }
10511: }
10512: $resulttext .= '</ul></li>';
10513: } else {
10514: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10515: }
10516: }
10517: }
1.160.6.5 raeburn 10518: } elsif ($item eq 'captcha') {
10519: if (ref($loginhash{'login'}) eq 'HASH') {
10520: my $chgtxt;
10521: if ($loginhash{'login'}{$item} eq 'notused') {
10522: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10523: } else {
10524: my %captchas = &captcha_phrases();
10525: if ($captchas{$loginhash{'login'}{$item}}) {
10526: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10527: } else {
10528: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10529: }
10530: }
10531: $resulttext .= '<li>'.$chgtxt.'</li>';
10532: }
10533: } elsif ($item eq 'recaptchakeys') {
10534: if (ref($loginhash{'login'}) eq 'HASH') {
10535: my ($privkey,$pubkey);
10536: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10537: $pubkey = $loginhash{'login'}{$item}{'public'};
10538: $privkey = $loginhash{'login'}{$item}{'private'};
10539: }
10540: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10541: if (!$pubkey) {
10542: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10543: } else {
10544: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10545: }
10546: if (!$privkey) {
10547: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10548: } else {
1.160.6.53 raeburn 10549: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 10550: }
10551: $chgtxt .= '</ul>';
10552: $resulttext .= '<li>'.$chgtxt.'</li>';
10553: }
1.160.6.69 raeburn 10554: } elsif ($item eq 'recaptchaversion') {
10555: if (ref($loginhash{'login'}) eq 'HASH') {
10556: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10557: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10558: '</li>';
10559: }
10560: }
1.41 raeburn 10561: } else {
10562: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10563: }
1.1 raeburn 10564: }
1.6 raeburn 10565: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10566: } else {
10567: $resulttext = &mt('No changes made to log-in page settings');
10568: }
10569: } else {
1.11 albertel 10570: $resulttext = '<span class="LC_error">'.
10571: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10572: }
1.6 raeburn 10573: if ($errors) {
1.9 raeburn 10574: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10575: $errors.'</ul>';
10576: }
10577: return $resulttext;
10578: }
10579:
1.160.6.56 raeburn 10580: sub check_exempt_addresses {
10581: my ($iplist) = @_;
10582: $iplist =~ s/^\s+//;
10583: $iplist =~ s/\s+$//;
10584: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10585: my (@okips,$new);
10586: foreach my $ip (@poss_ips) {
10587: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10588: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10589: push(@okips,$ip);
10590: }
10591: }
10592: }
10593: if (@okips > 0) {
10594: $new = join(',',@okips);
10595: } else {
10596: $new = '';
10597: }
10598: return $new;
10599: }
10600:
1.6 raeburn 10601: sub color_font_choices {
10602: my %choices =
10603: &Apache::lonlocal::texthash (
10604: img => "Header",
10605: bgs => "Background colors",
10606: links => "Link colors",
1.55 raeburn 10607: images => "Images",
1.6 raeburn 10608: font => "Font color",
1.160.6.22 raeburn 10609: fontmenu => "Font menu",
1.76 raeburn 10610: pgbg => "Page",
1.6 raeburn 10611: tabbg => "Header",
10612: sidebg => "Border",
10613: link => "Link",
10614: alink => "Active link",
10615: vlink => "Visited link",
10616: );
10617: return %choices;
10618: }
10619:
1.160.6.113 raeburn 10620: sub modify_ipaccess {
10621: my ($dom,$lastactref,%domconfig) = @_;
10622: my (@allpos,%changes,%confhash,$errors,$resulttext);
10623: my (@items,%deletions,%itemids,@warnings);
10624: my ($typeorder,$types) = &commblocktype_text();
10625: if ($env{'form.ipaccess_add'}) {
10626: my $name = $env{'form.ipaccess_name_add'};
10627: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10628: if ($newid) {
10629: $itemids{'add'} = $newid;
10630: push(@items,'add');
10631: $changes{$newid} = 1;
10632: } else {
10633: $error = &mt('Failed to acquire unique ID for new IP access control item');
10634: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10635: }
10636: }
10637: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10638: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10639: if (@todelete) {
10640: map { $deletions{$_} = 1; } @todelete;
10641: }
10642: my $maxnum = $env{'form.ipaccess_maxnum'};
10643: for (my $i=0; $i<$maxnum; $i++) {
10644: my $itemid = $env{'form.ipaccess_id_'.$i};
10645: $itemid =~ s/\D+//g;
10646: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10647: if ($deletions{$itemid}) {
10648: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10649: } else {
10650: push(@items,$i);
10651: $itemids{$i} = $itemid;
10652: }
10653: }
10654: }
10655: }
10656: foreach my $idx (@items) {
10657: my $itemid = $itemids{$idx};
10658: next unless ($itemid);
10659: my %current;
10660: unless ($idx eq 'add') {
10661: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10662: %current = %{$domconfig{'ipaccess'}{$itemid}};
10663: }
10664: }
10665: my $position = $env{'form.ipaccess_pos_'.$itemid};
10666: $position =~ s/\D+//g;
10667: if ($position ne '') {
10668: $allpos[$position] = $itemid;
10669: }
10670: my $name = $env{'form.ipaccess_name_'.$idx};
10671: $name =~ s/^\s+|\s+$//g;
10672: $confhash{$itemid}{'name'} = $name;
10673: my $possrange = $env{'form.ipaccess_range_'.$idx};
10674: $possrange =~ s/^\s+|\s+$//g;
10675: unless ($possrange eq '') {
10676: $possrange =~ s/[\r\n]+/\s/g;
10677: $possrange =~ s/\s*-\s*/-/g;
10678: $possrange =~ s/\s+/,/g;
10679: $possrange =~ s/,+/,/g;
10680: if ($possrange ne '') {
10681: my (@ok,$count);
10682: $count = 0;
10683: foreach my $poss (split(/\,/,$possrange)) {
10684: $count ++;
10685: $poss = &validate_ip_pattern($poss);
10686: if ($poss ne '') {
10687: push(@ok,$poss);
10688: }
10689: }
10690: my $diff = $count - scalar(@ok);
10691: if ($diff) {
10692: $errors .= '<li><span class="LC_error">'.
10693: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10694: $diff,$name).
10695: '</span></li>';
10696: }
10697: if (@ok) {
10698: my @cidr_list;
10699: foreach my $item (@ok) {
10700: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10701: }
10702: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10703: }
10704: }
10705: }
10706: foreach my $field ('name','ip') {
10707: unless (($idx eq 'add') || ($changes{$itemid})) {
10708: if ($current{$field} ne $confhash{$itemid}{$field}) {
10709: $changes{$itemid} = 1;
10710: last;
10711: }
10712: }
10713: }
10714: $confhash{$itemid}{'commblocks'} = {};
10715:
10716: my %commblocks;
10717: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10718: foreach my $type (@{$typeorder}) {
10719: if ($commblocks{$type}) {
10720: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10721: }
10722: unless (($idx eq 'add') || ($changes{$itemid})) {
10723: if (ref($current{'commblocks'}) eq 'HASH') {
10724: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10725: $changes{$itemid} = 1;
10726: }
10727: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10728: $changes{$itemid} = 1;
10729: }
10730: }
10731: }
10732: $confhash{$itemid}{'courses'} = {};
10733: my %crsdeletions;
10734: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10735: if (@delcrs) {
10736: map { $crsdeletions{$_} = 1; } @delcrs;
10737: }
10738: if (ref($current{'courses'}) eq 'HASH') {
10739: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10740: if ($crsdeletions{$cid}) {
10741: $changes{$itemid} = 1;
10742: } else {
10743: $confhash{$itemid}{'courses'}{$cid} = 1;
10744: }
10745: }
10746: }
10747: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10748: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10749: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10750: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10751: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10752: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10753: $errors .= '<li><span class="LC_error">'.
10754: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10755: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10756: '</span></li>';
10757: } else {
10758: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10759: $changes{$itemid} = 1;
10760: }
10761: }
10762: }
10763: if (@allpos > 0) {
10764: my $idx = 0;
10765: foreach my $itemid (@allpos) {
10766: if ($itemid ne '') {
10767: $confhash{$itemid}{'order'} = $idx;
10768: unless ($changes{$itemid}) {
10769: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10770: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10771: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10772: $changes{$itemid} = 1;
10773: }
10774: }
10775: }
10776: }
10777: $idx ++;
10778: }
10779: }
10780: }
10781: if (keys(%changes)) {
10782: my %defaultshash = (
10783: ipaccess => \%confhash,
10784: );
10785: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10786: $dom);
10787: if ($putresult eq 'ok') {
10788: my $cachetime = 1800;
10789: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10790: if (ref($lastactref) eq 'HASH') {
10791: $lastactref->{'ipaccess'} = 1;
10792: }
10793: $resulttext = &mt('Changes made:').'<ul>';
10794: my %bynum;
10795: foreach my $itemid (sort(keys(%changes))) {
10796: if (ref($confhash{$itemid}) eq 'HASH') {
10797: my $position = $confhash{$itemid}{'order'};
10798: if ($position =~ /^\d+$/) {
10799: $bynum{$position} = $itemid;
10800: }
10801: }
10802: }
10803: if (keys(%deletions)) {
10804: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10805: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10806: }
10807: }
10808: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10809: my $itemid = $bynum{$pos};
10810: if (ref($confhash{$itemid}) eq 'HASH') {
10811: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10812: my $position = $pos + 1;
10813: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10814: if ($confhash{$itemid}{'ip'} eq '') {
10815: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10816: } else {
10817: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10818: }
10819: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10820: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10821: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10822: '</li>';
10823: } else {
10824: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10825: }
10826: if (keys(%{$confhash{$itemid}{'courses'}})) {
10827: my @courses;
10828: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10829: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10830: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10831: }
10832: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10833: join('</li><li>',@courses).'</li></ul>';
10834: } else {
10835: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10836: }
10837: $resulttext .= '</ul></li>';
10838: }
10839: }
10840: $resulttext .= '</ul>';
10841: } else {
10842: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10843: }
10844: } else {
10845: $resulttext = &mt('No changes made');
10846: }
10847: if ($errors) {
10848: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10849: $errors.'</ul></p>';
10850: }
10851: return $resulttext;
10852: }
10853:
10854: sub get_ipaccess_id {
10855: my ($domain,$location) = @_;
10856: # get lock on ipaccess db
10857: my $lockhash = {
10858: lock => $env{'user.name'}.
10859: ':'.$env{'user.domain'},
10860: };
10861: my $tries = 0;
10862: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10863: my ($id,$error);
10864:
10865: while (($gotlock ne 'ok') && ($tries<10)) {
10866: $tries ++;
10867: sleep (0.1);
10868: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10869: }
10870: if ($gotlock eq 'ok') {
10871: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10872: if ($currids{'lock'}) {
10873: delete($currids{'lock'});
10874: if (keys(%currids)) {
10875: my @curr = sort { $a <=> $b } keys(%currids);
10876: if ($curr[-1] =~ /^\d+$/) {
10877: $id = 1 + $curr[-1];
10878: }
10879: } else {
10880: $id = 1;
10881: }
10882: if ($id) {
10883: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10884: $error = 'nostore';
10885: }
10886: } else {
10887: $error = 'nonumber';
10888: }
10889: }
10890: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10891: } else {
10892: $error = 'nolock';
10893: }
10894: return ($id,$error);
10895: }
10896:
1.6 raeburn 10897: sub modify_rolecolors {
1.160.6.24 raeburn 10898: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10899: my ($resulttext,%rolehash);
10900: $rolehash{'rolecolors'} = {};
1.55 raeburn 10901: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10902: if ($domconfig{'rolecolors'} eq '') {
10903: $domconfig{'rolecolors'} = {};
10904: }
10905: }
1.9 raeburn 10906: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10907: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10908: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10909: $dom);
10910: if ($putresult eq 'ok') {
10911: if (keys(%changes) > 0) {
1.41 raeburn 10912: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10913: if (ref($lastactref) eq 'HASH') {
10914: $lastactref->{'domainconfig'} = 1;
10915: }
1.6 raeburn 10916: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10917: $rolehash{'rolecolors'});
10918: } else {
10919: $resulttext = &mt('No changes made to default color schemes');
10920: }
10921: } else {
1.11 albertel 10922: $resulttext = '<span class="LC_error">'.
10923: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10924: }
10925: if ($errors) {
10926: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10927: $errors.'</ul>';
10928: }
10929: return $resulttext;
10930: }
10931:
10932: sub modify_colors {
1.9 raeburn 10933: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10934: my (%changes,%choices);
1.51 raeburn 10935: my @bgs;
1.6 raeburn 10936: my @links = ('link','alink','vlink');
1.41 raeburn 10937: my @logintext;
1.6 raeburn 10938: my @images;
10939: my $servadm = $r->dir_config('lonAdmEMail');
10940: my $errors;
1.160.6.22 raeburn 10941: my %defaults;
1.6 raeburn 10942: foreach my $role (@{$roles}) {
10943: if ($role eq 'login') {
1.12 raeburn 10944: %choices = &login_choices();
1.41 raeburn 10945: @logintext = ('textcol','bgcol');
1.12 raeburn 10946: } else {
10947: %choices = &color_font_choices();
10948: }
10949: if ($role eq 'login') {
1.41 raeburn 10950: @images = ('img','logo','domlogo','login');
1.51 raeburn 10951: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10952: } else {
10953: @images = ('img');
1.160.6.22 raeburn 10954: @bgs = ('pgbg','tabbg','sidebg');
10955: }
10956: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10957: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10958: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10959: }
10960: if ($role eq 'login') {
10961: foreach my $item (@logintext) {
1.160.6.39 raeburn 10962: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10963: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10964: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10965: }
10966: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10967: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10968: }
10969: }
10970: } else {
1.160.6.39 raeburn 10971: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10972: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10973: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10974: }
10975: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10976: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10977: }
1.6 raeburn 10978: }
1.160.6.22 raeburn 10979: foreach my $item (@bgs) {
1.160.6.39 raeburn 10980: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10981: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10982: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10983: }
10984: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10985: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10986: }
10987: }
10988: foreach my $item (@links) {
1.160.6.39 raeburn 10989: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10990: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10991: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10992: }
10993: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10994: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10995: }
1.6 raeburn 10996: }
1.46 raeburn 10997: my ($configuserok,$author_ok,$switchserver) =
10998: &config_check($dom,$confname,$servadm);
1.9 raeburn 10999: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11000: if (ref($domconfig->{$role}) ne 'HASH') {
11001: $domconfig->{$role} = {};
11002: }
1.8 raeburn 11003: foreach my $img (@images) {
1.160.6.118.2 2(raebur 11004:2): if ($role eq 'login') {
11005:2): if (($img eq 'img') || ($img eq 'logo')) {
11006:2): if (defined($env{'form.login_showlogo_'.$img})) {
11007:2): $confhash->{$role}{'showlogo'}{$img} = 1;
11008:2): } else {
11009:2): $confhash->{$role}{'showlogo'}{$img} = 0;
11010:2): }
1.70 raeburn 11011: }
1.160.6.118.2 2(raebur 11012:2): if ($env{'form.login_alt_'.$img} ne '') {
11013:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11014:2): }
11015:2): }
1.18 albertel 11016: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11017: && !defined($domconfig->{$role}{$img})
11018: && !$env{'form.'.$role.'_del_'.$img}
11019: && $env{'form.'.$role.'_import_'.$img}) {
11020: # import the old configured image from the .tab setting
11021: # if they haven't provided a new one
11022: $domconfig->{$role}{$img} =
11023: $env{'form.'.$role.'_import_'.$img};
11024: }
1.6 raeburn 11025: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11026: my $error;
1.6 raeburn 11027: if ($configuserok eq 'ok') {
1.9 raeburn 11028: if ($switchserver) {
1.12 raeburn 11029: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11030: } else {
11031: if ($author_ok eq 'ok') {
11032: my ($result,$logourl) =
11033: &publishlogo($r,'upload',$role.'_'.$img,
11034: $dom,$confname,$img,$width,$height);
11035: if ($result eq 'ok') {
11036: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11037: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11038: } else {
1.12 raeburn 11039: $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 11040: }
11041: } else {
1.46 raeburn 11042: $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 11043: }
11044: }
11045: } else {
1.46 raeburn 11046: $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 11047: }
11048: if ($error) {
1.8 raeburn 11049: &Apache::lonnet::logthis($error);
1.11 albertel 11050: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11051: }
11052: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11053: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11054: my $error;
11055: if ($configuserok eq 'ok') {
11056: # is confname an author?
11057: if ($switchserver eq '') {
11058: if ($author_ok eq 'ok') {
11059: my ($result,$logourl) =
11060: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11061: $dom,$confname,$img,$width,$height);
11062: if ($result eq 'ok') {
11063: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11064: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11065: }
11066: }
11067: }
11068: }
1.6 raeburn 11069: }
11070: }
11071: }
11072: if (ref($domconfig) eq 'HASH') {
11073: if (ref($domconfig->{$role}) eq 'HASH') {
11074: foreach my $img (@images) {
11075: if ($domconfig->{$role}{$img} ne '') {
11076: if ($env{'form.'.$role.'_del_'.$img}) {
11077: $confhash->{$role}{$img} = '';
1.12 raeburn 11078: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11079: } else {
1.9 raeburn 11080: if ($confhash->{$role}{$img} eq '') {
11081: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11082: }
1.6 raeburn 11083: }
11084: } else {
11085: if ($env{'form.'.$role.'_del_'.$img}) {
11086: $confhash->{$role}{$img} = '';
1.12 raeburn 11087: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11088: }
11089: }
1.160.6.118.2 2(raebur 11090:2): if ($role eq 'login') {
11091:2): if (($img eq 'logo') || ($img eq 'img')) {
11092:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11093:2): if ($confhash->{$role}{'showlogo'}{$img} ne
11094:2): $domconfig->{$role}{'showlogo'}{$img}) {
11095:2): $changes{$role}{'showlogo'}{$img} = 1;
11096:2): }
11097:2): } else {
11098:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11099:2): $changes{$role}{'showlogo'}{$img} = 1;
11100:2): }
1.70 raeburn 11101: }
1.160.6.118.2 2(raebur 11102:2): }
11103:2): if ($img ne 'login') {
11104:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11105:2): if ($confhash->{$role}{'alttext'}{$img} ne
11106:2): $domconfig->{$role}{'alttext'}{$img}) {
11107:2): $changes{$role}{'alttext'}{$img} = 1;
11108:2): }
11109:2): } else {
11110:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11111:2): $changes{$role}{'alttext'}{$img} = 1;
11112:2): }
1.70 raeburn 11113: }
11114: }
11115: }
11116: }
1.6 raeburn 11117: if ($domconfig->{$role}{'font'} ne '') {
11118: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11119: $changes{$role}{'font'} = 1;
11120: }
11121: } else {
11122: if ($confhash->{$role}{'font'}) {
11123: $changes{$role}{'font'} = 1;
11124: }
11125: }
1.107 raeburn 11126: if ($role ne 'login') {
11127: if ($domconfig->{$role}{'fontmenu'} ne '') {
11128: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11129: $changes{$role}{'fontmenu'} = 1;
11130: }
11131: } else {
11132: if ($confhash->{$role}{'fontmenu'}) {
11133: $changes{$role}{'fontmenu'} = 1;
11134: }
1.97 tempelho 11135: }
11136: }
1.6 raeburn 11137: foreach my $item (@bgs) {
11138: if ($domconfig->{$role}{$item} ne '') {
11139: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11140: $changes{$role}{'bgs'}{$item} = 1;
11141: }
11142: } else {
11143: if ($confhash->{$role}{$item}) {
11144: $changes{$role}{'bgs'}{$item} = 1;
11145: }
11146: }
11147: }
11148: foreach my $item (@links) {
11149: if ($domconfig->{$role}{$item} ne '') {
11150: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11151: $changes{$role}{'links'}{$item} = 1;
11152: }
11153: } else {
11154: if ($confhash->{$role}{$item}) {
11155: $changes{$role}{'links'}{$item} = 1;
11156: }
11157: }
11158: }
1.41 raeburn 11159: foreach my $item (@logintext) {
11160: if ($domconfig->{$role}{$item} ne '') {
11161: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11162: $changes{$role}{'logintext'}{$item} = 1;
11163: }
11164: } else {
11165: if ($confhash->{$role}{$item}) {
11166: $changes{$role}{'logintext'}{$item} = 1;
11167: }
11168: }
11169: }
1.6 raeburn 11170: } else {
11171: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11172: \@logintext,$confhash,\%changes);
1.6 raeburn 11173: }
11174: } else {
11175: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11176: \@logintext,$confhash,\%changes);
1.6 raeburn 11177: }
11178: }
11179: return ($errors,%changes);
11180: }
11181:
1.46 raeburn 11182: sub config_check {
11183: my ($dom,$confname,$servadm) = @_;
11184: my ($configuserok,$author_ok,$switchserver,%currroles);
11185: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11186: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11187: $confname,$servadm);
11188: if ($configuserok eq 'ok') {
11189: $switchserver = &check_switchserver($dom,$confname);
11190: if ($switchserver eq '') {
11191: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11192: }
11193: }
11194: return ($configuserok,$author_ok,$switchserver);
11195: }
11196:
1.6 raeburn 11197: sub default_change_checker {
1.41 raeburn 11198: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11199: foreach my $item (@{$links}) {
11200: if ($confhash->{$role}{$item}) {
11201: $changes->{$role}{'links'}{$item} = 1;
11202: }
11203: }
11204: foreach my $item (@{$bgs}) {
11205: if ($confhash->{$role}{$item}) {
11206: $changes->{$role}{'bgs'}{$item} = 1;
11207: }
11208: }
1.41 raeburn 11209: foreach my $item (@{$logintext}) {
11210: if ($confhash->{$role}{$item}) {
11211: $changes->{$role}{'logintext'}{$item} = 1;
11212: }
11213: }
1.6 raeburn 11214: foreach my $img (@{$images}) {
11215: if ($env{'form.'.$role.'_del_'.$img}) {
11216: $confhash->{$role}{$img} = '';
1.12 raeburn 11217: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11218: }
1.70 raeburn 11219: if ($role eq 'login') {
11220: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11221: $changes->{$role}{'showlogo'}{$img} = 1;
11222: }
1.160.6.118.2 2(raebur 11223:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11224:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11225:2): $changes->{$role}{'alttext'}{$img} = 1;
11226:2): }
11227:2): }
1.70 raeburn 11228: }
1.6 raeburn 11229: }
11230: if ($confhash->{$role}{'font'}) {
11231: $changes->{$role}{'font'} = 1;
11232: }
1.48 raeburn 11233: }
1.6 raeburn 11234:
11235: sub display_colorchgs {
11236: my ($dom,$changes,$roles,$confhash) = @_;
11237: my (%choices,$resulttext);
11238: if (!grep(/^login$/,@{$roles})) {
11239: $resulttext = &mt('Changes made:').'<br />';
11240: }
11241: foreach my $role (@{$roles}) {
11242: if ($role eq 'login') {
11243: %choices = &login_choices();
11244: } else {
11245: %choices = &color_font_choices();
11246: }
11247: if (ref($changes->{$role}) eq 'HASH') {
11248: if ($role ne 'login') {
11249: $resulttext .= '<h4>'.&mt($role).'</h4>';
11250: }
11251: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11252: if ($role ne 'login') {
11253: $resulttext .= '<ul>';
11254: }
11255: if (ref($changes->{$role}{$key}) eq 'HASH') {
11256: if ($role ne 'login') {
11257: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11258: }
11259: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11260: if (($role eq 'login') && ($key eq 'showlogo')) {
11261: if ($confhash->{$role}{$key}{$item}) {
11262: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11263: } else {
11264: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11265: }
1.160.6.118.2 2(raebur 11266:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
11267:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 11268:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 11269:2): $confhash->{$role}{$key}{$item}).'</li>';
11270:2): } else {
11271:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
11272:2): }
1.70 raeburn 11273: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11274: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11275: } else {
1.12 raeburn 11276: my $newitem = $confhash->{$role}{$item};
11277: if ($key eq 'images') {
11278: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
11279: }
11280: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11281: }
11282: }
11283: if ($role ne 'login') {
11284: $resulttext .= '</ul></li>';
11285: }
11286: } else {
11287: if ($confhash->{$role}{$key} eq '') {
11288: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11289: } else {
11290: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11291: }
11292: }
11293: if ($role ne 'login') {
11294: $resulttext .= '</ul>';
11295: }
11296: }
11297: }
11298: }
1.3 raeburn 11299: return $resulttext;
1.1 raeburn 11300: }
11301:
1.9 raeburn 11302: sub thumb_dimensions {
11303: return ('200','50');
11304: }
11305:
1.16 raeburn 11306: sub check_dimensions {
11307: my ($inputfile) = @_;
11308: my ($fullwidth,$fullheight);
11309: if ($inputfile =~ m|^[/\w.\-]+$|) {
11310: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11311: my $imageinfo = <PIPE>;
11312: if (!close(PIPE)) {
11313: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11314: }
11315: chomp($imageinfo);
11316: my ($fullsize) =
1.21 raeburn 11317: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11318: if ($fullsize) {
11319: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11320: }
11321: }
11322: }
11323: return ($fullwidth,$fullheight);
11324: }
11325:
1.9 raeburn 11326: sub check_configuser {
11327: my ($uhome,$dom,$confname,$servadm) = @_;
11328: my ($configuserok,%currroles);
11329: if ($uhome eq 'no_host') {
11330: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 11331: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11332: $configuserok =
11333: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11334: $configpass,'','','','','',undef,$servadm);
11335: } else {
11336: $configuserok = 'ok';
11337: %currroles =
11338: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11339: }
11340: return ($configuserok,%currroles);
11341: }
11342:
11343: sub check_authorstatus {
11344: my ($dom,$confname,%currroles) = @_;
11345: my $author_ok;
1.40 raeburn 11346: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11347: my $start = time;
11348: my $end = 0;
11349: $author_ok =
11350: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11351: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11352: } else {
11353: $author_ok = 'ok';
11354: }
11355: return $author_ok;
11356: }
11357:
11358: sub publishlogo {
1.46 raeburn 11359: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 11360: my ($output,$fname,$logourl);
11361: if ($action eq 'upload') {
11362: $fname=$env{'form.'.$formname.'.filename'};
11363: chop($env{'form.'.$formname});
11364: } else {
11365: ($fname) = ($formname =~ /([^\/]+)$/);
11366: }
1.46 raeburn 11367: if ($savefileas ne '') {
11368: $fname = $savefileas;
11369: }
1.9 raeburn 11370: $fname=&Apache::lonnet::clean_filename($fname);
11371: # See if there is anything left
11372: unless ($fname) { return ('error: no uploaded file'); }
11373: $fname="$subdir/$fname";
1.160.6.5 raeburn 11374: my $docroot=$r->dir_config('lonDocRoot');
11375: my $filepath="$docroot/priv";
11376: my $relpath = "$dom/$confname";
1.9 raeburn 11377: my ($fnamepath,$file,$fetchthumb);
11378: $file=$fname;
11379: if ($fname=~m|/|) {
11380: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11381: }
1.160.6.26 raeburn 11382: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11383: my $count;
1.160.6.5 raeburn 11384: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11385: $filepath.="/$parts[$count]";
11386: if ((-e $filepath)!=1) {
11387: mkdir($filepath,02770);
11388: }
11389: }
11390: # Check for bad extension and disallow upload
11391: if ($file=~/\.(\w+)$/ &&
11392: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11393: $output =
1.160.6.25 raeburn 11394: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11395: } elsif ($file=~/\.(\w+)$/ &&
11396: !defined(&Apache::loncommon::fileembstyle($1))) {
11397: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11398: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 11399: $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 11400: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 11401: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11402: } else {
11403: my $source = $filepath.'/'.$file;
11404: my $logfile;
1.160.6.88 raeburn 11405: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 11406: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11407: }
11408: print $logfile
11409: "\n================= Publish ".localtime()." ================\n".
11410: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11411: # Save the file
1.160.6.88 raeburn 11412: if (!open(FH,">",$source)) {
1.9 raeburn 11413: &Apache::lonnet::logthis('Failed to create '.$source);
11414: return (&mt('Failed to create file'));
11415: }
11416: if ($action eq 'upload') {
11417: if (!print FH ($env{'form.'.$formname})) {
11418: &Apache::lonnet::logthis('Failed to write to '.$source);
11419: return (&mt('Failed to write file'));
11420: }
11421: } else {
11422: my $original = &Apache::lonnet::filelocation('',$formname);
11423: if(!copy($original,$source)) {
11424: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11425: return (&mt('Failed to write file'));
11426: }
11427: }
11428: close(FH);
11429: chmod(0660, $source); # Permissions to rw-rw---.
11430:
11431: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11432: my $copyfile=$targetdir.'/'.$file;
11433:
11434: my @parts=split(/\//,$targetdir);
11435: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11436: for (my $count=5;$count<=$#parts;$count++) {
11437: $path.="/$parts[$count]";
11438: if (!-e $path) {
11439: print $logfile "\nCreating directory ".$path;
11440: mkdir($path,02770);
11441: }
11442: }
11443: my $versionresult;
11444: if (-e $copyfile) {
11445: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11446: } else {
11447: $versionresult = 'ok';
11448: }
11449: if ($versionresult eq 'ok') {
11450: if (copy($source,$copyfile)) {
11451: print $logfile "\nCopied original source to ".$copyfile."\n";
11452: $output = 'ok';
11453: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11454: push(@{$modified_urls},[$copyfile,$source]);
11455: my $metaoutput =
11456: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11457: unless ($registered_cleanup) {
11458: my $handlers = $r->get_handlers('PerlCleanupHandler');
11459: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11460: $registered_cleanup=1;
11461: }
1.9 raeburn 11462: } else {
11463: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11464: $output = &mt('Failed to copy file to RES space').", $!";
11465: }
11466: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11467: my $inputfile = $filepath.'/'.$file;
11468: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11469: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11470: if ($fullwidth ne '' && $fullheight ne '') {
11471: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11472: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 11473: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11474: system({$args[0]} @args);
1.16 raeburn 11475: chmod(0660, $filepath.'/tn-'.$file);
11476: if (-e $outfile) {
11477: my $copyfile=$targetdir.'/tn-'.$file;
11478: if (copy($outfile,$copyfile)) {
11479: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11480: my $thumb_metaoutput =
11481: &write_metadata($dom,$confname,$formname,
11482: $targetdir,'tn-'.$file,$logfile);
11483: push(@{$modified_urls},[$copyfile,$outfile]);
11484: unless ($registered_cleanup) {
11485: my $handlers = $r->get_handlers('PerlCleanupHandler');
11486: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11487: $registered_cleanup=1;
11488: }
1.16 raeburn 11489: } else {
11490: print $logfile "\nUnable to write ".$copyfile.
11491: ':'.$!."\n";
11492: }
11493: }
1.9 raeburn 11494: }
11495: }
11496: }
11497: } else {
11498: $output = $versionresult;
11499: }
11500: }
11501: return ($output,$logourl);
11502: }
11503:
11504: sub logo_versioning {
11505: my ($targetdir,$file,$logfile) = @_;
11506: my $target = $targetdir.'/'.$file;
11507: my ($maxversion,$fn,$extn,$output);
11508: $maxversion = 0;
11509: if ($file =~ /^(.+)\.(\w+)$/) {
11510: $fn=$1;
11511: $extn=$2;
11512: }
11513: opendir(DIR,$targetdir);
11514: while (my $filename=readdir(DIR)) {
11515: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11516: $maxversion=($1>$maxversion)?$1:$maxversion;
11517: }
11518: }
11519: $maxversion++;
11520: print $logfile "\nCreating old version ".$maxversion."\n";
11521: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11522: if (copy($target,$copyfile)) {
11523: print $logfile "Copied old target to ".$copyfile."\n";
11524: $copyfile=$copyfile.'.meta';
11525: if (copy($target.'.meta',$copyfile)) {
11526: print $logfile "Copied old target metadata to ".$copyfile."\n";
11527: $output = 'ok';
11528: } else {
11529: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11530: $output = &mt('Failed to copy old meta').", $!, ";
11531: }
11532: } else {
11533: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11534: $output = &mt('Failed to copy old target').", $!, ";
11535: }
11536: return $output;
11537: }
11538:
11539: sub write_metadata {
11540: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11541: my (%metadatafields,%metadatakeys,$output);
11542: $metadatafields{'title'}=$formname;
11543: $metadatafields{'creationdate'}=time;
11544: $metadatafields{'lastrevisiondate'}=time;
11545: $metadatafields{'copyright'}='public';
11546: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11547: $env{'user.domain'};
11548: $metadatafields{'authorspace'}=$confname.':'.$dom;
11549: $metadatafields{'domain'}=$dom;
11550: {
11551: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11552: my $mfh;
1.160.6.88 raeburn 11553: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 11554: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11555: unless ($_=~/\./) {
11556: my $unikey=$_;
11557: $unikey=~/^([A-Za-z]+)/;
11558: my $tag=$1;
11559: $tag=~tr/A-Z/a-z/;
11560: print $mfh "\n\<$tag";
11561: foreach (split(/\,/,$metadatakeys{$unikey})) {
11562: my $value=$metadatafields{$unikey.'.'.$_};
11563: $value=~s/\"/\'\'/g;
11564: print $mfh ' '.$_.'="'.$value.'"';
11565: }
11566: print $mfh '>'.
11567: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11568: .'</'.$tag.'>';
11569: }
11570: }
11571: $output = 'ok';
11572: print $logfile "\nWrote metadata";
11573: close($mfh);
11574: } else {
11575: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11576: $output = &mt('Could not write metadata');
11577: }
11578: }
1.155 raeburn 11579: return $output;
11580: }
11581:
11582: sub notifysubscribed {
11583: foreach my $targetsource (@{$modified_urls}){
11584: next unless (ref($targetsource) eq 'ARRAY');
11585: my ($target,$source)=@{$targetsource};
11586: if ($source ne '') {
1.160.6.88 raeburn 11587: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11588: print $logfh "\nCleanup phase: Notifications\n";
11589: my @subscribed=&subscribed_hosts($target);
11590: foreach my $subhost (@subscribed) {
11591: print $logfh "\nNotifying host ".$subhost.':';
11592: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11593: print $logfh $reply;
11594: }
11595: my @subscribedmeta=&subscribed_hosts("$target.meta");
11596: foreach my $subhost (@subscribedmeta) {
11597: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11598: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11599: $subhost);
11600: print $logfh $reply;
11601: }
11602: print $logfh "\n============ Done ============\n";
1.160 raeburn 11603: close($logfh);
1.155 raeburn 11604: }
11605: }
11606: }
11607: return OK;
11608: }
11609:
11610: sub subscribed_hosts {
11611: my ($target) = @_;
11612: my @subscribed;
1.160.6.88 raeburn 11613: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11614: while (my $subline=<$fh>) {
11615: if ($subline =~ /^($match_lonid):/) {
11616: my $host = $1;
11617: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11618: unless (grep(/^\Q$host\E$/,@subscribed)) {
11619: push(@subscribed,$host);
11620: }
11621: }
11622: }
11623: }
11624: }
11625: return @subscribed;
1.9 raeburn 11626: }
11627:
11628: sub check_switchserver {
11629: my ($dom,$confname) = @_;
11630: my ($allowed,$switchserver);
11631: my $home = &Apache::lonnet::homeserver($confname,$dom);
11632: if ($home eq 'no_host') {
11633: $home = &Apache::lonnet::domain($dom,'primary');
11634: }
11635: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11636: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11637: if (!$allowed) {
1.160.6.11 raeburn 11638: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11639: }
11640: return $switchserver;
11641: }
11642:
1.1 raeburn 11643: sub modify_quotas {
1.160.6.30 raeburn 11644: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11645: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 11646: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 11647: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11648: $validationfieldsref);
1.86 raeburn 11649: if ($action eq 'quotas') {
11650: $context = 'tools';
1.160.6.26 raeburn 11651: } else {
1.86 raeburn 11652: $context = $action;
11653: }
11654: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 11655: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 11656: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11657: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11658: %titles = &courserequest_titles();
11659: $toolregexp = join('|',@usertools);
11660: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 11661: $confname = $dom.'-domainconfig';
11662: my $servadm = $r->dir_config('lonAdmEMail');
11663: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 11664: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11665: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 11666: } elsif ($context eq 'requestauthor') {
11667: @usertools = ('author');
11668: %titles = &authorrequest_titles();
1.86 raeburn 11669: } else {
1.160.6.4 raeburn 11670: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11671: %titles = &tool_titles();
1.86 raeburn 11672: }
1.160.6.27 raeburn 11673: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11674: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11675: foreach my $key (keys(%env)) {
1.101 raeburn 11676: if ($context eq 'requestcourses') {
11677: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11678: my $item = $1;
11679: my $type = $2;
11680: if ($type =~ /^limit_(.+)/) {
11681: $limithash{$item}{$1} = $env{$key};
11682: } else {
11683: $confhash{$item}{$type} = $env{$key};
11684: }
11685: }
1.160.6.5 raeburn 11686: } elsif ($context eq 'requestauthor') {
11687: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11688: $confhash{$1} = $env{$key};
11689: }
1.101 raeburn 11690: } else {
1.86 raeburn 11691: if ($key =~ /^form\.quota_(.+)$/) {
11692: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 11693: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11694: $confhash{'authorquota'}{$1} = $env{$key};
11695: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11696: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11697: }
1.72 raeburn 11698: }
11699: }
1.160.6.5 raeburn 11700: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 11701: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11702: @approvalnotify = sort(@approvalnotify);
11703: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 11704: my @crstypes = ('official','unofficial','community','textbook');
11705: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11706: foreach my $type (@hasuniquecode) {
11707: if (grep(/^\Q$type\E$/,@crstypes)) {
11708: $confhash{'uniquecode'}{$type} = 1;
11709: }
11710: }
1.160.6.46 raeburn 11711: my (%newbook,%allpos);
1.160.6.30 raeburn 11712: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11713: foreach my $type ('textbooks','templates') {
11714: @{$allpos{$type}} = ();
11715: my $invalid;
11716: if ($type eq 'textbooks') {
11717: $invalid = &mt('Invalid LON-CAPA course for textbook');
11718: } else {
11719: $invalid = &mt('Invalid LON-CAPA course for template');
11720: }
11721: if ($env{'form.'.$type.'_addbook'}) {
11722: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11723: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11724: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11725: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11726: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11727: } else {
11728: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11729: my $position = $env{'form.'.$type.'_addbook_pos'};
11730: $position =~ s/\D+//g;
11731: if ($position ne '') {
11732: $allpos{$type}[$position] = $newbook{$type};
11733: }
1.160.6.30 raeburn 11734: }
1.160.6.46 raeburn 11735: } else {
11736: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 11737: }
11738: }
1.160.6.46 raeburn 11739: }
1.160.6.30 raeburn 11740: }
1.102 raeburn 11741: if (ref($domconfig{$action}) eq 'HASH') {
11742: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11743: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11744: $changes{'notify'}{'approval'} = 1;
11745: }
11746: } else {
1.144 raeburn 11747: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11748: $changes{'notify'}{'approval'} = 1;
11749: }
11750: }
1.160.6.30 raeburn 11751: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11752: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11753: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11754: unless ($confhash{'uniquecode'}{$crstype}) {
11755: $changes{'uniquecode'} = 1;
11756: }
11757: }
11758: unless ($changes{'uniquecode'}) {
11759: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11760: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11761: $changes{'uniquecode'} = 1;
11762: }
11763: }
11764: }
11765: } else {
11766: $changes{'uniquecode'} = 1;
11767: }
11768: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11769: $changes{'uniquecode'} = 1;
11770: }
11771: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11772: foreach my $type ('textbooks','templates') {
11773: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11774: my %deletions;
11775: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11776: if (@todelete) {
11777: map { $deletions{$_} = 1; } @todelete;
11778: }
11779: my %imgdeletions;
11780: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11781: if (@todeleteimages) {
11782: map { $imgdeletions{$_} = 1; } @todeleteimages;
11783: }
11784: my $maxnum = $env{'form.'.$type.'_maxnum'};
11785: for (my $i=0; $i<=$maxnum; $i++) {
11786: my $itemid = $env{'form.'.$type.'_id_'.$i};
11787: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11788: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11789: if ($deletions{$key}) {
11790: if ($domconfig{$action}{$type}{$key}{'image'}) {
11791: #FIXME need to obsolete item in RES space
11792: }
11793: next;
11794: } else {
11795: my $newpos = $env{'form.'.$itemid};
11796: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 11797: foreach my $item ('subject','title','publisher','author') {
11798: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11799: ($type eq 'templates'));
1.160.6.46 raeburn 11800: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11801: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11802: $changes{$type}{$key} = 1;
11803: }
11804: }
11805: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 11806: }
1.160.6.46 raeburn 11807: if ($imgdeletions{$key}) {
11808: $changes{$type}{$key} = 1;
11809: #FIXME need to obsolete item in RES space
11810: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11811: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 11812: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11813: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11814: } else {
11815: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11816: $cdom,$cnum,$type,$configuserok,
11817: $switchserver,$author_ok);
11818: if ($imgurl) {
11819: $confhash{$type}{$key}{'image'} = $imgurl;
11820: $changes{$type}{$key} = 1;
11821: }
11822: if ($error) {
11823: &Apache::lonnet::logthis($error);
11824: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11825: }
1.160.6.46 raeburn 11826: }
11827: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11828: $confhash{$type}{$key}{'image'} =
11829: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 11830: }
11831: }
11832: }
11833: }
11834: }
11835: }
1.102 raeburn 11836: } else {
1.144 raeburn 11837: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11838: $changes{'notify'}{'approval'} = 1;
11839: }
1.160.6.30 raeburn 11840: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11841: $changes{'uniquecode'} = 1;
11842: }
11843: }
11844: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11845: foreach my $type ('textbooks','templates') {
11846: if ($newbook{$type}) {
11847: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 11848: foreach my $item ('subject','title','publisher','author') {
11849: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11850: ($type eq 'template'));
1.160.6.46 raeburn 11851: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11852: if ($env{'form.'.$type.'_addbook_'.$item}) {
11853: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11854: }
11855: }
11856: if ($type eq 'textbooks') {
11857: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11858: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 11859: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11860: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11861: } else {
11862: my ($imageurl,$error) =
11863: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11864: $configuserok,$switchserver,$author_ok);
11865: if ($imageurl) {
11866: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11867: }
11868: if ($error) {
11869: &Apache::lonnet::logthis($error);
11870: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11871: }
1.160.6.46 raeburn 11872: }
11873: }
1.160.6.30 raeburn 11874: }
11875: }
1.160.6.46 raeburn 11876: if (@{$allpos{$type}} > 0) {
11877: my $idx = 0;
11878: foreach my $item (@{$allpos{$type}}) {
11879: if ($item ne '') {
11880: $confhash{$type}{$item}{'order'} = $idx;
11881: if (ref($domconfig{$action}) eq 'HASH') {
11882: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11883: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11884: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11885: $changes{$type}{$item} = 1;
11886: }
1.160.6.30 raeburn 11887: }
11888: }
11889: }
1.160.6.46 raeburn 11890: $idx ++;
1.160.6.30 raeburn 11891: }
11892: }
11893: }
11894: }
1.160.6.39 raeburn 11895: if (ref($validationitemsref) eq 'ARRAY') {
11896: foreach my $item (@{$validationitemsref}) {
11897: if ($item eq 'fields') {
11898: my @changed;
11899: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11900: if (@{$confhash{'validation'}{$item}} > 0) {
11901: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11902: }
1.160.6.65 raeburn 11903: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11904: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11905: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11906: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11907: $domconfig{'requestcourses'}{'validation'}{$item});
11908: } else {
11909: @changed = @{$confhash{'validation'}{$item}};
11910: }
1.160.6.39 raeburn 11911: } else {
11912: @changed = @{$confhash{'validation'}{$item}};
11913: }
11914: } else {
11915: @changed = @{$confhash{'validation'}{$item}};
11916: }
11917: if (@changed) {
11918: if ($confhash{'validation'}{$item}) {
11919: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11920: } else {
11921: $changes{'validation'}{$item} = &mt('None');
11922: }
11923: }
11924: } else {
11925: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11926: if ($item eq 'markup') {
11927: if ($env{'form.requestcourses_validation_'.$item}) {
11928: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11929: }
11930: }
1.160.6.65 raeburn 11931: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11932: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11933: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11934: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11935: }
11936: } else {
11937: if ($confhash{'validation'}{$item} ne '') {
11938: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11939: }
1.160.6.39 raeburn 11940: }
11941: } else {
11942: if ($confhash{'validation'}{$item} ne '') {
11943: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11944: }
11945: }
11946: }
11947: }
11948: }
11949: if ($env{'form.validationdc'}) {
11950: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11951: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11952: if (exists($domcoords{$newval})) {
11953: $confhash{'validation'}{'dc'} = $newval;
11954: }
11955: }
11956: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11957: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11958: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11959: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11960: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11961: if ($confhash{'validation'}{'dc'} eq '') {
11962: $changes{'validation'}{'dc'} = &mt('None');
11963: } else {
11964: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11965: }
1.160.6.39 raeburn 11966: }
1.160.6.65 raeburn 11967: } elsif ($confhash{'validation'}{'dc'} ne '') {
11968: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11969: }
11970: } elsif ($confhash{'validation'}{'dc'} ne '') {
11971: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11972: }
11973: } elsif ($confhash{'validation'}{'dc'} ne '') {
11974: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11975: }
1.160.6.65 raeburn 11976: } else {
11977: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11978: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11979: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11980: $changes{'validation'}{'dc'} = &mt('None');
11981: }
11982: }
1.160.6.39 raeburn 11983: }
11984: }
1.102 raeburn 11985: }
11986: } else {
1.86 raeburn 11987: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 11988: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11989: }
1.72 raeburn 11990: foreach my $item (@usertools) {
11991: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11992: my $unset;
1.101 raeburn 11993: if ($context eq 'requestcourses') {
1.104 raeburn 11994: $unset = '0';
11995: if ($type eq '_LC_adv') {
11996: $unset = '';
11997: }
1.101 raeburn 11998: if ($confhash{$item}{$type} eq 'autolimit') {
11999: $confhash{$item}{$type} .= '=';
12000: unless ($limithash{$item}{$type} =~ /\D/) {
12001: $confhash{$item}{$type} .= $limithash{$item}{$type};
12002: }
12003: }
1.160.6.5 raeburn 12004: } elsif ($context eq 'requestauthor') {
12005: $unset = '0';
12006: if ($type eq '_LC_adv') {
12007: $unset = '';
12008: }
1.72 raeburn 12009: } else {
1.101 raeburn 12010: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12011: $confhash{$item}{$type} = 1;
12012: } else {
12013: $confhash{$item}{$type} = 0;
12014: }
1.72 raeburn 12015: }
1.86 raeburn 12016: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 12017: if ($action eq 'requestauthor') {
12018: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12019: $changes{$type} = 1;
12020: }
12021: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12022: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12023: $changes{$item}{$type} = 1;
12024: }
12025: } else {
12026: if ($context eq 'requestcourses') {
1.104 raeburn 12027: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12028: $changes{$item}{$type} = 1;
12029: }
12030: } else {
12031: if (!$confhash{$item}{$type}) {
12032: $changes{$item}{$type} = 1;
12033: }
12034: }
12035: }
12036: } else {
12037: if ($context eq 'requestcourses') {
1.104 raeburn 12038: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12039: $changes{$item}{$type} = 1;
12040: }
1.160.6.5 raeburn 12041: } elsif ($context eq 'requestauthor') {
12042: if ($confhash{$type} ne $unset) {
12043: $changes{$type} = 1;
12044: }
1.72 raeburn 12045: } else {
12046: if (!$confhash{$item}{$type}) {
12047: $changes{$item}{$type} = 1;
12048: }
12049: }
12050: }
1.1 raeburn 12051: }
12052: }
1.160.6.5 raeburn 12053: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12054: if (ref($domconfig{'quotas'}) eq 'HASH') {
12055: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12056: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12057: if (exists($confhash{'defaultquota'}{$key})) {
12058: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12059: $changes{'defaultquota'}{$key} = 1;
12060: }
12061: } else {
12062: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12063: }
12064: }
1.86 raeburn 12065: } else {
12066: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12067: if (exists($confhash{'defaultquota'}{$key})) {
12068: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12069: $changes{'defaultquota'}{$key} = 1;
12070: }
12071: } else {
12072: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12073: }
1.1 raeburn 12074: }
12075: }
1.160.6.20 raeburn 12076: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12077: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12078: if (exists($confhash{'authorquota'}{$key})) {
12079: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12080: $changes{'authorquota'}{$key} = 1;
12081: }
12082: } else {
12083: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12084: }
12085: }
12086: }
1.1 raeburn 12087: }
1.86 raeburn 12088: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12089: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12090: if (ref($domconfig{'quotas'}) eq 'HASH') {
12091: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12092: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12093: $changes{'defaultquota'}{$key} = 1;
12094: }
12095: } else {
12096: if (!exists($domconfig{'quotas'}{$key})) {
12097: $changes{'defaultquota'}{$key} = 1;
12098: }
1.72 raeburn 12099: }
12100: } else {
1.86 raeburn 12101: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12102: }
1.1 raeburn 12103: }
12104: }
1.160.6.20 raeburn 12105: if (ref($confhash{'authorquota'}) eq 'HASH') {
12106: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12107: if (ref($domconfig{'quotas'}) eq 'HASH') {
12108: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12109: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12110: $changes{'authorquota'}{$key} = 1;
12111: }
12112: } else {
12113: $changes{'authorquota'}{$key} = 1;
12114: }
12115: } else {
12116: $changes{'authorquota'}{$key} = 1;
12117: }
12118: }
12119: }
1.1 raeburn 12120: }
1.72 raeburn 12121:
1.160.6.5 raeburn 12122: if ($context eq 'requestauthor') {
12123: $domdefaults{'requestauthor'} = \%confhash;
12124: } else {
12125: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 12126: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 12127: $domdefaults{$key} = $confhash{$key};
12128: }
1.160.6.5 raeburn 12129: }
1.72 raeburn 12130: }
1.160.6.5 raeburn 12131:
1.1 raeburn 12132: my %quotahash = (
1.86 raeburn 12133: $action => { %confhash }
1.1 raeburn 12134: );
12135: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12136: $dom);
12137: if ($putresult eq 'ok') {
12138: if (keys(%changes) > 0) {
1.72 raeburn 12139: my $cachetime = 24*60*60;
12140: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12141: if (ref($lastactref) eq 'HASH') {
12142: $lastactref->{'domdefaults'} = 1;
12143: }
1.1 raeburn 12144: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 12145: unless (($context eq 'requestcourses') ||
12146: ($context eq 'requestauthor')) {
1.86 raeburn 12147: if (ref($changes{'defaultquota'}) eq 'HASH') {
12148: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12149: foreach my $type (@{$types},'default') {
12150: if (defined($changes{'defaultquota'}{$type})) {
12151: my $typetitle = $usertypes->{$type};
12152: if ($type eq 'default') {
12153: $typetitle = $othertitle;
12154: }
1.160.6.28 raeburn 12155: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12156: }
12157: }
1.86 raeburn 12158: $resulttext .= '</ul></li>';
1.72 raeburn 12159: }
1.160.6.20 raeburn 12160: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 12161: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 12162: foreach my $type (@{$types},'default') {
12163: if (defined($changes{'authorquota'}{$type})) {
12164: my $typetitle = $usertypes->{$type};
12165: if ($type eq 'default') {
12166: $typetitle = $othertitle;
12167: }
1.160.6.28 raeburn 12168: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 12169: }
12170: }
12171: $resulttext .= '</ul></li>';
12172: }
1.72 raeburn 12173: }
1.80 raeburn 12174: my %newenv;
1.72 raeburn 12175: foreach my $item (@usertools) {
1.160.6.5 raeburn 12176: my (%haschgs,%inconf);
12177: if ($context eq 'requestauthor') {
12178: %haschgs = %changes;
12179: %inconf = %confhash;
12180: } else {
12181: if (ref($changes{$item}) eq 'HASH') {
12182: %haschgs = %{$changes{$item}};
12183: }
12184: if (ref($confhash{$item}) eq 'HASH') {
12185: %inconf = %{$confhash{$item}};
12186: }
12187: }
12188: if (keys(%haschgs) > 0) {
1.80 raeburn 12189: my $newacc =
12190: &Apache::lonnet::usertools_access($env{'user.name'},
12191: $env{'user.domain'},
1.86 raeburn 12192: $item,'reload',$context);
1.160.6.5 raeburn 12193: if (($context eq 'requestcourses') ||
12194: ($context eq 'requestauthor')) {
1.108 raeburn 12195: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12196: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12197: }
12198: } else {
12199: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12200: $newenv{'environment.availabletools.'.$item} = $newacc;
12201: }
1.80 raeburn 12202: }
1.160.6.5 raeburn 12203: unless ($context eq 'requestauthor') {
12204: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12205: }
1.72 raeburn 12206: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 12207: if ($haschgs{$type}) {
1.72 raeburn 12208: my $typetitle = $usertypes->{$type};
12209: if ($type eq 'default') {
12210: $typetitle = $othertitle;
12211: } elsif ($type eq '_LC_adv') {
12212: $typetitle = 'LON-CAPA Advanced Users';
12213: }
1.160.6.5 raeburn 12214: if ($inconf{$type}) {
1.101 raeburn 12215: if ($context eq 'requestcourses') {
12216: my $cond;
1.160.6.5 raeburn 12217: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12218: if ($1 eq '') {
12219: $cond = &mt('(Automatic processing of any request).');
12220: } else {
12221: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12222: }
12223: } else {
1.160.6.5 raeburn 12224: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12225: }
12226: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 12227: } elsif ($context eq 'requestauthor') {
12228: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12229: $titles{$inconf{$type}},$typetitle);
12230:
1.101 raeburn 12231: } else {
12232: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12233: }
1.72 raeburn 12234: } else {
1.104 raeburn 12235: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 12236: if ($inconf{$type} eq '0') {
1.104 raeburn 12237: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12238: } else {
12239: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12240: }
12241: } else {
12242: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12243: }
1.72 raeburn 12244: }
12245: }
1.26 raeburn 12246: }
1.160.6.5 raeburn 12247: unless ($context eq 'requestauthor') {
12248: $resulttext .= '</ul></li>';
12249: }
1.26 raeburn 12250: }
1.1 raeburn 12251: }
1.160.6.5 raeburn 12252: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12253: if (ref($changes{'notify'}) eq 'HASH') {
12254: if ($changes{'notify'}{'approval'}) {
12255: if (ref($confhash{'notify'}) eq 'HASH') {
12256: if ($confhash{'notify'}{'approval'}) {
12257: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12258: } else {
1.160.6.5 raeburn 12259: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12260: }
12261: }
12262: }
12263: }
12264: }
1.160.6.30 raeburn 12265: if ($action eq 'requestcourses') {
12266: my @offon = ('off','on');
12267: if ($changes{'uniquecode'}) {
12268: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12269: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12270: $resulttext .= '<li>'.
12271: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12272: '</li>';
12273: } else {
12274: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12275: '</li>';
12276: }
12277: }
1.160.6.46 raeburn 12278: foreach my $type ('textbooks','templates') {
12279: if (ref($changes{$type}) eq 'HASH') {
12280: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12281: foreach my $key (sort(keys(%{$changes{$type}}))) {
12282: my %coursehash = &Apache::lonnet::coursedescription($key);
12283: my $coursetitle = $coursehash{'description'};
12284: my $position = $confhash{$type}{$key}{'order'} + 1;
12285: $resulttext .= '<li>';
1.160.6.47 raeburn 12286: foreach my $item ('subject','title','publisher','author') {
12287: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12288: ($type eq 'templates'));
1.160.6.46 raeburn 12289: my $name = $item.':';
12290: $name =~ s/^(\w)/\U$1/;
12291: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12292: }
12293: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12294: if ($type eq 'textbooks') {
12295: if ($confhash{$type}{$key}{'image'}) {
12296: $resulttext .= ' '.&mt('Image: [_1]',
12297: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12298: ' alt="Textbook cover" />').'<br />';
12299: }
12300: }
12301: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 12302: }
1.160.6.46 raeburn 12303: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 12304: }
12305: }
1.160.6.39 raeburn 12306: if (ref($changes{'validation'}) eq 'HASH') {
12307: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12308: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12309: foreach my $item (@{$validationitemsref}) {
12310: if (exists($changes{'validation'}{$item})) {
12311: if ($item eq 'markup') {
12312: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12313: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12314: } else {
12315: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12316: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12317: }
12318: }
12319: }
12320: if (exists($changes{'validation'}{'dc'})) {
12321: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12322: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12323: }
12324: }
12325: }
1.160.6.30 raeburn 12326: }
1.1 raeburn 12327: $resulttext .= '</ul>';
1.80 raeburn 12328: if (keys(%newenv)) {
12329: &Apache::lonnet::appenv(\%newenv);
12330: }
1.1 raeburn 12331: } else {
1.86 raeburn 12332: if ($context eq 'requestcourses') {
12333: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 12334: } elsif ($context eq 'requestauthor') {
12335: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12336: } else {
1.90 weissno 12337: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12338: }
1.1 raeburn 12339: }
12340: } else {
1.11 albertel 12341: $resulttext = '<span class="LC_error">'.
12342: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12343: }
1.160.6.30 raeburn 12344: if ($errors) {
12345: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12346: '<ul>'.$errors.'</ul></p>';
12347: }
1.3 raeburn 12348: return $resulttext;
1.1 raeburn 12349: }
12350:
1.160.6.30 raeburn 12351: sub process_textbook_image {
1.160.6.46 raeburn 12352: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12353: my $filename = $env{'form.'.$caller.'.filename'};
12354: my ($error,$url);
12355: my ($width,$height) = (50,50);
12356: if ($configuserok eq 'ok') {
12357: if ($switchserver) {
12358: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12359: $switchserver);
12360: } elsif ($author_ok eq 'ok') {
12361: my ($result,$imageurl) =
12362: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 12363: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 12364: if ($result eq 'ok') {
12365: $url = $imageurl;
12366: } else {
12367: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12368: }
12369: } else {
12370: $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);
12371: }
12372: } else {
12373: $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);
12374: }
12375: return ($url,$error);
12376: }
12377:
1.160.6.118.2 1(raebur 12378:1): sub modify_ltitools {
12379:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12380:1): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12381:1): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12382:1): my $confname = $dom.'-domainconfig';
12383:1): my $servadm = $r->dir_config('lonAdmEMail');
12384:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12385:1): my (%posslti,%possfield);
12386:1): my @courseroles = ('cc','in','ta','ep','st');
12387:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12388:1): map { $posslti{$_} = 1; } @ltiroles;
12389:1): my @allfields = ('fullname','firstname','lastname','email','user','roles');
12390:1): map { $possfield{$_} = 1; } @allfields;
12391:1): my %lt = <itools_names();
12392:1): if ($env{'form.ltitools_add'}) {
12393:1): my $title = $env{'form.ltitools_add_title'};
12394:1): $title =~ s/(`)/'/g;
12395:1): ($newid,my $error) = &get_ltitools_id($dom,$title);
12396:1): if ($newid) {
12397:1): my $position = $env{'form.ltitools_add_pos'};
12398:1): $position =~ s/\D+//g;
12399:1): if ($position ne '') {
12400:1): $allpos[$position] = $newid;
12401:1): }
12402:1): $changes{$newid} = 1;
12403:1): foreach my $item ('title','url','key','secret','lifetime') {
12404:1): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12405:1): if ($item eq 'lifetime') {
12406:1): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12407:1): }
12408:1): if ($env{'form.ltitools_add_'.$item}) {
12409:1): if (($item eq 'key') || ($item eq 'secret')) {
12410:1): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12411:1): } else {
12412:1): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12413:1): }
12414:1): }
12415:1): }
12416:1): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12417:1): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12418:1): }
12419:1): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12420:1): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12421:1): }
12422:1): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12423:1): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12424:1): } else {
12425:1): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12426:1): }
12427:1): foreach my $item ('width','height','linktext','explanation') {
12428:1): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12429:1): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12430:1): if (($item eq 'width') || ($item eq 'height')) {
12431:1): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12432:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12433:1): }
12434:1): } else {
12435:1): if ($env{'form.ltitools_add_'.$item} ne '') {
12436:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12437:1): }
12438:1): }
12439:1): }
12440:1): if ($env{'form.ltitools_add_target'} eq 'window') {
12441:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12442:1): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12443:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12444:1): } else {
12445:1): $confhash{$newid}{'display'}{'target'} = 'iframe';
12446:1): }
12447:1): if ($env{'form.ltitools_add_image.filename'} ne '') {
12448:1): my ($imageurl,$error) =
12449:1): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12450:1): $configuserok,$switchserver,$author_ok);
12451:1): if ($imageurl) {
12452:1): $confhash{$newid}{'image'} = $imageurl;
12453:1): }
12454:1): if ($error) {
12455:1): &Apache::lonnet::logthis($error);
12456:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12457:1): }
12458:1): }
12459:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12460:1): foreach my $field (@fields) {
12461:1): if ($possfield{$field}) {
12462:1): if ($field eq 'roles') {
12463:1): foreach my $role (@courseroles) {
12464:1): my $choice = $env{'form.ltitools_add_roles_'.$role};
12465:1): if (($choice ne '') && ($posslti{$choice})) {
12466:1): $confhash{$newid}{'roles'}{$role} = $choice;
12467:1): if ($role eq 'cc') {
12468:1): $confhash{$newid}{'roles'}{'co'} = $choice;
12469:1): }
12470:1): }
12471:1): }
12472:1): } else {
12473:1): $confhash{$newid}{'fields'}{$field} = 1;
12474:1): }
12475:1): }
12476:1): }
12477:1): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12478:1): if ($confhash{$newid}{'fields'}{'user'}) {
12479:1): if ($env{'form.ltitools_userincdom_add'}) {
12480:1): $confhash{$newid}{'incdom'} = 1;
12481:1): }
12482:1): }
12483:1): }
12484:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12485:1): foreach my $item (@courseconfig) {
12486:1): $confhash{$newid}{'crsconf'}{$item} = 1;
12487:1): }
12488:1): if ($env{'form.ltitools_add_custom'}) {
12489:1): my $name = $env{'form.ltitools_add_custom_name'};
12490:1): my $value = $env{'form.ltitools_add_custom_value'};
12491:1): $value =~ s/(`)/'/g;
12492:1): $name =~ s/(`)/'/g;
12493:1): $confhash{$newid}{'custom'}{$name} = $value;
12494:1): }
12495:1): } else {
12496:1): my $error = &mt('Failed to acquire unique ID for new external tool');
12497:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12498:1): }
12499:1): }
12500:1): if (ref($domconfig{$action}) eq 'HASH') {
12501:1): my %deletions;
12502:1): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12503:1): if (@todelete) {
12504:1): map { $deletions{$_} = 1; } @todelete;
12505:1): }
12506:1): my %customadds;
12507:1): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12508:1): if (@newcustom) {
12509:1): map { $customadds{$_} = 1; } @newcustom;
12510:1): }
12511:1): my %imgdeletions;
12512:1): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12513:1): if (@todeleteimages) {
12514:1): map { $imgdeletions{$_} = 1; } @todeleteimages;
12515:1): }
12516:1): my $maxnum = $env{'form.ltitools_maxnum'};
12517:1): for (my $i=0; $i<=$maxnum; $i++) {
12518:1): my $itemid = $env{'form.ltitools_id_'.$i};
12519:1): $itemid =~ s/\D+//g;
12520:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12521:1): if ($deletions{$itemid}) {
12522:1): if ($domconfig{$action}{$itemid}{'image'}) {
12523:1): #FIXME need to obsolete item in RES space
12524:1): }
12525:1): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12526:1): next;
12527:1): } else {
12528:1): my $newpos = $env{'form.ltitools_'.$itemid};
12529:1): $newpos =~ s/\D+//g;
12530:1): foreach my $item ('title','url','lifetime') {
12531:1): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12532:1): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12533:1): $changes{$itemid} = 1;
12534:1): }
12535:1): }
12536:1): foreach my $item ('key','secret') {
12537:1): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12538:1): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12539:1): $changes{$itemid} = 1;
12540:1): }
12541:1): }
12542:1): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12543:1): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12544:1): }
12545:1): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12546:1): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12547:1): }
12548:1): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12549:1): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12550:1): } else {
12551:1): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12552:1): }
12553:1): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12554:1): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12555:1): $changes{$itemid} = 1;
12556:1): }
12557:1): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12558:1): $changes{$itemid} = 1;
12559:1): }
12560:1): foreach my $size ('width','height') {
12561:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12562:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12563:1): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12564:1): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12565:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12566:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12567:1): $changes{$itemid} = 1;
12568:1): }
12569:1): } else {
12570:1): $changes{$itemid} = 1;
12571:1): }
12572:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12573:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12574:1): $changes{$itemid} = 1;
12575:1): }
12576:1): }
12577:1): }
12578:1): foreach my $item ('linktext','explanation') {
12579:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12580:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12581:1): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12582:1): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12583:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12584:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12585:1): $changes{$itemid} = 1;
12586:1): }
12587:1): } else {
12588:1): $changes{$itemid} = 1;
12589:1): }
12590:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12591:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12592:1): $changes{$itemid} = 1;
12593:1): }
12594:1): }
12595:1): }
12596:1): if ($env{'form.ltitools_target_'.$i} eq 'window') {
12597:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12598:1): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12599:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12600:1): } else {
12601:1): $confhash{$itemid}{'display'}{'target'} = 'iframe';
12602:1): }
12603:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12604:1): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12605:1): $changes{$itemid} = 1;
12606:1): }
12607:1): } else {
12608:1): $changes{$itemid} = 1;
12609:1): }
12610:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12611:1): foreach my $item ('label','title','target','linktext','explanation','append') {
12612:1): if (grep(/^\Q$item\E$/,@courseconfig)) {
12613:1): $confhash{$itemid}{'crsconf'}{$item} = 1;
12614:1): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12615:1): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12616:1): $changes{$itemid} = 1;
12617:1): }
12618:1): } else {
12619:1): $changes{$itemid} = 1;
12620:1): }
12621:1): }
12622:1): }
12623:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12624:1): foreach my $field (@fields) {
12625:1): if ($possfield{$field}) {
12626:1): if ($field eq 'roles') {
12627:1): foreach my $role (@courseroles) {
12628:1): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12629:1): if (($choice ne '') && ($posslti{$choice})) {
12630:1): $confhash{$itemid}{'roles'}{$role} = $choice;
12631:1): if ($role eq 'cc') {
12632:1): $confhash{$itemid}{'roles'}{'co'} = $choice;
12633:1): }
12634:1): }
12635:1): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12636:1): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12637:1): $changes{$itemid} = 1;
12638:1): }
12639:1): } elsif ($confhash{$itemid}{'roles'}{$role}) {
12640:1): $changes{$itemid} = 1;
12641:1): }
12642:1): }
12643:1): } else {
12644:1): $confhash{$itemid}{'fields'}{$field} = 1;
12645:1): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12646:1): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12647:1): $changes{$itemid} = 1;
12648:1): }
12649:1): } else {
12650:1): $changes{$itemid} = 1;
12651:1): }
12652:1): }
12653:1): }
12654:1): }
12655:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12656:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12657:1): if ($env{'form.ltitools_userincdom_'.$i}) {
12658:1): $confhash{$itemid}{'incdom'} = 1;
12659:1): }
12660:1): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12661:1): $changes{$itemid} = 1;
12662:1): }
12663:1): }
12664:1): }
12665:1): $allpos[$newpos] = $itemid;
12666:1): }
12667:1): if ($imgdeletions{$itemid}) {
12668:1): $changes{$itemid} = 1;
12669:1): #FIXME need to obsolete item in RES space
12670:1): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12671:1): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12672:1): $itemid,$configuserok,$switchserver,
12673:1): $author_ok);
12674:1): if ($imgurl) {
12675:1): $confhash{$itemid}{'image'} = $imgurl;
12676:1): $changes{$itemid} = 1;
12677:1): }
12678:1): if ($error) {
12679:1): &Apache::lonnet::logthis($error);
12680:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12681:1): }
12682:1): } elsif ($domconfig{$action}{$itemid}{'image'}) {
12683:1): $confhash{$itemid}{'image'} =
12684:1): $domconfig{$action}{$itemid}{'image'};
12685:1): }
12686:1): if ($customadds{$i}) {
12687:1): my $name = $env{'form.ltitools_custom_name_'.$i};
12688:1): $name =~ s/(`)/'/g;
12689:1): $name =~ s/^\s+//;
12690:1): $name =~ s/\s+$//;
12691:1): my $value = $env{'form.ltitools_custom_value_'.$i};
12692:1): $value =~ s/(`)/'/g;
12693:1): $value =~ s/^\s+//;
12694:1): $value =~ s/\s+$//;
12695:1): if ($name ne '') {
12696:1): $confhash{$itemid}{'custom'}{$name} = $value;
12697:1): $changes{$itemid} = 1;
12698:1): }
12699:1): }
12700:1): my %customdels;
12701:1): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12702:1): if (@customdeletions) {
12703:1): $changes{$itemid} = 1;
12704:1): }
12705:1): map { $customdels{$_} = 1; } @customdeletions;
12706:1): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12707:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12708:1): unless ($customdels{$key}) {
12709:1): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12710:1): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12711:1): }
12712:1): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12713:1): $changes{$itemid} = 1;
12714:1): }
12715:1): }
12716:1): }
12717:1): }
12718:1): unless ($changes{$itemid}) {
12719:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12720:1): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12721:1): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12722:1): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12723:1): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12724:1): $changes{$itemid} = 1;
12725:1): last;
12726:1): }
12727:1): }
12728:1): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12729:1): $changes{$itemid} = 1;
12730:1): }
12731:1): }
12732:1): last if ($changes{$itemid});
12733:1): }
12734:1): }
12735:1): }
12736:1): }
12737:1): }
12738:1): if (@allpos > 0) {
12739:1): my $idx = 0;
12740:1): foreach my $itemid (@allpos) {
12741:1): if ($itemid ne '') {
12742:1): $confhash{$itemid}{'order'} = $idx;
12743:1): if (ref($domconfig{$action}) eq 'HASH') {
12744:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12745:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12746:1): $changes{$itemid} = 1;
12747:1): }
12748:1): }
12749:1): }
12750:1): $idx ++;
12751:1): }
12752:1): }
12753:1): }
12754:1): my %ltitoolshash = (
12755:1): $action => { %confhash }
12756:1): );
12757:1): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12758:1): $dom);
12759:1): if ($putresult eq 'ok') {
12760:1): my %ltienchash = (
12761:1): $action => { %encconfig }
12762:1): );
12763:1): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12764:1): if (keys(%changes) > 0) {
12765:1): my $cachetime = 24*60*60;
12766:1): my %ltiall = %confhash;
12767:1): foreach my $id (keys(%ltiall)) {
12768:1): if (ref($encconfig{$id}) eq 'HASH') {
12769:1): foreach my $item ('key','secret') {
12770:1): $ltiall{$id}{$item} = $encconfig{$id}{$item};
12771:1): }
12772:1): }
12773:1): }
12774:1): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12775:1): if (ref($lastactref) eq 'HASH') {
12776:1): $lastactref->{'ltitools'} = 1;
12777:1): }
12778:1): $resulttext = &mt('Changes made:').'<ul>';
12779:1): my %bynum;
12780:1): foreach my $itemid (sort(keys(%changes))) {
12781:1): my $position = $confhash{$itemid}{'order'};
12782:1): $bynum{$position} = $itemid;
12783:1): }
12784:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12785:1): my $itemid = $bynum{$pos};
12786:1): if (ref($confhash{$itemid}) ne 'HASH') {
12787:1): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12788:1): } else {
12789:1): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12790:1): if ($confhash{$itemid}{'image'}) {
12791:1): $resulttext .= ' '.
12792:1): '<img src="'.$confhash{$itemid}{'image'}.'"'.
12793:1): ' alt="'.&mt('Tool Provider icon').'" />';
12794:1): }
12795:1): $resulttext .= '</li><ul>';
12796:1): my $position = $pos + 1;
12797:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12798:1): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12799:1): if ($confhash{$itemid}{$item} ne '') {
12800:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12801:1): }
12802:1): }
12803:1): if ($encconfig{$itemid}{'key'} ne '') {
12804:1): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12805:1): }
12806:1): if ($encconfig{$itemid}{'secret'} ne '') {
12807:1): $resulttext .= '<li>'.$lt{'secret'}.': ';
12808:1): my $num = length($encconfig{$itemid}{'secret'});
12809:1): $resulttext .= ('*'x$num).'</li>';
12810:1): }
12811:1): $resulttext .= '<li>'.&mt('Configurable in course:');
12812:1): my @possconfig = ('label','title','target','linktext','explanation','append');
12813:1): my $numconfig = 0;
12814:1): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12815:1): foreach my $item (@possconfig) {
12816:1): if ($confhash{$itemid}{'crsconf'}{$item}) {
12817:1): $numconfig ++;
12818:1): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12819:1): }
12820:1): }
12821:1): }
12822:1): if (!$numconfig) {
12823:1): $resulttext .= &mt('None');
12824:1): }
12825:1): $resulttext .= '</li>';
12826:1): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12827:1): my $displaylist;
12828:1): if ($confhash{$itemid}{'display'}{'target'}) {
12829:1): $displaylist = &mt('Display target').': '.
12830:1): $confhash{$itemid}{'display'}{'target'}.',';
12831:1): }
12832:1): foreach my $size ('width','height') {
12833:1): if ($confhash{$itemid}{'display'}{$size}) {
12834:1): $displaylist .= (' 'x2).$lt{$size}.': '.
12835:1): $confhash{$itemid}{'display'}{$size}.',';
12836:1): }
12837:1): }
12838:1): if ($displaylist) {
12839:1): $displaylist =~ s/,$//;
12840:1): $resulttext .= '<li>'.$displaylist.'</li>';
12841:1): }
12842:1): foreach my $item ('linktext','explanation') {
12843:1): if ($confhash{$itemid}{'display'}{$item}) {
12844:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12845:1): }
12846:1): }
12847:1): }
12848:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12849:1): my $fieldlist;
12850:1): foreach my $field (@allfields) {
12851:1): if ($confhash{$itemid}{'fields'}{$field}) {
12852:1): $fieldlist .= (' 'x2).$lt{$field}.',';
12853:1): }
12854:1): }
12855:1): if ($fieldlist) {
12856:1): $fieldlist =~ s/,$//;
12857:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12858:1): if ($confhash{$itemid}{'incdom'}) {
12859:1): $fieldlist .= ' ('.&mt('username:domain').')';
12860:1): } else {
12861:1): $fieldlist .= ' ('.&mt('username').')';
12862:1): }
12863:1): }
12864:1): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12865:1): }
12866:1): }
12867:1): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12868:1): my $rolemaps;
12869:1): foreach my $role (@courseroles) {
12870:1): if ($confhash{$itemid}{'roles'}{$role}) {
12871:1): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12872:1): $confhash{$itemid}{'roles'}{$role}.',';
12873:1): }
12874:1): }
12875:1): if ($rolemaps) {
12876:1): $rolemaps =~ s/,$//;
12877:1): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12878:1): }
12879:1): }
12880:1): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12881:1): my $customlist;
12882:1): if (keys(%{$confhash{$itemid}{'custom'}})) {
12883:1): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12884:1): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12885:1): }
12886:1): }
12887:1): if ($customlist) {
12888:1): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12889:1): }
12890:1): }
12891:1): $resulttext .= '</ul></li>';
12892:1): }
12893:1): }
12894:1): $resulttext .= '</ul>';
12895:1): } else {
12896:1): $resulttext = &mt('No changes made.');
12897:1): }
12898:1): } else {
12899:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12900:1): }
12901:1): if ($errors) {
12902:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12903:1): $errors.'</ul>';
12904:1): }
12905:1): return $resulttext;
12906:1): }
12907:1):
12908:1): sub process_ltitools_image {
12909:1): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12910:1): my $filename = $env{'form.'.$caller.'.filename'};
12911:1): my ($error,$url);
12912:1): my ($width,$height) = (21,21);
12913:1): if ($configuserok eq 'ok') {
12914:1): if ($switchserver) {
12915:1): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12916:1): $switchserver);
12917:1): } elsif ($author_ok eq 'ok') {
12918:1): my ($result,$imageurl,$madethumb) =
12919:1): &publishlogo($r,'upload',$caller,$dom,$confname,
12920:1): "ltitools/$itemid/icon",$width,$height);
12921:1): if ($result eq 'ok') {
12922:1): if ($madethumb) {
12923:1): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12924:1): my $imagethumb = "$path/tn-".$imagefile;
12925:1): $url = $imagethumb;
12926:1): } else {
12927:1): $url = $imageurl;
12928:1): }
12929:1): } else {
12930:1): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12931:1): }
12932:1): } else {
12933:1): $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);
12934:1): }
12935:1): } else {
12936:1): $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);
12937:1): }
12938:1): return ($url,$error);
12939:1): }
12940:1):
12941:1): sub get_ltitools_id {
12942:1): my ($cdom,$title) = @_;
12943:1): # get lock on ltitools db
12944:1): my $lockhash = {
12945:1): lock => $env{'user.name'}.
12946:1): ':'.$env{'user.domain'},
12947:1): };
12948:1): my $tries = 0;
12949:1): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12950:1): my ($id,$error);
12951:1):
12952:1): while (($gotlock ne 'ok') && ($tries<10)) {
12953:1): $tries ++;
12954:1): sleep (0.1);
12955:1): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12956:1): }
12957:1): if ($gotlock eq 'ok') {
12958:1): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12959:1): if ($currids{'lock'}) {
12960:1): delete($currids{'lock'});
12961:1): if (keys(%currids)) {
12962:1): my @curr = sort { $a <=> $b } keys(%currids);
12963:1): if ($curr[-1] =~ /^\d+$/) {
12964:1): $id = 1 + $curr[-1];
12965:1): }
12966:1): } else {
12967:1): $id = 1;
12968:1): }
12969:1): if ($id) {
12970:1): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12971:1): $error = 'nostore';
12972:1): }
12973:1): } else {
12974:1): $error = 'nonumber';
12975:1): }
12976:1): }
12977:1): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12978:1): } else {
12979:1): $error = 'nolock';
12980:1): }
12981:1): return ($id,$error);
12982:1): }
12983:1):
5(raebur 12984:2): sub modify_lti {
12985:2): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12986:2): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12987:2): my (%encconfig,$errors,$resulttext);
12988:2):
12989:2): my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
12990:2): $newltisec{'private'}{'keys'} = [];
12991:2): $newltisec{'encrypt'} = {};
12992:2): $newltisec{'rules'} = {};
12993:2): $newltisec{'linkprot'} = {};
12994:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
12995:2): %currltisec = %{$domconfig{'ltisec'}};
12996:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
12997:2): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
12998:2): unless ($id =~ /^\d+$/) {
12999:2): delete($currltisec{'linkprot'}{$id});
13000:2): }
13001:2): }
13002:2): }
13003:2): if (ref($currltisec{'private'}) eq 'HASH') {
13004:2): if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
13005:2): $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
13006:2): map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
13007:2): }
13008:2): }
13009:2): }
13010:2): foreach my $item ('crs','dom') {
13011:2): my $formelement = 'form.ltisec_'.$item.'linkprot';
13012:2): if ($env{$formelement}) {
13013:2): $newltisec{'encrypt'}{$item} = 1;
13014:2): if (ref($currltisec{'encrypt'}) eq 'HASH') {
13015:2): unless ($currltisec{'encrypt'}{$item}) {
13016:2): $secchanges{'encrypt'} = 1;
13017:2): }
13018:2): } else {
13019:2): $secchanges{'encrypt'} = 1;
13020:2): }
13021:2): } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
13022:2): if ($currltisec{'encrypt'}{$item}) {
13023:2): $secchanges{'encrypt'} = 1;
13024:2): }
13025:2): }
13026:2): }
13027:2): unless (exists($currltisec{'rules'})) {
13028:2): $currltisec{'rules'} = {};
13029:2): }
13030:2): &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
13031:2):
13032:2): my @ids=&Apache::lonnet::current_machine_ids();
13033:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
13034:2):
13035:2): foreach my $hostid (keys(%servers)) {
13036:2): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13037:2): my $newkey;
13038:2): my $keyitem = 'form.ltisec_privkey_'.$hostid;
13039:2): if (exists($env{$keyitem})) {
13040:2): $env{$keyitem} =~ s/(`)/'/g;
13041:2): if ($keyset{$hostid}) {
13042:2): if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
13043:2): if ($env{$keyitem} ne '') {
13044:2): $secchanges{'private'} = 1;
13045:2): $newkeyset{$hostid} = $env{$keyitem};
13046:2): }
13047:2): }
13048:2): } elsif ($env{$keyitem} ne '') {
13049:2): unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
13050:2): push(@{$newltisec{'private'}{'keys'}},$hostid);
13051:2): }
13052:2): $secchanges{'private'} = 1;
13053:2): $newkeyset{$hostid} = $env{$keyitem};
13054:2): }
13055:2): }
13056:2): }
13057:2): }
13058:2):
13059:2): my (%linkprotchg,$linkprotoutput,$is_home);
13060:2): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13061:2): \%linkprotchg,'domain');
13062:2): my $home = &Apache::lonnet::domain($dom,'primary');
13063:2): unless (($home eq 'no_host') || ($home eq '')) {
13064:2): my @ids=&Apache::lonnet::current_machine_ids();
13065:2): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13066:2): }
13067:2):
13068:2): if (keys(%linkprotchg)) {
13069:2): $secchanges{'linkprot'} = 1;
13070:2): my %oldlinkprot;
13071:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13072:2): %oldlinkprot = %{$currltisec{'linkprot'}};
13073:2): }
13074:2): foreach my $id (keys(%linkprotchg)) {
13075:2): if (ref($linkprotchg{$id}) eq 'HASH') {
13076:2): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13077:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13078:2): if ($is_home) {
13079:2): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13080:2): }
13081:2): }
13082:2): }
13083:2): } else {
13084:2): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
13085:2): }
13086:2): }
13087:2): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13088:2): if (keys(%linkprotchg)) {
13089:2): %{$newltisec{'linkprot'}} = %linkprotchg;
13090:2): }
13091:2): }
13092:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13093:2): foreach my $id (%{$currltisec{'linkprot'}}) {
13094:2): next if ($id !~ /^\d+$/);
13095:2): unless (exists($linkprotchg{$id})) {
13096:2): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13097:2): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13098:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13099:2): if ($is_home) {
13100:2): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13101:2): }
13102:2): } else {
13103:2): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13104:2): }
13105:2): }
13106:2): } else {
13107:2): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13108:2): }
13109:2): }
13110:2): }
13111:2): }
13112:2): if ($proterror) {
13113:2): $errors .= '<li>'.$proterror.'</li>';
13114:2): }
13115:2):
13116:2): my $putresult;
13117:2): if (keys(%secchanges)) {
13118:2): my %ltienchash;
13119:2): my %ltihash = (
13120:2): 'ltisec' => { %newltisec }
13121:2): );
13122:2): $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
13123:2): if ($putresult eq 'ok') {
13124:2): my %keystore;
13125:2): if ($secchanges{'private'}) {
13126:2): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13127:2): foreach my $hostid (keys(%newkeyset)) {
13128:2): my $storehash = {
13129:2): key => $newkeyset{$hostid},
13130:2): who => $env{'user.name'}.':'.$env{'user.domain'},
13131:2): };
13132:2): $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
13133:2): $dom,$hostid);
13134:2): }
13135:2): }
13136:2): if (ref($lastactref) eq 'HASH') {
13137:2): if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13138:2): $lastactref->{'domdefaults'} = 1;
13139:2): }
13140:2): }
13141:2): if (($secchanges{'linkprot'}) && ($is_home)) {
13142:2): my %ltienchash = (
13143:2): 'linkprot' => { %newltienc }
13144:2): );
13145:2): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13146:2): }
13147:2): }
13148:2): } else {
13149:2): return &mt('No changes made.');
13150:2): }
13151:2): if ($putresult eq 'ok') {
13152:2): $resulttext = &mt('Changes made:').'<ul>';
13153:2): foreach my $item (keys(%secchanges)) {
13154:2): if ($item eq 'encrypt') {
13155:2): my %encrypted = (
13156:2): crs => {
13157:2): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13158:2): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13159:2): },
13160:2): dom => {
13161:2): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13162:2): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13163:2): },
13164:2): );
13165:2): foreach my $type ('crs','dom') {
13166:2): my $shown = $encrypted{$type}{'off'};
13167:2): if (ref($newltisec{$item}) eq 'HASH') {
13168:2): if ($newltisec{$item}{$type}) {
13169:2): $shown = $encrypted{$type}{'on'};
13170:2): }
13171:2): }
13172:2): $resulttext .= '<li>'.$shown.'</li>';
13173:2): }
13174:2): } elsif ($item eq 'rules') {
13175:2): my %titles = &Apache::lonlocal::texthash(
13176:2): min => 'Minimum password length',
13177:2): max => 'Maximum password length',
13178:2): chars => 'Required characters',
13179:2): );
13180:2): foreach my $rule ('min','max') {
13181:2): if ($newltisec{rules}{$rule} eq '') {
13182:2): if ($rule eq 'min') {
13183:2): $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13184:2): ' '.&mt('Default of [_1] will be used',
13185:2): $Apache::lonnet::passwdmin).'</li>';
13186:2): } else {
13187:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13188:2): }
13189:2): } else {
13190:2): $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
13191:2): }
13192:2): }
13193:2): if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
13194:2): if (@{$newltisec{'rules'}{'chars'}} > 0) {
13195:2): my %rulenames = &Apache::lonlocal::texthash(
13196:2): uc => 'At least one upper case letter',
13197:2): lc => 'At least one lower case letter',
13198:2): num => 'At least one number',
13199:2): spec => 'At least one non-alphanumeric',
13200:2): );
13201:2): my $needed = '<ul><li>'.
13202:2): join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
13203:2): '</li></ul>';
13204:2): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13205:2): } else {
13206:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13207:2): }
13208:2): } else {
13209:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13210:2): }
13211:2): } elsif ($item eq 'private') {
13212:2): if (keys(%newkeyset)) {
13213:2): foreach my $hostid (sort(keys(%newkeyset))) {
13214:2): if ($keystore{$hostid} eq 'ok') {
13215:2): $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13216:2): }
13217:2): }
13218:2): }
13219:2): } elsif ($item eq 'linkprot') {
13220:2): $resulttext .= $linkprotoutput;
13221:2): }
13222:2): }
13223:2): $resulttext .= '</ul>';
13224:2): } else {
13225:2): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13226:2): }
13227:2): if ($errors) {
13228:2): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13229:2): $errors.'</ul>';
13230:2): }
13231:2): return $resulttext;
13232:2): }
13233:2):
1.3 raeburn 13234: sub modify_autoenroll {
1.160.6.24 raeburn 13235: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 13236: my ($resulttext,%changes);
13237: my %currautoenroll;
13238: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13239: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13240: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13241: }
13242: }
13243: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13244: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13245: sender => 'Sender for notification messages',
1.160.6.68 raeburn 13246: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 13247: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13248: my @offon = ('off','on');
1.17 raeburn 13249: my $sender_uname = $env{'form.sender_uname'};
13250: my $sender_domain = $env{'form.sender_domain'};
13251: if ($sender_domain eq '') {
13252: $sender_uname = '';
13253: } elsif ($sender_uname eq '') {
13254: $sender_domain = '';
13255: }
1.129 raeburn 13256: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 13257: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
13258: $autofailsafe =~ s{^\s+|\s+$}{}g;
13259: if ($autofailsafe =~ /\D/) {
13260: undef($autofailsafe);
13261: }
1.160.6.68 raeburn 13262: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 13263: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
13264: $failsafe = 'off';
13265: undef($autofailsafe);
1.160.6.68 raeburn 13266: }
1.1 raeburn 13267: my %autoenrollhash = (
1.129 raeburn 13268: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13269: 'sender_uname' => $sender_uname,
13270: 'sender_domain' => $sender_domain,
13271: 'co-owners' => $coowners,
1.160.6.116 raeburn 13272: 'autofailsafe' => $autofailsafe,
13273: 'failsafe' => $failsafe,
1.1 raeburn 13274: }
13275: );
1.4 raeburn 13276: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13277: $dom);
1.1 raeburn 13278: if ($putresult eq 'ok') {
13279: if (exists($currautoenroll{'run'})) {
13280: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13281: $changes{'run'} = 1;
13282: }
13283: } elsif ($autorun) {
13284: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13285: $changes{'run'} = 1;
1.1 raeburn 13286: }
13287: }
1.17 raeburn 13288: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13289: $changes{'sender'} = 1;
13290: }
1.17 raeburn 13291: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13292: $changes{'sender'} = 1;
13293: }
1.129 raeburn 13294: if ($currautoenroll{'co-owners'} ne '') {
13295: if ($currautoenroll{'co-owners'} ne $coowners) {
13296: $changes{'coowners'} = 1;
13297: }
13298: } elsif ($coowners) {
13299: $changes{'coowners'} = 1;
1.160.6.68 raeburn 13300: }
1.160.6.116 raeburn 13301: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 13302: $changes{'autofailsafe'} = 1;
13303: }
1.160.6.116 raeburn 13304: if ($currautoenroll{'failsafe'} ne $failsafe) {
13305: $changes{'failsafe'} = 1;
13306: }
1.1 raeburn 13307: if (keys(%changes) > 0) {
13308: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13309: if ($changes{'run'}) {
1.1 raeburn 13310: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13311: }
13312: if ($changes{'sender'}) {
1.17 raeburn 13313: if ($sender_uname eq '' || $sender_domain eq '') {
13314: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13315: } else {
13316: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13317: }
1.1 raeburn 13318: }
1.129 raeburn 13319: if ($changes{'coowners'}) {
13320: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13321: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13322: if (ref($lastactref) eq 'HASH') {
13323: $lastactref->{'domainconfig'} = 1;
13324: }
1.129 raeburn 13325: }
1.160.6.68 raeburn 13326: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 13327: if ($autofailsafe ne '') {
13328: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 13329: } else {
1.160.6.116 raeburn 13330: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 13331: }
1.160.6.116 raeburn 13332: }
13333: if ($changes{'failsafe'}) {
13334: if ($failsafe eq 'off') {
13335: unless ($changes{'autofailsafe'}) {
13336: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
13337: }
13338: } elsif ($failsafe eq 'zero') {
13339: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
13340: } else {
13341: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
13342: }
13343: }
13344: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 13345: &Apache::lonnet::get_domain_defaults($dom,1);
13346: if (ref($lastactref) eq 'HASH') {
13347: $lastactref->{'domdefaults'} = 1;
13348: }
13349: }
1.1 raeburn 13350: $resulttext .= '</ul>';
13351: } else {
13352: $resulttext = &mt('No changes made to auto-enrollment settings');
13353: }
13354: } else {
1.11 albertel 13355: $resulttext = '<span class="LC_error">'.
13356: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13357: }
1.3 raeburn 13358: return $resulttext;
1.1 raeburn 13359: }
13360:
13361: sub modify_autoupdate {
1.3 raeburn 13362: my ($dom,%domconfig) = @_;
1.1 raeburn 13363: my ($resulttext,%currautoupdate,%fields,%changes);
13364: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13365: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13366: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13367: }
13368: }
13369: my @offon = ('off','on');
13370: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 13371: run => 'Auto-update:',
13372: classlists => 'Updates to user information in classlists?',
13373: unexpired => 'Skip updates for users without active or future roles?',
13374: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 13375: );
1.44 raeburn 13376: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13377: my %fieldtitles = &Apache::lonlocal::texthash (
13378: id => 'Student/Employee ID',
1.20 raeburn 13379: permanentemail => 'E-mail address',
1.1 raeburn 13380: lastname => 'Last Name',
13381: firstname => 'First Name',
13382: middlename => 'Middle Name',
1.132 raeburn 13383: generation => 'Generation',
1.1 raeburn 13384: );
1.142 raeburn 13385: $othertitle = &mt('All users');
1.1 raeburn 13386: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13387: $othertitle = &mt('Other users');
1.1 raeburn 13388: }
13389: foreach my $key (keys(%env)) {
13390: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13391: my ($usertype,$item) = ($1,$2);
13392: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13393: if ($usertype eq 'default') {
13394: push(@{$fields{$1}},$2);
13395: } elsif (ref($types) eq 'ARRAY') {
13396: if (grep(/^\Q$usertype\E$/,@{$types})) {
13397: push(@{$fields{$1}},$2);
13398: }
13399: }
13400: }
1.1 raeburn 13401: }
13402: }
1.131 raeburn 13403: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13404: @lockablenames = sort(@lockablenames);
13405: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13406: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13407: if (@changed) {
13408: $changes{'lockablenames'} = 1;
13409: }
13410: } else {
13411: if (@lockablenames) {
13412: $changes{'lockablenames'} = 1;
13413: }
13414: }
1.1 raeburn 13415: my %updatehash = (
13416: autoupdate => { run => $env{'form.autoupdate_run'},
13417: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 13418: unexpired => $env{'form.unexpired'},
1.1 raeburn 13419: fields => {%fields},
1.131 raeburn 13420: lockablenames => \@lockablenames,
1.1 raeburn 13421: }
13422: );
1.160.6.113 raeburn 13423: my $lastactivedays;
13424: if ($env{'form.lastactive'}) {
13425: $lastactivedays = $env{'form.lastactivedays'};
13426: $lastactivedays =~ s/^\s+|\s+$//g;
13427: unless ($lastactivedays =~ /^\d+$/) {
13428: undef($lastactivedays);
13429: $env{'form.lastactive'} = 0;
13430: }
13431: }
13432: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 13433: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 13434: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 13435: if (exists($updatehash{autoupdate}{$key})) {
13436: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13437: $changes{$key} = 1;
13438: }
13439: }
13440: } elsif ($key eq 'fields') {
13441: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13442: foreach my $item (@{$types},'default') {
1.1 raeburn 13443: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13444: my $change = 0;
13445: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13446: if (!exists($fields{$item})) {
13447: $change = 1;
1.132 raeburn 13448: last;
1.1 raeburn 13449: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13450: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13451: $change = 1;
1.132 raeburn 13452: last;
1.1 raeburn 13453: }
13454: }
13455: }
13456: if ($change) {
13457: push(@{$changes{$key}},$item);
13458: }
1.26 raeburn 13459: }
1.1 raeburn 13460: }
13461: }
1.131 raeburn 13462: } elsif ($key eq 'lockablenames') {
13463: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13464: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13465: if (@changed) {
13466: $changes{'lockablenames'} = 1;
13467: }
13468: } else {
13469: if (@lockablenames) {
13470: $changes{'lockablenames'} = 1;
13471: }
13472: }
13473: }
13474: }
13475: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13476: if (@lockablenames) {
13477: $changes{'lockablenames'} = 1;
1.1 raeburn 13478: }
13479: }
1.160.6.113 raeburn 13480: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
13481: if ($updatehash{'autoupdate'}{'unexpired'}) {
13482: $changes{'unexpired'} = 1;
13483: }
13484: }
13485: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
13486: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
13487: $changes{'lastactive'} = 1;
13488: }
13489: }
1.26 raeburn 13490: foreach my $item (@{$types},'default') {
13491: if (defined($fields{$item})) {
13492: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13493: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13494: my $change = 0;
13495: if (ref($fields{$item}) eq 'ARRAY') {
13496: foreach my $type (@{$fields{$item}}) {
13497: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13498: $change = 1;
13499: last;
13500: }
13501: }
13502: }
13503: if ($change) {
13504: push(@{$changes{'fields'}},$item);
13505: }
13506: } else {
1.26 raeburn 13507: push(@{$changes{'fields'}},$item);
13508: }
13509: } else {
13510: push(@{$changes{'fields'}},$item);
1.1 raeburn 13511: }
13512: }
13513: }
13514: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13515: $dom);
13516: if ($putresult eq 'ok') {
13517: if (keys(%changes) > 0) {
13518: $resulttext = &mt('Changes made:').'<ul>';
13519: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13520: if ($key eq 'lockablenames') {
13521: $resulttext .= '<li>';
13522: if (@lockablenames) {
13523: $usertypes->{'default'} = $othertitle;
13524: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13525: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13526: } else {
13527: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13528: }
13529: $resulttext .= '</li>';
13530: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13531: foreach my $item (@{$changes{$key}}) {
13532: my @newvalues;
13533: foreach my $type (@{$fields{$item}}) {
13534: push(@newvalues,$fieldtitles{$type});
13535: }
1.3 raeburn 13536: my $newvaluestr;
13537: if (@newvalues > 0) {
13538: $newvaluestr = join(', ',@newvalues);
13539: } else {
13540: $newvaluestr = &mt('none');
1.6 raeburn 13541: }
1.1 raeburn 13542: if ($item eq 'default') {
1.26 raeburn 13543: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13544: } else {
1.26 raeburn 13545: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13546: }
13547: }
13548: } else {
13549: my $newvalue;
13550: if ($key eq 'run') {
13551: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 13552: } elsif ($key eq 'lastactive') {
13553: $newvalue = $offon[$env{'form.lastactive'}];
13554: unless ($lastactivedays eq '') {
13555: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
13556: }
1.1 raeburn 13557: } else {
13558: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13559: }
1.1 raeburn 13560: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13561: }
13562: }
13563: $resulttext .= '</ul>';
13564: } else {
1.3 raeburn 13565: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13566: }
13567: } else {
1.11 albertel 13568: $resulttext = '<span class="LC_error">'.
13569: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13570: }
1.3 raeburn 13571: return $resulttext;
1.1 raeburn 13572: }
13573:
1.125 raeburn 13574: sub modify_autocreate {
13575: my ($dom,%domconfig) = @_;
13576: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13577: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13578: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13579: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13580: }
13581: }
13582: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13583: req => 'Auto-creation of validated requests for official courses',
13584: xmldc => 'Identity of course creator of courses from XML files',
13585: );
13586: my @types = ('xml','req');
13587: foreach my $item (@types) {
13588: $newvals{$item} = $env{'form.autocreate_'.$item};
13589: $newvals{$item} =~ s/\D//g;
13590: $newvals{$item} = 0 if ($newvals{$item} eq '');
13591: }
13592: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 13593: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13594: unless (exists($domcoords{$newvals{'xmldc'}})) {
13595: $newvals{'xmldc'} = '';
13596: }
13597: %autocreatehash = (
13598: autocreate => { xml => $newvals{'xml'},
13599: req => $newvals{'req'},
13600: }
13601: );
13602: if ($newvals{'xmldc'} ne '') {
13603: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13604: }
13605: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13606: $dom);
13607: if ($putresult eq 'ok') {
13608: my @items = @types;
13609: if ($newvals{'xml'}) {
13610: push(@items,'xmldc');
13611: }
13612: foreach my $item (@items) {
13613: if (exists($currautocreate{$item})) {
13614: if ($currautocreate{$item} ne $newvals{$item}) {
13615: $changes{$item} = 1;
13616: }
13617: } elsif ($newvals{$item}) {
13618: $changes{$item} = 1;
13619: }
13620: }
13621: if (keys(%changes) > 0) {
13622: my @offon = ('off','on');
13623: $resulttext = &mt('Changes made:').'<ul>';
13624: foreach my $item (@types) {
13625: if ($changes{$item}) {
13626: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 13627: $resulttext .= '<li>'.
13628: &mt("$title{$item} set to [_1]$newtxt [_2]",
13629: '<b>','</b>').
13630: '</li>';
1.125 raeburn 13631: }
13632: }
13633: if ($changes{'xmldc'}) {
13634: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13635: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 13636: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13637: }
13638: $resulttext .= '</ul>';
13639: } else {
13640: $resulttext = &mt('No changes made to auto-creation settings');
13641: }
13642: } else {
13643: $resulttext = '<span class="LC_error">'.
13644: &mt('An error occurred: [_1]',$putresult).'</span>';
13645: }
13646: return $resulttext;
13647: }
13648:
1.23 raeburn 13649: sub modify_directorysrch {
1.160.6.81 raeburn 13650: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13651: my ($resulttext,%changes);
13652: my %currdirsrch;
13653: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13654: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13655: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13656: }
13657: }
1.160.6.72 raeburn 13658: my %title = ( available => 'Institutional directory search available',
13659: localonly => 'Other domains can search institution',
13660: lcavailable => 'LON-CAPA directory search available',
13661: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13662: searchby => 'Search types',
13663: searchtypes => 'Search latitude');
13664: my @offon = ('off','on');
1.24 raeburn 13665: my @otherdoms = ('Yes','No');
1.23 raeburn 13666:
1.25 raeburn 13667: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13668: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13669: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13670:
1.44 raeburn 13671: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13672: if (keys(%{$usertypes}) == 0) {
13673: @cansearch = ('default');
13674: } else {
13675: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13676: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13677: if (!grep(/^\Q$type\E$/,@cansearch)) {
13678: push(@{$changes{'cansearch'}},$type);
13679: }
1.23 raeburn 13680: }
1.26 raeburn 13681: foreach my $type (@cansearch) {
13682: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13683: push(@{$changes{'cansearch'}},$type);
13684: }
1.23 raeburn 13685: }
1.26 raeburn 13686: } else {
13687: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13688: }
13689: }
13690:
13691: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13692: foreach my $by (@{$currdirsrch{'searchby'}}) {
13693: if (!grep(/^\Q$by\E$/,@searchby)) {
13694: push(@{$changes{'searchby'}},$by);
13695: }
13696: }
13697: foreach my $by (@searchby) {
13698: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13699: push(@{$changes{'searchby'}},$by);
13700: }
13701: }
13702: } else {
13703: push(@{$changes{'searchby'}},@searchby);
13704: }
1.25 raeburn 13705:
13706: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13707: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13708: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13709: push(@{$changes{'searchtypes'}},$type);
13710: }
13711: }
13712: foreach my $type (@searchtypes) {
13713: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13714: push(@{$changes{'searchtypes'}},$type);
13715: }
13716: }
13717: } else {
13718: if (exists($currdirsrch{'searchtypes'})) {
13719: foreach my $type (@searchtypes) {
13720: if ($type ne $currdirsrch{'searchtypes'}) {
13721: push(@{$changes{'searchtypes'}},$type);
13722: }
13723: }
13724: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13725: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13726: }
13727: } else {
13728: push(@{$changes{'searchtypes'}},@searchtypes);
13729: }
13730: }
13731:
1.23 raeburn 13732: my %dirsrch_hash = (
13733: directorysrch => { available => $env{'form.dirsrch_available'},
13734: cansearch => \@cansearch,
1.160.6.72 raeburn 13735: localonly => $env{'form.dirsrch_instlocalonly'},
13736: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13737: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13738: searchby => \@searchby,
1.25 raeburn 13739: searchtypes => \@searchtypes,
1.23 raeburn 13740: }
13741: );
13742: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13743: $dom);
13744: if ($putresult eq 'ok') {
13745: if (exists($currdirsrch{'available'})) {
13746: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13747: $changes{'available'} = 1;
13748: }
13749: } else {
13750: if ($env{'form.dirsrch_available'} eq '1') {
13751: $changes{'available'} = 1;
13752: }
13753: }
1.160.6.72 raeburn 13754: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 13755: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13756: $changes{'lcavailable'} = 1;
13757: }
1.24 raeburn 13758: } else {
1.160.6.72 raeburn 13759: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13760: $changes{'lcavailable'} = 1;
13761: }
13762: }
13763: if (exists($currdirsrch{'localonly'})) {
13764: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 13765: $changes{'localonly'} = 1;
13766: }
1.160.6.72 raeburn 13767: } else {
13768: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13769: $changes{'localonly'} = 1;
13770: }
13771: }
13772: if (exists($currdirsrch{'lclocalonly'})) {
13773: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13774: $changes{'lclocalonly'} = 1;
13775: }
13776: } else {
13777: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13778: $changes{'lclocalonly'} = 1;
13779: }
1.24 raeburn 13780: }
1.23 raeburn 13781: if (keys(%changes) > 0) {
13782: $resulttext = &mt('Changes made:').'<ul>';
13783: if ($changes{'available'}) {
13784: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13785: }
1.160.6.72 raeburn 13786: if ($changes{'lcavailable'}) {
13787: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13788: }
1.24 raeburn 13789: if ($changes{'localonly'}) {
1.160.6.72 raeburn 13790: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13791: }
13792: if ($changes{'lclocalonly'}) {
13793: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 13794: }
1.23 raeburn 13795: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13796: my $chgtext;
1.26 raeburn 13797: if (ref($usertypes) eq 'HASH') {
13798: if (keys(%{$usertypes}) > 0) {
13799: foreach my $type (@{$types}) {
13800: if (grep(/^\Q$type\E$/,@cansearch)) {
13801: $chgtext .= $usertypes->{$type}.'; ';
13802: }
13803: }
13804: if (grep(/^default$/,@cansearch)) {
13805: $chgtext .= $othertitle;
13806: } else {
13807: $chgtext =~ s/\; $//;
13808: }
1.160.6.13 raeburn 13809: $resulttext .=
13810: '<li>'.
13811: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13812: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13813: '</li>';
1.23 raeburn 13814: }
13815: }
13816: }
13817: if (ref($changes{'searchby'}) eq 'ARRAY') {
13818: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13819: my $chgtext;
13820: foreach my $type (@{$titleorder}) {
13821: if (grep(/^\Q$type\E$/,@searchby)) {
13822: if (defined($searchtitles->{$type})) {
13823: $chgtext .= $searchtitles->{$type}.'; ';
13824: }
13825: }
13826: }
13827: $chgtext =~ s/\; $//;
13828: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13829: }
1.25 raeburn 13830: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13831: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13832: my $chgtext;
13833: foreach my $type (@{$srchtypeorder}) {
13834: if (grep(/^\Q$type\E$/,@searchtypes)) {
13835: if (defined($srchtypes_desc->{$type})) {
13836: $chgtext .= $srchtypes_desc->{$type}.'; ';
13837: }
13838: }
13839: }
13840: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 13841: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13842: }
13843: $resulttext .= '</ul>';
1.160.6.81 raeburn 13844: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13845: if (ref($lastactref) eq 'HASH') {
13846: $lastactref->{'directorysrch'} = 1;
13847: }
1.23 raeburn 13848: } else {
1.160.6.72 raeburn 13849: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13850: }
13851: } else {
13852: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13853: &mt('An error occurred: [_1]',$putresult).'</span>';
13854: }
13855: return $resulttext;
13856: }
13857:
1.28 raeburn 13858: sub modify_contacts {
1.160.6.24 raeburn 13859: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13860: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13861: if (ref($domconfig{'contacts'}) eq 'HASH') {
13862: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13863: $currsetting{$key} = $domconfig{'contacts'}{$key};
13864: }
13865: }
1.160.6.78 raeburn 13866: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13867: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 13868: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 13869: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 13870: my @toggles = ('reporterrors','reportupdates','reportstatus');
13871: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 13872: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13873: foreach my $type (@mailings) {
13874: @{$newsetting{$type}} =
13875: &Apache::loncommon::get_env_multiple('form.'.$type);
13876: foreach my $item (@contacts) {
13877: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13878: $contacts_hash{contacts}{$type}{$item} = 1;
13879: } else {
13880: $contacts_hash{contacts}{$type}{$item} = 0;
13881: }
1.160.6.78 raeburn 13882: }
1.28 raeburn 13883: $others{$type} = $env{'form.'.$type.'_others'};
13884: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 13885: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13886: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13887: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 13888: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13889: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13890: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13891: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13892: }
1.134 raeburn 13893: }
1.28 raeburn 13894: }
13895: foreach my $item (@contacts) {
13896: $to{$item} = $env{'form.'.$item};
13897: $contacts_hash{'contacts'}{$item} = $to{$item};
13898: }
1.160.6.23 raeburn 13899: foreach my $item (@toggles) {
13900: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13901: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13902: }
13903: }
1.160.6.107 raeburn 13904: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13905: foreach my $item (@lonstatus) {
13906: if ($item eq 'excluded') {
13907: my (%serverhomes,@excluded);
13908: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13909: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13910: if (@possexcluded) {
13911: foreach my $id (sort(@possexcluded)) {
13912: if ($serverhomes{$id}) {
13913: push(@excluded,$id);
13914: }
13915: }
13916: }
13917: if (@excluded) {
13918: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13919: }
13920: } elsif ($item eq 'weights') {
13921: foreach my $type ('E','W','N','U') {
13922: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13923: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13924: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13925: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13926: $env{'form.error'.$item.'_'.$type};
13927: }
13928: }
13929: }
13930: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13931: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13932: if ($env{'form.error'.$item} =~ /^\d+$/) {
13933: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13934: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13935: }
13936: }
13937: }
13938: }
1.160.6.78 raeburn 13939: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13940: foreach my $field (@{$fields}) {
13941: if (ref($possoptions->{$field}) eq 'ARRAY') {
13942: my $value = $env{'form.helpform_'.$field};
13943: $value =~ s/^\s+|\s+$//g;
13944: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 13945: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 13946: if ($field eq 'screenshot') {
13947: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13948: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 13949: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 13950: }
13951: }
13952: }
13953: }
13954: }
13955: }
1.160.6.101 raeburn 13956: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13957: my (@statuses,%usertypeshash,@overrides);
13958: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13959: @statuses = @{$types};
13960: if (ref($usertypes) eq 'HASH') {
13961: %usertypeshash = %{$usertypes};
13962: }
13963: }
13964: if (@statuses) {
13965: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13966: foreach my $type (@possoverrides) {
13967: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13968: push(@overrides,$type);
13969: }
13970: }
13971: if (@overrides) {
13972: foreach my $type (@overrides) {
13973: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13974: foreach my $item (@contacts) {
13975: if (grep(/^\Q$item\E$/,@standard)) {
13976: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13977: $newsetting{'override_'.$type}{$item} = 1;
13978: } else {
13979: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13980: $newsetting{'override_'.$type}{$item} = 0;
13981: }
13982: }
13983: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13984: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13985: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13986: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13987: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13988: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13989: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13990: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13991: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13992: }
13993: }
13994: }
13995: }
1.28 raeburn 13996: if (keys(%currsetting) > 0) {
13997: foreach my $item (@contacts) {
13998: if ($to{$item} ne $currsetting{$item}) {
13999: $changes{$item} = 1;
14000: }
14001: }
14002: foreach my $type (@mailings) {
14003: foreach my $item (@contacts) {
14004: if (ref($currsetting{$type}) eq 'HASH') {
14005: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14006: push(@{$changes{$type}},$item);
14007: }
14008: } else {
14009: push(@{$changes{$type}},@{$newsetting{$type}});
14010: }
14011: }
14012: if ($others{$type} ne $currsetting{$type}{'others'}) {
14013: push(@{$changes{$type}},'others');
14014: }
1.160.6.78 raeburn 14015: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14016: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14017: push(@{$changes{$type}},'bcc');
14018: }
1.160.6.78 raeburn 14019: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14020: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14021: push(@{$changes{$type}},'include');
14022: }
14023: }
14024: }
14025: if (ref($fields) eq 'ARRAY') {
14026: if (ref($currsetting{'helpform'}) eq 'HASH') {
14027: foreach my $field (@{$fields}) {
14028: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14029: push(@{$changes{'helpform'}},$field);
14030: }
14031: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14032: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14033: push(@{$changes{'helpform'}},'maxsize');
14034: }
14035: }
14036: }
14037: } else {
14038: foreach my $field (@{$fields}) {
14039: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14040: push(@{$changes{'helpform'}},$field);
14041: }
14042: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14043: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14044: push(@{$changes{'helpform'}},'maxsize');
14045: }
14046: }
14047: }
1.134 raeburn 14048: }
1.28 raeburn 14049: }
1.160.6.101 raeburn 14050: if (@statuses) {
14051: if (ref($currsetting{'overrides'}) eq 'HASH') {
14052: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14053: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14054: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14055: foreach my $item (@contacts,'bcc','others','include') {
14056: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14057: push(@{$changes{'overrides'}},$key);
14058: last;
14059: }
14060: }
14061: } else {
14062: push(@{$changes{'overrides'}},$key);
14063: }
14064: }
14065: }
14066: foreach my $key (@overrides) {
14067: unless (exists($currsetting{'overrides'}{$key})) {
14068: push(@{$changes{'overrides'}},$key);
14069: }
14070: }
14071: } else {
14072: foreach my $key (@overrides) {
14073: push(@{$changes{'overrides'}},$key);
14074: }
14075: }
14076: }
1.160.6.107 raeburn 14077: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14078: foreach my $key ('excluded','weights','threshold','sysmail') {
14079: if ($key eq 'excluded') {
14080: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14081: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14082: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14083: (@{$currsetting{'lonstatus'}{$key}})) {
14084: my @diffs =
14085: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14086: $currsetting{'lonstatus'}{$key});
14087: if (@diffs) {
14088: push(@{$changes{'lonstatus'}},$key);
14089: }
14090: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14091: push(@{$changes{'lonstatus'}},$key);
14092: }
14093: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14094: (@{$currsetting{'lonstatus'}{$key}})) {
14095: push(@{$changes{'lonstatus'}},$key);
14096: }
14097: } elsif ($key eq 'weights') {
14098: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14099: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14100: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14101: foreach my $type ('E','W','N','U') {
14102: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14103: $currsetting{'lonstatus'}{$key}{$type}) {
14104: push(@{$changes{'lonstatus'}},$key);
14105: last;
14106: }
14107: }
14108: } else {
14109: foreach my $type ('E','W','N','U') {
14110: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14111: push(@{$changes{'lonstatus'}},$key);
14112: last;
14113: }
14114: }
14115: }
14116: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14117: foreach my $type ('E','W','N','U') {
14118: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14119: push(@{$changes{'lonstatus'}},$key);
14120: last;
14121: }
14122: }
14123: }
14124: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14125: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14126: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14127: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14128: push(@{$changes{'lonstatus'}},$key);
14129: }
14130: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14131: push(@{$changes{'lonstatus'}},$key);
14132: }
14133: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14134: push(@{$changes{'lonstatus'}},$key);
14135: }
14136: }
14137: }
14138: } else {
14139: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14140: foreach my $key ('excluded','weights','threshold','sysmail') {
14141: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14142: push(@{$changes{'lonstatus'}},$key);
14143: }
14144: }
14145: }
14146: }
1.28 raeburn 14147: } else {
14148: my %default;
14149: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14150: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14151: $default{'errormail'} = 'adminemail';
14152: $default{'packagesmail'} = 'adminemail';
14153: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 14154: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 14155: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 14156: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 14157: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 14158: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 14159: foreach my $item (@contacts) {
14160: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 14161: $changes{$item} = 1;
1.160.6.23 raeburn 14162: }
1.28 raeburn 14163: }
14164: foreach my $type (@mailings) {
14165: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14166: push(@{$changes{$type}},@{$newsetting{$type}});
14167: }
14168: if ($others{$type} ne '') {
14169: push(@{$changes{$type}},'others');
1.134 raeburn 14170: }
1.160.6.78 raeburn 14171: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14172: if ($bcc{$type} ne '') {
14173: push(@{$changes{$type}},'bcc');
14174: }
1.160.6.78 raeburn 14175: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14176: push(@{$changes{$type}},'include');
14177: }
14178: }
14179: }
14180: if (ref($fields) eq 'ARRAY') {
14181: foreach my $field (@{$fields}) {
14182: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14183: push(@{$changes{'helpform'}},$field);
14184: }
14185: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14186: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14187: push(@{$changes{'helpform'}},'maxsize');
14188: }
14189: }
1.134 raeburn 14190: }
1.28 raeburn 14191: }
1.160.6.107 raeburn 14192: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14193: foreach my $key ('excluded','weights','threshold','sysmail') {
14194: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14195: push(@{$changes{'lonstatus'}},$key);
14196: }
14197: }
14198: }
1.28 raeburn 14199: }
1.160.6.23 raeburn 14200: foreach my $item (@toggles) {
14201: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
14202: $changes{$item} = 1;
14203: } elsif ((!$env{'form.'.$item}) &&
14204: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
14205: $changes{$item} = 1;
14206: }
14207: }
1.28 raeburn 14208: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
14209: $dom);
14210: if ($putresult eq 'ok') {
14211: if (keys(%changes) > 0) {
1.160.6.24 raeburn 14212: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14213: if (ref($lastactref) eq 'HASH') {
14214: $lastactref->{'domainconfig'} = 1;
14215: }
1.28 raeburn 14216: my ($titles,$short_titles) = &contact_titles();
14217: $resulttext = &mt('Changes made:').'<ul>';
14218: foreach my $item (@contacts) {
14219: if ($changes{$item}) {
14220: $resulttext .= '<li>'.$titles->{$item}.
14221: &mt(' set to: ').
14222: '<span class="LC_cusr_emph">'.
14223: $to{$item}.'</span></li>';
14224: }
14225: }
14226: foreach my $type (@mailings) {
14227: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 14228: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14229: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
14230: } else {
14231: $resulttext .= '<li>'.$titles->{$type}.': ';
14232: }
1.28 raeburn 14233: my @text;
14234: foreach my $item (@{$newsetting{$type}}) {
14235: push(@text,$short_titles->{$item});
14236: }
14237: if ($others{$type} ne '') {
14238: push(@text,$others{$type});
14239: }
1.160.6.78 raeburn 14240: if (@text) {
14241: $resulttext .= '<span class="LC_cusr_emph">'.
14242: join(', ',@text).'</span>';
14243: }
14244: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14245: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 14246: my $bcctext;
14247: if (@text) {
14248: $bcctext = ' '.&mt('with Bcc to');
14249: } else {
14250: $bcctext = '(Bcc)';
14251: }
14252: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
14253: } elsif (!@text) {
14254: $resulttext .= &mt('No one');
1.134 raeburn 14255: }
1.160.6.78 raeburn 14256: if ($includestr{$type} ne '') {
14257: if ($includeloc{$type} eq 'b') {
14258: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
14259: } elsif ($includeloc{$type} eq 's') {
14260: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
14261: }
14262: }
14263: } elsif (!@text) {
14264: $resulttext .= &mt('No recipients');
1.134 raeburn 14265: }
14266: $resulttext .= '</li>';
1.28 raeburn 14267: }
14268: }
1.160.6.101 raeburn 14269: if (ref($changes{'overrides'}) eq 'ARRAY') {
14270: my @deletions;
14271: foreach my $type (@{$changes{'overrides'}}) {
14272: if ($usertypeshash{$type}) {
14273: if (grep(/^\Q$type\E/,@overrides)) {
14274: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14275: $usertypeshash{$type}).'<ul><li>';
14276: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14277: my @text;
14278: foreach my $item (@contacts) {
14279: if ($newsetting{'override_'.$type}{$item}) {
14280: push(@text,$short_titles->{$item});
14281: }
14282: }
14283: if ($newsetting{'override_'.$type}{'others'} ne '') {
14284: push(@text,$newsetting{'override_'.$type}{'others'});
14285: }
14286:
14287: if (@text) {
14288: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14289: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14290: }
14291: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14292: my $bcctext;
14293: if (@text) {
14294: $bcctext = ' '.&mt('with Bcc to');
14295: } else {
14296: $bcctext = '(Bcc)';
14297: }
14298: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14299: } elsif (!@text) {
14300: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14301: }
14302: $resulttext .= '</li>';
14303: if ($newsetting{'override_'.$type}{'include'} ne '') {
14304: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14305: if ($loc eq 'b') {
14306: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14307: } elsif ($loc eq 's') {
14308: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14309: }
14310: }
14311: }
14312: $resulttext .= '</li></ul></li>';
14313: } else {
14314: push(@deletions,$usertypeshash{$type});
14315: }
14316: }
14317: }
14318: if (@deletions) {
14319: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14320: join(', ',@deletions)).'</li>';
14321: }
14322: }
1.160.6.23 raeburn 14323: my @offon = ('off','on');
1.160.6.107 raeburn 14324: my $corelink = &core_link_msu();
1.160.6.23 raeburn 14325: if ($changes{'reporterrors'}) {
14326: $resulttext .= '<li>'.
14327: &mt('E-mail error reports to [_1] set to "'.
14328: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 14329: $corelink).
1.160.6.23 raeburn 14330: '</li>';
14331: }
14332: if ($changes{'reportupdates'}) {
14333: $resulttext .= '<li>'.
14334: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14335: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 14336: $corelink).
1.160.6.23 raeburn 14337: '</li>';
14338: }
1.160.6.107 raeburn 14339: if ($changes{'reportstatus'}) {
14340: $resulttext .= '<li>'.
14341: &mt('E-mail status if errors above threshold to [_1] set to "'.
14342: $offon[$env{'form.reportstatus'}].'".',
14343: $corelink).
14344: '</li>';
14345: }
14346: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14347: $resulttext .= '<li>'.
14348: &mt('Nightly status check e-mail settings').':<ul>';
14349: my (%defval,%use_def,%shown);
14350: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14351: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14352: $defval{'weights'} =
14353: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
14354: $defval{'excluded'} = &mt('None');
14355: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14356: foreach my $item ('threshold','sysmail','weights','excluded') {
14357: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14358: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14359: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14360: } elsif ($item eq 'weights') {
14361: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
14362: foreach my $type ('E','W','N','U') {
14363: $shown{$item} .= $lonstatus_names->{$type}.'=';
14364: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14365: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14366: } else {
14367: $shown{$item} .= $lonstatus_defs->{$type};
14368: }
14369: $shown{$item} .= ', ';
14370: }
14371: $shown{$item} =~ s/, $//;
14372: } else {
14373: $shown{$item} = $defval{$item};
14374: }
14375: } elsif ($item eq 'excluded') {
14376: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14377: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14378: } else {
14379: $shown{$item} = $defval{$item};
14380: }
14381: }
14382: } else {
14383: $shown{$item} = $defval{$item};
14384: }
14385: }
14386: } else {
14387: foreach my $item ('threshold','weights','excluded','sysmail') {
14388: $shown{$item} = $defval{$item};
14389: }
14390: }
14391: foreach my $item ('threshold','weights','excluded','sysmail') {
14392: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14393: $shown{$item}).'</li>';
14394: }
14395: $resulttext .= '</ul></li>';
14396: }
1.160.6.78 raeburn 14397: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14398: my (@optional,@required,@unused,$maxsizechg);
14399: foreach my $field (@{$changes{'helpform'}}) {
14400: if ($field eq 'maxsize') {
14401: $maxsizechg = 1;
14402: next;
14403: }
14404: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
14405: push(@optional,$field);
14406: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14407: push(@unused,$field);
14408: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
14409: push(@required,$field);
14410: }
14411: }
14412: if (@optional) {
14413: $resulttext .= '<li>'.
14414: &mt('Help form fields changed to "Optional": [_1].',
14415: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14416: '</li>';
14417: }
14418: if (@required) {
14419: $resulttext .= '<li>'.
14420: &mt('Help form fields changed to "Required": [_1].',
14421: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14422: '</li>';
14423: }
14424: if (@unused) {
14425: $resulttext .= '<li>'.
14426: &mt('Help form fields changed to "Not shown": [_1].',
14427: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14428: '</li>';
14429: }
14430: if ($maxsizechg) {
14431: $resulttext .= '<li>'.
14432: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14433: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14434: '</li>';
14435: }
14436: }
1.28 raeburn 14437: $resulttext .= '</ul>';
14438: } else {
1.160.6.78 raeburn 14439: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14440: }
14441: } else {
14442: $resulttext = '<span class="LC_error">'.
14443: &mt('An error occurred: [_1].',$putresult).'</span>';
14444: }
14445: return $resulttext;
14446: }
14447:
1.160.6.98 raeburn 14448: sub modify_passwords {
14449: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14450: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14451: $updatedefaults,$updateconf);
14452: my $customfn = 'resetpw.html';
14453: if (ref($domconfig{'passwords'}) eq 'HASH') {
14454: %current = %{$domconfig{'passwords'}};
14455: }
14456: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14457: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14458: if (ref($types) eq 'ARRAY') {
14459: @oktypes = @{$types};
14460: }
14461: push(@oktypes,'default');
14462:
14463: my %titles = &Apache::lonlocal::texthash (
14464: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14465: intauth_check => 'Check bcrypt cost if authenticated',
14466: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14467: permanent => 'Permanent e-mail address',
14468: critical => 'Critical notification address',
14469: notify => 'Notification address',
14470: min => 'Minimum password length',
14471: max => 'Maximum password length',
14472: chars => 'Required characters',
14473: numsaved => 'Number of previous passwords to save',
14474: reset => 'Resetting Forgotten Password',
14475: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14476: rules => 'Rules for LON-CAPA Passwords',
14477: crsownerchg => 'Course Owner Changing Student Passwords',
14478: username => 'Username',
14479: email => 'E-mail address',
14480: );
14481:
14482: #
14483: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14484: #
14485: my (%curr_defaults,%save_defaults);
14486: if (ref($domconfig{'defaults'}) eq 'HASH') {
14487: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14488: if ($key =~ /^intauth_(cost|check|switch)$/) {
14489: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14490: } else {
14491: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14492: }
14493: }
14494: }
14495: my %staticdefaults = (
14496: 'resetlink' => 2,
14497: 'resetcase' => \@oktypes,
14498: 'resetprelink' => 'both',
14499: 'resetemail' => ['critical','notify','permanent'],
14500: 'intauth_cost' => 10,
14501: 'intauth_check' => 0,
14502: 'intauth_switch' => 0,
14503: );
1.160.6.99 raeburn 14504: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 14505: foreach my $type (@oktypes) {
14506: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14507: }
14508: my $linklife = $env{'form.passwords_link'};
14509: $linklife =~ s/^\s+|\s+$//g;
14510: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14511: $newvalues{'resetlink'} = $linklife;
14512: if ($current{'resetlink'}) {
14513: if ($current{'resetlink'} ne $linklife) {
14514: $changes{'reset'} = 1;
14515: }
1.160.6.102 raeburn 14516: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14517: if ($staticdefaults{'resetlink'} ne $linklife) {
14518: $changes{'reset'} = 1;
14519: }
14520: }
14521: } elsif ($current{'resetlink'}) {
14522: $changes{'reset'} = 1;
14523: }
14524: my @casesens;
14525: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14526: foreach my $case (sort(@posscase)) {
14527: if (grep(/^\Q$case\E$/,@oktypes)) {
14528: push(@casesens,$case);
14529: }
14530: }
14531: $newvalues{'resetcase'} = \@casesens;
14532: if (ref($current{'resetcase'}) eq 'ARRAY') {
14533: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14534: if (@diffs > 0) {
14535: $changes{'reset'} = 1;
14536: }
1.160.6.102 raeburn 14537: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14538: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14539: if (@diffs > 0) {
14540: $changes{'reset'} = 1;
14541: }
14542: }
14543: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14544: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14545: if (exists($current{'resetprelink'})) {
14546: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14547: $changes{'reset'} = 1;
14548: }
1.160.6.102 raeburn 14549: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14550: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14551: $changes{'reset'} = 1;
14552: }
14553: }
14554: } elsif ($current{'resetprelink'}) {
14555: $changes{'reset'} = 1;
14556: }
14557: foreach my $type (@oktypes) {
14558: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14559: my @postlink;
14560: foreach my $item (sort(@possplink)) {
14561: if ($item =~ /^(email|username)$/) {
14562: push(@postlink,$item);
14563: }
14564: }
14565: $newvalues{'resetpostlink'}{$type} = \@postlink;
14566: unless ($changes{'reset'}) {
14567: if (ref($current{'resetpostlink'}) eq 'HASH') {
14568: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14569: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14570: if (@diffs > 0) {
14571: $changes{'reset'} = 1;
14572: }
14573: } else {
14574: $changes{'reset'} = 1;
14575: }
1.160.6.102 raeburn 14576: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14577: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14578: if (@diffs > 0) {
14579: $changes{'reset'} = 1;
14580: }
14581: }
14582: }
14583: }
14584: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14585: my @resetemail;
14586: foreach my $item (sort(@possemailsrc)) {
14587: if ($item =~ /^(permanent|critical|notify)$/) {
14588: push(@resetemail,$item);
14589: }
14590: }
14591: $newvalues{'resetemail'} = \@resetemail;
14592: unless ($changes{'reset'}) {
14593: if (ref($current{'resetemail'}) eq 'ARRAY') {
14594: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14595: if (@diffs > 0) {
14596: $changes{'reset'} = 1;
14597: }
1.160.6.102 raeburn 14598: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14599: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14600: if (@diffs > 0) {
14601: $changes{'reset'} = 1;
14602: }
14603: }
14604: }
14605: if ($env{'form.passwords_stdtext'} == 0) {
14606: $newvalues{'resetremove'} = 1;
14607: unless ($current{'resetremove'}) {
14608: $changes{'reset'} = 1;
14609: }
14610: } elsif ($current{'resetremove'}) {
14611: $changes{'reset'} = 1;
14612: }
14613: if ($env{'form.passwords_customfile.filename'} ne '') {
14614: my $servadm = $r->dir_config('lonAdmEMail');
14615: my $servadm = $r->dir_config('lonAdmEMail');
14616: my ($configuserok,$author_ok,$switchserver) =
14617: &config_check($dom,$confname,$servadm);
14618: my $error;
14619: if ($configuserok eq 'ok') {
14620: if ($switchserver) {
14621: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14622: } else {
14623: if ($author_ok eq 'ok') {
14624: my ($result,$customurl) =
14625: &publishlogo($r,'upload','passwords_customfile',$dom,
14626: $confname,'customtext/resetpw','','',$customfn);
14627: if ($result eq 'ok') {
14628: $newvalues{'resetcustom'} = $customurl;
14629: $changes{'reset'} = 1;
14630: } else {
14631: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14632: }
14633: } else {
14634: $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);
14635: }
14636: }
14637: } else {
14638: $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);
14639: }
14640: if ($error) {
14641: &Apache::lonnet::logthis($error);
14642: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14643: }
14644: } elsif ($current{'resetcustom'}) {
14645: if ($env{'form.passwords_custom_del'}) {
14646: $changes{'reset'} = 1;
14647: } else {
14648: $newvalues{'resetcustom'} = $current{'resetcustom'};
14649: }
14650: }
14651: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14652: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14653: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14654: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14655: $changes{'intauth'} = 1;
14656: }
14657: } else {
14658: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14659: }
14660: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14661: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14662: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14663: $changes{'intauth'} = 1;
14664: }
14665: } else {
14666: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14667: }
14668: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14669: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14670: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14671: $changes{'intauth'} = 1;
14672: }
14673: } else {
14674: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14675: }
14676: foreach my $item ('cost','check','switch') {
14677: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14678: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14679: $updatedefaults = 1;
14680: }
14681: }
1.160.6.118.2 5(raebur 14682:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 14683: my %crsownerchg = (
14684: by => [],
14685: for => [],
14686: );
14687: foreach my $item ('by','for') {
14688: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14689: foreach my $type (sort(@posstypes)) {
14690: if (grep(/^\Q$type\E$/,@oktypes)) {
14691: push(@{$crsownerchg{$item}},$type);
14692: }
14693: }
14694: }
14695: $newvalues{'crsownerchg'} = \%crsownerchg;
14696: if (ref($current{'crsownerchg'}) eq 'HASH') {
14697: foreach my $item ('by','for') {
14698: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14699: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14700: if (@diffs > 0) {
14701: $changes{'crsownerchg'} = 1;
14702: last;
14703: }
14704: }
14705: }
1.160.6.102 raeburn 14706: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 14707: foreach my $item ('by','for') {
14708: if (@{$crsownerchg{$item}} > 0) {
14709: $changes{'crsownerchg'} = 1;
14710: last;
14711: }
14712: }
14713: }
14714:
14715: my %confighash = (
14716: defaults => \%save_defaults,
14717: passwords => \%newvalues,
14718: );
14719: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14720:
14721: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14722: if ($putresult eq 'ok') {
14723: if (keys(%changes) > 0) {
14724: $resulttext = &mt('Changes made: ').'<ul>';
14725: foreach my $key ('reset','intauth','rules','crsownerchg') {
14726: if ($changes{$key}) {
14727: unless ($key eq 'intauth') {
14728: $updateconf = 1;
14729: }
14730: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14731: if ($key eq 'reset') {
14732: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14733: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14734: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14735: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 14736: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14737: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14738: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14739: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14740: }
1.160.6.98 raeburn 14741: } else {
14742: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14743: }
14744: if ($confighash{'passwords'}{'resetlink'}) {
14745: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14746: } else {
14747: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14748: &mt('Will default to 2 hours').'</li>';
14749: }
14750: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14751: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14752: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14753: } else {
14754: my $casesens;
14755: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14756: if ($type eq 'default') {
14757: $casesens .= $othertitle.', ';
14758: } elsif ($usertypes->{$type} ne '') {
14759: $casesens .= $usertypes->{$type}.', ';
14760: }
14761: }
14762: $casesens =~ s/\Q, \E$//;
14763: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14764: }
14765: } else {
14766: $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>';
14767: }
14768: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14769: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14770: } else {
14771: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14772: }
14773: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14774: my $output;
14775: if (ref($types) eq 'ARRAY') {
14776: foreach my $type (@{$types}) {
14777: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14778: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14779: $output .= $usertypes->{$type}.' -- '.&mt('none');
14780: } else {
14781: $output .= $usertypes->{$type}.' -- '.
14782: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14783: }
14784: }
14785: }
14786: }
14787: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14788: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14789: $output .= $othertitle.' -- '.&mt('none');
14790: } else {
14791: $output .= $othertitle.' -- '.
14792: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14793: }
14794: }
14795: if ($output) {
14796: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14797: } else {
14798: $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>';
14799: }
14800: } else {
14801: $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>';
14802: }
14803: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14804: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14805: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14806: } else {
14807: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14808: }
14809: } else {
1.160.6.110 raeburn 14810: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.160.6.98 raeburn 14811: }
14812: if ($confighash{'passwords'}{'resetremove'}) {
14813: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14814: } else {
14815: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14816: }
14817: if ($confighash{'passwords'}{'resetcustom'}) {
14818: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 14819: &mt('custom text'),600,500,undef,undef,
14820: undef,undef,'background-color:#ffffff');
14821: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 14822: } else {
14823: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14824: }
14825: } elsif ($key eq 'intauth') {
14826: foreach my $item ('cost','switch','check') {
14827: my $value = $save_defaults{$key.'_'.$item};
14828: if ($item eq 'switch') {
14829: my %optiondesc = &Apache::lonlocal::texthash (
14830: 0 => 'No',
14831: 1 => 'Yes',
14832: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14833: );
14834: if ($value =~ /^(0|1|2)$/) {
14835: $value = $optiondesc{$value};
14836: } else {
14837: $value = &mt('none -- defaults to No');
14838: }
14839: } elsif ($item eq 'check') {
14840: my %optiondesc = &Apache::lonlocal::texthash (
14841: 0 => 'No',
14842: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14843: 2 => 'Yes, disallow login if stored cost is less than domain default',
14844: );
14845: if ($value =~ /^(0|1|2)$/) {
14846: $value = $optiondesc{$value};
14847: } else {
14848: $value = &mt('none -- defaults to No');
14849: }
14850: }
14851: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14852: }
14853: } elsif ($key eq 'rules') {
14854: foreach my $rule ('min','max','numsaved') {
14855: if ($confighash{'passwords'}{$rule} eq '') {
14856: if ($rule eq 'min') {
14857: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 14858: ' '.&mt('Default of [_1] will be used',
14859: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 14860: } else {
14861: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14862: }
14863: } else {
14864: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14865: }
14866: }
1.160.6.104 raeburn 14867: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14868: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14869: my %rulenames = &Apache::lonlocal::texthash(
14870: uc => 'At least one upper case letter',
14871: lc => 'At least one lower case letter',
14872: num => 'At least one number',
14873: spec => 'At least one non-alphanumeric',
14874: );
14875: my $needed = '<ul><li>'.
14876: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14877: '</li></ul>';
14878: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14879: } else {
14880: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14881: }
14882: } else {
14883: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14884: }
1.160.6.98 raeburn 14885: } elsif ($key eq 'crsownerchg') {
14886: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14887: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14888: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14889: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14890: } else {
14891: my %crsownerstr;
14892: foreach my $item ('by','for') {
14893: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14894: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14895: if ($type eq 'default') {
14896: $crsownerstr{$item} .= $othertitle.', ';
14897: } elsif ($usertypes->{$type} ne '') {
14898: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14899: }
14900: }
14901: $crsownerstr{$item} =~ s/\Q, \E$//;
14902: }
14903: }
14904: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14905: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14906: }
14907: } else {
14908: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14909: }
14910: }
14911: $resulttext .= '</ul></li>';
14912: }
14913: }
14914: $resulttext .= '</ul>';
14915: } else {
14916: $resulttext = &mt('No changes made to password settings');
14917: }
14918: my $cachetime = 24*60*60;
14919: if ($updatedefaults) {
14920: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14921: if (ref($lastactref) eq 'HASH') {
14922: $lastactref->{'domdefaults'} = 1;
14923: }
14924: }
14925: if ($updateconf) {
14926: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14927: if (ref($lastactref) eq 'HASH') {
14928: $lastactref->{'passwdconf'} = 1;
14929: }
14930: }
14931: } else {
14932: $resulttext = '<span class="LC_error">'.
14933: &mt('An error occurred: [_1]',$putresult).'</span>';
14934: }
14935: if ($errors) {
14936: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14937: $errors.'</ul></p>';
14938: }
14939: return $resulttext;
14940: }
14941:
1.160.6.118.2 5(raebur 14942:2): sub password_rule_changes {
14943:2): my ($prefix,$newvalues,$current,$changes) = @_;
14944:2): return unless ((ref($newvalues) eq 'HASH') &&
14945:2): (ref($current) eq 'HASH') &&
14946:2): (ref($changes) eq 'HASH'));
14947:2): my (@rules,%staticdefaults);
14948:2): if ($prefix eq 'passwords') {
14949:2): @rules = ('min','max','numsaved');
14950:2): } elsif ($prefix eq 'secrets') {
14951:2): @rules = ('min','max');
14952:2): }
14953:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
14954:2): foreach my $rule (@rules) {
14955:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
14956:2): my $ruleok;
14957:2): if ($rule eq 'min') {
14958:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
14959:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
14960:2): $ruleok = 1;
14961:2): }
14962:2): }
14963:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
14964:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
14965:2): $ruleok = 1;
14966:2): }
14967:2): if ($ruleok) {
14968:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
14969:2): if (exists($current->{$rule})) {
14970:2): if ($newvalues->{$rule} ne $current->{$rule}) {
14971:2): $changes->{'rules'} = 1;
14972:2): }
14973:2): } elsif ($rule eq 'min') {
14974:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
14975:2): $changes->{'rules'} = 1;
14976:2): }
14977:2): } else {
14978:2): $changes->{'rules'} = 1;
14979:2): }
14980:2): } elsif (exists($current->{$rule})) {
14981:2): $changes->{'rules'} = 1;
14982:2): }
14983:2): }
14984:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
14985:2): my @chars;
14986:2): foreach my $item (sort(@posschars)) {
14987:2): if ($item =~ /^(uc|lc|num|spec)$/) {
14988:2): push(@chars,$item);
14989:2): }
14990:2): }
14991:2): $newvalues->{'chars'} = \@chars;
14992:2): unless ($changes->{'rules'}) {
14993:2): if (ref($current->{'chars'}) eq 'ARRAY') {
14994:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
14995:2): if (@diffs > 0) {
14996:2): $changes->{'rules'} = 1;
14997:2): }
14998:2): } else {
14999:2): if (@chars > 0) {
15000:2): $changes->{'rules'} = 1;
15001:2): }
15002:2): }
15003:2): }
15004:2): return;
15005:2): }
15006:2):
1.28 raeburn 15007: sub modify_usercreation {
1.27 raeburn 15008: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15009: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15010: my $warningmsg;
1.27 raeburn 15011: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15012: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 15013: if ($key eq 'cancreate') {
15014: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15015: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 15016: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 15017: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 15018: } else {
15019: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 15020: }
1.50 raeburn 15021: }
1.43 raeburn 15022: }
1.160.6.34 raeburn 15023: } elsif ($key eq 'email_rule') {
15024: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15025: } else {
15026: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 15027: }
15028: }
1.34 raeburn 15029: }
1.160.6.34 raeburn 15030: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15031: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15032: my @contexts = ('author','course','requestcrs');
15033: foreach my $item(@contexts) {
15034: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 15035: }
1.34 raeburn 15036: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15037: foreach my $item (@contexts) {
1.160.6.34 raeburn 15038: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15039: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 15040: }
1.27 raeburn 15041: }
1.34 raeburn 15042: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15043: foreach my $item (@contexts) {
1.43 raeburn 15044: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 15045: if ($cancreate{$item} ne 'any') {
15046: push(@{$changes{'cancreate'}},$item);
15047: }
15048: } else {
15049: if ($cancreate{$item} ne 'none') {
15050: push(@{$changes{'cancreate'}},$item);
15051: }
1.27 raeburn 15052: }
15053: }
15054: } else {
1.43 raeburn 15055: foreach my $item (@contexts) {
1.34 raeburn 15056: push(@{$changes{'cancreate'}},$item);
15057: }
1.27 raeburn 15058: }
1.34 raeburn 15059:
1.27 raeburn 15060: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15061: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15062: if (!grep(/^\Q$type\E$/,@username_rule)) {
15063: push(@{$changes{'username_rule'}},$type);
15064: }
15065: }
15066: foreach my $type (@username_rule) {
15067: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15068: push(@{$changes{'username_rule'}},$type);
15069: }
15070: }
15071: } else {
15072: push(@{$changes{'username_rule'}},@username_rule);
15073: }
15074:
1.32 raeburn 15075: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15076: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15077: if (!grep(/^\Q$type\E$/,@id_rule)) {
15078: push(@{$changes{'id_rule'}},$type);
15079: }
15080: }
15081: foreach my $type (@id_rule) {
15082: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15083: push(@{$changes{'id_rule'}},$type);
15084: }
15085: }
15086: } else {
15087: push(@{$changes{'id_rule'}},@id_rule);
15088: }
15089:
1.43 raeburn 15090: my @authen_contexts = ('author','course','domain');
1.28 raeburn 15091: my @authtypes = ('int','krb4','krb5','loc');
15092: my %authhash;
1.43 raeburn 15093: foreach my $item (@authen_contexts) {
1.28 raeburn 15094: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15095: foreach my $auth (@authtypes) {
15096: if (grep(/^\Q$auth\E$/,@authallowed)) {
15097: $authhash{$item}{$auth} = 1;
15098: } else {
15099: $authhash{$item}{$auth} = 0;
15100: }
15101: }
15102: }
15103: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15104: foreach my $item (@authen_contexts) {
1.28 raeburn 15105: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15106: foreach my $auth (@authtypes) {
15107: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15108: push(@{$changes{'authtypes'}},$item);
15109: last;
15110: }
15111: }
15112: }
15113: }
15114: } else {
1.43 raeburn 15115: foreach my $item (@authen_contexts) {
1.28 raeburn 15116: push(@{$changes{'authtypes'}},$item);
15117: }
15118: }
15119:
1.160.6.34 raeburn 15120: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15121: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15122: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15123: $save_usercreate{'id_rule'} = \@id_rule;
15124: $save_usercreate{'username_rule'} = \@username_rule,
15125: $save_usercreate{'authtypes'} = \%authhash;
15126:
1.27 raeburn 15127: my %usercreation_hash = (
1.160.6.34 raeburn 15128: usercreation => \%save_usercreate,
15129: );
1.27 raeburn 15130:
15131: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15132: $dom);
1.50 raeburn 15133:
1.160.6.34 raeburn 15134: if ($putresult eq 'ok') {
15135: if (keys(%changes) > 0) {
15136: $resulttext = &mt('Changes made:').'<ul>';
15137: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15138: my %lt = &usercreation_types();
15139: foreach my $type (@{$changes{'cancreate'}}) {
15140: my $chgtext = $lt{$type}.', ';
15141: if ($cancreate{$type} eq 'none') {
15142: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15143: } elsif ($cancreate{$type} eq 'any') {
15144: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15145: } elsif ($cancreate{$type} eq 'official') {
15146: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15147: } elsif ($cancreate{$type} eq 'unofficial') {
15148: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15149: }
15150: $resulttext .= '<li>'.$chgtext.'</li>';
15151: }
15152: }
15153: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15154: my ($rules,$ruleorder) =
15155: &Apache::lonnet::inst_userrules($dom,'username');
15156: my $chgtext = '<ul>';
15157: foreach my $type (@username_rule) {
15158: if (ref($rules->{$type}) eq 'HASH') {
15159: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15160: }
15161: }
15162: $chgtext .= '</ul>';
15163: if (@username_rule > 0) {
15164: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15165: } else {
15166: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15167: }
15168: }
15169: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15170: my ($idrules,$idruleorder) =
15171: &Apache::lonnet::inst_userrules($dom,'id');
15172: my $chgtext = '<ul>';
15173: foreach my $type (@id_rule) {
15174: if (ref($idrules->{$type}) eq 'HASH') {
15175: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15176: }
15177: }
15178: $chgtext .= '</ul>';
15179: if (@id_rule > 0) {
15180: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15181: } else {
15182: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15183: }
15184: }
15185: my %authname = &authtype_names();
15186: my %context_title = &context_names();
15187: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15188: my $chgtext = '<ul>';
15189: foreach my $type (@{$changes{'authtypes'}}) {
15190: my @allowed;
15191: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15192: foreach my $auth (@authtypes) {
15193: if ($authhash{$type}{$auth}) {
15194: push(@allowed,$authname{$auth});
15195: }
15196: }
15197: if (@allowed > 0) {
15198: $chgtext .= join(', ',@allowed).'</li>';
15199: } else {
15200: $chgtext .= &mt('none').'</li>';
15201: }
15202: }
15203: $chgtext .= '</ul>';
15204: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15205: $resulttext .= '</li>';
15206: }
15207: $resulttext .= '</ul>';
15208: } else {
15209: $resulttext = &mt('No changes made to user creation settings');
15210: }
15211: } else {
15212: $resulttext = '<span class="LC_error">'.
15213: &mt('An error occurred: [_1]',$putresult).'</span>';
15214: }
15215: if ($warningmsg ne '') {
15216: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15217: }
15218: return $resulttext;
15219: }
15220:
15221: sub modify_selfcreation {
1.160.6.93 raeburn 15222: my ($dom,$lastactref,%domconfig) = @_;
15223: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15224: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15225: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15226: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15227: if (ref($typesref) eq 'ARRAY') {
15228: @types = @{$typesref};
15229: }
15230: if (ref($usertypesref) eq 'HASH') {
15231: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 15232: }
1.160.6.93 raeburn 15233: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 15234: #
15235: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15236: #
15237: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15238: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15239: if ($key eq 'cancreate') {
15240: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15241: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15242: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 15243: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15244: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15245: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15246: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
15247: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 15248: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15249: } else {
15250: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15251: }
15252: }
15253: }
15254: } elsif ($key eq 'email_rule') {
15255: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15256: } else {
15257: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15258: }
15259: }
15260: }
15261: #
15262: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15263: #
15264: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15265: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15266: if ($key eq 'selfcreate') {
15267: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15268: } else {
15269: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15270: }
15271: }
15272: }
1.160.6.93 raeburn 15273: #
15274: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15275: #
15276: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15277: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15278: if ($key eq 'inststatusguest') {
15279: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15280: } else {
15281: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15282: }
15283: }
15284: }
1.160.6.34 raeburn 15285:
15286: my @contexts = ('selfcreate');
15287: @{$cancreate{'selfcreate'}} = ();
15288: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 15289: if (@types) {
15290: @{$cancreate{'statustocreate'}} = ();
15291: }
1.160.6.40 raeburn 15292: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 15293: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 15294: %{$cancreate{'emailverified'}} = ();
15295: %{$cancreate{'emailoptions'}} = ();
15296: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15297: my %selfcreatetypes = (
15298: sso => 'users authenticated by institutional single sign on',
15299: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 15300: email => 'users verified by e-mail',
1.50 raeburn 15301: );
1.160.6.34 raeburn 15302: #
15303: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15304: # is permitted.
15305: #
1.160.6.40 raeburn 15306:
1.160.6.93 raeburn 15307: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 15308:
1.160.6.93 raeburn 15309: my (@statuses,%email_rule);
1.160.6.35 raeburn 15310: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 15311: if ($item eq 'email') {
1.160.6.40 raeburn 15312: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 15313: if (@types) {
15314: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15315: foreach my $status (@poss_statuses) {
15316: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15317: push(@statuses,$status);
15318: }
15319: }
15320: $save_inststatus{'inststatusguest'} = \@statuses;
15321: } else {
15322: push(@statuses,'default');
15323: }
15324: if (@statuses) {
15325: my %curr_rule;
15326: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15327: foreach my $type (@statuses) {
15328: $curr_rule{$type} = $curr_usercreation{'email_rule'};
15329: }
15330: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15331: foreach my $type (@statuses) {
15332: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15333: }
15334: }
15335: push(@{$cancreate{'selfcreate'}},'email');
15336: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15337: my %curremaildom;
15338: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15339: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15340: }
15341: foreach my $type (@statuses) {
15342: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15343: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15344: }
15345: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15346: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15347: }
15348: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15349: #
15350: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15351: #
15352: my $chosen = $1;
15353: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15354: my $emaildom;
15355: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15356: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15357: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15358: if (ref($curremaildom{$type}) eq 'HASH') {
15359: if (exists($curremaildom{$type}{$chosen})) {
15360: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15361: push(@{$changes{'cancreate'}},'emaildomain');
15362: }
15363: } elsif ($emaildom ne '') {
15364: push(@{$changes{'cancreate'}},'emaildomain');
15365: }
15366: } elsif ($emaildom ne '') {
15367: push(@{$changes{'cancreate'}},'emaildomain');
15368: }
15369: }
15370: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15371: } elsif ($chosen eq 'custom') {
15372: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15373: $email_rule{$type} = [];
15374: if (ref($emailrules) eq 'HASH') {
15375: foreach my $rule (@possemail_rules) {
15376: if (exists($emailrules->{$rule})) {
15377: push(@{$email_rule{$type}},$rule);
15378: }
15379: }
15380: }
15381: if (@{$email_rule{$type}}) {
15382: $cancreate{'emailoptions'}{$type} = 'custom';
15383: if (ref($curr_rule{$type}) eq 'ARRAY') {
15384: if (@{$curr_rule{$type}} > 0) {
15385: foreach my $rule (@{$curr_rule{$type}}) {
15386: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15387: push(@{$changes{'email_rule'}},$type);
15388: }
15389: }
15390: }
15391: foreach my $type (@{$email_rule{$type}}) {
15392: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15393: push(@{$changes{'email_rule'}},$type);
15394: }
15395: }
15396: } else {
15397: push(@{$changes{'email_rule'}},$type);
15398: }
15399: }
15400: } else {
15401: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15402: }
15403: }
15404: }
15405: if (@types) {
15406: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15407: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15408: if (@changed) {
15409: push(@{$changes{'inststatus'}},'inststatusguest');
15410: }
15411: } else {
15412: push(@{$changes{'inststatus'}},'inststatusguest');
15413: }
15414: }
15415: } else {
15416: delete($env{'form.cancreate_email'});
15417: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15418: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15419: push(@{$changes{'inststatus'}},'inststatusguest');
15420: }
15421: }
15422: }
15423: } else {
15424: $save_inststatus{'inststatusguest'} = [];
15425: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15426: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15427: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 15428: }
15429: }
1.160.6.34 raeburn 15430: }
15431: } else {
15432: if ($env{'form.cancreate_'.$item}) {
15433: push(@{$cancreate{'selfcreate'}},$item);
15434: }
15435: }
15436: }
1.160.6.93 raeburn 15437: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 15438: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15439: #
1.160.6.35 raeburn 15440: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15441: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 15442: #
1.160.6.40 raeburn 15443:
1.160.6.48 raeburn 15444: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 15445: push(@contexts,'emailusername');
1.160.6.93 raeburn 15446: if (@statuses) {
15447: foreach my $type (@statuses) {
1.160.6.35 raeburn 15448: if (ref($infofields) eq 'ARRAY') {
15449: foreach my $field (@{$infofields}) {
15450: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15451: $cancreate{'emailusername'}{$type}{$field} = $1;
15452: }
15453: }
1.160.6.34 raeburn 15454: }
15455: }
15456: }
15457: #
15458: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 15459: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 15460: #
15461:
15462: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15463: @approvalnotify = sort(@approvalnotify);
15464: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15465: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15466: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15467: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15468: push(@{$changes{'cancreate'}},'notify');
15469: }
15470: } else {
15471: if ($cancreate{'notify'}{'approval'}) {
15472: push(@{$changes{'cancreate'}},'notify');
15473: }
15474: }
15475: } elsif ($cancreate{'notify'}{'approval'}) {
15476: push(@{$changes{'cancreate'}},'notify');
15477: }
15478:
15479: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15480: }
15481: #
1.160.6.40 raeburn 15482: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 15483: # institutional log-in.
15484: #
15485: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15486: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15487: ($domdefaults{'auth_def'} eq 'localauth'))) {
15488: $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.').' '.
15489: &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.');
15490: }
15491: }
15492: my @fields = ('lastname','firstname','middlename','generation',
15493: 'permanentemail','id');
1.160.6.44 raeburn 15494: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 15495: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15496: #
15497: # Where usernames may created for institutional log-in and/or institutional single sign on:
15498: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15499: # may self-create accounts
15500: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15501: # which the user may supply, if institutional data is unavailable.
15502: #
15503: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 15504: if (@types) {
15505: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15506: push(@contexts,'statustocreate');
15507: foreach my $type (@types) {
1.160.6.34 raeburn 15508: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15509: foreach my $field (@fields) {
15510: if (grep(/^\Q$field\E$/,@modifiable)) {
15511: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15512: } else {
15513: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15514: }
15515: }
15516: }
15517: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 15518: foreach my $type (@types) {
1.160.6.34 raeburn 15519: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15520: foreach my $field (@fields) {
15521: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15522: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15523: push(@{$changes{'selfcreate'}},$type);
15524: last;
15525: }
15526: }
15527: }
15528: }
15529: } else {
1.160.6.93 raeburn 15530: foreach my $type (@types) {
1.160.6.34 raeburn 15531: push(@{$changes{'selfcreate'}},$type);
15532: }
15533: }
15534: }
1.160.6.44 raeburn 15535: foreach my $field (@shibfields) {
15536: if ($env{'form.shibenv_'.$field} ne '') {
15537: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15538: }
15539: }
15540: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15541: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15542: foreach my $field (@shibfields) {
15543: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15544: push(@{$changes{'cancreate'}},'shibenv');
15545: }
15546: }
15547: } else {
15548: foreach my $field (@shibfields) {
15549: if ($env{'form.shibenv_'.$field}) {
15550: push(@{$changes{'cancreate'}},'shibenv');
15551: last;
15552: }
15553: }
15554: }
15555: }
1.160.6.34 raeburn 15556: }
15557: foreach my $item (@contexts) {
15558: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15559: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15560: if (ref($cancreate{$item}) eq 'ARRAY') {
15561: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15562: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15563: push(@{$changes{'cancreate'}},$item);
15564: }
15565: }
15566: }
15567: }
15568: if (ref($cancreate{$item}) eq 'ARRAY') {
15569: foreach my $type (@{$cancreate{$item}}) {
15570: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15571: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15572: push(@{$changes{'cancreate'}},$item);
15573: }
15574: }
15575: }
15576: }
15577: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15578: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 15579: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15580: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15581: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15582: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15583: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15584: push(@{$changes{'cancreate'}},$item);
15585: }
15586: }
15587: }
1.160.6.93 raeburn 15588: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15589: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15590: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15591: push(@{$changes{'cancreate'}},$item);
15592: }
1.160.6.34 raeburn 15593: }
15594: }
15595: }
1.160.6.93 raeburn 15596: foreach my $type (keys(%{$cancreate{$item}})) {
15597: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15598: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15599: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15600: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15601: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15602: push(@{$changes{'cancreate'}},$item);
15603: }
15604: }
15605: } else {
15606: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15607: push(@{$changes{'cancreate'}},$item);
15608: }
15609: }
15610: }
1.160.6.93 raeburn 15611: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15612: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15613: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15614: push(@{$changes{'cancreate'}},$item);
15615: }
1.160.6.34 raeburn 15616: }
15617: }
15618: }
15619: }
15620: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15621: if (ref($cancreate{$item}) eq 'ARRAY') {
15622: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15623: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15624: push(@{$changes{'cancreate'}},$item);
15625: }
15626: }
1.160.6.93 raeburn 15627: }
15628: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15629: if (ref($cancreate{$item}) eq 'HASH') {
15630: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15631: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 15632: }
15633: }
15634: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 15635: if (ref($cancreate{$item}) eq 'HASH') {
15636: foreach my $type (keys(%{$cancreate{$item}})) {
15637: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15638: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15639: if ($cancreate{$item}{$type}{$field}) {
15640: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15641: push(@{$changes{'cancreate'}},$item);
15642: }
15643: last;
15644: }
15645: }
15646: }
15647: }
1.160.6.34 raeburn 15648: }
15649: }
15650: }
15651: #
15652: # Populate %save_usercreate hash with updates to self-creation configuration.
15653: #
15654: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15655: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 15656: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 15657: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15658: if (ref($cancreate{'notify'}) eq 'HASH') {
15659: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15660: }
1.160.6.40 raeburn 15661: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15662: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15663: }
1.160.6.93 raeburn 15664: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15665: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15666: }
15667: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15668: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15669: }
15670: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15671: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15672: }
1.160.6.34 raeburn 15673: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15674: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15675: }
1.160.6.44 raeburn 15676: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15677: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15678: }
1.160.6.34 raeburn 15679: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 15680: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 15681:
15682: my %userconfig_hash = (
15683: usercreation => \%save_usercreate,
15684: usermodification => \%save_usermodify,
1.160.6.93 raeburn 15685: inststatus => \%save_inststatus,
1.160.6.34 raeburn 15686: );
1.160.6.93 raeburn 15687:
1.160.6.34 raeburn 15688: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15689: $dom);
15690: #
1.160.6.93 raeburn 15691: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 15692: #
1.27 raeburn 15693: if ($putresult eq 'ok') {
15694: if (keys(%changes) > 0) {
15695: $resulttext = &mt('Changes made:').'<ul>';
15696: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 15697: my %lt = &selfcreation_types();
1.34 raeburn 15698: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 15699: my $chgtext = '';
1.45 raeburn 15700: if ($type eq 'selfcreate') {
1.50 raeburn 15701: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 15702: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15703: } else {
1.160.6.34 raeburn 15704: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15705: '<ul>';
1.50 raeburn 15706: foreach my $case (@{$cancreate{$type}}) {
15707: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15708: }
15709: $chgtext .= '</ul>';
1.100 raeburn 15710: if (ref($cancreate{$type}) eq 'ARRAY') {
15711: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15712: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15713: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 15714: $chgtext .= '<span class="LC_warning">'.
15715: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15716: '</span><br />';
1.100 raeburn 15717: }
15718: }
15719: }
1.160.6.93 raeburn 15720: if (grep(/^email$/,@{$cancreate{$type}})) {
15721: if (!@statuses) {
15722: $chgtext .= '<span class="LC_warning">'.
15723: &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.").
15724: '</span><br />';
15725:
15726: }
15727: }
1.100 raeburn 15728: }
1.43 raeburn 15729: }
1.160.6.44 raeburn 15730: } elsif ($type eq 'shibenv') {
15731: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 15732: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 15733: } else {
15734: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15735: '<ul>';
15736: foreach my $field (@shibfields) {
15737: next if ($cancreate{$type}{$field} eq '');
15738: if ($field eq 'inststatus') {
15739: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15740: } else {
15741: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15742: }
15743: }
15744: $chgtext .= '</ul>';
1.160.6.93 raeburn 15745: }
1.93 raeburn 15746: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15747: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15748: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15749: if (@{$cancreate{'selfcreate'}} > 0) {
15750: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15751: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15752: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 15753: $chgtext .= '<br />'.
15754: '<span class="LC_warning">'.
15755: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15756: '</span>';
15757: }
1.160.6.93 raeburn 15758: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15759: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15760: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15761: } else {
15762: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15763: }
15764: $chgtext .= '<ul>';
15765: foreach my $case (@{$cancreate{$type}}) {
15766: if ($case eq 'default') {
15767: $chgtext .= '<li>'.$othertitle.'</li>';
15768: } else {
1.160.6.93 raeburn 15769: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15770: }
15771: }
1.100 raeburn 15772: $chgtext .= '</ul>';
15773: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 15774: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 15775: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15776: '</span>';
1.100 raeburn 15777: }
15778: }
15779: } else {
15780: if (@{$cancreate{$type}} == 0) {
15781: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15782: } else {
15783: $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 15784: }
15785: }
1.160.6.93 raeburn 15786: $chgtext .= '<br />';
1.93 raeburn 15787: }
1.160.6.40 raeburn 15788: } elsif ($type eq 'selfcreateprocessing') {
15789: my %choices = &Apache::lonlocal::texthash (
15790: automatic => 'Automatic approval',
15791: approval => 'Queued for approval',
15792: );
1.160.6.93 raeburn 15793: if (@types) {
15794: if (@statuses) {
15795: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15796: '<ul>';
15797: foreach my $status (@statuses) {
15798: if ($status eq 'default') {
15799: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15800: } else {
15801: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15802: }
15803: }
15804: $chgtext .= '</ul>';
15805: }
15806: } else {
15807: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15808: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15809: }
15810: } elsif ($type eq 'emailverified') {
15811: my %options = &Apache::lonlocal::texthash (
15812: all => 'Same as e-mail',
15813: first => 'Omit @domain',
15814: free => 'Free to choose',
15815: );
15816: if (@types) {
15817: if (@statuses) {
15818: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15819: '<ul>';
15820: foreach my $status (@statuses) {
15821: if ($status eq 'default') {
15822: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15823: } else {
15824: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15825: }
15826: }
15827: $chgtext .= '</ul>';
15828: }
1.160.6.40 raeburn 15829: } else {
1.160.6.93 raeburn 15830: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15831: $options{$cancreate{'emailverified'}{'default'}});
15832: }
15833: } elsif ($type eq 'emailoptions') {
15834: my %options = &Apache::lonlocal::texthash (
15835: any => 'Any e-mail',
15836: inst => 'Institutional only',
15837: noninst => 'Non-institutional only',
15838: custom => 'Custom restrictions',
15839: );
15840: if (@types) {
15841: if (@statuses) {
15842: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15843: '<ul>';
15844: foreach my $status (@statuses) {
15845: if ($type eq 'default') {
15846: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15847: } else {
15848: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15849: }
15850: }
15851: $chgtext .= '</ul>';
15852: }
15853: } else {
15854: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15855: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15856: } else {
15857: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15858: $options{$cancreate{'emailoptions'}{'default'}});
15859: }
15860: }
15861: } elsif ($type eq 'emaildomain') {
15862: my $output;
15863: if (@statuses) {
15864: foreach my $type (@statuses) {
15865: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15866: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15867: if ($type eq 'default') {
15868: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15869: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15870: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15871: } else {
15872: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15873: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15874: }
15875: } else {
15876: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15877: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15878: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15879: } else {
15880: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15881: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15882: }
15883: }
15884: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15885: if ($type eq 'default') {
15886: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15887: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15888: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15889: } else {
15890: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15891: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15892: }
15893: } else {
15894: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15895: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15896: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15897: } else {
15898: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15899: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15900: }
15901: }
15902: }
15903: }
15904: }
15905: }
15906: if ($output ne '') {
15907: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15908: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 15909: }
1.160.6.5 raeburn 15910: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 15911: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 15912: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15913: } else {
15914: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 15915: if ($captchas{$savecaptcha{$type}}) {
15916: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 15917: } else {
15918: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
15919: }
15920: }
15921: } elsif ($type eq 'recaptchakeys') {
15922: my ($privkey,$pubkey);
1.160.6.34 raeburn 15923: if (ref($savecaptcha{$type}) eq 'HASH') {
15924: $pubkey = $savecaptcha{$type}{'public'};
15925: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 15926: }
15927: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15928: if (!$pubkey) {
15929: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15930: } else {
15931: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15932: }
15933: if (!$privkey) {
15934: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15935: } else {
15936: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15937: }
15938: $chgtext .= '</ul>';
1.160.6.69 raeburn 15939: } elsif ($type eq 'recaptchaversion') {
15940: if ($savecaptcha{'captcha'} eq 'recaptcha') {
15941: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
15942: }
1.160.6.34 raeburn 15943: } elsif ($type eq 'emailusername') {
15944: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 15945: if (@statuses) {
15946: foreach my $type (@statuses) {
1.160.6.35 raeburn 15947: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15948: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 15949: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 15950: '<ul>';
15951: foreach my $field (@{$infofields}) {
15952: if ($cancreate{'emailusername'}{$type}{$field}) {
15953: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15954: }
15955: }
1.160.6.50 raeburn 15956: $chgtext .= '</ul>';
15957: } else {
1.160.6.93 raeburn 15958: $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.160.6.35 raeburn 15959: }
15960: } else {
1.160.6.93 raeburn 15961: $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.160.6.34 raeburn 15962: }
15963: }
15964: }
15965: }
15966: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 15967: my $numapprove = 0;
1.160.6.34 raeburn 15968: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15969: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15970: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 15971: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15972: $numapprove ++;
1.160.6.34 raeburn 15973: }
15974: }
1.43 raeburn 15975: }
1.160.6.93 raeburn 15976: unless ($numapprove) {
15977: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15978: }
1.34 raeburn 15979: }
1.160.6.34 raeburn 15980: if ($chgtext) {
15981: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15982: }
15983: }
15984: }
1.160.6.93 raeburn 15985: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15986: my ($emailrules,$emailruleorder) =
15987: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 15988: foreach my $type (@{$changes{'email_rule'}}) {
15989: if (ref($email_rule{$type}) eq 'ARRAY') {
15990: my $chgtext = '<ul>';
15991: foreach my $rule (@{$email_rule{$type}}) {
15992: if (ref($emailrules->{$rule}) eq 'HASH') {
15993: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15994: }
15995: }
15996: $chgtext .= '</ul>';
15997: my $typename;
15998: if (@types) {
15999: if ($type eq 'default') {
16000: $typename = $othertitle;
16001: } else {
16002: $typename = $usertypes{$type};
16003: }
16004: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16005: }
16006: if (@{$email_rule{$type}} > 0) {
16007: $resulttext .= '<li>'.
16008: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16009: $usertypes{$type}).
16010: $chgtext.
16011: '</li>';
16012: } else {
16013: $resulttext .= '<li>'.
16014: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16015: '</li>'.
16016: &mt('(Affiliation: [_1])',$typename);
16017: }
1.43 raeburn 16018: }
16019: }
1.160.6.93 raeburn 16020: }
16021: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16022: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16023: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16024: my $chgtext = '<ul>';
16025: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16026: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16027: }
16028: $chgtext .= '</ul>';
16029: $resulttext .= '<li>'.
16030: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16031: $chgtext.
16032: '</li>';
16033: } else {
16034: $resulttext .= '<li>'.
16035: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16036: '</li>';
16037: }
1.43 raeburn 16038: }
16039: }
1.160.6.34 raeburn 16040: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16041: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16042: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16043: foreach my $type (@{$changes{'selfcreate'}}) {
16044: my $typename = $type;
1.160.6.93 raeburn 16045: if (keys(%usertypes) > 0) {
16046: if ($usertypes{$type} ne '') {
16047: $typename = $usertypes{$type};
1.28 raeburn 16048: }
16049: }
1.160.6.34 raeburn 16050: my @modifiable;
16051: $resulttext .= '<li>'.
16052: &mt('Self-creation of account by users with status: [_1]',
16053: '<span class="LC_cusr_emph">'.$typename.'</span>').
16054: ' - '.&mt('modifiable fields (if institutional data blank): ');
16055: foreach my $field (@fields) {
16056: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16057: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16058: }
16059: }
16060: if (@modifiable > 0) {
16061: $resulttext .= join(', ',@modifiable);
1.43 raeburn 16062: } else {
1.160.6.34 raeburn 16063: $resulttext .= &mt('none');
1.43 raeburn 16064: }
1.160.6.34 raeburn 16065: $resulttext .= '</li>';
1.28 raeburn 16066: }
1.160.6.34 raeburn 16067: $resulttext .= '</ul></li>';
1.28 raeburn 16068: }
1.27 raeburn 16069: $resulttext .= '</ul>';
1.160.6.93 raeburn 16070: my $cachetime = 24*60*60;
16071: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16072: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16073: if (ref($lastactref) eq 'HASH') {
16074: $lastactref->{'domdefaults'} = 1;
16075: }
1.27 raeburn 16076: } else {
1.160.6.34 raeburn 16077: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 16078: }
16079: } else {
16080: $resulttext = '<span class="LC_error">'.
1.23 raeburn 16081: &mt('An error occurred: [_1]',$putresult).'</span>';
16082: }
1.43 raeburn 16083: if ($warningmsg ne '') {
16084: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16085: }
1.23 raeburn 16086: return $resulttext;
16087: }
16088:
1.160.6.5 raeburn 16089: sub process_captcha {
1.160.6.104 raeburn 16090: my ($container,$changes,$newsettings,$currsettings) = @_;
16091: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 16092: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16093: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16094: $newsettings->{'captcha'} = 'original';
16095: }
1.160.6.104 raeburn 16096: my %current;
16097: if (ref($currsettings) eq 'HASH') {
16098: %current = %{$currsettings};
16099: }
16100: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 16101: if ($container eq 'cancreate') {
16102: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16103: push(@{$changes->{'cancreate'}},'captcha');
16104: } elsif (!defined($changes->{'cancreate'})) {
16105: $changes->{'cancreate'} = ['captcha'];
16106: }
1.160.6.102 raeburn 16107: } elsif ($container eq 'passwords') {
16108: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16109: } else {
16110: $changes->{'captcha'} = 1;
16111: }
16112: }
1.160.6.69 raeburn 16113: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 16114: if ($newsettings->{'captcha'} eq 'recaptcha') {
16115: $newpub = $env{'form.'.$container.'_recaptchapub'};
16116: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 16117: $newpub =~ s/[^\w\-]//g;
16118: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 16119: $newsettings->{'recaptchakeys'} = {
16120: public => $newpub,
16121: private => $newpriv,
16122: };
1.160.6.69 raeburn 16123: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16124: $newversion =~ s/\D//g;
16125: if ($newversion ne '2') {
16126: $newversion = 1;
16127: }
16128: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 16129: }
1.160.6.104 raeburn 16130: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16131: $currpub = $current{'recaptchakeys'}{'public'};
16132: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 16133: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16134: $newsettings->{'recaptchakeys'} = {
16135: public => '',
16136: private => '',
16137: }
16138: }
1.160.6.5 raeburn 16139: }
1.160.6.104 raeburn 16140: if ($current{'captcha'} eq 'recaptcha') {
16141: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 16142: if ($currversion ne '2') {
16143: $currversion = 1;
16144: }
16145: }
16146: if ($currversion ne $newversion) {
16147: if ($container eq 'cancreate') {
16148: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16149: push(@{$changes->{'cancreate'}},'recaptchaversion');
16150: } elsif (!defined($changes->{'cancreate'})) {
16151: $changes->{'cancreate'} = ['recaptchaversion'];
16152: }
1.160.6.102 raeburn 16153: } elsif ($container eq 'passwords') {
16154: $changes->{'reset'} = 1;
1.160.6.69 raeburn 16155: } else {
16156: $changes->{'recaptchaversion'} = 1;
16157: }
16158: }
1.160.6.5 raeburn 16159: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16160: if ($container eq 'cancreate') {
16161: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16162: push(@{$changes->{'cancreate'}},'recaptchakeys');
16163: } elsif (!defined($changes->{'cancreate'})) {
16164: $changes->{'cancreate'} = ['recaptchakeys'];
16165: }
1.160.6.102 raeburn 16166: } elsif ($container eq 'passwords') {
16167: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16168: } else {
16169: $changes->{'recaptchakeys'} = 1;
16170: }
16171: }
16172: return;
16173: }
16174:
1.33 raeburn 16175: sub modify_usermodification {
16176: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16177: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16178: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16179: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 16180: if ($key eq 'selfcreate') {
16181: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16182: } else {
16183: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16184: }
1.33 raeburn 16185: }
16186: }
1.160.6.34 raeburn 16187: my @contexts = ('author','course');
1.33 raeburn 16188: my %context_title = (
16189: author => 'In author context',
16190: course => 'In course context',
16191: );
16192: my @fields = ('lastname','firstname','middlename','generation',
16193: 'permanentemail','id');
16194: my %roles = (
16195: author => ['ca','aa'],
16196: course => ['st','ep','ta','in','cr'],
16197: );
16198: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16199: foreach my $context (@contexts) {
16200: foreach my $role (@{$roles{$context}}) {
16201: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16202: foreach my $item (@fields) {
16203: if (grep(/^\Q$item\E$/,@modifiable)) {
16204: $modifyhash{$context}{$role}{$item} = 1;
16205: } else {
16206: $modifyhash{$context}{$role}{$item} = 0;
16207: }
16208: }
16209: }
16210: if (ref($curr_usermodification{$context}) eq 'HASH') {
16211: foreach my $role (@{$roles{$context}}) {
16212: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16213: foreach my $field (@fields) {
16214: if ($modifyhash{$context}{$role}{$field} ne
16215: $curr_usermodification{$context}{$role}{$field}) {
16216: push(@{$changes{$context}},$role);
16217: last;
16218: }
16219: }
16220: }
16221: }
16222: } else {
16223: foreach my $context (@contexts) {
16224: foreach my $role (@{$roles{$context}}) {
16225: push(@{$changes{$context}},$role);
16226: }
16227: }
16228: }
16229: }
16230: my %usermodification_hash = (
16231: usermodification => \%modifyhash,
16232: );
16233: my $putresult = &Apache::lonnet::put_dom('configuration',
16234: \%usermodification_hash,$dom);
16235: if ($putresult eq 'ok') {
16236: if (keys(%changes) > 0) {
16237: $resulttext = &mt('Changes made: ').'<ul>';
16238: foreach my $context (@contexts) {
16239: if (ref($changes{$context}) eq 'ARRAY') {
16240: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16241: if (ref($changes{$context}) eq 'ARRAY') {
16242: foreach my $role (@{$changes{$context}}) {
16243: my $rolename;
1.160.6.34 raeburn 16244: if ($role eq 'cr') {
16245: $rolename = &mt('Custom');
1.33 raeburn 16246: } else {
1.160.6.34 raeburn 16247: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16248: }
16249: my @modifiable;
1.160.6.34 raeburn 16250: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16251: foreach my $field (@fields) {
16252: if ($modifyhash{$context}{$role}{$field}) {
16253: push(@modifiable,$fieldtitles{$field});
16254: }
16255: }
16256: if (@modifiable > 0) {
16257: $resulttext .= join(', ',@modifiable);
16258: } else {
16259: $resulttext .= &mt('none');
16260: }
16261: $resulttext .= '</li>';
16262: }
16263: $resulttext .= '</ul></li>';
16264: }
16265: }
16266: }
16267: $resulttext .= '</ul>';
16268: } else {
16269: $resulttext = &mt('No changes made to user modification settings');
16270: }
16271: } else {
16272: $resulttext = '<span class="LC_error">'.
16273: &mt('An error occurred: [_1]',$putresult).'</span>';
16274: }
16275: return $resulttext;
16276: }
16277:
1.43 raeburn 16278: sub modify_defaults {
1.160.6.27 raeburn 16279: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16280: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 16281: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 16282: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 16283: 'portal_def');
1.43 raeburn 16284: my @authtypes = ('internal','krb4','krb5','localauth');
16285: foreach my $item (@items) {
16286: $newvalues{$item} = $env{'form.'.$item};
16287: if ($item eq 'auth_def') {
16288: if ($newvalues{$item} ne '') {
16289: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16290: push(@errors,$item);
16291: }
16292: }
16293: } elsif ($item eq 'lang_def') {
16294: if ($newvalues{$item} ne '') {
16295: if ($newvalues{$item} =~ /^(\w+)/) {
16296: my $langcode = $1;
1.103 raeburn 16297: if ($langcode ne 'x_chef') {
16298: if (code2language($langcode) eq '') {
16299: push(@errors,$item);
16300: }
1.43 raeburn 16301: }
16302: } else {
16303: push(@errors,$item);
16304: }
16305: }
1.54 raeburn 16306: } elsif ($item eq 'timezone_def') {
16307: if ($newvalues{$item} ne '') {
1.62 raeburn 16308: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16309: push(@errors,$item);
16310: }
16311: }
1.68 raeburn 16312: } elsif ($item eq 'datelocale_def') {
16313: if ($newvalues{$item} ne '') {
16314: my @datelocale_ids = DateTime::Locale->ids();
16315: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16316: push(@errors,$item);
16317: }
16318: }
1.141 raeburn 16319: } elsif ($item eq 'portal_def') {
16320: if ($newvalues{$item} ne '') {
16321: 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])\/?$/) {
16322: push(@errors,$item);
16323: }
16324: }
1.43 raeburn 16325: }
16326: if (grep(/^\Q$item\E$/,@errors)) {
16327: $newvalues{$item} = $domdefaults{$item};
16328: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16329: $changes{$item} = 1;
16330: }
1.72 raeburn 16331: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16332: }
1.160.6.98 raeburn 16333: my %staticdefaults = (
16334: 'intauth_cost' => 10,
16335: 'intauth_check' => 0,
16336: 'intauth_switch' => 0,
16337: );
16338: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16339: if (exists($domdefaults{$item})) {
16340: $newvalues{$item} = $domdefaults{$item};
16341: } else {
16342: $newvalues{$item} = $staticdefaults{$item};
16343: }
16344: }
1.43 raeburn 16345: my %defaults_hash = (
1.72 raeburn 16346: defaults => \%newvalues,
16347: );
1.43 raeburn 16348: my $title = &defaults_titles();
1.160.6.40 raeburn 16349:
16350: my $currinststatus;
16351: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16352: $currinststatus = $domconfig{'inststatus'};
16353: } else {
16354: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16355: $currinststatus = {
16356: inststatustypes => $usertypes,
16357: inststatusorder => $types,
16358: inststatusguest => [],
16359: };
16360: }
16361: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16362: my @allpos;
16363: my %alltypes;
1.160.6.93 raeburn 16364: my @inststatusguest;
16365: if (ref($currinststatus) eq 'HASH') {
16366: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16367: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16368: unless (grep(/^\Q$type\E$/,@todelete)) {
16369: push(@inststatusguest,$type);
16370: }
16371: }
16372: }
16373: }
16374: my ($currtitles,$currorder);
1.160.6.40 raeburn 16375: if (ref($currinststatus) eq 'HASH') {
16376: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16377: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16378: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16379: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16380: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16381: }
16382: }
16383: unless (grep(/^\Q$type\E$/,@todelete)) {
16384: my $position = $env{'form.inststatus_pos_'.$type};
16385: $position =~ s/\D+//g;
16386: $allpos[$position] = $type;
16387: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16388: $alltypes{$type} =~ s/`//g;
16389: }
16390: }
16391: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16392: $currtitles =~ s/,$//;
16393: }
16394: }
16395: if ($env{'form.addinststatus'}) {
16396: my $newtype = $env{'form.addinststatus'};
16397: $newtype =~ s/\W//g;
16398: unless (exists($alltypes{$newtype})) {
16399: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16400: $alltypes{$newtype} =~ s/`//g;
16401: my $position = $env{'form.addinststatus_pos'};
16402: $position =~ s/\D+//g;
16403: if ($position ne '') {
16404: $allpos[$position] = $newtype;
16405: }
16406: }
16407: }
1.160.6.93 raeburn 16408: my @orderedstatus;
1.160.6.40 raeburn 16409: foreach my $type (@allpos) {
16410: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16411: push(@orderedstatus,$type);
16412: }
16413: }
16414: foreach my $type (keys(%alltypes)) {
16415: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16416: delete($alltypes{$type});
16417: }
16418: }
16419: $defaults_hash{'inststatus'} = {
16420: inststatustypes => \%alltypes,
16421: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 16422: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 16423: };
16424: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16425: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16426: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16427: }
16428: }
16429: if ($currorder ne join(',',@orderedstatus)) {
16430: $changes{'inststatus'}{'inststatusorder'} = 1;
16431: }
16432: my $newtitles;
16433: foreach my $item (@orderedstatus) {
16434: $newtitles .= $alltypes{$item}.',';
16435: }
16436: $newtitles =~ s/,$//;
16437: if ($currtitles ne $newtitles) {
16438: $changes{'inststatus'}{'inststatustypes'} = 1;
16439: }
1.43 raeburn 16440: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16441: $dom);
16442: if ($putresult eq 'ok') {
16443: if (keys(%changes) > 0) {
16444: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 16445: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16446: 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";
16447: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 16448: if ($item eq 'inststatus') {
16449: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 16450: if (@orderedstatus) {
1.160.6.40 raeburn 16451: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16452: foreach my $type (@orderedstatus) {
16453: $resulttext .= $alltypes{$type}.', ';
16454: }
16455: $resulttext =~ s/, $//;
16456: $resulttext .= '</li>';
1.160.6.93 raeburn 16457: } else {
16458: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 16459: }
16460: }
16461: } else {
16462: my $value = $env{'form.'.$item};
16463: if ($value eq '') {
16464: $value = &mt('none');
16465: } elsif ($item eq 'auth_def') {
16466: my %authnames = &authtype_names();
16467: my %shortauth = (
16468: internal => 'int',
16469: krb4 => 'krb4',
16470: krb5 => 'krb5',
16471: localauth => 'loc',
16472: );
16473: $value = $authnames{$shortauth{$value}};
16474: }
16475: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16476: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 16477: }
16478: }
16479: $resulttext .= '</ul>';
16480: $mailmsgtext .= "\n";
16481: my $cachetime = 24*60*60;
1.72 raeburn 16482: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 16483: if (ref($lastactref) eq 'HASH') {
16484: $lastactref->{'domdefaults'} = 1;
16485: }
1.68 raeburn 16486: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 16487: my $notify = 1;
16488: if (ref($domconfig{'contacts'}) eq 'HASH') {
16489: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16490: $notify = 0;
16491: }
16492: }
16493: if ($notify) {
16494: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16495: "LON-CAPA Domain Settings Change - $dom",
16496: $mailmsgtext);
16497: }
1.54 raeburn 16498: }
1.43 raeburn 16499: } else {
1.54 raeburn 16500: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16501: }
16502: } else {
16503: $resulttext = '<span class="LC_error">'.
16504: &mt('An error occurred: [_1]',$putresult).'</span>';
16505: }
16506: if (@errors > 0) {
16507: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16508: foreach my $item (@errors) {
16509: $resulttext .= ' "'.$title->{$item}.'",';
16510: }
16511: $resulttext =~ s/,$//;
16512: }
16513: return $resulttext;
16514: }
16515:
1.46 raeburn 16516: sub modify_scantron {
1.160.6.24 raeburn 16517: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16518: my ($resulttext,%confhash,%changes,$errors);
16519: my $custom = 'custom.tab';
16520: my $default = 'default.tab';
16521: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 16522: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16523: &config_check($dom,$confname,$servadm);
16524: if ($env{'form.scantronformat.filename'} ne '') {
16525: my $error;
16526: if ($configuserok eq 'ok') {
16527: if ($switchserver) {
1.130 raeburn 16528: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16529: } else {
16530: if ($author_ok eq 'ok') {
16531: my ($result,$scantronurl) =
16532: &publishlogo($r,'upload','scantronformat',$dom,
16533: $confname,'scantron','','',$custom);
16534: if ($result eq 'ok') {
16535: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16536: $changes{'scantronformat'} = 1;
1.46 raeburn 16537: } else {
16538: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16539: }
16540: } else {
16541: $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);
16542: }
16543: }
16544: } else {
16545: $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);
16546: }
16547: if ($error) {
16548: &Apache::lonnet::logthis($error);
16549: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16550: }
16551: }
1.48 raeburn 16552: if (ref($domconfig{'scantron'}) eq 'HASH') {
16553: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16554: if ($env{'form.scantronformat_del'}) {
16555: $confhash{'scantron'}{'scantronformat'} = '';
16556: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 16557: } else {
16558: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
16559: }
16560: }
16561: }
16562: my @options = ('hdr','pad','rem');
16563: my @fields = &scantroncsv_fields();
16564: my %titles = &scantronconfig_titles();
16565: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
16566: my ($newdat,$currdat,%newcol,%currcol);
16567: if (grep(/^dat$/,@formats)) {
16568: $confhash{'scantron'}{config}{dat} = 1;
16569: $newdat = 1;
16570: } else {
16571: $newdat = 0;
16572: }
16573: if (grep(/^csv$/,@formats)) {
16574: my %bynum;
16575: foreach my $field (@fields) {
16576: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16577: my $posscol = $1;
16578: if (($posscol < 20) && (!$bynum{$posscol})) {
16579: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
16580: $bynum{$posscol} = $field;
16581: $newcol{$field} = $posscol;
16582: }
16583: }
16584: }
16585: if (keys(%newcol)) {
16586: foreach my $option (@options) {
16587: if ($env{'form.scantroncsv_'.$option}) {
16588: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16589: }
16590: }
16591: }
16592: }
16593: $currdat = 1;
16594: if (ref($domconfig{'scantron'}) eq 'HASH') {
16595: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
16596: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
16597: $currdat = 0;
16598: }
16599: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16600: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16601: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16602: }
16603: }
16604: }
16605: }
16606: if ($currdat != $newdat) {
16607: $changes{'config'} = 1;
16608: } else {
16609: foreach my $field (@fields) {
16610: if ($currcol{$field} ne '') {
16611: if ($currcol{$field} ne $newcol{$field}) {
16612: $changes{'config'} = 1;
16613: last;
16614: }
16615: } elsif ($newcol{$field} ne '') {
16616: $changes{'config'} = 1;
16617: last;
1.46 raeburn 16618: }
16619: }
16620: }
16621: if (keys(%confhash) > 0) {
16622: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16623: $dom);
16624: if ($putresult eq 'ok') {
16625: if (keys(%changes) > 0) {
1.48 raeburn 16626: if (ref($confhash{'scantron'}) eq 'HASH') {
16627: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 16628: if ($changes{'scantronformat'}) {
16629: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16630: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16631: } else {
16632: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16633: }
16634: }
16635: if ($changes{'config'}) {
16636: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16637: if ($confhash{'scantron'}{'config'}{'dat'}) {
16638: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16639: }
16640: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16641: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16642: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16643: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16644: foreach my $field (@fields) {
16645: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16646: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16647: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16648: }
16649: }
16650: $resulttext .= '</ul></li>';
16651: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16652: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16653: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16654: foreach my $option (@options) {
16655: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16656: $resulttext .= '<li>'.$titles{$option}.'</li>';
16657: }
16658: }
16659: $resulttext .= '</ul></li>';
16660: }
16661: }
16662: }
16663: }
16664: }
16665: } else {
16666: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16667: }
1.46 raeburn 16668: }
1.48 raeburn 16669: $resulttext .= '</ul>';
16670: } else {
1.130 raeburn 16671: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16672: }
16673: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 16674: if (ref($lastactref) eq 'HASH') {
16675: $lastactref->{'domainconfig'} = 1;
16676: }
1.46 raeburn 16677: } else {
1.160.6.97 raeburn 16678: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16679: }
16680: } else {
16681: $resulttext = '<span class="LC_error">'.
16682: &mt('An error occurred: [_1]',$putresult).'</span>';
16683: }
16684: } else {
1.160.6.97 raeburn 16685: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16686: }
16687: if ($errors) {
16688: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16689: $errors.'</ul>';
16690: }
16691: return $resulttext;
16692: }
16693:
1.48 raeburn 16694: sub modify_coursecategories {
1.160.6.43 raeburn 16695: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16696: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16697: $cathash);
1.48 raeburn 16698: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 16699: my @catitems = ('unauth','auth');
16700: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16701: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16702: $cathash = $domconfig{'coursecategories'}{'cats'};
16703: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16704: $changes{'togglecats'} = 1;
16705: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16706: }
16707: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16708: $changes{'categorize'} = 1;
16709: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16710: }
1.120 raeburn 16711: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16712: $changes{'togglecatscomm'} = 1;
16713: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16714: }
16715: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16716: $changes{'categorizecomm'} = 1;
16717: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16718: }
1.160.6.42 raeburn 16719: foreach my $item (@catitems) {
16720: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16721: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16722: $changes{$item} = 1;
16723: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16724: }
16725: }
16726: }
1.57 raeburn 16727: } else {
16728: $changes{'togglecats'} = 1;
16729: $changes{'categorize'} = 1;
1.124 raeburn 16730: $changes{'togglecatscomm'} = 1;
16731: $changes{'categorizecomm'} = 1;
1.87 raeburn 16732: $domconfig{'coursecategories'} = {
16733: togglecats => $env{'form.togglecats'},
16734: categorize => $env{'form.categorize'},
1.124 raeburn 16735: togglecatscomm => $env{'form.togglecatscomm'},
16736: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 16737: };
1.160.6.42 raeburn 16738: foreach my $item (@catitems) {
16739: if ($env{'form.coursecat_'.$item} ne 'std') {
16740: $changes{$item} = 1;
16741: }
16742: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16743: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16744: }
16745: }
1.57 raeburn 16746: }
16747: if (ref($cathash) eq 'HASH') {
16748: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16749: push (@deletecategory,'instcode::0');
16750: }
1.120 raeburn 16751: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16752: push(@deletecategory,'communities::0');
16753: }
1.48 raeburn 16754: }
1.57 raeburn 16755: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16756: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16757: if (@deletecategory > 0) {
16758: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16759: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16760: foreach my $item (@deletecategory) {
1.57 raeburn 16761: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16762: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16763: $deletions{$item} = 1;
1.57 raeburn 16764: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16765: }
16766: }
16767: }
1.57 raeburn 16768: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16769: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16770: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16771: $reorderings{$item} = 1;
1.57 raeburn 16772: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16773: }
16774: if ($env{'form.addcategory_name_'.$item} ne '') {
16775: my $newcat = $env{'form.addcategory_name_'.$item};
16776: my $newdepth = $depth+1;
16777: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16778: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16779: $adds{$newitem} = 1;
16780: }
16781: if ($env{'form.subcat_'.$item} ne '') {
16782: my $newcat = $env{'form.subcat_'.$item};
16783: my $newdepth = $depth+1;
16784: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16785: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16786: $adds{$newitem} = 1;
16787: }
16788: }
16789: }
16790: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16791: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16792: my $newitem = 'instcode::0';
1.57 raeburn 16793: if ($cathash->{$newitem} eq '') {
16794: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16795: $adds{$newitem} = 1;
16796: }
16797: } else {
16798: my $newitem = 'instcode::0';
1.57 raeburn 16799: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16800: $adds{$newitem} = 1;
16801: }
16802: }
1.120 raeburn 16803: if ($env{'form.communities'} eq '1') {
16804: if (ref($cathash) eq 'HASH') {
16805: my $newitem = 'communities::0';
16806: if ($cathash->{$newitem} eq '') {
16807: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16808: $adds{$newitem} = 1;
16809: }
16810: } else {
16811: my $newitem = 'communities::0';
16812: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16813: $adds{$newitem} = 1;
16814: }
16815: }
1.48 raeburn 16816: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16817: if (($env{'form.addcategory_name'} ne 'instcode') &&
16818: ($env{'form.addcategory_name'} ne 'communities')) {
16819: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16820: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16821: $adds{$newitem} = 1;
16822: }
1.48 raeburn 16823: }
1.57 raeburn 16824: my $putresult;
1.48 raeburn 16825: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16826: if (keys(%deletions) > 0) {
16827: foreach my $key (keys(%deletions)) {
16828: if ($predelallitems{$key} ne '') {
16829: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16830: }
16831: }
16832: }
16833: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16834: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16835: if (ref($chkcats[0]) eq 'ARRAY') {
16836: my $depth = 0;
16837: my $chg = 0;
16838: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16839: my $name = $chkcats[0][$i];
16840: my $item;
16841: if ($name eq '') {
16842: $chg ++;
16843: } else {
16844: $item = &escape($name).'::0';
16845: if ($chg) {
1.57 raeburn 16846: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16847: }
16848: $depth ++;
1.57 raeburn 16849: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16850: $depth --;
16851: }
16852: }
16853: }
1.57 raeburn 16854: }
16855: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16856: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16857: if ($putresult eq 'ok') {
1.57 raeburn 16858: my %title = (
1.120 raeburn 16859: togglecats => 'Show/Hide a course in catalog',
16860: categorize => 'Assign a category to a course',
16861: togglecatscomm => 'Show/Hide a community in catalog',
16862: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16863: );
16864: my %level = (
1.120 raeburn 16865: dom => 'set in Domain ("Modify Course/Community")',
16866: crs => 'set in Course ("Course Configuration")',
16867: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 16868: none => 'No catalog',
16869: std => 'Standard catalog',
16870: domonly => 'Domain-only catalog',
16871: codesrch => 'Code search form',
1.57 raeburn 16872: );
1.48 raeburn 16873: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16874: if ($changes{'togglecats'}) {
16875: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16876: }
16877: if ($changes{'categorize'}) {
16878: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16879: }
1.120 raeburn 16880: if ($changes{'togglecatscomm'}) {
16881: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16882: }
16883: if ($changes{'categorizecomm'}) {
16884: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16885: }
1.160.6.42 raeburn 16886: if ($changes{'unauth'}) {
16887: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16888: }
16889: if ($changes{'auth'}) {
16890: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16891: }
1.57 raeburn 16892: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16893: my $cathash;
16894: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16895: $cathash = $domconfig{'coursecategories'}{'cats'};
16896: } else {
16897: $cathash = {};
16898: }
16899: my (@cats,@trails,%allitems);
16900: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16901: if (keys(%deletions) > 0) {
16902: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16903: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16904: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16905: }
16906: $resulttext .= '</ul></li>';
16907: }
16908: if (keys(%reorderings) > 0) {
16909: my %sort_by_trail;
16910: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16911: foreach my $key (keys(%reorderings)) {
16912: if ($allitems{$key} ne '') {
16913: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16914: }
1.48 raeburn 16915: }
1.57 raeburn 16916: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16917: $resulttext .= '<li>'.$trails[$trail].'</li>';
16918: }
16919: $resulttext .= '</ul></li>';
1.48 raeburn 16920: }
1.57 raeburn 16921: if (keys(%adds) > 0) {
16922: my %sort_by_trail;
16923: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16924: foreach my $key (keys(%adds)) {
16925: if ($allitems{$key} ne '') {
16926: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16927: }
16928: }
16929: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16930: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16931: }
1.57 raeburn 16932: $resulttext .= '</ul></li>';
1.48 raeburn 16933: }
1.160.6.92 raeburn 16934: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
16935: if (ref($lastactref) eq 'HASH') {
16936: $lastactref->{'cats'} = 1;
16937: }
1.48 raeburn 16938: }
16939: $resulttext .= '</ul>';
1.160.6.43 raeburn 16940: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 16941: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16942: if ($changes{'auth'}) {
16943: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16944: }
16945: if ($changes{'unauth'}) {
16946: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16947: }
16948: my $cachetime = 24*60*60;
16949: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 16950: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 16951: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 16952: }
16953: }
1.48 raeburn 16954: } else {
16955: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16956: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16957: }
16958: } else {
1.120 raeburn 16959: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16960: }
16961: return $resulttext;
16962: }
16963:
1.69 raeburn 16964: sub modify_serverstatuses {
16965: my ($dom,%domconfig) = @_;
16966: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16967: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16968: %currserverstatus = %{$domconfig{'serverstatuses'}};
16969: }
16970: my @pages = &serverstatus_pages();
16971: foreach my $type (@pages) {
16972: $newserverstatus{$type}{'namedusers'} = '';
16973: $newserverstatus{$type}{'machines'} = '';
16974: if (defined($env{'form.'.$type.'_namedusers'})) {
16975: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16976: my @okusers;
16977: foreach my $user (@users) {
16978: my ($uname,$udom) = split(/:/,$user);
16979: if (($udom =~ /^$match_domain$/) &&
16980: (&Apache::lonnet::domain($udom)) &&
16981: ($uname =~ /^$match_username$/)) {
16982: if (!grep(/^\Q$user\E/,@okusers)) {
16983: push(@okusers,$user);
16984: }
16985: }
16986: }
16987: if (@okusers > 0) {
16988: @okusers = sort(@okusers);
16989: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16990: }
16991: }
16992: if (defined($env{'form.'.$type.'_machines'})) {
16993: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16994: my @okmachines;
16995: foreach my $ip (@machines) {
16996: my @parts = split(/\./,$ip);
16997: next if (@parts < 4);
16998: my $badip = 0;
16999: for (my $i=0; $i<4; $i++) {
17000: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17001: $badip = 1;
17002: last;
17003: }
17004: }
17005: if (!$badip) {
17006: push(@okmachines,$ip);
17007: }
17008: }
17009: @okmachines = sort(@okmachines);
17010: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17011: }
17012: }
17013: my %serverstatushash = (
17014: serverstatuses => \%newserverstatus,
17015: );
17016: foreach my $type (@pages) {
1.83 raeburn 17017: foreach my $setting ('namedusers','machines') {
1.84 raeburn 17018: my (@current,@new);
1.83 raeburn 17019: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 17020: if ($currserverstatus{$type}{$setting} ne '') {
17021: @current = split(/,/,$currserverstatus{$type}{$setting});
17022: }
17023: }
17024: if ($newserverstatus{$type}{$setting} ne '') {
17025: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 17026: }
17027: if (@current > 0) {
17028: if (@new > 0) {
17029: foreach my $item (@current) {
17030: if (!grep(/^\Q$item\E$/,@new)) {
17031: $changes{$type}{$setting} = 1;
1.82 raeburn 17032: last;
17033: }
17034: }
1.84 raeburn 17035: foreach my $item (@new) {
17036: if (!grep(/^\Q$item\E$/,@current)) {
17037: $changes{$type}{$setting} = 1;
17038: last;
1.82 raeburn 17039: }
17040: }
17041: } else {
1.83 raeburn 17042: $changes{$type}{$setting} = 1;
1.69 raeburn 17043: }
1.83 raeburn 17044: } elsif (@new > 0) {
17045: $changes{$type}{$setting} = 1;
1.69 raeburn 17046: }
17047: }
17048: }
17049: if (keys(%changes) > 0) {
1.81 raeburn 17050: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 17051: my $putresult = &Apache::lonnet::put_dom('configuration',
17052: \%serverstatushash,$dom);
17053: if ($putresult eq 'ok') {
17054: $resulttext .= &mt('Changes made:').'<ul>';
17055: foreach my $type (@pages) {
1.84 raeburn 17056: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 17057: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 17058: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 17059: if ($newserverstatus{$type}{'namedusers'} eq '') {
17060: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17061: } else {
17062: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17063: }
1.84 raeburn 17064: }
17065: if ($changes{$type}{'machines'}) {
1.69 raeburn 17066: if ($newserverstatus{$type}{'machines'} eq '') {
17067: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17068: } else {
17069: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
17070: }
17071:
17072: }
17073: $resulttext .= '</ul></li>';
17074: }
17075: }
17076: $resulttext .= '</ul>';
17077: } else {
17078: $resulttext = '<span class="LC_error">'.
17079: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17080:
17081: }
17082: } else {
17083: $resulttext = &mt('No changes made to access to server status pages');
17084: }
17085: return $resulttext;
17086: }
17087:
1.118 jms 17088: sub modify_helpsettings {
1.160.6.77 raeburn 17089: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 17090: my ($resulttext,$errors,%changes,%helphash);
17091: my %defaultchecked = ('submitbugs' => 'on');
17092: my @offon = ('off','on');
1.118 jms 17093: my @toggles = ('submitbugs');
1.160.6.77 raeburn 17094: my %current = ('submitbugs' => '',
17095: 'adhoc' => {},
17096: );
1.118 jms 17097: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 17098: %current = %{$domconfig{'helpsettings'}};
17099: }
1.160.6.77 raeburn 17100: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 17101: foreach my $item (@toggles) {
17102: if ($defaultchecked{$item} eq 'on') {
17103: if ($current{$item} eq '') {
17104: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 17105: $changes{$item} = 1;
17106: }
1.160.6.73 raeburn 17107: } elsif ($current{$item} ne $env{'form.'.$item}) {
17108: $changes{$item} = 1;
17109: }
17110: } elsif ($defaultchecked{$item} eq 'off') {
17111: if ($current{$item} eq '') {
17112: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 17113: $changes{$item} = 1;
17114: }
1.160.6.73 raeburn 17115: } elsif ($current{$item} ne $env{'form.'.$item}) {
17116: $changes{$item} = 1;
17117: }
17118: }
17119: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17120: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17121: }
17122: }
1.160.6.77 raeburn 17123: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 17124: my $confname = $dom.'-domainconfig';
17125: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 17126: my (@allpos,%newsettings,%changedprivs,$newrole);
17127: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 17128: my @accesstypes = ('all','dh','da','none','status','inc','exc');
17129: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 17130: my %lt = &Apache::lonlocal::texthash(
17131: s => 'system',
17132: d => 'domain',
17133: order => 'Display order',
17134: access => 'Role usage',
1.160.6.79 raeburn 17135: all => 'All with domain helpdesk or helpdesk assistant role',
17136: dh => 'All with domain helpdesk role',
17137: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 17138: none => 'None',
17139: status => 'Determined based on institutional status',
17140: inc => 'Include all, but exclude specific personnel',
17141: exc => 'Exclude all, but include specific personnel',
17142: );
17143: for (my $num=0; $num<=$maxnum; $num++) {
17144: my ($prefix,$identifier,$rolename,%curr);
17145: if ($num == $maxnum) {
17146: next unless ($env{'form.newcusthelp'} == $maxnum);
17147: $identifier = 'custhelp'.$num;
17148: $prefix = 'helproles_'.$num;
17149: $rolename = $env{'form.custhelpname'.$num};
17150: $rolename=~s/[^A-Za-z0-9]//gs;
17151: next if ($rolename eq '');
17152: next if (exists($existing{'rolesdef_'.$rolename}));
17153: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17154: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17155: $newprivs{'c'},$confname,$dom);
17156: if ($result ne 'ok') {
17157: $errors .= '<li><span class="LC_error">'.
17158: &mt('An error occurred storing the new custom role: [_1]',
17159: $result).'</span></li>';
17160: next;
17161: } else {
17162: $changedprivs{$rolename} = \%newprivs;
17163: $newrole = $rolename;
17164: }
17165: } else {
17166: $prefix = 'helproles_'.$num;
17167: $rolename = $env{'form.'.$prefix};
17168: next if ($rolename eq '');
17169: next unless (exists($existing{'rolesdef_'.$rolename}));
17170: $identifier = 'custhelp'.$num;
17171: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17172: my %currprivs;
17173: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
17174: split(/\_/,$existing{'rolesdef_'.$rolename});
17175: foreach my $level ('c','d','s') {
17176: if ($newprivs{$level} ne $currprivs{$level}) {
17177: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17178: $newprivs{'c'},$confname,$dom);
17179: if ($result ne 'ok') {
17180: $errors .= '<li><span class="LC_error">'.
17181: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17182: $rolename,$result).'</span></li>';
17183: } else {
17184: $changedprivs{$rolename} = \%newprivs;
17185: }
17186: last;
17187: }
17188: }
17189: if (ref($current{'adhoc'}) eq 'HASH') {
17190: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17191: %curr = %{$current{'adhoc'}{$rolename}};
17192: }
17193: }
17194: }
17195: my $newpos = $env{'form.'.$prefix.'_pos'};
17196: $newpos =~ s/\D+//g;
17197: $allpos[$newpos] = $rolename;
17198: my $newdesc = $env{'form.'.$prefix.'_desc'};
17199: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17200: if ($curr{'desc'}) {
17201: if ($curr{'desc'} ne $newdesc) {
17202: $changes{'customrole'}{$rolename}{'desc'} = 1;
17203: $newsettings{$rolename}{'desc'} = $newdesc;
17204: }
17205: } elsif ($newdesc ne '') {
17206: $changes{'customrole'}{$rolename}{'desc'} = 1;
17207: $newsettings{$rolename}{'desc'} = $newdesc;
17208: }
17209: my $access = $env{'form.'.$prefix.'_access'};
17210: if (grep(/^\Q$access\E$/,@accesstypes)) {
17211: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17212: if ($access eq 'status') {
17213: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17214: if (scalar(@statuses) == 0) {
17215: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
17216: } else {
17217: my (@shownstatus,$numtypes);
17218: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17219: if (ref($types) eq 'ARRAY') {
17220: $numtypes = scalar(@{$types});
17221: foreach my $type (sort(@statuses)) {
17222: if ($type eq 'default') {
17223: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17224: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17225: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17226: push(@shownstatus,$usertypes->{$type});
17227: }
1.160.6.73 raeburn 17228: }
17229: }
1.160.6.77 raeburn 17230: if (grep(/^default$/,@statuses)) {
17231: push(@shownstatus,$othertitle);
17232: }
17233: if (scalar(@shownstatus) == 1+$numtypes) {
17234: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17235: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17236: } else {
17237: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17238: if (ref($curr{'status'}) eq 'ARRAY') {
17239: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17240: if (@diffs) {
17241: $changes{'customrole'}{$rolename}{$access} = 1;
17242: }
17243: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17244: $changes{'customrole'}{$rolename}{$access} = 1;
17245: }
17246: }
17247: }
17248: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17249: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17250: my @newspecstaff;
17251: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17252: foreach my $person (sort(@personnel)) {
17253: if ($domhelpdesk{$person}) {
17254: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17255: }
17256: }
17257: if (ref($curr{$access}) eq 'ARRAY') {
17258: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17259: if (@diffs) {
17260: $changes{'customrole'}{$rolename}{$access} = 1;
17261: }
17262: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17263: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 17264: }
1.160.6.77 raeburn 17265: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17266: my ($uname,$udom) = split(/:/,$person);
17267: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17268: }
17269: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 17270: }
1.160.6.77 raeburn 17271: } else {
17272: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17273: }
17274: unless ($curr{'access'} eq $access) {
17275: $changes{'customrole'}{$rolename}{'access'} = 1;
17276: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 17277: }
17278: }
1.160.6.77 raeburn 17279: if (@allpos > 0) {
17280: my $idx = 0;
17281: foreach my $rolename (@allpos) {
17282: if ($rolename ne '') {
17283: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17284: if (ref($current{'adhoc'}) eq 'HASH') {
17285: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17286: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17287: $changes{'customrole'}{$rolename}{'order'} = 1;
17288: $newsettings{$rolename}{'order'} = $idx+1;
17289: }
17290: }
1.160.6.73 raeburn 17291: }
1.160.6.77 raeburn 17292: $idx ++;
1.122 jms 17293: }
17294: }
1.118 jms 17295: }
1.123 jms 17296: my $putresult;
17297: if (keys(%changes) > 0) {
1.160.6.5 raeburn 17298: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
17299: if ($putresult eq 'ok') {
1.160.6.77 raeburn 17300: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17301: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17302: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17303: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17304: }
17305: }
17306: my $cachetime = 24*60*60;
17307: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17308: if (ref($lastactref) eq 'HASH') {
17309: $lastactref->{'domdefaults'} = 1;
17310: }
17311: } else {
17312: $errors .= '<li><span class="LC_error">'.
17313: &mt('An error occurred storing the settings: [_1]',
17314: $putresult).'</span></li>';
17315: }
17316: }
17317: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17318: $resulttext = &mt('Changes made:').'<ul>';
17319: my (%shownprivs,@levelorder);
17320: @levelorder = ('c','d','s');
17321: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 17322: foreach my $item (sort(keys(%changes))) {
17323: if ($item eq 'submitbugs') {
17324: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17325: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17326: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 17327: } elsif ($item eq 'customrole') {
17328: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 17329: my @keyorder = ('order','desc','access','status','exc','inc');
17330: my %keytext = &Apache::lonlocal::texthash(
17331: order => 'Order',
17332: desc => 'Role description',
17333: access => 'Role usage',
1.160.6.83 raeburn 17334: status => 'Allowed institutional types',
1.160.6.77 raeburn 17335: exc => 'Allowed personnel',
17336: inc => 'Disallowed personnel',
17337: );
1.160.6.73 raeburn 17338: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 17339: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17340: if ($role eq $newrole) {
17341: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17342: $role).'<ul>';
17343: } else {
17344: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17345: $role).'<ul>';
17346: }
17347: foreach my $key (@keyorder) {
17348: if ($changes{'customrole'}{$role}{$key}) {
17349: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17350: $keytext{$key},$newsettings{$role}{$key}).
17351: '</li>';
17352: }
17353: }
17354: if (ref($changedprivs{$role}) eq 'HASH') {
17355: $shownprivs{$role} = 1;
17356: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17357: foreach my $level (@levelorder) {
17358: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17359: next if ($item eq '');
17360: my ($priv) = split(/\&/,$item,2);
17361: if (&Apache::lonnet::plaintext($priv)) {
17362: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17363: unless ($level eq 'c') {
17364: $resulttext .= ' ('.$lt{$level}.')';
17365: }
17366: $resulttext .= '</li>';
17367: }
17368: }
17369: }
17370: $resulttext .= '</ul>';
17371: }
17372: $resulttext .= '</ul></li>';
17373: }
1.160.6.73 raeburn 17374: }
17375: }
1.160.6.5 raeburn 17376: }
17377: }
17378: }
1.160.6.77 raeburn 17379: if (keys(%changedprivs)) {
17380: foreach my $role (sort(keys(%changedprivs))) {
17381: unless ($shownprivs{$role}) {
17382: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17383: $role).'<ul>'.
17384: '<li>'.&mt('Privileges set to :').'<ul>';
17385: foreach my $level (@levelorder) {
17386: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17387: next if ($item eq '');
17388: my ($priv) = split(/\&/,$item,2);
17389: if (&Apache::lonnet::plaintext($priv)) {
17390: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17391: unless ($level eq 'c') {
17392: $resulttext .= ' ('.$lt{$level}.')';
17393: }
17394: $resulttext .= '</li>';
17395: }
17396: }
17397: }
17398: $resulttext .= '</ul></li></ul></li>';
17399: }
17400: }
17401: }
17402: $resulttext .= '</ul>';
17403: } else {
17404: $resulttext = &mt('No changes made to help settings');
1.118 jms 17405: }
17406: if ($errors) {
1.160.6.5 raeburn 17407: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 17408: $errors.'</ul>';
1.118 jms 17409: }
17410: return $resulttext;
17411: }
17412:
1.121 raeburn 17413: sub modify_coursedefaults {
1.160.6.27 raeburn 17414: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17415: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 17416: my %defaultchecked = (
17417: 'uselcmath' => 'on',
1.160.6.115 raeburn 17418: 'usejsme' => 'on',
17419: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 17420:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 17421: );
1.160.6.118.2 4(raebur 17422:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 17423: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 17424: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
17425: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 17426: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 17427: my %staticdefaults = (
17428: anonsurvey_threshold => 10,
17429: uploadquota => 500,
1.160.6.57 raeburn 17430: postsubmit => 60,
1.160.6.70 raeburn 17431: mysqltables => 172800,
1.160.6.21 raeburn 17432: );
1.160.6.90 raeburn 17433: my %texoptions = (
17434: MathJax => 'MathJax',
17435: mimetex => &mt('Convert to Images'),
17436: tth => &mt('TeX to HTML'),
17437: );
1.121 raeburn 17438: $defaultshash{'coursedefaults'} = {};
17439:
17440: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17441: if ($domconfig{'coursedefaults'} eq '') {
17442: $domconfig{'coursedefaults'} = {};
17443: }
17444: }
17445:
17446: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17447: foreach my $item (@toggles) {
17448: if ($defaultchecked{$item} eq 'on') {
17449: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17450: ($env{'form.'.$item} eq '0')) {
17451: $changes{$item} = 1;
1.160.6.16 raeburn 17452: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17453: $changes{$item} = 1;
17454: }
17455: } elsif ($defaultchecked{$item} eq 'off') {
17456: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17457: ($env{'form.'.$item} eq '1')) {
17458: $changes{$item} = 1;
17459: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17460: $changes{$item} = 1;
17461: }
17462: }
17463: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17464: }
1.160.6.21 raeburn 17465: foreach my $item (@numbers) {
17466: my ($currdef,$newdef);
1.160.6.26 raeburn 17467: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 17468: if ($item eq 'anonsurvey_threshold') {
17469: $currdef = $domconfig{'coursedefaults'}{$item};
17470: $newdef =~ s/\D//g;
17471: if ($newdef eq '' || $newdef < 1) {
17472: $newdef = 1;
17473: }
17474: $defaultshash{'coursedefaults'}{$item} = $newdef;
17475: } else {
1.160.6.70 raeburn 17476: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17477: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17478: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 17479: }
17480: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 17481: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 17482: }
17483: if ($currdef ne $newdef) {
17484: if ($item eq 'anonsurvey_threshold') {
17485: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17486: $changes{$item} = 1;
17487: }
1.160.6.70 raeburn 17488: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
17489: my $setting = $1;
17490: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17491: $changes{$setting} = 1;
1.160.6.21 raeburn 17492: }
17493: }
1.139 raeburn 17494: }
17495: }
1.160.6.90 raeburn 17496: my $texengine;
17497: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17498: $texengine = $env{'form.texengine'};
17499: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17500: if ($currdef eq '') {
17501: unless ($texengine eq $Apache::lonnet::deftex) {
17502: $changes{'texengine'} = 1;
17503: }
17504: } elsif ($currdef ne $texengine) {
17505: $changes{'texengine'} = 1;
17506: }
17507: }
17508: if ($texengine ne '') {
17509: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17510: }
1.160.6.64 raeburn 17511: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17512: my @currclonecode;
17513: if (ref($currclone) eq 'HASH') {
17514: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17515: @currclonecode = @{$currclone->{'instcode'}};
17516: }
17517: }
17518: my $newclone;
17519: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
17520: $newclone = $env{'form.canclone'};
17521: }
17522: if ($newclone eq 'instcode') {
17523: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17524: my (%codedefaults,@code_order,@clonecode);
17525: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17526: \@code_order);
17527: foreach my $item (@code_order) {
17528: if (grep(/^\Q$item\E$/,@newcodes)) {
17529: push(@clonecode,$item);
17530: }
17531: }
17532: if (@clonecode) {
17533: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17534: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17535: if (@diffs) {
17536: $changes{'canclone'} = 1;
17537: }
17538: } else {
17539: $newclone eq '';
17540: }
17541: } elsif ($newclone ne '') {
17542: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17543: }
17544: if ($newclone ne $currclone) {
17545: $changes{'canclone'} = 1;
17546: }
1.160.6.57 raeburn 17547: my %credits;
17548: foreach my $type (@types) {
17549: unless ($type eq 'community') {
17550: $credits{$type} = $env{'form.'.$type.'_credits'};
17551: $credits{$type} =~ s/[^\d.]+//g;
17552: }
17553: }
17554: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17555: ($env{'form.coursecredits'} eq '1')) {
17556: $changes{'coursecredits'} = 1;
17557: foreach my $type (keys(%credits)) {
17558: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17559: }
17560: } else {
17561: if ($env{'form.coursecredits'} eq '1') {
17562: foreach my $type (@types) {
17563: unless ($type eq 'community') {
17564: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
17565: $changes{'coursecredits'} = 1;
17566: }
17567: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17568: }
17569: }
17570: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17571: foreach my $type (@types) {
17572: unless ($type eq 'community') {
17573: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17574: $changes{'coursecredits'} = 1;
17575: last;
17576: }
17577: }
17578: }
17579: }
17580: }
17581: if ($env{'form.postsubmit'} eq '1') {
17582: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17583: my %currtimeout;
17584: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17585: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17586: $changes{'postsubmit'} = 1;
17587: }
17588: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17589: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17590: }
17591: } else {
17592: $changes{'postsubmit'} = 1;
17593: }
17594: foreach my $type (@types) {
17595: my $timeout = $env{'form.'.$type.'_timeout'};
17596: $timeout =~ s/\D//g;
17597: if ($timeout == $staticdefaults{'postsubmit'}) {
17598: $timeout = '';
17599: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17600: $timeout = '0';
17601: }
17602: unless ($timeout eq '') {
17603: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17604: }
17605: if (exists($currtimeout{$type})) {
17606: if ($timeout ne $currtimeout{$type}) {
17607: $changes{'postsubmit'} = 1;
17608: }
17609: } elsif ($timeout ne '') {
17610: $changes{'postsubmit'} = 1;
17611: }
17612: }
17613: } else {
17614: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17615: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17616: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17617: $changes{'postsubmit'} = 1;
17618: }
17619: } else {
17620: $changes{'postsubmit'} = 1;
17621: }
1.160.6.16 raeburn 17622: }
1.121 raeburn 17623: }
17624: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17625: $dom);
17626: if ($putresult eq 'ok') {
17627: if (keys(%changes) > 0) {
1.160.6.27 raeburn 17628: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 17629: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 17630: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 17631: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 4(raebur 17632:2): ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
17633:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 17634: if ($changes{$item}) {
17635: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17636: }
1.160.6.16 raeburn 17637: }
17638: if ($changes{'coursecredits'}) {
17639: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 17640: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17641: $domdefaults{$type.'credits'} =
17642: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17643: }
17644: }
17645: }
17646: if ($changes{'postsubmit'}) {
17647: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17648: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17649: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17650: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17651: $domdefaults{$type.'postsubtimeout'} =
17652: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17653: }
17654: }
1.160.6.16 raeburn 17655: }
17656: }
1.160.6.21 raeburn 17657: if ($changes{'uploadquota'}) {
17658: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17659: foreach my $type (@types) {
17660: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17661: }
17662: }
17663: }
1.160.6.64 raeburn 17664: if ($changes{'canclone'}) {
17665: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17666: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17667: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17668: if (@clonecodes) {
17669: $domdefaults{'canclone'} = join('+',@clonecodes);
17670: }
17671: }
17672: } else {
17673: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17674: }
17675: }
1.121 raeburn 17676: my $cachetime = 24*60*60;
17677: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17678: if (ref($lastactref) eq 'HASH') {
17679: $lastactref->{'domdefaults'} = 1;
17680: }
1.121 raeburn 17681: }
17682: $resulttext = &mt('Changes made:').'<ul>';
17683: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 17684: if ($item eq 'uselcmath') {
1.121 raeburn 17685: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 17686: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 17687: } else {
1.160.6.57 raeburn 17688: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17689: }
17690: } elsif ($item eq 'usejsme') {
17691: if ($env{'form.'.$item} eq '1') {
17692: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17693: } else {
17694: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 17695: }
1.160.6.115 raeburn 17696: } elsif ($item eq 'inline_chem') {
17697: if ($env{'form.'.$item} eq '1') {
17698: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17699: } else {
17700: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17701: }
1.160.6.90 raeburn 17702: } elsif ($item eq 'texengine') {
17703: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17704: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17705: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17706: }
1.139 raeburn 17707: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 17708: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 17709: } elsif ($item eq 'uploadquota') {
17710: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17711: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17712: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17713: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 17714: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17715:
1.160.6.21 raeburn 17716: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17717: '</ul>'.
17718: '</li>';
17719: } else {
17720: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17721: }
1.160.6.70 raeburn 17722: } elsif ($item eq 'mysqltables') {
17723: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17724: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17725: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17726: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17727: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17728: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17729: '</ul>'.
17730: '</li>';
17731: } else {
17732: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17733: }
1.160.6.57 raeburn 17734: } elsif ($item eq 'postsubmit') {
17735: if ($domdefaults{'postsubmit'} eq 'off') {
17736: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17737: } else {
17738: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17739: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17740: $resulttext .= &mt('durations:').'<ul>';
17741: foreach my $type (@types) {
17742: $resulttext .= '<li>';
17743: my $timeout;
17744: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17745: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17746: }
17747: my $display;
17748: if ($timeout eq '0') {
17749: $display = &mt('unlimited');
17750: } elsif ($timeout eq '') {
17751: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17752: } else {
17753: $display = &mt('[quant,_1,second]',$timeout);
17754: }
17755: if ($type eq 'community') {
17756: $resulttext .= &mt('Communities');
17757: } elsif ($type eq 'official') {
17758: $resulttext .= &mt('Official courses');
17759: } elsif ($type eq 'unofficial') {
17760: $resulttext .= &mt('Unofficial courses');
17761: } elsif ($type eq 'textbook') {
17762: $resulttext .= &mt('Textbook courses');
17763: }
17764: $resulttext .= ' -- '.$display.'</li>';
17765: }
17766: $resulttext .= '</ul>';
17767: }
17768: $resulttext .= '</li>';
17769: }
1.160.6.16 raeburn 17770: } elsif ($item eq 'coursecredits') {
17771: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17772: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 17773: ($domdefaults{'unofficialcredits'} eq '') &&
17774: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 17775: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17776: } else {
17777: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17778: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17779: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 17780: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 17781: '</ul>'.
17782: '</li>';
17783: }
17784: } else {
17785: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17786: }
1.160.6.64 raeburn 17787: } elsif ($item eq 'canclone') {
17788: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17789: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17790: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17791: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17792: }
17793: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17794: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17795: } else {
17796: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
17797: }
1.160.6.118.2 4(raebur 17798:2): } elsif ($item eq 'ltiauth') {
17799:2): if ($env{'form.'.$item} eq '1') {
17800:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
17801:2): } else {
17802:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
17803:2): }
1.140 raeburn 17804: }
1.121 raeburn 17805: }
17806: $resulttext .= '</ul>';
17807: } else {
17808: $resulttext = &mt('No changes made to course defaults');
17809: }
17810: } else {
17811: $resulttext = '<span class="LC_error">'.
17812: &mt('An error occurred: [_1]',$putresult).'</span>';
17813: }
17814: return $resulttext;
17815: }
17816:
1.160.6.37 raeburn 17817: sub modify_selfenrollment {
17818: my ($dom,$lastactref,%domconfig) = @_;
17819: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
17820: my @types = ('official','unofficial','community','textbook');
17821: my %titles = &tool_titles();
17822: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17823: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
17824: $ordered{'default'} = ['types','registered','approval','limit'];
17825:
17826: my (%roles,%shown,%toplevel);
17827: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17828:
17829: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17830: if ($domconfig{'selfenrollment'} eq '') {
17831: $domconfig{'selfenrollment'} = {};
17832: }
17833: }
17834: %toplevel = (
17835: admin => 'Configuration Rights',
17836: default => 'Default settings',
17837: validation => 'Validation of self-enrollment requests',
17838: );
17839: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
17840:
17841: if (ref($ordered{'admin'}) eq 'ARRAY') {
17842: foreach my $item (@{$ordered{'admin'}}) {
17843: foreach my $type (@types) {
17844: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17845: $selfenrollhash{'admin'}{$type}{$item} = 1;
17846: } else {
17847: $selfenrollhash{'admin'}{$type}{$item} = 0;
17848: }
17849: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17850: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17851: if ($selfenrollhash{'admin'}{$type}{$item} ne
17852: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17853: push(@{$changes{'admin'}{$type}},$item);
17854: }
17855: } else {
17856: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17857: push(@{$changes{'admin'}{$type}},$item);
17858: }
17859: }
17860: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17861: push(@{$changes{'admin'}{$type}},$item);
17862: }
17863: }
17864: }
17865: }
17866:
17867: foreach my $item (@{$ordered{'default'}}) {
17868: foreach my $type (@types) {
17869: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17870: if ($item eq 'types') {
17871: unless (($value eq 'all') || ($value eq 'dom')) {
17872: $value = '';
17873: }
17874: } elsif ($item eq 'registered') {
17875: unless ($value eq '1') {
17876: $value = 0;
17877: }
17878: } elsif ($item eq 'approval') {
17879: unless ($value =~ /^[012]$/) {
17880: $value = 0;
17881: }
17882: } else {
17883: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17884: $value = 'none';
17885: }
17886: }
17887: $selfenrollhash{'default'}{$type}{$item} = $value;
17888: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17889: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17890: if ($selfenrollhash{'default'}{$type}{$item} ne
17891: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17892: push(@{$changes{'default'}{$type}},$item);
17893: }
17894: } else {
17895: push(@{$changes{'default'}{$type}},$item);
17896: }
17897: } else {
17898: push(@{$changes{'default'}{$type}},$item);
17899: }
17900: if ($item eq 'limit') {
17901: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17902: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17903: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17904: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17905: }
17906: } else {
17907: $selfenrollhash{'default'}{$type}{'cap'} = '';
17908: }
17909: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17910: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17911: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17912: push(@{$changes{'default'}{$type}},'cap');
17913: }
17914: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17915: push(@{$changes{'default'}{$type}},'cap');
17916: }
17917: }
17918: }
17919: }
17920:
17921: foreach my $item (@{$itemsref}) {
17922: if ($item eq 'fields') {
17923: my @changed;
17924: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17925: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17926: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17927: }
17928: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17929: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17930: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17931: $domconfig{'selfenrollment'}{'validation'}{$item});
17932: } else {
17933: @changed = @{$selfenrollhash{'validation'}{$item}};
17934: }
17935: } else {
17936: @changed = @{$selfenrollhash{'validation'}{$item}};
17937: }
17938: if (@changed) {
17939: if ($selfenrollhash{'validation'}{$item}) {
17940: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17941: } else {
17942: $changes{'validation'}{$item} = &mt('None');
17943: }
17944: }
17945: } else {
17946: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17947: if ($item eq 'markup') {
17948: if ($env{'form.selfenroll_validation_'.$item}) {
17949: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17950: }
17951: }
17952: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17953: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17954: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17955: }
17956: }
17957: }
17958: }
17959:
17960: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17961: $dom);
17962: if ($putresult eq 'ok') {
17963: if (keys(%changes) > 0) {
17964: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17965: $resulttext = &mt('Changes made:').'<ul>';
17966: foreach my $key ('admin','default','validation') {
17967: if (ref($changes{$key}) eq 'HASH') {
17968: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17969: if ($key eq 'validation') {
17970: foreach my $item (@{$itemsref}) {
17971: if (exists($changes{$key}{$item})) {
17972: if ($item eq 'markup') {
17973: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17974: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17975: } else {
17976: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17977: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17978: }
17979: }
17980: }
17981: } else {
17982: foreach my $type (@types) {
17983: if ($type eq 'community') {
17984: $roles{'1'} = &mt('Community personnel');
17985: } else {
17986: $roles{'1'} = &mt('Course personnel');
17987: }
17988: if (ref($changes{$key}{$type}) eq 'ARRAY') {
17989: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17990: if ($key eq 'admin') {
17991: my @mgrdc = ();
17992: if (ref($ordered{$key}) eq 'ARRAY') {
17993: foreach my $item (@{$ordered{'admin'}}) {
17994: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17995: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17996: push(@mgrdc,$item);
17997: }
17998: }
17999: }
18000: if (@mgrdc) {
18001: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
18002: } else {
18003: delete($domdefaults{$type.'selfenrolladmdc'});
18004: }
18005: }
18006: } else {
18007: if (ref($ordered{$key}) eq 'ARRAY') {
18008: foreach my $item (@{$ordered{$key}}) {
18009: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18010: $domdefaults{$type.'selfenroll'.$item} =
18011: $selfenrollhash{$key}{$type}{$item};
18012: }
18013: }
18014: }
18015: }
18016: }
18017: $resulttext .= '<li>'.$titles{$type}.'<ul>';
18018: foreach my $item (@{$ordered{$key}}) {
18019: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18020: $resulttext .= '<li>';
18021: if ($key eq 'admin') {
18022: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
18023: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
18024: } else {
18025: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
18026: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
18027: }
18028: $resulttext .= '</li>';
18029: }
18030: }
18031: $resulttext .= '</ul></li>';
18032: }
18033: }
18034: $resulttext .= '</ul></li>';
18035: }
18036: }
1.160.6.93 raeburn 18037: }
18038: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
18039: my $cachetime = 24*60*60;
18040: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18041: if (ref($lastactref) eq 'HASH') {
18042: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 18043: }
18044: }
18045: $resulttext .= '</ul>';
18046: } else {
18047: $resulttext = &mt('No changes made to self-enrollment settings');
18048: }
18049: } else {
18050: $resulttext = '<span class="LC_error">'.
18051: &mt('An error occurred: [_1]',$putresult).'</span>';
18052: }
18053: return $resulttext;
18054: }
18055:
1.160.6.113 raeburn 18056: sub modify_wafproxy {
18057: my ($dom,$action,$lastactref,%domconfig) = @_;
18058: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18059: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
18060: %wafproxy,%changes,%expirecache,%expiresaml);
18061: foreach my $server (sort(keys(%servers))) {
18062: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18063: if ($serverhome eq $server) {
18064: my $serverdom = &Apache::lonnet::host_domain($server);
18065: if ($serverdom eq $dom) {
18066: $canset{$server} = 1;
18067: }
18068: }
18069: }
18070: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
18071: %{$values{$dom}} = ();
18072: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
18073: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
18074: }
18075: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
18076: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
18077: }
18078: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18079: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
18080: }
18081: }
18082: my $output;
18083: if (keys(%canset)) {
18084: %{$wafproxy{'alias'}} = ();
18085: %{$wafproxy{'saml'}} = ();
18086: foreach my $key (sort(keys(%canset))) {
18087: if ($env{'form.wafproxy_'.$dom}) {
18088: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
18089: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
18090: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
18091: $changes{'alias'} = 1;
18092: }
18093: if ($env{'form.wafproxy_alias_saml_'.$key}) {
18094: $wafproxy{'saml'}{$key} = 1;
18095: }
18096: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
18097: $changes{'saml'} = 1;
18098: }
18099: } else {
18100: $wafproxy{'alias'}{$key} = '';
18101: $wafproxy{'saml'}{$key} = '';
18102: if ($curralias{$key}) {
18103: $changes{'alias'} = 1;
18104: }
18105: if ($currsaml{$key}) {
18106: $changes{'saml'} = 1;
18107: }
18108: }
18109: if ($wafproxy{'alias'}{$key} eq '') {
18110: if ($curralias{$key}) {
18111: $expirecache{$key} = 1;
18112: }
18113: delete($wafproxy{'alias'}{$key});
18114: }
18115: if ($wafproxy{'saml'}{$key} eq '') {
18116: if ($currsaml{$key}) {
18117: $expiresaml{$key} = 1;
18118: }
18119: delete($wafproxy{'saml'}{$key});
18120: }
18121: }
18122: unless (keys(%{$wafproxy{'alias'}})) {
18123: delete($wafproxy{'alias'});
18124: }
18125: unless (keys(%{$wafproxy{'saml'}})) {
18126: delete($wafproxy{'saml'});
18127: }
18128: # Localization for values in %warn occurs in &mt() calls separately.
18129: my %warn = (
18130: trusted => 'trusted IP range(s)',
18131: vpnint => 'internal IP range(s) for VPN sessions(s)',
18132: vpnext => 'IP range(s) for backend WAF connections',
18133: );
18134: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18135: my $possible = $env{'form.wafproxy_'.$item};
18136: $possible =~ s/^\s+|\s+$//g;
18137: if ($possible ne '') {
18138: if ($item eq 'remoteip') {
18139: if ($possible =~ /^[mhn]$/) {
18140: $wafproxy{$item} = $possible;
18141: }
18142: } elsif ($item eq 'ipheader') {
18143: if ($wafproxy{'remoteip'} eq 'h') {
18144: $wafproxy{$item} = $possible;
18145: }
18146: } elsif ($item eq 'sslopt') {
18147: if ($possible =~ /^0|1$/) {
18148: $wafproxy{$item} = $possible;
18149: }
18150: } else {
18151: my (@ok,$count);
18152: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
18153: unless ($env{'form.wafproxy_vpnaccess'}) {
18154: $possible = '';
18155: }
18156: } elsif ($item eq 'trusted') {
18157: unless ($wafproxy{'remoteip'} eq 'h') {
18158: $possible = '';
18159: }
18160: }
18161: unless ($possible eq '') {
18162: $possible =~ s/[\r\n]+/\s/g;
18163: $possible =~ s/\s*-\s*/-/g;
18164: $possible =~ s/\s+/,/g;
18165: $possible =~ s/,+/,/g;
18166: }
18167: $count = 0;
18168: if ($possible ne '') {
18169: foreach my $poss (split(/\,/,$possible)) {
18170: $count ++;
18171: $poss = &validate_ip_pattern($poss);
18172: if ($poss ne '') {
18173: push(@ok,$poss);
18174: }
18175: }
18176: my $diff = $count - scalar(@ok);
18177: if ($diff) {
18178: push(@warnings,'<li>'.
18179: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
18180: $diff,$warn{$item}).
18181: '</li>');
18182: }
18183: if (@ok) {
18184: my @cidr_list;
18185: foreach my $item (@ok) {
18186: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
18187: }
18188: $wafproxy{$item} = join(',',@cidr_list);
18189: }
18190: }
18191: }
18192: if ($wafproxy{$item} ne $currvalue{$item}) {
18193: $changes{$item} = 1;
18194: }
18195: } elsif ($currvalue{$item}) {
18196: $changes{$item} = 1;
18197: }
18198: }
18199: } else {
18200: if (keys(%curralias)) {
18201: $changes{'alias'} = 1;
18202: }
18203: if (keys(%currsaml)) {
18204: $changes{'saml'} = 1;
18205: }
18206: if (keys(%currvalue)) {
18207: foreach my $key (keys(%currvalue)) {
18208: $changes{$key} = 1;
18209: }
18210: }
18211: }
18212: if (keys(%changes)) {
18213: my %defaultshash = (
18214: wafproxy => \%wafproxy,
18215: );
18216: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18217: $dom);
18218: if ($putresult eq 'ok') {
18219: my $cachetime = 24*60*60;
18220: my (%domdefaults,$updatedomdefs);
18221: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
18222: if ($changes{$item}) {
18223: unless ($updatedomdefs) {
18224: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18225: $updatedomdefs = 1;
18226: }
18227: if ($wafproxy{$item}) {
18228: $domdefaults{'waf_'.$item} = $wafproxy{$item};
18229: } elsif (exists($domdefaults{'waf_'.$item})) {
18230: delete($domdefaults{'waf_'.$item});
18231: }
18232: }
18233: }
18234: if ($updatedomdefs) {
18235: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18236: if (ref($lastactref) eq 'HASH') {
18237: $lastactref->{'domdefaults'} = 1;
18238: }
18239: }
18240: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
18241: my %updates = %expirecache;
18242: foreach my $key (keys(%expirecache)) {
18243: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
18244: }
18245: if (ref($wafproxy{'alias'}) eq 'HASH') {
18246: my $cachetime = 24*60*60;
18247: foreach my $key (keys(%{$wafproxy{'alias'}})) {
18248: $updates{$key} = 1;
18249: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
18250: $cachetime);
18251: }
18252: }
18253: if (ref($lastactref) eq 'HASH') {
18254: $lastactref->{'proxyalias'} = \%updates;
18255: }
18256: }
18257: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
18258: my %samlupdates = %expiresaml;
18259: foreach my $key (keys(%expiresaml)) {
18260: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
18261: }
18262: if (ref($wafproxy{'saml'}) eq 'HASH') {
18263: my $cachetime = 24*60*60;
18264: foreach my $key (keys(%{$wafproxy{'saml'}})) {
18265: $samlupdates{$key} = 1;
18266: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
18267: $cachetime);
18268: }
18269: }
18270: if (ref($lastactref) eq 'HASH') {
18271: $lastactref->{'proxysaml'} = \%samlupdates;
18272: }
18273: }
18274: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 18275: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 18276: if ($changes{$item}) {
18277: if ($item eq 'alias') {
18278: my $numaliased = 0;
18279: if (ref($wafproxy{'alias'}) eq 'HASH') {
18280: my $shown;
18281: if (keys(%{$wafproxy{'alias'}})) {
18282: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
18283: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
18284: &Apache::lonnet::hostname($server),
18285: $wafproxy{'alias'}{$server}).'</li>';
18286: $numaliased ++;
18287: }
18288: if ($numaliased) {
18289: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
18290: '<ul>'.$shown.'</ul>').'</li>';
18291: }
18292: }
18293: }
18294: unless ($numaliased) {
18295: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
18296: }
18297: } elsif ($item eq 'saml') {
18298: my $shown;
18299: if (ref($wafproxy{'saml'}) eq 'HASH') {
18300: if (keys(%{$wafproxy{'saml'}})) {
18301: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
18302: }
18303: }
18304: if ($shown) {
18305: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
18306: $shown).'</li>';
18307: } else {
18308: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
18309: }
18310: } else {
18311: if ($item eq 'remoteip') {
18312: my %ip_methods = &remoteip_methods();
18313: if ($wafproxy{$item} =~ /^[mh]$/) {
18314: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
18315: $ip_methods{$wafproxy{$item}}).'</li>';
18316: } else {
18317: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
18318: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
18319: '</li>';
18320: } else {
18321: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
18322: }
18323: }
18324: } elsif ($item eq 'ipheader') {
18325: if ($wafproxy{$item}) {
18326: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
18327: $wafproxy{$item}).'</li>';
18328: } else {
18329: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
18330: }
18331: } elsif ($item eq 'trusted') {
18332: if ($wafproxy{$item}) {
18333: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
18334: $wafproxy{$item}).'</li>';
18335: } else {
18336: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
18337: }
18338: } elsif ($item eq 'vpnint') {
18339: if ($wafproxy{$item}) {
18340: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
18341: $wafproxy{$item}).'</li>';
18342: } else {
18343: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
18344: }
18345: } elsif ($item eq 'vpnext') {
18346: if ($wafproxy{$item}) {
18347: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
18348: $wafproxy{$item}).'</li>';
18349: } else {
18350: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
18351: }
18352: } elsif ($item eq 'sslopt') {
18353: if ($wafproxy{$item}) {
18354: $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>';
18355: } else {
18356: $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>';
18357: }
18358: }
18359: }
18360: }
18361: }
18362: } else {
18363: $output = '<span class="LC_error">'.
18364: &mt('An error occurred: [_1]',$putresult).'</span>';
18365: }
18366: } elsif (keys(%canset)) {
18367: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
18368: }
18369: if (@warnings) {
18370: $output .= '<br />'.&mt('Warnings:').'<ul>'.
18371: join("\n",@warnings).'</ul>';
18372: }
18373: return $output;
18374: }
18375:
18376: sub validate_ip_pattern {
18377: my ($pattern) = @_;
18378: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
18379: my ($start,$end) = ($1,$2);
18380: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
18381: if (($start !~ m{/}) && ($end !~ m{/})) {
18382: return $start.'-'.$end;
18383: }
18384: }
18385: } elsif ($pattern ne '') {
18386: $pattern = &Net::CIDR::cidrvalidate($pattern);
18387: if ($pattern ne '') {
18388: return $pattern;
18389: }
18390: }
18391: return;
18392: }
18393:
1.137 raeburn 18394: sub modify_usersessions {
1.160.6.27 raeburn 18395: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 18396: my @hostingtypes = ('version','excludedomain','includedomain');
18397: my @offloadtypes = ('primary','default');
18398: my %types = (
18399: remote => \@hostingtypes,
18400: hosted => \@hostingtypes,
18401: spares => \@offloadtypes,
18402: );
18403: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 18404: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 18405: my (%by_ip,%by_location,@intdoms);
18406: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
18407: my @locations = sort(keys(%by_location));
1.137 raeburn 18408: my (%defaultshash,%changes);
18409: foreach my $prefix (@prefixes) {
18410: $defaultshash{'usersessions'}{$prefix} = {};
18411: }
1.160.6.27 raeburn 18412: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 18413: my $resulttext;
1.138 raeburn 18414: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 18415: foreach my $prefix (@prefixes) {
1.145 raeburn 18416: next if ($prefix eq 'spares');
18417: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 18418: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18419: if ($type eq 'version') {
18420: my $value = $env{'form.'.$prefix.'_'.$type};
18421: my $okvalue;
18422: if ($value ne '') {
18423: if (grep(/^\Q$value\E$/,@lcversions)) {
18424: $okvalue = $value;
18425: }
18426: }
18427: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18428: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18429: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18430: if ($inuse == 0) {
18431: $changes{$prefix}{$type} = 1;
18432: } else {
18433: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18434: $changes{$prefix}{$type} = 1;
18435: }
18436: if ($okvalue ne '') {
18437: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18438: }
18439: }
18440: } else {
18441: if (($inuse == 1) && ($okvalue ne '')) {
18442: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18443: $changes{$prefix}{$type} = 1;
18444: }
18445: }
18446: } else {
18447: if (($inuse == 1) && ($okvalue ne '')) {
18448: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18449: $changes{$prefix}{$type} = 1;
18450: }
18451: }
18452: } else {
18453: if (($inuse == 1) && ($okvalue ne '')) {
18454: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18455: $changes{$prefix}{$type} = 1;
18456: }
18457: }
18458: } else {
18459: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18460: my @okvals;
18461: foreach my $val (@vals) {
1.138 raeburn 18462: if ($val =~ /:/) {
18463: my @items = split(/:/,$val);
18464: foreach my $item (@items) {
18465: if (ref($by_location{$item}) eq 'ARRAY') {
18466: push(@okvals,$item);
18467: }
18468: }
18469: } else {
18470: if (ref($by_location{$val}) eq 'ARRAY') {
18471: push(@okvals,$val);
18472: }
1.137 raeburn 18473: }
18474: }
18475: @okvals = sort(@okvals);
18476: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18477: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18478: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18479: if ($inuse == 0) {
18480: $changes{$prefix}{$type} = 1;
18481: } else {
18482: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18483: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18484: if (@changed > 0) {
18485: $changes{$prefix}{$type} = 1;
18486: }
18487: }
18488: } else {
18489: if ($inuse == 1) {
18490: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18491: $changes{$prefix}{$type} = 1;
18492: }
18493: }
18494: } else {
18495: if ($inuse == 1) {
18496: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18497: $changes{$prefix}{$type} = 1;
18498: }
18499: }
18500: } else {
18501: if ($inuse == 1) {
18502: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18503: $changes{$prefix}{$type} = 1;
18504: }
18505: }
18506: }
18507: }
18508: }
1.145 raeburn 18509:
18510: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18511: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18512: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18513: my $savespares;
18514:
18515: foreach my $lonhost (sort(keys(%servers))) {
18516: my $serverhomeID =
18517: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18518: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18519: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18520: my %spareschg;
18521: foreach my $type (@{$types{'spares'}}) {
18522: my @okspares;
18523: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18524: foreach my $server (@checked) {
1.152 raeburn 18525: if (&Apache::lonnet::hostname($server) ne '') {
18526: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18527: unless (grep(/^\Q$server\E$/,@okspares)) {
18528: push(@okspares,$server);
18529: }
1.145 raeburn 18530: }
18531: }
18532: }
18533: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18534: my $newspare;
1.152 raeburn 18535: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18536: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18537: $newspare = $new;
18538: }
18539: }
1.152 raeburn 18540: my @spares;
18541: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18542: @spares = sort(@okspares,$newspare);
18543: } else {
18544: @spares = sort(@okspares);
18545: }
18546: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18547: if (ref($spareid{$lonhost}) eq 'HASH') {
18548: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18549: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18550: if (@diffs > 0) {
18551: $spareschg{$type} = 1;
18552: }
18553: }
18554: }
18555: }
18556: if (keys(%spareschg) > 0) {
18557: $changes{'spares'}{$lonhost} = \%spareschg;
18558: }
18559: }
1.160.6.61 raeburn 18560: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 18561: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 18562: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18563: my @okoffload;
18564: if (@offloadnow) {
18565: foreach my $server (@offloadnow) {
18566: if (&Apache::lonnet::hostname($server) ne '') {
18567: unless (grep(/^\Q$server\E$/,@okoffload)) {
18568: push(@okoffload,$server);
18569: }
18570: }
18571: }
18572: if (@okoffload) {
18573: foreach my $lonhost (@okoffload) {
18574: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18575: }
18576: }
18577: }
1.160.6.105 raeburn 18578: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
18579: my @okoffloadoth;
18580: if (@offloadoth) {
18581: foreach my $server (@offloadoth) {
18582: if (&Apache::lonnet::hostname($server) ne '') {
18583: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
18584: push(@okoffloadoth,$server);
18585: }
18586: }
18587: }
18588: if (@okoffloadoth) {
18589: foreach my $lonhost (@okoffloadoth) {
18590: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
18591: }
18592: }
18593: }
1.145 raeburn 18594: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18595: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18596: if (ref($changes{'spares'}) eq 'HASH') {
18597: if (keys(%{$changes{'spares'}}) > 0) {
18598: $savespares = 1;
18599: }
18600: }
18601: } else {
18602: $savespares = 1;
18603: }
1.160.6.105 raeburn 18604: foreach my $offload ('offloadnow','offloadoth') {
18605: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
18606: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
18607: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
18608: $changes{$offload} = 1;
1.160.6.61 raeburn 18609: last;
18610: }
18611: }
1.160.6.105 raeburn 18612: unless ($changes{$offload}) {
18613: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
18614: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
18615: $changes{$offload} = 1;
18616: last;
18617: }
18618: }
18619: }
18620: } else {
18621: if (($offload eq 'offloadnow') && (@okoffload)) {
18622: $changes{'offloadnow'} = 1;
18623: }
18624: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
18625: $changes{'offloadoth'} = 1;
18626: }
1.160.6.61 raeburn 18627: }
1.160.6.105 raeburn 18628: }
18629: } else {
18630: if (@okoffload) {
1.160.6.61 raeburn 18631: $changes{'offloadnow'} = 1;
18632: }
1.160.6.105 raeburn 18633: if (@okoffloadoth) {
18634: $changes{'offloadoth'} = 1;
18635: }
1.145 raeburn 18636: }
1.147 raeburn 18637: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18638: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18639: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18640: $dom);
18641: if ($putresult eq 'ok') {
18642: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18643: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18644: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18645: }
18646: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18647: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18648: }
1.160.6.61 raeburn 18649: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18650: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18651: }
1.160.6.105 raeburn 18652: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18653: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18654: }
1.137 raeburn 18655: }
18656: my $cachetime = 24*60*60;
18657: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 18658: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 18659: if (ref($lastactref) eq 'HASH') {
18660: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 18661: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 18662: }
1.147 raeburn 18663: if (keys(%changes) > 0) {
18664: my %lt = &usersession_titles();
18665: $resulttext = &mt('Changes made:').'<ul>';
18666: foreach my $prefix (@prefixes) {
18667: if (ref($changes{$prefix}) eq 'HASH') {
18668: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18669: if ($prefix eq 'spares') {
18670: if (ref($changes{$prefix}) eq 'HASH') {
18671: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18672: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18673: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 18674: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18675: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18676: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18677: foreach my $type (@{$types{$prefix}}) {
18678: if ($changes{$prefix}{$lonhost}{$type}) {
18679: my $offloadto = &mt('None');
18680: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18681: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18682: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18683: }
1.145 raeburn 18684: }
1.147 raeburn 18685: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18686: }
1.137 raeburn 18687: }
18688: }
1.147 raeburn 18689: $resulttext .= '</li>';
1.137 raeburn 18690: }
18691: }
1.147 raeburn 18692: } else {
18693: foreach my $type (@{$types{$prefix}}) {
18694: if (defined($changes{$prefix}{$type})) {
18695: my $newvalue;
18696: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18697: if (ref($defaultshash{'usersessions'}{$prefix})) {
18698: if ($type eq 'version') {
18699: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18700: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18701: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18702: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18703: }
1.145 raeburn 18704: }
18705: }
18706: }
1.147 raeburn 18707: if ($newvalue eq '') {
18708: if ($type eq 'version') {
18709: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18710: } else {
18711: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18712: }
1.145 raeburn 18713: } else {
1.147 raeburn 18714: if ($type eq 'version') {
18715: $newvalue .= ' '.&mt('(or later)');
18716: }
18717: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18718: }
1.137 raeburn 18719: }
18720: }
18721: }
1.147 raeburn 18722: $resulttext .= '</ul>';
1.137 raeburn 18723: }
18724: }
1.160.6.61 raeburn 18725: if ($changes{'offloadnow'}) {
18726: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18727: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 18728: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 18729: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18730: $resulttext .= '<li>'.$lonhost.'</li>';
18731: }
18732: $resulttext .= '</ul>';
18733: } else {
1.160.6.105 raeburn 18734: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18735: }
18736: } else {
18737: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18738: }
18739: }
18740: if ($changes{'offloadoth'}) {
18741: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18742: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18743: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18744: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18745: $resulttext .= '<li>'.$lonhost.'</li>';
18746: }
18747: $resulttext .= '</ul>';
18748: } else {
18749: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 18750: }
18751: } else {
1.160.6.105 raeburn 18752: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 18753: }
18754: }
1.147 raeburn 18755: $resulttext .= '</ul>';
18756: } else {
18757: $resulttext = $nochgmsg;
1.137 raeburn 18758: }
18759: } else {
18760: $resulttext = '<span class="LC_error">'.
18761: &mt('An error occurred: [_1]',$putresult).'</span>';
18762: }
18763: } else {
1.147 raeburn 18764: $resulttext = $nochgmsg;
1.137 raeburn 18765: }
18766: return $resulttext;
18767: }
18768:
1.150 raeburn 18769: sub modify_loadbalancing {
18770: my ($dom,%domconfig) = @_;
18771: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18772: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18773: my ($othertitle,$usertypes,$types) =
18774: &Apache::loncommon::sorted_inst_types($dom);
18775: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 18776: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18777: my @sparestypes = ('primary','default');
18778: my %typetitles = &sparestype_titles();
18779: my $resulttext;
1.160.6.94 raeburn 18780: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18781: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18782: %existing = %{$domconfig{'loadbalancing'}};
18783: }
18784: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18785: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18786: my ($saveloadbalancing,%defaultshash,%changes);
18787: my ($alltypes,$othertypes,$titles) =
18788: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18789: my %ruletitles = &offloadtype_text();
18790: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18791: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18792: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18793: if ($balancer eq '') {
18794: next;
18795: }
18796: if (!exists($servers{$balancer})) {
18797: if (exists($currbalancer{$balancer})) {
18798: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18799: }
1.160.6.7 raeburn 18800: next;
18801: }
18802: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18803: push(@{$changes{'delete'}},$balancer);
18804: next;
18805: }
18806: if (!exists($currbalancer{$balancer})) {
18807: push(@{$changes{'add'}},$balancer);
18808: }
18809: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18810: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18811: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18812: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18813: $saveloadbalancing = 1;
18814: }
18815: foreach my $sparetype (@sparestypes) {
18816: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18817: my @offloadto;
18818: foreach my $target (@targets) {
18819: if (($servers{$target}) && ($target ne $balancer)) {
18820: if ($sparetype eq 'default') {
18821: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18822: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18823: }
18824: }
1.160.6.7 raeburn 18825: unless(grep(/^\Q$target\E$/,@offloadto)) {
18826: push(@offloadto,$target);
18827: }
1.150 raeburn 18828: }
18829: }
1.160.6.76 raeburn 18830: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18831: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18832: push(@offloadto,$balancer);
18833: }
18834: }
18835: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18836: }
1.160.6.94 raeburn 18837: if ($env{'form.loadbalancing_cookie_'.$i}) {
18838: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18839: if (exists($currbalancer{$balancer})) {
18840: unless ($currcookies{$balancer}) {
18841: $changes{'curr'}{$balancer}{'cookie'} = 1;
18842: }
18843: }
18844: } elsif (exists($currbalancer{$balancer})) {
18845: if ($currcookies{$balancer}) {
18846: $changes{'curr'}{$balancer}{'cookie'} = 1;
18847: }
18848: }
1.160.6.7 raeburn 18849: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18850: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 18851: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18852: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18853: if (@targetdiffs > 0) {
1.160.6.7 raeburn 18854: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18855: }
1.160.6.7 raeburn 18856: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18857: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18858: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18859: }
18860: }
18861: }
18862: } else {
1.160.6.7 raeburn 18863: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
18864: foreach my $sparetype (@sparestypes) {
18865: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18866: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18867: $changes{'curr'}{$balancer}{'targets'} = 1;
18868: }
1.150 raeburn 18869: }
18870: }
1.160.6.7 raeburn 18871: }
1.150 raeburn 18872: }
18873: my $ishomedom;
1.160.6.7 raeburn 18874: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18875: $ishomedom = 1;
1.150 raeburn 18876: }
18877: if (ref($alltypes) eq 'ARRAY') {
18878: foreach my $type (@{$alltypes}) {
18879: my $rule;
1.160.6.7 raeburn 18880: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18881: (!$ishomedom)) {
1.160.6.7 raeburn 18882: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18883: }
18884: if ($rule eq 'specific') {
1.160.6.55 raeburn 18885: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
18886: if (exists($servers{$specifiedhost})) {
18887: $rule = $specifiedhost;
18888: }
1.150 raeburn 18889: }
1.160.6.7 raeburn 18890: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18891: if (ref($currrules{$balancer}) eq 'HASH') {
18892: if ($rule ne $currrules{$balancer}{$type}) {
18893: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18894: }
18895: } elsif ($rule ne '') {
1.160.6.7 raeburn 18896: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18897: }
18898: }
18899: }
1.160.6.7 raeburn 18900: }
18901: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18902: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18903: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18904: $defaultshash{'loadbalancing'} = {};
18905: }
18906: my $putresult = &Apache::lonnet::put_dom('configuration',
18907: \%defaultshash,$dom);
18908: if ($putresult eq 'ok') {
18909: if (keys(%changes) > 0) {
1.160.6.54 raeburn 18910: my %toupdate;
1.160.6.7 raeburn 18911: if (ref($changes{'delete'}) eq 'ARRAY') {
18912: foreach my $balancer (sort(@{$changes{'delete'}})) {
18913: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 18914: $toupdate{$balancer} = 1;
1.150 raeburn 18915: }
1.160.6.7 raeburn 18916: }
18917: if (ref($changes{'add'}) eq 'ARRAY') {
18918: foreach my $balancer (sort(@{$changes{'add'}})) {
18919: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 18920: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18921: }
18922: }
18923: if (ref($changes{'curr'}) eq 'HASH') {
18924: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 18925: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18926: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18927: if ($changes{'curr'}{$balancer}{'targets'}) {
18928: my %offloadstr;
18929: foreach my $sparetype (@sparestypes) {
18930: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18931: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18932: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18933: }
18934: }
1.150 raeburn 18935: }
1.160.6.7 raeburn 18936: if (keys(%offloadstr) == 0) {
18937: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18938: } else {
1.160.6.7 raeburn 18939: my $showoffload;
18940: foreach my $sparetype (@sparestypes) {
18941: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18942: if (defined($offloadstr{$sparetype})) {
18943: $showoffload .= $offloadstr{$sparetype};
18944: } else {
18945: $showoffload .= &mt('None');
18946: }
18947: $showoffload .= (' 'x3);
18948: }
18949: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18950: }
18951: }
18952: }
1.160.6.7 raeburn 18953: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18954: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18955: foreach my $type (@{$alltypes}) {
18956: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18957: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18958: my $balancetext;
18959: if ($rule eq '') {
18960: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 18961: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 18962: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
18963: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 18964: foreach my $sparetype (@sparestypes) {
18965: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18966: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18967: }
18968: }
1.160.6.55 raeburn 18969: foreach my $item (@{$alltypes}) {
18970: next if ($item =~ /^_LC_ipchange/);
18971: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18972: if ($hasrule eq 'homeserver') {
18973: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18974: } else {
18975: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18976: if ($servers{$hasrule}) {
18977: $toupdate{$hasrule} = 1;
18978: }
18979: }
18980: }
18981: }
18982: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18983: $balancetext = $ruletitles{$rule};
18984: } else {
18985: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18986: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18987: if ($receiver) {
18988: $toupdate{$receiver};
18989: }
18990: }
18991: } else {
18992: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 18993: }
1.160.6.7 raeburn 18994: } else {
18995: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18996: }
1.160.6.26 raeburn 18997: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18998: }
18999: }
19000: }
19001: }
1.160.6.94 raeburn 19002: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 19003: if ($currcookies{$balancer}) {
19004: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
19005: $balancer).'</li>';
19006: } else {
19007: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
19008: $balancer).'</li>';
19009: }
1.160.6.94 raeburn 19010: }
1.160.6.106 raeburn 19011: }
19012: }
19013: if (keys(%toupdate)) {
19014: my %thismachine;
19015: my $updatedhere;
19016: my $cachetime = 60*60*24;
19017: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
19018: foreach my $lonhost (keys(%toupdate)) {
19019: if ($thismachine{$lonhost}) {
19020: unless ($updatedhere) {
19021: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
19022: $defaultshash{'loadbalancing'},
19023: $cachetime);
19024: $updatedhere = 1;
1.160.6.54 raeburn 19025: }
1.160.6.106 raeburn 19026: } else {
19027: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
19028: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 19029: }
1.150 raeburn 19030: }
1.160.6.7 raeburn 19031: }
19032: if ($resulttext ne '') {
19033: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 19034: } else {
19035: $resulttext = $nochgmsg;
19036: }
19037: } else {
1.160.6.7 raeburn 19038: $resulttext = $nochgmsg;
1.150 raeburn 19039: }
19040: } else {
1.160.6.7 raeburn 19041: $resulttext = '<span class="LC_error">'.
19042: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 19043: }
19044: } else {
1.160.6.7 raeburn 19045: $resulttext = $nochgmsg;
1.150 raeburn 19046: }
19047: return $resulttext;
19048: }
19049:
1.48 raeburn 19050: sub recurse_check {
19051: my ($chkcats,$categories,$depth,$name) = @_;
19052: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
19053: my $chg = 0;
19054: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
19055: my $category = $chkcats->[$depth]{$name}[$j];
19056: my $item;
19057: if ($category eq '') {
19058: $chg ++;
19059: } else {
19060: my $deeper = $depth + 1;
19061: $item = &escape($category).':'.&escape($name).':'.$depth;
19062: if ($chg) {
19063: $categories->{$item} -= $chg;
19064: }
19065: &recurse_check($chkcats,$categories,$deeper,$category);
19066: $deeper --;
19067: }
19068: }
19069: }
19070: return;
19071: }
19072:
19073: sub recurse_cat_deletes {
19074: my ($item,$coursecategories,$deletions) = @_;
19075: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
19076: my $subdepth = $depth + 1;
19077: if (ref($coursecategories) eq 'HASH') {
19078: foreach my $subitem (keys(%{$coursecategories})) {
19079: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
19080: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
19081: delete($coursecategories->{$subitem});
19082: $deletions->{$subitem} = 1;
19083: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 19084: }
1.48 raeburn 19085: }
19086: }
19087: return;
19088: }
19089:
1.125 raeburn 19090: sub active_dc_picker {
1.160.6.16 raeburn 19091: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 19092: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 19093: my @domcoord = keys(%domcoords);
19094: if (keys(%currhash)) {
19095: foreach my $dc (keys(%currhash)) {
19096: unless (exists($domcoords{$dc})) {
19097: push(@domcoord,$dc);
19098: }
19099: }
19100: }
19101: @domcoord = sort(@domcoord);
19102: my $numdcs = scalar(@domcoord);
19103: my $rows = 0;
19104: my $table;
1.125 raeburn 19105: if ($numdcs > 1) {
1.160.6.16 raeburn 19106: $table = '<table>';
19107: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 19108: my $rem = $i%($numinrow);
19109: if ($rem == 0) {
19110: if ($i > 0) {
1.160.6.16 raeburn 19111: $table .= '</tr>';
1.125 raeburn 19112: }
1.160.6.16 raeburn 19113: $table .= '<tr>';
19114: $rows ++;
1.125 raeburn 19115: }
1.160.6.16 raeburn 19116: my $check = '';
19117: if ($inputtype eq 'radio') {
19118: if (keys(%currhash) == 0) {
19119: if (!$i) {
19120: $check = ' checked="checked"';
19121: }
19122: } elsif (exists($currhash{$domcoord[$i]})) {
19123: $check = ' checked="checked"';
19124: }
19125: } else {
19126: if (exists($currhash{$domcoord[$i]})) {
19127: $check = ' checked="checked"';
1.125 raeburn 19128: }
19129: }
1.160.6.16 raeburn 19130: if ($i == @domcoord - 1) {
1.125 raeburn 19131: my $colsleft = $numinrow - $rem;
19132: if ($colsleft > 1) {
1.160.6.16 raeburn 19133: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 19134: } else {
1.160.6.16 raeburn 19135: $table .= '<td class="LC_left_item">';
1.125 raeburn 19136: }
19137: } else {
1.160.6.16 raeburn 19138: $table .= '<td class="LC_left_item">';
19139: }
19140: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
19141: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19142: $table .= '<span class="LC_nobreak"><label>'.
19143: '<input type="'.$inputtype.'" name="'.$name.'"'.
19144: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19145: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 19146: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 19147: }
1.160.6.33 raeburn 19148: $table .= '</label></span></td>';
1.125 raeburn 19149: }
1.160.6.16 raeburn 19150: $table .= '</tr></table>';
19151: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 19152: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19153: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 19154: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 19155: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 19156: if ($user ne $dcname.':'.$dcdom) {
19157: $table .= ' ('.$dcname.':'.$dcdom.')';
19158: }
1.160.6.16 raeburn 19159: } else {
19160: my $check;
19161: if (exists($currhash{$domcoord[0]})) {
19162: $check = ' checked="checked"';
19163: }
1.160.6.50 raeburn 19164: $table = '<span class="LC_nobreak"><label>'.
19165: '<input type="checkbox" name="'.$name.'" '.
19166: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 19167: if ($user ne $dcname.':'.$dcdom) {
19168: $table .= ' ('.$dcname.':'.$dcdom.')';
19169: }
19170: $table .= '</label></span>';
1.160.6.16 raeburn 19171: $rows ++;
19172: }
1.125 raeburn 19173: }
1.160.6.16 raeburn 19174: return ($numdcs,$table,$rows);
1.125 raeburn 19175: }
19176:
1.137 raeburn 19177: sub usersession_titles {
19178: return &Apache::lonlocal::texthash(
19179: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19180: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19181: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19182: version => 'LON-CAPA version requirement',
1.138 raeburn 19183: excludedomain => 'Allow all, but exclude specific domains',
19184: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19185: primary => 'Primary (checked first)',
1.154 raeburn 19186: default => 'Default',
1.137 raeburn 19187: );
19188: }
19189:
1.152 raeburn 19190: sub id_for_thisdom {
19191: my (%servers) = @_;
19192: my %altids;
19193: foreach my $server (keys(%servers)) {
19194: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19195: if ($serverhome ne $server) {
19196: $altids{$serverhome} = $server;
19197: }
19198: }
19199: return %altids;
19200: }
19201:
1.150 raeburn 19202: sub count_servers {
19203: my ($currbalancer,%servers) = @_;
19204: my (@spares,$numspares);
19205: foreach my $lonhost (sort(keys(%servers))) {
19206: next if ($currbalancer eq $lonhost);
19207: push(@spares,$lonhost);
19208: }
19209: if ($currbalancer) {
19210: $numspares = scalar(@spares);
19211: } else {
19212: $numspares = scalar(@spares) - 1;
19213: }
19214: return ($numspares,@spares);
19215: }
19216:
19217: sub lonbalance_targets_js {
1.160.6.7 raeburn 19218: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19219: my $select = &mt('Select');
19220: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19221: if (ref($servers) eq 'HASH') {
19222: $alltargets = join("','",sort(keys(%{$servers})));
19223: my @homedoms;
19224: foreach my $server (sort(keys(%{$servers}))) {
19225: if (&Apache::lonnet::host_domain($server) eq $dom) {
19226: push(@homedoms,'1');
19227: } else {
19228: push(@homedoms,'0');
19229: }
19230: }
19231: $allishome = join("','",@homedoms);
19232: }
19233: if (ref($types) eq 'ARRAY') {
19234: if (@{$types} > 0) {
19235: @alltypes = @{$types};
19236: }
19237: }
19238: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19239: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 19240: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 19241: if (ref($settings) eq 'HASH') {
19242: %existing = %{$settings};
19243: }
19244: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 19245: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 19246: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19247: return <<"END";
19248:
19249: <script type="text/javascript">
19250: // <![CDATA[
19251:
1.160.6.7 raeburn 19252: currBalancers = new Array('$balancers');
19253:
19254: function toggleTargets(balnum) {
19255: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19256: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19257: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19258: var prevbalancer = prevhostitem.value;
19259: var baltotal = document.getElementById('loadbalancing_total').value;
19260: prevhostitem.value = balancer;
19261: if (prevbalancer != '') {
19262: var prevIdx = currBalancers.indexOf(prevbalancer);
19263: if (prevIdx != -1) {
19264: currBalancers.splice(prevIdx,1);
19265: }
19266: }
1.150 raeburn 19267: if (balancer == '') {
1.160.6.7 raeburn 19268: hideSpares(balnum);
1.150 raeburn 19269: } else {
1.160.6.7 raeburn 19270: var currIdx = currBalancers.indexOf(balancer);
19271: if (currIdx == -1) {
19272: currBalancers.push(balancer);
19273: }
1.150 raeburn 19274: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 19275: var ishomedom = homedoms[lonhostitem.selectedIndex];
19276: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19277: }
1.160.6.7 raeburn 19278: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19279: return;
19280: }
19281:
1.160.6.7 raeburn 19282: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19283: var alltargets = new Array('$alltargets');
19284: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19285: var offloadtypes = new Array('primary','default');
19286:
1.160.6.7 raeburn 19287: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19288: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19289:
1.151 raeburn 19290: for (var i=0; i<offloadtypes.length; i++) {
19291: var count = 0;
19292: for (var j=0; j<alltargets.length; j++) {
19293: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 19294: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19295: item.value = alltargets[j];
19296: item.style.textAlign='left';
19297: item.style.textFace='normal';
19298: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19299: if (currBalancers.indexOf(alltargets[j]) == -1) {
19300: item.disabled = '';
19301: } else {
19302: item.disabled = 'disabled';
19303: item.checked = false;
19304: }
1.151 raeburn 19305: count ++;
19306: }
1.150 raeburn 19307: }
19308: }
1.151 raeburn 19309: for (var k=0; k<insttypes.length; k++) {
19310: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19311: if (ishomedom == 1) {
1.160.6.7 raeburn 19312: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19313: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19314: } else {
1.160.6.7 raeburn 19315: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19316: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19317: }
19318: } else {
1.160.6.7 raeburn 19319: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19320: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19321: }
1.151 raeburn 19322: if ((insttypes[k] != '_LC_external') &&
19323: ((insttypes[k] != '_LC_internetdom') ||
19324: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 19325: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19326: item.options.length = 0;
19327: item.options[0] = new Option("","",true,true);
19328: var idx = 0;
1.151 raeburn 19329: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 19330: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19331: idx ++;
19332: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19333: }
19334: }
19335: }
19336: }
19337: return;
19338: }
19339:
1.160.6.7 raeburn 19340: function hideSpares(balnum) {
1.150 raeburn 19341: var alltargets = new Array('$alltargets');
19342: var insttypes = new Array('$allinsttypes');
19343: var offloadtypes = new Array('primary','default');
19344:
1.160.6.7 raeburn 19345: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19346: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19347:
19348: var total = alltargets.length - 1;
19349: for (var i=0; i<offloadtypes; i++) {
19350: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 19351: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19352: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19353: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19354: }
1.150 raeburn 19355: }
19356: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 19357: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19358: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19359: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 19360: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19361: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19362: }
19363: }
19364: return;
19365: }
19366:
1.160.6.7 raeburn 19367: function checkOffloads(item,balnum,type) {
1.150 raeburn 19368: var alltargets = new Array('$alltargets');
19369: var offloadtypes = new Array('primary','default');
19370: if (item.checked) {
19371: var total = alltargets.length - 1;
19372: var other;
19373: if (type == offloadtypes[0]) {
1.151 raeburn 19374: other = offloadtypes[1];
1.150 raeburn 19375: } else {
1.151 raeburn 19376: other = offloadtypes[0];
1.150 raeburn 19377: }
19378: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 19379: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19380: if (server == item.value) {
1.160.6.7 raeburn 19381: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19382: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19383: }
19384: }
19385: }
19386: }
19387: return;
19388: }
19389:
1.160.6.7 raeburn 19390: function singleServerToggle(balnum,type) {
19391: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19392: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 19393: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19394: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19395:
19396: } else {
1.160.6.7 raeburn 19397: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19398: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19399: }
19400: return;
19401: }
19402:
1.160.6.7 raeburn 19403: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19404: if (type == '_LC_external') {
1.160.6.26 raeburn 19405: return;
1.150 raeburn 19406: }
1.160.6.7 raeburn 19407: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19408: for (var i=0; i<typesRules.length; i++) {
19409: if (formname.elements[typesRules[i]].checked) {
19410: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 19411: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19412: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19413: } else {
1.160.6.7 raeburn 19414: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19415: }
19416: }
19417: }
19418: return;
19419: }
19420:
19421: function balancerDeleteChange(balnum) {
19422: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19423: var baltotal = document.getElementById('loadbalancing_total').value;
19424: var addtarget;
19425: var removetarget;
19426: var action = 'delete';
19427: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19428: var lonhost = hostitem.value;
19429: var currIdx = currBalancers.indexOf(lonhost);
19430: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19431: if (currIdx != -1) {
19432: currBalancers.splice(currIdx,1);
19433: }
19434: addtarget = lonhost;
19435: } else {
19436: if (currIdx == -1) {
19437: currBalancers.push(lonhost);
19438: }
19439: removetarget = lonhost;
19440: action = 'undelete';
19441: }
19442: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19443: }
19444: return;
19445: }
19446:
19447: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19448: if (baltotal > 1) {
19449: var offloadtypes = new Array('primary','default');
19450: var alltargets = new Array('$alltargets');
19451: var insttypes = new Array('$allinsttypes');
19452: for (var i=0; i<baltotal; i++) {
19453: if (i != balnum) {
19454: for (var j=0; j<offloadtypes.length; j++) {
19455: var total = alltargets.length - 1;
19456: for (var k=0; k<total; k++) {
19457: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19458: var server = serveritem.value;
19459: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19460: if (server == addtarget) {
19461: serveritem.disabled = '';
19462: }
19463: }
19464: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19465: if (server == removetarget) {
19466: serveritem.disabled = 'disabled';
19467: serveritem.checked = false;
19468: }
19469: }
19470: }
19471: }
19472: for (var j=0; j<insttypes.length; j++) {
19473: if (insttypes[j] != '_LC_external') {
19474: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19475: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19476: var currSel = singleserver.selectedIndex;
19477: var currVal = singleserver.options[currSel].value;
19478: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19479: var numoptions = singleserver.options.length;
19480: var needsnew = 1;
19481: for (var k=0; k<numoptions; k++) {
19482: if (singleserver.options[k] == addtarget) {
19483: needsnew = 0;
19484: break;
19485: }
19486: }
19487: if (needsnew == 1) {
19488: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19489: }
19490: }
19491: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19492: singleserver.options.length = 0;
19493: if ((currVal) && (currVal != removetarget)) {
19494: singleserver.options[0] = new Option("","",false,false);
19495: } else {
19496: singleserver.options[0] = new Option("","",true,true);
19497: }
19498: var idx = 0;
19499: for (var m=0; m<alltargets.length; m++) {
19500: if (currBalancers.indexOf(alltargets[m]) == -1) {
19501: idx ++;
19502: if (currVal == alltargets[m]) {
19503: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19504: } else {
19505: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19506: }
19507: }
19508: }
19509: }
19510: }
19511: }
19512: }
1.150 raeburn 19513: }
19514: }
19515: }
19516: return;
19517: }
19518:
1.152 raeburn 19519: // ]]>
19520: </script>
19521:
19522: END
19523: }
19524:
19525: sub new_spares_js {
19526: my @sparestypes = ('primary','default');
19527: my $types = join("','",@sparestypes);
19528: my $select = &mt('Select');
19529: return <<"END";
19530:
19531: <script type="text/javascript">
19532: // <![CDATA[
19533:
19534: function updateNewSpares(formname,lonhost) {
19535: var types = new Array('$types');
19536: var include = new Array();
19537: var exclude = new Array();
19538: for (var i=0; i<types.length; i++) {
19539: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19540: for (var j=0; j<spareboxes.length; j++) {
19541: if (formname.elements[spareboxes[j]].checked) {
19542: exclude.push(formname.elements[spareboxes[j]].value);
19543: } else {
19544: include.push(formname.elements[spareboxes[j]].value);
19545: }
19546: }
19547: }
19548: for (var i=0; i<types.length; i++) {
19549: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19550: var selIdx = newSpare.selectedIndex;
19551: var currnew = newSpare.options[selIdx].value;
19552: var okSpares = new Array();
19553: for (var j=0; j<newSpare.options.length; j++) {
19554: var possible = newSpare.options[j].value;
19555: if (possible != '') {
19556: if (exclude.indexOf(possible) == -1) {
19557: okSpares.push(possible);
19558: } else {
19559: if (currnew == possible) {
19560: selIdx = 0;
19561: }
19562: }
19563: }
19564: }
19565: for (var k=0; k<include.length; k++) {
19566: if (okSpares.indexOf(include[k]) == -1) {
19567: okSpares.push(include[k]);
19568: }
19569: }
19570: okSpares.sort();
19571: newSpare.options.length = 0;
19572: if (selIdx == 0) {
19573: newSpare.options[0] = new Option("$select","",true,true);
19574: } else {
19575: newSpare.options[0] = new Option("$select","",false,false);
19576: }
19577: for (var m=0; m<okSpares.length; m++) {
19578: var idx = m+1;
19579: var selThis = 0;
19580: if (selIdx != 0) {
19581: if (okSpares[m] == currnew) {
19582: selThis = 1;
19583: }
19584: }
19585: if (selThis == 1) {
19586: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19587: } else {
19588: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19589: }
19590: }
19591: }
19592: return;
19593: }
19594:
19595: function checkNewSpares(lonhost,type) {
19596: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19597: var chosen = newSpare.options[newSpare.selectedIndex].value;
19598: if (chosen != '') {
19599: var othertype;
19600: var othernewSpare;
19601: if (type == 'primary') {
19602: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19603: }
19604: if (type == 'default') {
19605: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19606: }
19607: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19608: othernewSpare.selectedIndex = 0;
19609: }
19610: }
19611: return;
19612: }
19613:
19614: // ]]>
19615: </script>
19616:
19617: END
19618:
19619: }
19620:
19621: sub common_domprefs_js {
19622: return <<"END";
19623:
19624: <script type="text/javascript">
19625: // <![CDATA[
19626:
1.150 raeburn 19627: function getIndicesByName(formname,item) {
1.152 raeburn 19628: var group = new Array();
1.150 raeburn 19629: for (var i=0;i<formname.elements.length;i++) {
19630: if (formname.elements[i].name == item) {
1.152 raeburn 19631: group.push(formname.elements[i].id);
1.150 raeburn 19632: }
19633: }
1.152 raeburn 19634: return group;
1.150 raeburn 19635: }
19636:
19637: // ]]>
19638: </script>
19639:
19640: END
1.152 raeburn 19641:
1.150 raeburn 19642: }
19643:
1.160.6.5 raeburn 19644: sub recaptcha_js {
19645: my %lt = &captcha_phrases();
19646: return <<"END";
19647:
19648: <script type="text/javascript">
19649: // <![CDATA[
19650:
19651: function updateCaptcha(caller,context) {
19652: var privitem;
19653: var pubitem;
19654: var privtext;
19655: var pubtext;
1.160.6.69 raeburn 19656: var versionitem;
19657: var versiontext;
1.160.6.5 raeburn 19658: if (document.getElementById(context+'_recaptchapub')) {
19659: pubitem = document.getElementById(context+'_recaptchapub');
19660: } else {
19661: return;
19662: }
19663: if (document.getElementById(context+'_recaptchapriv')) {
19664: privitem = document.getElementById(context+'_recaptchapriv');
19665: } else {
19666: return;
19667: }
19668: if (document.getElementById(context+'_recaptchapubtxt')) {
19669: pubtext = document.getElementById(context+'_recaptchapubtxt');
19670: } else {
19671: return;
19672: }
19673: if (document.getElementById(context+'_recaptchaprivtxt')) {
19674: privtext = document.getElementById(context+'_recaptchaprivtxt');
19675: } else {
19676: return;
19677: }
1.160.6.69 raeburn 19678: if (document.getElementById(context+'_recaptchaversion')) {
19679: versionitem = document.getElementById(context+'_recaptchaversion');
19680: } else {
19681: return;
19682: }
19683: if (document.getElementById(context+'_recaptchavertxt')) {
19684: versiontext = document.getElementById(context+'_recaptchavertxt');
19685: } else {
19686: return;
19687: }
1.160.6.5 raeburn 19688: if (caller.checked) {
19689: if (caller.value == 'recaptcha') {
19690: pubitem.type = 'text';
19691: privitem.type = 'text';
19692: pubitem.size = '40';
19693: privitem.size = '40';
19694: pubtext.innerHTML = "$lt{'pub'}";
19695: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 19696: versionitem.type = 'text';
19697: versionitem.size = '3';
19698: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 19699: } else {
19700: pubitem.type = 'hidden';
19701: privitem.type = 'hidden';
1.160.6.69 raeburn 19702: versionitem.type = 'hidden';
1.160.6.5 raeburn 19703: pubtext.innerHTML = '';
19704: privtext.innerHTML = '';
1.160.6.69 raeburn 19705: versiontext.innerHTML = '';
1.160.6.5 raeburn 19706: }
19707: }
19708: return;
19709: }
19710:
19711: // ]]>
19712: </script>
19713:
19714: END
19715:
19716: }
19717:
1.160.6.40 raeburn 19718: sub toggle_display_js {
1.160.6.16 raeburn 19719: return <<"END";
19720:
19721: <script type="text/javascript">
19722: // <![CDATA[
19723:
1.160.6.40 raeburn 19724: function toggleDisplay(domForm,caller) {
19725: if (document.getElementById(caller)) {
19726: var divitem = document.getElementById(caller);
19727: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 19728: var checkval = 1;
19729: var dispval = 'block';
1.160.6.93 raeburn 19730: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 19731: if (caller == 'emailoptions') {
19732: optionsElement = domForm.cancreate_email;
19733: }
1.160.6.57 raeburn 19734: if (caller == 'studentsubmission') {
19735: optionsElement = domForm.postsubmit;
19736: }
1.160.6.64 raeburn 19737: if (caller == 'cloneinstcode') {
19738: optionsElement = domForm.canclone;
19739: checkval = 'instcode';
19740: }
1.160.6.93 raeburn 19741: if (selfcreateRegExp.test(caller)) {
19742: optionsElement = domForm.elements[caller];
19743: checkval = 'other';
19744: dispval = 'inline'
19745: }
1.160.6.40 raeburn 19746: if (optionsElement.length) {
1.160.6.16 raeburn 19747: var currval;
1.160.6.40 raeburn 19748: for (var i=0; i<optionsElement.length; i++) {
19749: if (optionsElement[i].checked) {
19750: currval = optionsElement[i].value;
1.160.6.16 raeburn 19751: }
19752: }
1.160.6.64 raeburn 19753: if (currval == checkval) {
19754: divitem.style.display = dispval;
1.160.6.16 raeburn 19755: } else {
1.160.6.40 raeburn 19756: divitem.style.display = 'none';
1.160.6.16 raeburn 19757: }
19758: }
19759: }
19760: return;
19761: }
19762:
19763: // ]]>
19764: </script>
19765:
19766: END
19767:
19768: }
19769:
1.160.6.5 raeburn 19770: sub captcha_phrases {
19771: return &Apache::lonlocal::texthash (
19772: priv => 'Private key',
19773: pub => 'Public key',
19774: original => 'original (CAPTCHA)',
19775: recaptcha => 'successor (ReCAPTCHA)',
19776: notused => 'unused',
1.160.6.69 raeburn 19777: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 19778: );
19779: }
19780:
1.160.6.24 raeburn 19781: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 19782: my ($dom,$cachekeys) = @_;
19783: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 19784: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19785: my %thismachine;
19786: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 19787:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 19788: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19789: 'ipaccess');
19790: my %cache_by_lonhost;
19791: if (exists($cachekeys->{'samllanding'})) {
19792: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19793: my %landing = %{$cachekeys->{'samllanding'}};
19794: my %domservers = &Apache::lonnet::get_servers($dom);
19795: if (keys(%domservers)) {
19796: foreach my $server (keys(%domservers)) {
19797: my @cached;
19798: next if ($thismachine{$server});
19799: if ($landing{$server}) {
19800: push(@cached,&escape('samllanding').':'.&escape($server));
19801: }
19802: if (@cached) {
19803: $cache_by_lonhost{$server} = \@cached;
19804: }
19805: }
19806: }
19807: }
19808: }
1.160.6.61 raeburn 19809: if (keys(%servers)) {
1.160.6.24 raeburn 19810: foreach my $server (keys(%servers)) {
19811: next if ($thismachine{$server});
1.160.6.27 raeburn 19812: my @cached;
19813: foreach my $name (@posscached) {
19814: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 19815: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
19816: if (ref($cachekeys->{$name}) eq 'HASH') {
19817: foreach my $key (keys(%{$cachekeys->{$name}})) {
19818: push(@cached,&escape($name).':'.&escape($key));
19819: }
19820: }
19821: } else {
19822: push(@cached,&escape($name).':'.&escape($dom));
19823: }
1.160.6.27 raeburn 19824: }
19825: }
1.160.6.113 raeburn 19826: if ((exists($cache_by_lonhost{$server})) &&
19827: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
19828: push(@cached,@{$cache_by_lonhost{$server}});
19829: }
1.160.6.27 raeburn 19830: if (@cached) {
19831: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19832: }
1.160.6.24 raeburn 19833: }
19834: }
19835: return;
19836: }
19837:
1.3 raeburn 19838: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>