Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.4
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 4(raebur 4:2): # $Id: domainprefs.pm,v 1.160.6.118.2.3 2022/01/19 17:07:56 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 1(raebur 221:1): 'passwords','ltitools','wafproxy','ipaccess'],$dom);
222:1): if (ref($domconfig{'ltitools'}) eq 'HASH') {
223:1): my %encconfig =
224:1): &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom,undef,1);
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): }
1.160.6.113 raeburn 235: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
236: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
237: 'contacts','usercreation','selfcreation','usermodification',
238: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 239: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2 1(raebur 240:1): 'ltitools','selfenrollment','usersessions');
1.160.6.7 raeburn 241: my %existing;
242: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
243: %existing = %{$domconfig{'loadbalancing'}};
244: }
245: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 246: push(@prefs_order,'loadbalancing');
247: }
1.30 raeburn 248: my %prefs = (
249: 'rolecolors' =>
250: { text => 'Default color schemes',
1.67 raeburn 251: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 252: header => [{col1 => 'Student Settings',
253: col2 => '',},
254: {col1 => 'Coordinator Settings',
255: col2 => '',},
256: {col1 => 'Author Settings',
257: col2 => '',},
258: {col1 => 'Administrator Settings',
259: col2 => '',}],
1.160.6.37 raeburn 260: print => \&print_rolecolors,
261: modify => \&modify_rolecolors,
1.30 raeburn 262: },
1.110 raeburn 263: 'login' =>
1.30 raeburn 264: { text => 'Log-in page options',
1.67 raeburn 265: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 266: header => [{col1 => 'Log-in Page Items',
267: col2 => '',},
268: {col1 => 'Log-in Help',
1.160.6.56 raeburn 269: col2 => 'Value'},
270: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 271: col2 => 'Value'},
272: {col1 => 'SSO',
273: col2 => 'Dual login: SSO and non-SSO options'},
274: ],
1.160.6.37 raeburn 275: print => \&print_login,
276: modify => \&modify_login,
1.30 raeburn 277: },
1.43 raeburn 278: 'defaults' =>
1.160.6.40 raeburn 279: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 280: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 281: header => [{col1 => 'Setting',
1.160.6.40 raeburn 282: col2 => 'Value'},
283: {col1 => 'Institutional user types',
1.160.6.93 raeburn 284: col2 => 'Name displayed'}],
1.160.6.37 raeburn 285: print => \&print_defaults,
286: modify => \&modify_defaults,
1.43 raeburn 287: },
1.160.6.113 raeburn 288: 'wafproxy' =>
289: { text => 'Web Application Firewall/Reverse Proxy',
290: help => 'Domain_Configuration_WAF_Proxy',
291: header => [{col1 => 'Domain(s)',
292: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
293: },
294: {col1 => 'Domain(s)',
295: col2 => 'WAF Configuration',}],
296: print => \&print_wafproxy,
297: modify => \&modify_wafproxy,
298: },
1.160.6.98 raeburn 299: 'passwords' =>
300: { text => 'Passwords (Internal authentication)',
301: help => 'Domain_Configuration_Passwords',
302: header => [{col1 => 'Resetting Forgotten Password',
303: col2 => 'Settings'},
304: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
305: col2 => 'Settings'},
306: {col1 => 'Rules for LON-CAPA Passwords',
307: col2 => 'Settings'},
308: {col1 => 'Course Owner Changing Student Passwords',
309: col2 => 'Settings'}],
310: print => \&print_passwords,
311: modify => \&modify_passwords,
312: },
1.30 raeburn 313: 'quotas' =>
1.160.6.20 raeburn 314: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 315: help => 'Domain_Configuration_Quotas',
1.77 raeburn 316: header => [{col1 => 'User affiliation',
1.72 raeburn 317: col2 => 'Available tools',
1.160.6.28 raeburn 318: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 319: print => \&print_quotas,
320: modify => \&modify_quotas,
1.30 raeburn 321: },
322: 'autoenroll' =>
323: { text => 'Auto-enrollment settings',
1.67 raeburn 324: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 325: header => [{col1 => 'Configuration setting',
326: col2 => 'Value(s)'}],
1.160.6.37 raeburn 327: print => \&print_autoenroll,
328: modify => \&modify_autoenroll,
1.30 raeburn 329: },
330: 'autoupdate' =>
331: { text => 'Auto-update settings',
1.67 raeburn 332: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 333: header => [{col1 => 'Setting',
334: col2 => 'Value',},
1.131 raeburn 335: {col1 => 'Setting',
336: col2 => 'Affiliation'},
1.43 raeburn 337: {col1 => 'User population',
1.160.6.35 raeburn 338: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 339: print => \&print_autoupdate,
340: modify => \&modify_autoupdate,
1.30 raeburn 341: },
1.125 raeburn 342: 'autocreate' =>
343: { text => 'Auto-course creation settings',
344: help => 'Domain_Configuration_Auto_Creation',
345: header => [{col1 => 'Configuration Setting',
346: col2 => 'Value',}],
1.160.6.37 raeburn 347: print => \&print_autocreate,
348: modify => \&modify_autocreate,
1.125 raeburn 349: },
1.30 raeburn 350: 'directorysrch' =>
1.160.6.72 raeburn 351: { text => 'Directory searches',
1.67 raeburn 352: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 353: header => [{col1 => 'Institutional Directory Setting',
354: col2 => 'Value',},
355: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 356: col2 => 'Value',}],
1.160.6.37 raeburn 357: print => \&print_directorysrch,
358: modify => \&modify_directorysrch,
1.30 raeburn 359: },
360: 'contacts' =>
1.160.6.78 raeburn 361: { text => 'E-mail addresses and helpform',
1.67 raeburn 362: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 363: header => [{col1 => 'Default e-mail addresses',
364: col2 => 'Value',},
365: {col1 => 'Recipient(s) for notifications',
366: col2 => 'Value',},
1.160.6.107 raeburn 367: {col1 => 'Nightly status check e-mail',
368: col2 => 'Settings',},
1.160.6.78 raeburn 369: {col1 => 'Ask helpdesk form settings',
370: col2 => 'Value',},],
1.160.6.37 raeburn 371: print => \&print_contacts,
372: modify => \&modify_contacts,
1.30 raeburn 373: },
374: 'usercreation' =>
375: { text => 'User creation',
1.67 raeburn 376: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 377: header => [{col1 => 'Format rule type',
378: col2 => 'Format rules in force'},
1.34 raeburn 379: {col1 => 'User account creation',
380: col2 => 'Usernames which may be created',},
1.30 raeburn 381: {col1 => 'Context',
1.43 raeburn 382: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 383: print => \&print_usercreation,
384: modify => \&modify_usercreation,
1.30 raeburn 385: },
1.160.6.34 raeburn 386: 'selfcreation' =>
387: { text => 'Users self-creating accounts',
388: help => 'Domain_Configuration_Self_Creation',
389: header => [{col1 => 'Self-creation with institutional username',
390: col2 => 'Enabled?'},
391: {col1 => 'Institutional user type (login/SSO self-creation)',
392: col2 => 'Information user can enter'},
1.160.6.93 raeburn 393: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 394: col2 => 'Settings'}],
1.160.6.37 raeburn 395: print => \&print_selfcreation,
396: modify => \&modify_selfcreation,
1.160.6.34 raeburn 397: },
1.69 raeburn 398: 'usermodification' =>
1.33 raeburn 399: { text => 'User modification',
1.67 raeburn 400: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 401: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 402: col2 => 'User information updatable in author context'},
1.33 raeburn 403: {col1 => 'Target user has role',
1.160.6.35 raeburn 404: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 405: print => \&print_usermodification,
406: modify => \&modify_usermodification,
1.33 raeburn 407: },
1.69 raeburn 408: 'scantron' =>
1.160.6.97 raeburn 409: { text => 'Bubblesheet format',
1.67 raeburn 410: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 411: header => [ {col1 => 'Bubblesheet format file',
412: col2 => ''},
413: {col1 => 'Bubblesheet data upload formats',
414: col2 => 'Settings'}],
1.160.6.37 raeburn 415: print => \&print_scantron,
416: modify => \&modify_scantron,
1.46 raeburn 417: },
1.86 raeburn 418: 'requestcourses' =>
419: {text => 'Request creation of courses',
420: help => 'Domain_Configuration_Request_Courses',
421: header => [{col1 => 'User affiliation',
1.102 raeburn 422: col2 => 'Availability/Processing of requests',},
423: {col1 => 'Setting',
1.160.6.30 raeburn 424: col2 => 'Value'},
425: {col1 => 'Available textbooks',
1.160.6.39 raeburn 426: col2 => ''},
1.160.6.46 raeburn 427: {col1 => 'Available templates',
428: col2 => ''},
1.160.6.39 raeburn 429: {col1 => 'Validation (not official courses)',
430: col2 => 'Value'},],
1.160.6.37 raeburn 431: print => \&print_quotas,
432: modify => \&modify_quotas,
1.86 raeburn 433: },
1.160.6.5 raeburn 434: 'requestauthor' =>
1.160.6.34 raeburn 435: {text => 'Request Authoring Space',
1.160.6.5 raeburn 436: help => 'Domain_Configuration_Request_Author',
437: header => [{col1 => 'User affiliation',
438: col2 => 'Availability/Processing of requests',},
439: {col1 => 'Setting',
440: col2 => 'Value'}],
1.160.6.37 raeburn 441: print => \&print_quotas,
442: modify => \&modify_quotas,
1.160.6.5 raeburn 443: },
1.69 raeburn 444: 'coursecategories' =>
1.120 raeburn 445: { text => 'Cataloging of courses/communities',
1.67 raeburn 446: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 447: header => [{col1 => 'Catalog type/availability',
448: col2 => '',},
449: {col1 => 'Category settings for standard catalog',
1.57 raeburn 450: col2 => '',},
451: {col1 => 'Categories',
452: col2 => '',
453: }],
1.160.6.37 raeburn 454: print => \&print_coursecategories,
455: modify => \&modify_coursecategories,
1.69 raeburn 456: },
457: 'serverstatuses' =>
1.77 raeburn 458: {text => 'Access to server status pages',
1.69 raeburn 459: help => 'Domain_Configuration_Server_Status',
460: header => [{col1 => 'Status Page',
461: col2 => 'Other named users',
462: col3 => 'Specific IPs',
463: }],
1.160.6.37 raeburn 464: print => \&print_serverstatuses,
465: modify => \&modify_serverstatuses,
1.69 raeburn 466: },
1.160.6.73 raeburn 467: 'helpsettings' =>
468: {text => 'Support settings',
469: help => 'Domain_Configuration_Help_Settings',
470: header => [{col1 => 'Help Page Settings (logged-in users)',
471: col2 => 'Value'},
472: {col1 => 'Helpdesk Roles',
473: col2 => 'Settings'},],
474: print => \&print_helpsettings,
475: modify => \&modify_helpsettings,
476: },
1.160.6.39 raeburn 477: 'coursedefaults' =>
1.160.6.16 raeburn 478: {text => 'Course/Community defaults',
479: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 480: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
481: col2 => 'Value',},
482: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 483: col2 => 'Value',},],
1.160.6.37 raeburn 484: print => \&print_coursedefaults,
485: modify => \&modify_coursedefaults,
486: },
1.160.6.39 raeburn 487: 'selfenrollment' =>
1.160.6.37 raeburn 488: {text => 'Self-enrollment in Course/Community',
489: help => 'Domain_Configuration_Selfenrollment',
490: header => [{col1 => 'Configuration Rights',
491: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
492: {col1 => 'Defaults',
493: col2 => 'Value'},
494: {col1 => 'Self-enrollment validation (optional)',
495: col2 => 'Value'},],
496: print => \&print_selfenrollment,
497: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 498: },
1.141 raeburn 499: 'usersessions' =>
1.145 raeburn 500: {text => 'User session hosting/offloading',
1.137 raeburn 501: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 502: header => [{col1 => 'Domain server',
503: col2 => 'Servers to offload sessions to when busy'},
504: {col1 => 'Hosting of users from other domains',
1.137 raeburn 505: col2 => 'Rules'},
506: {col1 => "Hosting domain's own users elsewhere",
507: col2 => 'Rules'}],
1.160.6.37 raeburn 508: print => \&print_usersessions,
509: modify => \&modify_usersessions,
1.137 raeburn 510: },
1.160.6.78 raeburn 511: 'loadbalancing' =>
1.160.6.7 raeburn 512: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 513: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 514: header => [{col1 => 'Balancers',
1.150 raeburn 515: col2 => 'Default destinations',
1.160.6.13 raeburn 516: col3 => 'User affiliation',
1.150 raeburn 517: col4 => 'Overrides'},
518: ],
1.160.6.37 raeburn 519: print => \&print_loadbalancing,
520: modify => \&modify_loadbalancing,
1.150 raeburn 521: },
1.160.6.118.2 1(raebur 522:1): 'ltitools' =>
523:1): {text => 'External Tools (LTI)',
524:1): help => 'Domain_Configuration_LTI_Tools',
525:1): header => [{col1 => 'Setting',
526:1): col2 => 'Value',}],
527:1): print => \&print_ltitools,
528:1): modify => \&modify_ltitools,
529:1): },
1.160.6.113 raeburn 530: 'ipaccess' =>
531: {text => 'IP-based access control',
532: help => 'Domain_Configuration_IP_Access',
533: header => [{col1 => 'Setting',
534: col2 => 'Value'},],
535: print => \&print_ipaccess,
536: modify => \&modify_ipaccess,
537: },
1.3 raeburn 538: );
1.110 raeburn 539: if (keys(%servers) > 1) {
540: $prefs{'login'} = { text => 'Log-in page options',
541: help => 'Domain_Configuration_Login_Page',
542: header => [{col1 => 'Log-in Service',
543: col2 => 'Server Setting',},
544: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 545: col2 => ''},
546: {col1 => 'Log-in Help',
1.160.6.56 raeburn 547: col2 => 'Value'},
548: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 549: col2 => 'Value'},
550: {col1 => 'SSO',
551: col2 => 'Dual login: SSO and non-SSO options'},
552: ],
1.160.6.37 raeburn 553: print => \&print_login,
554: modify => \&modify_login,
1.110 raeburn 555: };
556: }
1.160.6.13 raeburn 557:
1.6 raeburn 558: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 559: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 560: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 561: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 562: text=>"Settings to display/modify"});
1.9 raeburn 563: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 564:
1.3 raeburn 565: if ($phase eq 'process') {
1.160.6.27 raeburn 566: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
567: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 568: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 569: $r->rflush();
1.160.6.27 raeburn 570: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 571: }
1.30 raeburn 572: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 573: my $js = &recaptcha_js().
1.160.6.40 raeburn 574: &toggle_display_js();
1.160.6.7 raeburn 575: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 576: my ($othertitle,$usertypes,$types) =
577: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 578: $js .= &lonbalance_targets_js($dom,$types,\%servers,
579: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 580: &new_spares_js().
581: &common_domprefs_js().
582: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 583: }
1.160.6.30 raeburn 584: if (grep(/^requestcourses$/,@actions)) {
585: my $javascript_validations;
586: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
587: $js .= <<END;
588: <script type="text/javascript">
589: $javascript_validations
590: </script>
591: $coursebrowserjs
592: END
1.160.6.113 raeburn 593: } elsif (grep(/^ipaccess$/,@actions)) {
594: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 595: }
1.160.6.93 raeburn 596: if (grep(/^selfcreation$/,@actions)) {
597: $js .= &selfcreate_javascript();
598: }
1.160.6.78 raeburn 599: if (grep(/^contacts$/,@actions)) {
600: $js .= &contacts_javascript();
601: }
1.160.6.97 raeburn 602: if (grep(/^scantron$/,@actions)) {
603: $js .= &scantron_javascript();
604: }
1.150 raeburn 605: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 606: } else {
1.160.6.11 raeburn 607: # check if domconfig user exists for the domain.
608: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 609: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 610: &config_check($dom,$confname,$servadm);
611: unless ($configuserok eq 'ok') {
612: &Apache::lonconfigsettings::print_header($r,$phase,$context);
613: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
614: $confname).
615: '<br />'
616: );
617: if ($switchserver) {
618: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
619: '<br />'.
620: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
621: '<br />'.
622: &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).
623: '<br />'.
624: &mt('To do that now, use the following link: [_1]',$switchserver)
625: );
626: } else {
627: $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.').
628: '<br />'.
629: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
630: );
631: }
632: $r->print(&Apache::loncommon::end_page());
633: return OK;
634: }
1.21 raeburn 635: if (keys(%domconfig) == 0) {
636: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 637: my @ids=&Apache::lonnet::current_machine_ids();
638: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 639: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 640: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 641: my $custom_img_count = 0;
642: foreach my $img (@loginimages) {
643: if ($designhash{$dom.'.login.'.$img} ne '') {
644: $custom_img_count ++;
645: }
646: }
647: foreach my $role (@roles) {
648: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
649: $custom_img_count ++;
650: }
651: }
652: if ($custom_img_count > 0) {
1.94 raeburn 653: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 654: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 655: $r->print(
656: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
657: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
658: &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 />'.
659: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
660: if ($switch_server) {
1.30 raeburn 661: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 662: }
1.91 raeburn 663: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 664: return OK;
665: }
666: }
667: }
1.91 raeburn 668: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 669: }
670: return OK;
671: }
672:
673: sub process_changes {
1.160.6.24 raeburn 674: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 675: my %domconfig;
676: if (ref($values) eq 'HASH') {
677: %domconfig = %{$values};
678: }
1.3 raeburn 679: my $output;
680: if ($action eq 'login') {
1.160.6.24 raeburn 681: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 682: } elsif ($action eq 'rolecolors') {
1.9 raeburn 683: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 684: $lastactref,%domconfig);
1.3 raeburn 685: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 686: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 687: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 688: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 689: } elsif ($action eq 'autoupdate') {
690: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 691: } elsif ($action eq 'autocreate') {
692: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 693: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 694: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 695: } elsif ($action eq 'usercreation') {
1.28 raeburn 696: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 697: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 698: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 699: } elsif ($action eq 'usermodification') {
700: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 701: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 702: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 703: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 704: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 705: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 706: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 707: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 708: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 709: } elsif ($action eq 'serverstatuses') {
710: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 711: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 712: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 713: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 714: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 715: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 716: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 717: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 718: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 719: } elsif ($action eq 'selfenrollment') {
720: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 721: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 722: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 723: } elsif ($action eq 'loadbalancing') {
724: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98 raeburn 725: } elsif ($action eq 'passwords') {
726: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.118.2 1(raebur 727:1): } elsif ($action eq 'ltitools') {
728:1): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.160.6.113 raeburn 729: } elsif ($action eq 'wafproxy') {
730: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
731: } elsif ($action eq 'ipaccess') {
732: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 733: }
734: return $output;
735: }
736:
737: sub print_config_box {
1.9 raeburn 738: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 739: my $rowtotal = 0;
1.49 raeburn 740: my $output;
741: if ($action eq 'coursecategories') {
742: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 743: } elsif ($action eq 'defaults') {
744: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 745: } elsif ($action eq 'passwords') {
746: $output = &passwords_javascript();
1.160.6.73 raeburn 747: } elsif ($action eq 'helpsettings') {
748: my (%privs,%levelscurrent);
749: my %full=();
750: my %levels=(
751: course => {},
752: domain => {},
753: system => {},
754: );
755: my $context = 'domain';
756: my $crstype = 'Course';
757: my $formname = 'display';
758: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
759: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
760: $output =
761: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
762: \@templateroles);
1.160.6.118.2 1(raebur 763:1): } elsif ($action eq 'ltitools') {
764:1): $output .= <itools_javascript($settings);
1.160.6.113 raeburn 765: } elsif ($action eq 'wafproxy') {
766: $output .= &wafproxy_javascript($dom);
767: } elsif ($action eq 'autoupdate') {
768: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 769: } elsif ($action eq 'autoenroll') {
770: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 771: } elsif ($action eq 'login') {
772: $output .= &saml_javascript();
773: } elsif ($action eq 'ipaccess') {
774: $output .= &ipaccess_javascript($settings);
1.91 raeburn 775: }
1.160.6.40 raeburn 776: $output .=
1.30 raeburn 777: '<table class="LC_nested_outer">
1.3 raeburn 778: <tr>
1.160.6.113 raeburn 779: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 780: &mt($item->{text}).' '.
781: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
782: '</tr>';
1.30 raeburn 783: $rowtotal ++;
1.110 raeburn 784: my $numheaders = 1;
785: if (ref($item->{'header'}) eq 'ARRAY') {
786: $numheaders = scalar(@{$item->{'header'}});
787: }
788: if ($numheaders > 1) {
1.64 raeburn 789: my $colspan = '';
1.145 raeburn 790: my $rightcolspan = '';
1.160.6.104 raeburn 791: my $leftnobr = '';
1.160.6.42 raeburn 792: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 793: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 794: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 795: $colspan = ' colspan="2"';
796: }
1.145 raeburn 797: if ($action eq 'usersessions') {
798: $rightcolspan = ' colspan="3"';
799: }
1.160.6.104 raeburn 800: if ($action eq 'passwords') {
801: $leftnobr = ' LC_nobreak';
802: }
1.30 raeburn 803: $output .= '
1.3 raeburn 804: <tr>
805: <td>
806: <table class="LC_nested">
807: <tr class="LC_info_row">
1.160.6.104 raeburn 808: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 809: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 810: </tr>';
1.69 raeburn 811: $rowtotal ++;
1.160.6.37 raeburn 812: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 813: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 814: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 815: ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 816: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 817: } elsif ($action eq 'passwords') {
818: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 819: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 820: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 821: } elsif ($action eq 'scantron') {
822: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 823: } elsif ($action eq 'login') {
1.160.6.113 raeburn 824: if ($numheaders == 5) {
1.160.6.5 raeburn 825: $colspan = ' colspan="2"';
826: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
827: } else {
828: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
829: }
1.160.6.37 raeburn 830: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 831: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 832: } elsif ($action eq 'rolecolors') {
1.30 raeburn 833: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 834: }
1.30 raeburn 835: $output .= '
1.6 raeburn 836: </table>
837: </td>
838: </tr>
839: <tr>
840: <td>
841: <table class="LC_nested">
842: <tr class="LC_info_row">
1.160.6.37 raeburn 843: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 844: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 845: </tr>';
846: $rowtotal ++;
1.160.6.37 raeburn 847: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
848: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 849: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98 raeburn 850: ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42 raeburn 851: if ($action eq 'coursecategories') {
852: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
853: $colspan = ' colspan="2"';
1.160.6.98 raeburn 854: } elsif ($action eq 'passwords') {
855: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 856: } else {
857: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
858: }
859: $output .= '
1.63 raeburn 860: </table>
861: </td>
862: </tr>
863: <tr>
864: <td>
865: <table class="LC_nested">
866: <tr class="LC_info_row">
1.160.6.113 raeburn 867: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 868: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 869: </tr>'."\n";
870: if ($action eq 'coursecategories') {
871: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 872: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 873: if ($action eq 'passwords') {
874: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
875: } else {
876: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
877: }
878: $output .= '
1.160.6.98 raeburn 879: </tr>
880: </table>
881: </td>
882: </tr>
883: <tr>
884: <td>
885: <table class="LC_nested">
886: <tr class="LC_info_row">
1.160.6.113 raeburn 887: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 888: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 889: if ($action eq 'passwords') {
890: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
891: } else {
892: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
893: }
894: $output .= '
1.160.6.98 raeburn 895: </table>
896: </td>
897: </tr>
898: <tr>';
1.160.6.42 raeburn 899: } else {
900: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
901: }
1.63 raeburn 902: $rowtotal ++;
1.160.6.57 raeburn 903: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 904: ($action eq 'defaults') || ($action eq 'directorysrch') ||
1.160.6.113 raeburn 905: ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
1.160.6.37 raeburn 906: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 907: } elsif ($action eq 'scantron') {
908: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 909: } elsif ($action eq 'login') {
1.160.6.113 raeburn 910: if ($numheaders == 5) {
1.160.6.5 raeburn 911: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
912: </table>
913: </td>
914: </tr>
915: <tr>
916: <td>
917: <table class="LC_nested">
918: <tr class="LC_info_row">
919: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 920: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 921: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
922: $rowtotal ++;
923: } else {
924: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
925: }
1.160.6.56 raeburn 926: $output .= '
927: </table>
928: </td>
929: </tr>
930: <tr>
931: <td>
932: <table class="LC_nested">
933: <tr class="LC_info_row">';
1.160.6.113 raeburn 934: if ($numheaders == 5) {
1.160.6.56 raeburn 935: $output .= '
936: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
937: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
938: </tr>';
939: } else {
940: $output .= '
941: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
942: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
943: </tr>';
944: }
945: $rowtotal ++;
1.160.6.113 raeburn 946: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
947: </table>
948: </td>
949: </tr>
950: <tr>
951: <td>
952: <table class="LC_nested">
953: <tr class="LC_info_row">';
954: if ($numheaders == 5) {
955: $output .= '
956: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
957: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
958: </tr>';
959: } else {
960: $output .= '
961: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
962: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
963: </tr>';
964: }
965: $rowtotal ++;
966: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 967: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 968: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
969: $rowtotal ++;
970: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 971: </table>
972: </td>
973: </tr>
974: <tr>
975: <td>
976: <table class="LC_nested">
977: <tr class="LC_info_row">
978: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
979: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 980: &textbookcourses_javascript($settings).
981: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
982: </table>
983: </td>
984: </tr>
985: <tr>
986: <td>
987: <table class="LC_nested">
988: <tr class="LC_info_row">
989: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
990: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
991: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 992: </table>
993: </td>
994: </tr>
995: <tr>
996: <td>
997: <table class="LC_nested">
998: <tr class="LC_info_row">
1.160.6.46 raeburn 999: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1000: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1001: </tr>'.
1002: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1003: } elsif ($action eq 'requestauthor') {
1004: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1005: $rowtotal ++;
1.122 jms 1006: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1007: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1008: </table>
1009: </td>
1010: </tr>
1011: <tr>
1012: <td>
1013: <table class="LC_nested">
1014: <tr class="LC_info_row">
1.69 raeburn 1015: <td class="LC_left_item"'.$colspan.' valign="top">'.
1016: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1017: <td class="LC_right_item" valign="top">'.
1018: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1019: </tr>'.
1.30 raeburn 1020: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1021: </table>
1022: </td>
1023: </tr>
1024: <tr>
1025: <td>
1026: <table class="LC_nested">
1027: <tr class="LC_info_row">
1.59 bisitz 1028: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1029: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1030: </tr>'.
1.30 raeburn 1031: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1032: $rowtotal += 2;
1.6 raeburn 1033: }
1.3 raeburn 1034: } else {
1.30 raeburn 1035: $output .= '
1.3 raeburn 1036: <tr>
1037: <td>
1038: <table class="LC_nested">
1.30 raeburn 1039: <tr class="LC_info_row">';
1.160.6.72 raeburn 1040: if ($action eq 'login') {
1.30 raeburn 1041: $output .= '
1.59 bisitz 1042: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1043: } elsif ($action eq 'serverstatuses') {
1044: $output .= '
1045: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1046: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1047:
1.6 raeburn 1048: } else {
1.30 raeburn 1049: $output .= '
1.69 raeburn 1050: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1051: }
1.72 raeburn 1052: if (defined($item->{'header'}->[0]->{'col3'})) {
1053: $output .= '<td class="LC_left_item" valign="top">'.
1054: &mt($item->{'header'}->[0]->{'col2'});
1055: if ($action eq 'serverstatuses') {
1056: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1057: }
1.69 raeburn 1058: } else {
1059: $output .= '<td class="LC_right_item" valign="top">'.
1060: &mt($item->{'header'}->[0]->{'col2'});
1061: }
1062: $output .= '</td>';
1063: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1064: if (defined($item->{'header'}->[0]->{'col4'})) {
1065: $output .= '<td class="LC_left_item" valign="top">'.
1066: &mt($item->{'header'}->[0]->{'col3'});
1067: } else {
1068: $output .= '<td class="LC_right_item" valign="top">'.
1069: &mt($item->{'header'}->[0]->{'col3'});
1070: }
1.69 raeburn 1071: if ($action eq 'serverstatuses') {
1072: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1073: }
1074: $output .= '</td>';
1.6 raeburn 1075: }
1.150 raeburn 1076: if ($item->{'header'}->[0]->{'col4'}) {
1077: $output .= '<td class="LC_right_item" valign="top">'.
1078: &mt($item->{'header'}->[0]->{'col4'});
1079: }
1.69 raeburn 1080: $output .= '</tr>';
1.48 raeburn 1081: $rowtotal ++;
1.160.6.5 raeburn 1082: if ($action eq 'quotas') {
1.86 raeburn 1083: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1084: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1085: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 1(raebur 1086:1): ($action eq 'ltitools') || ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1087: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1088: }
1.3 raeburn 1089: }
1.30 raeburn 1090: $output .= '
1.3 raeburn 1091: </table>
1092: </td>
1093: </tr>
1.30 raeburn 1094: </table><br />';
1095: return ($output,$rowtotal);
1.1 raeburn 1096: }
1097:
1.3 raeburn 1098: sub print_login {
1.160.6.5 raeburn 1099: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1100: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1101: my %choices = &login_choices();
1.160.6.113 raeburn 1102: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1103: %lt = &login_file_options();
1104: $switchserver = &check_switchserver($dom,$confname);
1105: }
1.110 raeburn 1106:
1.160.6.5 raeburn 1107: if ($caller eq 'service') {
1.149 raeburn 1108: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1109: my $choice = $choices{'disallowlogin'};
1110: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1111: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1112: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1113: '<th>'.$choices{'server'}.'</th>'.
1114: '<th>'.$choices{'serverpath'}.'</th>'.
1115: '<th>'.$choices{'custompath'}.'</th>'.
1116: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1117: my %disallowed;
1118: if (ref($settings) eq 'HASH') {
1119: if (ref($settings->{'loginvia'}) eq 'HASH') {
1120: %disallowed = %{$settings->{'loginvia'}};
1121: }
1122: }
1123: foreach my $lonhost (sort(keys(%servers))) {
1124: my $direct = 'selected="selected"';
1.128 raeburn 1125: if (ref($disallowed{$lonhost}) eq 'HASH') {
1126: if ($disallowed{$lonhost}{'server'} ne '') {
1127: $direct = '';
1128: }
1.110 raeburn 1129: }
1.115 raeburn 1130: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1131: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1132: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1133: '</option>';
1.160.6.13 raeburn 1134: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1135: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1136: my $selected = '';
1.128 raeburn 1137: if (ref($disallowed{$lonhost}) eq 'HASH') {
1138: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1139: $selected = 'selected="selected"';
1140: }
1.110 raeburn 1141: }
1142: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1143: $servers{$hostid}.'</option>';
1144: }
1.128 raeburn 1145: $datatable .= '</select></td>'.
1146: '<td><select name="'.$lonhost.'_serverpath">';
1147: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1148: my $pathname = $path;
1149: if ($path eq 'custom') {
1150: $pathname = &mt('Custom Path').' ->';
1151: }
1152: my $selected = '';
1153: if (ref($disallowed{$lonhost}) eq 'HASH') {
1154: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1155: $selected = 'selected="selected"';
1156: }
1157: } elsif ($path eq '') {
1158: $selected = 'selected="selected"';
1159: }
1160: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1161: }
1162: $datatable .= '</select></td>';
1163: my ($custom,$exempt);
1164: if (ref($disallowed{$lonhost}) eq 'HASH') {
1165: $custom = $disallowed{$lonhost}{'custompath'};
1166: $exempt = $disallowed{$lonhost}{'exempt'};
1167: }
1168: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1169: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1170: '</tr>';
1.110 raeburn 1171: }
1172: $datatable .= '</table></td></tr>';
1173: return $datatable;
1.160.6.5 raeburn 1174: } elsif ($caller eq 'page') {
1175: my %defaultchecked = (
1176: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1177: 'helpdesk' => 'on',
1.160.6.5 raeburn 1178: 'adminmail' => 'off',
1179: 'newuser' => 'off',
1180: );
1.160.6.14 raeburn 1181: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1182: my (%checkedon,%checkedoff);
1.42 raeburn 1183: foreach my $item (@toggles) {
1.160.6.5 raeburn 1184: if ($defaultchecked{$item} eq 'on') {
1185: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1186: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1187: } elsif ($defaultchecked{$item} eq 'off') {
1188: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1189: $checkedon{$item} = ' ';
1190: }
1.1 raeburn 1191: }
1.160.6.5 raeburn 1192: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1193:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1194: my @logintext = ('textcol','bgcol');
1195: my @bgs = ('pgbg','mainbg','sidebg');
1196: my @links = ('link','alink','vlink');
1197: my %designhash = &Apache::loncommon::get_domainconf($dom);
1198: my %defaultdesign = %Apache::loncommon::defaultdesign;
1199: my (%is_custom,%designs);
1200: my %defaults = (
1201: font => $defaultdesign{'login.font'},
1202: );
1.6 raeburn 1203: foreach my $item (@images) {
1.160.6.5 raeburn 1204: $defaults{$item} = $defaultdesign{'login.'.$item};
1205: $defaults{'showlogo'}{$item} = 1;
1206: }
1207: foreach my $item (@bgs) {
1208: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1209: }
1.41 raeburn 1210: foreach my $item (@logintext) {
1.160.6.5 raeburn 1211: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1212: }
1.160.6.5 raeburn 1213: foreach my $item (@links) {
1214: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1215: }
1.160.6.5 raeburn 1216: if (ref($settings) eq 'HASH') {
1217: foreach my $item (@toggles) {
1218: if ($settings->{$item} eq '1') {
1219: $checkedon{$item} = ' checked="checked" ';
1220: $checkedoff{$item} = ' ';
1221: } elsif ($settings->{$item} eq '0') {
1222: $checkedoff{$item} = ' checked="checked" ';
1223: $checkedon{$item} = ' ';
1224: }
1.6 raeburn 1225: }
1.160.6.5 raeburn 1226: foreach my $item (@images) {
1227: if (defined($settings->{$item})) {
1228: $designs{$item} = $settings->{$item};
1229: $is_custom{$item} = 1;
1230: }
1231: if (defined($settings->{'showlogo'}{$item})) {
1232: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1233: }
1234: }
1.160.6.118.2 2(raebur 1235:2): foreach my $item (@alttext) {
1236:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1237:2): if ($settings->{'alttext'}->{$item} ne '') {
1238:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1239:2): }
1240:2): }
1241:2): }
1.160.6.5 raeburn 1242: foreach my $item (@logintext) {
1243: if ($settings->{$item} ne '') {
1244: $designs{'logintext'}{$item} = $settings->{$item};
1245: $is_custom{$item} = 1;
1246: }
1247: }
1248: if ($settings->{'font'} ne '') {
1249: $designs{'font'} = $settings->{'font'};
1250: $is_custom{'font'} = 1;
1251: }
1252: foreach my $item (@bgs) {
1253: if ($settings->{$item} ne '') {
1254: $designs{'bgs'}{$item} = $settings->{$item};
1255: $is_custom{$item} = 1;
1256: }
1257: }
1258: foreach my $item (@links) {
1259: if ($settings->{$item} ne '') {
1260: $designs{'links'}{$item} = $settings->{$item};
1261: $is_custom{$item} = 1;
1262: }
1263: }
1264: } else {
1265: if ($designhash{$dom.'.login.font'} ne '') {
1266: $designs{'font'} = $designhash{$dom.'.login.font'};
1267: $is_custom{'font'} = 1;
1268: }
1269: foreach my $item (@images) {
1270: if ($designhash{$dom.'.login.'.$item} ne '') {
1271: $designs{$item} = $designhash{$dom.'.login.'.$item};
1272: $is_custom{$item} = 1;
1273: }
1274: }
1275: foreach my $item (@bgs) {
1276: if ($designhash{$dom.'.login.'.$item} ne '') {
1277: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1278: $is_custom{$item} = 1;
1279: }
1280: }
1281: foreach my $item (@links) {
1282: if ($designhash{$dom.'.login.'.$item} ne '') {
1283: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1284: $is_custom{$item} = 1;
1285: }
1.6 raeburn 1286: }
1287: }
1.160.6.5 raeburn 1288: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1289: logo => 'Institution Logo',
1290: domlogo => 'Domain Logo',
1291: login => 'Login box');
1292: my $itemcount = 1;
1293: foreach my $item (@toggles) {
1294: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1295: $datatable .=
1296: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1297: '</td><td>'.
1298: '<span class="LC_nobreak"><label><input type="radio" name="'.
1299: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1300: '</label> <label><input type="radio" name="'.$item.'"'.
1301: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1302: '</tr>';
1303: $itemcount ++;
1.6 raeburn 1304: }
1.160.6.5 raeburn 1305: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1306: $datatable .= '</tr></table></td></tr>';
1307: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1308: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1309: my $itemcount = 1;
1310: $defaulturl = '/adm/loginproblems.html';
1311: $defaulttype = 'default';
1312: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1313: my @currlangs;
1314: if (ref($settings) eq 'HASH') {
1315: if (ref($settings->{'helpurl'}) eq 'HASH') {
1316: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1317: next if ($settings->{'helpurl'}{$key} eq '');
1318: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1319: $type{$key} = 'custom';
1320: unless ($key eq 'nolang') {
1321: push(@currlangs,$key);
1322: }
1323: }
1324: } elsif ($settings->{'helpurl'} ne '') {
1325: $type{'nolang'} = 'custom';
1326: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1327: }
1328: }
1.160.6.5 raeburn 1329: foreach my $lang ('nolang',sort(@currlangs)) {
1330: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1331: $datatable .= '<tr'.$css_class.'>';
1332: if ($url{$lang} eq '') {
1333: $url{$lang} = $defaulturl;
1334: }
1335: if ($type{$lang} eq '') {
1336: $type{$lang} = $defaulttype;
1337: }
1338: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1339: if ($lang eq 'nolang') {
1340: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1341: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1342: } else {
1343: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1344: $langchoices{$lang},
1345: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1346: }
1347: $datatable .= '</span></td>'."\n".
1348: '<td class="LC_left_item">';
1349: if ($type{$lang} eq 'custom') {
1350: $datatable .= '<span class="LC_nobreak"><label>'.
1351: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1352: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1353: } else {
1354: $datatable .= $lt{'upl'};
1355: }
1356: $datatable .='<br />';
1357: if ($switchserver) {
1358: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1359: } else {
1360: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1361: }
1.160.6.5 raeburn 1362: $datatable .= '</td></tr>';
1363: $itemcount ++;
1.6 raeburn 1364: }
1.160.6.5 raeburn 1365: my @addlangs;
1366: foreach my $lang (sort(keys(%langchoices))) {
1367: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1368: push(@addlangs,$lang);
1369: }
1370: if (@addlangs > 0) {
1371: my %toadd;
1372: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1373: $toadd{''} = &mt('Select');
1374: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1375: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1376: &mt('Add log-in help page for a specific language:').' '.
1377: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1378: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1379: if ($switchserver) {
1380: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1381: } else {
1382: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1383: }
1.160.6.5 raeburn 1384: $datatable .= '</td></tr>';
1385: $itemcount ++;
1.6 raeburn 1386: }
1.160.6.5 raeburn 1387: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1388: } elsif ($caller eq 'headtag') {
1389: my %domservers = &Apache::lonnet::get_servers($dom);
1390: my $choice = $choices{'headtag'};
1391: $css_class = ' class="LC_odd_row"';
1392: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1393: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1394: '<th>'.$choices{'current'}.'</th>'.
1395: '<th>'.$choices{'action'}.'</th>'.
1396: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1397: my (%currurls,%currexempt);
1398: if (ref($settings) eq 'HASH') {
1399: if (ref($settings->{'headtag'}) eq 'HASH') {
1400: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1401: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1402: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1403: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1404: }
1405: }
1406: }
1407: }
1408: foreach my $lonhost (sort(keys(%domservers))) {
1409: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1410: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1411: if ($currurls{$lonhost}) {
1412: $datatable .= '<td class="LC_right_item"><a href="'.
1413: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1414: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1415: '">'.$lt{'curr'}.'</a></td>'.
1416: '<td><span class="LC_nobreak"><label>'.
1417: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1418: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1419: } else {
1420: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1421: }
1422: $datatable .='<br />';
1423: if ($switchserver) {
1424: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1425: } else {
1426: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1427: }
1.160.6.87 raeburn 1428: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1429: }
1430: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1431: } elsif ($caller eq 'saml') {
1432: my %domservers = &Apache::lonnet::get_servers($dom);
1433: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1434: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1435: '<th>'.$choices{'samllanding'}.'</th>'.
1436: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1437: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1438: foreach my $lonhost (keys(%domservers)) {
1439: $samlurl{$lonhost} = '/adm/sso';
1440: $styleon{$lonhost} = 'display:none';
1441: $styleoff{$lonhost} = '';
1442: }
1443: if (ref($settings->{'saml'}) eq 'HASH') {
1444: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1445: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1446: $saml{$lonhost} = 1;
1447: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1448: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1449: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1450: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1451: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1452: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1453: $styleon{$lonhost} = '';
1454: $styleoff{$lonhost} = 'display:none';
1455: } else {
1456: $styleon{$lonhost} = 'display:none';
1457: $styleoff{$lonhost} = '';
1458: }
1459: }
1460: }
1461: my $itemcount = 1;
1462: foreach my $lonhost (sort(keys(%domservers))) {
1463: my $samlon = ' ';
1464: my $samloff = ' checked="checked" ';
1465: if ($saml{$lonhost}) {
1466: $samlon = $samloff;
1467: $samloff = ' ';
1468: }
1469: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1470: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1471: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1472: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1473: &mt('No').'</label>'.(' 'x2).
1474: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1475: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1476: &mt('Yes').'</label></span></td>'.
1477: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1478: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1479: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1480: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1481: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1482: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1483: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1484: $samltext{$lonhost}.'" /></td><td>';
1485: if ($samlimg{$lonhost}) {
1486: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1487: '<span class="LC_nobreak"><label>'.
1488: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1489: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1490: } else {
1491: $datatable .= $lt{'upl'};
1492: }
1493: $datatable .='<br />';
1494: if ($switchserver) {
1495: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1496: } else {
1497: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1498: }
1499: $datatable .= '</td>'.
1500: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1501: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1502: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1503: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1504: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1505: $samltitle{$lonhost}.'</textarea></td>'.
1506: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1507: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1508: '</table></td>'.
1509: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1510: $itemcount ++;
1511: }
1512: $datatable .= '</table></td></tr>';
1.1 raeburn 1513: }
1.6 raeburn 1514: return $datatable;
1515: }
1516:
1517: sub login_choices {
1518: my %choices =
1519: &Apache::lonlocal::texthash (
1.116 bisitz 1520: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1521: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1522: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1523: disallowlogin => "Login page requests redirected",
1524: hostid => "Server",
1.128 raeburn 1525: server => "Redirect to:",
1526: serverpath => "Path",
1527: custompath => "Custom",
1528: exempt => "Exempt IP(s)",
1.110 raeburn 1529: directlogin => "No redirect",
1530: newuser => "Link to create a user account",
1531: img => "Header",
1532: logo => "Main Logo",
1533: domlogo => "Domain Logo",
1534: login => "Log-in Header",
1535: textcol => "Text color",
1536: bgcol => "Box color",
1537: bgs => "Background colors",
1538: links => "Link colors",
1539: font => "Font color",
1540: pgbg => "Header",
1541: mainbg => "Page",
1542: sidebg => "Login box",
1543: link => "Link",
1544: alink => "Active link",
1545: vlink => "Visited link",
1.160.6.56 raeburn 1546: headtag => "Custom markup",
1547: action => "Action",
1548: current => "Current",
1.160.6.113 raeburn 1549: samllanding => "Dual login?",
1550: samloptions => "Options",
1.160.6.118.2 2(raebur 1551:2): alttext => "Alt text",
1.6 raeburn 1552: );
1553: return %choices;
1554: }
1555:
1.160.6.113 raeburn 1556: sub login_file_options {
1557: return &Apache::lonlocal::texthash(
1558: del => 'Delete?',
1559: rep => 'Replace:',
1560: upl => 'Upload:',
1561: curr => 'View contents',
1562: default => 'Default',
1563: custom => 'Custom',
1564: none => 'None',
1565: );
1566: }
1567:
1568: sub print_ipaccess {
1569: my ($dom,$settings,$rowtotal) = @_;
1570: my $css_class;
1571: my $itemcount = 0;
1572: my $datatable;
1573: my %ordered;
1574: if (ref($settings) eq 'HASH') {
1575: foreach my $item (keys(%{$settings})) {
1576: if (ref($settings->{$item}) eq 'HASH') {
1577: my $num = $settings->{$item}{'order'};
1578: if ($num eq '') {
1579: $num = scalar(keys(%{$settings}));
1580: }
1581: $ordered{$num} = $item;
1582: }
1583: }
1584: }
1585: my $maxnum = scalar(keys(%ordered));
1586: if (keys(%ordered)) {
1587: my @items = sort { $a <=> $b } keys(%ordered);
1588: for (my $i=0; $i<@items; $i++) {
1589: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1590: my $item = $ordered{$items[$i]};
1591: my ($name,$ipranges,%commblocks,%courses);
1592: if (ref($settings->{$item}) eq 'HASH') {
1593: $name = $settings->{$item}->{'name'};
1594: $ipranges = $settings->{$item}->{'ip'};
1595: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1596: %commblocks = %{$settings->{$item}->{'commblocks'}};
1597: }
1598: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1599: %courses = %{$settings->{$item}->{'courses'}};
1600: }
1601: }
1602: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1603: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1604: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1605: for (my $k=0; $k<=$maxnum; $k++) {
1606: my $vpos = $k+1;
1607: my $selstr;
1608: if ($k == $i) {
1609: $selstr = ' selected="selected" ';
1610: }
1611: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1612: }
1613: $datatable .= '</select>'.(' 'x2).
1614: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1615: &mt('Delete?').'</label></span></td>'.
1616: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1617: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1618: '</td></tr>';
1619: $itemcount ++;
1620: }
1621: }
1622: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1623: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1624: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1625: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1626: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1627: for (my $k=0; $k<$maxnum+1; $k++) {
1628: my $vpos = $k+1;
1629: my $selstr;
1630: if ($k == $maxnum) {
1631: $selstr = ' selected="selected" ';
1632: }
1633: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1634: }
1635: $datatable .= '</select> '."\n".
1636: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1637: '<td colspan="2">'.
1638: &ipaccess_options('add',$itemcount,$dom).
1639: '</td>'."\n".
1640: '</tr>'."\n";
1641: $$rowtotal ++;
1642: return $datatable;
1643: }
1644:
1645: sub ipaccess_options {
1646: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1647: my (%currblocks,%currcourses,$output);
1648: if (ref($blocksref) eq 'HASH') {
1649: %currblocks = %{$blocksref};
1650: }
1651: if (ref($coursesref) eq 'HASH') {
1652: %currcourses = %{$coursesref};
1653: }
1654: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1655: '<span class="LC_nobreak">'.&mt('Name').': '.
1656: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1657: '</span></fieldset>'.
1658: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1659: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1660: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1661: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1662: $ipranges.'</textarea></fieldset>'.
1663: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1664: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1665: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1666: '<table>';
1667: foreach my $cid (sort(keys(%currcourses))) {
1668: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1669: $output .= '<tr><td><span class="LC_nobreak">'.
1670: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1671: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1672: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1673: }
1674: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1675: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1676: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1677: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1678: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1679: '</span></td></tr></table>'."\n".
1680: '</fieldset>';
1681: return $output;
1682: }
1683:
1684: sub blocker_checkboxes {
1685: my ($num,$blocks) = @_;
1686: my ($typeorder,$types) = &commblocktype_text();
1687: my $numinrow = 6;
1688: my $output = '<table>';
1689: for (my $i=0; $i<@{$typeorder}; $i++) {
1690: my $block = $typeorder->[$i];
1691: my $blockstatus;
1692: if (ref($blocks) eq 'HASH') {
1693: if ($blocks->{$block} eq 'on') {
1694: $blockstatus = 'checked="checked"';
1695: }
1696: }
1697: my $rem = $i%($numinrow);
1698: if ($rem == 0) {
1699: if ($i > 0) {
1700: $output .= '</tr>';
1701: }
1702: $output .= '<tr>';
1703: }
1704: if ($i == scalar(@{$typeorder})-1) {
1705: my $colsleft = $numinrow-$rem;
1706: if ($colsleft > 1) {
1707: $output .= '<td colspan="'.$colsleft.'">';
1708: } else {
1709: $output .= '<td>';
1710: }
1711: } else {
1712: $output .= '<td>';
1713: }
1714: my $item = 'ipaccess_block_'.$num;
1715: if ($blockstatus) {
1716: $blockstatus = ' '.$blockstatus;
1717: }
1718: $output .= '<span class="LC_nobreak"><label>'."\n".
1719: '<input type="checkbox" name="'.$item.'"'.
1720: $blockstatus.' value="'.$block.'"'.' />'.
1721: $types->{$block}.'</label></span>'."\n".
1722: '<br /></td>';
1723: }
1724: $output .= '</tr></table>';
1725: return $output;
1726: }
1727:
1728: sub commblocktype_text {
1729: my %types = &Apache::lonlocal::texthash(
1730: 'com' => 'Messaging',
1731: 'chat' => 'Chat Room',
1732: 'boards' => 'Discussion',
1733: 'port' => 'Portfolio',
1734: 'groups' => 'Groups',
1735: 'blogs' => 'Blogs',
1736: 'about' => 'User Information',
1737: 'printout' => 'Printouts',
1738: 'passwd' => 'Change Password',
1739: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1740: 'search' => 'Course search',
1741: 'wishlist' => 'Stored links',
1742: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1743: );
1.160.6.115 raeburn 1744: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1745: return ($typeorder,\%types);
1746: }
1747:
1.6 raeburn 1748: sub print_rolecolors {
1.30 raeburn 1749: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1750: my %choices = &color_font_choices();
1751: my @bgs = ('pgbg','tabbg','sidebg');
1752: my @links = ('link','alink','vlink');
1753: my @images = ('img');
1754: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1755: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1756: my %defaultdesign = %Apache::loncommon::defaultdesign;
1757: my (%is_custom,%designs);
1.160.6.22 raeburn 1758: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1759: if (ref($settings) eq 'HASH') {
1760: if (ref($settings->{$role}) eq 'HASH') {
1761: if ($settings->{$role}->{'img'} ne '') {
1762: $designs{'img'} = $settings->{$role}->{'img'};
1763: $is_custom{'img'} = 1;
1764: }
1765: if ($settings->{$role}->{'font'} ne '') {
1766: $designs{'font'} = $settings->{$role}->{'font'};
1767: $is_custom{'font'} = 1;
1768: }
1.97 tempelho 1769: if ($settings->{$role}->{'fontmenu'} ne '') {
1770: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1771: $is_custom{'fontmenu'} = 1;
1772: }
1.6 raeburn 1773: foreach my $item (@bgs) {
1774: if ($settings->{$role}->{$item} ne '') {
1775: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1776: $is_custom{$item} = 1;
1777: }
1778: }
1779: foreach my $item (@links) {
1780: if ($settings->{$role}->{$item} ne '') {
1781: $designs{'links'}{$item} = $settings->{$role}->{$item};
1782: $is_custom{$item} = 1;
1783: }
1784: }
1785: }
1786: } else {
1787: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1788: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1789: $is_custom{'img'} = 1;
1790: }
1.97 tempelho 1791: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1792: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1793: $is_custom{'fontmenu'} = 1;
1794: }
1.6 raeburn 1795: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1796: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1797: $is_custom{'font'} = 1;
1798: }
1799: foreach my $item (@bgs) {
1800: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1801: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1802: $is_custom{$item} = 1;
1803:
1804: }
1805: }
1806: foreach my $item (@links) {
1807: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1808: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1809: $is_custom{$item} = 1;
1810: }
1811: }
1812: }
1813: my $itemcount = 1;
1.30 raeburn 1814: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1815: $datatable .= '</tr></table></td></tr>';
1816: return $datatable;
1817: }
1818:
1.160.6.22 raeburn 1819: sub role_defaults {
1820: my ($role,$bgs,$links,$images,$logintext) = @_;
1821: my %defaults;
1822: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1823: return %defaults;
1824: }
1825: my %defaultdesign = %Apache::loncommon::defaultdesign;
1826: if ($role eq 'login') {
1827: %defaults = (
1828: font => $defaultdesign{$role.'.font'},
1829: );
1830: if (ref($logintext) eq 'ARRAY') {
1831: foreach my $item (@{$logintext}) {
1832: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1833: }
1834: }
1835: foreach my $item (@{$images}) {
1836: $defaults{'showlogo'}{$item} = 1;
1837: }
1838: } else {
1839: %defaults = (
1840: img => $defaultdesign{$role.'.img'},
1841: font => $defaultdesign{$role.'.font'},
1842: fontmenu => $defaultdesign{$role.'.fontmenu'},
1843: );
1844: }
1845: foreach my $item (@{$bgs}) {
1846: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1847: }
1848: foreach my $item (@{$links}) {
1849: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1850: }
1851: foreach my $item (@{$images}) {
1852: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1853: }
1854: return %defaults;
1855: }
1856:
1.6 raeburn 1857: sub display_color_options {
1.9 raeburn 1858: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1859: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1860: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1861: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1862: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1863: '<td>'.$choices->{'font'}.'</td>';
1864: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1865: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1866: } else {
1867: $datatable .= '<td> </td>';
1868: }
1.160.6.9 raeburn 1869: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1870:
1.8 raeburn 1871: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1872: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1873: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1874: ' </span></td></tr>';
1.107 raeburn 1875: unless ($role eq 'login') {
1876: $datatable .= '<tr'.$css_class.'>'.
1877: '<td>'.$choices->{'fontmenu'}.'</td>';
1878: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1879: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1880: } else {
1881: $datatable .= '<td> </td>';
1882: }
1.160.6.22 raeburn 1883: $current_color = $designs->{'fontmenu'} ?
1884: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1885: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1886: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1887: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1888: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1889: ' </span></td></tr>';
1.97 tempelho 1890: }
1.9 raeburn 1891: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1892: foreach my $img (@{$images}) {
1.18 albertel 1893: $itemcount ++;
1.6 raeburn 1894: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1895: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1896: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 1897:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1898: if ($role eq 'login') {
1899: if ($img eq 'login') {
1900: $login_hdr_pick =
1.135 bisitz 1901: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1902: $logincolors =
1903: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1904: $designs,$defaults);
1.160.6.118.2 2(raebur 1905:2): } else {
1906:2): if ($img ne 'domlogo') {
1907:2): $datatable.= &logo_display_options($img,$defaults,$designs);
1908:2): }
1909:2): if (ref($designs->{'alttext'}) eq 'HASH') {
1910:2): $alttext = $designs->{'alttext'}{$img};
1911:2): }
1.70 raeburn 1912: }
1913: }
1914: $datatable .= '</td>';
1.6 raeburn 1915: if ($designs->{$img} ne '') {
1916: $imgfile = $designs->{$img};
1.18 albertel 1917: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1918: } else {
1919: $imgfile = $defaults->{$img};
1920: }
1921: if ($imgfile) {
1.9 raeburn 1922: my ($showfile,$fullsize);
1923: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1924: my $urldir = $1;
1925: my $filename = $2;
1926: my @info = &Apache::lonnet::stat_file($designs->{$img});
1927: if (@info) {
1928: my $thumbfile = 'tn-'.$filename;
1929: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1930: if (@thumb) {
1931: $showfile = $urldir.'/'.$thumbfile;
1932: } else {
1933: $showfile = $imgfile;
1934: }
1935: } else {
1936: $showfile = '';
1937: }
1938: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1939: $showfile = $imgfile;
1.6 raeburn 1940: my $imgdir = $1;
1941: my $filename = $2;
1.159 raeburn 1942: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1943: $showfile = "/$imgdir/tn-".$filename;
1944: } else {
1.159 raeburn 1945: my $input = $londocroot.$imgfile;
1946: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1947: if (!-e $output) {
1.9 raeburn 1948: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1949: my ($fullwidth,$fullheight) = &check_dimensions($input);
1950: if ($fullwidth ne '' && $fullheight ne '') {
1951: if ($fullwidth > $width && $fullheight > $height) {
1952: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1953: my @args = ('convert','-sample',$size,$input,$output);
1954: system({$args[0]} @args);
1.159 raeburn 1955: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1956: }
1957: }
1.6 raeburn 1958: }
1959: }
1.16 raeburn 1960: }
1.6 raeburn 1961: if ($showfile) {
1.40 raeburn 1962: if ($showfile =~ m{^/(adm|res)/}) {
1963: if ($showfile =~ m{^/res/}) {
1964: my $local_showfile =
1965: &Apache::lonnet::filelocation('',$showfile);
1966: &Apache::lonnet::repcopy($local_showfile);
1967: }
1968: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1969: }
1970: if ($imgfile) {
1971: if ($imgfile =~ m{^/(adm|res)/}) {
1972: if ($imgfile =~ m{^/res/}) {
1973: my $local_imgfile =
1974: &Apache::lonnet::filelocation('',$imgfile);
1975: &Apache::lonnet::repcopy($local_imgfile);
1976: }
1977: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1978: } else {
1979: $fullsize = $imgfile;
1980: }
1981: }
1.41 raeburn 1982: $datatable .= '<td>';
1983: if ($img eq 'login') {
1.135 bisitz 1984: $datatable .= $login_hdr_pick;
1985: }
1.41 raeburn 1986: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1987: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1988: } else {
1.160.6.22 raeburn 1989: $datatable .= '<td> </td><td class="LC_left_item">'.
1990: &mt('Upload:').'<br />';
1.6 raeburn 1991: }
1992: } else {
1.160.6.22 raeburn 1993: $datatable .= '<td> </td><td class="LC_left_item">'.
1994: &mt('Upload:').'<br />';
1.6 raeburn 1995: }
1.9 raeburn 1996: if ($switchserver) {
1997: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1998: } else {
1.135 bisitz 1999: if ($img ne 'login') { # suppress file selection for Log-in header
2000: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2001: }
1.9 raeburn 2002: }
1.160.6.118.2 2(raebur 2003:2): if (($role eq 'login') && ($img ne 'login')) {
2004:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2005:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2006:2): '</label></span>';
2007:2): }
1.9 raeburn 2008: $datatable .= '</td></tr>';
1.6 raeburn 2009: }
2010: $itemcount ++;
2011: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2012: $datatable .= '<tr'.$css_class.'>'.
2013: '<td>'.$choices->{'bgs'}.'</td>';
2014: my $bgs_def;
2015: foreach my $item (@{$bgs}) {
2016: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2017: $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 2018: }
2019: }
2020: if ($bgs_def) {
1.8 raeburn 2021: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2022: } else {
2023: $datatable .= '<td> </td>';
2024: }
2025: $datatable .= '<td class="LC_right_item">'.
2026: '<table border="0"><tr>';
1.160.6.13 raeburn 2027:
1.6 raeburn 2028: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2029: $datatable .= '<td align="center">'.$choices->{$item};
2030: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2031: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2032: $datatable .= ' ';
1.6 raeburn 2033: }
1.160.6.9 raeburn 2034: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2035: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2036: }
2037: $datatable .= '</tr></table></td></tr>';
2038: $itemcount ++;
2039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2040: $datatable .= '<tr'.$css_class.'>'.
2041: '<td>'.$choices->{'links'}.'</td>';
2042: my $links_def;
2043: foreach my $item (@{$links}) {
2044: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2045: $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 2046: }
2047: }
2048: if ($links_def) {
1.8 raeburn 2049: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2050: } else {
2051: $datatable .= '<td> </td>';
2052: }
2053: $datatable .= '<td class="LC_right_item">'.
2054: '<table border="0"><tr>';
2055: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2056: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2057: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2058: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2059: $datatable.=' ';
1.6 raeburn 2060: }
1.160.6.9 raeburn 2061: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2062: '" /></td>';
2063: }
1.30 raeburn 2064: $$rowtotal += $itemcount;
1.3 raeburn 2065: return $datatable;
2066: }
2067:
1.70 raeburn 2068: sub logo_display_options {
2069: my ($img,$defaults,$designs) = @_;
2070: my $checkedon;
2071: if (ref($defaults) eq 'HASH') {
2072: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2073: if ($defaults->{'showlogo'}{$img}) {
2074: $checkedon = 'checked="checked" ';
2075: }
2076: }
2077: }
2078: if (ref($designs) eq 'HASH') {
2079: if (ref($designs->{'showlogo'}) eq 'HASH') {
2080: if (defined($designs->{'showlogo'}{$img})) {
2081: if ($designs->{'showlogo'}{$img} == 0) {
2082: $checkedon = '';
2083: } elsif ($designs->{'showlogo'}{$img} == 1) {
2084: $checkedon = 'checked="checked" ';
2085: }
2086: }
2087: }
2088: }
2089: return '<br /><label> <input type="checkbox" name="'.
2090: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2091: &mt('show').'</label>'."\n";
2092: }
2093:
1.41 raeburn 2094: sub login_header_options {
1.135 bisitz 2095: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2096: my $output = '';
1.41 raeburn 2097: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2098: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2099: if (!$is_custom->{'textcol'}) {
2100: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2101: ' ';
2102: }
2103: if (!$is_custom->{'bgcol'}) {
2104: $output .= $choices->{'bgcol'}.': '.
2105: '<span id="css_'.$role.'_font" style="background-color: '.
2106: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2107: }
2108: $output .= '<br />';
2109: }
2110: $output .='<br />';
2111: return $output;
2112: }
2113:
2114: sub login_text_colors {
1.160.6.22 raeburn 2115: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2116: my $color_menu = '<table border="0"><tr>';
2117: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2118: $color_menu .= '<td align="center">'.$choices->{$item};
2119: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2120: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2121: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2122: }
2123: $color_menu .= '</tr></table><br />';
2124: return $color_menu;
2125: }
2126:
2127: sub image_changes {
2128: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2129: my $output;
1.135 bisitz 2130: if ($img eq 'login') {
1.160.6.87 raeburn 2131: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2132: } elsif (!$is_custom) {
1.70 raeburn 2133: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2134: $output = &mt('Default image:').'<br />';
1.41 raeburn 2135: } else {
1.160.6.87 raeburn 2136: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2137: }
2138: }
1.160.6.87 raeburn 2139: if ($img ne 'login') {
1.135 bisitz 2140: if ($img_import) {
2141: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2142: }
2143: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2144: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2145: if ($is_custom) {
2146: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2147: '<input type="checkbox" name="'.
2148: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2149: '</label> '.&mt('Replace:').'</span><br />';
2150: } else {
1.160.6.22 raeburn 2151: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2152: }
1.41 raeburn 2153: }
2154: return $output;
2155: }
2156:
1.3 raeburn 2157: sub print_quotas {
1.86 raeburn 2158: my ($dom,$settings,$rowtotal,$action) = @_;
2159: my $context;
2160: if ($action eq 'quotas') {
2161: $context = 'tools';
2162: } else {
2163: $context = $action;
2164: }
1.160.6.20 raeburn 2165: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2166: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2167: my $typecount = 0;
1.101 raeburn 2168: my ($css_class,%titles);
1.86 raeburn 2169: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2170: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2171: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2172: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2173: %titles = &courserequest_titles();
1.160.6.5 raeburn 2174: } elsif ($context eq 'requestauthor') {
2175: @usertools = ('author');
2176: @options = ('norequest','approval','automatic');
2177: %titles = &authorrequest_titles();
1.86 raeburn 2178: } else {
1.160.6.4 raeburn 2179: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2180: %titles = &tool_titles();
1.86 raeburn 2181: }
1.26 raeburn 2182: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2183: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2184: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2185: unless (($context eq 'requestcourses') ||
2186: ($context eq 'requestauthor')) {
1.86 raeburn 2187: if (ref($settings) eq 'HASH') {
2188: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2189: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2190: } else {
2191: $currdefquota = $settings->{$type};
2192: }
1.160.6.20 raeburn 2193: if (ref($settings->{authorquota}) eq 'HASH') {
2194: $currauthorquota = $settings->{authorquota}->{$type};
2195: }
1.78 raeburn 2196: }
1.72 raeburn 2197: }
1.3 raeburn 2198: if (defined($usertypes->{$type})) {
2199: $typecount ++;
2200: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2201: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2202: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2203: '<td class="LC_left_item">';
1.101 raeburn 2204: if ($context eq 'requestcourses') {
2205: $datatable .= '<table><tr>';
2206: }
2207: my %cell;
1.72 raeburn 2208: foreach my $item (@usertools) {
1.101 raeburn 2209: if ($context eq 'requestcourses') {
2210: my ($curroption,$currlimit);
2211: if (ref($settings) eq 'HASH') {
2212: if (ref($settings->{$item}) eq 'HASH') {
2213: $curroption = $settings->{$item}->{$type};
2214: if ($curroption =~ /^autolimit=(\d*)$/) {
2215: $currlimit = $1;
2216: }
2217: }
2218: }
2219: if (!$curroption) {
2220: $curroption = 'norequest';
2221: }
2222: $datatable .= '<th>'.$titles{$item}.'</th>';
2223: foreach my $option (@options) {
2224: my $val = $option;
2225: if ($option eq 'norequest') {
2226: $val = 0;
2227: }
2228: if ($option eq 'validate') {
2229: my $canvalidate = 0;
2230: if (ref($validations{$item}) eq 'HASH') {
2231: if ($validations{$item}{$type}) {
2232: $canvalidate = 1;
2233: }
2234: }
2235: next if (!$canvalidate);
2236: }
2237: my $checked = '';
2238: if ($option eq $curroption) {
2239: $checked = ' checked="checked"';
2240: } elsif ($option eq 'autolimit') {
2241: if ($curroption =~ /^autolimit/) {
2242: $checked = ' checked="checked"';
2243: }
2244: }
2245: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2246: '<input type="radio" name="crsreq_'.$item.
2247: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2248: $titles{$option}.'</label>';
1.101 raeburn 2249: if ($option eq 'autolimit') {
1.127 raeburn 2250: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2251: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2252: 'value="'.$currlimit.'" />';
1.101 raeburn 2253: }
1.127 raeburn 2254: $cell{$item} .= '</span> ';
1.103 raeburn 2255: if ($option eq 'autolimit') {
1.127 raeburn 2256: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2257: }
1.101 raeburn 2258: }
1.160.6.5 raeburn 2259: } elsif ($context eq 'requestauthor') {
2260: my $curroption;
2261: if (ref($settings) eq 'HASH') {
2262: $curroption = $settings->{$type};
2263: }
2264: if (!$curroption) {
2265: $curroption = 'norequest';
2266: }
2267: foreach my $option (@options) {
2268: my $val = $option;
2269: if ($option eq 'norequest') {
2270: $val = 0;
2271: }
2272: my $checked = '';
2273: if ($option eq $curroption) {
2274: $checked = ' checked="checked"';
2275: }
2276: $datatable .= '<span class="LC_nobreak"><label>'.
2277: '<input type="radio" name="authorreq_'.$type.
2278: '" value="'.$val.'"'.$checked.' />'.
2279: $titles{$option}.'</label></span> ';
2280: }
1.101 raeburn 2281: } else {
2282: my $checked = 'checked="checked" ';
2283: if (ref($settings) eq 'HASH') {
2284: if (ref($settings->{$item}) eq 'HASH') {
2285: if ($settings->{$item}->{$type} == 0) {
2286: $checked = '';
2287: } elsif ($settings->{$item}->{$type} == 1) {
2288: $checked = 'checked="checked" ';
2289: }
1.78 raeburn 2290: }
1.72 raeburn 2291: }
1.101 raeburn 2292: $datatable .= '<span class="LC_nobreak"><label>'.
2293: '<input type="checkbox" name="'.$context.'_'.$item.
2294: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2295: '</label></span> ';
1.72 raeburn 2296: }
1.101 raeburn 2297: }
2298: if ($context eq 'requestcourses') {
2299: $datatable .= '</tr><tr>';
2300: foreach my $item (@usertools) {
1.106 raeburn 2301: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2302: }
2303: $datatable .= '</tr></table>';
1.72 raeburn 2304: }
1.86 raeburn 2305: $datatable .= '</td>';
1.160.6.5 raeburn 2306: unless (($context eq 'requestcourses') ||
2307: ($context eq 'requestauthor')) {
1.86 raeburn 2308: $datatable .=
1.160.6.20 raeburn 2309: '<td class="LC_right_item">'.
2310: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2311: '<input type="text" name="quota_'.$type.
1.72 raeburn 2312: '" value="'.$currdefquota.
1.160.6.20 raeburn 2313: '" size="5" /></span>'.(' ' x 2).
2314: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2315: '<input type="text" name="authorquota_'.$type.
2316: '" value="'.$currauthorquota.
2317: '" size="5" /></span></td>';
1.86 raeburn 2318: }
2319: $datatable .= '</tr>';
1.3 raeburn 2320: }
2321: }
2322: }
1.160.6.5 raeburn 2323: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2324: $defaultquota = '20';
1.160.6.20 raeburn 2325: $authorquota = '500';
1.86 raeburn 2326: if (ref($settings) eq 'HASH') {
2327: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2328: $defaultquota = $settings->{'defaultquota'}->{'default'};
2329: } elsif (defined($settings->{'default'})) {
2330: $defaultquota = $settings->{'default'};
2331: }
1.160.6.20 raeburn 2332: if (ref($settings->{'authorquota'}) eq 'HASH') {
2333: $authorquota = $settings->{'authorquota'}->{'default'};
2334: }
1.3 raeburn 2335: }
2336: }
2337: $typecount ++;
2338: $css_class = $typecount%2?' class="LC_odd_row"':'';
2339: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2340: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2341: '<td class="LC_left_item">';
1.101 raeburn 2342: if ($context eq 'requestcourses') {
2343: $datatable .= '<table><tr>';
2344: }
2345: my %defcell;
1.72 raeburn 2346: foreach my $item (@usertools) {
1.101 raeburn 2347: if ($context eq 'requestcourses') {
2348: my ($curroption,$currlimit);
2349: if (ref($settings) eq 'HASH') {
2350: if (ref($settings->{$item}) eq 'HASH') {
2351: $curroption = $settings->{$item}->{'default'};
2352: if ($curroption =~ /^autolimit=(\d*)$/) {
2353: $currlimit = $1;
2354: }
2355: }
2356: }
2357: if (!$curroption) {
2358: $curroption = 'norequest';
2359: }
2360: $datatable .= '<th>'.$titles{$item}.'</th>';
2361: foreach my $option (@options) {
2362: my $val = $option;
2363: if ($option eq 'norequest') {
2364: $val = 0;
2365: }
2366: if ($option eq 'validate') {
2367: my $canvalidate = 0;
2368: if (ref($validations{$item}) eq 'HASH') {
2369: if ($validations{$item}{'default'}) {
2370: $canvalidate = 1;
2371: }
2372: }
2373: next if (!$canvalidate);
2374: }
2375: my $checked = '';
2376: if ($option eq $curroption) {
2377: $checked = ' checked="checked"';
2378: } elsif ($option eq 'autolimit') {
2379: if ($curroption =~ /^autolimit/) {
2380: $checked = ' checked="checked"';
2381: }
2382: }
2383: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2384: '<input type="radio" name="crsreq_'.$item.
2385: '_default" value="'.$val.'"'.$checked.' />'.
2386: $titles{$option}.'</label>';
2387: if ($option eq 'autolimit') {
1.127 raeburn 2388: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2389: $item.'_limit_default" size="1" '.
2390: 'value="'.$currlimit.'" />';
2391: }
1.127 raeburn 2392: $defcell{$item} .= '</span> ';
1.104 raeburn 2393: if ($option eq 'autolimit') {
1.127 raeburn 2394: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2395: }
1.101 raeburn 2396: }
1.160.6.5 raeburn 2397: } elsif ($context eq 'requestauthor') {
2398: my $curroption;
2399: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2400: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2401: }
2402: if (!$curroption) {
2403: $curroption = 'norequest';
2404: }
2405: foreach my $option (@options) {
2406: my $val = $option;
2407: if ($option eq 'norequest') {
2408: $val = 0;
2409: }
2410: my $checked = '';
2411: if ($option eq $curroption) {
2412: $checked = ' checked="checked"';
2413: }
2414: $datatable .= '<span class="LC_nobreak"><label>'.
2415: '<input type="radio" name="authorreq_default"'.
2416: ' value="'.$val.'"'.$checked.' />'.
2417: $titles{$option}.'</label></span> ';
2418: }
1.101 raeburn 2419: } else {
2420: my $checked = 'checked="checked" ';
2421: if (ref($settings) eq 'HASH') {
2422: if (ref($settings->{$item}) eq 'HASH') {
2423: if ($settings->{$item}->{'default'} == 0) {
2424: $checked = '';
2425: } elsif ($settings->{$item}->{'default'} == 1) {
2426: $checked = 'checked="checked" ';
2427: }
1.78 raeburn 2428: }
1.72 raeburn 2429: }
1.101 raeburn 2430: $datatable .= '<span class="LC_nobreak"><label>'.
2431: '<input type="checkbox" name="'.$context.'_'.$item.
2432: '" value="default" '.$checked.'/>'.$titles{$item}.
2433: '</label></span> ';
2434: }
2435: }
2436: if ($context eq 'requestcourses') {
2437: $datatable .= '</tr><tr>';
2438: foreach my $item (@usertools) {
1.106 raeburn 2439: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2440: }
1.101 raeburn 2441: $datatable .= '</tr></table>';
1.72 raeburn 2442: }
1.86 raeburn 2443: $datatable .= '</td>';
1.160.6.5 raeburn 2444: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2445: $datatable .= '<td class="LC_right_item">'.
2446: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2447: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2448: $defaultquota.'" size="5" /></span>'.(' ' x2).
2449: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2450: '<input type="text" name="authorquota" value="'.
2451: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2452: }
2453: $datatable .= '</tr>';
1.72 raeburn 2454: $typecount ++;
2455: $css_class = $typecount%2?' class="LC_odd_row"':'';
2456: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2457: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2458: if ($context eq 'requestcourses') {
1.109 raeburn 2459: $datatable .= &mt('(overrides affiliation, if set)').
2460: '</td>'.
2461: '<td class="LC_left_item">'.
2462: '<table><tr>';
1.101 raeburn 2463: } else {
1.109 raeburn 2464: $datatable .= &mt('(overrides affiliation, if checked)').
2465: '</td>'.
2466: '<td class="LC_left_item" colspan="2">'.
2467: '<br />';
1.101 raeburn 2468: }
2469: my %advcell;
1.72 raeburn 2470: foreach my $item (@usertools) {
1.101 raeburn 2471: if ($context eq 'requestcourses') {
2472: my ($curroption,$currlimit);
2473: if (ref($settings) eq 'HASH') {
2474: if (ref($settings->{$item}) eq 'HASH') {
2475: $curroption = $settings->{$item}->{'_LC_adv'};
2476: if ($curroption =~ /^autolimit=(\d*)$/) {
2477: $currlimit = $1;
2478: }
2479: }
2480: }
2481: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2482: my $checked = '';
2483: if ($curroption eq '') {
2484: $checked = ' checked="checked"';
2485: }
2486: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2487: '<input type="radio" name="crsreq_'.$item.
2488: '__LC_adv" value=""'.$checked.' />'.
2489: &mt('No override set').'</label></span> ';
1.101 raeburn 2490: foreach my $option (@options) {
2491: my $val = $option;
2492: if ($option eq 'norequest') {
2493: $val = 0;
2494: }
2495: if ($option eq 'validate') {
2496: my $canvalidate = 0;
2497: if (ref($validations{$item}) eq 'HASH') {
2498: if ($validations{$item}{'_LC_adv'}) {
2499: $canvalidate = 1;
2500: }
2501: }
2502: next if (!$canvalidate);
2503: }
2504: my $checked = '';
1.104 raeburn 2505: if ($val eq $curroption) {
1.101 raeburn 2506: $checked = ' checked="checked"';
2507: } elsif ($option eq 'autolimit') {
2508: if ($curroption =~ /^autolimit/) {
2509: $checked = ' checked="checked"';
2510: }
2511: }
2512: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="crsreq_'.$item.
2514: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2515: $titles{$option}.'</label>';
2516: if ($option eq 'autolimit') {
1.127 raeburn 2517: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2518: $item.'_limit__LC_adv" size="1" '.
2519: 'value="'.$currlimit.'" />';
2520: }
1.127 raeburn 2521: $advcell{$item} .= '</span> ';
1.104 raeburn 2522: if ($option eq 'autolimit') {
1.127 raeburn 2523: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2524: }
1.101 raeburn 2525: }
1.160.6.5 raeburn 2526: } elsif ($context eq 'requestauthor') {
2527: my $curroption;
2528: if (ref($settings) eq 'HASH') {
2529: $curroption = $settings->{'_LC_adv'};
2530: }
2531: my $checked = '';
2532: if ($curroption eq '') {
2533: $checked = ' checked="checked"';
2534: }
2535: $datatable .= '<span class="LC_nobreak"><label>'.
2536: '<input type="radio" name="authorreq__LC_adv"'.
2537: ' value=""'.$checked.' />'.
2538: &mt('No override set').'</label></span> ';
2539: foreach my $option (@options) {
2540: my $val = $option;
2541: if ($option eq 'norequest') {
2542: $val = 0;
2543: }
2544: my $checked = '';
2545: if ($val eq $curroption) {
2546: $checked = ' checked="checked"';
2547: }
2548: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2549: '<input type="radio" name="authorreq__LC_adv"'.
2550: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2551: $titles{$option}.'</label></span> ';
2552: }
1.101 raeburn 2553: } else {
2554: my $checked = 'checked="checked" ';
2555: if (ref($settings) eq 'HASH') {
2556: if (ref($settings->{$item}) eq 'HASH') {
2557: if ($settings->{$item}->{'_LC_adv'} == 0) {
2558: $checked = '';
2559: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2560: $checked = 'checked="checked" ';
2561: }
1.79 raeburn 2562: }
1.72 raeburn 2563: }
1.101 raeburn 2564: $datatable .= '<span class="LC_nobreak"><label>'.
2565: '<input type="checkbox" name="'.$context.'_'.$item.
2566: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2567: '</label></span> ';
2568: }
2569: }
2570: if ($context eq 'requestcourses') {
2571: $datatable .= '</tr><tr>';
2572: foreach my $item (@usertools) {
1.106 raeburn 2573: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2574: }
1.101 raeburn 2575: $datatable .= '</tr></table>';
1.72 raeburn 2576: }
1.98 raeburn 2577: $datatable .= '</td></tr>';
1.30 raeburn 2578: $$rowtotal += $typecount;
1.3 raeburn 2579: return $datatable;
2580: }
2581:
1.160.6.5 raeburn 2582: sub print_requestmail {
1.160.6.93 raeburn 2583: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2584: my ($now,$datatable,%currapp);
1.102 raeburn 2585: $now = time;
2586: if (ref($settings) eq 'HASH') {
2587: if (ref($settings->{'notify'}) eq 'HASH') {
2588: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2589: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2590: }
2591: }
2592: }
1.160.6.16 raeburn 2593: my $numinrow = 2;
1.160.6.34 raeburn 2594: my $css_class;
1.160.6.93 raeburn 2595: if ($$rowtotal%2) {
2596: $css_class = 'LC_odd_row';
2597: }
2598: if ($customcss) {
2599: $css_class .= " $customcss";
2600: }
2601: $css_class =~ s/^\s+//;
2602: if ($css_class) {
2603: $css_class = ' class="'.$css_class.'"';
2604: }
2605: if ($rowstyle) {
2606: $css_class .= ' style="'.$rowstyle.'"';
2607: }
1.160.6.5 raeburn 2608: my $text;
2609: if ($action eq 'requestcourses') {
2610: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2611: } elsif ($action eq 'requestauthor') {
2612: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2613: } else {
1.160.6.34 raeburn 2614: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2615: }
1.160.6.34 raeburn 2616: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2617: ' <td>'.$text.'</td>'.
1.102 raeburn 2618: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2619: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2620: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2621: if ($numdc > 0) {
2622: $datatable .= $table;
1.102 raeburn 2623: } else {
2624: $datatable .= &mt('There are no active Domain Coordinators');
2625: }
2626: $datatable .='</td></tr>';
2627: return $datatable;
2628: }
2629:
1.160.6.30 raeburn 2630: sub print_studentcode {
2631: my ($settings,$rowtotal) = @_;
2632: my $rownum = 0;
2633: my ($output,%current);
2634: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2635: if (ref($settings) eq 'HASH') {
2636: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2637: foreach my $type (@crstypes) {
2638: $current{$type} = $settings->{'uniquecode'}{$type};
2639: }
1.160.6.30 raeburn 2640: }
2641: }
2642: $output .= '<tr>'.
2643: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2644: '<td class="LC_left_item">';
2645: foreach my $type (@crstypes) {
2646: my $check = ' ';
2647: if ($current{$type}) {
2648: $check = ' checked="checked" ';
2649: }
2650: $output .= '<span class="LC_nobreak"><label>'.
2651: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2652: &mt($type).'</label></span>'.(' 'x2).' ';
2653: }
2654: $output .= '</td></tr>';
2655: $$rowtotal ++;
2656: return $output;
2657: }
2658:
2659: sub print_textbookcourses {
1.160.6.46 raeburn 2660: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2661: my $rownum = 0;
2662: my $css_class;
2663: my $itemcount = 1;
2664: my $maxnum = 0;
2665: my $bookshash;
2666: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2667: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2668: }
2669: my %ordered;
2670: if (ref($bookshash) eq 'HASH') {
2671: foreach my $item (keys(%{$bookshash})) {
2672: if (ref($bookshash->{$item}) eq 'HASH') {
2673: my $num = $bookshash->{$item}{'order'};
2674: $ordered{$num} = $item;
2675: }
2676: }
2677: }
2678: my $confname = $dom.'-domainconfig';
2679: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2680: my $maxnum = scalar(keys(%ordered));
2681: my $datatable;
1.160.6.30 raeburn 2682: if (keys(%ordered)) {
2683: my @items = sort { $a <=> $b } keys(%ordered);
2684: for (my $i=0; $i<@items; $i++) {
2685: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2686: my $key = $ordered{$items[$i]};
2687: my %coursehash=&Apache::lonnet::coursedescription($key);
2688: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2689: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2690: if (ref($bookshash->{$key}) eq 'HASH') {
2691: $subject = $bookshash->{$key}->{'subject'};
2692: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2693: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2694: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2695: $author = $bookshash->{$key}->{'author'};
2696: $image = $bookshash->{$key}->{'image'};
2697: if ($image ne '') {
2698: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2699: my $imagethumb = "$path/tn-".$imagefile;
2700: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2701: }
1.160.6.30 raeburn 2702: }
2703: }
1.160.6.46 raeburn 2704: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2705: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2706: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2707: for (my $k=0; $k<=$maxnum; $k++) {
2708: my $vpos = $k+1;
2709: my $selstr;
2710: if ($k == $i) {
2711: $selstr = ' selected="selected" ';
2712: }
2713: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2714: }
2715: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2716: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2717: &mt('Delete?').'</label></span></td>'.
2718: '<td colspan="2">'.
1.160.6.46 raeburn 2719: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2720: (' 'x2).
1.160.6.46 raeburn 2721: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2722: if ($type eq 'textbooks') {
2723: $datatable .= (' 'x2).
1.160.6.47 raeburn 2724: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2725: (' 'x2).
1.160.6.46 raeburn 2726: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2727: (' 'x2).
2728: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2729: if ($image) {
1.160.6.114 raeburn 2730: $datatable .= $imgsrc.
1.160.6.46 raeburn 2731: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2732: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2733: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2734: }
2735: if ($switchserver) {
2736: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2737: } else {
2738: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2739: }
1.160.6.30 raeburn 2740: }
1.160.6.46 raeburn 2741: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2742: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2743: $coursetitle.'</span></td></tr>'."\n";
2744: $itemcount ++;
2745: }
2746: }
2747: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2748: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2749: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2750: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2751: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2752: for (my $k=0; $k<$maxnum+1; $k++) {
2753: my $vpos = $k+1;
2754: my $selstr;
2755: if ($k == $maxnum) {
2756: $selstr = ' selected="selected" ';
2757: }
2758: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2759: }
2760: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2761: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2762: '<td colspan="2">'.
1.160.6.46 raeburn 2763: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2764: (' 'x2).
1.160.6.46 raeburn 2765: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2766: (' 'x2);
2767: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2768: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2769: (' 'x2).
2770: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2771: (' 'x2).
2772: '<span class="LC_nobreak">'.&mt('Image:').' ';
2773: if ($switchserver) {
2774: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2775: } else {
2776: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2777: }
1.160.6.87 raeburn 2778: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2779: }
1.160.6.87 raeburn 2780: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2781: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2782: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2783: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2784: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2785: '</span></td>'."\n".
2786: '</tr>'."\n";
2787: $itemcount ++;
2788: return $datatable;
2789: }
2790:
2791: sub textbookcourses_javascript {
1.160.6.46 raeburn 2792: my ($settings) = @_;
2793: return unless(ref($settings) eq 'HASH');
2794: my (%ordered,%total,%jstext);
2795: foreach my $type ('textbooks','templates') {
2796: $total{$type} = 0;
2797: if (ref($settings->{$type}) eq 'HASH') {
2798: foreach my $item (keys(%{$settings->{$type}})) {
2799: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2800: my $num = $settings->{$type}->{$item}{'order'};
2801: $ordered{$type}{$num} = $item;
2802: }
2803: }
2804: $total{$type} = scalar(keys(%{$settings->{$type}}));
2805: }
2806: my @jsarray = ();
2807: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2808: push(@jsarray,$ordered{$type}{$item});
2809: }
2810: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2811: }
2812: return <<"ENDSCRIPT";
2813: <script type="text/javascript">
2814: // <![CDATA[
1.160.6.46 raeburn 2815: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2816: var changedVal;
1.160.6.46 raeburn 2817: $jstext{'textbooks'};
2818: $jstext{'templates'};
2819: var newpos;
2820: var maxh;
2821: if (caller == 'textbooks') {
2822: newpos = 'textbooks_addbook_pos';
2823: maxh = 1 + $total{'textbooks'};
2824: } else {
2825: newpos = 'templates_addbook_pos';
2826: maxh = 1 + $total{'templates'};
2827: }
1.160.6.30 raeburn 2828: var current = new Array;
2829: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2830: if (item == newpos) {
2831: changedVal = newitemVal;
2832: } else {
2833: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2834: current[newitemVal] = newpos;
2835: }
1.160.6.46 raeburn 2836: if (caller == 'textbooks') {
2837: for (var i=0; i<textbooks.length; i++) {
2838: var elementName = 'textbooks_'+textbooks[i];
2839: if (elementName != item) {
2840: if (form.elements[elementName]) {
2841: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2842: current[currVal] = elementName;
2843: }
2844: }
2845: }
2846: }
2847: if (caller == 'templates') {
2848: for (var i=0; i<templates.length; i++) {
2849: var elementName = 'templates_'+templates[i];
2850: if (elementName != item) {
2851: if (form.elements[elementName]) {
2852: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2853: current[currVal] = elementName;
2854: }
1.160.6.30 raeburn 2855: }
2856: }
2857: }
2858: var oldVal;
2859: for (var j=0; j<maxh; j++) {
2860: if (current[j] == undefined) {
2861: oldVal = j;
2862: }
2863: }
2864: if (oldVal < changedVal) {
2865: for (var k=oldVal+1; k<=changedVal ; k++) {
2866: var elementName = current[k];
2867: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2868: }
2869: } else {
2870: for (var k=changedVal; k<oldVal; k++) {
2871: var elementName = current[k];
2872: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2873: }
2874: }
2875: return;
2876: }
2877:
2878: // ]]>
2879: </script>
2880:
2881: ENDSCRIPT
2882: }
2883:
1.160.6.118.2 1(raebur 2884:1): sub ltitools_javascript {
2885:1): my ($settings) = @_;
2886:1): my $togglejs = <itools_toggle_js();
2887:1): unless (ref($settings) eq 'HASH') {
2888:1): return $togglejs;
2889:1): }
2890:1): my (%ordered,$total,%jstext);
2891:1): $total = 0;
2892:1): foreach my $item (keys(%{$settings})) {
2893:1): if (ref($settings->{$item}) eq 'HASH') {
2894:1): my $num = $settings->{$item}{'order'};
2895:1): $ordered{$num} = $item;
2896:1): }
2897:1): }
2898:1): $total = scalar(keys(%{$settings}));
2899:1): my @jsarray = ();
2900:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2901:1): push(@jsarray,$ordered{$item});
2902:1): }
2903:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2904:1): return <<"ENDSCRIPT";
2905:1): <script type="text/javascript">
2906:1): // <![CDATA[
2907:1): function reorderLTITools(form,item) {
2908:1): var changedVal;
2909:1): $jstext
2910:1): var newpos = 'ltitools_add_pos';
2911:1): var maxh = 1 + $total;
2912:1): var current = new Array;
2913:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2914:1): if (item == newpos) {
2915:1): changedVal = newitemVal;
2916:1): } else {
2917:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2918:1): current[newitemVal] = newpos;
2919:1): }
2920:1): for (var i=0; i<ltitools.length; i++) {
2921:1): var elementName = 'ltitools_'+ltitools[i];
2922:1): if (elementName != item) {
2923:1): if (form.elements[elementName]) {
2924:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2925:1): current[currVal] = elementName;
2926:1): }
2927:1): }
2928:1): }
2929:1): var oldVal;
2930:1): for (var j=0; j<maxh; j++) {
2931:1): if (current[j] == undefined) {
2932:1): oldVal = j;
2933:1): }
2934:1): }
2935:1): if (oldVal < changedVal) {
2936:1): for (var k=oldVal+1; k<=changedVal ; k++) {
2937:1): var elementName = current[k];
2938:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2939:1): }
2940:1): } else {
2941:1): for (var k=changedVal; k<oldVal; k++) {
2942:1): var elementName = current[k];
2943:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2944:1): }
2945:1): }
2946:1): return;
2947:1): }
2948:1):
2949:1): // ]]>
2950:1): </script>
2951:1):
2952:1): $togglejs
2953:1):
2954:1): ENDSCRIPT
2955:1): }
2956:1):
2957:1): sub ltitools_toggle_js {
2958:1): return <<"ENDSCRIPT";
2959:1): <script type="text/javascript">
2960:1): // <![CDATA[
2961:1):
2962:1): function toggleLTITools(form,setting,item) {
2963:1): var radioname = '';
2964:1): var divid = '';
2965:1): if (setting == 'user') {
2966:1): divid = 'ltitools_'+setting+'_div_'+item;
2967:1): var checkid = 'ltitools_'+setting+'_field_'+item;
2968:1): if (document.getElementById(divid)) {
2969:1): if (document.getElementById(checkid)) {
2970:1): if (document.getElementById(checkid).checked) {
2971:1): document.getElementById(divid).style.display = 'inline-block';
2972:1): } else {
2973:1): document.getElementById(divid).style.display = 'none';
2974:1): }
2975:1): }
2976:1): }
2977:1): }
2978:1): return;
2979:1): }
2980:1): // ]]>
2981:1): </script>
2982:1):
2983:1): ENDSCRIPT
2984:1): }
2985:1):
1.160.6.113 raeburn 2986: sub wafproxy_javascript {
2987: my ($dom) = @_;
2988: return <<"ENDSCRIPT";
2989: <script type="text/javascript">
2990: // <![CDATA[
2991: function updateWAF() {
2992: if (document.getElementById('wafproxy_remoteip')) {
2993: var wafremote = 0;
2994: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
2995: wafremote = 1;
2996: }
2997: var fields = new Array('header','trust');
2998: for (var i=0; i<fields.length; i++) {
2999: if (document.getElementById('wafproxy_'+fields[i])) {
3000: if (wafremote == 1) {
3001: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3002: }
3003: else {
3004: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3005: }
3006: }
3007: }
3008: if (document.getElementById('wafproxyranges_$dom')) {
3009: if (wafremote == 1) {
3010: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3011: } else {
3012: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3013: if (document.display.wafproxy_vpnaccess[i].checked) {
3014: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3015: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3016: }
3017: }
3018: }
3019: }
3020: }
3021: }
3022: return;
3023: }
3024:
3025: function checkWAF() {
3026: if (document.getElementById('wafproxy_remoteip')) {
3027: var wafvpn = 0;
3028: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3029: if (document.display.wafproxy_vpnaccess[i].checked) {
3030: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3031: wafvpn = 1;
3032: }
3033: break;
3034: }
3035: }
3036: var vpn = new Array('vpnint','vpnext');
3037: for (var i=0; i<vpn.length; i++) {
3038: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3039: if (wafvpn == 1) {
3040: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3041: }
3042: else {
3043: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3044: }
3045: }
3046: }
3047: if (document.getElementById('wafproxyranges_$dom')) {
3048: if (wafvpn == 1) {
3049: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3050: }
3051: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3052: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3053: }
3054: }
3055: }
3056: return;
3057: }
3058:
3059: function toggleWAF() {
3060: if (document.getElementById('wafproxy_table')) {
3061: var wafproxy = 0;
3062: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3063: if (document.display.wafproxy_${dom}[i].checked) {
3064: if (document.display.wafproxy_${dom}[i].value == 1) {
3065: wafproxy = 1;
3066: break;
3067: }
3068: }
3069: }
3070: if (wafproxy == 1) {
3071: document.getElementById('wafproxy_table').style.display='inline';
3072: }
3073: else {
3074: document.getElementById('wafproxy_table').style.display='none';
3075: }
3076: if (document.getElementById('wafproxyrow_${dom}')) {
3077: if (wafproxy == 1) {
3078: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3079: }
3080: else {
3081: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3082: }
3083: }
3084: if (document.getElementById('nowafproxyrow_$dom')) {
3085: if (wafproxy == 1) {
3086: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3087: }
3088: else {
3089: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3090: }
3091: }
3092: }
3093: return;
3094: }
3095: // ]]>
3096: </script>
3097:
3098: ENDSCRIPT
3099: }
3100:
3101: sub autoupdate_javascript {
3102: return <<"ENDSCRIPT";
3103: <script type="text/javascript">
3104: // <![CDATA[
3105: function toggleLastActiveDays(form) {
3106: var radioname = 'lastactive';
3107: var divid = 'lastactive_div';
3108: var num = form.elements[radioname].length;
3109: if (num) {
3110: var setvis = '';
3111: for (var i=0; i<num; i++) {
3112: if (form.elements[radioname][i].checked) {
3113: if (form.elements[radioname][i].value == '1') {
3114: if (document.getElementById(divid)) {
3115: document.getElementById(divid).style.display = 'inline-block';
3116: }
3117: setvis = 1;
3118: }
3119: break;
3120: }
3121: }
3122: if (!setvis) {
3123: if (document.getElementById(divid)) {
3124: document.getElementById(divid).style.display = 'none';
3125: }
3126: }
3127: }
3128: return;
3129: }
3130: // ]]>
3131: </script>
3132:
3133: ENDSCRIPT
3134: }
3135:
1.160.6.116 raeburn 3136: sub autoenroll_javascript {
3137: return <<"ENDSCRIPT";
3138: <script type="text/javascript">
3139: // <![CDATA[
3140: function toggleFailsafe(form) {
3141: var radioname = 'autoenroll_failsafe';
3142: var divid = 'autoenroll_failsafe_div';
3143: var num = form.elements[radioname].length;
3144: if (num) {
3145: var setvis = '';
3146: for (var i=0; i<num; i++) {
3147: if (form.elements[radioname][i].checked) {
3148: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3149: if (document.getElementById(divid)) {
3150: document.getElementById(divid).style.display = 'inline-block';
3151: }
3152: setvis = 1;
3153: }
3154: break;
3155: }
3156: }
3157: if (!setvis) {
3158: if (document.getElementById(divid)) {
3159: document.getElementById(divid).style.display = 'none';
3160: }
3161: }
3162: }
3163: return;
3164: }
3165: // ]]>
3166: </script>
3167:
3168: ENDSCRIPT
3169: }
3170:
1.160.6.113 raeburn 3171: sub saml_javascript {
3172: return <<"ENDSCRIPT";
3173: <script type="text/javascript">
3174: // <![CDATA[
3175: function toggleSamlOptions(form,hostid) {
3176: var radioname = 'saml_'+hostid;
3177: var tablecellon = 'samloptionson_'+hostid;
3178: var tablecelloff = 'samloptionsoff_'+hostid;
3179: var num = form.elements[radioname].length;
3180: if (num) {
3181: var setvis = '';
3182: for (var i=0; i<num; i++) {
3183: if (form.elements[radioname][i].checked) {
3184: if (form.elements[radioname][i].value == '1') {
3185: if (document.getElementById(tablecellon)) {
3186: document.getElementById(tablecellon).style.display='';
3187: }
3188: if (document.getElementById(tablecelloff)) {
3189: document.getElementById(tablecelloff).style.display='none';
3190: }
3191: setvis = 1;
3192: }
3193: break;
3194: }
3195: }
3196: if (!setvis) {
3197: if (document.getElementById(tablecellon)) {
3198: document.getElementById(tablecellon).style.display='none';
3199: }
3200: if (document.getElementById(tablecelloff)) {
3201: document.getElementById(tablecelloff).style.display='';
3202: }
3203: }
3204: }
3205: return;
3206: }
3207: // ]]>
3208: </script>
3209:
3210: ENDSCRIPT
3211: }
3212:
3213: sub ipaccess_javascript {
3214: my ($settings) = @_;
3215: my (%ordered,$total,%jstext);
3216: $total = 0;
3217: if (ref($settings) eq 'HASH') {
3218: foreach my $item (keys(%{$settings})) {
3219: if (ref($settings->{$item}) eq 'HASH') {
3220: my $num = $settings->{$item}{'order'};
3221: $ordered{$num} = $item;
3222: }
3223: }
3224: $total = scalar(keys(%{$settings}));
3225: }
3226: my @jsarray = ();
3227: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3228: push(@jsarray,$ordered{$item});
3229: }
3230: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3231: return <<"ENDSCRIPT";
3232: <script type="text/javascript">
3233: // <![CDATA[
3234: function reorderIPaccess(form,item) {
3235: var changedVal;
3236: $jstext
3237: var newpos = 'ipaccess_pos_add';
3238: var maxh = 1 + $total;
3239: var current = new Array;
3240: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3241: if (item == newpos) {
3242: changedVal = newitemVal;
3243: } else {
3244: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3245: current[newitemVal] = newpos;
3246: }
3247: for (var i=0; i<ipaccess.length; i++) {
3248: var elementName = 'ipaccess_pos_'+ipaccess[i];
3249: if (elementName != item) {
3250: if (form.elements[elementName]) {
3251: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3252: current[currVal] = elementName;
3253: }
3254: }
3255: }
3256: var oldVal;
3257: for (var j=0; j<maxh; j++) {
3258: if (current[j] == undefined) {
3259: oldVal = j;
3260: }
3261: }
3262: if (oldVal < changedVal) {
3263: for (var k=oldVal+1; k<=changedVal ; k++) {
3264: var elementName = current[k];
3265: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3266: }
3267: } else {
3268: for (var k=changedVal; k<oldVal; k++) {
3269: var elementName = current[k];
3270: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3271: }
3272: }
3273: return;
3274: }
3275: // ]]>
3276: </script>
3277:
3278: ENDSCRIPT
3279: }
3280:
1.3 raeburn 3281: sub print_autoenroll {
1.30 raeburn 3282: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3283: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3284: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3285: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3286: $failsafesty = 'none';
3287: %failsafechecked = (
3288: off => ' checked="checked"',
3289: );
1.3 raeburn 3290: if (ref($settings) eq 'HASH') {
3291: if (exists($settings->{'run'})) {
3292: if ($settings->{'run'} eq '0') {
3293: $runoff = ' checked="checked" ';
3294: $runon = ' ';
3295: } else {
3296: $runon = ' checked="checked" ';
3297: $runoff = ' ';
3298: }
3299: } else {
3300: if ($autorun) {
3301: $runon = ' checked="checked" ';
3302: $runoff = ' ';
3303: } else {
3304: $runoff = ' checked="checked" ';
3305: $runon = ' ';
3306: }
3307: }
1.129 raeburn 3308: if (exists($settings->{'co-owners'})) {
3309: if ($settings->{'co-owners'} eq '0') {
3310: $coownersoff = ' checked="checked" ';
3311: $coownerson = ' ';
3312: } else {
3313: $coownerson = ' checked="checked" ';
3314: $coownersoff = ' ';
3315: }
3316: } else {
3317: $coownersoff = ' checked="checked" ';
3318: $coownerson = ' ';
3319: }
1.3 raeburn 3320: if (exists($settings->{'sender_domain'})) {
3321: $defdom = $settings->{'sender_domain'};
3322: }
1.160.6.116 raeburn 3323: if (exists($settings->{'failsafe'})) {
3324: $failsafe = $settings->{'failsafe'};
3325: if ($failsafe eq 'zero') {
3326: $failsafechecked{'zero'} = ' checked="checked"';
3327: $failsafechecked{'off'} = '';
3328: $failsafesty = 'inline-block';
3329: } elsif ($failsafe eq 'any') {
3330: $failsafechecked{'any'} = ' checked="checked"';
3331: $failsafechecked{'off'} = '';
3332: }
3333: $autofailsafe = $settings->{'autofailsafe'};
3334: } elsif (exists($settings->{'autofailsafe'})) {
3335: $autofailsafe = $settings->{'autofailsafe'};
3336: if ($autofailsafe ne '') {
3337: $failsafechecked{'zero'} = ' checked="checked"';
3338: $failsafe = 'zero';
3339: $failsafechecked{'off'} = '';
3340: }
1.160.6.68 raeburn 3341: }
1.14 raeburn 3342: } else {
3343: if ($autorun) {
3344: $runon = ' checked="checked" ';
3345: $runoff = ' ';
3346: } else {
3347: $runoff = ' checked="checked" ';
3348: $runon = ' ';
3349: }
1.3 raeburn 3350: }
3351: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3352: my $notif_sender;
3353: if (ref($settings) eq 'HASH') {
3354: $notif_sender = $settings->{'sender_uname'};
3355: }
1.3 raeburn 3356: my $datatable='<tr class="LC_odd_row">'.
3357: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3358: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3359: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3360: $runon.' value="1" />'.&mt('Yes').'</label> '.
3361: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3362: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3363: '</tr><tr>'.
3364: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3365: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3366: &mt('username').': '.
3367: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3368: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3369: ': '.$domform.'</span></td></tr>'.
3370: '<tr class="LC_odd_row">'.
3371: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3372: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3373: '<input type="radio" name="autoassign_coowners"'.
3374: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3375: '<label><input type="radio" name="autoassign_coowners"'.
3376: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3377: '</tr><tr>'.
3378: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3379: '<td class="LC_left_item"><span class="LC_nobreak">'.
3380: '<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> '.
3381: '<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 />'.
3382: '<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>'.
3383: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3384: '<span class="LC_nobreak">'.
3385: &mt('Threshold for number of students in section to drop: [_1]',
3386: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3387: '</span></div></td></tr>';
1.160.6.68 raeburn 3388: $$rowtotal += 4;
1.3 raeburn 3389: return $datatable;
3390: }
3391:
3392: sub print_autoupdate {
1.30 raeburn 3393: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3394: my ($enable,$datatable);
1.3 raeburn 3395: if ($position eq 'top') {
1.160.6.113 raeburn 3396: my %choices = &Apache::lonlocal::texthash (
3397: run => 'Auto-update active?',
3398: classlists => 'Update information in classlists?',
3399: unexpired => 'Skip updates for users without active or future roles?',
3400: lastactive => 'Skip updates for inactive users?',
3401: );
3402: my $itemcount = 0;
1.3 raeburn 3403: my $updateon = ' ';
3404: my $updateoff = ' checked="checked" ';
3405: if (ref($settings) eq 'HASH') {
3406: if ($settings->{'run'} eq '1') {
3407: $updateon = $updateoff;
3408: $updateoff = ' ';
3409: }
3410: }
1.160.6.113 raeburn 3411: $enable = '<tr class="LC_odd_row">'.
3412: '<td>'.&mt($choices{'run'}).'</td>'.
3413: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3414: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3415: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3416: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3417: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3418: '</tr>';
1.160.6.113 raeburn 3419: my @toggles = ('classlists','unexpired');
3420: my %defaultchecked = ('classlists' => 'off',
3421: 'unexpired' => 'off'
3422: );
3423: $$rowtotal ++;
3424: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3425: \%choices,$itemcount,'','','left','no');
3426: $datatable = $enable.$datatable;
3427: $$rowtotal += $itemcount;
3428: my $lastactiveon = ' ';
3429: my $lastactiveoff = ' checked="checked" ';
3430: my $lastactivestyle = 'none';
3431: my $lastactivedays;
3432: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3433: if (ref($settings) eq 'HASH') {
3434: if ($settings->{'lastactive'} =~ /^\d+$/) {
3435: $lastactiveon = $lastactiveoff;
3436: $lastactiveoff = ' ';
3437: $lastactivestyle = 'inline-block';
3438: $lastactivedays = $settings->{'lastactive'};
3439: }
3440: }
3441: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3442: $datatable .= '<tr'.$css_class.'>'.
3443: '<td>'.$choices{'lastactive'}.'</td>'.
3444: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3445: '<input type="radio" name="lastactive"'.
3446: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3447: ' <label>'.
3448: '<input type="radio" name="lastactive"'.
3449: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3450: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3451: ': '.&mt('inactive = no activity in last [_1] days',
3452: '<input type="text" size="5" name="lastactivedays" value="'.
3453: $lastactivedays.'" />').
3454: '</span></td>'.
3455: '</tr>';
3456: $$rowtotal ++;
1.131 raeburn 3457: } elsif ($position eq 'middle') {
3458: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3459: my $numinrow = 3;
3460: my $locknamesettings;
3461: $datatable .= &insttypes_row($settings,$types,$usertypes,
3462: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3463: 'lockablenames',$rowtotal);
1.131 raeburn 3464: $$rowtotal ++;
1.3 raeburn 3465: } else {
1.44 raeburn 3466: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3467: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3468: 'permanentemail','id');
1.33 raeburn 3469: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3470: my $numrows = 0;
1.26 raeburn 3471: if (ref($types) eq 'ARRAY') {
3472: if (@{$types} > 0) {
3473: $datatable =
3474: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3475: \@fields,$types,\$numrows);
1.30 raeburn 3476: $$rowtotal += @{$types};
1.26 raeburn 3477: }
1.3 raeburn 3478: }
3479: $datatable .=
3480: &usertype_update_row($settings,{'default' => $othertitle},
3481: \%fieldtitles,\@fields,['default'],
3482: \$numrows);
1.30 raeburn 3483: $$rowtotal ++;
1.3 raeburn 3484: }
3485: return $datatable;
3486: }
3487:
1.125 raeburn 3488: sub print_autocreate {
3489: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3490: my (%createon,%createoff,%currhash);
1.125 raeburn 3491: my @types = ('xml','req');
3492: if (ref($settings) eq 'HASH') {
3493: foreach my $item (@types) {
3494: $createoff{$item} = ' checked="checked" ';
3495: $createon{$item} = ' ';
3496: if (exists($settings->{$item})) {
3497: if ($settings->{$item}) {
3498: $createon{$item} = ' checked="checked" ';
3499: $createoff{$item} = ' ';
3500: }
3501: }
3502: }
1.160.6.16 raeburn 3503: if ($settings->{'xmldc'} ne '') {
3504: $currhash{$settings->{'xmldc'}} = 1;
3505: }
1.125 raeburn 3506: } else {
3507: foreach my $item (@types) {
3508: $createoff{$item} = ' checked="checked" ';
3509: $createon{$item} = ' ';
3510: }
3511: }
3512: $$rowtotal += 2;
1.160.6.16 raeburn 3513: my $numinrow = 2;
1.125 raeburn 3514: my $datatable='<tr class="LC_odd_row">'.
3515: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3516: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3517: '<input type="radio" name="autocreate_xml"'.
3518: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3519: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3520: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3521: '</td></tr><tr>'.
3522: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3523: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3524: '<input type="radio" name="autocreate_req"'.
3525: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3526: '<label><input type="radio" name="autocreate_req"'.
3527: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3528: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3529: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3530: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3531: if ($numdc > 1) {
1.160.6.50 raeburn 3532: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3533: '</td><td class="LC_left_item">';
1.125 raeburn 3534: } else {
1.160.6.50 raeburn 3535: $datatable .= &mt('Course creation processed as:').
3536: '</td><td class="LC_right_item">';
1.125 raeburn 3537: }
1.160.6.50 raeburn 3538: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3539: $$rowtotal += $rows;
1.125 raeburn 3540: return $datatable;
3541: }
3542:
1.23 raeburn 3543: sub print_directorysrch {
1.160.6.72 raeburn 3544: my ($position,$dom,$settings,$rowtotal) = @_;
3545: my $datatable;
3546: if ($position eq 'top') {
3547: my $instsrchon = ' ';
3548: my $instsrchoff = ' checked="checked" ';
3549: my ($exacton,$containson,$beginson);
3550: my $instlocalon = ' ';
3551: my $instlocaloff = ' checked="checked" ';
3552: if (ref($settings) eq 'HASH') {
3553: if ($settings->{'available'} eq '1') {
3554: $instsrchon = $instsrchoff;
3555: $instsrchoff = ' ';
3556: }
3557: if ($settings->{'localonly'} eq '1') {
3558: $instlocalon = $instlocaloff;
3559: $instlocaloff = ' ';
3560: }
3561: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3562: foreach my $type (@{$settings->{'searchtypes'}}) {
3563: if ($type eq 'exact') {
3564: $exacton = ' checked="checked" ';
3565: } elsif ($type eq 'contains') {
3566: $containson = ' checked="checked" ';
3567: } elsif ($type eq 'begins') {
3568: $beginson = ' checked="checked" ';
3569: }
3570: }
3571: } else {
3572: if ($settings->{'searchtypes'} eq 'exact') {
3573: $exacton = ' checked="checked" ';
3574: } elsif ($settings->{'searchtypes'} eq 'contains') {
3575: $containson = ' checked="checked" ';
3576: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3577: $exacton = ' checked="checked" ';
3578: $containson = ' checked="checked" ';
3579: }
3580: }
1.23 raeburn 3581: }
1.160.6.72 raeburn 3582: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3583: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3584:
1.160.6.72 raeburn 3585: my $numinrow = 4;
3586: my $cansrchrow = 0;
3587: $datatable='<tr class="LC_odd_row">'.
3588: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3589: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3590: '<input type="radio" name="dirsrch_available"'.
3591: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3592: '<label><input type="radio" name="dirsrch_available"'.
3593: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3594: '</tr><tr>'.
3595: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3596: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3597: '<input type="radio" name="dirsrch_instlocalonly"'.
3598: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3599: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3600: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3601: '</tr>';
3602: $$rowtotal += 2;
3603: if (ref($usertypes) eq 'HASH') {
3604: if (keys(%{$usertypes}) > 0) {
3605: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3606: $numinrow,$othertitle,'cansearch',
3607: $rowtotal);
1.160.6.72 raeburn 3608: $cansrchrow = 1;
3609: }
1.26 raeburn 3610: }
1.160.6.72 raeburn 3611: if ($cansrchrow) {
3612: $$rowtotal ++;
3613: $datatable .= '<tr>';
3614: } else {
3615: $datatable .= '<tr class="LC_odd_row">';
3616: }
3617: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3618: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3619: foreach my $title (@{$titleorder}) {
3620: if (defined($searchtitles->{$title})) {
3621: my $check = ' ';
3622: if (ref($settings) eq 'HASH') {
3623: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3624: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3625: $check = ' checked="checked" ';
3626: }
1.39 raeburn 3627: }
1.25 raeburn 3628: }
1.160.6.72 raeburn 3629: $datatable .= '<td class="LC_left_item">'.
3630: '<span class="LC_nobreak"><label>'.
3631: '<input type="checkbox" name="searchby" '.
3632: 'value="'.$title.'"'.$check.'/>'.
3633: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3634: }
3635: }
1.160.6.72 raeburn 3636: $datatable .= '</tr></table></td></tr>';
3637: $$rowtotal ++;
3638: if ($cansrchrow) {
3639: $datatable .= '<tr class="LC_odd_row">';
3640: } else {
3641: $datatable .= '<tr>';
3642: }
3643: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3644: '<td class="LC_left_item" colspan="2">'.
3645: '<span class="LC_nobreak"><label>'.
3646: '<input type="checkbox" name="searchtypes" '.
3647: $exacton.' value="exact" />'.&mt('Exact match').
3648: '</label> '.
3649: '<label><input type="checkbox" name="searchtypes" '.
3650: $beginson.' value="begins" />'.&mt('Begins with').
3651: '</label> '.
3652: '<label><input type="checkbox" name="searchtypes" '.
3653: $containson.' value="contains" />'.&mt('Contains').
3654: '</label></span></td></tr>';
3655: $$rowtotal ++;
1.26 raeburn 3656: } else {
1.160.6.72 raeburn 3657: my $domsrchon = ' checked="checked" ';
3658: my $domsrchoff = ' ';
3659: my $domlocalon = ' ';
3660: my $domlocaloff = ' checked="checked" ';
3661: if (ref($settings) eq 'HASH') {
3662: if ($settings->{'lclocalonly'} eq '1') {
3663: $domlocalon = $domlocaloff;
3664: $domlocaloff = ' ';
3665: }
3666: if ($settings->{'lcavailable'} eq '0') {
3667: $domsrchoff = $domsrchon;
3668: $domsrchon = ' ';
3669: }
3670: }
3671: $datatable='<tr class="LC_odd_row">'.
3672: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3673: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3674: '<input type="radio" name="dirsrch_domavailable"'.
3675: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3676: '<label><input type="radio" name="dirsrch_domavailable"'.
3677: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3678: '</tr><tr>'.
3679: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3680: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3681: '<input type="radio" name="dirsrch_domlocalonly"'.
3682: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3683: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3684: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3685: '</tr>';
3686: $$rowtotal += 2;
1.26 raeburn 3687: }
1.25 raeburn 3688: return $datatable;
3689: }
3690:
1.28 raeburn 3691: sub print_contacts {
1.160.6.78 raeburn 3692: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3693: my $datatable;
3694: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3695: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3696: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3697: if ($position eq 'top') {
3698: if (ref($settings) eq 'HASH') {
3699: foreach my $item (@contacts) {
3700: if (exists($settings->{$item})) {
3701: $to{$item} = $settings->{$item};
3702: }
1.28 raeburn 3703: }
3704: }
1.160.6.78 raeburn 3705: } elsif ($position eq 'middle') {
3706: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3707: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3708: foreach my $type (@mailings) {
1.160.6.78 raeburn 3709: $otheremails{$type} = '';
3710: }
1.160.6.107 raeburn 3711: } elsif ($position eq 'lower') {
3712: if (ref($settings) eq 'HASH') {
3713: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3714: %lonstatus = %{$settings->{'lonstatus'}};
3715: }
3716: }
1.160.6.78 raeburn 3717: } else {
3718: @mailings = ('helpdeskmail','otherdomsmail');
3719: foreach my $type (@mailings) {
3720: $otheremails{$type} = '';
3721: }
3722: $bccemails{'helpdeskmail'} = '';
3723: $bccemails{'otherdomsmail'} = '';
3724: $includestr{'helpdeskmail'} = '';
3725: $includestr{'otherdomsmail'} = '';
3726: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3727: }
3728: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3729: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3730: foreach my $type (@mailings) {
3731: if (exists($settings->{$type})) {
3732: if (ref($settings->{$type}) eq 'HASH') {
3733: foreach my $item (@contacts) {
3734: if ($settings->{$type}{$item}) {
3735: $checked{$type}{$item} = ' checked="checked" ';
3736: }
1.28 raeburn 3737: }
1.160.6.78 raeburn 3738: $otheremails{$type} = $settings->{$type}{'others'};
3739: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3740: $bccemails{$type} = $settings->{$type}{'bcc'};
3741: if ($settings->{$type}{'include'} ne '') {
3742: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3743: $includestr{$type} = &unescape($includestr{$type});
3744: }
3745: }
3746: }
3747: } elsif ($type eq 'lonstatusmail') {
3748: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3749: }
3750: }
3751: }
3752: if ($position eq 'bottom') {
3753: foreach my $type (@mailings) {
3754: $bccemails{$type} = $settings->{$type}{'bcc'};
3755: if ($settings->{$type}{'include'} ne '') {
3756: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3757: $includestr{$type} = &unescape($includestr{$type});
3758: }
3759: }
3760: if (ref($settings->{'helpform'}) eq 'HASH') {
3761: if (ref($fields) eq 'ARRAY') {
3762: foreach my $field (@{$fields}) {
3763: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3764: }
1.160.6.78 raeburn 3765: }
3766: if (exists($settings->{'helpform'}{'maxsize'})) {
3767: $maxsize = $settings->{'helpform'}{'maxsize'};
3768: } else {
3769: $maxsize = '1.0';
3770: }
3771: } else {
3772: if (ref($fields) eq 'ARRAY') {
3773: foreach my $field (@{$fields}) {
3774: $currfield{$field} = 'yes';
1.134 raeburn 3775: }
1.28 raeburn 3776: }
1.160.6.78 raeburn 3777: $maxsize = '1.0';
1.28 raeburn 3778: }
3779: }
3780: } else {
1.160.6.78 raeburn 3781: if ($position eq 'top') {
3782: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3783: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3784: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3785: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3786: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3787: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3788: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3789: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3790: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3791: } elsif ($position eq 'bottom') {
3792: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3793: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3794: if (ref($fields) eq 'ARRAY') {
3795: foreach my $field (@{$fields}) {
3796: $currfield{$field} = 'yes';
3797: }
3798: }
3799: $maxsize = '1.0';
3800: }
1.28 raeburn 3801: }
3802: my ($titles,$short_titles) = &contact_titles();
3803: my $rownum = 0;
3804: my $css_class;
1.160.6.78 raeburn 3805: if ($position eq 'top') {
3806: foreach my $item (@contacts) {
3807: $css_class = $rownum%2?' class="LC_odd_row"':'';
3808: $datatable .= '<tr'.$css_class.'>'.
3809: '<td><span class="LC_nobreak">'.$titles->{$item}.
3810: '</span></td><td class="LC_right_item">'.
3811: '<input type="text" name="'.$item.'" value="'.
3812: $to{$item}.'" /></td></tr>';
3813: $rownum ++;
3814: }
1.160.6.101 raeburn 3815: } elsif ($position eq 'bottom') {
3816: $css_class = $rownum%2?' class="LC_odd_row"':'';
3817: $datatable .= '<tr'.$css_class.'>'.
3818: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3819: &mt('(e-mail, subject, and description always shown)').
3820: '</td><td class="LC_left_item">';
3821: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3822: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3823: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3824: foreach my $field (@{$fields}) {
3825: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3826: if (($field eq 'screenshot') || ($field eq 'cc')) {
3827: $datatable .= ' '.&mt('(logged-in users)');
3828: }
3829: $datatable .='</td><td>';
3830: my $clickaction;
3831: if ($field eq 'screenshot') {
3832: $clickaction = ' onclick="screenshotSize(this);"';
3833: }
3834: if (ref($possoptions->{$field}) eq 'ARRAY') {
3835: foreach my $option (@{$possoptions->{$field}}) {
3836: my $checked;
3837: if ($currfield{$field} eq $option) {
3838: $checked = ' checked="checked"';
3839: }
3840: $datatable .= '<span class="LC_nobreak"><label>'.
3841: '<input type="radio" name="helpform_'.$field.'" '.
3842: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3843: '</label></span>'.(' 'x2);
3844: }
3845: }
3846: if ($field eq 'screenshot') {
3847: my $display;
3848: if ($currfield{$field} eq 'no') {
3849: $display = ' style="display:none"';
3850: }
3851: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
3852: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3853: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3854: }
3855: $datatable .= '</td></tr>';
3856: }
3857: $datatable .= '</table>';
3858: }
3859: $datatable .= '</td></tr>'."\n";
3860: $rownum ++;
3861: }
1.160.6.107 raeburn 3862: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3863: foreach my $type (@mailings) {
3864: $css_class = $rownum%2?' class="LC_odd_row"':'';
3865: $datatable .= '<tr'.$css_class.'>'.
3866: '<td><span class="LC_nobreak">'.
3867: $titles->{$type}.': </span></td>'.
3868: '<td class="LC_left_item">';
3869: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3870: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3871: }
3872: $datatable .= '<span class="LC_nobreak">';
3873: foreach my $item (@contacts) {
3874: $datatable .= '<label>'.
3875: '<input type="checkbox" name="'.$type.'"'.
3876: $checked{$type}{$item}.
3877: ' value="'.$item.'" />'.$short_titles->{$item}.
3878: '</label> ';
3879: }
3880: $datatable .= '</span><br />'.&mt('Others').': '.
3881: '<input type="text" name="'.$type.'_others" '.
3882: 'value="'.$otheremails{$type}.'" />';
3883: my %locchecked;
3884: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3885: foreach my $loc ('s','b') {
3886: if ($includeloc{$type} eq $loc) {
3887: $locchecked{$loc} = ' checked="checked"';
3888: last;
3889: }
3890: }
3891: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3892: '<input type="text" name="'.$type.'_bcc" '.
3893: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3894: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3895: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 3896: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 3897: '<span class="LC_nobreak">'.&mt('Location:').' '.
3898: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3899: (' 'x2).
3900: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3901: '</span></fieldset>';
3902: }
3903: $datatable .= '</td></tr>'."\n";
3904: $rownum ++;
3905: }
1.28 raeburn 3906: }
1.160.6.78 raeburn 3907: if ($position eq 'middle') {
3908: my %choices;
1.160.6.107 raeburn 3909: my $corelink = &core_link_msu();
3910: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 3911: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 3912: $corelink);
3913: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3914: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 3915: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 3916: 'reportupdates' => 'on',
3917: 'reportstatus' => 'on');
1.160.6.78 raeburn 3918: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3919: \%choices,$rownum);
3920: $datatable .= $reports;
1.160.6.107 raeburn 3921: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 3922: my (%current,%excluded,%weights);
1.160.6.107 raeburn 3923: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3924: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 3925: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 3926: } else {
1.160.6.109 raeburn 3927: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 3928: }
3929: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 3930: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 3931: } else {
1.160.6.109 raeburn 3932: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 3933: }
3934: if (ref($lonstatus{'weights'}) eq 'HASH') {
3935: foreach my $type ('E','W','N','U') {
3936: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3937: $weights{$type} = $lonstatus{'weights'}{$type};
3938: } else {
3939: $weights{$type} = $defaults->{$type};
3940: }
3941: }
3942: } else {
3943: foreach my $type ('E','W','N','U') {
3944: $weights{$type} = $defaults->{$type};
3945: }
3946: }
3947: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3948: if (@{$lonstatus{'excluded'}} > 0) {
3949: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3950: }
3951: }
1.160.6.109 raeburn 3952: foreach my $item ('errorthreshold','errorsysmail') {
3953: $css_class = $rownum%2?' class="LC_odd_row"':'';
3954: $datatable .= '<tr'.$css_class.'>'.
3955: '<td class="LC_left_item"><span class="LC_nobreak">'.
3956: $titles->{$item}.
3957: '</span></td><td class="LC_left_item">'.
3958: '<input type="text" name="'.$item.'" value="'.
3959: $current{$item}.'" size="5" /></td></tr>';
3960: $rownum ++;
3961: }
1.160.6.107 raeburn 3962: $css_class = $rownum%2?' class="LC_odd_row"':'';
3963: $datatable .= '<tr'.$css_class.'>'.
3964: '<td class="LC_left_item">'.
3965: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3966: '</span></td><td class="LC_left_item"><table><tr>';
3967: foreach my $type ('E','W','N','U') {
3968: $datatable .= '<td>'.$names->{$type}.'<br />'.
3969: '<input type="text" name="errorweights_'.$type.'" value="'.
3970: $weights{$type}.'" size="5" /></td>';
3971: }
3972: $datatable .= '</tr></table></tr>';
3973: $rownum ++;
3974: $css_class = $rownum%2?' class="LC_odd_row"':'';
3975: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3976: $titles->{'errorexcluded'}.'</td>'.
3977: '<td class="LC_left_item"><table>';
3978: my $numinrow = 4;
3979: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3980: for (my $i=0; $i<@ids; $i++) {
3981: my $rem = $i%($numinrow);
3982: if ($rem == 0) {
3983: if ($i > 0) {
3984: $datatable .= '</tr>';
3985: }
3986: $datatable .= '<tr>';
3987: }
3988: my $check;
3989: if ($excluded{$ids[$i]}) {
3990: $check = ' checked="checked" ';
3991: }
3992: $datatable .= '<td class="LC_left_item">'.
3993: '<span class="LC_nobreak"><label>'.
3994: '<input type="checkbox" name="errorexcluded" '.
3995: 'value="'.$ids[$i].'"'.$check.' />'.
3996: $ids[$i].'</label></span></td>';
3997: }
3998: my $colsleft = $numinrow - @ids%($numinrow);
3999: if ($colsleft > 1 ) {
4000: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4001: ' </td>';
4002: } elsif ($colsleft == 1) {
4003: $datatable .= '<td class="LC_left_item"> </td>';
4004: }
4005: $datatable .= '</tr></table></td></tr>';
4006: $rownum ++;
1.160.6.78 raeburn 4007: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4008: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4009: my (@posstypes,%usertypeshash);
4010: if (ref($types) eq 'ARRAY') {
4011: @posstypes = @{$types};
4012: }
4013: if (@posstypes) {
4014: if (ref($usertypes) eq 'HASH') {
4015: %usertypeshash = %{$usertypes};
4016: }
4017: my @overridden;
4018: my $numinrow = 4;
4019: if (ref($settings) eq 'HASH') {
4020: if (ref($settings->{'overrides'}) eq 'HASH') {
4021: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4022: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4023: push(@overridden,$key);
4024: foreach my $item (@contacts) {
4025: if ($settings->{'overrides'}{$key}{$item}) {
4026: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4027: }
4028: }
4029: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4030: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4031: $includeloc{'override_'.$key} = '';
4032: $includestr{'override_'.$key} = '';
4033: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4034: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4035: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4036: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4037: }
1.160.6.78 raeburn 4038: }
4039: }
4040: }
1.160.6.101 raeburn 4041: }
4042: my $customclass = 'LC_helpdesk_override';
4043: my $optionsprefix = 'LC_options_helpdesk_';
4044:
4045: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4046:
4047: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4048: $numinrow,$othertitle,'overrides',
4049: \$rownum,$onclicktypes,$customclass);
4050: $rownum ++;
4051: $usertypeshash{'default'} = $othertitle;
4052: foreach my $status (@posstypes) {
4053: my $css_class;
4054: if ($rownum%2) {
4055: $css_class = 'LC_odd_row ';
4056: }
4057: $css_class .= $customclass;
4058: my $rowid = $optionsprefix.$status;
4059: my $hidden = 1;
4060: my $currstyle = 'display:none';
4061: if (grep(/^\Q$status\E$/,@overridden)) {
4062: $currstyle = 'display:table-row';
4063: $hidden = 0;
4064: }
4065: my $key = 'override_'.$status;
4066: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4067: $includeloc{$key},$includestr{$key},$status,$rowid,
4068: $usertypeshash{$status},$css_class,$currstyle,
4069: \@contacts,$short_titles);
4070: unless ($hidden) {
4071: $rownum ++;
1.160.6.78 raeburn 4072: }
4073: }
1.134 raeburn 4074: }
1.28 raeburn 4075: }
1.30 raeburn 4076: $$rowtotal += $rownum;
1.28 raeburn 4077: return $datatable;
4078: }
4079:
1.160.6.107 raeburn 4080: sub core_link_msu {
4081: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4082: &mt('LON-CAPA core group - MSU'),600,500);
4083: }
4084:
1.160.6.101 raeburn 4085: sub overridden_helpdesk {
4086: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4087: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4088: my $class = 'LC_left_item';
4089: if ($css_class) {
4090: $css_class = ' class="'.$css_class.'"';
4091: }
4092: if ($rowid) {
4093: $rowid = ' id="'.$rowid.'"';
4094: }
4095: if ($rowstyle) {
4096: $rowstyle = ' style="'.$rowstyle.'"';
4097: }
4098: my ($output,$description);
4099: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4100: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4101: "<td>$description</td>\n".
4102: '<td class="'.$class.'" colspan="2">'.
4103: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4104: '<span class="LC_nobreak">';
4105: if (ref($contacts) eq 'ARRAY') {
4106: foreach my $item (@{$contacts}) {
4107: my $check;
4108: if (ref($checked) eq 'HASH') {
4109: $check = $checked->{$item};
4110: }
4111: my $title;
4112: if (ref($short_titles) eq 'HASH') {
4113: $title = $short_titles->{$item};
4114: }
4115: $output .= '<label>'.
4116: '<input type="checkbox" name="override_'.$type.'"'.$check.
4117: ' value="'.$item.'" />'.$title.'</label> ';
4118: }
4119: }
4120: $output .= '</span><br />'.&mt('Others').': '.
4121: '<input type="text" name="override_'.$type.'_others" '.
4122: 'value="'.$otheremails.'" />';
4123: my %locchecked;
4124: foreach my $loc ('s','b') {
4125: if ($includeloc eq $loc) {
4126: $locchecked{$loc} = ' checked="checked"';
4127: last;
4128: }
4129: }
4130: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4131: '<input type="text" name="override_'.$type.'_bcc" '.
4132: 'value="'.$bccemails.'" /></fieldset>'.
4133: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4134: &mt('Text automatically added to e-mail:').' '.
4135: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4136: '<span class="LC_nobreak">'.&mt('Location:').' '.
4137: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4138: (' 'x2).
4139: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4140: '</span></fieldset>'.
4141: '</td></tr>'."\n";
4142: return $output;
4143: }
4144:
1.160.6.78 raeburn 4145: sub contacts_javascript {
4146: return <<"ENDSCRIPT";
4147:
4148: <script type="text/javascript">
4149: // <![CDATA[
4150:
4151: function screenshotSize(field) {
4152: if (document.getElementById('help_screenshotsize')) {
4153: if (field.value == 'no') {
4154: document.getElementById('help_screenshotsize').style.display="none";
4155: } else {
4156: document.getElementById('help_screenshotsize').style.display="";
4157: }
4158: }
4159: return;
4160: }
4161:
1.160.6.101 raeburn 4162: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4163: if (form.elements[checkbox].length != undefined) {
4164: var count = 0;
4165: if (docount) {
4166: for (var i=0; i<form.elements[checkbox].length; i++) {
4167: if (form.elements[checkbox][i].checked) {
4168: count ++;
4169: }
4170: }
4171: }
4172: for (var i=0; i<form.elements[checkbox].length; i++) {
4173: var type = form.elements[checkbox][i].value;
4174: if (document.getElementById(prefix+type)) {
4175: if (form.elements[checkbox][i].checked) {
4176: document.getElementById(prefix+type).style.display = 'table-row';
4177: if (count % 2 == 1) {
4178: document.getElementById(prefix+type).className = target+' LC_odd_row';
4179: } else {
4180: document.getElementById(prefix+type).className = target;
4181: }
4182: count ++;
4183: } else {
4184: document.getElementById(prefix+type).style.display = 'none';
4185: }
4186: }
4187: }
4188: }
4189: return;
4190: }
4191:
1.160.6.78 raeburn 4192: // ]]>
4193: </script>
4194:
4195: ENDSCRIPT
4196: }
4197:
1.118 jms 4198: sub print_helpsettings {
1.160.6.73 raeburn 4199: my ($position,$dom,$settings,$rowtotal) = @_;
4200: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4201: my $formname = 'display';
1.160.6.5 raeburn 4202: my ($datatable,$itemcount);
1.160.6.73 raeburn 4203: if ($position eq 'top') {
4204: $itemcount = 1;
4205: my (%choices,%defaultchecked,@toggles);
4206: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4207: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4208: &mt('LON-CAPA bug tracker'),600,500));
4209: %defaultchecked = ('submitbugs' => 'on');
4210: @toggles = ('submitbugs');
4211: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4212: \%choices,$itemcount);
4213: $$rowtotal ++;
4214: } else {
4215: my $css_class;
4216: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4217: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4218: if (ref($settings) eq 'HASH') {
4219: if (ref($settings->{'adhoc'}) eq 'HASH') {
4220: %current = %{$settings->{'adhoc'}};
4221: }
1.160.6.77 raeburn 4222: }
4223: my $count = 0;
4224: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4225: if ($key=~/^rolesdef\_(\w+)$/) {
4226: my $rolename = $1;
1.160.6.77 raeburn 4227: my (%privs,$order);
1.160.6.73 raeburn 4228: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4229: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4230: if (ref($current{$rolename}) eq 'HASH') {
4231: $order = $current{$rolename}{'order'};
4232: }
4233: if ($order eq '') {
4234: $order = $count;
4235: }
4236: $ordered{$order} = $rolename;
4237: $count++;
1.160.6.73 raeburn 4238: }
4239: }
1.160.6.77 raeburn 4240: my $maxnum = scalar(keys(%ordered));
4241: my @roles_by_num = ();
4242: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4243: push(@roles_by_num,$item);
4244: }
4245: my $context = 'domprefs';
4246: my $crstype = 'Course';
4247: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4248: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4249: my ($numstatustypes,@jsarray);
4250: if (ref($types) eq 'ARRAY') {
4251: if (@{$types} > 0) {
4252: $numstatustypes = scalar(@{$types});
4253: push(@accesstypes,'status');
4254: @jsarray = ('bystatus');
4255: }
4256: }
1.160.6.86 raeburn 4257: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4258: if (keys(%domhelpdesk)) {
4259: push(@accesstypes,('inc','exc'));
4260: push(@jsarray,('notinc','notexc'));
4261: }
4262: my $hiddenstr = join("','",@jsarray);
4263: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4264: my $context = 'domprefs';
4265: my $crstype = 'Course';
1.160.6.77 raeburn 4266: my $prefix = 'helproles_';
4267: my $add_class = 'LC_hidden';
4268: foreach my $num (@roles_by_num) {
4269: my $role = $ordered{$num};
4270: my ($desc,$access,@statuses);
4271: if (ref($current{$role}) eq 'HASH') {
4272: $desc = $current{$role}{'desc'};
4273: $access = $current{$role}{'access'};
4274: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4275: @statuses = @{$current{$role}{'insttypes'}};
4276: }
4277: }
4278: if ($desc eq '') {
4279: $desc = $role;
4280: }
4281: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4282: my %full=();
4283: my %levels= (
4284: course => {},
4285: domain => {},
4286: system => {},
4287: );
4288: my %levelscurrent=(
4289: course => {},
4290: domain => {},
4291: system => {},
4292: );
4293: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4294: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4295: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4296: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4297: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4298: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4299: for (my $k=0; $k<=$maxnum; $k++) {
4300: my $vpos = $k+1;
4301: my $selstr;
4302: if ($k == $num) {
4303: $selstr = ' selected="selected" ';
4304: }
4305: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4306: }
4307: $datatable .= '</select>'.(' 'x2).
4308: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4309: '</td>'.
4310: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4311: &mt('Name shown to users:').
4312: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4313: '</fieldset>'.
4314: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4315: $othertitle,$usertypes,$types,\%domhelpdesk).
4316: '<fieldset>'.
4317: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4318: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4319: \%levelscurrent,$identifier,
4320: 'LC_hidden',$prefix.$num.'_privs').
4321: '</fieldset></td>';
1.160.6.73 raeburn 4322: $itemcount ++;
4323: }
4324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4325: my $newcust = 'custhelp'.$count;
4326: my (%privs,%levelscurrent);
4327: my %full=();
4328: my %levels= (
4329: course => {},
4330: domain => {},
4331: system => {},
4332: );
4333: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4334: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4335: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4336: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4337: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4338: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4339: for (my $k=0; $k<$maxnum+1; $k++) {
4340: my $vpos = $k+1;
4341: my $selstr;
4342: if ($k == $maxnum) {
4343: $selstr = ' selected="selected" ';
4344: }
4345: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4346: }
4347: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4348: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4349: '</label></span></td>'.
1.160.6.77 raeburn 4350: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4351: '<span class="LC_nobreak">'.
4352: &mt('Internal name:').
4353: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4354: '</span>'.(' 'x4).
4355: '<span class="LC_nobreak">'.
4356: &mt('Name shown to users:').
4357: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4358: '</span></fieldset>'.
4359: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4360: $usertypes,$types,\%domhelpdesk).
4361: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4362: &Apache::lonuserutils::custom_role_header($context,$crstype,
4363: \@templateroles,$newcust).
4364: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4365: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4366: '</fieldset>'.
4367: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4368: '</td></tr>';
1.160.6.73 raeburn 4369: $count ++;
4370: $$rowtotal += $count;
4371: }
1.160.6.5 raeburn 4372: return $datatable;
1.121 raeburn 4373: }
4374:
1.160.6.77 raeburn 4375: sub adhocbutton {
4376: my ($prefix,$num,$field,$visibility) = @_;
4377: my %lt = &Apache::lonlocal::texthash(
4378: show => 'Show details',
4379: hide => 'Hide details',
4380: );
4381: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4382: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4383: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4384: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4385: }
4386:
4387: sub helpsettings_javascript {
4388: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4389: return unless(ref($roles_by_num) eq 'ARRAY');
4390: my %html_js_lt = &Apache::lonlocal::texthash(
4391: show => 'Show details',
4392: hide => 'Hide details',
4393: );
4394: &html_escape(\%html_js_lt);
4395: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4396: return <<"ENDSCRIPT";
4397: <script type="text/javascript">
4398: // <![CDATA[
4399:
4400: function reorderHelpRoles(form,item) {
4401: var changedVal;
4402: $jstext
4403: var newpos = 'helproles_${total}_pos';
4404: var maxh = 1 + $total;
4405: var current = new Array();
4406: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4407: if (item == newpos) {
4408: changedVal = newitemVal;
4409: } else {
4410: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4411: current[newitemVal] = newpos;
4412: }
4413: for (var i=0; i<helproles.length; i++) {
4414: var elementName = 'helproles_'+helproles[i]+'_pos';
4415: if (elementName != item) {
4416: if (form.elements[elementName]) {
4417: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4418: current[currVal] = elementName;
4419: }
4420: }
4421: }
4422: var oldVal;
4423: for (var j=0; j<maxh; j++) {
4424: if (current[j] == undefined) {
4425: oldVal = j;
4426: }
4427: }
4428: if (oldVal < changedVal) {
4429: for (var k=oldVal+1; k<=changedVal ; k++) {
4430: var elementName = current[k];
4431: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4432: }
4433: } else {
4434: for (var k=changedVal; k<oldVal; k++) {
4435: var elementName = current[k];
4436: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4437: }
4438: }
4439: return;
4440: }
4441:
4442: function helpdeskAccess(num) {
4443: var curraccess = null;
4444: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4445: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4446: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4447: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4448: }
4449: }
4450: }
4451: var shown = Array();
4452: var hidden = Array();
4453: if (curraccess == 'none') {
4454: hidden = Array('$hiddenstr');
4455: } else {
4456: if (curraccess == 'status') {
4457: shown = Array('bystatus');
4458: hidden = Array('notinc','notexc');
4459: } else {
4460: if (curraccess == 'exc') {
4461: shown = Array('notexc');
4462: hidden = Array('notinc','bystatus');
4463: }
4464: if (curraccess == 'inc') {
4465: shown = Array('notinc');
4466: hidden = Array('notexc','bystatus');
4467: }
1.160.6.79 raeburn 4468: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4469: hidden = Array('notinc','notexc','bystatus');
4470: }
4471: }
4472: }
4473: if (hidden.length > 0) {
4474: for (var i=0; i<hidden.length; i++) {
4475: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4476: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4477: }
4478: }
4479: }
4480: if (shown.length > 0) {
4481: for (var i=0; i<shown.length; i++) {
4482: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4483: if (shown[i] == 'privs') {
4484: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4485: } else {
4486: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4487: }
4488: }
4489: }
4490: }
4491: return;
4492: }
4493:
4494: function toggleHelpdeskItem(num,field) {
4495: if (document.getElementById('helproles_'+num+'_'+field)) {
4496: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4497: document.getElementById('helproles_'+num+'_'+field).className =
4498: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4499: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4500: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4501: }
4502: } else {
4503: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4504: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4505: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4506: }
4507: }
4508: }
4509: return;
4510: }
4511:
4512: // ]]>
4513: </script>
4514:
4515: ENDSCRIPT
4516: }
4517:
4518: sub helpdeskroles_access {
4519: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4520: $usertypes,$types,$domhelpdesk) = @_;
4521: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4522: my %lt = &Apache::lonlocal::texthash(
4523: 'rou' => 'Role usage',
4524: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4525: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4526: 'dh' => 'All with domain helpdesk role',
4527: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4528: 'none' => 'None',
4529: 'status' => 'Determined based on institutional status',
4530: 'inc' => 'Include all, but exclude specific personnel',
4531: 'exc' => 'Exclude all, but include specific personnel',
4532: );
4533: my %usecheck = (
4534: all => ' checked="checked"',
4535: );
4536: my %displaydiv = (
4537: status => 'none',
4538: inc => 'none',
4539: exc => 'none',
4540: priv => 'block',
4541: );
4542: my $output;
4543: if (ref($current) eq 'HASH') {
4544: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4545: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4546: $usecheck{$current->{access}} = $usecheck{'all'};
4547: delete($usecheck{'all'});
4548: if ($current->{access} =~ /^(status|inc|exc)$/) {
4549: my $access = $1;
4550: $displaydiv{$access} = 'inline';
4551: } elsif ($current->{access} eq 'none') {
4552: $displaydiv{'priv'} = 'none';
4553: }
4554: }
4555: }
4556: }
4557: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4558: '<p>'.$lt{'whi'}.'</p>';
4559: foreach my $access (@{$accesstypes}) {
4560: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4561: ' onclick="helpdeskAccess('."'$num'".');" />'.
4562: $lt{$access}.'</label>';
4563: if ($access eq 'status') {
4564: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4565: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4566: $othertitle,$usertypes,$types).
4567: '</div>';
4568: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4569: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4570: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4571: '</div>';
4572: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4573: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4574: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4575: '</div>';
4576: }
4577: $output .= '</p>';
4578: }
4579: $output .= '</fieldset>';
4580: return $output;
4581: }
4582:
1.121 raeburn 4583: sub radiobutton_prefs {
1.160.6.16 raeburn 4584: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4585: $additional,$align,$firstval) = @_;
1.121 raeburn 4586: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4587: (ref($choices) eq 'HASH'));
4588:
4589: my (%checkedon,%checkedoff,$datatable,$css_class);
4590:
4591: foreach my $item (@{$toggles}) {
4592: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4593: $checkedon{$item} = ' checked="checked" ';
4594: $checkedoff{$item} = ' ';
1.121 raeburn 4595: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4596: $checkedoff{$item} = ' checked="checked" ';
4597: $checkedon{$item} = ' ';
4598: }
4599: }
4600: if (ref($settings) eq 'HASH') {
1.121 raeburn 4601: foreach my $item (@{$toggles}) {
1.118 jms 4602: if ($settings->{$item} eq '1') {
4603: $checkedon{$item} = ' checked="checked" ';
4604: $checkedoff{$item} = ' ';
4605: } elsif ($settings->{$item} eq '0') {
4606: $checkedoff{$item} = ' checked="checked" ';
4607: $checkedon{$item} = ' ';
4608: }
4609: }
1.121 raeburn 4610: }
1.160.6.16 raeburn 4611: if ($onclick) {
4612: $onclick = ' onclick="'.$onclick.'"';
4613: }
1.121 raeburn 4614: foreach my $item (@{$toggles}) {
1.118 jms 4615: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4616: $datatable .=
1.160.6.16 raeburn 4617: '<tr'.$css_class.'><td valign="top">'.
4618: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4619: '</span></td>';
4620: if ($align eq 'left') {
4621: $datatable .= '<td class="LC_left_item">';
4622: } else {
4623: $datatable .= '<td class="LC_right_item">';
4624: }
1.160.6.113 raeburn 4625: $datatable .= '<span class="LC_nobreak">';
4626: if ($firstval eq 'no') {
4627: $datatable .=
4628: '<label><input type="radio" name="'.
4629: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4630: '</label> <label><input type="radio" name="'.$item.'" '.
4631: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4632: } else {
4633: $datatable .=
1.118 jms 4634: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4635: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4636: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4637: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4638: }
4639: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4640: $itemcount ++;
1.121 raeburn 4641: }
4642: return ($datatable,$itemcount);
4643: }
4644:
1.160.6.118.2 1(raebur 4645:1): sub print_ltitools {
4646:1): my ($dom,$settings,$rowtotal) = @_;
4647:1): my $rownum = 0;
4648:1): my $css_class;
4649:1): my $itemcount = 1;
4650:1): my $maxnum = 0;
4651:1): my %ordered;
4652:1): if (ref($settings) eq 'HASH') {
4653:1): foreach my $item (keys(%{$settings})) {
4654:1): if (ref($settings->{$item}) eq 'HASH') {
4655:1): my $num = $settings->{$item}{'order'};
4656:1): $ordered{$num} = $item;
4657:1): }
4658:1): }
4659:1): }
4660:1): my $confname = $dom.'-domainconfig';
4661:1): my $switchserver = &check_switchserver($dom,$confname);
4662:1): my $maxnum = scalar(keys(%ordered));
4663:1): my $datatable;
4664:1): my %lt = <itools_names();
4665:1): my @courseroles = ('cc','in','ta','ep','st');
4666:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4667:1): my @fields = ('fullname','firstname','lastname','email','roles','user');
4668:1): if (keys(%ordered)) {
4669:1): my @items = sort { $a <=> $b } keys(%ordered);
4670:1): for (my $i=0; $i<@items; $i++) {
4671:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4672:1): my $item = $ordered{$items[$i]};
4673:1): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
4674:1): if (ref($settings->{$item}) eq 'HASH') {
4675:1): $title = $settings->{$item}->{'title'};
4676:1): $url = $settings->{$item}->{'url'};
4677:1): $key = $settings->{$item}->{'key'};
4678:1): $secret = $settings->{$item}->{'secret'};
4679:1): $lifetime = $settings->{$item}->{'lifetime'};
4680:1): my $image = $settings->{$item}->{'image'};
4681:1): if ($image ne '') {
4682:1): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4683:1): }
4684:1): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4685:1): $sigsel{'HMAC-256'} = ' selected="selected"';
4686:1): } else {
4687:1): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4688:1): }
4689:1): }
4690:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
4691:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4692:1): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4693:1): for (my $k=0; $k<=$maxnum; $k++) {
4694:1): my $vpos = $k+1;
4695:1): my $selstr;
4696:1): if ($k == $i) {
4697:1): $selstr = ' selected="selected" ';
4698:1): }
4699:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4700:1): }
4701:1): $datatable .= '</select>'.(' 'x2).
4702:1): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4703:1): &mt('Delete?').'</label></span></td>'.
4704:1): '<td colspan="2">'.
4705:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4706:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4707:1): (' 'x2).
4708:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4709:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4710:1): (' 'x2).
4711:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4712:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4713:1): (' 'x2).
4714:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4715:1): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4716:1): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4717:1): '<br /><br />'.
4718:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4719:1): ' value="'.$url.'" /></span>'.
4720:1): (' 'x2).
4721:1): '<span class="LC_nobreak">'.$lt{'key'}.':'.
4722:1): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4723:1): (' 'x2).
4724:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4725:1): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4726:1): (' 'x2).
4727:1): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4728:1): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4729: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>'.
4730:1): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4731:1): '</fieldset>'.
4732:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4733:1): '<span class="LC_nobreak">'.&mt('Display target:');
4734:1): my %currdisp;
4735:1): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4736:1): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4737:1): $currdisp{'window'} = ' checked="checked"';
4738:1): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4739:1): $currdisp{'tab'} = ' checked="checked"';
4740:1): } else {
4741:1): $currdisp{'iframe'} = ' checked="checked"';
4742:1): }
4743:1): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4744:1): $currdisp{'width'} = $1;
4745:1): }
4746:1): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4747:1): $currdisp{'height'} = $1;
4748:1): }
4749:1): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4750:1): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4751:1): } else {
4752:1): $currdisp{'iframe'} = ' checked="checked"';
4753:1): }
4754:1): foreach my $disp ('iframe','tab','window') {
4755:1): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4756:1): $lt{$disp}.'</label>'.(' 'x2);
4757:1): }
4758:1): $datatable .= (' 'x4);
4759:1): foreach my $dimen ('width','height') {
4760:1): $datatable .= '<label>'.$lt{$dimen}.' '.
4761:1): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4762:1): (' 'x2);
4763:1): }
4764:1): $datatable .= '</span><br />'.
4765:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4766:1): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4767:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4768:1): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4769:1): '</textarea></div><div style=""></div>'.
4770:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4771:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4772:1): if ($imgsrc) {
4773:1): $datatable .= $imgsrc.
4774:1): '<label><input type="checkbox" name="ltitools_image_del"'.
4775:1): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4776:1): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4777:1): } else {
4778:1): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4779:1): }
4780:1): if ($switchserver) {
4781:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4782:1): } else {
4783:1): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4784:1): }
4785:1): $datatable .= '</span></fieldset>';
4786:1): my (%checkedfields,%rolemaps,$userincdom);
4787:1): if (ref($settings->{$item}) eq 'HASH') {
4788:1): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4789:1): %checkedfields = %{$settings->{$item}->{'fields'}};
4790:1): }
4791:1): $userincdom = $settings->{$item}->{'incdom'};
4792:1): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4793:1): %rolemaps = %{$settings->{$item}->{'roles'}};
4794:1): $checkedfields{'roles'} = 1;
4795:1): }
4796:1): }
4797:1): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4798:1): '<span class="LC_nobreak">';
4799:1): my $userfieldstyle = 'display:none;';
4800:1): my $seluserdom = '';
4801:1): my $unseluserdom = ' selected="selected"';
4802:1): foreach my $field (@fields) {
4803:1): my ($checked,$onclick,$id,$spacer);
4804:1): if ($checkedfields{$field}) {
4805:1): $checked = ' checked="checked"';
4806:1): }
4807:1): if ($field eq 'user') {
4808:1): $id = ' id="ltitools_user_field_'.$i.'"';
4809:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4810:1): if ($checked) {
4811:1): $userfieldstyle = 'display:inline-block';
4812:1): if ($userincdom) {
4813:1): $seluserdom = $unseluserdom;
4814:1): $unseluserdom = '';
4815:1): }
4816:1): }
4817:1): } else {
4818:1): $spacer = (' ' x2);
4819:1): }
4820:1): $datatable .= '<label>'.
4821:1): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4822:1): $lt{$field}.'</label>'.$spacer;
4823:1): }
4824:1): $datatable .= '</span>';
4825:1): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4826:1): '<span class="LC_nobreak"> : '.
4827:1): '<select name="ltitools_userincdom_'.$i.'">'.
4828:1): '<option value="">'.&mt('Select').'</option>'.
4829:1): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4830:1): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4831:1): '</select></span></div>';
4832:1): $datatable .= '</fieldset>'.
4833:1): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4834:1): foreach my $role (@courseroles) {
4835:1): my ($selected,$selectnone);
4836:1): if (!$rolemaps{$role}) {
4837:1): $selectnone = ' selected="selected"';
4838:1): }
4839:1): $datatable .= '<td align="center">'.
4840:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4841:1): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4842:1): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4843:1): foreach my $ltirole (@ltiroles) {
4844:1): unless ($selectnone) {
4845:1): if ($rolemaps{$role} eq $ltirole) {
4846:1): $selected = ' selected="selected"';
4847:1): } else {
4848:1): $selected = '';
4849:1): }
4850:1): }
4851:1): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4852:1): }
4853:1): $datatable .= '</select></td>';
4854:1): }
4855:1): $datatable .= '</tr></table></fieldset>';
4856:1): my %courseconfig;
4857:1): if (ref($settings->{$item}) eq 'HASH') {
4858:1): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4859:1): %courseconfig = %{$settings->{$item}->{'crsconf'}};
4860:1): }
4861:1): }
4862:1): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4863:1): foreach my $item ('label','title','target','linktext','explanation','append') {
4864:1): my $checked;
4865:1): if ($courseconfig{$item}) {
4866:1): $checked = ' checked="checked"';
4867:1): }
4868:1): $datatable .= '<label>'.
4869:1): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4870:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4871:1): }
4872:1): $datatable .= '</span></fieldset>'.
4873:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4874:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4875:1): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4876:1): my %custom = %{$settings->{$item}->{'custom'}};
4877:1): if (keys(%custom) > 0) {
4878:1): foreach my $key (sort(keys(%custom))) {
4879:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
4880:1): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4881:1): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4882:1): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4883:1): ' value="'.$custom{$key}.'" /></td></tr>';
4884:1): }
4885:1): }
4886:1): }
4887:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
4888:1): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4889:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4890:1): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4891:1): $datatable .= '</table></fieldset></td></tr>'."\n";
4892:1): $itemcount ++;
4893:1): }
4894:1): }
4895:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4896:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
4897:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4898:1): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4899:1): '<select name="ltitools_add_pos"'.$chgstr.'>';
4900:1): for (my $k=0; $k<$maxnum+1; $k++) {
4901:1): my $vpos = $k+1;
4902:1): my $selstr;
4903:1): if ($k == $maxnum) {
4904:1): $selstr = ' selected="selected" ';
4905:1): }
4906:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4907:1): }
4908:1): $datatable .= '</select> '."\n".
4909:1): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
4910:1): '<td colspan="2">'.
4911:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4912:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
4913:1): (' 'x2).
4914:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4915:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4916:1): (' 'x2).
4917:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4918:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4919:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4920:1): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4921:1): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
4922:1): '<br />'.
4923:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
4924:1): (' 'x2).
4925:1): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4926:1): (' 'x2).
4927:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4928:1): (' 'x2).
4929:1): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4930: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".
4931:1): '</fieldset>'.
4932:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4933:1): '<span class="LC_nobreak">'.&mt('Display target:');
4934:1): my %defaultdisp;
4935:1): $defaultdisp{'iframe'} = ' checked="checked"';
4936:1): foreach my $disp ('iframe','tab','window') {
4937:1): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4938:1): $lt{$disp}.'</label>'.(' 'x2);
4939:1): }
4940:1): $datatable .= (' 'x4);
4941:1): foreach my $dimen ('width','height') {
4942:1): $datatable .= '<label>'.$lt{$dimen}.' '.
4943:1): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4944:1): (' 'x2);
4945:1): }
4946:1): $datatable .= '</span><br />'.
4947:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4948:1): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
4949:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4950:1): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4951:1): '</div><div style=""></div>'.
4952:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4953:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
4954:1): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4955:1): if ($switchserver) {
4956:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4957:1): } else {
4958:1): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4959:1): }
4960:1): $datatable .= '</span></fieldset>'.
4961:1): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4962:1): '<span class="LC_nobreak">';
4963:1): foreach my $field (@fields) {
4964:1): my ($id,$onclick,$spacer);
4965:1): if ($field eq 'user') {
4966:1): $id = ' id="ltitools_user_field_add"';
4967:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4968:1): } else {
4969:1): $spacer = (' ' x2);
4970:1): }
4971:1): $datatable .= '<label>'.
4972:1): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4973:1): $lt{$field}.'</label>'.$spacer;
4974:1): }
4975:1): $datatable .= '</span>'.
4976:1): '<div style="display:none;" id="ltitools_user_div_add">'.
4977:1): '<span class="LC_nobreak"> : '.
4978:1): '<select name="ltitools_userincdom_add">'.
4979:1): '<option value="" selected="selected">'.&mt('Select').'</option>'.
4980:1): '<option value="0">'.&mt('username').'</option>'.
4981:1): '<option value="1">'.&mt('username:domain').'</option>'.
4982:1): '</select></span></div></fieldset>';
4983:1): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4984:1): foreach my $role (@courseroles) {
4985:1): my ($checked,$checkednone);
4986:1): $datatable .= '<td align="center">'.
4987:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
4988:1): '<select name="ltitools_add_roles_'.$role.'">'.
4989:1): '<option value="" selected="selected">'.&mt('Select').'</option>';
4990:1): foreach my $ltirole (@ltiroles) {
4991:1): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4992:1): }
4993:1): $datatable .= '</select></td>';
4994:1): }
4995:1): $datatable .= '</tr></table></fieldset>'.
4996:1): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
4997:1): foreach my $item ('label','title','target','linktext','explanation','append') {
4998:1): $datatable .= '<label>'.
4999:1): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5000:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5001:1): }
5002:1): $datatable .= '</span></fieldset>'.
5003:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5004:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5005:1): '<tr><td><span class="LC_nobreak">'.
5006:1): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5007:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5008:1): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5009:1): '</table></fieldset>'."\n".
5010:1): '</td>'."\n".
5011:1): '</tr>'."\n";
5012:1): $itemcount ++;
5013:1): return $datatable;
5014:1): }
5015:1):
5016:1): sub ltitools_names {
5017:1): my %lt = &Apache::lonlocal::texthash(
5018:1): 'title' => 'Title',
5019:1): 'version' => 'Version',
5020:1): 'msgtype' => 'Message Type',
5021:1): 'sigmethod' => 'Signature Method',
5022:1): 'url' => 'URL',
5023:1): 'key' => 'Key',
5024:1): 'lifetime' => 'Nonce lifetime (s)',
5025:1): 'secret' => 'Secret',
5026:1): 'icon' => 'Icon',
5027:1): 'user' => 'User',
5028:1): 'fullname' => 'Full Name',
5029:1): 'firstname' => 'First Name',
5030:1): 'lastname' => 'Last Name',
5031:1): 'email' => 'E-mail',
5032:1): 'roles' => 'Role',
5033:1): 'window' => 'Window',
5034:1): 'tab' => 'Tab',
5035:1): 'iframe' => 'iFrame',
5036:1): 'height' => 'Height',
5037:1): 'width' => 'Width',
5038:1): 'linktext' => 'Default Link Text',
5039:1): 'explanation' => 'Default Explanation',
5040:1): 'crstarget' => 'Display target',
5041:1): 'crslabel' => 'Course label',
5042:1): 'crstitle' => 'Course title',
5043:1): 'crslinktext' => 'Link Text',
5044:1): 'crsexplanation' => 'Explanation',
5045:1): 'crsappend' => 'Provider URL',
5046:1): );
5047:1):
5048:1): return %lt;
5049:1): }
5050:1):
1.121 raeburn 5051: sub print_coursedefaults {
1.139 raeburn 5052: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5053: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5054: my $itemcount = 1;
1.160.6.16 raeburn 5055: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5056: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 5057: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5058: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5059: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5060: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5061: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5062: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5063: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5064: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5065: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 4(raebur 5066:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.160.6.16 raeburn 5067: );
1.160.6.21 raeburn 5068: my %staticdefaults = (
5069: anonsurvey_threshold => 10,
5070: uploadquota => 500,
1.160.6.57 raeburn 5071: postsubmit => 60,
1.160.6.70 raeburn 5072: mysqltables => 172800,
1.160.6.21 raeburn 5073: );
1.139 raeburn 5074: if ($position eq 'top') {
1.160.6.57 raeburn 5075: %defaultchecked = (
5076: 'uselcmath' => 'on',
5077: 'usejsme' => 'on',
1.160.6.115 raeburn 5078: 'inline_chem' => 'on',
1.160.6.64 raeburn 5079: 'canclone' => 'none',
1.160.6.57 raeburn 5080: );
1.160.6.115 raeburn 5081: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5082: my $deftex = $Apache::lonnet::deftex;
5083: if (ref($settings) eq 'HASH') {
5084: if ($settings->{'texengine'}) {
5085: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5086: $deftex = $settings->{'texengine'};
5087: }
5088: }
5089: }
5090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5091: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5092: '<span class="LC_nobreak">'.$choices{'texengine'}.
5093: '</span></td><td class="LC_right_item">'.
5094: '<select name="texengine">'."\n";
5095: my %texoptions = (
5096: MathJax => 'MathJax',
5097: mimetex => &mt('Convert to Images'),
5098: tth => &mt('TeX to HTML'),
5099: );
5100: foreach my $renderer ('MathJax','mimetex','tth') {
5101: my $selected = '';
5102: if ($renderer eq $deftex) {
5103: $selected = ' selected="selected"';
5104: }
5105: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5106: }
5107: $mathdisp .= '</select></td></tr>'."\n";
5108: $itemcount ++;
1.139 raeburn 5109: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5110: \%choices,$itemcount);
1.160.6.90 raeburn 5111: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5112: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5113: $datatable .=
5114: '<tr'.$css_class.'><td valign="top">'.
5115: '<span class="LC_nobreak">'.$choices{'canclone'}.
5116: '</span></td><td class="LC_left_item">';
5117: my $currcanclone = 'none';
5118: my $onclick;
5119: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5120: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5121: none => 'No additional course requesters',
5122: domain => "Any course requester in course's domain",
5123: instcode => 'Course requests for official courses ...',
5124: );
5125: my (%codedefaults,@code_order,@posscodes);
5126: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5127: \@code_order) eq 'ok') {
5128: if (@code_order > 0) {
5129: push(@cloneoptions,'instcode');
5130: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5131: }
5132: }
5133: if (ref($settings) eq 'HASH') {
5134: if ($settings->{'canclone'}) {
5135: if (ref($settings->{'canclone'}) eq 'HASH') {
5136: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5137: if (@code_order > 0) {
5138: $currcanclone = 'instcode';
5139: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5140: }
5141: }
5142: } elsif ($settings->{'canclone'} eq 'domain') {
5143: $currcanclone = $settings->{'canclone'};
5144: }
5145: }
5146: }
5147: foreach my $option (@cloneoptions) {
5148: my ($checked,$additional);
5149: if ($currcanclone eq $option) {
5150: $checked = ' checked="checked"';
5151: }
5152: if ($option eq 'instcode') {
5153: if (@code_order) {
5154: my $show = 'none';
5155: if ($checked) {
5156: $show = 'block';
5157: }
5158: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5159: &mt('Institutional codes for new and cloned course have identical:').
5160: '<br />';
5161: foreach my $item (@code_order) {
5162: my $codechk;
5163: if ($checked) {
5164: if (grep(/^\Q$item\E$/,@posscodes)) {
5165: $codechk = ' checked="checked"';
5166: }
5167: }
5168: $additional .= '<label>'.
5169: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5170: $item.'</label>';
5171: }
5172: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5173: }
5174: }
5175: $datatable .=
5176: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5177: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5178: '</label> '.$additional.'</span><br />';
5179: }
5180: $datatable .= '</td>'.
5181: '</tr>';
5182: $itemcount ++;
1.139 raeburn 5183: } else {
5184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 5185: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 5186: my $currusecredits = 0;
1.160.6.57 raeburn 5187: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 5188:2): my $ltiauth = 0;
1.160.6.30 raeburn 5189: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 5190: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 5191:2): if ($settings->{'ltiauth'}) {
5192:2): $ltiauth = 1;
5193:2): }
1.139 raeburn 5194: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 5195: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5196: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5197: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5198: }
5199: }
1.160.6.16 raeburn 5200: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 5201: foreach my $type (@types) {
5202: next if ($type eq 'community');
5203: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5204: if ($defcredits{$type} ne '') {
5205: $currusecredits = 1;
5206: }
5207: }
5208: }
5209: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5210: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5211: $postsubmitclient = 0;
5212: foreach my $type (@types) {
5213: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5214: }
5215: } else {
5216: foreach my $type (@types) {
5217: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5218: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5219: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5220: } else {
5221: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5222: }
5223: } else {
5224: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5225: }
5226: }
5227: }
5228: } else {
5229: foreach my $type (@types) {
5230: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 5231: }
5232: }
1.160.6.70 raeburn 5233: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5234: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5235: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5236: }
5237: } else {
5238: foreach my $type (@types) {
5239: $currmysql{$type} = $staticdefaults{'mysqltables'};
5240: }
5241: }
1.160.6.58 raeburn 5242: } else {
5243: foreach my $type (@types) {
5244: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5245: }
1.139 raeburn 5246: }
5247: if (!$currdefresponder) {
1.160.6.21 raeburn 5248: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5249: } elsif ($currdefresponder < 1) {
5250: $currdefresponder = 1;
5251: }
1.160.6.21 raeburn 5252: foreach my $type (@types) {
5253: if ($curruploadquota{$type} eq '') {
5254: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5255: }
5256: }
1.139 raeburn 5257: $datatable .=
1.160.6.16 raeburn 5258: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5259: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5260: '</span></td>'.
5261: '<td class="LC_right_item"><span class="LC_nobreak">'.
5262: '<input type="text" name="anonsurvey_threshold"'.
5263: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 5264: '</td></tr>'."\n";
5265: $itemcount ++;
5266: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5267: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5268: $choices{'uploadquota'}.
5269: '</span></td>'.
5270: '<td align="right" class="LC_right_item">'.
5271: '<table><tr>';
1.160.6.21 raeburn 5272: foreach my $type (@types) {
5273: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5274: '<input type="text" name="uploadquota_'.$type.'"'.
5275: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5276: }
5277: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 5278: $itemcount ++;
1.160.6.40 raeburn 5279: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 5280: my $display = 'none';
5281: if ($currusecredits) {
5282: $display = 'block';
5283: }
5284: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 5285: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5286: foreach my $type (@types) {
5287: next if ($type eq 'community');
5288: $additional .= '<td align="center">'.&mt($type).'<br />'.
5289: '<input type="text" name="'.$type.'_credits"'.
5290: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5291: }
5292: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 5293: %defaultchecked = ('coursecredits' => 'off');
5294: @toggles = ('coursecredits');
5295: my $current = {
5296: 'coursecredits' => $currusecredits,
5297: };
5298: (my $table,$itemcount) =
5299: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5300: \%choices,$itemcount,$onclick,$additional,'left');
5301: $datatable .= $table;
5302: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5303: my $display = 'none';
5304: if ($postsubmitclient) {
5305: $display = 'block';
5306: }
5307: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 5308: &mt('Number of seconds submit is disabled').'<br />'.
5309: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5310: '<table><tr>';
1.160.6.57 raeburn 5311: foreach my $type (@types) {
5312: $additional .= '<td align="center">'.&mt($type).'<br />'.
5313: '<input type="text" name="'.$type.'_timeout" value="'.
5314: $deftimeout{$type}.'" size="5" /></td>';
5315: }
5316: $additional .= '</tr></table></div>'."\n";
5317: %defaultchecked = ('postsubmit' => 'on');
5318: @toggles = ('postsubmit');
1.160.6.70 raeburn 5319: $current = {
5320: 'postsubmit' => $postsubmitclient,
5321: };
1.160.6.57 raeburn 5322: ($table,$itemcount) =
5323: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5324: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 5325: $datatable .= $table;
1.160.6.70 raeburn 5326: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5327: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5328: $choices{'mysqltables'}.
5329: '</span></td>'.
5330: '<td align="right" class="LC_right_item">'.
5331: '<table><tr>';
5332: foreach my $type (@types) {
5333: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5334: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 5335: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 5336: }
5337: $datatable .= '</tr></table></td></tr>'."\n";
5338: $itemcount ++;
1.160.6.118.2 4(raebur 5339:2): %defaultchecked = ('ltiauth' => 'off');
5340:2): @toggles = ('ltiauth');
5341:2): $current = {
5342:2): 'ltiauth' => $ltiauth,
5343:2): };
5344:2): ($table,$itemcount) =
5345:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5346:2): \%choices,$itemcount,undef,undef,'left');
5347:2): $datatable .= $table;
5348:2): $itemcount ++;
1.160.6.37 raeburn 5349: }
5350: $$rowtotal += $itemcount;
5351: return $datatable;
5352: }
5353:
5354: sub print_selfenrollment {
5355: my ($position,$dom,$settings,$rowtotal) = @_;
5356: my ($css_class,$datatable);
5357: my $itemcount = 1;
5358: my @types = ('official','unofficial','community','textbook');
5359: if (($position eq 'top') || ($position eq 'middle')) {
5360: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5361: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5362: my @rows;
5363: my $key;
5364: if ($position eq 'top') {
5365: $key = 'admin';
5366: if (ref($rowsref) eq 'ARRAY') {
5367: @rows = @{$rowsref};
5368: }
5369: } elsif ($position eq 'middle') {
5370: $key = 'default';
5371: @rows = ('types','registered','approval','limit');
5372: }
5373: foreach my $row (@rows) {
5374: if (defined($titlesref->{$row})) {
5375: $itemcount ++;
5376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5377: $datatable .= '<tr'.$css_class.'>'.
5378: '<td>'.$titlesref->{$row}.'</td>'.
5379: '<td class="LC_left_item">'.
5380: '<table><tr>';
5381: my (%current,%currentcap);
5382: if (ref($settings) eq 'HASH') {
5383: if (ref($settings->{$key}) eq 'HASH') {
5384: foreach my $type (@types) {
5385: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5386: $current{$type} = $settings->{$key}->{$type}->{$row};
5387: }
5388: if (($row eq 'limit') && ($key eq 'default')) {
5389: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5390: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5391: }
5392: }
5393: }
5394: }
5395: }
5396: my %roles = (
5397: '0' => &Apache::lonnet::plaintext('dc'),
5398: );
5399:
5400: foreach my $type (@types) {
5401: unless (($row eq 'registered') && ($key eq 'default')) {
5402: $datatable .= '<th>'.&mt($type).'</th>';
5403: }
5404: }
5405: unless (($row eq 'registered') && ($key eq 'default')) {
5406: $datatable .= '</tr><tr>';
5407: }
5408: foreach my $type (@types) {
5409: if ($type eq 'community') {
5410: $roles{'1'} = &mt('Community personnel');
5411: } else {
5412: $roles{'1'} = &mt('Course personnel');
5413: }
5414: $datatable .= '<td style="vertical-align: top">';
5415: if ($position eq 'top') {
5416: my %checked;
5417: if ($current{$type} eq '0') {
5418: $checked{'0'} = ' checked="checked"';
5419: } else {
5420: $checked{'1'} = ' checked="checked"';
5421: }
5422: foreach my $role ('1','0') {
5423: $datatable .= '<span class="LC_nobreak"><label>'.
5424: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5425: 'value="'.$role.'"'.$checked{$role}.' />'.
5426: $roles{$role}.'</label></span> ';
5427: }
5428: } else {
5429: if ($row eq 'types') {
5430: my %checked;
5431: if ($current{$type} =~ /^(all|dom)$/) {
5432: $checked{$1} = ' checked="checked"';
5433: } else {
5434: $checked{''} = ' checked="checked"';
5435: }
5436: foreach my $val ('','dom','all') {
5437: $datatable .= '<span class="LC_nobreak"><label>'.
5438: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5439: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5440: }
5441: } elsif ($row eq 'registered') {
5442: my %checked;
5443: if ($current{$type} eq '1') {
5444: $checked{'1'} = ' checked="checked"';
5445: } else {
5446: $checked{'0'} = ' checked="checked"';
5447: }
5448: foreach my $val ('0','1') {
5449: $datatable .= '<span class="LC_nobreak"><label>'.
5450: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5451: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5452: }
5453: } elsif ($row eq 'approval') {
5454: my %checked;
5455: if ($current{$type} =~ /^([12])$/) {
5456: $checked{$1} = ' checked="checked"';
5457: } else {
5458: $checked{'0'} = ' checked="checked"';
5459: }
5460: for my $val (0..2) {
5461: $datatable .= '<span class="LC_nobreak"><label>'.
5462: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5463: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5464: }
5465: } elsif ($row eq 'limit') {
5466: my %checked;
5467: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5468: $checked{$1} = ' checked="checked"';
5469: } else {
5470: $checked{'none'} = ' checked="checked"';
5471: }
5472: my $cap;
5473: if ($currentcap{$type} =~ /^\d+$/) {
5474: $cap = $currentcap{$type};
5475: }
5476: foreach my $val ('none','allstudents','selfenrolled') {
5477: $datatable .= '<span class="LC_nobreak"><label>'.
5478: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5479: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5480: }
5481: $datatable .= '<br />'.
5482: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5483: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5484: '</span>';
5485: }
5486: }
5487: $datatable .= '</td>';
5488: }
5489: $datatable .= '</tr>';
5490: }
5491: $datatable .= '</table></td></tr>';
5492: }
5493: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 5494: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5495: }
5496: $$rowtotal += $itemcount;
5497: return $datatable;
5498: }
5499:
5500: sub print_validation_rows {
5501: my ($caller,$dom,$settings,$rowtotal) = @_;
5502: my ($itemsref,$namesref,$fieldsref);
5503: if ($caller eq 'selfenroll') {
5504: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5505: } elsif ($caller eq 'requestcourses') {
5506: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5507: }
5508: my %currvalidation;
5509: if (ref($settings) eq 'HASH') {
5510: if (ref($settings->{'validation'}) eq 'HASH') {
5511: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 5512: }
1.160.6.39 raeburn 5513: }
5514: my $datatable;
5515: my $itemcount = 0;
5516: foreach my $item (@{$itemsref}) {
5517: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5518: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5519: $namesref->{$item}.
5520: '</span></td>'.
5521: '<td class="LC_left_item">';
5522: if (($item eq 'url') || ($item eq 'button')) {
5523: $datatable .= '<span class="LC_nobreak">'.
5524: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5525: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5526: } elsif ($item eq 'fields') {
5527: my @currfields;
5528: if (ref($currvalidation{$item}) eq 'ARRAY') {
5529: @currfields = @{$currvalidation{$item}};
5530: }
5531: foreach my $field (@{$fieldsref}) {
5532: my $check = '';
5533: if (grep(/^\Q$field\E$/,@currfields)) {
5534: $check = ' checked="checked"';
5535: }
5536: $datatable .= '<span class="LC_nobreak"><label>'.
5537: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5538: ' value="'.$field.'"'.$check.' />'.$field.
5539: '</label></span> ';
5540: }
5541: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 5542: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 5543: $currvalidation{$item}.
1.160.6.37 raeburn 5544: '</textarea>';
1.160.6.39 raeburn 5545: }
5546: $datatable .= '</td></tr>'."\n";
5547: if (ref($rowtotal)) {
1.160.6.37 raeburn 5548: $itemcount ++;
5549: }
1.139 raeburn 5550: }
1.160.6.39 raeburn 5551: if ($caller eq 'requestcourses') {
5552: my %currhash;
1.160.6.51 raeburn 5553: if (ref($settings) eq 'HASH') {
5554: if (ref($settings->{'validation'}) eq 'HASH') {
5555: if ($settings->{'validation'}{'dc'} ne '') {
5556: $currhash{$settings->{'validation'}{'dc'}} = 1;
5557: }
1.160.6.39 raeburn 5558: }
5559: }
5560: my $numinrow = 2;
5561: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5562: 'validationdc',%currhash);
1.160.6.50 raeburn 5563: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5564: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5565: if ($numdc > 1) {
1.160.6.50 raeburn 5566: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5567: } else {
1.160.6.50 raeburn 5568: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5569: }
1.160.6.50 raeburn 5570: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5571: $itemcount ++;
5572: }
5573: if (ref($rowtotal)) {
5574: $$rowtotal += $itemcount;
5575: }
1.121 raeburn 5576: return $datatable;
1.118 jms 5577: }
5578:
1.160.6.98 raeburn 5579: sub print_passwords {
5580: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5581: my ($datatable,$css_class);
5582: my $itemcount = 0;
5583: my %titles = &Apache::lonlocal::texthash (
5584: captcha => '"Forgot Password" CAPTCHA validation',
5585: link => 'Reset link expiration (hours)',
5586: case => 'Case-sensitive usernames/e-mail',
5587: prelink => 'Information required (form 1)',
5588: postlink => 'Information required (form 2)',
5589: emailsrc => 'LON-CAPA e-mail address type(s)',
5590: customtext => 'Domain specific text (HTML)',
5591: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5592: intauth_check => 'Check bcrypt cost if authenticated',
5593: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5594: permanent => 'Permanent e-mail address',
5595: critical => 'Critical notification address',
5596: notify => 'Notification address',
5597: min => 'Minimum password length',
5598: max => 'Maximum password length',
5599: chars => 'Required characters',
5600: numsaved => 'Number of previous passwords to save and disallow reuse',
5601: );
5602: if ($position eq 'top') {
5603: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5604: my $shownlinklife = 2;
5605: my $prelink = 'both';
5606: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5607: if (ref($settings) eq 'HASH') {
5608: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5609: $shownlinklife = $settings->{resetlink};
5610: }
5611: if (ref($settings->{resetcase}) eq 'ARRAY') {
5612: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5613: }
5614: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5615: $prelink = $settings->{resetprelink};
5616: }
5617: if (ref($settings->{resetpostlink}) eq 'HASH') {
5618: %postlink = %{$settings->{resetpostlink}};
5619: }
5620: if (ref($settings->{resetemail}) eq 'ARRAY') {
5621: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5622: }
5623: if ($settings->{resetremove}) {
5624: $nostdtext = 1;
5625: }
5626: if ($settings->{resetcustom}) {
5627: $customurl = $settings->{resetcustom};
5628: }
5629: } else {
5630: if (ref($types) eq 'ARRAY') {
5631: foreach my $item (@{$types}) {
5632: $casesens{$item} = 1;
5633: $postlink{$item} = ['username','email'];
5634: }
5635: }
5636: $casesens{'default'} = 1;
5637: $postlink{'default'} = ['username','email'];
5638: $prelink = 'both';
5639: %emailsrc = (
5640: permanent => 1,
5641: critical => 1,
5642: notify => 1,
5643: );
5644: }
5645: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5646: $itemcount ++;
5647: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5648: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5649: '<td class="LC_left_item">'.
5650: '<input type="textbox" value="'.$shownlinklife.'" '.
5651: 'name="passwords_link" size="3" /></td></tr>';
5652: $itemcount ++;
5653: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5654: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5655: '<td class="LC_left_item">';
5656: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5657: foreach my $item (@{$types}) {
5658: my $checkedcase;
5659: if ($casesens{$item}) {
5660: $checkedcase = ' checked="checked"';
5661: }
5662: $datatable .= '<span class="LC_nobreak"><label>'.
5663: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5664: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5665: '</span> ';
1.160.6.98 raeburn 5666: }
5667: }
5668: my $checkedcase;
5669: if ($casesens{'default'}) {
5670: $checkedcase = ' checked="checked"';
5671: }
5672: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5673: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5674: $othertitle.'</label></span></td>';
5675: $itemcount ++;
5676: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5677: my %checkedpre = (
5678: both => ' checked="checked"',
5679: either => '',
5680: );
5681: if ($prelink eq 'either') {
5682: $checkedpre{either} = ' checked="checked"';
5683: $checkedpre{both} = '';
5684: }
5685: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5686: '<td class="LC_left_item"><span class="LC_nobreak">'.
5687: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5688: &mt('Both username and e-mail address').'</label></span> '.
5689: '<span class="LC_nobreak"><label>'.
5690: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5691: &mt('Either username or e-mail address').'</label></span></td></tr>';
5692: $itemcount ++;
5693: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5694: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5695: '<td class="LC_left_item">';
5696: my %postlinked;
5697: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5698: foreach my $item (@{$types}) {
5699: undef(%postlinked);
5700: $datatable .= '<fieldset style="display: inline-block;">'.
5701: '<legend>'.$usertypes->{$item}.'</legend>';
5702: if (ref($postlink{$item}) eq 'ARRAY') {
5703: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5704: }
5705: foreach my $field ('email','username') {
5706: my $checked;
5707: if ($postlinked{$field}) {
5708: $checked = ' checked="checked"';
5709: }
5710: $datatable .= '<span class="LC_nobreak"><label>'.
5711: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5712: $field.'"'.$checked.' />'.$field.'</label>'.
5713: '<span> ';
5714: }
5715: $datatable .= '</fieldset>';
5716: }
5717: }
5718: if (ref($postlink{'default'}) eq 'ARRAY') {
5719: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5720: }
5721: $datatable .= '<fieldset style="display: inline-block;">'.
5722: '<legend>'.$othertitle.'</legend>';
5723: foreach my $field ('email','username') {
5724: my $checked;
5725: if ($postlinked{$field}) {
5726: $checked = ' checked="checked"';
5727: }
5728: $datatable .= '<span class="LC_nobreak"><label>'.
5729: '<input type="checkbox" name="passwords_postlink_default" value="'.
5730: $field.'"'.$checked.' />'.$field.'</label>'.
5731: '<span> ';
5732: }
5733: $datatable .= '</fieldset></td></tr>';
5734: $itemcount ++;
5735: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5736: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5737: '<td class="LC_left_item">';
5738: foreach my $type ('permanent','critical','notify') {
5739: my $checkedemail;
5740: if ($emailsrc{$type}) {
5741: $checkedemail = ' checked="checked"';
5742: }
5743: $datatable .= '<span class="LC_nobreak"><label>'.
5744: '<input type="checkbox" name="passwords_emailsrc" value="'.
5745: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5746: '<span> ';
5747: }
5748: $datatable .= '</td></tr>';
5749: $itemcount ++;
5750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5751: my $switchserver = &check_switchserver($dom,$confname);
5752: my ($showstd,$noshowstd);
5753: if ($nostdtext) {
5754: $noshowstd = ' checked="checked"';
5755: } else {
5756: $showstd = ' checked="checked"';
5757: }
5758: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5759: '<td class="LC_left_item"><span class="LC_nobreak">'.
5760: &mt('Retain standard text:').
5761: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5762: &mt('Yes').'</label>'.' '.
5763: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5764: &mt('No').'</label></span><br />'.
5765: '<span class="LC_fontsize_small">'.
5766: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5767: &mt('Include custom text:');
5768: if ($customurl) {
1.160.6.104 raeburn 5769: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5770: undef,undef,undef,undef,'background-color:#ffffff');
5771: $datatable .= '<span class="LC_nobreak"> '.$link.
5772: '<label><input type="checkbox" name="passwords_custom_del"'.
5773: ' value="1" />'.&mt('Delete?').'</label></span>'.
5774: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5775: }
5776: if ($switchserver) {
5777: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5778: } else {
5779: $datatable .='<span class="LC_nobreak"> '.
5780: '<input type="file" name="passwords_customfile" /></span>';
5781: }
5782: $datatable .= '</td></tr>';
5783: } elsif ($position eq 'middle') {
5784: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5785: my @items = ('intauth_cost','intauth_check','intauth_switch');
5786: my %defaults;
5787: if (ref($domconf{'defaults'}) eq 'HASH') {
5788: %defaults = %{$domconf{'defaults'}};
5789: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5790: $defaults{'intauth_cost'} = 10;
5791: }
5792: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5793: $defaults{'intauth_check'} = 0;
5794: }
5795: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5796: $defaults{'intauth_switch'} = 0;
5797: }
5798: } else {
5799: %defaults = (
5800: 'intauth_cost' => 10,
5801: 'intauth_check' => 0,
5802: 'intauth_switch' => 0,
5803: );
5804: }
5805: foreach my $item (@items) {
5806: if ($itemcount%2) {
5807: $css_class = '';
5808: } else {
5809: $css_class = ' class="LC_odd_row" ';
5810: }
5811: $datatable .= '<tr'.$css_class.'>'.
5812: '<td><span class="LC_nobreak">'.$titles{$item}.
5813: '</span></td><td class="LC_left_item" colspan="3">';
5814: if ($item eq 'intauth_switch') {
5815: my @options = (0,1,2);
5816: my %optiondesc = &Apache::lonlocal::texthash (
5817: 0 => 'No',
5818: 1 => 'Yes',
5819: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5820: );
5821: $datatable .= '<table width="100%">';
5822: foreach my $option (@options) {
5823: my $checked = ' ';
5824: if ($defaults{$item} eq $option) {
5825: $checked = ' checked="checked"';
5826: }
5827: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5828: '<label><input type="radio" name="'.$item.
5829: '" value="'.$option.'"'.$checked.' />'.
5830: $optiondesc{$option}.'</label></span></td></tr>';
5831: }
5832: $datatable .= '</table>';
5833: } elsif ($item eq 'intauth_check') {
5834: my @options = (0,1,2);
5835: my %optiondesc = &Apache::lonlocal::texthash (
5836: 0 => 'No',
5837: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5838: 2 => 'Yes, disallow login if stored cost is less than domain default',
5839: );
5840: $datatable .= '<table width="100%">';
5841: foreach my $option (@options) {
5842: my $checked = ' ';
5843: my $onclick;
5844: if ($defaults{$item} eq $option) {
5845: $checked = ' checked="checked"';
5846: }
5847: if ($option == 2) {
5848: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5849: }
5850: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5851: '<label><input type="radio" name="'.$item.
5852: '" value="'.$option.'"'.$checked.$onclick.' />'.
5853: $optiondesc{$option}.'</label></span></td></tr>';
5854: }
5855: $datatable .= '</table>';
5856: } else {
5857: $datatable .= '<input type="text" name="'.$item.'" value="'.
5858: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5859: }
5860: $datatable .= '</td></tr>';
5861: $itemcount ++;
5862: }
5863: } elsif ($position eq 'lower') {
5864: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5865: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5866: if (ref($settings) eq 'HASH') {
5867: if ($settings->{min}) {
5868: $min = $settings->{min};
5869: }
5870: if ($settings->{max}) {
5871: $max = $settings->{max};
5872: }
5873: if (ref($settings->{chars}) eq 'ARRAY') {
5874: map { $chars{$_} = 1; } (@{$settings->{chars}});
5875: }
5876: if ($settings->{numsaved}) {
5877: $numsaved = $settings->{numsaved};
5878: }
5879: }
5880: my %rulenames = &Apache::lonlocal::texthash(
5881: uc => 'At least one upper case letter',
5882: lc => 'At least one lower case letter',
5883: num => 'At least one number',
5884: spec => 'At least one non-alphanumeric',
5885: );
5886: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5887: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5888: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5889: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5890: 'onblur="javascript:warnIntPass(this);" />'.
5891: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5892: '</span></td></tr>';
5893: $itemcount ++;
5894: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5895: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5896: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5897: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5898: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5899: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5900: '</span></td></tr>';
5901: $itemcount ++;
5902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5903: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5904: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5905: '</span></td>';
5906: my $numinrow = 2;
5907: my @possrules = ('uc','lc','num','spec');
5908: $datatable .= '<td class="LC_left_item"><table>';
5909: for (my $i=0; $i<@possrules; $i++) {
5910: my ($rem,$checked);
5911: if ($chars{$possrules[$i]}) {
5912: $checked = ' checked="checked"';
5913: }
5914: $rem = $i%($numinrow);
5915: if ($rem == 0) {
5916: if ($i > 0) {
5917: $datatable .= '</tr>';
5918: }
5919: $datatable .= '<tr>';
5920: }
5921: $datatable .= '<td><span class="LC_nobreak"><label>'.
5922: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5923: $rulenames{$possrules[$i]}.'</label></span></td>';
5924: }
5925: my $rem = @possrules%($numinrow);
5926: my $colsleft = $numinrow - $rem;
5927: if ($colsleft > 1 ) {
5928: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5929: ' </td>';
5930: } elsif ($colsleft == 1) {
5931: $datatable .= '<td class="LC_left_item"> </td>';
5932: }
5933: $datatable .='</table></td></tr>';
5934: $itemcount ++;
5935: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5936: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5937: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5938: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5939: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5940: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5941: '</span></td></tr>';
5942: } else {
5943: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5944: my %ownerchg = (
5945: by => {},
5946: for => {},
5947: );
5948: my %ownertitles = &Apache::lonlocal::texthash (
5949: by => 'Course owner status(es) allowed',
5950: for => 'Student status(es) allowed',
5951: );
5952: if (ref($settings) eq 'HASH') {
5953: if (ref($settings->{crsownerchg}) eq 'HASH') {
5954: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5955: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5956: }
5957: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5958: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5959: }
5960: }
5961: }
5962: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5963: $datatable .= '<tr '.$css_class.'>'.
5964: '<td>'.
5965: &mt('Requirements').'<ul>'.
5966: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5967: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5968: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5969: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5970: '</ul>'.
5971: '</td>'.
5972: '<td class="LC_left_item">';
5973: foreach my $item ('by','for') {
5974: $datatable .= '<fieldset style="display: inline-block;">'.
5975: '<legend>'.$ownertitles{$item}.'</legend>';
5976: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5977: foreach my $type (@{$types}) {
5978: my $checked;
5979: if ($ownerchg{$item}{$type}) {
5980: $checked = ' checked="checked"';
5981: }
5982: $datatable .= '<span class="LC_nobreak"><label>'.
5983: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5984: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5985: '</span> ';
1.160.6.98 raeburn 5986: }
5987: }
5988: my $checked;
5989: if ($ownerchg{$item}{'default'}) {
5990: $checked = ' checked="checked"';
5991: }
5992: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5993: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5994: $othertitle.'</label></span></fieldset>';
5995: }
5996: $datatable .= '</td></tr>';
5997: }
5998: return $datatable;
5999: }
6000:
1.160.6.113 raeburn 6001: sub print_wafproxy {
6002: my ($position,$dom,$settings,$rowtotal) = @_;
6003: my $css_class;
6004: my $itemcount = 0;
6005: my $datatable;
6006: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6007: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6008: my %lt = &wafproxy_titles();
6009: foreach my $server (sort(keys(%servers))) {
6010: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6011: next if ($serverhome eq '');
6012: my $serverdom;
6013: if ($serverhome ne $server) {
6014: $serverdom = &Apache::lonnet::host_domain($serverhome);
6015: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6016: $othercontrol{$server} = $serverdom;
6017: }
6018: } else {
6019: $serverdom = &Apache::lonnet::host_domain($server);
6020: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6021: if ($serverdom ne $dom) {
6022: $othercontrol{$server} = $serverdom;
6023: } else {
6024: $setdom = 1;
6025: if (ref($settings) eq 'HASH') {
6026: if (ref($settings->{'alias'}) eq 'HASH') {
6027: $aliases{$dom} = $settings->{'alias'};
6028: if ($aliases{$dom} ne '') {
6029: $showdom = 1;
6030: }
6031: }
6032: if (ref($settings->{'saml'}) eq 'HASH') {
6033: $saml{$dom} = $settings->{'saml'};
6034: }
6035: }
6036: }
6037: }
6038: }
6039: if ($setdom) {
6040: %{$values{$dom}} = ();
6041: if (ref($settings) eq 'HASH') {
6042: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6043: $values{$dom}{$item} = $settings->{$item};
6044: }
6045: }
6046: }
6047: if (keys(%othercontrol)) {
6048: %otherdoms = reverse(%othercontrol);
6049: foreach my $domain (keys(%otherdoms)) {
6050: %{$values{$domain}} = ();
6051: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6052: if (ref($config{'wafproxy'}) eq 'HASH') {
6053: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6054: if (exists($config{'wafproxy'}{'saml'})) {
6055: $saml{$domain} = $config{'wafproxy'}{'saml'};
6056: }
6057: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6058: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6059: }
6060: }
6061: }
6062: }
6063: if ($position eq 'top') {
6064: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6065: my %aliasinfo;
6066: foreach my $server (sort(keys(%servers))) {
6067: $itemcount ++;
6068: my $dom_in_effect;
6069: my $aliasrows = '<tr>'.
6070: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6071: &mt('Hostname').': '.
6072: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6073: if ($othercontrol{$server}) {
6074: $dom_in_effect = $othercontrol{$server};
6075: my ($current,$forsaml);
6076: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6077: $current = $aliases{$dom_in_effect}{$server};
6078: }
6079: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6080: if ($saml{$dom_in_effect}{$server}) {
6081: $forsaml = 1;
6082: }
6083: }
6084: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6085: &mt('Alias').': ';
6086: if ($current) {
6087: $aliasrows .= $current;
6088: if ($forsaml) {
6089: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6090: }
6091: } else {
6092: $aliasrows .= &mt('None');
6093: }
6094: $aliasrows .= ' <span class="LC_small">('.
6095: &mt('controlled by domain: [_1]',
6096: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6097: } else {
6098: $dom_in_effect = $dom;
6099: my ($current,$samlon,$samloff);
6100: $samloff = ' checked="checked"';
6101: if (ref($aliases{$dom}) eq 'HASH') {
6102: if ($aliases{$dom}{$server}) {
6103: $current = $aliases{$dom}{$server};
6104: }
6105: }
6106: if (ref($saml{$dom}) eq 'HASH') {
6107: if ($saml{$dom}{$server}) {
6108: $samlon = $samloff;
6109: undef($samloff);
6110: }
6111: }
6112: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6113: &mt('Alias').': '.
6114: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6115: 'value="'.$current.'" size="30" />'.
6116: (' 'x2).'<span class="LC_nobreak">'.
6117: &mt('Alias used for SSO Auth').': <label>'.
6118: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6119: &mt('No').'</label> <label>'.
6120: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6121: &mt('Yes').'</label></span>'.
6122: '</td>';
6123: }
6124: $aliasrows .= '</tr>';
6125: $aliasinfo{$dom_in_effect} .= $aliasrows;
6126: }
6127: if ($aliasinfo{$dom}) {
6128: my ($onclick,$wafon,$wafoff,$showtable);
6129: $onclick = ' onclick="javascript:toggleWAF();"';
6130: $wafoff = ' checked="checked"';
6131: $showtable = ' style="display:none";';
6132: if ($showdom) {
6133: $wafon = $wafoff;
6134: $wafoff = '';
6135: $showtable = ' style="display:inline;"';
6136: }
6137: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6138: $datatable = '<tr'.$css_class.'>'.
6139: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6140: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6141: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6142: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6143: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6144: &mt('No').'</label></span></td>'.
6145: '<td class="LC_left_item">'.
6146: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6147: '</table></td></tr>';
6148: $itemcount++;
6149: }
6150: if (keys(%otherdoms)) {
6151: foreach my $key (sort(keys(%otherdoms))) {
6152: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6153: $datatable .= '<tr'.$css_class.'>'.
6154: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6155: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6156: '</table></td></tr>';
6157: $itemcount++;
6158: }
6159: }
6160: } else {
6161: my %ip_methods = &remoteip_methods();
6162: if ($setdom) {
6163: $itemcount ++;
6164: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6165: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6166: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6167: $wafstyle = ' style="display:none;"';
6168: $nowafstyle = ' style="display:table-row;"';
6169: $currwafdisplay = ' style="display: none"';
6170: $wafrangestyle = ' style="display: none"';
6171: $curr_remotip = 'n';
6172: $ssltossl = ' checked="checked"';
6173: if ($showdom) {
6174: $wafstyle = ' style="display:table-row;"';
6175: $nowafstyle = ' style="display:none;"';
6176: if (keys(%{$values{$dom}})) {
6177: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6178: $curr_remotip = $values{$dom}{remoteip};
6179: }
6180: if ($curr_remotip eq 'h') {
6181: $currwafdisplay = ' style="display:table-row"';
6182: $wafrangestyle = ' style="display:inline-block;"';
6183: }
6184: if ($values{$dom}{'sslopt'}) {
6185: $alltossl = ' checked="checked"';
6186: $ssltossl = '';
6187: }
6188: }
6189: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6190: $vpndircheck = ' checked="checked"';
6191: $currwafvpn = ' style="display:table-row;"';
6192: $wafrangestyle = ' style="display:inline-block;"';
6193: } else {
6194: $vpnaliascheck = ' checked="checked"';
6195: $currwafvpn = ' style="display:none;"';
6196: }
6197: }
6198: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6199: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6200: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6201: '</tr>'.
6202: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6203: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6204: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6205: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6206: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6207: '<td class="LC_left_item"><table>'.
6208: '<tr>'.
6209: '<td valign="top">'.$lt{'remoteip'}.': '.
6210: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6211: foreach my $option ('m','h','n') {
6212: my $sel;
1.160.6.114 raeburn 6213: if ($option eq $curr_remotip) {
6214: $sel = ' selected="selected"';
6215: }
6216: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6217: $ip_methods{$option}.'</option>';
6218: }
6219: $datatable .= '</select></td></tr>'."\n".
6220: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6221: $lt{'ipheader'}.': '.
6222: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6223: 'name="wafproxy_ipheader" />'.
6224: '</td></tr>'."\n".
6225: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6226: $lt{'trusted'}.':<br />'.
6227: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6228: $values{$dom}{'trusted'}.'</textarea>'.
6229: '</td></tr>'."\n".
6230: '<tr><td><hr /></td></tr>'."\n".
6231: '<tr>'.
1.160.6.113 raeburn 6232: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6233: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6234: $lt{'vpndirect'}.'</label>'.(' 'x2).
6235: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6236: $lt{'vpnaliased'}.'</label></span></td></tr>';
6237: foreach my $item ('vpnint','vpnext') {
6238: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6239: '<td valign="top">'.$lt{$item}.':<br />'.
6240: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6241: $values{$dom}{$item}.'</textarea>'.
6242: '</td></tr>'."\n";
6243: }
6244: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6245: '<tr>'.
6246: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6247: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6248: $lt{'alltossl'}.'</label>'.(' 'x2).
6249: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6250: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6251: '</table></td></tr>';
6252: }
6253: if (keys(%otherdoms)) {
6254: foreach my $domain (sort(keys(%otherdoms))) {
6255: $itemcount ++;
6256: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6257: $datatable .= '<tr'.$css_class.'>'.
6258: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6259: '<td class="LC_left_item"><table>';
6260: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6261: my $showval = &mt('None');
6262: if ($item eq 'ssl') {
6263: $showval = $lt{'ssltossl'};
6264: }
6265: if ($values{$domain}{$item}) {
6266: $showval = $values{$domain}{$item};
6267: if ($item eq 'ssl') {
6268: $showval = $lt{'alltossl'};
6269: } elsif ($item eq 'remoteip') {
6270: $showval = $ip_methods{$values{$domain}{$item}};
6271: }
6272: }
6273: $datatable .= '<tr>'.
6274: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6275: }
6276: $datatable .= '</table></td></tr>';
6277: }
6278: }
6279: }
6280: $$rowtotal += $itemcount;
6281: return $datatable;
6282: }
6283:
6284: sub wafproxy_titles {
6285: return &Apache::lonlocal::texthash(
6286: remoteip => "Method for determining user's IP",
6287: ipheader => 'Request header containing remote IP',
6288: trusted => 'Trusted IP range(s)',
6289: vpnaccess => 'Access from institutional VPN',
6290: vpndirect => 'via regular hostname (no WAF)',
6291: vpnaliased => 'via aliased hostname (WAF)',
6292: vpnint => 'Internal IP Range(s) for VPN sessions',
6293: vpnext => 'IP Range(s) for backend WAF connections',
6294: sslopt => 'Forwarding http/https',
6295: alltossl => 'WAF forwards both http and https requests to https',
6296: ssltossl => 'WAF forwards http requests to http and https to https',
6297: );
6298: }
6299:
6300: sub remoteip_methods {
6301: return &Apache::lonlocal::texthash(
6302: m => 'Use Apache mod_remoteip',
6303: h => 'Use headers parsed by LON-CAPA',
6304: n => 'Not in use',
6305: );
6306: }
6307:
1.137 raeburn 6308: sub print_usersessions {
6309: my ($position,$dom,$settings,$rowtotal) = @_;
6310: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 6311: my (%by_ip,%by_location,@intdoms);
6312: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 6313:
6314: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6315: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6316: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6317: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6318: my $itemcount = 1;
6319: if ($position eq 'top') {
1.152 raeburn 6320: if (keys(%serverhomes) > 1) {
1.145 raeburn 6321: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 6322: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 6323: if (ref($settings) eq 'HASH') {
6324: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6325: $curroffloadnow = $settings->{'offloadnow'};
6326: }
1.160.6.105 raeburn 6327: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6328: $curroffloadoth = $settings->{'offloadoth'};
6329: }
1.160.6.61 raeburn 6330: }
1.160.6.105 raeburn 6331: my $other_insts = scalar(keys(%by_location));
6332: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6333: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 6334: } else {
1.140 raeburn 6335: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6336: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 6337: }
1.137 raeburn 6338: } else {
1.145 raeburn 6339: if (keys(%by_location) == 0) {
6340: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6341: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 6342: } else {
6343: my %lt = &usersession_titles();
6344: my $numinrow = 5;
6345: my $prefix;
6346: my @types;
6347: if ($position eq 'bottom') {
6348: $prefix = 'remote';
6349: @types = ('version','excludedomain','includedomain');
6350: } else {
6351: $prefix = 'hosted';
6352: @types = ('excludedomain','includedomain');
6353: }
6354: my (%current,%checkedon,%checkedoff);
6355: my @lcversions = &Apache::lonnet::all_loncaparevs();
6356: my @locations = sort(keys(%by_location));
6357: foreach my $type (@types) {
6358: $checkedon{$type} = '';
6359: $checkedoff{$type} = ' checked="checked"';
6360: }
6361: if (ref($settings) eq 'HASH') {
6362: if (ref($settings->{$prefix}) eq 'HASH') {
6363: foreach my $key (keys(%{$settings->{$prefix}})) {
6364: $current{$key} = $settings->{$prefix}{$key};
6365: if ($key eq 'version') {
6366: if ($current{$key} ne '') {
6367: $checkedon{$key} = ' checked="checked"';
6368: $checkedoff{$key} = '';
6369: }
6370: } elsif (ref($current{$key}) eq 'ARRAY') {
6371: $checkedon{$key} = ' checked="checked"';
6372: $checkedoff{$key} = '';
6373: }
1.137 raeburn 6374: }
6375: }
6376: }
1.145 raeburn 6377: foreach my $type (@types) {
6378: next if ($type ne 'version' && !@locations);
6379: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6380: $datatable .= '<tr'.$css_class.'>
6381: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6382: <span class="LC_nobreak">
6383: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6384: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6385: if ($type eq 'version') {
6386: my $selector = '<select name="'.$prefix.'_version">';
6387: foreach my $version (@lcversions) {
6388: my $selected = '';
6389: if ($current{'version'} eq $version) {
6390: $selected = ' selected="selected"';
6391: }
6392: $selector .= ' <option value="'.$version.'"'.
6393: $selected.'>'.$version.'</option>';
6394: }
6395: $selector .= '</select> ';
6396: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6397: } else {
6398: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6399: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6400: ' />'.(' 'x2).
6401: '<input type="button" value="'.&mt('uncheck all').'" '.
6402: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6403: "\n".
6404: '</div><div><table>';
6405: my $rem;
6406: for (my $i=0; $i<@locations; $i++) {
6407: my ($showloc,$value,$checkedtype);
6408: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6409: my $ip = $by_location{$locations[$i]}->[0];
6410: if (ref($by_ip{$ip}) eq 'ARRAY') {
6411: $value = join(':',@{$by_ip{$ip}});
6412: $showloc = join(', ',@{$by_ip{$ip}});
6413: if (ref($current{$type}) eq 'ARRAY') {
6414: foreach my $loc (@{$by_ip{$ip}}) {
6415: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6416: $checkedtype = ' checked="checked"';
6417: last;
6418: }
6419: }
1.138 raeburn 6420: }
6421: }
6422: }
1.145 raeburn 6423: $rem = $i%($numinrow);
6424: if ($rem == 0) {
6425: if ($i > 0) {
6426: $datatable .= '</tr>';
6427: }
6428: $datatable .= '<tr>';
6429: }
6430: $datatable .= '<td class="LC_left_item">'.
6431: '<span class="LC_nobreak"><label>'.
6432: '<input type="checkbox" name="'.$prefix.'_'.$type.
6433: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6434: '</label></span></td>';
1.137 raeburn 6435: }
1.145 raeburn 6436: $rem = @locations%($numinrow);
6437: my $colsleft = $numinrow - $rem;
6438: if ($colsleft > 1 ) {
6439: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6440: ' </td>';
6441: } elsif ($colsleft == 1) {
6442: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6443: }
1.145 raeburn 6444: $datatable .= '</tr></table>';
1.137 raeburn 6445: }
1.145 raeburn 6446: $datatable .= '</td></tr>';
6447: $itemcount ++;
1.137 raeburn 6448: }
6449: }
6450: }
6451: $$rowtotal += $itemcount;
6452: return $datatable;
6453: }
6454:
1.138 raeburn 6455: sub build_location_hashes {
6456: my ($intdoms,$by_ip,$by_location) = @_;
6457: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6458: (ref($by_location) eq 'HASH'));
6459: my %iphost = &Apache::lonnet::get_iphost();
6460: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6461: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6462: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6463: foreach my $id (@{$iphost{$primary_ip}}) {
6464: my $intdom = &Apache::lonnet::internet_dom($id);
6465: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6466: push(@{$intdoms},$intdom);
6467: }
6468: }
6469: }
6470: foreach my $ip (keys(%iphost)) {
6471: if (ref($iphost{$ip}) eq 'ARRAY') {
6472: foreach my $id (@{$iphost{$ip}}) {
6473: my $location = &Apache::lonnet::internet_dom($id);
6474: if ($location) {
6475: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6476: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6477: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6478: push(@{$by_ip->{$ip}},$location);
6479: }
6480: } else {
6481: $by_ip->{$ip} = [$location];
6482: }
6483: }
6484: }
6485: }
6486: }
6487: foreach my $ip (sort(keys(%{$by_ip}))) {
6488: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6489: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6490: my $first = $by_ip->{$ip}->[0];
6491: if (ref($by_location->{$first}) eq 'ARRAY') {
6492: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6493: push(@{$by_location->{$first}},$ip);
6494: }
6495: } else {
6496: $by_location->{$first} = [$ip];
6497: }
6498: }
6499: }
6500: return;
6501: }
6502:
1.145 raeburn 6503: sub current_offloads_to {
6504: my ($dom,$settings,$servers) = @_;
6505: my (%spareid,%otherdomconfigs);
1.152 raeburn 6506: if (ref($servers) eq 'HASH') {
1.145 raeburn 6507: foreach my $lonhost (sort(keys(%{$servers}))) {
6508: my $gotspares;
1.152 raeburn 6509: if (ref($settings) eq 'HASH') {
6510: if (ref($settings->{'spares'}) eq 'HASH') {
6511: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6512: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6513: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6514: $gotspares = 1;
6515: }
1.145 raeburn 6516: }
6517: }
6518: unless ($gotspares) {
6519: my $gotspares;
6520: my $serverhomeID =
6521: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6522: my $serverhomedom =
6523: &Apache::lonnet::host_domain($serverhomeID);
6524: if ($serverhomedom ne $dom) {
6525: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6526: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6527: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6528: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6529: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6530: $gotspares = 1;
6531: }
6532: }
6533: } else {
6534: $otherdomconfigs{$serverhomedom} =
6535: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6536: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6537: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6538: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6539: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6540: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6541: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6542: $gotspares = 1;
6543: }
6544: }
6545: }
6546: }
6547: }
6548: }
6549: }
6550: unless ($gotspares) {
6551: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6552: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6553: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6554: } else {
6555: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6556: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6557: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6558: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6559: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6560: } else {
1.150 raeburn 6561: my %what = (
6562: spareid => 1,
6563: );
6564: my ($result,$returnhash) =
6565: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6566: if ($result eq 'ok') {
6567: if (ref($returnhash) eq 'HASH') {
6568: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6569: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6570: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6571: }
6572: }
1.145 raeburn 6573: }
6574: }
6575: }
6576: }
6577: }
6578: }
6579: return %spareid;
6580: }
6581:
6582: sub spares_row {
1.160.6.105 raeburn 6583: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6584: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6585: my $css_class;
6586: my $numinrow = 4;
6587: my $itemcount = 1;
6588: my $datatable;
1.152 raeburn 6589: my %typetitles = &sparestype_titles();
6590: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6591: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6592: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6593: my ($othercontrol,$serverdom);
6594: if ($serverhome ne $server) {
6595: $serverdom = &Apache::lonnet::host_domain($serverhome);
6596: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6597: } else {
6598: $serverdom = &Apache::lonnet::host_domain($server);
6599: if ($serverdom ne $dom) {
6600: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6601: }
6602: }
6603: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6604: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6605: if (ref($curroffloadnow) eq 'HASH') {
6606: if ($curroffloadnow->{$server}) {
6607: $checkednow = ' checked="checked"';
6608: }
6609: }
1.160.6.105 raeburn 6610: if (ref($curroffloadoth) eq 'HASH') {
6611: if ($curroffloadoth->{$server}) {
6612: $checkedoth = ' checked="checked"';
6613: }
6614: }
1.145 raeburn 6615: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6616: $datatable .= '<tr'.$css_class.'>
6617: <td rowspan="2">
1.160.6.13 raeburn 6618: <span class="LC_nobreak">'.
6619: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6620: ,'<b>'.$server.'</b>').'</span><br />'.
6621: '<span class="LC_nobreak">'."\n".
6622: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6623: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6624: "\n";
1.160.6.105 raeburn 6625: if ($other_insts) {
6626: $datatable .= '<br />'.
6627: '<span class="LC_nobreak">'."\n".
6628: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6629: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6630: "\n";
6631: }
1.145 raeburn 6632: my (%current,%canselect);
1.152 raeburn 6633: my @choices =
6634: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6635: foreach my $type ('primary','default') {
6636: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6637: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6638: my @spares = @{$spareid->{$server}{$type}};
6639: if (@spares > 0) {
1.152 raeburn 6640: if ($othercontrol) {
6641: $current{$type} = join(', ',@spares);
6642: } else {
6643: $current{$type} .= '<table>';
6644: my $numspares = scalar(@spares);
6645: for (my $i=0; $i<@spares; $i++) {
6646: my $rem = $i%($numinrow);
6647: if ($rem == 0) {
6648: if ($i > 0) {
6649: $current{$type} .= '</tr>';
6650: }
6651: $current{$type} .= '<tr>';
1.145 raeburn 6652: }
1.152 raeburn 6653: $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'".');" /> '.
6654: $spareid->{$server}{$type}[$i].
6655: '</label></td>'."\n";
6656: }
6657: my $rem = @spares%($numinrow);
6658: my $colsleft = $numinrow - $rem;
6659: if ($colsleft > 1 ) {
6660: $current{$type} .= '<td colspan="'.$colsleft.
6661: '" class="LC_left_item">'.
6662: ' </td>';
6663: } elsif ($colsleft == 1) {
6664: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6665: }
1.152 raeburn 6666: $current{$type} .= '</tr></table>';
1.150 raeburn 6667: }
1.145 raeburn 6668: }
6669: }
6670: if ($current{$type} eq '') {
6671: $current{$type} = &mt('None specified');
6672: }
1.152 raeburn 6673: if ($othercontrol) {
6674: if ($type eq 'primary') {
6675: $canselect{$type} = $othercontrol;
6676: }
6677: } else {
6678: $canselect{$type} =
6679: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6680: '<select name="newspare_'.$type.'_'.$server.'" '.
6681: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6682: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6683: if (@choices > 0) {
6684: foreach my $lonhost (@choices) {
6685: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6686: }
6687: }
6688: $canselect{$type} .= '</select>'."\n";
6689: }
6690: } else {
6691: $current{$type} = &mt('Could not be determined');
6692: if ($type eq 'primary') {
6693: $canselect{$type} = $othercontrol;
6694: }
1.145 raeburn 6695: }
1.152 raeburn 6696: if ($type eq 'default') {
6697: $datatable .= '<tr'.$css_class.'>';
6698: }
6699: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6700: '<td>'.$current{$type}.'</td>'."\n".
6701: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6702: }
6703: $itemcount ++;
6704: }
6705: }
6706: $$rowtotal += $itemcount;
6707: return $datatable;
6708: }
6709:
1.152 raeburn 6710: sub possible_newspares {
6711: my ($server,$currspares,$serverhomes,$altids) = @_;
6712: my $serverhostname = &Apache::lonnet::hostname($server);
6713: my %excluded;
6714: if ($serverhostname ne '') {
6715: %excluded = (
6716: $serverhostname => 1,
6717: );
6718: }
6719: if (ref($currspares) eq 'HASH') {
6720: foreach my $type (keys(%{$currspares})) {
6721: if (ref($currspares->{$type}) eq 'ARRAY') {
6722: if (@{$currspares->{$type}} > 0) {
6723: foreach my $curr (@{$currspares->{$type}}) {
6724: my $hostname = &Apache::lonnet::hostname($curr);
6725: $excluded{$hostname} = 1;
6726: }
6727: }
6728: }
6729: }
6730: }
6731: my @choices;
6732: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6733: if (keys(%{$serverhomes}) > 1) {
6734: foreach my $name (sort(keys(%{$serverhomes}))) {
6735: unless ($excluded{$name}) {
6736: if (exists($altids->{$serverhomes->{$name}})) {
6737: push(@choices,$altids->{$serverhomes->{$name}});
6738: } else {
6739: push(@choices,$serverhomes->{$name});
1.145 raeburn 6740: }
6741: }
6742: }
6743: }
6744: }
1.152 raeburn 6745: return sort(@choices);
1.145 raeburn 6746: }
6747:
1.150 raeburn 6748: sub print_loadbalancing {
6749: my ($dom,$settings,$rowtotal) = @_;
6750: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6751: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6752: my $numinrow = 1;
6753: my $datatable;
6754: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6755: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6756: if (ref($settings) eq 'HASH') {
6757: %existing = %{$settings};
6758: }
6759: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6760: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6761: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6762: } else {
6763: return;
6764: }
6765: my ($othertitle,$usertypes,$types) =
6766: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6767: my $rownum = 8;
1.150 raeburn 6768: if (ref($types) eq 'ARRAY') {
6769: $rownum += scalar(@{$types});
6770: }
1.160.6.7 raeburn 6771: my @css_class = ('LC_odd_row','LC_even_row');
6772: my $balnum = 0;
6773: my $islast;
6774: my (@toshow,$disabledtext);
6775: if (keys(%currbalancer) > 0) {
6776: @toshow = sort(keys(%currbalancer));
6777: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6778: push(@toshow,'');
6779: }
6780: } else {
6781: @toshow = ('');
6782: $disabledtext = &mt('No existing load balancer');
6783: }
6784: foreach my $lonhost (@toshow) {
6785: if ($balnum == scalar(@toshow)-1) {
6786: $islast = 1;
6787: } else {
6788: $islast = 0;
6789: }
6790: my $cssidx = $balnum%2;
6791: my $targets_div_style = 'display: none';
6792: my $disabled_div_style = 'display: block';
6793: my $homedom_div_style = 'display: none';
6794: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6795: '<td rowspan="'.$rownum.'" valign="top">'.
6796: '<p>';
6797: if ($lonhost eq '') {
6798: $datatable .= '<span class="LC_nobreak">';
6799: if (keys(%currbalancer) > 0) {
6800: $datatable .= &mt('Add balancer:');
6801: } else {
6802: $datatable .= &mt('Enable balancer:');
6803: }
6804: $datatable .= ' '.
6805: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6806: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6807: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6808: '<option value="" selected="selected">'.&mt('None').
6809: '</option>'."\n";
6810: foreach my $server (sort(keys(%servers))) {
6811: next if ($currbalancer{$server});
6812: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6813: }
6814: $datatable .=
6815: '</select>'."\n".
6816: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6817: } else {
6818: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6819: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6820: &mt('Stop balancing').'</label>'.
6821: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6822: $targets_div_style = 'display: block';
6823: $disabled_div_style = 'display: none';
6824: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6825: $homedom_div_style = 'display: block';
6826: }
6827: }
6828: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6829: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6830: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6831: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6832: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6833: my @sparestypes = ('primary','default');
6834: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6835: my %hostherechecked = (
6836: no => ' checked="checked"',
6837: );
1.160.6.94 raeburn 6838: my %balcookiechecked = (
6839: no => ' checked="checked"',
6840: );
1.160.6.7 raeburn 6841: foreach my $sparetype (@sparestypes) {
6842: my $targettable;
6843: for (my $i=0; $i<$numspares; $i++) {
6844: my $checked;
6845: if (ref($currtargets{$lonhost}) eq 'HASH') {
6846: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6847: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6848: $checked = ' checked="checked"';
6849: }
6850: }
6851: }
6852: my ($chkboxval,$disabled);
6853: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6854: $chkboxval = $spares[$i];
6855: }
6856: if (exists($currbalancer{$spares[$i]})) {
6857: $disabled = ' disabled="disabled"';
6858: }
6859: $targettable .=
1.160.6.55 raeburn 6860: '<td><span class="LC_nobreak"><label>'.
6861: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6862: $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 6863: '</span></label></span></td>';
1.160.6.7 raeburn 6864: my $rem = $i%($numinrow);
6865: if ($rem == 0) {
6866: if (($i > 0) && ($i < $numspares-1)) {
6867: $targettable .= '</tr>';
6868: }
6869: if ($i < $numspares-1) {
6870: $targettable .= '<tr>';
1.150 raeburn 6871: }
6872: }
6873: }
1.160.6.7 raeburn 6874: if ($targettable ne '') {
6875: my $rem = $numspares%($numinrow);
6876: my $colsleft = $numinrow - $rem;
6877: if ($colsleft > 1 ) {
6878: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6879: ' </td>';
6880: } elsif ($colsleft == 1) {
6881: $targettable .= '<td class="LC_left_item"> </td>';
6882: }
6883: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6884: '<table><tr>'.$targettable.'</tr></table><br />';
6885: }
1.160.6.76 raeburn 6886: $hostherechecked{$sparetype} = '';
6887: if (ref($currtargets{$lonhost}) eq 'HASH') {
6888: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6889: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6890: $hostherechecked{$sparetype} = ' checked="checked"';
6891: $hostherechecked{'no'} = '';
6892: }
6893: }
6894: }
6895: }
1.160.6.94 raeburn 6896: if ($currcookies{$lonhost}) {
6897: %balcookiechecked = (
6898: yes => ' checked="checked"',
6899: );
6900: }
1.160.6.76 raeburn 6901: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6902: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6903: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6904: foreach my $sparetype (@sparestypes) {
6905: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6906: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6907: '</i></label><br />';
1.160.6.7 raeburn 6908: }
1.160.6.94 raeburn 6909: $datatable .= &mt('Use balancer cookie').'<br />'.
6910: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6911: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6912: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6913: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6914: '</div></td></tr>'.
1.160.6.7 raeburn 6915: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6916: $othertitle,$usertypes,$types,\%servers,
6917: \%currbalancer,$lonhost,
6918: $targets_div_style,$homedom_div_style,
6919: $css_class[$cssidx],$balnum,$islast);
6920: $$rowtotal += $rownum;
6921: $balnum ++;
6922: }
6923: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6924: return $datatable;
6925: }
6926:
6927: sub get_loadbalancers_config {
1.160.6.94 raeburn 6928: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6929: return unless ((ref($servers) eq 'HASH') &&
6930: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6931: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6932: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6933: if (keys(%{$existing}) > 0) {
6934: my $oldlonhost;
6935: foreach my $key (sort(keys(%{$existing}))) {
6936: if ($key eq 'lonhost') {
6937: $oldlonhost = $existing->{'lonhost'};
6938: $currbalancer->{$oldlonhost} = 1;
6939: } elsif ($key eq 'targets') {
6940: if ($oldlonhost) {
6941: $currtargets->{$oldlonhost} = $existing->{'targets'};
6942: }
6943: } elsif ($key eq 'rules') {
6944: if ($oldlonhost) {
6945: $currrules->{$oldlonhost} = $existing->{'rules'};
6946: }
6947: } elsif (ref($existing->{$key}) eq 'HASH') {
6948: $currbalancer->{$key} = 1;
6949: $currtargets->{$key} = $existing->{$key}{'targets'};
6950: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6951: if ($existing->{$key}{'cookie'}) {
6952: $currcookies->{$key} = 1;
6953: }
1.150 raeburn 6954: }
6955: }
1.160.6.7 raeburn 6956: } else {
6957: my ($balancerref,$targetsref) =
6958: &Apache::lonnet::get_lonbalancer_config($servers);
6959: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6960: foreach my $server (sort(keys(%{$balancerref}))) {
6961: $currbalancer->{$server} = 1;
6962: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6963: }
6964: }
6965: }
1.160.6.7 raeburn 6966: return;
1.150 raeburn 6967: }
6968:
6969: sub loadbalancing_rules {
6970: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6971: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6972: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6973: my $output;
1.160.6.7 raeburn 6974: my $num = 0;
6975: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6976: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6977: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6978: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6979: $num ++;
1.150 raeburn 6980: my $current;
6981: if (ref($currrules) eq 'HASH') {
6982: $current = $currrules->{$type};
6983: }
1.160.6.55 raeburn 6984: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6985: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6986: $current = '';
6987: }
6988: }
6989: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6990: $servers,$currbalancer,$lonhost,$dom,
6991: $targets_div_style,$homedom_div_style,
6992: $css_class,$balnum,$num,$islast);
1.150 raeburn 6993: }
6994: }
6995: return $output;
6996: }
6997:
6998: sub loadbalancing_titles {
6999: my ($dom,$intdom,$usertypes,$types) = @_;
7000: my %othertypes = (
7001: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7002: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7003: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7004: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 7005: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7006: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7007: );
1.160.6.26 raeburn 7008: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 7009: my @available;
1.150 raeburn 7010: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7011: @available = @{$types};
1.150 raeburn 7012: }
1.160.6.89 raeburn 7013: unless (grep(/^default$/,@available)) {
7014: push(@available,'default');
7015: }
7016: unshift(@alltypes,@available);
1.150 raeburn 7017: my %titles;
7018: foreach my $type (@alltypes) {
7019: if ($type =~ /^_LC_/) {
7020: $titles{$type} = $othertypes{$type};
7021: } elsif ($type eq 'default') {
7022: $titles{$type} = &mt('All users from [_1]',$dom);
7023: if (ref($types) eq 'ARRAY') {
7024: if (@{$types} > 0) {
7025: $titles{$type} = &mt('Other users from [_1]',$dom);
7026: }
7027: }
7028: } elsif (ref($usertypes) eq 'HASH') {
7029: $titles{$type} = $usertypes->{$type};
7030: }
7031: }
7032: return (\@alltypes,\%othertypes,\%titles);
7033: }
7034:
7035: sub loadbalance_rule_row {
1.160.6.7 raeburn 7036: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7037: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 7038: my @rulenames;
1.150 raeburn 7039: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 7040: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 7041: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7042: } else {
1.160.6.26 raeburn 7043: @rulenames = ('default','homeserver');
7044: if ($type eq '_LC_external') {
7045: push(@rulenames,'externalbalancer');
7046: } else {
7047: push(@rulenames,'specific');
7048: }
7049: push(@rulenames,'none');
1.150 raeburn 7050: }
7051: my $style = $targets_div_style;
1.160.6.55 raeburn 7052: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7053: $style = $homedom_div_style;
7054: }
1.160.6.7 raeburn 7055: my $space;
7056: if ($islast && $num == 1) {
7057: $space = '<div display="inline-block"> </div>';
7058: }
7059: my $output =
7060: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7061: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7062: '<td valaign="top">'.$space.
7063: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7064: for (my $i=0; $i<@rulenames; $i++) {
7065: my $rule = $rulenames[$i];
7066: my ($checked,$extra);
7067: if ($rulenames[$i] eq 'default') {
7068: $rule = '';
7069: }
7070: if ($rulenames[$i] eq 'specific') {
7071: if (ref($servers) eq 'HASH') {
7072: my $default;
7073: if (($current ne '') && (exists($servers->{$current}))) {
7074: $checked = ' checked="checked"';
7075: }
7076: unless ($checked) {
7077: $default = ' selected="selected"';
7078: }
1.160.6.7 raeburn 7079: $extra =
7080: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7081: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7082: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7083: '<option value=""'.$default.'></option>'."\n";
7084: foreach my $server (sort(keys(%{$servers}))) {
7085: if (ref($currbalancer) eq 'HASH') {
7086: next if (exists($currbalancer->{$server}));
7087: }
1.150 raeburn 7088: my $selected;
1.160.6.7 raeburn 7089: if ($server eq $current) {
1.150 raeburn 7090: $selected = ' selected="selected"';
7091: }
1.160.6.7 raeburn 7092: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7093: }
7094: $extra .= '</select>';
7095: }
7096: } elsif ($rule eq $current) {
7097: $checked = ' checked="checked"';
7098: }
7099: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 7100: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7101: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7102: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 7103: ')"'.$checked.' /> ';
1.160.6.56 raeburn 7104: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 7105: $output .= $ruletitles{'particular'};
7106: } else {
7107: $output .= $ruletitles{$rulenames[$i]};
7108: }
7109: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7110: }
7111: $output .= '</div></td></tr>'."\n";
7112: return $output;
7113: }
7114:
7115: sub offloadtype_text {
7116: my %ruletitles = &Apache::lonlocal::texthash (
7117: 'default' => 'Offloads to default destinations',
7118: 'homeserver' => "Offloads to user's home server",
7119: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7120: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 7121: 'none' => 'No offload',
1.160.6.26 raeburn 7122: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7123: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 7124: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7125: );
7126: return %ruletitles;
7127: }
7128:
7129: sub sparestype_titles {
7130: my %typestitles = &Apache::lonlocal::texthash (
7131: 'primary' => 'primary',
7132: 'default' => 'default',
7133: );
7134: return %typestitles;
7135: }
7136:
1.28 raeburn 7137: sub contact_titles {
7138: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 7139: 'supportemail' => 'Support E-mail address',
7140: 'adminemail' => 'Default Server Admin E-mail address',
7141: 'errormail' => 'Error reports to be e-mailed to',
7142: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 7143: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7144: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 7145: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7146: 'requestsmail' => 'E-mail from course requests requiring approval',
7147: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 7148: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 7149: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 7150: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7151: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 7152: 'errorweights' => 'Weights used to compute error count',
7153: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7154: );
7155: my %short_titles = &Apache::lonlocal::texthash (
7156: adminemail => 'Admin E-mail address',
7157: supportemail => 'Support E-mail',
7158: );
7159: return (\%titles,\%short_titles);
7160: }
7161:
1.160.6.78 raeburn 7162: sub helpform_fields {
7163: my %titles = &Apache::lonlocal::texthash (
7164: 'username' => 'Name',
7165: 'user' => 'Username/domain',
7166: 'phone' => 'Phone',
7167: 'cc' => 'Cc e-mail',
7168: 'course' => 'Course Details',
7169: 'section' => 'Sections',
7170: 'screenshot' => 'File upload',
7171: );
7172: my @fields = ('username','phone','user','course','section','cc','screenshot');
7173: my %possoptions = (
7174: username => ['yes','no','req'],
7175: phone => ['yes','no','req'],
7176: user => ['yes','no'],
7177: cc => ['yes','no'],
7178: course => ['yes','no'],
7179: section => ['yes','no'],
7180: screenshot => ['yes','no'],
7181: );
7182: my %fieldoptions = &Apache::lonlocal::texthash (
7183: 'yes' => 'Optional',
7184: 'req' => 'Required',
7185: 'no' => "Not shown",
7186: );
7187: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7188: }
7189:
1.72 raeburn 7190: sub tool_titles {
7191: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 7192: aboutme => 'Personal web page',
1.86 raeburn 7193: blog => 'Blog',
1.160.6.4 raeburn 7194: webdav => 'WebDAV',
1.86 raeburn 7195: portfolio => 'Portfolio',
1.88 bisitz 7196: official => 'Official courses (with institutional codes)',
7197: unofficial => 'Unofficial courses',
1.98 raeburn 7198: community => 'Communities',
1.160.6.30 raeburn 7199: textbook => 'Textbook courses',
1.86 raeburn 7200: );
1.72 raeburn 7201: return %titles;
7202: }
7203:
1.101 raeburn 7204: sub courserequest_titles {
7205: my %titles = &Apache::lonlocal::texthash (
7206: official => 'Official',
7207: unofficial => 'Unofficial',
7208: community => 'Communities',
1.160.6.30 raeburn 7209: textbook => 'Textbook',
1.101 raeburn 7210: norequest => 'Not allowed',
1.104 raeburn 7211: approval => 'Approval by Dom. Coord.',
1.101 raeburn 7212: validate => 'With validation',
7213: autolimit => 'Numerical limit',
1.103 raeburn 7214: unlimited => '(blank for unlimited)',
1.101 raeburn 7215: );
7216: return %titles;
7217: }
7218:
1.160.6.5 raeburn 7219: sub authorrequest_titles {
7220: my %titles = &Apache::lonlocal::texthash (
7221: norequest => 'Not allowed',
7222: approval => 'Approval by Dom. Coord.',
7223: automatic => 'Automatic approval',
7224: );
7225: return %titles;
7226: }
7227:
1.101 raeburn 7228: sub courserequest_conditions {
7229: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7230: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 7231: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7232: );
7233: return %conditions;
7234: }
7235:
7236:
1.27 raeburn 7237: sub print_usercreation {
1.30 raeburn 7238: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7239: my $numinrow = 4;
1.28 raeburn 7240: my $datatable;
7241: if ($position eq 'top') {
1.30 raeburn 7242: $$rowtotal ++;
1.34 raeburn 7243: my $rowcount = 0;
1.32 raeburn 7244: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7245: if (ref($rules) eq 'HASH') {
7246: if (keys(%{$rules}) > 0) {
1.32 raeburn 7247: $datatable .= &user_formats_row('username',$settings,$rules,
7248: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7249: $$rowtotal ++;
1.32 raeburn 7250: $rowcount ++;
7251: }
7252: }
7253: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7254: if (ref($idrules) eq 'HASH') {
7255: if (keys(%{$idrules}) > 0) {
7256: $datatable .= &user_formats_row('id',$settings,$idrules,
7257: $idruleorder,$numinrow,$rowcount);
7258: $$rowtotal ++;
7259: $rowcount ++;
1.28 raeburn 7260: }
7261: }
1.39 raeburn 7262: if ($rowcount == 0) {
7263: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7264: $$rowtotal ++;
7265: $rowcount ++;
7266: }
1.34 raeburn 7267: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 7268: my @creators = ('author','course','requestcrs');
1.37 raeburn 7269: my ($rules,$ruleorder) =
7270: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7271: my %lt = &usercreation_types();
7272: my %checked;
7273: if (ref($settings) eq 'HASH') {
7274: if (ref($settings->{'cancreate'}) eq 'HASH') {
7275: foreach my $item (@creators) {
7276: $checked{$item} = $settings->{'cancreate'}{$item};
7277: }
7278: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7279: foreach my $item (@creators) {
7280: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7281: $checked{$item} = 'none';
7282: }
7283: }
7284: }
7285: }
7286: my $rownum = 0;
7287: foreach my $item (@creators) {
7288: $rownum ++;
1.160.6.34 raeburn 7289: if ($checked{$item} eq '') {
7290: $checked{$item} = 'any';
1.34 raeburn 7291: }
7292: my $css_class;
7293: if ($rownum%2) {
7294: $css_class = '';
7295: } else {
7296: $css_class = ' class="LC_odd_row" ';
7297: }
7298: $datatable .= '<tr'.$css_class.'>'.
7299: '<td><span class="LC_nobreak">'.$lt{$item}.
7300: '</span></td><td align="right">';
1.160.6.34 raeburn 7301: my @options = ('any');
7302: if (ref($rules) eq 'HASH') {
7303: if (keys(%{$rules}) > 0) {
7304: push(@options,('official','unofficial'));
1.37 raeburn 7305: }
7306: }
1.160.6.34 raeburn 7307: push(@options,'none');
1.37 raeburn 7308: foreach my $option (@options) {
1.50 raeburn 7309: my $type = 'radio';
1.34 raeburn 7310: my $check = ' ';
1.160.6.34 raeburn 7311: if ($checked{$item} eq $option) {
7312: $check = ' checked="checked" ';
1.34 raeburn 7313: }
7314: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7315: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7316: $item.'" value="'.$option.'"'.$check.'/> '.
7317: $lt{$option}.'</label> </span>';
7318: }
7319: $datatable .= '</td></tr>';
7320: }
1.28 raeburn 7321: } else {
7322: my @contexts = ('author','course','domain');
7323: my @authtypes = ('int','krb4','krb5','loc');
7324: my %checked;
7325: if (ref($settings) eq 'HASH') {
7326: if (ref($settings->{'authtypes'}) eq 'HASH') {
7327: foreach my $item (@contexts) {
7328: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7329: foreach my $auth (@authtypes) {
7330: if ($settings->{'authtypes'}{$item}{$auth}) {
7331: $checked{$item}{$auth} = ' checked="checked" ';
7332: }
7333: }
7334: }
7335: }
1.27 raeburn 7336: }
1.35 raeburn 7337: } else {
7338: foreach my $item (@contexts) {
1.36 raeburn 7339: foreach my $auth (@authtypes) {
1.35 raeburn 7340: $checked{$item}{$auth} = ' checked="checked" ';
7341: }
7342: }
1.27 raeburn 7343: }
1.28 raeburn 7344: my %title = &context_names();
7345: my %authname = &authtype_names();
7346: my $rownum = 0;
7347: my $css_class;
7348: foreach my $item (@contexts) {
7349: if ($rownum%2) {
7350: $css_class = '';
7351: } else {
7352: $css_class = ' class="LC_odd_row" ';
7353: }
1.30 raeburn 7354: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7355: '<td>'.$title{$item}.
7356: '</td><td class="LC_left_item">'.
7357: '<span class="LC_nobreak">';
7358: foreach my $auth (@authtypes) {
7359: $datatable .= '<label>'.
7360: '<input type="checkbox" name="'.$item.'_auth" '.
7361: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7362: $authname{$auth}.'</label> ';
7363: }
7364: $datatable .= '</span></td></tr>';
7365: $rownum ++;
1.27 raeburn 7366: }
1.30 raeburn 7367: $$rowtotal += $rownum;
1.27 raeburn 7368: }
7369: return $datatable;
7370: }
7371:
1.160.6.34 raeburn 7372: sub print_selfcreation {
7373: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 7374: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7375: $emaildomain,$datatable);
1.160.6.34 raeburn 7376: if (ref($settings) eq 'HASH') {
7377: if (ref($settings->{'cancreate'}) eq 'HASH') {
7378: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 7379: if (ref($createsettings) eq 'HASH') {
7380: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7381: @selfcreate = @{$createsettings->{'selfcreate'}};
7382: } elsif ($createsettings->{'selfcreate'} ne '') {
7383: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7384: @selfcreate = ('email','login','sso');
7385: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7386: @selfcreate = ($createsettings->{'selfcreate'});
7387: }
7388: }
7389: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7390: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 7391: }
1.160.6.93 raeburn 7392: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7393: $emailoptions = $createsettings->{'emailoptions'};
7394: }
7395: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7396: $emailverified = $createsettings->{'emailverified'};
7397: }
7398: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7399: $emaildomain = $createsettings->{'emaildomain'};
7400: }
1.160.6.34 raeburn 7401: }
7402: }
7403: }
7404: my %radiohash;
7405: my $numinrow = 4;
7406: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 7407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 7408: if ($position eq 'top') {
7409: my %choices = &Apache::lonlocal::texthash (
7410: cancreate_login => 'Institutional Login',
7411: cancreate_sso => 'Institutional Single Sign On',
7412: );
7413: my @toggles = sort(keys(%choices));
7414: my %defaultchecked = (
7415: 'cancreate_login' => 'off',
7416: 'cancreate_sso' => 'off',
7417: );
1.160.6.35 raeburn 7418: my ($onclick,$itemcount);
1.160.6.34 raeburn 7419: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7420: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 7421: $$rowtotal += $itemcount;
1.160.6.34 raeburn 7422:
7423: if (ref($usertypes) eq 'HASH') {
7424: if (keys(%{$usertypes}) > 0) {
7425: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7426: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 7427: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 7428: $$rowtotal ++;
7429: }
7430: }
1.160.6.44 raeburn 7431: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7432: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7433: $fieldtitles{'inststatus'} = &mt('Institutional status');
7434: my $rem;
7435: my $numperrow = 2;
7436: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7437: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 7438: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 7439: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 7440: '<table>'."\n";
1.160.6.44 raeburn 7441: for (my $i=0; $i<@fields; $i++) {
7442: $rem = $i%($numperrow);
7443: if ($rem == 0) {
7444: if ($i > 0) {
7445: $datatable .= '</tr>';
7446: }
7447: $datatable .= '<tr>';
7448: }
7449: my $currval;
1.160.6.51 raeburn 7450: if (ref($createsettings) eq 'HASH') {
7451: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7452: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7453: }
1.160.6.44 raeburn 7454: }
7455: $datatable .= '<td class="LC_left_item">'.
7456: '<span class="LC_nobreak">'.
7457: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7458: 'value="'.$currval.'" size="10" /> '.
7459: $fieldtitles{$fields[$i]}.'</span></td>';
7460: }
7461: my $colsleft = $numperrow - $rem;
7462: if ($colsleft > 1 ) {
7463: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7464: ' </td>';
7465: } elsif ($colsleft == 1) {
7466: $datatable .= '<td class="LC_left_item"> </td>';
7467: }
7468: $datatable .= '</tr></table></td></tr>';
7469: $$rowtotal ++;
1.160.6.34 raeburn 7470: } elsif ($position eq 'middle') {
7471: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 7472: my @posstypes;
1.160.6.34 raeburn 7473: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7474: @posstypes = @{$types};
7475: }
7476: unless (grep(/^default$/,@posstypes)) {
7477: push(@posstypes,'default');
7478: }
7479: my %usertypeshash;
7480: if (ref($usertypes) eq 'HASH') {
7481: %usertypeshash = %{$usertypes};
7482: }
7483: $usertypeshash{'default'} = $othertitle;
7484: foreach my $status (@posstypes) {
7485: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7486: $numinrow,$$rowtotal,\%usertypeshash);
7487: $$rowtotal ++;
1.160.6.34 raeburn 7488: }
7489: } else {
1.160.6.40 raeburn 7490: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 7491: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 7492: );
7493: my @toggles = sort(keys(%choices));
7494: my %defaultchecked = (
7495: 'cancreate_email' => 'off',
7496: );
1.160.6.93 raeburn 7497: my $customclass = 'LC_selfcreate_email';
7498: my $classprefix = 'LC_canmodify_emailusername_';
7499: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 7500: my $display = 'none';
1.160.6.93 raeburn 7501: my $rowstyle = 'display:none';
1.160.6.40 raeburn 7502: if (grep(/^\Qemail\E$/,@selfcreate)) {
7503: $display = 'block';
1.160.6.93 raeburn 7504: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 7505: }
1.160.6.93 raeburn 7506: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7507: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7508: \%choices,$$rowtotal,$onclick);
7509: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7510: $rowstyle);
7511: $$rowtotal ++;
7512: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7513: $rowstyle);
7514: $$rowtotal ++;
7515: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 7516: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 7517: my ($emailrules,$emailruleorder) =
7518: &Apache::lonnet::inst_userrules($dom,'email');
7519: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7520: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7521: if (ref($types) eq 'ARRAY') {
7522: @posstypes = @{$types};
7523: }
7524: if (@posstypes) {
7525: unless (grep(/^default$/,@posstypes)) {
7526: push(@posstypes,'default');
1.160.6.89 raeburn 7527: }
7528: if (ref($usertypes) eq 'HASH') {
7529: %usertypeshash = %{$usertypes};
7530: }
1.160.6.93 raeburn 7531: my $currassign;
7532: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7533: $currassign = {
7534: selfassign => $domdefaults{'inststatusguest'},
7535: };
7536: @ordered = @{$domdefaults{'inststatusguest'}};
7537: } else {
7538: $currassign = { selfassign => [] };
7539: }
7540: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7541: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7542: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7543: $numinrow,$othertitle,'selfassign',
7544: $rowtotal,$onclicktypes,$customclass,
7545: $rowstyle);
7546: $$rowtotal ++;
1.160.6.89 raeburn 7547: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7548: foreach my $status (@posstypes) {
7549: my $css_class;
7550: if ($$rowtotal%2) {
7551: $css_class = 'LC_odd_row ';
7552: }
7553: $css_class .= $customclass;
7554: my $rowid = $optionsprefix.$status;
7555: my $hidden = 1;
7556: my $currstyle = 'display:none';
7557: if (grep(/^\Q$status\E$/,@ordered)) {
7558: $currstyle = $rowstyle;
7559: $hidden = 0;
7560: }
7561: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7562: $emailrules,$emailruleorder,$settings,$status,$rowid,
7563: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7564: unless ($hidden) {
7565: $$rowtotal ++;
7566: }
1.160.6.89 raeburn 7567: }
7568: } else {
1.160.6.93 raeburn 7569: my $css_class;
7570: if ($$rowtotal%2) {
7571: $css_class = 'LC_odd_row ';
7572: }
7573: $css_class .= $customclass;
1.160.6.89 raeburn 7574: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7575: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7576: $emailrules,$emailruleorder,$settings,'default','',
7577: $othertitle,$css_class,$rowstyle,$intdom);
7578: $$rowtotal ++;
1.160.6.34 raeburn 7579: }
1.160.6.35 raeburn 7580: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7581: $numinrow = 1;
1.160.6.93 raeburn 7582: if (@posstypes) {
7583: foreach my $status (@posstypes) {
7584: my $rowid = $classprefix.$status;
7585: my $datarowstyle = 'display:none';
7586: if (grep(/^\Q$status\E$/,@ordered)) {
7587: $datarowstyle = $rowstyle;
7588: }
7589: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7590: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7591: $infotitles,$rowid,$customclass,$datarowstyle);
7592: unless ($datarowstyle eq 'display:none') {
7593: $$rowtotal ++;
7594: }
1.160.6.34 raeburn 7595: }
1.160.6.93 raeburn 7596: } else {
7597: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7598: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7599: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7600: }
7601: }
7602: return $datatable;
7603: }
7604:
1.160.6.93 raeburn 7605: sub selfcreate_javascript {
7606: return <<"ENDSCRIPT";
7607:
7608: <script type="text/javascript">
7609: // <![CDATA[
7610:
7611: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7612: var x = document.getElementsByClassName(target);
7613: var insttypes = 0;
7614: var insttypeRegExp = new RegExp(prefix);
7615: if ((x.length != undefined) && (x.length > 0)) {
7616: if (form.elements[radio].length != undefined) {
7617: for (var i=0; i<form.elements[radio].length; i++) {
7618: if (form.elements[radio][i].checked) {
7619: if (form.elements[radio][i].value == 1) {
7620: for (var j=0; j<x.length; j++) {
7621: if (x[j].id == 'undefined') {
7622: x[j].style.display = 'table-row';
7623: } else if (insttypeRegExp.test(x[j].id)) {
7624: insttypes ++;
7625: } else {
7626: x[j].style.display = 'table-row';
7627: }
7628: }
7629: } else {
7630: for (var j=0; j<x.length; j++) {
7631: x[j].style.display = 'none';
7632: }
1.160.6.40 raeburn 7633: }
1.160.6.93 raeburn 7634: break;
7635: }
7636: }
7637: if (insttypes > 0) {
7638: toggleDataRow(form,checkbox,target,altprefix);
7639: toggleDataRow(form,checkbox,target,prefix,1);
7640: }
7641: }
7642: }
7643: return;
7644: }
7645:
7646: function toggleDataRow(form,checkbox,target,prefix,docount) {
7647: if (form.elements[checkbox].length != undefined) {
7648: var count = 0;
7649: if (docount) {
7650: for (var i=0; i<form.elements[checkbox].length; i++) {
7651: if (form.elements[checkbox][i].checked) {
7652: count ++;
7653: }
7654: }
7655: }
7656: for (var i=0; i<form.elements[checkbox].length; i++) {
7657: var type = form.elements[checkbox][i].value;
7658: if (document.getElementById(prefix+type)) {
7659: if (form.elements[checkbox][i].checked) {
7660: document.getElementById(prefix+type).style.display = 'table-row';
7661: if (count % 2 == 1) {
7662: document.getElementById(prefix+type).className = target+' LC_odd_row';
7663: } else {
7664: document.getElementById(prefix+type).className = target;
7665: }
7666: count ++;
1.160.6.40 raeburn 7667: } else {
1.160.6.93 raeburn 7668: document.getElementById(prefix+type).style.display = 'none';
7669: }
7670: }
7671: }
7672: }
7673: return;
7674: }
7675:
7676: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7677: var caller = radio+'_'+status;
7678: if (form.elements[caller].length != undefined) {
7679: for (var i=0; i<form.elements[caller].length; i++) {
7680: if (form.elements[caller][i].checked) {
7681: if (document.getElementById(altprefix+'_inst_'+status)) {
7682: var curr = form.elements[caller][i].value;
7683: if (prefix) {
7684: document.getElementById(prefix+'_'+status).style.display = 'none';
7685: }
7686: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7687: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7688: if (curr == 'custom') {
7689: if (prefix) {
7690: document.getElementById(prefix+'_'+status).style.display = 'inline';
7691: }
7692: } else if (curr == 'inst') {
7693: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7694: } else if (curr == 'noninst') {
7695: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7696: }
1.160.6.93 raeburn 7697: break;
1.160.6.40 raeburn 7698: }
1.160.6.93 raeburn 7699: }
7700: }
7701: }
7702: }
7703:
7704: // ]]>
7705: </script>
7706:
7707: ENDSCRIPT
7708: }
7709:
7710: sub noninst_users {
7711: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7712: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7713: my $class = 'LC_left_item';
7714: if ($css_class) {
7715: $css_class = ' class="'.$css_class.'"';
7716: }
7717: if ($rowid) {
7718: $rowid = ' id="'.$rowid.'"';
7719: }
7720: if ($rowstyle) {
7721: $rowstyle = ' style="'.$rowstyle.'"';
7722: }
7723: my ($output,$description);
7724: if ($type eq 'default') {
7725: $description = &mt('Requests for: [_1]',$typetitle);
7726: } else {
7727: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7728: }
7729: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7730: "<td>$description</td>\n".
7731: '<td class="'.$class.'" colspan="2">'.
7732: '<table><tr>';
7733: my %headers = &Apache::lonlocal::texthash(
7734: approve => 'Processing',
7735: email => 'E-mail',
7736: username => 'Username',
7737: );
7738: foreach my $item ('approve','email','username') {
7739: $output .= '<th>'.$headers{$item}.'</th>';
7740: }
7741: $output .= '</tr><tr>';
7742: foreach my $item ('approve','email','username') {
7743: $output .= '<td valign="top">';
7744: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7745: if ($item eq 'approve') {
7746: %choices = &Apache::lonlocal::texthash (
7747: automatic => 'Automatically approved',
7748: approval => 'Queued for approval',
7749: );
7750: @options = ('automatic','approval');
7751: $hashref = $processing;
7752: $defoption = 'automatic';
7753: $name = 'cancreate_emailprocess_'.$type;
7754: } elsif ($item eq 'email') {
7755: %choices = &Apache::lonlocal::texthash (
7756: any => 'Any e-mail',
7757: inst => 'Institutional only',
7758: noninst => 'Non-institutional only',
7759: custom => 'Custom restrictions',
7760: );
7761: @options = ('any','inst','noninst');
7762: my $showcustom;
7763: if (ref($emailrules) eq 'HASH') {
7764: if (keys(%{$emailrules}) > 0) {
7765: push(@options,'custom');
7766: $showcustom = 'cancreate_emailrule';
7767: if (ref($settings) eq 'HASH') {
7768: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7769: foreach my $rule (@{$settings->{'email_rule'}}) {
7770: if (exists($emailrules->{$rule})) {
7771: $hascustom ++;
7772: }
7773: }
7774: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7775: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7776: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7777: if (exists($emailrules->{$rule})) {
7778: $hascustom ++;
7779: }
7780: }
7781: }
7782: }
7783: }
7784: }
7785: }
7786: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7787: "'cancreate_emaildomain','$type'".');"';
7788: $hashref = $emailoptions;
7789: $defoption = 'any';
7790: $name = 'cancreate_emailoptions_'.$type;
7791: } elsif ($item eq 'username') {
7792: %choices = &Apache::lonlocal::texthash (
7793: all => 'Same as e-mail',
7794: first => 'Omit @domain',
7795: free => 'Free to choose',
7796: );
7797: @options = ('all','first','free');
7798: $hashref = $emailverified;
7799: $defoption = 'all';
7800: $name = 'cancreate_usernameoptions_'.$type;
7801: }
7802: foreach my $option (@options) {
7803: my $checked;
7804: if (ref($hashref) eq 'HASH') {
7805: if ($type eq '') {
7806: if (!exists($hashref->{'default'})) {
7807: if ($option eq $defoption) {
7808: $checked = ' checked="checked"';
7809: }
7810: } else {
7811: if ($hashref->{'default'} eq $option) {
7812: $checked = ' checked="checked"';
7813: }
1.160.6.40 raeburn 7814: }
7815: } else {
1.160.6.93 raeburn 7816: if (!exists($hashref->{$type})) {
7817: if ($option eq $defoption) {
7818: $checked = ' checked="checked"';
7819: }
7820: } else {
7821: if ($hashref->{$type} eq $option) {
7822: $checked = ' checked="checked"';
7823: }
1.160.6.40 raeburn 7824: }
7825: }
1.160.6.93 raeburn 7826: } elsif (($item eq 'email') && ($hascustom)) {
7827: if ($option eq 'custom') {
7828: $checked = ' checked="checked"';
7829: }
7830: } elsif ($option eq $defoption) {
7831: $checked = ' checked="checked"';
7832: }
7833: $output .= '<span class="LC_nobreak"><label>'.
7834: '<input type="radio" name="'.$name.'"'.
7835: $checked.' value="'.$option.'"'.$onclick.' />'.
7836: $choices{$option}.'</label></span><br />';
7837: if ($item eq 'email') {
7838: if ($option eq 'custom') {
7839: my $id = 'cancreate_emailrule_'.$type;
7840: my $display = 'none';
7841: if ($checked) {
7842: $display = 'inline';
7843: }
7844: my $numinrow = 2;
7845: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7846: '<legend>'.&mt('Disallow').'</legend><table>'.
7847: &user_formats_row('email',$settings,$emailrules,
7848: $emailruleorder,$numinrow,'',$type);
7849: '</table></fieldset>';
7850: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7851: my %text = &Apache::lonlocal::texthash (
7852: inst => 'must end:',
7853: noninst => 'cannot end:',
7854: );
7855: my $value;
7856: if (ref($emaildomain) eq 'HASH') {
7857: if (ref($emaildomain->{$type}) eq 'HASH') {
7858: $value = $emaildomain->{$type}->{$option};
7859: }
7860: }
7861: if ($value eq '') {
7862: $value = '@'.$intdom;
7863: }
7864: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7865: my $display = 'none';
7866: if ($checked) {
7867: $display = 'inline';
7868: }
7869: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7870: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7871: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7872: '</div>';
7873: }
1.160.6.40 raeburn 7874: }
7875: }
1.160.6.93 raeburn 7876: $output .= '</td>'."\n";
1.160.6.40 raeburn 7877: }
1.160.6.93 raeburn 7878: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7879: return $output;
7880: }
7881:
1.160.6.5 raeburn 7882: sub captcha_choice {
1.160.6.93 raeburn 7883: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7884: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7885: $vertext,$currver);
1.160.6.5 raeburn 7886: my %lt = &captcha_phrases();
7887: $keyentry = 'hidden';
1.160.6.98 raeburn 7888: my $colspan=2;
1.160.6.5 raeburn 7889: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7890: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7891: } elsif ($context eq 'login') {
7892: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7893: } elsif ($context eq 'passwords') {
7894: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7895: $colspan=1;
1.160.6.5 raeburn 7896: }
7897: if (ref($settings) eq 'HASH') {
7898: if ($settings->{'captcha'}) {
7899: $checked{$settings->{'captcha'}} = ' checked="checked"';
7900: } else {
7901: $checked{'original'} = ' checked="checked"';
7902: }
7903: if ($settings->{'captcha'} eq 'recaptcha') {
7904: $pubtext = $lt{'pub'};
7905: $privtext = $lt{'priv'};
7906: $keyentry = 'text';
1.160.6.69 raeburn 7907: $vertext = $lt{'ver'};
7908: $currver = $settings->{'recaptchaversion'};
7909: if ($currver ne '2') {
7910: $currver = 1;
7911: }
1.160.6.5 raeburn 7912: }
7913: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7914: $currpub = $settings->{'recaptchakeys'}{'public'};
7915: $currpriv = $settings->{'recaptchakeys'}{'private'};
7916: }
7917: } else {
7918: $checked{'original'} = ' checked="checked"';
7919: }
1.160.6.93 raeburn 7920: my $css_class;
7921: if ($itemcount%2) {
7922: $css_class = 'LC_odd_row';
7923: }
7924: if ($customcss) {
7925: $css_class .= " $customcss";
7926: }
7927: $css_class =~ s/^\s+//;
7928: if ($css_class) {
7929: $css_class = ' class="'.$css_class.'"';
7930: }
7931: if ($rowstyle) {
7932: $css_class .= ' style="'.$rowstyle.'"';
7933: }
1.160.6.5 raeburn 7934: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7935: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7936: '<table><tr><td>'."\n";
7937: foreach my $option ('original','recaptcha','notused') {
7938: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7939: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7940: $lt{$option}.'</label></span>';
7941: unless ($option eq 'notused') {
7942: $output .= (' 'x2)."\n";
7943: }
7944: }
7945: #
7946: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7947: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7948: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7949: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7950: #
7951: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7952: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7953: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7954: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7955: $currpub.'" size="40" /></span><br />'."\n".
7956: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7957: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7958: $currpriv.'" size="40" /></span><br />'.
7959: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7960: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7961: $currver.'" size="3" /></span><br />'.
7962: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7963: '</td></tr>';
7964: return $output;
7965: }
7966:
1.32 raeburn 7967: sub user_formats_row {
1.160.6.93 raeburn 7968: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7969: my $output;
7970: my %text = (
7971: 'username' => 'new usernames',
7972: 'id' => 'IDs',
7973: );
1.160.6.93 raeburn 7974: unless ($type eq 'email') {
7975: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7976: $output = '<tr '.$css_class.'>'.
7977: '<td><span class="LC_nobreak">'.
7978: &mt("Format rules to check for $text{$type}: ").
7979: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7980: }
1.27 raeburn 7981: my $rem;
7982: if (ref($ruleorder) eq 'ARRAY') {
7983: for (my $i=0; $i<@{$ruleorder}; $i++) {
7984: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7985: my $rem = $i%($numinrow);
7986: if ($rem == 0) {
7987: if ($i > 0) {
7988: $output .= '</tr>';
7989: }
7990: $output .= '<tr>';
7991: }
7992: my $check = ' ';
1.39 raeburn 7993: if (ref($settings) eq 'HASH') {
7994: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7995: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7996: $check = ' checked="checked" ';
7997: }
1.160.6.93 raeburn 7998: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7999: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8000: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8001: $check = ' checked="checked" ';
8002: }
8003: }
1.27 raeburn 8004: }
8005: }
1.160.6.93 raeburn 8006: my $name = $type.'_rule';
8007: if ($type eq 'email') {
8008: $name .= '_'.$status;
8009: }
1.27 raeburn 8010: $output .= '<td class="LC_left_item">'.
8011: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 8012: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8013: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8014: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8015: }
8016: }
8017: $rem = @{$ruleorder}%($numinrow);
8018: }
1.160.6.93 raeburn 8019: my $colsleft;
8020: if ($rem) {
8021: $colsleft = $numinrow - $rem;
8022: }
1.27 raeburn 8023: if ($colsleft > 1 ) {
8024: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8025: ' </td>';
8026: } elsif ($colsleft == 1) {
8027: $output .= '<td class="LC_left_item"> </td>';
8028: }
1.160.6.93 raeburn 8029: $output .= '</tr></table>';
8030: unless ($type eq 'email') {
8031: $output .= '</td></tr>';
8032: }
1.27 raeburn 8033: return $output;
8034: }
8035:
1.34 raeburn 8036: sub usercreation_types {
8037: my %lt = &Apache::lonlocal::texthash (
8038: author => 'When adding a co-author',
8039: course => 'When adding a user to a course',
1.100 raeburn 8040: requestcrs => 'When requesting a course',
1.34 raeburn 8041: any => 'Any',
8042: official => 'Institutional only ',
8043: unofficial => 'Non-institutional only',
8044: none => 'None',
8045: );
8046: return %lt;
1.48 raeburn 8047: }
1.34 raeburn 8048:
1.160.6.34 raeburn 8049: sub selfcreation_types {
8050: my %lt = &Apache::lonlocal::texthash (
8051: selfcreate => 'User creates own account',
8052: any => 'Any',
8053: official => 'Institutional only ',
8054: unofficial => 'Non-institutional only',
8055: email => 'E-mail address',
8056: login => 'Institutional Login',
8057: sso => 'SSO',
8058: );
8059: }
8060:
1.28 raeburn 8061: sub authtype_names {
8062: my %lt = &Apache::lonlocal::texthash(
8063: int => 'Internal',
8064: krb4 => 'Kerberos 4',
8065: krb5 => 'Kerberos 5',
8066: loc => 'Local',
8067: );
8068: return %lt;
8069: }
8070:
8071: sub context_names {
8072: my %context_title = &Apache::lonlocal::texthash(
8073: author => 'Creating users when an Author',
8074: course => 'Creating users when in a course',
8075: domain => 'Creating users when a Domain Coordinator',
8076: );
8077: return %context_title;
8078: }
8079:
1.33 raeburn 8080: sub print_usermodification {
8081: my ($position,$dom,$settings,$rowtotal) = @_;
8082: my $numinrow = 4;
8083: my ($context,$datatable,$rowcount);
8084: if ($position eq 'top') {
8085: $rowcount = 0;
8086: $context = 'author';
8087: foreach my $role ('ca','aa') {
8088: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8089: $numinrow,$rowcount);
8090: $$rowtotal ++;
8091: $rowcount ++;
8092: }
1.160.6.37 raeburn 8093: } elsif ($position eq 'bottom') {
1.33 raeburn 8094: $context = 'course';
8095: $rowcount = 0;
8096: foreach my $role ('st','ep','ta','in','cr') {
8097: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8098: $numinrow,$rowcount);
8099: $$rowtotal ++;
8100: $rowcount ++;
8101: }
8102: }
8103: return $datatable;
8104: }
8105:
1.43 raeburn 8106: sub print_defaults {
1.160.6.40 raeburn 8107: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8108: my $rownum = 0;
1.160.6.80 raeburn 8109: my ($datatable,$css_class,$titles);
8110: unless ($position eq 'bottom') {
8111: $titles = &defaults_titles($dom);
8112: }
1.160.6.40 raeburn 8113: if ($position eq 'top') {
8114: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8115: 'datelocale_def','portal_def');
8116: my %defaults;
8117: if (ref($settings) eq 'HASH') {
8118: %defaults = %{$settings};
1.43 raeburn 8119: } else {
1.160.6.40 raeburn 8120: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8121: foreach my $item (@items) {
8122: $defaults{$item} = $domdefaults{$item};
8123: }
1.43 raeburn 8124: }
1.160.6.40 raeburn 8125: foreach my $item (@items) {
8126: if ($rownum%2) {
8127: $css_class = '';
8128: } else {
8129: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 8130: }
1.160.6.40 raeburn 8131: $datatable .= '<tr'.$css_class.'>'.
8132: '<td><span class="LC_nobreak">'.$titles->{$item}.
8133: '</span></td><td class="LC_right_item" colspan="3">';
8134: if ($item eq 'auth_def') {
8135: my @authtypes = ('internal','krb4','krb5','localauth');
8136: my %shortauth = (
8137: internal => 'int',
8138: krb4 => 'krb4',
8139: krb5 => 'krb5',
8140: localauth => 'loc'
8141: );
8142: my %authnames = &authtype_names();
8143: foreach my $auth (@authtypes) {
8144: my $checked = ' ';
8145: if ($defaults{$item} eq $auth) {
8146: $checked = ' checked="checked" ';
8147: }
8148: $datatable .= '<label><input type="radio" name="'.$item.
8149: '" value="'.$auth.'"'.$checked.'/>'.
8150: $authnames{$shortauth{$auth}}.'</label> ';
8151: }
8152: } elsif ($item eq 'timezone_def') {
8153: my $includeempty = 1;
8154: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8155: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 8156: my $includeempty = 1;
8157: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8158: } elsif ($item eq 'lang_def') {
8159: my $includeempty = 1;
8160: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 8161: } else {
1.160.6.98 raeburn 8162: my $size;
8163: if ($item eq 'portal_def') {
8164: $size = ' size="25"';
8165: }
1.160.6.80 raeburn 8166: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 8167: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 8168: }
8169: $datatable .= '</td></tr>';
8170: $rownum ++;
8171: }
1.160.6.40 raeburn 8172: } else {
1.160.6.80 raeburn 8173: my %defaults;
1.160.6.40 raeburn 8174: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 8175: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 8176: my $maxnum = @{$settings->{'inststatusorder'}};
8177: for (my $i=0; $i<$maxnum; $i++) {
8178: $css_class = $rownum%2?' class="LC_odd_row"':'';
8179: my $item = $settings->{'inststatusorder'}->[$i];
8180: my $title = $settings->{'inststatustypes'}->{$item};
8181: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8182: $datatable .= '<tr'.$css_class.'>'.
8183: '<td><span class="LC_nobreak">'.
8184: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8185: for (my $k=0; $k<=$maxnum; $k++) {
8186: my $vpos = $k+1;
8187: my $selstr;
8188: if ($k == $i) {
8189: $selstr = ' selected="selected" ';
8190: }
8191: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8192: }
8193: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8194: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8195: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 8196: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 8197: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 8198: '</span></td></tr>';
1.160.6.40 raeburn 8199: }
8200: $css_class = $rownum%2?' class="LC_odd_row"':'';
8201: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8202: $datatable .= '<tr '.$css_class.'>'.
8203: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8204: for (my $k=0; $k<=$maxnum; $k++) {
8205: my $vpos = $k+1;
8206: my $selstr;
8207: if ($k == $maxnum) {
8208: $selstr = ' selected="selected" ';
8209: }
8210: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8211: }
8212: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 8213: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 8214: ' '.&mt('(new)').
8215: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 8216: &mt('Name displayed').':'.
1.160.6.40 raeburn 8217: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8218: '</tr>'."\n";
8219: $rownum ++;
1.141 raeburn 8220: }
1.43 raeburn 8221: }
8222: }
8223: $$rowtotal += $rownum;
8224: return $datatable;
8225: }
8226:
1.160.6.5 raeburn 8227: sub get_languages_hash {
8228: my %langchoices;
8229: foreach my $id (&Apache::loncommon::languageids()) {
8230: my $code = &Apache::loncommon::supportedlanguagecode($id);
8231: if ($code ne '') {
8232: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8233: }
8234: }
8235: return %langchoices;
8236: }
8237:
1.43 raeburn 8238: sub defaults_titles {
1.141 raeburn 8239: my ($dom) = @_;
1.43 raeburn 8240: my %titles = &Apache::lonlocal::texthash (
8241: 'auth_def' => 'Default authentication type',
8242: 'auth_arg_def' => 'Default authentication argument',
8243: 'lang_def' => 'Default language',
1.54 raeburn 8244: 'timezone_def' => 'Default timezone',
1.68 raeburn 8245: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8246: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 8247: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8248: 'intauth_check' => 'Check bcrypt cost if authenticated',
8249: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8250: );
1.141 raeburn 8251: if ($dom) {
8252: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8253: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8254: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8255: $protocol = 'http' if ($protocol ne 'https');
8256: if ($uint_dom) {
8257: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8258: $uint_dom);
8259: }
8260: }
1.43 raeburn 8261: return (\%titles);
8262: }
8263:
1.160.6.97 raeburn 8264: sub print_scantron {
8265: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8266: if ($position eq 'top') {
8267: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8268: } else {
8269: return &print_scantronconfig($dom,$settings,\$rowtotal);
8270: }
8271: }
8272:
8273: sub scantron_javascript {
8274: return <<"ENDSCRIPT";
8275:
8276: <script type="text/javascript">
8277: // <![CDATA[
8278:
8279: function toggleScantron(form) {
8280: var csvfieldset = new Array();
8281: if (document.getElementById('scantroncsv_cols')) {
8282: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8283: }
8284: if (document.getElementById('scantroncsv_options')) {
8285: csvfieldset.push(document.getElementById('scantroncsv_options'));
8286: }
8287: if (csvfieldset.length) {
8288: if (document.getElementById('scantronconfcsv')) {
8289: var scantroncsv = document.getElementById('scantronconfcsv');
8290: if (scantroncsv.checked) {
8291: for (var i=0; i<csvfieldset.length; i++) {
8292: csvfieldset[i].style.display = 'block';
8293: }
8294: } else {
8295: for (var i=0; i<csvfieldset.length; i++) {
8296: csvfieldset[i].style.display = 'none';
8297: }
8298: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8299: if (csvselects.length) {
8300: for (var j=0; j<csvselects.length; j++) {
8301: csvselects[j].selectedIndex = 0;
8302: }
8303: }
8304: }
8305: }
8306: }
8307: return;
8308: }
8309: // ]]>
8310: </script>
8311:
8312: ENDSCRIPT
8313:
8314: }
8315:
1.46 raeburn 8316: sub print_scantronformat {
8317: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8318: my $itemcount = 1;
1.60 raeburn 8319: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8320: %confhash);
1.46 raeburn 8321: my $switchserver = &check_switchserver($dom,$confname);
8322: my %lt = &Apache::lonlocal::texthash (
1.95 www 8323: default => 'Default bubblesheet format file error',
8324: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8325: );
8326: my %scantronfiles = (
8327: default => 'default.tab',
8328: custom => 'custom.tab',
8329: );
8330: foreach my $key (keys(%scantronfiles)) {
8331: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8332: .$scantronfiles{$key};
8333: }
8334: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8335: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8336: if (!$switchserver) {
8337: my $servadm = $r->dir_config('lonAdmEMail');
8338: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8339: if ($configuserok eq 'ok') {
8340: if ($author_ok eq 'ok') {
8341: my %legacyfile = (
1.160.6.97 raeburn 8342: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8343: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8344: );
8345: my %md5chk;
8346: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8347: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8348: chomp($md5chk{$type});
1.46 raeburn 8349: }
8350: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8351: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 8352: ($scantronurls{$type},my $error) =
1.46 raeburn 8353: &legacy_scantronformat($r,$dom,$confname,
8354: $type,$legacyfile{$type},
8355: $scantronurls{$type},
8356: $scantronfiles{$type});
1.60 raeburn 8357: if ($error ne '') {
8358: $error{$type} = $error;
8359: }
8360: }
8361: if (keys(%error) == 0) {
8362: $is_custom = 1;
1.160.6.97 raeburn 8363: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8364: $scantronurls{'custom'};
1.160.6.97 raeburn 8365: my $putresult =
1.60 raeburn 8366: &Apache::lonnet::put_dom('configuration',
8367: \%confhash,$dom);
8368: if ($putresult ne 'ok') {
1.160.6.97 raeburn 8369: $error{'custom'} =
1.60 raeburn 8370: '<span class="LC_error">'.
8371: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8372: }
1.46 raeburn 8373: }
8374: } else {
1.60 raeburn 8375: ($scantronurls{'default'},my $error) =
1.46 raeburn 8376: &legacy_scantronformat($r,$dom,$confname,
8377: 'default',$legacyfile{'default'},
8378: $scantronurls{'default'},
8379: $scantronfiles{'default'});
1.60 raeburn 8380: if ($error eq '') {
8381: $confhash{'scantron'}{'scantronformat'} = '';
8382: my $putresult =
8383: &Apache::lonnet::put_dom('configuration',
8384: \%confhash,$dom);
8385: if ($putresult ne 'ok') {
8386: $error{'default'} =
8387: '<span class="LC_error">'.
8388: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8389: }
8390: } else {
8391: $error{'default'} = $error;
8392: }
1.46 raeburn 8393: }
8394: }
8395: }
8396: } else {
1.95 www 8397: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8398: }
8399: }
8400: if (ref($settings) eq 'HASH') {
8401: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8402: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8403: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8404: $scantronurl = '';
8405: } else {
8406: $scantronurl = $settings->{'scantronformat'};
8407: }
8408: $is_custom = 1;
8409: } else {
8410: $scantronurl = $scantronurls{'default'};
8411: }
8412: } else {
1.60 raeburn 8413: if ($is_custom) {
8414: $scantronurl = $scantronurls{'custom'};
8415: } else {
8416: $scantronurl = $scantronurls{'default'};
8417: }
1.46 raeburn 8418: }
8419: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8420: $datatable .= '<tr'.$css_class.'>';
8421: if (!$is_custom) {
1.65 raeburn 8422: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8423: '<span class="LC_nobreak">';
1.46 raeburn 8424: if ($scantronurl) {
1.160.6.21 raeburn 8425: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8426: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8427: } else {
8428: $datatable = &mt('File unavailable for display');
8429: }
1.65 raeburn 8430: $datatable .= '</span></td>';
1.60 raeburn 8431: if (keys(%error) == 0) {
8432: $datatable .= '<td valign="bottom">';
8433: if (!$switchserver) {
8434: $datatable .= &mt('Upload:').'<br />';
8435: }
8436: } else {
8437: my $errorstr;
8438: foreach my $key (sort(keys(%error))) {
8439: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8440: }
8441: $datatable .= '<td>'.$errorstr;
8442: }
1.46 raeburn 8443: } else {
8444: if (keys(%error) > 0) {
8445: my $errorstr;
8446: foreach my $key (sort(keys(%error))) {
8447: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8448: }
1.60 raeburn 8449: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8450: } elsif ($scantronurl) {
1.160.6.26 raeburn 8451: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 8452: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8453: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 8454: $link.
8455: '<label><input type="checkbox" name="scantronformat_del"'.
8456: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8457: '<td><span class="LC_nobreak"> '.
8458: &mt('Replace:').'</span><br />';
1.46 raeburn 8459: }
8460: }
8461: if (keys(%error) == 0) {
8462: if ($switchserver) {
8463: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8464: } else {
1.65 raeburn 8465: $datatable .='<span class="LC_nobreak"> '.
8466: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8467: }
8468: }
8469: $datatable .= '</td></tr>';
8470: $$rowtotal ++;
8471: return $datatable;
8472: }
8473:
8474: sub legacy_scantronformat {
8475: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8476: my ($url,$error);
8477: my @statinfo = &Apache::lonnet::stat_file($newurl);
8478: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8479: (my $result,$url) =
8480: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8481: '','',$newfile);
8482: if ($result ne 'ok') {
1.130 raeburn 8483: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8484: }
8485: }
8486: return ($url,$error);
8487: }
1.43 raeburn 8488:
1.160.6.97 raeburn 8489: sub print_scantronconfig {
8490: my ($dom,$settings,$rowtotal) = @_;
8491: my $itemcount = 2;
8492: my $is_checked = ' checked="checked"';
8493: my %optionson = (
8494: hdr => ' checked="checked"',
8495: pad => ' checked="checked"',
8496: rem => ' checked="checked"',
8497: );
8498: my %optionsoff = (
8499: hdr => '',
8500: pad => '',
8501: rem => '',
8502: );
8503: my $currcsvsty = 'none';
8504: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8505: my @fields = &scantroncsv_fields();
8506: my %titles = &scantronconfig_titles();
8507: if (ref($settings) eq 'HASH') {
8508: if (ref($settings->{config}) eq 'HASH') {
8509: if ($settings->{config}->{dat}) {
8510: $checked{'dat'} = $is_checked;
8511: }
8512: if (ref($settings->{config}->{csv}) eq 'HASH') {
8513: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8514: %csvfields = %{$settings->{config}->{csv}->{fields}};
8515: if (keys(%csvfields) > 0) {
8516: $checked{'csv'} = $is_checked;
8517: $currcsvsty = 'block';
8518: }
8519: }
8520: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8521: %csvoptions = %{$settings->{config}->{csv}->{options}};
8522: foreach my $option (keys(%optionson)) {
8523: unless ($csvoptions{$option}) {
8524: $optionsoff{$option} = $optionson{$option};
8525: $optionson{$option} = '';
8526: }
8527: }
8528: }
8529: }
8530: } else {
8531: $checked{'dat'} = $is_checked;
8532: }
8533: } else {
8534: $checked{'dat'} = $is_checked;
8535: }
8536: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8537: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8538: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8539: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8540: foreach my $item ('dat','csv') {
8541: my $id;
8542: if ($item eq 'csv') {
8543: $id = 'id="scantronconfcsv" ';
8544: }
8545: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8546: $titles{$item}.'</label>'.(' 'x3);
8547: if ($item eq 'csv') {
8548: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8549: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8550: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8551: foreach my $col (@fields) {
8552: my $selnone;
8553: if ($csvfields{$col} eq '') {
8554: $selnone = ' selected="selected"';
8555: }
8556: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8557: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8558: '<option value=""'.$selnone.'></option>';
8559: for (my $i=0; $i<20; $i++) {
8560: my $shown = $i+1;
8561: my $sel;
8562: unless ($selnone) {
8563: if (exists($csvfields{$col})) {
8564: if ($csvfields{$col} == $i) {
8565: $sel = ' selected="selected"';
8566: }
8567: }
8568: }
8569: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8570: }
8571: $datatable .= '</select></td></tr>';
8572: }
8573: $datatable .= '</table></fieldset>'.
8574: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8575: '<legend>'.&mt('CSV Options').'</legend>';
8576: foreach my $option ('hdr','pad','rem') {
8577: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8578: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8579: &mt('Yes').'</label>'.(' 'x2)."\n".
8580: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8581: }
8582: $datatable .= '</fieldset>';
8583: $itemcount ++;
8584: }
8585: }
8586: $datatable .= '</td></tr>';
8587: $$rowtotal ++;
8588: return $datatable;
8589: }
8590:
8591: sub scantronconfig_titles {
8592: return &Apache::lonlocal::texthash(
8593: dat => 'Standard format (.dat)',
8594: csv => 'Comma separated values (.csv)',
8595: hdr => 'Remove first line in file (contains column titles)',
8596: pad => 'Prepend 0s to PaperID',
8597: rem => 'Remove leading spaces (except Question Response columns)',
8598: CODE => 'CODE',
8599: ID => 'Student ID',
8600: PaperID => 'Paper ID',
8601: FirstName => 'First Name',
8602: LastName => 'Last Name',
8603: FirstQuestion => 'First Question Response',
8604: Section => 'Section',
8605: );
8606: }
8607:
8608: sub scantroncsv_fields {
8609: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8610: }
8611:
1.49 raeburn 8612: sub print_coursecategories {
1.57 raeburn 8613: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8614: my $datatable;
8615: if ($position eq 'top') {
1.160.6.42 raeburn 8616: my (%checked);
8617: my @catitems = ('unauth','auth');
8618: my @cattypes = ('std','domonly','codesrch','none');
8619: $checked{'unauth'} = 'std';
8620: $checked{'auth'} = 'std';
8621: if (ref($settings) eq 'HASH') {
8622: foreach my $type (@cattypes) {
8623: if ($type eq $settings->{'unauth'}) {
8624: $checked{'unauth'} = $type;
8625: }
8626: if ($type eq $settings->{'auth'}) {
8627: $checked{'auth'} = $type;
8628: }
8629: }
8630: }
8631: my %lt = &Apache::lonlocal::texthash (
8632: unauth => 'Catalog type for unauthenticated users',
8633: auth => 'Catalog type for authenticated users',
8634: none => 'No catalog',
8635: std => 'Standard catalog',
8636: domonly => 'Domain-only catalog',
8637: codesrch => "Code search form",
8638: );
8639: my $itemcount = 0;
8640: foreach my $item (@catitems) {
8641: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8642: $datatable .= '<tr '.$css_class.'>'.
8643: '<td>'.$lt{$item}.'</td>'.
8644: '<td class="LC_right_item"><span class="LC_nobreak">';
8645: foreach my $type (@cattypes) {
8646: my $ischecked;
8647: if ($checked{$item} eq $type) {
8648: $ischecked=' checked="checked"';
8649: }
8650: $datatable .= '<label>'.
8651: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8652: ' />'.$lt{$type}.'</label> ';
8653: }
1.160.6.87 raeburn 8654: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8655: $itemcount ++;
8656: }
8657: $$rowtotal += $itemcount;
8658: } elsif ($position eq 'middle') {
1.57 raeburn 8659: my $toggle_cats_crs = ' ';
8660: my $toggle_cats_dom = ' checked="checked" ';
8661: my $can_cat_crs = ' ';
8662: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8663: my $toggle_catscomm_comm = ' ';
8664: my $toggle_catscomm_dom = ' checked="checked" ';
8665: my $can_catcomm_comm = ' ';
8666: my $can_catcomm_dom = ' checked="checked" ';
8667:
1.57 raeburn 8668: if (ref($settings) eq 'HASH') {
8669: if ($settings->{'togglecats'} eq 'crs') {
8670: $toggle_cats_crs = $toggle_cats_dom;
8671: $toggle_cats_dom = ' ';
8672: }
8673: if ($settings->{'categorize'} eq 'crs') {
8674: $can_cat_crs = $can_cat_dom;
8675: $can_cat_dom = ' ';
8676: }
1.120 raeburn 8677: if ($settings->{'togglecatscomm'} eq 'comm') {
8678: $toggle_catscomm_comm = $toggle_catscomm_dom;
8679: $toggle_catscomm_dom = ' ';
8680: }
8681: if ($settings->{'categorizecomm'} eq 'comm') {
8682: $can_catcomm_comm = $can_catcomm_dom;
8683: $can_catcomm_dom = ' ';
8684: }
1.57 raeburn 8685: }
8686: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8687: togglecats => 'Show/Hide a course in catalog',
8688: togglecatscomm => 'Show/Hide a community in catalog',
8689: categorize => 'Assign a category to a course',
8690: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8691: );
8692: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8693: dom => 'Set in Domain',
8694: crs => 'Set in Course',
8695: comm => 'Set in Community',
1.57 raeburn 8696: );
8697: $datatable = '<tr class="LC_odd_row">'.
8698: '<td>'.$title{'togglecats'}.'</td>'.
8699: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8700: '<input type="radio" name="togglecats"'.
8701: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8702: '<label><input type="radio" name="togglecats"'.
8703: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8704: '</tr><tr>'.
8705: '<td>'.$title{'categorize'}.'</td>'.
8706: '<td class="LC_right_item"><span class="LC_nobreak">'.
8707: '<label><input type="radio" name="categorize"'.
8708: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8709: '<label><input type="radio" name="categorize"'.
8710: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8711: '</tr><tr class="LC_odd_row">'.
8712: '<td>'.$title{'togglecatscomm'}.'</td>'.
8713: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8714: '<input type="radio" name="togglecatscomm"'.
8715: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8716: '<label><input type="radio" name="togglecatscomm"'.
8717: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8718: '</tr><tr>'.
8719: '<td>'.$title{'categorizecomm'}.'</td>'.
8720: '<td class="LC_right_item"><span class="LC_nobreak">'.
8721: '<label><input type="radio" name="categorizecomm"'.
8722: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8723: '<label><input type="radio" name="categorizecomm"'.
8724: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8725: '</tr>';
1.120 raeburn 8726: $$rowtotal += 4;
1.57 raeburn 8727: } else {
8728: my $css_class;
8729: my $itemcount = 1;
8730: my $cathash;
8731: if (ref($settings) eq 'HASH') {
8732: $cathash = $settings->{'cats'};
8733: }
8734: if (ref($cathash) eq 'HASH') {
8735: my (@cats,@trails,%allitems,%idx,@jsarray);
8736: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8737: \%allitems,\%idx,\@jsarray);
8738: my $maxdepth = scalar(@cats);
8739: my $colattrib = '';
8740: if ($maxdepth > 2) {
8741: $colattrib = ' colspan="2" ';
8742: }
8743: my @path;
8744: if (@cats > 0) {
8745: if (ref($cats[0]) eq 'ARRAY') {
8746: my $numtop = @{$cats[0]};
8747: my $maxnum = $numtop;
1.120 raeburn 8748: my %default_names = (
8749: instcode => &mt('Official courses'),
8750: communities => &mt('Communities'),
8751: );
8752:
8753: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8754: ($cathash->{'instcode::0'} eq '') ||
8755: (!grep(/^communities$/,@{$cats[0]})) ||
8756: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8757: $maxnum ++;
8758: }
8759: my $lastidx;
8760: for (my $i=0; $i<$numtop; $i++) {
8761: my $parent = $cats[0][$i];
8762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8763: my $item = &escape($parent).'::0';
8764: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8765: $lastidx = $idx{$item};
8766: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8767: .'<select name="'.$item.'"'.$chgstr.'>';
8768: for (my $k=0; $k<=$maxnum; $k++) {
8769: my $vpos = $k+1;
8770: my $selstr;
8771: if ($k == $i) {
8772: $selstr = ' selected="selected" ';
8773: }
8774: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8775: }
1.160.6.29 raeburn 8776: $datatable .= '</select></span></td><td>';
1.120 raeburn 8777: if ($parent eq 'instcode' || $parent eq 'communities') {
8778: $datatable .= '<span class="LC_nobreak">'
8779: .$default_names{$parent}.'</span>';
8780: if ($parent eq 'instcode') {
8781: $datatable .= '<br /><span class="LC_nobreak">('
8782: .&mt('with institutional codes')
8783: .')</span></td><td'.$colattrib.'>';
8784: } else {
8785: $datatable .= '<table><tr><td>';
8786: }
8787: $datatable .= '<span class="LC_nobreak">'
8788: .'<label><input type="radio" name="'
8789: .$parent.'" value="1" checked="checked" />'
8790: .&mt('Display').'</label>';
8791: if ($parent eq 'instcode') {
8792: $datatable .= ' ';
8793: } else {
8794: $datatable .= '</span></td></tr><tr><td>'
8795: .'<span class="LC_nobreak">';
8796: }
8797: $datatable .= '<label><input type="radio" name="'
8798: .$parent.'" value="0" />'
8799: .&mt('Do not display').'</label></span>';
8800: if ($parent eq 'communities') {
8801: $datatable .= '</td></tr></table>';
8802: }
8803: $datatable .= '</td>';
1.57 raeburn 8804: } else {
8805: $datatable .= $parent
1.160.6.29 raeburn 8806: .' <span class="LC_nobreak"><label>'
8807: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8808: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8809: }
8810: my $depth = 1;
8811: push(@path,$parent);
8812: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8813: pop(@path);
8814: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8815: $itemcount ++;
8816: }
1.48 raeburn 8817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8818: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8819: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8820: for (my $k=0; $k<=$maxnum; $k++) {
8821: my $vpos = $k+1;
8822: my $selstr;
1.57 raeburn 8823: if ($k == $numtop) {
1.48 raeburn 8824: $selstr = ' selected="selected" ';
8825: }
8826: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8827: }
1.59 bisitz 8828: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8829: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8830: .'</tr>'."\n";
1.48 raeburn 8831: $itemcount ++;
1.120 raeburn 8832: foreach my $default ('instcode','communities') {
8833: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8834: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8835: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8836: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8837: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8838: for (my $k=0; $k<=$maxnum; $k++) {
8839: my $vpos = $k+1;
8840: my $selstr;
8841: if ($k == $maxnum) {
8842: $selstr = ' selected="selected" ';
8843: }
8844: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8845: }
1.120 raeburn 8846: $datatable .= '</select></span></td>'.
8847: '<td><span class="LC_nobreak">'.
8848: $default_names{$default}.'</span>';
8849: if ($default eq 'instcode') {
8850: $datatable .= '<br /><span class="LC_nobreak">('
8851: .&mt('with institutional codes').')</span>';
8852: }
8853: $datatable .= '</td>'
8854: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8855: .&mt('Display').'</label> '
8856: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8857: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8858: }
8859: }
8860: }
1.57 raeburn 8861: } else {
8862: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8863: }
8864: } else {
1.160.6.87 raeburn 8865: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8866: .&initialize_categories($itemcount);
1.48 raeburn 8867: }
1.57 raeburn 8868: $$rowtotal += $itemcount;
1.48 raeburn 8869: }
8870: return $datatable;
8871: }
8872:
1.69 raeburn 8873: sub print_serverstatuses {
8874: my ($dom,$settings,$rowtotal) = @_;
8875: my $datatable;
8876: my @pages = &serverstatus_pages();
8877: my (%namedaccess,%machineaccess);
8878: foreach my $type (@pages) {
8879: $namedaccess{$type} = '';
8880: $machineaccess{$type}= '';
8881: }
8882: if (ref($settings) eq 'HASH') {
8883: foreach my $type (@pages) {
8884: if (exists($settings->{$type})) {
8885: if (ref($settings->{$type}) eq 'HASH') {
8886: foreach my $key (keys(%{$settings->{$type}})) {
8887: if ($key eq 'namedusers') {
8888: $namedaccess{$type} = $settings->{$type}->{$key};
8889: } elsif ($key eq 'machines') {
8890: $machineaccess{$type} = $settings->{$type}->{$key};
8891: }
8892: }
8893: }
8894: }
8895: }
8896: }
1.81 raeburn 8897: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8898: my $rownum = 0;
8899: my $css_class;
8900: foreach my $type (@pages) {
8901: $rownum ++;
8902: $css_class = $rownum%2?' class="LC_odd_row"':'';
8903: $datatable .= '<tr'.$css_class.'>'.
8904: '<td><span class="LC_nobreak">'.
8905: $titles->{$type}.'</span></td>'.
8906: '<td class="LC_left_item">'.
8907: '<input type="text" name="'.$type.'_namedusers" '.
8908: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8909: '<td class="LC_right_item">'.
8910: '<span class="LC_nobreak">'.
8911: '<input type="text" name="'.$type.'_machines" '.
8912: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8913: '</span></td></tr>'."\n";
1.69 raeburn 8914: }
8915: $$rowtotal += $rownum;
8916: return $datatable;
8917: }
8918:
8919: sub serverstatus_pages {
8920: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8921: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8922: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8923: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8924: }
8925:
1.160.6.40 raeburn 8926: sub defaults_javascript {
8927: my ($settings) = @_;
1.160.6.98 raeburn 8928: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8929: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8930: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8931: if ($maxnum eq '') {
8932: $maxnum = 0;
8933: }
8934: $maxnum ++;
1.160.6.51 raeburn 8935: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8936: return <<"ENDSCRIPT";
8937: <script type="text/javascript">
8938: // <![CDATA[
8939: function reorderTypes(form,caller) {
8940: var changedVal;
8941: $jstext
8942: var newpos = 'addinststatus_pos';
8943: var current = new Array;
8944: var maxh = $maxnum;
8945: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8946: var oldVal;
8947: if (caller == newpos) {
8948: changedVal = newitemVal;
8949: } else {
8950: var curritem = 'inststatus_pos_'+caller;
8951: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8952: current[newitemVal] = newpos;
8953: }
8954: for (var i=0; i<inststatuses.length; i++) {
8955: if (inststatuses[i] != caller) {
8956: var elementName = 'inststatus_pos_'+inststatuses[i];
8957: if (form.elements[elementName]) {
8958: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8959: current[currVal] = elementName;
8960: }
8961: }
8962: }
8963: for (var j=0; j<maxh; j++) {
8964: if (current[j] == undefined) {
8965: oldVal = j;
8966: }
8967: }
8968: if (oldVal < changedVal) {
8969: for (var k=oldVal+1; k<=changedVal ; k++) {
8970: var elementName = current[k];
8971: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8972: }
8973: } else {
8974: for (var k=changedVal; k<oldVal; k++) {
8975: var elementName = current[k];
8976: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8977: }
8978: }
8979: return;
8980: }
8981:
8982: // ]]>
8983: </script>
8984:
8985: ENDSCRIPT
8986: }
8987: }
8988:
1.160.6.98 raeburn 8989: sub passwords_javascript {
1.160.6.99 raeburn 8990: my %intalert = &Apache::lonlocal::texthash (
8991: 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.',
8992: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8993: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8994: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8995: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8996: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8997: );
8998: &js_escape(\%intalert);
8999: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 9000: my $intauthjs = <<"ENDSCRIPT";
9001:
9002: function warnIntAuth(field) {
9003: if (field.name == 'intauth_check') {
9004: if (field.value == '2') {
1.160.6.99 raeburn 9005: alert('$intalert{authcheck}');
1.160.6.98 raeburn 9006: }
9007: }
9008: if (field.name == 'intauth_cost') {
9009: field.value.replace(/\s/g,'');
9010: if (field.value != '') {
9011: var regexdigit=/^\\d+\$/;
9012: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 9013: alert('$intalert{authcost}');
9014: }
9015: }
9016: }
9017: return;
9018: }
9019:
9020: function warnIntPass(field) {
9021: field.value.replace(/^\s+/,'');
9022: field.value.replace(/\s+\$/,'');
9023: var regexdigit=/^\\d+\$/;
9024: if (field.name == 'passwords_min') {
9025: if (field.value == '') {
9026: alert('$intalert{passmin}');
9027: field.value = '$defmin';
9028: } else {
9029: if (!regexdigit.test(field.value)) {
9030: alert('$intalert{passmin}');
9031: field.value = '$defmin';
9032: }
9033: var minval = parseInt(field.value,10);
9034: if (minval < $defmin) {
9035: alert('$intalert{passmin}');
9036: field.value = '$defmin';
9037: }
9038: }
9039: } else {
9040: if (field.value == '0') {
9041: field.value = '';
9042: }
9043: if (field.value != '') {
9044: if (field.name == 'passwords_expire') {
9045: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
9046: if (!regexpposnum.test(field.value)) {
9047: alert('$intalert{passexp}');
9048: field.value = '';
9049: } else {
9050: var expval = parseFloat(field.value);
9051: if (expval == 0) {
9052: alert('$intalert{passexp}');
9053: field.value = '';
9054: }
9055: }
9056: } else {
9057: if (!regexdigit.test(field.value)) {
9058: if (field.name == 'passwords_max') {
9059: alert('$intalert{passmax}');
9060: } else {
9061: if (field.name == 'passwords_numsaved') {
9062: alert('$intalert{passnum}');
9063: }
9064: }
1.160.6.104 raeburn 9065: field.value = '';
1.160.6.99 raeburn 9066: }
1.160.6.98 raeburn 9067: }
9068: }
9069: }
9070: return;
9071: }
9072:
9073: ENDSCRIPT
9074: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9075: }
9076:
1.49 raeburn 9077: sub coursecategories_javascript {
9078: my ($settings) = @_;
1.57 raeburn 9079: my ($output,$jstext,$cathash);
1.49 raeburn 9080: if (ref($settings) eq 'HASH') {
1.57 raeburn 9081: $cathash = $settings->{'cats'};
9082: }
9083: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9084: my (@cats,@jsarray,%idx);
1.57 raeburn 9085: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9086: if (@jsarray > 0) {
9087: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9088: for (my $i=0; $i<@jsarray; $i++) {
9089: if (ref($jsarray[$i]) eq 'ARRAY') {
9090: my $catstr = join('","',@{$jsarray[$i]});
9091: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9092: }
9093: }
9094: }
9095: } else {
9096: $jstext = ' var categories = Array(1);'."\n".
9097: ' categories[0] = Array("instcode_pos");'."\n";
9098: }
1.160.6.42 raeburn 9099: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9100: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 9101: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9102: &js_escape(\$instcode_reserved);
9103: &js_escape(\$communities_reserved);
9104: &js_escape(\$choose_again);
1.49 raeburn 9105: $output = <<"ENDSCRIPT";
9106: <script type="text/javascript">
1.109 raeburn 9107: // <![CDATA[
1.49 raeburn 9108: function reorderCats(form,parent,item,idx) {
9109: var changedVal;
9110: $jstext
9111: var newpos = 'addcategory_pos';
9112: if (parent == '') {
9113: var has_instcode = 0;
9114: var maxtop = categories[idx].length;
9115: for (var j=0; j<maxtop; j++) {
9116: if (categories[idx][j] == 'instcode::0') {
9117: has_instcode == 1;
9118: }
9119: }
9120: if (has_instcode == 0) {
9121: categories[idx][maxtop] = 'instcode_pos';
9122: }
9123: } else {
9124: newpos += '_'+parent;
9125: }
9126: var maxh = 1 + categories[idx].length;
9127: var current = new Array;
9128: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9129: if (item == newpos) {
9130: changedVal = newitemVal;
9131: } else {
9132: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9133: current[newitemVal] = newpos;
9134: }
9135: for (var i=0; i<categories[idx].length; i++) {
9136: var elementName = categories[idx][i];
9137: if (elementName != item) {
9138: if (form.elements[elementName]) {
9139: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9140: current[currVal] = elementName;
9141: }
9142: }
9143: }
9144: var oldVal;
9145: for (var j=0; j<maxh; j++) {
9146: if (current[j] == undefined) {
9147: oldVal = j;
9148: }
9149: }
9150: if (oldVal < changedVal) {
9151: for (var k=oldVal+1; k<=changedVal ; k++) {
9152: var elementName = current[k];
9153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9154: }
9155: } else {
9156: for (var k=changedVal; k<oldVal; k++) {
9157: var elementName = current[k];
9158: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9159: }
9160: }
9161: return;
9162: }
1.120 raeburn 9163:
9164: function categoryCheck(form) {
9165: if (form.elements['addcategory_name'].value == 'instcode') {
9166: alert('$instcode_reserved\\n$choose_again');
9167: return false;
9168: }
9169: if (form.elements['addcategory_name'].value == 'communities') {
9170: alert('$communities_reserved\\n$choose_again');
9171: return false;
9172: }
9173: return true;
9174: }
9175:
1.109 raeburn 9176: // ]]>
1.49 raeburn 9177: </script>
9178:
9179: ENDSCRIPT
9180: return $output;
9181: }
9182:
1.48 raeburn 9183: sub initialize_categories {
9184: my ($itemcount) = @_;
1.120 raeburn 9185: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 9186: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 9187: instcode => 'Official courses (with institutional codes)',
9188: communities => 'Communities',
9189: );
9190: my $select0 = ' selected="selected"';
9191: my $select1 = '';
9192: foreach my $default ('instcode','communities') {
9193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 9194: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 9195: if ($default eq 'communities') {
9196: $select1 = $select0;
9197: $select0 = '';
9198: }
9199: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9200: .'<select name="'.$default.'_pos">'
9201: .'<option value="0"'.$select0.'>1</option>'
9202: .'<option value="1"'.$select1.'>2</option>'
9203: .'<option value="2">3</option></select> '
9204: .$default_names{$default}
9205: .'</span></td><td><span class="LC_nobreak">'
9206: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9207: .&mt('Display').'</label> <label>'
9208: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9209: .'</label></span></td></tr>';
1.120 raeburn 9210: $itemcount ++;
9211: }
1.48 raeburn 9212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9213: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9214: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9215: .'<select name="addcategory_pos"'.$chgstr.'>'
9216: .'<option value="0">1</option>'
9217: .'<option value="1">2</option>'
9218: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 9219: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 9220: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9221: .'</td></tr>';
1.48 raeburn 9222: return $datatable;
9223: }
9224:
9225: sub build_category_rows {
1.49 raeburn 9226: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9227: my ($text,$name,$item,$chgstr);
1.48 raeburn 9228: if (ref($cats) eq 'ARRAY') {
9229: my $maxdepth = scalar(@{$cats});
9230: if (ref($cats->[$depth]) eq 'HASH') {
9231: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9232: my $numchildren = @{$cats->[$depth]{$parent}};
9233: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 9234: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9235: my ($idxnum,$parent_name,$parent_item);
9236: my $higher = $depth - 1;
9237: if ($higher == 0) {
9238: $parent_name = &escape($parent).'::'.$higher;
9239: } else {
9240: if (ref($path) eq 'ARRAY') {
9241: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9242: }
9243: }
9244: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9245: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9246: if ($j < $numchildren) {
1.48 raeburn 9247: $name = $cats->[$depth]{$parent}[$j];
9248: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9249: $idxnum = $idx->{$item};
9250: } else {
9251: $name = $parent_name;
9252: $item = $parent_item;
1.48 raeburn 9253: }
1.49 raeburn 9254: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9255: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9256: for (my $i=0; $i<=$numchildren; $i++) {
9257: my $vpos = $i+1;
9258: my $selstr;
9259: if ($j == $i) {
9260: $selstr = ' selected="selected" ';
9261: }
9262: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9263: }
9264: $text .= '</select> ';
9265: if ($j < $numchildren) {
9266: my $deeper = $depth+1;
9267: $text .= $name.' '
9268: .'<label><input type="checkbox" name="deletecategory" value="'
9269: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9270: if(ref($path) eq 'ARRAY') {
9271: push(@{$path},$name);
1.49 raeburn 9272: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9273: pop(@{$path});
9274: }
9275: } else {
1.160.6.87 raeburn 9276: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9277: if ($j == $numchildren) {
9278: $text .= $name;
9279: } else {
9280: $text .= $item;
9281: }
9282: $text .= '" value="" />';
9283: }
9284: $text .= '</td></tr>';
9285: }
9286: $text .= '</table></td>';
9287: } else {
9288: my $higher = $depth-1;
9289: if ($higher == 0) {
9290: $name = &escape($parent).'::'.$higher;
9291: } else {
9292: if (ref($path) eq 'ARRAY') {
9293: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9294: }
9295: }
9296: my $colspan;
9297: if ($parent ne 'instcode') {
9298: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 9299: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9300: }
9301: }
9302: }
9303: }
9304: return $text;
9305: }
9306:
1.33 raeburn 9307: sub modifiable_userdata_row {
1.160.6.93 raeburn 9308: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9309: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 9310: my ($role,$rolename,$statustype);
9311: $role = $item;
1.160.6.34 raeburn 9312: if ($context eq 'cancreate') {
1.160.6.93 raeburn 9313: if ($item =~ /^(emailusername)_(.+)$/) {
9314: $role = $1;
9315: $statustype = $2;
1.160.6.35 raeburn 9316: if (ref($usertypes) eq 'HASH') {
9317: if ($usertypes->{$statustype}) {
9318: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9319: } else {
9320: $rolename = &mt('Data provided by user');
9321: }
9322: }
1.160.6.34 raeburn 9323: }
9324: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9325: if (ref($usertypes) eq 'HASH') {
9326: $rolename = $usertypes->{$role};
9327: } else {
9328: $rolename = $role;
9329: }
1.33 raeburn 9330: } else {
1.63 raeburn 9331: if ($role eq 'cr') {
9332: $rolename = &mt('Custom role');
9333: } else {
9334: $rolename = &Apache::lonnet::plaintext($role);
9335: }
1.33 raeburn 9336: }
1.160.6.34 raeburn 9337: my (@fields,%fieldtitles);
9338: if (ref($fieldsref) eq 'ARRAY') {
9339: @fields = @{$fieldsref};
9340: } else {
9341: @fields = ('lastname','firstname','middlename','generation',
9342: 'permanentemail','id');
9343: }
9344: if ((ref($titlesref) eq 'HASH')) {
9345: %fieldtitles = %{$titlesref};
9346: } else {
9347: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9348: }
1.33 raeburn 9349: my $output;
1.160.6.93 raeburn 9350: my $css_class;
9351: if ($rowcount%2) {
9352: $css_class = 'LC_odd_row';
9353: }
9354: if ($customcss) {
9355: $css_class .= " $customcss";
9356: }
9357: $css_class =~ s/^\s+//;
9358: if ($css_class) {
9359: $css_class = ' class="'.$css_class.'"';
9360: }
9361: if ($rowstyle) {
9362: $css_class .= ' style="'.$rowstyle.'"';
9363: }
9364: if ($rowid) {
9365: $rowid = ' id="'.$rowid.'"';
9366: }
9367:
9368: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9369: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9370: '<td class="LC_left_item" colspan="2"><table>';
9371: my $rem;
9372: my %checks;
9373: if (ref($settings) eq 'HASH') {
9374: if (ref($settings->{$context}) eq 'HASH') {
9375: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 9376: my $hashref = $settings->{$context}->{$role};
9377: if ($role eq 'emailusername') {
9378: if ($statustype) {
9379: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9380: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 9381: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 9382: foreach my $field (@fields) {
9383: if ($hashref->{$field}) {
9384: $checks{$field} = $hashref->{$field};
9385: }
9386: }
9387: }
9388: }
9389: }
9390: } else {
9391: if (ref($hashref) eq 'HASH') {
9392: foreach my $field (@fields) {
9393: if ($hashref->{$field}) {
9394: $checks{$field} = ' checked="checked" ';
9395: }
9396: }
1.33 raeburn 9397: }
9398: }
9399: }
9400: }
9401: }
1.160.6.93 raeburn 9402:
9403: my $total = scalar(@fields);
9404: for (my $i=0; $i<$total; $i++) {
9405: $rem = $i%($numinrow);
1.33 raeburn 9406: if ($rem == 0) {
9407: if ($i > 0) {
9408: $output .= '</tr>';
9409: }
9410: $output .= '<tr>';
9411: }
9412: my $check = ' ';
1.160.6.35 raeburn 9413: unless ($role eq 'emailusername') {
9414: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 9415: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 9416: } else {
9417: if ($role eq 'st') {
9418: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 9419: $check = ' checked="checked" ';
1.160.6.35 raeburn 9420: }
1.33 raeburn 9421: }
9422: }
9423: }
9424: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 9425: '<span class="LC_nobreak">';
9426: if ($role eq 'emailusername') {
9427: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9428: $checks{$fields[$i]} = 'omit';
9429: }
9430: foreach my $option ('required','optional','omit') {
9431: my $checked='';
9432: if ($checks{$fields[$i]} eq $option) {
9433: $checked='checked="checked" ';
9434: }
9435: $output .= '<label>'.
9436: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9437: &mt($option).'</label>'.(' ' x2);
9438: }
9439: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9440: } else {
9441: $output .= '<label>'.
9442: '<input type="checkbox" name="canmodify_'.$role.'" '.
9443: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9444: '</label>';
9445: }
9446: $output .= '</span></td>';
1.33 raeburn 9447: }
1.160.6.93 raeburn 9448: $rem = $total%$numinrow;
9449: my $colsleft;
9450: if ($rem) {
9451: $colsleft = $numinrow - $rem;
9452: }
9453: if ($colsleft > 1) {
1.33 raeburn 9454: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9455: ' </td>';
9456: } elsif ($colsleft == 1) {
9457: $output .= '<td class="LC_left_item"> </td>';
9458: }
9459: $output .= '</tr></table></td></tr>';
9460: return $output;
9461: }
1.28 raeburn 9462:
1.93 raeburn 9463: sub insttypes_row {
1.160.6.93 raeburn 9464: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9465: $customcss,$rowstyle) = @_;
1.93 raeburn 9466: my %lt = &Apache::lonlocal::texthash (
9467: cansearch => 'Users allowed to search',
9468: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9469: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 9470: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 9471: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9472: );
9473: my $showdom;
9474: if ($context eq 'cansearch') {
9475: $showdom = ' ('.$dom.')';
9476: }
1.160.6.5 raeburn 9477: my $class = 'LC_left_item';
9478: if ($context eq 'statustocreate') {
9479: $class = 'LC_right_item';
9480: }
1.160.6.93 raeburn 9481: my $css_class;
9482: if ($$rowtotal%2) {
9483: $css_class = 'LC_odd_row';
9484: }
9485: if ($customcss) {
9486: $css_class .= ' '.$customcss;
9487: }
9488: $css_class =~ s/^\s+//;
9489: if ($css_class) {
9490: $css_class = ' class="'.$css_class.'"';
9491: }
9492: if ($rowstyle) {
9493: $css_class .= ' style="'.$rowstyle.'"';
9494: }
9495: if ($onclick) {
9496: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 9497: }
9498: my $output = '<tr'.$css_class.'>'.
9499: '<td>'.$lt{$context}.$showdom.
9500: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9501: my $rem;
9502: if (ref($types) eq 'ARRAY') {
9503: for (my $i=0; $i<@{$types}; $i++) {
9504: if (defined($usertypes->{$types->[$i]})) {
9505: my $rem = $i%($numinrow);
9506: if ($rem == 0) {
9507: if ($i > 0) {
9508: $output .= '</tr>';
9509: }
9510: $output .= '<tr>';
1.23 raeburn 9511: }
1.26 raeburn 9512: my $check = ' ';
1.99 raeburn 9513: if (ref($settings) eq 'HASH') {
9514: if (ref($settings->{$context}) eq 'ARRAY') {
9515: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9516: $check = ' checked="checked" ';
9517: }
1.160.6.101 raeburn 9518: } elsif (ref($settings->{$context}) eq 'HASH') {
9519: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9520: $check = ' checked="checked" ';
9521: }
1.99 raeburn 9522: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9523: $check = ' checked="checked" ';
9524: }
1.23 raeburn 9525: }
1.26 raeburn 9526: $output .= '<td class="LC_left_item">'.
9527: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9528: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9529: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9530: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9531: }
9532: }
1.26 raeburn 9533: $rem = @{$types}%($numinrow);
1.23 raeburn 9534: }
9535: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9536: if ($context eq 'overrides') {
9537: if ($colsleft > 1) {
9538: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9539: } else {
9540: $output .= '<td class="LC_left_item">';
9541: }
9542: $output .= ' ';
1.23 raeburn 9543: } else {
1.160.6.101 raeburn 9544: if ($rem == 0) {
9545: $output .= '<tr>';
9546: }
9547: if ($colsleft > 1) {
9548: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9549: } else {
9550: $output .= '<td class="LC_left_item">';
9551: }
9552: my $defcheck = ' ';
9553: if (ref($settings) eq 'HASH') {
9554: if (ref($settings->{$context}) eq 'ARRAY') {
9555: if (grep(/^default$/,@{$settings->{$context}})) {
9556: $defcheck = ' checked="checked" ';
9557: }
9558: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9559: $defcheck = ' checked="checked" ';
9560: }
1.26 raeburn 9561: }
1.160.6.101 raeburn 9562: $output .= '<span class="LC_nobreak"><label>'.
9563: '<input type="checkbox" name="'.$context.'" '.
9564: 'value="default"'.$defcheck.$onclick.' />'.
9565: $othertitle.'</label></span>';
1.23 raeburn 9566: }
1.160.6.101 raeburn 9567: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9568: return $output;
1.23 raeburn 9569: }
9570:
9571: sub sorted_searchtitles {
9572: my %searchtitles = &Apache::lonlocal::texthash(
9573: 'uname' => 'username',
9574: 'lastname' => 'last name',
9575: 'lastfirst' => 'last name, first name',
9576: );
9577: my @titleorder = ('uname','lastname','lastfirst');
9578: return (\%searchtitles,\@titleorder);
9579: }
9580:
1.25 raeburn 9581: sub sorted_searchtypes {
9582: my %srchtypes_desc = (
9583: exact => 'is exact match',
9584: contains => 'contains ..',
9585: begins => 'begins with ..',
9586: );
9587: my @srchtypeorder = ('exact','begins','contains');
9588: return (\%srchtypes_desc,\@srchtypeorder);
9589: }
9590:
1.3 raeburn 9591: sub usertype_update_row {
9592: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9593: my $datatable;
9594: my $numinrow = 4;
9595: foreach my $type (@{$types}) {
9596: if (defined($usertypes->{$type})) {
9597: $$rownums ++;
9598: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9599: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9600: '</td><td class="LC_left_item"><table>';
9601: for (my $i=0; $i<@{$fields}; $i++) {
9602: my $rem = $i%($numinrow);
9603: if ($rem == 0) {
9604: if ($i > 0) {
9605: $datatable .= '</tr>';
9606: }
9607: $datatable .= '<tr>';
9608: }
9609: my $check = ' ';
1.39 raeburn 9610: if (ref($settings) eq 'HASH') {
9611: if (ref($settings->{'fields'}) eq 'HASH') {
9612: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9613: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9614: $check = ' checked="checked" ';
9615: }
1.3 raeburn 9616: }
9617: }
9618: }
9619:
9620: if ($i == @{$fields}-1) {
9621: my $colsleft = $numinrow - $rem;
9622: if ($colsleft > 1) {
9623: $datatable .= '<td colspan="'.$colsleft.'">';
9624: } else {
9625: $datatable .= '<td>';
9626: }
9627: } else {
9628: $datatable .= '<td>';
9629: }
1.8 raeburn 9630: $datatable .= '<span class="LC_nobreak"><label>'.
9631: '<input type="checkbox" name="updateable_'.$type.
9632: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9633: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9634: }
9635: $datatable .= '</tr></table></td></tr>';
9636: }
9637: }
9638: return $datatable;
1.1 raeburn 9639: }
9640:
9641: sub modify_login {
1.160.6.24 raeburn 9642: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9643: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9644: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9645: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9646: %title = ( coursecatalog => 'Display course catalog',
9647: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9648: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9649: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9650: loginheader => 'Log-in box header',
9651: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9652: @offon = ('off','on');
1.112 raeburn 9653: if (ref($domconfig{login}) eq 'HASH') {
9654: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9655: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9656: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9657: }
9658: }
1.160.6.113 raeburn 9659: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9660: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9661: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9662: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9663: $saml{$lonhost} = 1;
9664: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9665: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9666: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9667: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9668: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9669: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9670: }
9671: }
9672: }
1.112 raeburn 9673: }
1.9 raeburn 9674: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9675: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9676: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9677: foreach my $item (@toggles) {
9678: $loginhash{login}{$item} = $env{'form.'.$item};
9679: }
1.41 raeburn 9680: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9681: if (ref($colchanges{'login'}) eq 'HASH') {
9682: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9683: \%loginhash);
9684: }
1.110 raeburn 9685:
1.149 raeburn 9686: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9687: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9688: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9689: if (keys(%servers) > 1) {
9690: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9691: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9692: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9693: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9694: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9695: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9696: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9697: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9698: $changes{'loginvia'}{$lonhost} = 1;
9699: } else {
9700: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9701: $changes{'loginvia'}{$lonhost} = 1;
9702: }
9703: } else {
9704: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9705: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9706: $changes{'loginvia'}{$lonhost} = 1;
9707: }
9708: }
9709: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9710: foreach my $item (@loginvia_attribs) {
9711: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9712: }
9713: } else {
9714: foreach my $item (@loginvia_attribs) {
9715: my $new = $env{'form.'.$lonhost.'_'.$item};
9716: if (($item eq 'serverpath') && ($new eq 'custom')) {
9717: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9718: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9719: $new = '/';
9720: }
9721: }
9722: if (($item eq 'custompath') &&
9723: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9724: $new = '';
9725: }
9726: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9727: $changes{'loginvia'}{$lonhost} = 1;
9728: }
9729: if ($item eq 'exempt') {
1.160.6.56 raeburn 9730: $new = &check_exempt_addresses($new);
1.128 raeburn 9731: }
9732: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9733: }
9734: }
1.112 raeburn 9735: } else {
1.128 raeburn 9736: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9737: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9738: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9739: foreach my $item (@loginvia_attribs) {
9740: my $new = $env{'form.'.$lonhost.'_'.$item};
9741: if (($item eq 'serverpath') && ($new eq 'custom')) {
9742: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9743: $new = '/';
9744: }
9745: }
9746: if (($item eq 'custompath') &&
9747: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9748: $new = '';
9749: }
9750: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9751: }
1.110 raeburn 9752: }
9753: }
9754: }
9755: }
1.119 raeburn 9756:
1.160.6.5 raeburn 9757: my $servadm = $r->dir_config('lonAdmEMail');
9758: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9759: if (ref($domconfig{'login'}) eq 'HASH') {
9760: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9761: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9762: if ($lang eq 'nolang') {
9763: push(@currlangs,$lang);
9764: } elsif (defined($langchoices{$lang})) {
9765: push(@currlangs,$lang);
9766: } else {
9767: next;
9768: }
9769: }
9770: }
9771: }
9772: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9773: if (@currlangs > 0) {
9774: foreach my $lang (@currlangs) {
9775: if (grep(/^\Q$lang\E$/,@delurls)) {
9776: $changes{'helpurl'}{$lang} = 1;
9777: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9778: $changes{'helpurl'}{$lang} = 1;
9779: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9780: push(@newlangs,$lang);
9781: } else {
9782: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9783: }
9784: }
9785: }
9786: unless (grep(/^nolang$/,@currlangs)) {
9787: if ($env{'form.loginhelpurl_nolang.filename'}) {
9788: $changes{'helpurl'}{'nolang'} = 1;
9789: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9790: push(@newlangs,'nolang');
9791: }
9792: }
9793: if ($env{'form.loginhelpurl_add_lang'}) {
9794: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9795: ($env{'form.loginhelpurl_add_file.filename'})) {
9796: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9797: $addedfile = $env{'form.loginhelpurl_add_lang'};
9798: }
9799: }
9800: if ((@newlangs > 0) || ($addedfile)) {
9801: my $error;
9802: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9803: if ($configuserok eq 'ok') {
9804: if ($switchserver) {
9805: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9806: } elsif ($author_ok eq 'ok') {
9807: my @allnew = @newlangs;
9808: if ($addedfile ne '') {
9809: push(@allnew,$addedfile);
9810: }
9811: foreach my $lang (@allnew) {
9812: my $formelem = 'loginhelpurl_'.$lang;
9813: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9814: $formelem = 'loginhelpurl_add_file';
9815: }
9816: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9817: "help/$lang",'','',$newfile{$lang});
9818: if ($result eq 'ok') {
9819: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9820: $changes{'helpurl'}{$lang} = 1;
9821: } else {
9822: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9823: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9824: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9825: (!grep(/^\Q$lang\E$/,@delurls))) {
9826: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9827: }
9828: }
9829: }
9830: } else {
9831: $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);
9832: }
9833: } else {
9834: $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);
9835: }
9836: if ($error) {
9837: &Apache::lonnet::logthis($error);
9838: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9839: }
9840: }
1.160.6.56 raeburn 9841:
9842: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9843: if (ref($domconfig{'login'}) eq 'HASH') {
9844: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9845: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9846: if ($domservers{$lonhost}) {
9847: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9848: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9849: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9850: }
9851: }
9852: }
9853: }
9854: }
9855: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9856: foreach my $lonhost (sort(keys(%domservers))) {
9857: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9858: $changes{'headtag'}{$lonhost} = 1;
9859: } else {
9860: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9861: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9862: }
9863: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9864: push(@newhosts,$lonhost);
9865: } elsif ($currheadtagurls{$lonhost}) {
9866: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9867: if ($currexempt{$lonhost}) {
9868: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9869: $changes{'headtag'}{$lonhost} = 1;
9870: }
9871: } elsif ($possexempt{$lonhost}) {
9872: $changes{'headtag'}{$lonhost} = 1;
9873: }
9874: if ($possexempt{$lonhost}) {
9875: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9876: }
9877: }
9878: }
9879: }
9880: if (@newhosts) {
9881: my $error;
9882: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9883: if ($configuserok eq 'ok') {
9884: if ($switchserver) {
9885: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9886: } elsif ($author_ok eq 'ok') {
9887: foreach my $lonhost (@newhosts) {
9888: my $formelem = 'loginheadtag_'.$lonhost;
9889: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9890: "login/headtag/$lonhost",'','',
9891: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9892: if ($result eq 'ok') {
1.160.6.113 raeburn 9893: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9894: $changes{'headtag'}{$lonhost} = 1;
9895: if ($possexempt{$lonhost}) {
9896: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9897: }
9898: } else {
9899: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9900: $newheadtagurls{$lonhost},$result);
9901: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9902: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9903: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9904: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9905: }
9906: }
9907: }
9908: } else {
9909: $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);
9910: }
9911: } else {
9912: $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);
9913: }
9914: if ($error) {
9915: &Apache::lonnet::logthis($error);
9916: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9917: }
9918: }
9919: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9920: my @newsamlimgs;
9921: foreach my $lonhost (keys(%domservers)) {
9922: if ($env{'form.saml_'.$lonhost}) {
9923: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9924: push(@newsamlimgs,$lonhost);
9925: }
9926: foreach my $item ('text','alt','url','title','notsso') {
9927: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9928: }
9929: if ($saml{$lonhost}) {
9930: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9931: #FIXME Need to obsolete published image
9932: delete($currsaml{$lonhost}{'img'});
9933: $changes{'saml'}{$lonhost} = 1;
9934: }
9935: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9936: $changes{'saml'}{$lonhost} = 1;
9937: }
9938: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9939: $changes{'saml'}{$lonhost} = 1;
9940: }
9941: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9942: $changes{'saml'}{$lonhost} = 1;
9943: }
9944: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9945: $changes{'saml'}{$lonhost} = 1;
9946: }
9947: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9948: $changes{'saml'}{$lonhost} = 1;
9949: }
9950: } else {
9951: $changes{'saml'}{$lonhost} = 1;
9952: }
9953: foreach my $item ('text','alt','url','title','notsso') {
9954: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9955: }
9956: } else {
9957: if ($saml{$lonhost}) {
9958: $changes{'saml'}{$lonhost} = 1;
9959: delete($currsaml{$lonhost});
9960: }
9961: }
9962: }
9963: foreach my $posshost (keys(%currsaml)) {
9964: unless (exists($domservers{$posshost})) {
9965: delete($currsaml{$posshost});
9966: }
9967: }
9968: %{$loginhash{'login'}{'saml'}} = %currsaml;
9969: if (@newsamlimgs) {
9970: my $error;
9971: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9972: if ($configuserok eq 'ok') {
9973: if ($switchserver) {
9974: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9975: } elsif ($author_ok eq 'ok') {
9976: foreach my $lonhost (@newsamlimgs) {
9977: my $formelem = 'saml_img_'.$lonhost;
9978: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9979: "login/saml/$lonhost",'','',
9980: $env{'form.saml_img_'.$lonhost.'.filename'});
9981: if ($result eq 'ok') {
9982: $currsaml{$lonhost}{'img'} = $imgurl;
9983: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9984: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9985: } else {
1.160.6.113 raeburn 9986: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9987: $lonhost,$result);
1.160.6.56 raeburn 9988: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9989: }
9990: }
9991: } else {
1.160.6.113 raeburn 9992: $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 9993: }
9994: } else {
1.160.6.113 raeburn 9995: $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 9996: }
9997: if ($error) {
9998: &Apache::lonnet::logthis($error);
9999: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10000: }
10001: }
1.160.6.5 raeburn 10002: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
10003:
10004: my $defaulthelpfile = '/adm/loginproblems.html';
10005: my $defaulttext = &mt('Default in use');
10006:
1.1 raeburn 10007: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10008: $dom);
10009: if ($putresult eq 'ok') {
1.160.6.14 raeburn 10010: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10011: my %defaultchecked = (
10012: 'coursecatalog' => 'on',
1.160.6.14 raeburn 10013: 'helpdesk' => 'on',
1.42 raeburn 10014: 'adminmail' => 'off',
1.43 raeburn 10015: 'newuser' => 'off',
1.42 raeburn 10016: );
1.55 raeburn 10017: if (ref($domconfig{'login'}) eq 'HASH') {
10018: foreach my $item (@toggles) {
10019: if ($defaultchecked{$item} eq 'on') {
10020: if (($domconfig{'login'}{$item} eq '0') &&
10021: ($env{'form.'.$item} eq '1')) {
10022: $changes{$item} = 1;
10023: } elsif (($domconfig{'login'}{$item} eq '' ||
10024: $domconfig{'login'}{$item} eq '1') &&
10025: ($env{'form.'.$item} eq '0')) {
10026: $changes{$item} = 1;
10027: }
10028: } elsif ($defaultchecked{$item} eq 'off') {
10029: if (($domconfig{'login'}{$item} eq '1') &&
10030: ($env{'form.'.$item} eq '0')) {
10031: $changes{$item} = 1;
10032: } elsif (($domconfig{'login'}{$item} eq '' ||
10033: $domconfig{'login'}{$item} eq '0') &&
10034: ($env{'form.'.$item} eq '1')) {
10035: $changes{$item} = 1;
10036: }
1.42 raeburn 10037: }
10038: }
1.41 raeburn 10039: }
1.6 raeburn 10040: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10041: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 10042: if (exists($changes{'saml'})) {
10043: my $hostid_in_use;
10044: my @hosts = &Apache::lonnet::current_machine_ids();
10045: if (@hosts > 1) {
10046: foreach my $hostid (@hosts) {
10047: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10048: $hostid_in_use = $hostid;
10049: last;
10050: }
10051: }
10052: } else {
10053: $hostid_in_use = $r->dir_config('lonHostID');
10054: }
10055: if (($hostid_in_use) &&
10056: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10057: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10058: }
10059: if (ref($lastactref) eq 'HASH') {
10060: if (ref($changes{'saml'}) eq 'HASH') {
10061: my %updates;
10062: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10063: $lastactref->{'samllanding'} = \%updates;
10064: }
10065: }
10066: }
1.160.6.27 raeburn 10067: if (ref($lastactref) eq 'HASH') {
10068: $lastactref->{'domainconfig'} = 1;
10069: }
1.1 raeburn 10070: $resulttext = &mt('Changes made:').'<ul>';
10071: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10072: if ($item eq 'loginvia') {
1.112 raeburn 10073: if (ref($changes{$item}) eq 'HASH') {
10074: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10075: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10076: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10077: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10078: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10079: $protocol = 'http' if ($protocol ne 'https');
10080: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10081:
10082: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10083: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10084: } else {
10085: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10086: }
10087: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10088: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10089: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10090: }
10091: $resulttext .= '</li>';
10092: } else {
10093: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10094: }
1.112 raeburn 10095: } else {
1.128 raeburn 10096: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10097: }
10098: }
1.128 raeburn 10099: $resulttext .= '</ul></li>';
1.112 raeburn 10100: }
1.160.6.5 raeburn 10101: } elsif ($item eq 'helpurl') {
10102: if (ref($changes{$item}) eq 'HASH') {
10103: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10104: if (grep(/^\Q$lang\E$/,@delurls)) {
10105: my ($chg,$link);
10106: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10107: if ($lang eq 'nolang') {
10108: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10109: } else {
10110: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10111: }
10112: $resulttext .= '<li>'.$chg.'</li>';
10113: } else {
10114: my $chg;
10115: if ($lang eq 'nolang') {
10116: $chg = &mt('custom log-in help file for no preferred language');
10117: } else {
10118: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10119: }
10120: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10121: $loginhash{'login'}{'helpurl'}{$lang}.
10122: '?inhibitmenu=yes',$chg,600,500).
10123: '</li>';
10124: }
10125: }
10126: }
1.160.6.56 raeburn 10127: } elsif ($item eq 'headtag') {
10128: if (ref($changes{$item}) eq 'HASH') {
10129: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10130: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10131: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10132: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10133: $resulttext .= '<li><a href="'.
10134: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10135: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10136: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10137: if ($possexempt{$lonhost}) {
10138: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10139: } else {
10140: $resulttext .= &mt('included for any client IP');
10141: }
10142: $resulttext .= '</li>';
10143: }
10144: }
10145: }
1.160.6.113 raeburn 10146: } elsif ($item eq 'saml') {
10147: if (ref($changes{$item}) eq 'HASH') {
10148: my %notlt = (
10149: text => 'Text for log-in by SSO',
10150: img => 'SSO button image',
10151: alt => 'Alt text for button image',
10152: url => 'SSO URL',
10153: title => 'Tooltip for SSO link',
10154: notsso => 'Text for non-SSO log-in',
10155: );
10156: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10157: if (ref($currsaml{$lonhost}) eq 'HASH') {
10158: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10159: '<ul>';
10160: foreach my $key ('text','img','alt','url','title','notsso') {
10161: if ($currsaml{$lonhost}{$key} eq '') {
10162: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10163: } else {
10164: my $value = "'$currsaml{$lonhost}{$key}'";
10165: if ($key eq 'img') {
10166: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
10167: }
10168: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10169: $value).'</li>';
10170: }
10171: }
10172: $resulttext .= '</ul></li>';
10173: } else {
10174: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10175: }
10176: }
10177: }
1.160.6.5 raeburn 10178: } elsif ($item eq 'captcha') {
10179: if (ref($loginhash{'login'}) eq 'HASH') {
10180: my $chgtxt;
10181: if ($loginhash{'login'}{$item} eq 'notused') {
10182: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10183: } else {
10184: my %captchas = &captcha_phrases();
10185: if ($captchas{$loginhash{'login'}{$item}}) {
10186: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10187: } else {
10188: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10189: }
10190: }
10191: $resulttext .= '<li>'.$chgtxt.'</li>';
10192: }
10193: } elsif ($item eq 'recaptchakeys') {
10194: if (ref($loginhash{'login'}) eq 'HASH') {
10195: my ($privkey,$pubkey);
10196: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10197: $pubkey = $loginhash{'login'}{$item}{'public'};
10198: $privkey = $loginhash{'login'}{$item}{'private'};
10199: }
10200: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10201: if (!$pubkey) {
10202: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10203: } else {
10204: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10205: }
10206: if (!$privkey) {
10207: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10208: } else {
1.160.6.53 raeburn 10209: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 10210: }
10211: $chgtxt .= '</ul>';
10212: $resulttext .= '<li>'.$chgtxt.'</li>';
10213: }
1.160.6.69 raeburn 10214: } elsif ($item eq 'recaptchaversion') {
10215: if (ref($loginhash{'login'}) eq 'HASH') {
10216: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10217: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10218: '</li>';
10219: }
10220: }
1.41 raeburn 10221: } else {
10222: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10223: }
1.1 raeburn 10224: }
1.6 raeburn 10225: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10226: } else {
10227: $resulttext = &mt('No changes made to log-in page settings');
10228: }
10229: } else {
1.11 albertel 10230: $resulttext = '<span class="LC_error">'.
10231: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10232: }
1.6 raeburn 10233: if ($errors) {
1.9 raeburn 10234: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10235: $errors.'</ul>';
10236: }
10237: return $resulttext;
10238: }
10239:
1.160.6.56 raeburn 10240: sub check_exempt_addresses {
10241: my ($iplist) = @_;
10242: $iplist =~ s/^\s+//;
10243: $iplist =~ s/\s+$//;
10244: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10245: my (@okips,$new);
10246: foreach my $ip (@poss_ips) {
10247: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10248: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10249: push(@okips,$ip);
10250: }
10251: }
10252: }
10253: if (@okips > 0) {
10254: $new = join(',',@okips);
10255: } else {
10256: $new = '';
10257: }
10258: return $new;
10259: }
10260:
1.6 raeburn 10261: sub color_font_choices {
10262: my %choices =
10263: &Apache::lonlocal::texthash (
10264: img => "Header",
10265: bgs => "Background colors",
10266: links => "Link colors",
1.55 raeburn 10267: images => "Images",
1.6 raeburn 10268: font => "Font color",
1.160.6.22 raeburn 10269: fontmenu => "Font menu",
1.76 raeburn 10270: pgbg => "Page",
1.6 raeburn 10271: tabbg => "Header",
10272: sidebg => "Border",
10273: link => "Link",
10274: alink => "Active link",
10275: vlink => "Visited link",
10276: );
10277: return %choices;
10278: }
10279:
1.160.6.113 raeburn 10280: sub modify_ipaccess {
10281: my ($dom,$lastactref,%domconfig) = @_;
10282: my (@allpos,%changes,%confhash,$errors,$resulttext);
10283: my (@items,%deletions,%itemids,@warnings);
10284: my ($typeorder,$types) = &commblocktype_text();
10285: if ($env{'form.ipaccess_add'}) {
10286: my $name = $env{'form.ipaccess_name_add'};
10287: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10288: if ($newid) {
10289: $itemids{'add'} = $newid;
10290: push(@items,'add');
10291: $changes{$newid} = 1;
10292: } else {
10293: $error = &mt('Failed to acquire unique ID for new IP access control item');
10294: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10295: }
10296: }
10297: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10298: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10299: if (@todelete) {
10300: map { $deletions{$_} = 1; } @todelete;
10301: }
10302: my $maxnum = $env{'form.ipaccess_maxnum'};
10303: for (my $i=0; $i<$maxnum; $i++) {
10304: my $itemid = $env{'form.ipaccess_id_'.$i};
10305: $itemid =~ s/\D+//g;
10306: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10307: if ($deletions{$itemid}) {
10308: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10309: } else {
10310: push(@items,$i);
10311: $itemids{$i} = $itemid;
10312: }
10313: }
10314: }
10315: }
10316: foreach my $idx (@items) {
10317: my $itemid = $itemids{$idx};
10318: next unless ($itemid);
10319: my %current;
10320: unless ($idx eq 'add') {
10321: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10322: %current = %{$domconfig{'ipaccess'}{$itemid}};
10323: }
10324: }
10325: my $position = $env{'form.ipaccess_pos_'.$itemid};
10326: $position =~ s/\D+//g;
10327: if ($position ne '') {
10328: $allpos[$position] = $itemid;
10329: }
10330: my $name = $env{'form.ipaccess_name_'.$idx};
10331: $name =~ s/^\s+|\s+$//g;
10332: $confhash{$itemid}{'name'} = $name;
10333: my $possrange = $env{'form.ipaccess_range_'.$idx};
10334: $possrange =~ s/^\s+|\s+$//g;
10335: unless ($possrange eq '') {
10336: $possrange =~ s/[\r\n]+/\s/g;
10337: $possrange =~ s/\s*-\s*/-/g;
10338: $possrange =~ s/\s+/,/g;
10339: $possrange =~ s/,+/,/g;
10340: if ($possrange ne '') {
10341: my (@ok,$count);
10342: $count = 0;
10343: foreach my $poss (split(/\,/,$possrange)) {
10344: $count ++;
10345: $poss = &validate_ip_pattern($poss);
10346: if ($poss ne '') {
10347: push(@ok,$poss);
10348: }
10349: }
10350: my $diff = $count - scalar(@ok);
10351: if ($diff) {
10352: $errors .= '<li><span class="LC_error">'.
10353: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10354: $diff,$name).
10355: '</span></li>';
10356: }
10357: if (@ok) {
10358: my @cidr_list;
10359: foreach my $item (@ok) {
10360: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10361: }
10362: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10363: }
10364: }
10365: }
10366: foreach my $field ('name','ip') {
10367: unless (($idx eq 'add') || ($changes{$itemid})) {
10368: if ($current{$field} ne $confhash{$itemid}{$field}) {
10369: $changes{$itemid} = 1;
10370: last;
10371: }
10372: }
10373: }
10374: $confhash{$itemid}{'commblocks'} = {};
10375:
10376: my %commblocks;
10377: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10378: foreach my $type (@{$typeorder}) {
10379: if ($commblocks{$type}) {
10380: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10381: }
10382: unless (($idx eq 'add') || ($changes{$itemid})) {
10383: if (ref($current{'commblocks'}) eq 'HASH') {
10384: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10385: $changes{$itemid} = 1;
10386: }
10387: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10388: $changes{$itemid} = 1;
10389: }
10390: }
10391: }
10392: $confhash{$itemid}{'courses'} = {};
10393: my %crsdeletions;
10394: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10395: if (@delcrs) {
10396: map { $crsdeletions{$_} = 1; } @delcrs;
10397: }
10398: if (ref($current{'courses'}) eq 'HASH') {
10399: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10400: if ($crsdeletions{$cid}) {
10401: $changes{$itemid} = 1;
10402: } else {
10403: $confhash{$itemid}{'courses'}{$cid} = 1;
10404: }
10405: }
10406: }
10407: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10408: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10409: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10410: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10411: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10412: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10413: $errors .= '<li><span class="LC_error">'.
10414: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10415: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10416: '</span></li>';
10417: } else {
10418: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10419: $changes{$itemid} = 1;
10420: }
10421: }
10422: }
10423: if (@allpos > 0) {
10424: my $idx = 0;
10425: foreach my $itemid (@allpos) {
10426: if ($itemid ne '') {
10427: $confhash{$itemid}{'order'} = $idx;
10428: unless ($changes{$itemid}) {
10429: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10430: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10431: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10432: $changes{$itemid} = 1;
10433: }
10434: }
10435: }
10436: }
10437: $idx ++;
10438: }
10439: }
10440: }
10441: if (keys(%changes)) {
10442: my %defaultshash = (
10443: ipaccess => \%confhash,
10444: );
10445: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10446: $dom);
10447: if ($putresult eq 'ok') {
10448: my $cachetime = 1800;
10449: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10450: if (ref($lastactref) eq 'HASH') {
10451: $lastactref->{'ipaccess'} = 1;
10452: }
10453: $resulttext = &mt('Changes made:').'<ul>';
10454: my %bynum;
10455: foreach my $itemid (sort(keys(%changes))) {
10456: if (ref($confhash{$itemid}) eq 'HASH') {
10457: my $position = $confhash{$itemid}{'order'};
10458: if ($position =~ /^\d+$/) {
10459: $bynum{$position} = $itemid;
10460: }
10461: }
10462: }
10463: if (keys(%deletions)) {
10464: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10465: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10466: }
10467: }
10468: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10469: my $itemid = $bynum{$pos};
10470: if (ref($confhash{$itemid}) eq 'HASH') {
10471: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10472: my $position = $pos + 1;
10473: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10474: if ($confhash{$itemid}{'ip'} eq '') {
10475: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10476: } else {
10477: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10478: }
10479: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10480: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10481: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10482: '</li>';
10483: } else {
10484: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10485: }
10486: if (keys(%{$confhash{$itemid}{'courses'}})) {
10487: my @courses;
10488: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10489: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10490: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10491: }
10492: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10493: join('</li><li>',@courses).'</li></ul>';
10494: } else {
10495: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10496: }
10497: $resulttext .= '</ul></li>';
10498: }
10499: }
10500: $resulttext .= '</ul>';
10501: } else {
10502: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10503: }
10504: } else {
10505: $resulttext = &mt('No changes made');
10506: }
10507: if ($errors) {
10508: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10509: $errors.'</ul></p>';
10510: }
10511: return $resulttext;
10512: }
10513:
10514: sub get_ipaccess_id {
10515: my ($domain,$location) = @_;
10516: # get lock on ipaccess db
10517: my $lockhash = {
10518: lock => $env{'user.name'}.
10519: ':'.$env{'user.domain'},
10520: };
10521: my $tries = 0;
10522: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10523: my ($id,$error);
10524:
10525: while (($gotlock ne 'ok') && ($tries<10)) {
10526: $tries ++;
10527: sleep (0.1);
10528: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10529: }
10530: if ($gotlock eq 'ok') {
10531: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10532: if ($currids{'lock'}) {
10533: delete($currids{'lock'});
10534: if (keys(%currids)) {
10535: my @curr = sort { $a <=> $b } keys(%currids);
10536: if ($curr[-1] =~ /^\d+$/) {
10537: $id = 1 + $curr[-1];
10538: }
10539: } else {
10540: $id = 1;
10541: }
10542: if ($id) {
10543: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10544: $error = 'nostore';
10545: }
10546: } else {
10547: $error = 'nonumber';
10548: }
10549: }
10550: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10551: } else {
10552: $error = 'nolock';
10553: }
10554: return ($id,$error);
10555: }
10556:
1.6 raeburn 10557: sub modify_rolecolors {
1.160.6.24 raeburn 10558: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10559: my ($resulttext,%rolehash);
10560: $rolehash{'rolecolors'} = {};
1.55 raeburn 10561: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10562: if ($domconfig{'rolecolors'} eq '') {
10563: $domconfig{'rolecolors'} = {};
10564: }
10565: }
1.9 raeburn 10566: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10567: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10568: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10569: $dom);
10570: if ($putresult eq 'ok') {
10571: if (keys(%changes) > 0) {
1.41 raeburn 10572: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10573: if (ref($lastactref) eq 'HASH') {
10574: $lastactref->{'domainconfig'} = 1;
10575: }
1.6 raeburn 10576: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10577: $rolehash{'rolecolors'});
10578: } else {
10579: $resulttext = &mt('No changes made to default color schemes');
10580: }
10581: } else {
1.11 albertel 10582: $resulttext = '<span class="LC_error">'.
10583: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10584: }
10585: if ($errors) {
10586: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10587: $errors.'</ul>';
10588: }
10589: return $resulttext;
10590: }
10591:
10592: sub modify_colors {
1.9 raeburn 10593: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10594: my (%changes,%choices);
1.51 raeburn 10595: my @bgs;
1.6 raeburn 10596: my @links = ('link','alink','vlink');
1.41 raeburn 10597: my @logintext;
1.6 raeburn 10598: my @images;
10599: my $servadm = $r->dir_config('lonAdmEMail');
10600: my $errors;
1.160.6.22 raeburn 10601: my %defaults;
1.6 raeburn 10602: foreach my $role (@{$roles}) {
10603: if ($role eq 'login') {
1.12 raeburn 10604: %choices = &login_choices();
1.41 raeburn 10605: @logintext = ('textcol','bgcol');
1.12 raeburn 10606: } else {
10607: %choices = &color_font_choices();
10608: }
10609: if ($role eq 'login') {
1.41 raeburn 10610: @images = ('img','logo','domlogo','login');
1.51 raeburn 10611: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10612: } else {
10613: @images = ('img');
1.160.6.22 raeburn 10614: @bgs = ('pgbg','tabbg','sidebg');
10615: }
10616: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10617: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10618: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10619: }
10620: if ($role eq 'login') {
10621: foreach my $item (@logintext) {
1.160.6.39 raeburn 10622: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10623: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10624: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10625: }
10626: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10627: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10628: }
10629: }
10630: } else {
1.160.6.39 raeburn 10631: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10632: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10633: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10634: }
10635: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10636: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10637: }
1.6 raeburn 10638: }
1.160.6.22 raeburn 10639: foreach my $item (@bgs) {
1.160.6.39 raeburn 10640: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10641: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10642: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10643: }
10644: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10645: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10646: }
10647: }
10648: foreach my $item (@links) {
1.160.6.39 raeburn 10649: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10650: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10651: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10652: }
10653: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10654: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10655: }
1.6 raeburn 10656: }
1.46 raeburn 10657: my ($configuserok,$author_ok,$switchserver) =
10658: &config_check($dom,$confname,$servadm);
1.9 raeburn 10659: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10660: if (ref($domconfig->{$role}) ne 'HASH') {
10661: $domconfig->{$role} = {};
10662: }
1.8 raeburn 10663: foreach my $img (@images) {
1.160.6.118.2 2(raebur 10664:2): if ($role eq 'login') {
10665:2): if (($img eq 'img') || ($img eq 'logo')) {
10666:2): if (defined($env{'form.login_showlogo_'.$img})) {
10667:2): $confhash->{$role}{'showlogo'}{$img} = 1;
10668:2): } else {
10669:2): $confhash->{$role}{'showlogo'}{$img} = 0;
10670:2): }
1.70 raeburn 10671: }
1.160.6.118.2 2(raebur 10672:2): if ($env{'form.login_alt_'.$img} ne '') {
10673:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
10674:2): }
10675:2): }
1.18 albertel 10676: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10677: && !defined($domconfig->{$role}{$img})
10678: && !$env{'form.'.$role.'_del_'.$img}
10679: && $env{'form.'.$role.'_import_'.$img}) {
10680: # import the old configured image from the .tab setting
10681: # if they haven't provided a new one
10682: $domconfig->{$role}{$img} =
10683: $env{'form.'.$role.'_import_'.$img};
10684: }
1.6 raeburn 10685: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10686: my $error;
1.6 raeburn 10687: if ($configuserok eq 'ok') {
1.9 raeburn 10688: if ($switchserver) {
1.12 raeburn 10689: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10690: } else {
10691: if ($author_ok eq 'ok') {
10692: my ($result,$logourl) =
10693: &publishlogo($r,'upload',$role.'_'.$img,
10694: $dom,$confname,$img,$width,$height);
10695: if ($result eq 'ok') {
10696: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10697: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10698: } else {
1.12 raeburn 10699: $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 10700: }
10701: } else {
1.46 raeburn 10702: $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 10703: }
10704: }
10705: } else {
1.46 raeburn 10706: $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 10707: }
10708: if ($error) {
1.8 raeburn 10709: &Apache::lonnet::logthis($error);
1.11 albertel 10710: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10711: }
10712: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10713: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10714: my $error;
10715: if ($configuserok eq 'ok') {
10716: # is confname an author?
10717: if ($switchserver eq '') {
10718: if ($author_ok eq 'ok') {
10719: my ($result,$logourl) =
10720: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10721: $dom,$confname,$img,$width,$height);
10722: if ($result eq 'ok') {
10723: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10724: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10725: }
10726: }
10727: }
10728: }
1.6 raeburn 10729: }
10730: }
10731: }
10732: if (ref($domconfig) eq 'HASH') {
10733: if (ref($domconfig->{$role}) eq 'HASH') {
10734: foreach my $img (@images) {
10735: if ($domconfig->{$role}{$img} ne '') {
10736: if ($env{'form.'.$role.'_del_'.$img}) {
10737: $confhash->{$role}{$img} = '';
1.12 raeburn 10738: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10739: } else {
1.9 raeburn 10740: if ($confhash->{$role}{$img} eq '') {
10741: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10742: }
1.6 raeburn 10743: }
10744: } else {
10745: if ($env{'form.'.$role.'_del_'.$img}) {
10746: $confhash->{$role}{$img} = '';
1.12 raeburn 10747: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10748: }
10749: }
1.160.6.118.2 2(raebur 10750:2): if ($role eq 'login') {
10751:2): if (($img eq 'logo') || ($img eq 'img')) {
10752:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10753:2): if ($confhash->{$role}{'showlogo'}{$img} ne
10754:2): $domconfig->{$role}{'showlogo'}{$img}) {
10755:2): $changes{$role}{'showlogo'}{$img} = 1;
10756:2): }
10757:2): } else {
10758:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10759:2): $changes{$role}{'showlogo'}{$img} = 1;
10760:2): }
1.70 raeburn 10761: }
1.160.6.118.2 2(raebur 10762:2): }
10763:2): if ($img ne 'login') {
10764:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
10765:2): if ($confhash->{$role}{'alttext'}{$img} ne
10766:2): $domconfig->{$role}{'alttext'}{$img}) {
10767:2): $changes{$role}{'alttext'}{$img} = 1;
10768:2): }
10769:2): } else {
10770:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
10771:2): $changes{$role}{'alttext'}{$img} = 1;
10772:2): }
1.70 raeburn 10773: }
10774: }
10775: }
10776: }
1.6 raeburn 10777: if ($domconfig->{$role}{'font'} ne '') {
10778: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10779: $changes{$role}{'font'} = 1;
10780: }
10781: } else {
10782: if ($confhash->{$role}{'font'}) {
10783: $changes{$role}{'font'} = 1;
10784: }
10785: }
1.107 raeburn 10786: if ($role ne 'login') {
10787: if ($domconfig->{$role}{'fontmenu'} ne '') {
10788: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10789: $changes{$role}{'fontmenu'} = 1;
10790: }
10791: } else {
10792: if ($confhash->{$role}{'fontmenu'}) {
10793: $changes{$role}{'fontmenu'} = 1;
10794: }
1.97 tempelho 10795: }
10796: }
1.6 raeburn 10797: foreach my $item (@bgs) {
10798: if ($domconfig->{$role}{$item} ne '') {
10799: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10800: $changes{$role}{'bgs'}{$item} = 1;
10801: }
10802: } else {
10803: if ($confhash->{$role}{$item}) {
10804: $changes{$role}{'bgs'}{$item} = 1;
10805: }
10806: }
10807: }
10808: foreach my $item (@links) {
10809: if ($domconfig->{$role}{$item} ne '') {
10810: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10811: $changes{$role}{'links'}{$item} = 1;
10812: }
10813: } else {
10814: if ($confhash->{$role}{$item}) {
10815: $changes{$role}{'links'}{$item} = 1;
10816: }
10817: }
10818: }
1.41 raeburn 10819: foreach my $item (@logintext) {
10820: if ($domconfig->{$role}{$item} ne '') {
10821: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10822: $changes{$role}{'logintext'}{$item} = 1;
10823: }
10824: } else {
10825: if ($confhash->{$role}{$item}) {
10826: $changes{$role}{'logintext'}{$item} = 1;
10827: }
10828: }
10829: }
1.6 raeburn 10830: } else {
10831: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10832: \@logintext,$confhash,\%changes);
1.6 raeburn 10833: }
10834: } else {
10835: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10836: \@logintext,$confhash,\%changes);
1.6 raeburn 10837: }
10838: }
10839: return ($errors,%changes);
10840: }
10841:
1.46 raeburn 10842: sub config_check {
10843: my ($dom,$confname,$servadm) = @_;
10844: my ($configuserok,$author_ok,$switchserver,%currroles);
10845: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10846: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10847: $confname,$servadm);
10848: if ($configuserok eq 'ok') {
10849: $switchserver = &check_switchserver($dom,$confname);
10850: if ($switchserver eq '') {
10851: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10852: }
10853: }
10854: return ($configuserok,$author_ok,$switchserver);
10855: }
10856:
1.6 raeburn 10857: sub default_change_checker {
1.41 raeburn 10858: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10859: foreach my $item (@{$links}) {
10860: if ($confhash->{$role}{$item}) {
10861: $changes->{$role}{'links'}{$item} = 1;
10862: }
10863: }
10864: foreach my $item (@{$bgs}) {
10865: if ($confhash->{$role}{$item}) {
10866: $changes->{$role}{'bgs'}{$item} = 1;
10867: }
10868: }
1.41 raeburn 10869: foreach my $item (@{$logintext}) {
10870: if ($confhash->{$role}{$item}) {
10871: $changes->{$role}{'logintext'}{$item} = 1;
10872: }
10873: }
1.6 raeburn 10874: foreach my $img (@{$images}) {
10875: if ($env{'form.'.$role.'_del_'.$img}) {
10876: $confhash->{$role}{$img} = '';
1.12 raeburn 10877: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10878: }
1.70 raeburn 10879: if ($role eq 'login') {
10880: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10881: $changes->{$role}{'showlogo'}{$img} = 1;
10882: }
1.160.6.118.2 2(raebur 10883:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
10884:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
10885:2): $changes->{$role}{'alttext'}{$img} = 1;
10886:2): }
10887:2): }
1.70 raeburn 10888: }
1.6 raeburn 10889: }
10890: if ($confhash->{$role}{'font'}) {
10891: $changes->{$role}{'font'} = 1;
10892: }
1.48 raeburn 10893: }
1.6 raeburn 10894:
10895: sub display_colorchgs {
10896: my ($dom,$changes,$roles,$confhash) = @_;
10897: my (%choices,$resulttext);
10898: if (!grep(/^login$/,@{$roles})) {
10899: $resulttext = &mt('Changes made:').'<br />';
10900: }
10901: foreach my $role (@{$roles}) {
10902: if ($role eq 'login') {
10903: %choices = &login_choices();
10904: } else {
10905: %choices = &color_font_choices();
10906: }
10907: if (ref($changes->{$role}) eq 'HASH') {
10908: if ($role ne 'login') {
10909: $resulttext .= '<h4>'.&mt($role).'</h4>';
10910: }
10911: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10912: if ($role ne 'login') {
10913: $resulttext .= '<ul>';
10914: }
10915: if (ref($changes->{$role}{$key}) eq 'HASH') {
10916: if ($role ne 'login') {
10917: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10918: }
10919: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10920: if (($role eq 'login') && ($key eq 'showlogo')) {
10921: if ($confhash->{$role}{$key}{$item}) {
10922: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10923: } else {
10924: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10925: }
1.160.6.118.2 2(raebur 10926:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
10927:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 10928:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 10929:2): $confhash->{$role}{$key}{$item}).'</li>';
10930:2): } else {
10931:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
10932:2): }
1.70 raeburn 10933: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10934: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10935: } else {
1.12 raeburn 10936: my $newitem = $confhash->{$role}{$item};
10937: if ($key eq 'images') {
10938: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10939: }
10940: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10941: }
10942: }
10943: if ($role ne 'login') {
10944: $resulttext .= '</ul></li>';
10945: }
10946: } else {
10947: if ($confhash->{$role}{$key} eq '') {
10948: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10949: } else {
10950: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10951: }
10952: }
10953: if ($role ne 'login') {
10954: $resulttext .= '</ul>';
10955: }
10956: }
10957: }
10958: }
1.3 raeburn 10959: return $resulttext;
1.1 raeburn 10960: }
10961:
1.9 raeburn 10962: sub thumb_dimensions {
10963: return ('200','50');
10964: }
10965:
1.16 raeburn 10966: sub check_dimensions {
10967: my ($inputfile) = @_;
10968: my ($fullwidth,$fullheight);
10969: if ($inputfile =~ m|^[/\w.\-]+$|) {
10970: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10971: my $imageinfo = <PIPE>;
10972: if (!close(PIPE)) {
10973: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10974: }
10975: chomp($imageinfo);
10976: my ($fullsize) =
1.21 raeburn 10977: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10978: if ($fullsize) {
10979: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10980: }
10981: }
10982: }
10983: return ($fullwidth,$fullheight);
10984: }
10985:
1.9 raeburn 10986: sub check_configuser {
10987: my ($uhome,$dom,$confname,$servadm) = @_;
10988: my ($configuserok,%currroles);
10989: if ($uhome eq 'no_host') {
10990: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10991: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10992: $configuserok =
10993: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10994: $configpass,'','','','','',undef,$servadm);
10995: } else {
10996: $configuserok = 'ok';
10997: %currroles =
10998: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10999: }
11000: return ($configuserok,%currroles);
11001: }
11002:
11003: sub check_authorstatus {
11004: my ($dom,$confname,%currroles) = @_;
11005: my $author_ok;
1.40 raeburn 11006: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11007: my $start = time;
11008: my $end = 0;
11009: $author_ok =
11010: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11011: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11012: } else {
11013: $author_ok = 'ok';
11014: }
11015: return $author_ok;
11016: }
11017:
11018: sub publishlogo {
1.46 raeburn 11019: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 11020: my ($output,$fname,$logourl);
11021: if ($action eq 'upload') {
11022: $fname=$env{'form.'.$formname.'.filename'};
11023: chop($env{'form.'.$formname});
11024: } else {
11025: ($fname) = ($formname =~ /([^\/]+)$/);
11026: }
1.46 raeburn 11027: if ($savefileas ne '') {
11028: $fname = $savefileas;
11029: }
1.9 raeburn 11030: $fname=&Apache::lonnet::clean_filename($fname);
11031: # See if there is anything left
11032: unless ($fname) { return ('error: no uploaded file'); }
11033: $fname="$subdir/$fname";
1.160.6.5 raeburn 11034: my $docroot=$r->dir_config('lonDocRoot');
11035: my $filepath="$docroot/priv";
11036: my $relpath = "$dom/$confname";
1.9 raeburn 11037: my ($fnamepath,$file,$fetchthumb);
11038: $file=$fname;
11039: if ($fname=~m|/|) {
11040: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11041: }
1.160.6.26 raeburn 11042: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11043: my $count;
1.160.6.5 raeburn 11044: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11045: $filepath.="/$parts[$count]";
11046: if ((-e $filepath)!=1) {
11047: mkdir($filepath,02770);
11048: }
11049: }
11050: # Check for bad extension and disallow upload
11051: if ($file=~/\.(\w+)$/ &&
11052: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11053: $output =
1.160.6.25 raeburn 11054: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11055: } elsif ($file=~/\.(\w+)$/ &&
11056: !defined(&Apache::loncommon::fileembstyle($1))) {
11057: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11058: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 11059: $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 11060: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 11061: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11062: } else {
11063: my $source = $filepath.'/'.$file;
11064: my $logfile;
1.160.6.88 raeburn 11065: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 11066: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11067: }
11068: print $logfile
11069: "\n================= Publish ".localtime()." ================\n".
11070: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11071: # Save the file
1.160.6.88 raeburn 11072: if (!open(FH,">",$source)) {
1.9 raeburn 11073: &Apache::lonnet::logthis('Failed to create '.$source);
11074: return (&mt('Failed to create file'));
11075: }
11076: if ($action eq 'upload') {
11077: if (!print FH ($env{'form.'.$formname})) {
11078: &Apache::lonnet::logthis('Failed to write to '.$source);
11079: return (&mt('Failed to write file'));
11080: }
11081: } else {
11082: my $original = &Apache::lonnet::filelocation('',$formname);
11083: if(!copy($original,$source)) {
11084: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11085: return (&mt('Failed to write file'));
11086: }
11087: }
11088: close(FH);
11089: chmod(0660, $source); # Permissions to rw-rw---.
11090:
11091: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11092: my $copyfile=$targetdir.'/'.$file;
11093:
11094: my @parts=split(/\//,$targetdir);
11095: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11096: for (my $count=5;$count<=$#parts;$count++) {
11097: $path.="/$parts[$count]";
11098: if (!-e $path) {
11099: print $logfile "\nCreating directory ".$path;
11100: mkdir($path,02770);
11101: }
11102: }
11103: my $versionresult;
11104: if (-e $copyfile) {
11105: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11106: } else {
11107: $versionresult = 'ok';
11108: }
11109: if ($versionresult eq 'ok') {
11110: if (copy($source,$copyfile)) {
11111: print $logfile "\nCopied original source to ".$copyfile."\n";
11112: $output = 'ok';
11113: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11114: push(@{$modified_urls},[$copyfile,$source]);
11115: my $metaoutput =
11116: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11117: unless ($registered_cleanup) {
11118: my $handlers = $r->get_handlers('PerlCleanupHandler');
11119: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11120: $registered_cleanup=1;
11121: }
1.9 raeburn 11122: } else {
11123: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11124: $output = &mt('Failed to copy file to RES space').", $!";
11125: }
11126: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11127: my $inputfile = $filepath.'/'.$file;
11128: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11129: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11130: if ($fullwidth ne '' && $fullheight ne '') {
11131: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11132: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 11133: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11134: system({$args[0]} @args);
1.16 raeburn 11135: chmod(0660, $filepath.'/tn-'.$file);
11136: if (-e $outfile) {
11137: my $copyfile=$targetdir.'/tn-'.$file;
11138: if (copy($outfile,$copyfile)) {
11139: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11140: my $thumb_metaoutput =
11141: &write_metadata($dom,$confname,$formname,
11142: $targetdir,'tn-'.$file,$logfile);
11143: push(@{$modified_urls},[$copyfile,$outfile]);
11144: unless ($registered_cleanup) {
11145: my $handlers = $r->get_handlers('PerlCleanupHandler');
11146: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11147: $registered_cleanup=1;
11148: }
1.16 raeburn 11149: } else {
11150: print $logfile "\nUnable to write ".$copyfile.
11151: ':'.$!."\n";
11152: }
11153: }
1.9 raeburn 11154: }
11155: }
11156: }
11157: } else {
11158: $output = $versionresult;
11159: }
11160: }
11161: return ($output,$logourl);
11162: }
11163:
11164: sub logo_versioning {
11165: my ($targetdir,$file,$logfile) = @_;
11166: my $target = $targetdir.'/'.$file;
11167: my ($maxversion,$fn,$extn,$output);
11168: $maxversion = 0;
11169: if ($file =~ /^(.+)\.(\w+)$/) {
11170: $fn=$1;
11171: $extn=$2;
11172: }
11173: opendir(DIR,$targetdir);
11174: while (my $filename=readdir(DIR)) {
11175: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11176: $maxversion=($1>$maxversion)?$1:$maxversion;
11177: }
11178: }
11179: $maxversion++;
11180: print $logfile "\nCreating old version ".$maxversion."\n";
11181: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11182: if (copy($target,$copyfile)) {
11183: print $logfile "Copied old target to ".$copyfile."\n";
11184: $copyfile=$copyfile.'.meta';
11185: if (copy($target.'.meta',$copyfile)) {
11186: print $logfile "Copied old target metadata to ".$copyfile."\n";
11187: $output = 'ok';
11188: } else {
11189: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11190: $output = &mt('Failed to copy old meta').", $!, ";
11191: }
11192: } else {
11193: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11194: $output = &mt('Failed to copy old target').", $!, ";
11195: }
11196: return $output;
11197: }
11198:
11199: sub write_metadata {
11200: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11201: my (%metadatafields,%metadatakeys,$output);
11202: $metadatafields{'title'}=$formname;
11203: $metadatafields{'creationdate'}=time;
11204: $metadatafields{'lastrevisiondate'}=time;
11205: $metadatafields{'copyright'}='public';
11206: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11207: $env{'user.domain'};
11208: $metadatafields{'authorspace'}=$confname.':'.$dom;
11209: $metadatafields{'domain'}=$dom;
11210: {
11211: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11212: my $mfh;
1.160.6.88 raeburn 11213: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 11214: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11215: unless ($_=~/\./) {
11216: my $unikey=$_;
11217: $unikey=~/^([A-Za-z]+)/;
11218: my $tag=$1;
11219: $tag=~tr/A-Z/a-z/;
11220: print $mfh "\n\<$tag";
11221: foreach (split(/\,/,$metadatakeys{$unikey})) {
11222: my $value=$metadatafields{$unikey.'.'.$_};
11223: $value=~s/\"/\'\'/g;
11224: print $mfh ' '.$_.'="'.$value.'"';
11225: }
11226: print $mfh '>'.
11227: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11228: .'</'.$tag.'>';
11229: }
11230: }
11231: $output = 'ok';
11232: print $logfile "\nWrote metadata";
11233: close($mfh);
11234: } else {
11235: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11236: $output = &mt('Could not write metadata');
11237: }
11238: }
1.155 raeburn 11239: return $output;
11240: }
11241:
11242: sub notifysubscribed {
11243: foreach my $targetsource (@{$modified_urls}){
11244: next unless (ref($targetsource) eq 'ARRAY');
11245: my ($target,$source)=@{$targetsource};
11246: if ($source ne '') {
1.160.6.88 raeburn 11247: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11248: print $logfh "\nCleanup phase: Notifications\n";
11249: my @subscribed=&subscribed_hosts($target);
11250: foreach my $subhost (@subscribed) {
11251: print $logfh "\nNotifying host ".$subhost.':';
11252: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11253: print $logfh $reply;
11254: }
11255: my @subscribedmeta=&subscribed_hosts("$target.meta");
11256: foreach my $subhost (@subscribedmeta) {
11257: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11258: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11259: $subhost);
11260: print $logfh $reply;
11261: }
11262: print $logfh "\n============ Done ============\n";
1.160 raeburn 11263: close($logfh);
1.155 raeburn 11264: }
11265: }
11266: }
11267: return OK;
11268: }
11269:
11270: sub subscribed_hosts {
11271: my ($target) = @_;
11272: my @subscribed;
1.160.6.88 raeburn 11273: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11274: while (my $subline=<$fh>) {
11275: if ($subline =~ /^($match_lonid):/) {
11276: my $host = $1;
11277: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11278: unless (grep(/^\Q$host\E$/,@subscribed)) {
11279: push(@subscribed,$host);
11280: }
11281: }
11282: }
11283: }
11284: }
11285: return @subscribed;
1.9 raeburn 11286: }
11287:
11288: sub check_switchserver {
11289: my ($dom,$confname) = @_;
11290: my ($allowed,$switchserver);
11291: my $home = &Apache::lonnet::homeserver($confname,$dom);
11292: if ($home eq 'no_host') {
11293: $home = &Apache::lonnet::domain($dom,'primary');
11294: }
11295: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11296: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11297: if (!$allowed) {
1.160.6.11 raeburn 11298: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11299: }
11300: return $switchserver;
11301: }
11302:
1.1 raeburn 11303: sub modify_quotas {
1.160.6.30 raeburn 11304: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11305: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 11306: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 11307: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11308: $validationfieldsref);
1.86 raeburn 11309: if ($action eq 'quotas') {
11310: $context = 'tools';
1.160.6.26 raeburn 11311: } else {
1.86 raeburn 11312: $context = $action;
11313: }
11314: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 11315: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 11316: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11317: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11318: %titles = &courserequest_titles();
11319: $toolregexp = join('|',@usertools);
11320: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 11321: $confname = $dom.'-domainconfig';
11322: my $servadm = $r->dir_config('lonAdmEMail');
11323: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 11324: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11325: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 11326: } elsif ($context eq 'requestauthor') {
11327: @usertools = ('author');
11328: %titles = &authorrequest_titles();
1.86 raeburn 11329: } else {
1.160.6.4 raeburn 11330: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11331: %titles = &tool_titles();
1.86 raeburn 11332: }
1.160.6.27 raeburn 11333: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11334: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11335: foreach my $key (keys(%env)) {
1.101 raeburn 11336: if ($context eq 'requestcourses') {
11337: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11338: my $item = $1;
11339: my $type = $2;
11340: if ($type =~ /^limit_(.+)/) {
11341: $limithash{$item}{$1} = $env{$key};
11342: } else {
11343: $confhash{$item}{$type} = $env{$key};
11344: }
11345: }
1.160.6.5 raeburn 11346: } elsif ($context eq 'requestauthor') {
11347: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11348: $confhash{$1} = $env{$key};
11349: }
1.101 raeburn 11350: } else {
1.86 raeburn 11351: if ($key =~ /^form\.quota_(.+)$/) {
11352: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 11353: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11354: $confhash{'authorquota'}{$1} = $env{$key};
11355: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11356: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11357: }
1.72 raeburn 11358: }
11359: }
1.160.6.5 raeburn 11360: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 11361: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11362: @approvalnotify = sort(@approvalnotify);
11363: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 11364: my @crstypes = ('official','unofficial','community','textbook');
11365: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11366: foreach my $type (@hasuniquecode) {
11367: if (grep(/^\Q$type\E$/,@crstypes)) {
11368: $confhash{'uniquecode'}{$type} = 1;
11369: }
11370: }
1.160.6.46 raeburn 11371: my (%newbook,%allpos);
1.160.6.30 raeburn 11372: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11373: foreach my $type ('textbooks','templates') {
11374: @{$allpos{$type}} = ();
11375: my $invalid;
11376: if ($type eq 'textbooks') {
11377: $invalid = &mt('Invalid LON-CAPA course for textbook');
11378: } else {
11379: $invalid = &mt('Invalid LON-CAPA course for template');
11380: }
11381: if ($env{'form.'.$type.'_addbook'}) {
11382: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11383: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11384: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11385: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11386: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11387: } else {
11388: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11389: my $position = $env{'form.'.$type.'_addbook_pos'};
11390: $position =~ s/\D+//g;
11391: if ($position ne '') {
11392: $allpos{$type}[$position] = $newbook{$type};
11393: }
1.160.6.30 raeburn 11394: }
1.160.6.46 raeburn 11395: } else {
11396: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 11397: }
11398: }
1.160.6.46 raeburn 11399: }
1.160.6.30 raeburn 11400: }
1.102 raeburn 11401: if (ref($domconfig{$action}) eq 'HASH') {
11402: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11403: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11404: $changes{'notify'}{'approval'} = 1;
11405: }
11406: } else {
1.144 raeburn 11407: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11408: $changes{'notify'}{'approval'} = 1;
11409: }
11410: }
1.160.6.30 raeburn 11411: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11412: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11413: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11414: unless ($confhash{'uniquecode'}{$crstype}) {
11415: $changes{'uniquecode'} = 1;
11416: }
11417: }
11418: unless ($changes{'uniquecode'}) {
11419: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11420: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11421: $changes{'uniquecode'} = 1;
11422: }
11423: }
11424: }
11425: } else {
11426: $changes{'uniquecode'} = 1;
11427: }
11428: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11429: $changes{'uniquecode'} = 1;
11430: }
11431: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11432: foreach my $type ('textbooks','templates') {
11433: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11434: my %deletions;
11435: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11436: if (@todelete) {
11437: map { $deletions{$_} = 1; } @todelete;
11438: }
11439: my %imgdeletions;
11440: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11441: if (@todeleteimages) {
11442: map { $imgdeletions{$_} = 1; } @todeleteimages;
11443: }
11444: my $maxnum = $env{'form.'.$type.'_maxnum'};
11445: for (my $i=0; $i<=$maxnum; $i++) {
11446: my $itemid = $env{'form.'.$type.'_id_'.$i};
11447: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11448: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11449: if ($deletions{$key}) {
11450: if ($domconfig{$action}{$type}{$key}{'image'}) {
11451: #FIXME need to obsolete item in RES space
11452: }
11453: next;
11454: } else {
11455: my $newpos = $env{'form.'.$itemid};
11456: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 11457: foreach my $item ('subject','title','publisher','author') {
11458: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11459: ($type eq 'templates'));
1.160.6.46 raeburn 11460: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11461: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11462: $changes{$type}{$key} = 1;
11463: }
11464: }
11465: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 11466: }
1.160.6.46 raeburn 11467: if ($imgdeletions{$key}) {
11468: $changes{$type}{$key} = 1;
11469: #FIXME need to obsolete item in RES space
11470: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11471: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 11472: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11473: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11474: } else {
11475: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11476: $cdom,$cnum,$type,$configuserok,
11477: $switchserver,$author_ok);
11478: if ($imgurl) {
11479: $confhash{$type}{$key}{'image'} = $imgurl;
11480: $changes{$type}{$key} = 1;
11481: }
11482: if ($error) {
11483: &Apache::lonnet::logthis($error);
11484: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11485: }
1.160.6.46 raeburn 11486: }
11487: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11488: $confhash{$type}{$key}{'image'} =
11489: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 11490: }
11491: }
11492: }
11493: }
11494: }
11495: }
1.102 raeburn 11496: } else {
1.144 raeburn 11497: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11498: $changes{'notify'}{'approval'} = 1;
11499: }
1.160.6.30 raeburn 11500: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11501: $changes{'uniquecode'} = 1;
11502: }
11503: }
11504: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11505: foreach my $type ('textbooks','templates') {
11506: if ($newbook{$type}) {
11507: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 11508: foreach my $item ('subject','title','publisher','author') {
11509: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11510: ($type eq 'template'));
1.160.6.46 raeburn 11511: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11512: if ($env{'form.'.$type.'_addbook_'.$item}) {
11513: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11514: }
11515: }
11516: if ($type eq 'textbooks') {
11517: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11518: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 11519: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11520: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11521: } else {
11522: my ($imageurl,$error) =
11523: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11524: $configuserok,$switchserver,$author_ok);
11525: if ($imageurl) {
11526: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11527: }
11528: if ($error) {
11529: &Apache::lonnet::logthis($error);
11530: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11531: }
1.160.6.46 raeburn 11532: }
11533: }
1.160.6.30 raeburn 11534: }
11535: }
1.160.6.46 raeburn 11536: if (@{$allpos{$type}} > 0) {
11537: my $idx = 0;
11538: foreach my $item (@{$allpos{$type}}) {
11539: if ($item ne '') {
11540: $confhash{$type}{$item}{'order'} = $idx;
11541: if (ref($domconfig{$action}) eq 'HASH') {
11542: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11543: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11544: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11545: $changes{$type}{$item} = 1;
11546: }
1.160.6.30 raeburn 11547: }
11548: }
11549: }
1.160.6.46 raeburn 11550: $idx ++;
1.160.6.30 raeburn 11551: }
11552: }
11553: }
11554: }
1.160.6.39 raeburn 11555: if (ref($validationitemsref) eq 'ARRAY') {
11556: foreach my $item (@{$validationitemsref}) {
11557: if ($item eq 'fields') {
11558: my @changed;
11559: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11560: if (@{$confhash{'validation'}{$item}} > 0) {
11561: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11562: }
1.160.6.65 raeburn 11563: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11564: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11565: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11566: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11567: $domconfig{'requestcourses'}{'validation'}{$item});
11568: } else {
11569: @changed = @{$confhash{'validation'}{$item}};
11570: }
1.160.6.39 raeburn 11571: } else {
11572: @changed = @{$confhash{'validation'}{$item}};
11573: }
11574: } else {
11575: @changed = @{$confhash{'validation'}{$item}};
11576: }
11577: if (@changed) {
11578: if ($confhash{'validation'}{$item}) {
11579: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11580: } else {
11581: $changes{'validation'}{$item} = &mt('None');
11582: }
11583: }
11584: } else {
11585: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11586: if ($item eq 'markup') {
11587: if ($env{'form.requestcourses_validation_'.$item}) {
11588: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11589: }
11590: }
1.160.6.65 raeburn 11591: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11592: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11593: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11594: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11595: }
11596: } else {
11597: if ($confhash{'validation'}{$item} ne '') {
11598: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11599: }
1.160.6.39 raeburn 11600: }
11601: } else {
11602: if ($confhash{'validation'}{$item} ne '') {
11603: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11604: }
11605: }
11606: }
11607: }
11608: }
11609: if ($env{'form.validationdc'}) {
11610: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11611: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11612: if (exists($domcoords{$newval})) {
11613: $confhash{'validation'}{'dc'} = $newval;
11614: }
11615: }
11616: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11617: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11618: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11619: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11620: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11621: if ($confhash{'validation'}{'dc'} eq '') {
11622: $changes{'validation'}{'dc'} = &mt('None');
11623: } else {
11624: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11625: }
1.160.6.39 raeburn 11626: }
1.160.6.65 raeburn 11627: } elsif ($confhash{'validation'}{'dc'} ne '') {
11628: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11629: }
11630: } elsif ($confhash{'validation'}{'dc'} ne '') {
11631: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11632: }
11633: } elsif ($confhash{'validation'}{'dc'} ne '') {
11634: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11635: }
1.160.6.65 raeburn 11636: } else {
11637: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11638: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11639: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11640: $changes{'validation'}{'dc'} = &mt('None');
11641: }
11642: }
1.160.6.39 raeburn 11643: }
11644: }
1.102 raeburn 11645: }
11646: } else {
1.86 raeburn 11647: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 11648: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11649: }
1.72 raeburn 11650: foreach my $item (@usertools) {
11651: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11652: my $unset;
1.101 raeburn 11653: if ($context eq 'requestcourses') {
1.104 raeburn 11654: $unset = '0';
11655: if ($type eq '_LC_adv') {
11656: $unset = '';
11657: }
1.101 raeburn 11658: if ($confhash{$item}{$type} eq 'autolimit') {
11659: $confhash{$item}{$type} .= '=';
11660: unless ($limithash{$item}{$type} =~ /\D/) {
11661: $confhash{$item}{$type} .= $limithash{$item}{$type};
11662: }
11663: }
1.160.6.5 raeburn 11664: } elsif ($context eq 'requestauthor') {
11665: $unset = '0';
11666: if ($type eq '_LC_adv') {
11667: $unset = '';
11668: }
1.72 raeburn 11669: } else {
1.101 raeburn 11670: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11671: $confhash{$item}{$type} = 1;
11672: } else {
11673: $confhash{$item}{$type} = 0;
11674: }
1.72 raeburn 11675: }
1.86 raeburn 11676: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11677: if ($action eq 'requestauthor') {
11678: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11679: $changes{$type} = 1;
11680: }
11681: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11682: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11683: $changes{$item}{$type} = 1;
11684: }
11685: } else {
11686: if ($context eq 'requestcourses') {
1.104 raeburn 11687: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11688: $changes{$item}{$type} = 1;
11689: }
11690: } else {
11691: if (!$confhash{$item}{$type}) {
11692: $changes{$item}{$type} = 1;
11693: }
11694: }
11695: }
11696: } else {
11697: if ($context eq 'requestcourses') {
1.104 raeburn 11698: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11699: $changes{$item}{$type} = 1;
11700: }
1.160.6.5 raeburn 11701: } elsif ($context eq 'requestauthor') {
11702: if ($confhash{$type} ne $unset) {
11703: $changes{$type} = 1;
11704: }
1.72 raeburn 11705: } else {
11706: if (!$confhash{$item}{$type}) {
11707: $changes{$item}{$type} = 1;
11708: }
11709: }
11710: }
1.1 raeburn 11711: }
11712: }
1.160.6.5 raeburn 11713: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11714: if (ref($domconfig{'quotas'}) eq 'HASH') {
11715: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11716: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11717: if (exists($confhash{'defaultquota'}{$key})) {
11718: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11719: $changes{'defaultquota'}{$key} = 1;
11720: }
11721: } else {
11722: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11723: }
11724: }
1.86 raeburn 11725: } else {
11726: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11727: if (exists($confhash{'defaultquota'}{$key})) {
11728: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11729: $changes{'defaultquota'}{$key} = 1;
11730: }
11731: } else {
11732: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11733: }
1.1 raeburn 11734: }
11735: }
1.160.6.20 raeburn 11736: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11737: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11738: if (exists($confhash{'authorquota'}{$key})) {
11739: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11740: $changes{'authorquota'}{$key} = 1;
11741: }
11742: } else {
11743: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11744: }
11745: }
11746: }
1.1 raeburn 11747: }
1.86 raeburn 11748: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11749: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11750: if (ref($domconfig{'quotas'}) eq 'HASH') {
11751: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11752: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11753: $changes{'defaultquota'}{$key} = 1;
11754: }
11755: } else {
11756: if (!exists($domconfig{'quotas'}{$key})) {
11757: $changes{'defaultquota'}{$key} = 1;
11758: }
1.72 raeburn 11759: }
11760: } else {
1.86 raeburn 11761: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11762: }
1.1 raeburn 11763: }
11764: }
1.160.6.20 raeburn 11765: if (ref($confhash{'authorquota'}) eq 'HASH') {
11766: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11767: if (ref($domconfig{'quotas'}) eq 'HASH') {
11768: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11769: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11770: $changes{'authorquota'}{$key} = 1;
11771: }
11772: } else {
11773: $changes{'authorquota'}{$key} = 1;
11774: }
11775: } else {
11776: $changes{'authorquota'}{$key} = 1;
11777: }
11778: }
11779: }
1.1 raeburn 11780: }
1.72 raeburn 11781:
1.160.6.5 raeburn 11782: if ($context eq 'requestauthor') {
11783: $domdefaults{'requestauthor'} = \%confhash;
11784: } else {
11785: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11786: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11787: $domdefaults{$key} = $confhash{$key};
11788: }
1.160.6.5 raeburn 11789: }
1.72 raeburn 11790: }
1.160.6.5 raeburn 11791:
1.1 raeburn 11792: my %quotahash = (
1.86 raeburn 11793: $action => { %confhash }
1.1 raeburn 11794: );
11795: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11796: $dom);
11797: if ($putresult eq 'ok') {
11798: if (keys(%changes) > 0) {
1.72 raeburn 11799: my $cachetime = 24*60*60;
11800: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11801: if (ref($lastactref) eq 'HASH') {
11802: $lastactref->{'domdefaults'} = 1;
11803: }
1.1 raeburn 11804: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11805: unless (($context eq 'requestcourses') ||
11806: ($context eq 'requestauthor')) {
1.86 raeburn 11807: if (ref($changes{'defaultquota'}) eq 'HASH') {
11808: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11809: foreach my $type (@{$types},'default') {
11810: if (defined($changes{'defaultquota'}{$type})) {
11811: my $typetitle = $usertypes->{$type};
11812: if ($type eq 'default') {
11813: $typetitle = $othertitle;
11814: }
1.160.6.28 raeburn 11815: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11816: }
11817: }
1.86 raeburn 11818: $resulttext .= '</ul></li>';
1.72 raeburn 11819: }
1.160.6.20 raeburn 11820: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11821: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11822: foreach my $type (@{$types},'default') {
11823: if (defined($changes{'authorquota'}{$type})) {
11824: my $typetitle = $usertypes->{$type};
11825: if ($type eq 'default') {
11826: $typetitle = $othertitle;
11827: }
1.160.6.28 raeburn 11828: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11829: }
11830: }
11831: $resulttext .= '</ul></li>';
11832: }
1.72 raeburn 11833: }
1.80 raeburn 11834: my %newenv;
1.72 raeburn 11835: foreach my $item (@usertools) {
1.160.6.5 raeburn 11836: my (%haschgs,%inconf);
11837: if ($context eq 'requestauthor') {
11838: %haschgs = %changes;
11839: %inconf = %confhash;
11840: } else {
11841: if (ref($changes{$item}) eq 'HASH') {
11842: %haschgs = %{$changes{$item}};
11843: }
11844: if (ref($confhash{$item}) eq 'HASH') {
11845: %inconf = %{$confhash{$item}};
11846: }
11847: }
11848: if (keys(%haschgs) > 0) {
1.80 raeburn 11849: my $newacc =
11850: &Apache::lonnet::usertools_access($env{'user.name'},
11851: $env{'user.domain'},
1.86 raeburn 11852: $item,'reload',$context);
1.160.6.5 raeburn 11853: if (($context eq 'requestcourses') ||
11854: ($context eq 'requestauthor')) {
1.108 raeburn 11855: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11856: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11857: }
11858: } else {
11859: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11860: $newenv{'environment.availabletools.'.$item} = $newacc;
11861: }
1.80 raeburn 11862: }
1.160.6.5 raeburn 11863: unless ($context eq 'requestauthor') {
11864: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11865: }
1.72 raeburn 11866: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11867: if ($haschgs{$type}) {
1.72 raeburn 11868: my $typetitle = $usertypes->{$type};
11869: if ($type eq 'default') {
11870: $typetitle = $othertitle;
11871: } elsif ($type eq '_LC_adv') {
11872: $typetitle = 'LON-CAPA Advanced Users';
11873: }
1.160.6.5 raeburn 11874: if ($inconf{$type}) {
1.101 raeburn 11875: if ($context eq 'requestcourses') {
11876: my $cond;
1.160.6.5 raeburn 11877: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11878: if ($1 eq '') {
11879: $cond = &mt('(Automatic processing of any request).');
11880: } else {
11881: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11882: }
11883: } else {
1.160.6.5 raeburn 11884: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11885: }
11886: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11887: } elsif ($context eq 'requestauthor') {
11888: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11889: $titles{$inconf{$type}},$typetitle);
11890:
1.101 raeburn 11891: } else {
11892: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11893: }
1.72 raeburn 11894: } else {
1.104 raeburn 11895: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11896: if ($inconf{$type} eq '0') {
1.104 raeburn 11897: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11898: } else {
11899: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11900: }
11901: } else {
11902: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11903: }
1.72 raeburn 11904: }
11905: }
1.26 raeburn 11906: }
1.160.6.5 raeburn 11907: unless ($context eq 'requestauthor') {
11908: $resulttext .= '</ul></li>';
11909: }
1.26 raeburn 11910: }
1.1 raeburn 11911: }
1.160.6.5 raeburn 11912: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11913: if (ref($changes{'notify'}) eq 'HASH') {
11914: if ($changes{'notify'}{'approval'}) {
11915: if (ref($confhash{'notify'}) eq 'HASH') {
11916: if ($confhash{'notify'}{'approval'}) {
11917: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11918: } else {
1.160.6.5 raeburn 11919: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11920: }
11921: }
11922: }
11923: }
11924: }
1.160.6.30 raeburn 11925: if ($action eq 'requestcourses') {
11926: my @offon = ('off','on');
11927: if ($changes{'uniquecode'}) {
11928: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11929: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11930: $resulttext .= '<li>'.
11931: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11932: '</li>';
11933: } else {
11934: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11935: '</li>';
11936: }
11937: }
1.160.6.46 raeburn 11938: foreach my $type ('textbooks','templates') {
11939: if (ref($changes{$type}) eq 'HASH') {
11940: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11941: foreach my $key (sort(keys(%{$changes{$type}}))) {
11942: my %coursehash = &Apache::lonnet::coursedescription($key);
11943: my $coursetitle = $coursehash{'description'};
11944: my $position = $confhash{$type}{$key}{'order'} + 1;
11945: $resulttext .= '<li>';
1.160.6.47 raeburn 11946: foreach my $item ('subject','title','publisher','author') {
11947: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11948: ($type eq 'templates'));
1.160.6.46 raeburn 11949: my $name = $item.':';
11950: $name =~ s/^(\w)/\U$1/;
11951: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11952: }
11953: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11954: if ($type eq 'textbooks') {
11955: if ($confhash{$type}{$key}{'image'}) {
11956: $resulttext .= ' '.&mt('Image: [_1]',
11957: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11958: ' alt="Textbook cover" />').'<br />';
11959: }
11960: }
11961: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11962: }
1.160.6.46 raeburn 11963: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11964: }
11965: }
1.160.6.39 raeburn 11966: if (ref($changes{'validation'}) eq 'HASH') {
11967: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11968: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11969: foreach my $item (@{$validationitemsref}) {
11970: if (exists($changes{'validation'}{$item})) {
11971: if ($item eq 'markup') {
11972: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11973: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11974: } else {
11975: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11976: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11977: }
11978: }
11979: }
11980: if (exists($changes{'validation'}{'dc'})) {
11981: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11982: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11983: }
11984: }
11985: }
1.160.6.30 raeburn 11986: }
1.1 raeburn 11987: $resulttext .= '</ul>';
1.80 raeburn 11988: if (keys(%newenv)) {
11989: &Apache::lonnet::appenv(\%newenv);
11990: }
1.1 raeburn 11991: } else {
1.86 raeburn 11992: if ($context eq 'requestcourses') {
11993: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11994: } elsif ($context eq 'requestauthor') {
11995: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11996: } else {
1.90 weissno 11997: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11998: }
1.1 raeburn 11999: }
12000: } else {
1.11 albertel 12001: $resulttext = '<span class="LC_error">'.
12002: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12003: }
1.160.6.30 raeburn 12004: if ($errors) {
12005: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12006: '<ul>'.$errors.'</ul></p>';
12007: }
1.3 raeburn 12008: return $resulttext;
1.1 raeburn 12009: }
12010:
1.160.6.30 raeburn 12011: sub process_textbook_image {
1.160.6.46 raeburn 12012: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12013: my $filename = $env{'form.'.$caller.'.filename'};
12014: my ($error,$url);
12015: my ($width,$height) = (50,50);
12016: if ($configuserok eq 'ok') {
12017: if ($switchserver) {
12018: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12019: $switchserver);
12020: } elsif ($author_ok eq 'ok') {
12021: my ($result,$imageurl) =
12022: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 12023: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 12024: if ($result eq 'ok') {
12025: $url = $imageurl;
12026: } else {
12027: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12028: }
12029: } else {
12030: $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);
12031: }
12032: } else {
12033: $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);
12034: }
12035: return ($url,$error);
12036: }
12037:
1.160.6.118.2 1(raebur 12038:1): sub modify_ltitools {
12039:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12040:1): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12041:1): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12042:1): my $confname = $dom.'-domainconfig';
12043:1): my $servadm = $r->dir_config('lonAdmEMail');
12044:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12045:1): my (%posslti,%possfield);
12046:1): my @courseroles = ('cc','in','ta','ep','st');
12047:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12048:1): map { $posslti{$_} = 1; } @ltiroles;
12049:1): my @allfields = ('fullname','firstname','lastname','email','user','roles');
12050:1): map { $possfield{$_} = 1; } @allfields;
12051:1): my %lt = <itools_names();
12052:1): if ($env{'form.ltitools_add'}) {
12053:1): my $title = $env{'form.ltitools_add_title'};
12054:1): $title =~ s/(`)/'/g;
12055:1): ($newid,my $error) = &get_ltitools_id($dom,$title);
12056:1): if ($newid) {
12057:1): my $position = $env{'form.ltitools_add_pos'};
12058:1): $position =~ s/\D+//g;
12059:1): if ($position ne '') {
12060:1): $allpos[$position] = $newid;
12061:1): }
12062:1): $changes{$newid} = 1;
12063:1): foreach my $item ('title','url','key','secret','lifetime') {
12064:1): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12065:1): if ($item eq 'lifetime') {
12066:1): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12067:1): }
12068:1): if ($env{'form.ltitools_add_'.$item}) {
12069:1): if (($item eq 'key') || ($item eq 'secret')) {
12070:1): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12071:1): } else {
12072:1): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12073:1): }
12074:1): }
12075:1): }
12076:1): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12077:1): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12078:1): }
12079:1): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12080:1): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12081:1): }
12082:1): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12083:1): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12084:1): } else {
12085:1): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12086:1): }
12087:1): foreach my $item ('width','height','linktext','explanation') {
12088:1): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12089:1): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12090:1): if (($item eq 'width') || ($item eq 'height')) {
12091:1): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12092:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12093:1): }
12094:1): } else {
12095:1): if ($env{'form.ltitools_add_'.$item} ne '') {
12096:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12097:1): }
12098:1): }
12099:1): }
12100:1): if ($env{'form.ltitools_add_target'} eq 'window') {
12101:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12102:1): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12103:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12104:1): } else {
12105:1): $confhash{$newid}{'display'}{'target'} = 'iframe';
12106:1): }
12107:1): if ($env{'form.ltitools_add_image.filename'} ne '') {
12108:1): my ($imageurl,$error) =
12109:1): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12110:1): $configuserok,$switchserver,$author_ok);
12111:1): if ($imageurl) {
12112:1): $confhash{$newid}{'image'} = $imageurl;
12113:1): }
12114:1): if ($error) {
12115:1): &Apache::lonnet::logthis($error);
12116:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12117:1): }
12118:1): }
12119:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12120:1): foreach my $field (@fields) {
12121:1): if ($possfield{$field}) {
12122:1): if ($field eq 'roles') {
12123:1): foreach my $role (@courseroles) {
12124:1): my $choice = $env{'form.ltitools_add_roles_'.$role};
12125:1): if (($choice ne '') && ($posslti{$choice})) {
12126:1): $confhash{$newid}{'roles'}{$role} = $choice;
12127:1): if ($role eq 'cc') {
12128:1): $confhash{$newid}{'roles'}{'co'} = $choice;
12129:1): }
12130:1): }
12131:1): }
12132:1): } else {
12133:1): $confhash{$newid}{'fields'}{$field} = 1;
12134:1): }
12135:1): }
12136:1): }
12137:1): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12138:1): if ($confhash{$newid}{'fields'}{'user'}) {
12139:1): if ($env{'form.ltitools_userincdom_add'}) {
12140:1): $confhash{$newid}{'incdom'} = 1;
12141:1): }
12142:1): }
12143:1): }
12144:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12145:1): foreach my $item (@courseconfig) {
12146:1): $confhash{$newid}{'crsconf'}{$item} = 1;
12147:1): }
12148:1): if ($env{'form.ltitools_add_custom'}) {
12149:1): my $name = $env{'form.ltitools_add_custom_name'};
12150:1): my $value = $env{'form.ltitools_add_custom_value'};
12151:1): $value =~ s/(`)/'/g;
12152:1): $name =~ s/(`)/'/g;
12153:1): $confhash{$newid}{'custom'}{$name} = $value;
12154:1): }
12155:1): } else {
12156:1): my $error = &mt('Failed to acquire unique ID for new external tool');
12157:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12158:1): }
12159:1): }
12160:1): if (ref($domconfig{$action}) eq 'HASH') {
12161:1): my %deletions;
12162:1): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12163:1): if (@todelete) {
12164:1): map { $deletions{$_} = 1; } @todelete;
12165:1): }
12166:1): my %customadds;
12167:1): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12168:1): if (@newcustom) {
12169:1): map { $customadds{$_} = 1; } @newcustom;
12170:1): }
12171:1): my %imgdeletions;
12172:1): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12173:1): if (@todeleteimages) {
12174:1): map { $imgdeletions{$_} = 1; } @todeleteimages;
12175:1): }
12176:1): my $maxnum = $env{'form.ltitools_maxnum'};
12177:1): for (my $i=0; $i<=$maxnum; $i++) {
12178:1): my $itemid = $env{'form.ltitools_id_'.$i};
12179:1): $itemid =~ s/\D+//g;
12180:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12181:1): if ($deletions{$itemid}) {
12182:1): if ($domconfig{$action}{$itemid}{'image'}) {
12183:1): #FIXME need to obsolete item in RES space
12184:1): }
12185:1): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12186:1): next;
12187:1): } else {
12188:1): my $newpos = $env{'form.ltitools_'.$itemid};
12189:1): $newpos =~ s/\D+//g;
12190:1): foreach my $item ('title','url','lifetime') {
12191:1): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12192:1): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12193:1): $changes{$itemid} = 1;
12194:1): }
12195:1): }
12196:1): foreach my $item ('key','secret') {
12197:1): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12198:1): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12199:1): $changes{$itemid} = 1;
12200:1): }
12201:1): }
12202:1): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12203:1): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12204:1): }
12205:1): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12206:1): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12207:1): }
12208:1): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12209:1): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12210:1): } else {
12211:1): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12212:1): }
12213:1): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12214:1): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12215:1): $changes{$itemid} = 1;
12216:1): }
12217:1): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12218:1): $changes{$itemid} = 1;
12219:1): }
12220:1): foreach my $size ('width','height') {
12221:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12222:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12223:1): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12224:1): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12225:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12226:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12227:1): $changes{$itemid} = 1;
12228:1): }
12229:1): } else {
12230:1): $changes{$itemid} = 1;
12231:1): }
12232:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12233:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12234:1): $changes{$itemid} = 1;
12235:1): }
12236:1): }
12237:1): }
12238:1): foreach my $item ('linktext','explanation') {
12239:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12240:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12241:1): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12242:1): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12243:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12244:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12245:1): $changes{$itemid} = 1;
12246:1): }
12247:1): } else {
12248:1): $changes{$itemid} = 1;
12249:1): }
12250:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12251:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12252:1): $changes{$itemid} = 1;
12253:1): }
12254:1): }
12255:1): }
12256:1): if ($env{'form.ltitools_target_'.$i} eq 'window') {
12257:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12258:1): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12259:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12260:1): } else {
12261:1): $confhash{$itemid}{'display'}{'target'} = 'iframe';
12262:1): }
12263:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12264:1): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12265:1): $changes{$itemid} = 1;
12266:1): }
12267:1): } else {
12268:1): $changes{$itemid} = 1;
12269:1): }
12270:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12271:1): foreach my $item ('label','title','target','linktext','explanation','append') {
12272:1): if (grep(/^\Q$item\E$/,@courseconfig)) {
12273:1): $confhash{$itemid}{'crsconf'}{$item} = 1;
12274:1): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12275:1): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12276:1): $changes{$itemid} = 1;
12277:1): }
12278:1): } else {
12279:1): $changes{$itemid} = 1;
12280:1): }
12281:1): }
12282:1): }
12283:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12284:1): foreach my $field (@fields) {
12285:1): if ($possfield{$field}) {
12286:1): if ($field eq 'roles') {
12287:1): foreach my $role (@courseroles) {
12288:1): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12289:1): if (($choice ne '') && ($posslti{$choice})) {
12290:1): $confhash{$itemid}{'roles'}{$role} = $choice;
12291:1): if ($role eq 'cc') {
12292:1): $confhash{$itemid}{'roles'}{'co'} = $choice;
12293:1): }
12294:1): }
12295:1): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12296:1): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12297:1): $changes{$itemid} = 1;
12298:1): }
12299:1): } elsif ($confhash{$itemid}{'roles'}{$role}) {
12300:1): $changes{$itemid} = 1;
12301:1): }
12302:1): }
12303:1): } else {
12304:1): $confhash{$itemid}{'fields'}{$field} = 1;
12305:1): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12306:1): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12307:1): $changes{$itemid} = 1;
12308:1): }
12309:1): } else {
12310:1): $changes{$itemid} = 1;
12311:1): }
12312:1): }
12313:1): }
12314:1): }
12315:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12316:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12317:1): if ($env{'form.ltitools_userincdom_'.$i}) {
12318:1): $confhash{$itemid}{'incdom'} = 1;
12319:1): }
12320:1): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12321:1): $changes{$itemid} = 1;
12322:1): }
12323:1): }
12324:1): }
12325:1): $allpos[$newpos] = $itemid;
12326:1): }
12327:1): if ($imgdeletions{$itemid}) {
12328:1): $changes{$itemid} = 1;
12329:1): #FIXME need to obsolete item in RES space
12330:1): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12331:1): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12332:1): $itemid,$configuserok,$switchserver,
12333:1): $author_ok);
12334:1): if ($imgurl) {
12335:1): $confhash{$itemid}{'image'} = $imgurl;
12336:1): $changes{$itemid} = 1;
12337:1): }
12338:1): if ($error) {
12339:1): &Apache::lonnet::logthis($error);
12340:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12341:1): }
12342:1): } elsif ($domconfig{$action}{$itemid}{'image'}) {
12343:1): $confhash{$itemid}{'image'} =
12344:1): $domconfig{$action}{$itemid}{'image'};
12345:1): }
12346:1): if ($customadds{$i}) {
12347:1): my $name = $env{'form.ltitools_custom_name_'.$i};
12348:1): $name =~ s/(`)/'/g;
12349:1): $name =~ s/^\s+//;
12350:1): $name =~ s/\s+$//;
12351:1): my $value = $env{'form.ltitools_custom_value_'.$i};
12352:1): $value =~ s/(`)/'/g;
12353:1): $value =~ s/^\s+//;
12354:1): $value =~ s/\s+$//;
12355:1): if ($name ne '') {
12356:1): $confhash{$itemid}{'custom'}{$name} = $value;
12357:1): $changes{$itemid} = 1;
12358:1): }
12359:1): }
12360:1): my %customdels;
12361:1): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12362:1): if (@customdeletions) {
12363:1): $changes{$itemid} = 1;
12364:1): }
12365:1): map { $customdels{$_} = 1; } @customdeletions;
12366:1): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12367:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12368:1): unless ($customdels{$key}) {
12369:1): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12370:1): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12371:1): }
12372:1): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12373:1): $changes{$itemid} = 1;
12374:1): }
12375:1): }
12376:1): }
12377:1): }
12378:1): unless ($changes{$itemid}) {
12379:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12380:1): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12381:1): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12382:1): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12383:1): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12384:1): $changes{$itemid} = 1;
12385:1): last;
12386:1): }
12387:1): }
12388:1): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12389:1): $changes{$itemid} = 1;
12390:1): }
12391:1): }
12392:1): last if ($changes{$itemid});
12393:1): }
12394:1): }
12395:1): }
12396:1): }
12397:1): }
12398:1): if (@allpos > 0) {
12399:1): my $idx = 0;
12400:1): foreach my $itemid (@allpos) {
12401:1): if ($itemid ne '') {
12402:1): $confhash{$itemid}{'order'} = $idx;
12403:1): if (ref($domconfig{$action}) eq 'HASH') {
12404:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12405:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12406:1): $changes{$itemid} = 1;
12407:1): }
12408:1): }
12409:1): }
12410:1): $idx ++;
12411:1): }
12412:1): }
12413:1): }
12414:1): my %ltitoolshash = (
12415:1): $action => { %confhash }
12416:1): );
12417:1): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12418:1): $dom);
12419:1): if ($putresult eq 'ok') {
12420:1): my %ltienchash = (
12421:1): $action => { %encconfig }
12422:1): );
12423:1): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12424:1): if (keys(%changes) > 0) {
12425:1): my $cachetime = 24*60*60;
12426:1): my %ltiall = %confhash;
12427:1): foreach my $id (keys(%ltiall)) {
12428:1): if (ref($encconfig{$id}) eq 'HASH') {
12429:1): foreach my $item ('key','secret') {
12430:1): $ltiall{$id}{$item} = $encconfig{$id}{$item};
12431:1): }
12432:1): }
12433:1): }
12434:1): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12435:1): if (ref($lastactref) eq 'HASH') {
12436:1): $lastactref->{'ltitools'} = 1;
12437:1): }
12438:1): $resulttext = &mt('Changes made:').'<ul>';
12439:1): my %bynum;
12440:1): foreach my $itemid (sort(keys(%changes))) {
12441:1): my $position = $confhash{$itemid}{'order'};
12442:1): $bynum{$position} = $itemid;
12443:1): }
12444:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12445:1): my $itemid = $bynum{$pos};
12446:1): if (ref($confhash{$itemid}) ne 'HASH') {
12447:1): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12448:1): } else {
12449:1): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12450:1): if ($confhash{$itemid}{'image'}) {
12451:1): $resulttext .= ' '.
12452:1): '<img src="'.$confhash{$itemid}{'image'}.'"'.
12453:1): ' alt="'.&mt('Tool Provider icon').'" />';
12454:1): }
12455:1): $resulttext .= '</li><ul>';
12456:1): my $position = $pos + 1;
12457:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12458:1): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12459:1): if ($confhash{$itemid}{$item} ne '') {
12460:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12461:1): }
12462:1): }
12463:1): if ($encconfig{$itemid}{'key'} ne '') {
12464:1): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12465:1): }
12466:1): if ($encconfig{$itemid}{'secret'} ne '') {
12467:1): $resulttext .= '<li>'.$lt{'secret'}.': ';
12468:1): my $num = length($encconfig{$itemid}{'secret'});
12469:1): $resulttext .= ('*'x$num).'</li>';
12470:1): }
12471:1): $resulttext .= '<li>'.&mt('Configurable in course:');
12472:1): my @possconfig = ('label','title','target','linktext','explanation','append');
12473:1): my $numconfig = 0;
12474:1): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12475:1): foreach my $item (@possconfig) {
12476:1): if ($confhash{$itemid}{'crsconf'}{$item}) {
12477:1): $numconfig ++;
12478:1): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12479:1): }
12480:1): }
12481:1): }
12482:1): if (!$numconfig) {
12483:1): $resulttext .= &mt('None');
12484:1): }
12485:1): $resulttext .= '</li>';
12486:1): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12487:1): my $displaylist;
12488:1): if ($confhash{$itemid}{'display'}{'target'}) {
12489:1): $displaylist = &mt('Display target').': '.
12490:1): $confhash{$itemid}{'display'}{'target'}.',';
12491:1): }
12492:1): foreach my $size ('width','height') {
12493:1): if ($confhash{$itemid}{'display'}{$size}) {
12494:1): $displaylist .= (' 'x2).$lt{$size}.': '.
12495:1): $confhash{$itemid}{'display'}{$size}.',';
12496:1): }
12497:1): }
12498:1): if ($displaylist) {
12499:1): $displaylist =~ s/,$//;
12500:1): $resulttext .= '<li>'.$displaylist.'</li>';
12501:1): }
12502:1): foreach my $item ('linktext','explanation') {
12503:1): if ($confhash{$itemid}{'display'}{$item}) {
12504:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12505:1): }
12506:1): }
12507:1): }
12508:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12509:1): my $fieldlist;
12510:1): foreach my $field (@allfields) {
12511:1): if ($confhash{$itemid}{'fields'}{$field}) {
12512:1): $fieldlist .= (' 'x2).$lt{$field}.',';
12513:1): }
12514:1): }
12515:1): if ($fieldlist) {
12516:1): $fieldlist =~ s/,$//;
12517:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12518:1): if ($confhash{$itemid}{'incdom'}) {
12519:1): $fieldlist .= ' ('.&mt('username:domain').')';
12520:1): } else {
12521:1): $fieldlist .= ' ('.&mt('username').')';
12522:1): }
12523:1): }
12524:1): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12525:1): }
12526:1): }
12527:1): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12528:1): my $rolemaps;
12529:1): foreach my $role (@courseroles) {
12530:1): if ($confhash{$itemid}{'roles'}{$role}) {
12531:1): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12532:1): $confhash{$itemid}{'roles'}{$role}.',';
12533:1): }
12534:1): }
12535:1): if ($rolemaps) {
12536:1): $rolemaps =~ s/,$//;
12537:1): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12538:1): }
12539:1): }
12540:1): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12541:1): my $customlist;
12542:1): if (keys(%{$confhash{$itemid}{'custom'}})) {
12543:1): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12544:1): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12545:1): }
12546:1): }
12547:1): if ($customlist) {
12548:1): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12549:1): }
12550:1): }
12551:1): $resulttext .= '</ul></li>';
12552:1): }
12553:1): }
12554:1): $resulttext .= '</ul>';
12555:1): } else {
12556:1): $resulttext = &mt('No changes made.');
12557:1): }
12558:1): } else {
12559:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12560:1): }
12561:1): if ($errors) {
12562:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12563:1): $errors.'</ul>';
12564:1): }
12565:1): return $resulttext;
12566:1): }
12567:1):
12568:1): sub process_ltitools_image {
12569:1): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12570:1): my $filename = $env{'form.'.$caller.'.filename'};
12571:1): my ($error,$url);
12572:1): my ($width,$height) = (21,21);
12573:1): if ($configuserok eq 'ok') {
12574:1): if ($switchserver) {
12575:1): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12576:1): $switchserver);
12577:1): } elsif ($author_ok eq 'ok') {
12578:1): my ($result,$imageurl,$madethumb) =
12579:1): &publishlogo($r,'upload',$caller,$dom,$confname,
12580:1): "ltitools/$itemid/icon",$width,$height);
12581:1): if ($result eq 'ok') {
12582:1): if ($madethumb) {
12583:1): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12584:1): my $imagethumb = "$path/tn-".$imagefile;
12585:1): $url = $imagethumb;
12586:1): } else {
12587:1): $url = $imageurl;
12588:1): }
12589:1): } else {
12590:1): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12591:1): }
12592:1): } else {
12593: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);
12594:1): }
12595:1): } else {
12596: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);
12597:1): }
12598:1): return ($url,$error);
12599:1): }
12600:1):
12601:1): sub get_ltitools_id {
12602:1): my ($cdom,$title) = @_;
12603:1): # get lock on ltitools db
12604:1): my $lockhash = {
12605:1): lock => $env{'user.name'}.
12606:1): ':'.$env{'user.domain'},
12607:1): };
12608:1): my $tries = 0;
12609:1): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12610:1): my ($id,$error);
12611:1):
12612:1): while (($gotlock ne 'ok') && ($tries<10)) {
12613:1): $tries ++;
12614:1): sleep (0.1);
12615:1): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12616:1): }
12617:1): if ($gotlock eq 'ok') {
12618:1): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12619:1): if ($currids{'lock'}) {
12620:1): delete($currids{'lock'});
12621:1): if (keys(%currids)) {
12622:1): my @curr = sort { $a <=> $b } keys(%currids);
12623:1): if ($curr[-1] =~ /^\d+$/) {
12624:1): $id = 1 + $curr[-1];
12625:1): }
12626:1): } else {
12627:1): $id = 1;
12628:1): }
12629:1): if ($id) {
12630:1): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12631:1): $error = 'nostore';
12632:1): }
12633:1): } else {
12634:1): $error = 'nonumber';
12635:1): }
12636:1): }
12637:1): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12638:1): } else {
12639:1): $error = 'nolock';
12640:1): }
12641:1): return ($id,$error);
12642:1): }
12643:1):
1.3 raeburn 12644: sub modify_autoenroll {
1.160.6.24 raeburn 12645: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12646: my ($resulttext,%changes);
12647: my %currautoenroll;
12648: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12649: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12650: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12651: }
12652: }
12653: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12654: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12655: sender => 'Sender for notification messages',
1.160.6.68 raeburn 12656: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 12657: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12658: my @offon = ('off','on');
1.17 raeburn 12659: my $sender_uname = $env{'form.sender_uname'};
12660: my $sender_domain = $env{'form.sender_domain'};
12661: if ($sender_domain eq '') {
12662: $sender_uname = '';
12663: } elsif ($sender_uname eq '') {
12664: $sender_domain = '';
12665: }
1.129 raeburn 12666: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 12667: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
12668: $autofailsafe =~ s{^\s+|\s+$}{}g;
12669: if ($autofailsafe =~ /\D/) {
12670: undef($autofailsafe);
12671: }
1.160.6.68 raeburn 12672: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 12673: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
12674: $failsafe = 'off';
12675: undef($autofailsafe);
1.160.6.68 raeburn 12676: }
1.1 raeburn 12677: my %autoenrollhash = (
1.129 raeburn 12678: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12679: 'sender_uname' => $sender_uname,
12680: 'sender_domain' => $sender_domain,
12681: 'co-owners' => $coowners,
1.160.6.116 raeburn 12682: 'autofailsafe' => $autofailsafe,
12683: 'failsafe' => $failsafe,
1.1 raeburn 12684: }
12685: );
1.4 raeburn 12686: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12687: $dom);
1.1 raeburn 12688: if ($putresult eq 'ok') {
12689: if (exists($currautoenroll{'run'})) {
12690: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12691: $changes{'run'} = 1;
12692: }
12693: } elsif ($autorun) {
12694: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12695: $changes{'run'} = 1;
1.1 raeburn 12696: }
12697: }
1.17 raeburn 12698: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12699: $changes{'sender'} = 1;
12700: }
1.17 raeburn 12701: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12702: $changes{'sender'} = 1;
12703: }
1.129 raeburn 12704: if ($currautoenroll{'co-owners'} ne '') {
12705: if ($currautoenroll{'co-owners'} ne $coowners) {
12706: $changes{'coowners'} = 1;
12707: }
12708: } elsif ($coowners) {
12709: $changes{'coowners'} = 1;
1.160.6.68 raeburn 12710: }
1.160.6.116 raeburn 12711: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 12712: $changes{'autofailsafe'} = 1;
12713: }
1.160.6.116 raeburn 12714: if ($currautoenroll{'failsafe'} ne $failsafe) {
12715: $changes{'failsafe'} = 1;
12716: }
1.1 raeburn 12717: if (keys(%changes) > 0) {
12718: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12719: if ($changes{'run'}) {
1.1 raeburn 12720: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12721: }
12722: if ($changes{'sender'}) {
1.17 raeburn 12723: if ($sender_uname eq '' || $sender_domain eq '') {
12724: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12725: } else {
12726: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12727: }
1.1 raeburn 12728: }
1.129 raeburn 12729: if ($changes{'coowners'}) {
12730: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12731: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12732: if (ref($lastactref) eq 'HASH') {
12733: $lastactref->{'domainconfig'} = 1;
12734: }
1.129 raeburn 12735: }
1.160.6.68 raeburn 12736: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 12737: if ($autofailsafe ne '') {
12738: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 12739: } else {
1.160.6.116 raeburn 12740: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 12741: }
1.160.6.116 raeburn 12742: }
12743: if ($changes{'failsafe'}) {
12744: if ($failsafe eq 'off') {
12745: unless ($changes{'autofailsafe'}) {
12746: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
12747: }
12748: } elsif ($failsafe eq 'zero') {
12749: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
12750: } else {
12751: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
12752: }
12753: }
12754: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 12755: &Apache::lonnet::get_domain_defaults($dom,1);
12756: if (ref($lastactref) eq 'HASH') {
12757: $lastactref->{'domdefaults'} = 1;
12758: }
12759: }
1.1 raeburn 12760: $resulttext .= '</ul>';
12761: } else {
12762: $resulttext = &mt('No changes made to auto-enrollment settings');
12763: }
12764: } else {
1.11 albertel 12765: $resulttext = '<span class="LC_error">'.
12766: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12767: }
1.3 raeburn 12768: return $resulttext;
1.1 raeburn 12769: }
12770:
12771: sub modify_autoupdate {
1.3 raeburn 12772: my ($dom,%domconfig) = @_;
1.1 raeburn 12773: my ($resulttext,%currautoupdate,%fields,%changes);
12774: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12775: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12776: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12777: }
12778: }
12779: my @offon = ('off','on');
12780: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 12781: run => 'Auto-update:',
12782: classlists => 'Updates to user information in classlists?',
12783: unexpired => 'Skip updates for users without active or future roles?',
12784: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 12785: );
1.44 raeburn 12786: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12787: my %fieldtitles = &Apache::lonlocal::texthash (
12788: id => 'Student/Employee ID',
1.20 raeburn 12789: permanentemail => 'E-mail address',
1.1 raeburn 12790: lastname => 'Last Name',
12791: firstname => 'First Name',
12792: middlename => 'Middle Name',
1.132 raeburn 12793: generation => 'Generation',
1.1 raeburn 12794: );
1.142 raeburn 12795: $othertitle = &mt('All users');
1.1 raeburn 12796: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12797: $othertitle = &mt('Other users');
1.1 raeburn 12798: }
12799: foreach my $key (keys(%env)) {
12800: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12801: my ($usertype,$item) = ($1,$2);
12802: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12803: if ($usertype eq 'default') {
12804: push(@{$fields{$1}},$2);
12805: } elsif (ref($types) eq 'ARRAY') {
12806: if (grep(/^\Q$usertype\E$/,@{$types})) {
12807: push(@{$fields{$1}},$2);
12808: }
12809: }
12810: }
1.1 raeburn 12811: }
12812: }
1.131 raeburn 12813: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12814: @lockablenames = sort(@lockablenames);
12815: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12816: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12817: if (@changed) {
12818: $changes{'lockablenames'} = 1;
12819: }
12820: } else {
12821: if (@lockablenames) {
12822: $changes{'lockablenames'} = 1;
12823: }
12824: }
1.1 raeburn 12825: my %updatehash = (
12826: autoupdate => { run => $env{'form.autoupdate_run'},
12827: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 12828: unexpired => $env{'form.unexpired'},
1.1 raeburn 12829: fields => {%fields},
1.131 raeburn 12830: lockablenames => \@lockablenames,
1.1 raeburn 12831: }
12832: );
1.160.6.113 raeburn 12833: my $lastactivedays;
12834: if ($env{'form.lastactive'}) {
12835: $lastactivedays = $env{'form.lastactivedays'};
12836: $lastactivedays =~ s/^\s+|\s+$//g;
12837: unless ($lastactivedays =~ /^\d+$/) {
12838: undef($lastactivedays);
12839: $env{'form.lastactive'} = 0;
12840: }
12841: }
12842: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 12843: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 12844: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 12845: if (exists($updatehash{autoupdate}{$key})) {
12846: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12847: $changes{$key} = 1;
12848: }
12849: }
12850: } elsif ($key eq 'fields') {
12851: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12852: foreach my $item (@{$types},'default') {
1.1 raeburn 12853: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12854: my $change = 0;
12855: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12856: if (!exists($fields{$item})) {
12857: $change = 1;
1.132 raeburn 12858: last;
1.1 raeburn 12859: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12860: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12861: $change = 1;
1.132 raeburn 12862: last;
1.1 raeburn 12863: }
12864: }
12865: }
12866: if ($change) {
12867: push(@{$changes{$key}},$item);
12868: }
1.26 raeburn 12869: }
1.1 raeburn 12870: }
12871: }
1.131 raeburn 12872: } elsif ($key eq 'lockablenames') {
12873: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12874: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12875: if (@changed) {
12876: $changes{'lockablenames'} = 1;
12877: }
12878: } else {
12879: if (@lockablenames) {
12880: $changes{'lockablenames'} = 1;
12881: }
12882: }
12883: }
12884: }
12885: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12886: if (@lockablenames) {
12887: $changes{'lockablenames'} = 1;
1.1 raeburn 12888: }
12889: }
1.160.6.113 raeburn 12890: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
12891: if ($updatehash{'autoupdate'}{'unexpired'}) {
12892: $changes{'unexpired'} = 1;
12893: }
12894: }
12895: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
12896: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
12897: $changes{'lastactive'} = 1;
12898: }
12899: }
1.26 raeburn 12900: foreach my $item (@{$types},'default') {
12901: if (defined($fields{$item})) {
12902: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12903: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12904: my $change = 0;
12905: if (ref($fields{$item}) eq 'ARRAY') {
12906: foreach my $type (@{$fields{$item}}) {
12907: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12908: $change = 1;
12909: last;
12910: }
12911: }
12912: }
12913: if ($change) {
12914: push(@{$changes{'fields'}},$item);
12915: }
12916: } else {
1.26 raeburn 12917: push(@{$changes{'fields'}},$item);
12918: }
12919: } else {
12920: push(@{$changes{'fields'}},$item);
1.1 raeburn 12921: }
12922: }
12923: }
12924: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12925: $dom);
12926: if ($putresult eq 'ok') {
12927: if (keys(%changes) > 0) {
12928: $resulttext = &mt('Changes made:').'<ul>';
12929: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12930: if ($key eq 'lockablenames') {
12931: $resulttext .= '<li>';
12932: if (@lockablenames) {
12933: $usertypes->{'default'} = $othertitle;
12934: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12935: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12936: } else {
12937: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12938: }
12939: $resulttext .= '</li>';
12940: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12941: foreach my $item (@{$changes{$key}}) {
12942: my @newvalues;
12943: foreach my $type (@{$fields{$item}}) {
12944: push(@newvalues,$fieldtitles{$type});
12945: }
1.3 raeburn 12946: my $newvaluestr;
12947: if (@newvalues > 0) {
12948: $newvaluestr = join(', ',@newvalues);
12949: } else {
12950: $newvaluestr = &mt('none');
1.6 raeburn 12951: }
1.1 raeburn 12952: if ($item eq 'default') {
1.26 raeburn 12953: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12954: } else {
1.26 raeburn 12955: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12956: }
12957: }
12958: } else {
12959: my $newvalue;
12960: if ($key eq 'run') {
12961: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 12962: } elsif ($key eq 'lastactive') {
12963: $newvalue = $offon[$env{'form.lastactive'}];
12964: unless ($lastactivedays eq '') {
12965: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
12966: }
1.1 raeburn 12967: } else {
12968: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12969: }
1.1 raeburn 12970: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12971: }
12972: }
12973: $resulttext .= '</ul>';
12974: } else {
1.3 raeburn 12975: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12976: }
12977: } else {
1.11 albertel 12978: $resulttext = '<span class="LC_error">'.
12979: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12980: }
1.3 raeburn 12981: return $resulttext;
1.1 raeburn 12982: }
12983:
1.125 raeburn 12984: sub modify_autocreate {
12985: my ($dom,%domconfig) = @_;
12986: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12987: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12988: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12989: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12990: }
12991: }
12992: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12993: req => 'Auto-creation of validated requests for official courses',
12994: xmldc => 'Identity of course creator of courses from XML files',
12995: );
12996: my @types = ('xml','req');
12997: foreach my $item (@types) {
12998: $newvals{$item} = $env{'form.autocreate_'.$item};
12999: $newvals{$item} =~ s/\D//g;
13000: $newvals{$item} = 0 if ($newvals{$item} eq '');
13001: }
13002: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 13003: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13004: unless (exists($domcoords{$newvals{'xmldc'}})) {
13005: $newvals{'xmldc'} = '';
13006: }
13007: %autocreatehash = (
13008: autocreate => { xml => $newvals{'xml'},
13009: req => $newvals{'req'},
13010: }
13011: );
13012: if ($newvals{'xmldc'} ne '') {
13013: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13014: }
13015: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13016: $dom);
13017: if ($putresult eq 'ok') {
13018: my @items = @types;
13019: if ($newvals{'xml'}) {
13020: push(@items,'xmldc');
13021: }
13022: foreach my $item (@items) {
13023: if (exists($currautocreate{$item})) {
13024: if ($currautocreate{$item} ne $newvals{$item}) {
13025: $changes{$item} = 1;
13026: }
13027: } elsif ($newvals{$item}) {
13028: $changes{$item} = 1;
13029: }
13030: }
13031: if (keys(%changes) > 0) {
13032: my @offon = ('off','on');
13033: $resulttext = &mt('Changes made:').'<ul>';
13034: foreach my $item (@types) {
13035: if ($changes{$item}) {
13036: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 13037: $resulttext .= '<li>'.
13038: &mt("$title{$item} set to [_1]$newtxt [_2]",
13039: '<b>','</b>').
13040: '</li>';
1.125 raeburn 13041: }
13042: }
13043: if ($changes{'xmldc'}) {
13044: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13045: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 13046: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13047: }
13048: $resulttext .= '</ul>';
13049: } else {
13050: $resulttext = &mt('No changes made to auto-creation settings');
13051: }
13052: } else {
13053: $resulttext = '<span class="LC_error">'.
13054: &mt('An error occurred: [_1]',$putresult).'</span>';
13055: }
13056: return $resulttext;
13057: }
13058:
1.23 raeburn 13059: sub modify_directorysrch {
1.160.6.81 raeburn 13060: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13061: my ($resulttext,%changes);
13062: my %currdirsrch;
13063: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13064: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13065: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13066: }
13067: }
1.160.6.72 raeburn 13068: my %title = ( available => 'Institutional directory search available',
13069: localonly => 'Other domains can search institution',
13070: lcavailable => 'LON-CAPA directory search available',
13071: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13072: searchby => 'Search types',
13073: searchtypes => 'Search latitude');
13074: my @offon = ('off','on');
1.24 raeburn 13075: my @otherdoms = ('Yes','No');
1.23 raeburn 13076:
1.25 raeburn 13077: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13078: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13079: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13080:
1.44 raeburn 13081: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13082: if (keys(%{$usertypes}) == 0) {
13083: @cansearch = ('default');
13084: } else {
13085: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13086: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13087: if (!grep(/^\Q$type\E$/,@cansearch)) {
13088: push(@{$changes{'cansearch'}},$type);
13089: }
1.23 raeburn 13090: }
1.26 raeburn 13091: foreach my $type (@cansearch) {
13092: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13093: push(@{$changes{'cansearch'}},$type);
13094: }
1.23 raeburn 13095: }
1.26 raeburn 13096: } else {
13097: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13098: }
13099: }
13100:
13101: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13102: foreach my $by (@{$currdirsrch{'searchby'}}) {
13103: if (!grep(/^\Q$by\E$/,@searchby)) {
13104: push(@{$changes{'searchby'}},$by);
13105: }
13106: }
13107: foreach my $by (@searchby) {
13108: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13109: push(@{$changes{'searchby'}},$by);
13110: }
13111: }
13112: } else {
13113: push(@{$changes{'searchby'}},@searchby);
13114: }
1.25 raeburn 13115:
13116: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13117: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13118: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13119: push(@{$changes{'searchtypes'}},$type);
13120: }
13121: }
13122: foreach my $type (@searchtypes) {
13123: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13124: push(@{$changes{'searchtypes'}},$type);
13125: }
13126: }
13127: } else {
13128: if (exists($currdirsrch{'searchtypes'})) {
13129: foreach my $type (@searchtypes) {
13130: if ($type ne $currdirsrch{'searchtypes'}) {
13131: push(@{$changes{'searchtypes'}},$type);
13132: }
13133: }
13134: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13135: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13136: }
13137: } else {
13138: push(@{$changes{'searchtypes'}},@searchtypes);
13139: }
13140: }
13141:
1.23 raeburn 13142: my %dirsrch_hash = (
13143: directorysrch => { available => $env{'form.dirsrch_available'},
13144: cansearch => \@cansearch,
1.160.6.72 raeburn 13145: localonly => $env{'form.dirsrch_instlocalonly'},
13146: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13147: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13148: searchby => \@searchby,
1.25 raeburn 13149: searchtypes => \@searchtypes,
1.23 raeburn 13150: }
13151: );
13152: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13153: $dom);
13154: if ($putresult eq 'ok') {
13155: if (exists($currdirsrch{'available'})) {
13156: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13157: $changes{'available'} = 1;
13158: }
13159: } else {
13160: if ($env{'form.dirsrch_available'} eq '1') {
13161: $changes{'available'} = 1;
13162: }
13163: }
1.160.6.72 raeburn 13164: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 13165: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13166: $changes{'lcavailable'} = 1;
13167: }
1.24 raeburn 13168: } else {
1.160.6.72 raeburn 13169: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13170: $changes{'lcavailable'} = 1;
13171: }
13172: }
13173: if (exists($currdirsrch{'localonly'})) {
13174: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 13175: $changes{'localonly'} = 1;
13176: }
1.160.6.72 raeburn 13177: } else {
13178: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13179: $changes{'localonly'} = 1;
13180: }
13181: }
13182: if (exists($currdirsrch{'lclocalonly'})) {
13183: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13184: $changes{'lclocalonly'} = 1;
13185: }
13186: } else {
13187: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13188: $changes{'lclocalonly'} = 1;
13189: }
1.24 raeburn 13190: }
1.23 raeburn 13191: if (keys(%changes) > 0) {
13192: $resulttext = &mt('Changes made:').'<ul>';
13193: if ($changes{'available'}) {
13194: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13195: }
1.160.6.72 raeburn 13196: if ($changes{'lcavailable'}) {
13197: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13198: }
1.24 raeburn 13199: if ($changes{'localonly'}) {
1.160.6.72 raeburn 13200: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13201: }
13202: if ($changes{'lclocalonly'}) {
13203: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 13204: }
1.23 raeburn 13205: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13206: my $chgtext;
1.26 raeburn 13207: if (ref($usertypes) eq 'HASH') {
13208: if (keys(%{$usertypes}) > 0) {
13209: foreach my $type (@{$types}) {
13210: if (grep(/^\Q$type\E$/,@cansearch)) {
13211: $chgtext .= $usertypes->{$type}.'; ';
13212: }
13213: }
13214: if (grep(/^default$/,@cansearch)) {
13215: $chgtext .= $othertitle;
13216: } else {
13217: $chgtext =~ s/\; $//;
13218: }
1.160.6.13 raeburn 13219: $resulttext .=
13220: '<li>'.
13221: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13222: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13223: '</li>';
1.23 raeburn 13224: }
13225: }
13226: }
13227: if (ref($changes{'searchby'}) eq 'ARRAY') {
13228: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13229: my $chgtext;
13230: foreach my $type (@{$titleorder}) {
13231: if (grep(/^\Q$type\E$/,@searchby)) {
13232: if (defined($searchtitles->{$type})) {
13233: $chgtext .= $searchtitles->{$type}.'; ';
13234: }
13235: }
13236: }
13237: $chgtext =~ s/\; $//;
13238: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13239: }
1.25 raeburn 13240: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13241: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13242: my $chgtext;
13243: foreach my $type (@{$srchtypeorder}) {
13244: if (grep(/^\Q$type\E$/,@searchtypes)) {
13245: if (defined($srchtypes_desc->{$type})) {
13246: $chgtext .= $srchtypes_desc->{$type}.'; ';
13247: }
13248: }
13249: }
13250: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 13251: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13252: }
13253: $resulttext .= '</ul>';
1.160.6.81 raeburn 13254: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13255: if (ref($lastactref) eq 'HASH') {
13256: $lastactref->{'directorysrch'} = 1;
13257: }
1.23 raeburn 13258: } else {
1.160.6.72 raeburn 13259: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13260: }
13261: } else {
13262: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13263: &mt('An error occurred: [_1]',$putresult).'</span>';
13264: }
13265: return $resulttext;
13266: }
13267:
1.28 raeburn 13268: sub modify_contacts {
1.160.6.24 raeburn 13269: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13270: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13271: if (ref($domconfig{'contacts'}) eq 'HASH') {
13272: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13273: $currsetting{$key} = $domconfig{'contacts'}{$key};
13274: }
13275: }
1.160.6.78 raeburn 13276: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13277: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 13278: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 13279: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 13280: my @toggles = ('reporterrors','reportupdates','reportstatus');
13281: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 13282: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13283: foreach my $type (@mailings) {
13284: @{$newsetting{$type}} =
13285: &Apache::loncommon::get_env_multiple('form.'.$type);
13286: foreach my $item (@contacts) {
13287: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13288: $contacts_hash{contacts}{$type}{$item} = 1;
13289: } else {
13290: $contacts_hash{contacts}{$type}{$item} = 0;
13291: }
1.160.6.78 raeburn 13292: }
1.28 raeburn 13293: $others{$type} = $env{'form.'.$type.'_others'};
13294: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 13295: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13296: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13297: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 13298: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13299: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13300: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13301: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13302: }
1.134 raeburn 13303: }
1.28 raeburn 13304: }
13305: foreach my $item (@contacts) {
13306: $to{$item} = $env{'form.'.$item};
13307: $contacts_hash{'contacts'}{$item} = $to{$item};
13308: }
1.160.6.23 raeburn 13309: foreach my $item (@toggles) {
13310: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13311: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13312: }
13313: }
1.160.6.107 raeburn 13314: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13315: foreach my $item (@lonstatus) {
13316: if ($item eq 'excluded') {
13317: my (%serverhomes,@excluded);
13318: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13319: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13320: if (@possexcluded) {
13321: foreach my $id (sort(@possexcluded)) {
13322: if ($serverhomes{$id}) {
13323: push(@excluded,$id);
13324: }
13325: }
13326: }
13327: if (@excluded) {
13328: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13329: }
13330: } elsif ($item eq 'weights') {
13331: foreach my $type ('E','W','N','U') {
13332: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13333: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13334: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13335: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13336: $env{'form.error'.$item.'_'.$type};
13337: }
13338: }
13339: }
13340: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13341: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13342: if ($env{'form.error'.$item} =~ /^\d+$/) {
13343: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13344: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13345: }
13346: }
13347: }
13348: }
1.160.6.78 raeburn 13349: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13350: foreach my $field (@{$fields}) {
13351: if (ref($possoptions->{$field}) eq 'ARRAY') {
13352: my $value = $env{'form.helpform_'.$field};
13353: $value =~ s/^\s+|\s+$//g;
13354: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 13355: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 13356: if ($field eq 'screenshot') {
13357: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13358: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 13359: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 13360: }
13361: }
13362: }
13363: }
13364: }
13365: }
1.160.6.101 raeburn 13366: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13367: my (@statuses,%usertypeshash,@overrides);
13368: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13369: @statuses = @{$types};
13370: if (ref($usertypes) eq 'HASH') {
13371: %usertypeshash = %{$usertypes};
13372: }
13373: }
13374: if (@statuses) {
13375: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13376: foreach my $type (@possoverrides) {
13377: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13378: push(@overrides,$type);
13379: }
13380: }
13381: if (@overrides) {
13382: foreach my $type (@overrides) {
13383: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13384: foreach my $item (@contacts) {
13385: if (grep(/^\Q$item\E$/,@standard)) {
13386: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13387: $newsetting{'override_'.$type}{$item} = 1;
13388: } else {
13389: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13390: $newsetting{'override_'.$type}{$item} = 0;
13391: }
13392: }
13393: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13394: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13395: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13396: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13397: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13398: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13399: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13400: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13401: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13402: }
13403: }
13404: }
13405: }
1.28 raeburn 13406: if (keys(%currsetting) > 0) {
13407: foreach my $item (@contacts) {
13408: if ($to{$item} ne $currsetting{$item}) {
13409: $changes{$item} = 1;
13410: }
13411: }
13412: foreach my $type (@mailings) {
13413: foreach my $item (@contacts) {
13414: if (ref($currsetting{$type}) eq 'HASH') {
13415: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13416: push(@{$changes{$type}},$item);
13417: }
13418: } else {
13419: push(@{$changes{$type}},@{$newsetting{$type}});
13420: }
13421: }
13422: if ($others{$type} ne $currsetting{$type}{'others'}) {
13423: push(@{$changes{$type}},'others');
13424: }
1.160.6.78 raeburn 13425: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13426: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13427: push(@{$changes{$type}},'bcc');
13428: }
1.160.6.78 raeburn 13429: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13430: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13431: push(@{$changes{$type}},'include');
13432: }
13433: }
13434: }
13435: if (ref($fields) eq 'ARRAY') {
13436: if (ref($currsetting{'helpform'}) eq 'HASH') {
13437: foreach my $field (@{$fields}) {
13438: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13439: push(@{$changes{'helpform'}},$field);
13440: }
13441: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13442: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13443: push(@{$changes{'helpform'}},'maxsize');
13444: }
13445: }
13446: }
13447: } else {
13448: foreach my $field (@{$fields}) {
13449: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13450: push(@{$changes{'helpform'}},$field);
13451: }
13452: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13453: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13454: push(@{$changes{'helpform'}},'maxsize');
13455: }
13456: }
13457: }
1.134 raeburn 13458: }
1.28 raeburn 13459: }
1.160.6.101 raeburn 13460: if (@statuses) {
13461: if (ref($currsetting{'overrides'}) eq 'HASH') {
13462: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13463: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13464: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13465: foreach my $item (@contacts,'bcc','others','include') {
13466: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13467: push(@{$changes{'overrides'}},$key);
13468: last;
13469: }
13470: }
13471: } else {
13472: push(@{$changes{'overrides'}},$key);
13473: }
13474: }
13475: }
13476: foreach my $key (@overrides) {
13477: unless (exists($currsetting{'overrides'}{$key})) {
13478: push(@{$changes{'overrides'}},$key);
13479: }
13480: }
13481: } else {
13482: foreach my $key (@overrides) {
13483: push(@{$changes{'overrides'}},$key);
13484: }
13485: }
13486: }
1.160.6.107 raeburn 13487: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13488: foreach my $key ('excluded','weights','threshold','sysmail') {
13489: if ($key eq 'excluded') {
13490: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13491: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13492: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13493: (@{$currsetting{'lonstatus'}{$key}})) {
13494: my @diffs =
13495: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13496: $currsetting{'lonstatus'}{$key});
13497: if (@diffs) {
13498: push(@{$changes{'lonstatus'}},$key);
13499: }
13500: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13501: push(@{$changes{'lonstatus'}},$key);
13502: }
13503: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13504: (@{$currsetting{'lonstatus'}{$key}})) {
13505: push(@{$changes{'lonstatus'}},$key);
13506: }
13507: } elsif ($key eq 'weights') {
13508: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13509: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13510: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
13511: foreach my $type ('E','W','N','U') {
13512: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13513: $currsetting{'lonstatus'}{$key}{$type}) {
13514: push(@{$changes{'lonstatus'}},$key);
13515: last;
13516: }
13517: }
13518: } else {
13519: foreach my $type ('E','W','N','U') {
13520: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13521: push(@{$changes{'lonstatus'}},$key);
13522: last;
13523: }
13524: }
13525: }
13526: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
13527: foreach my $type ('E','W','N','U') {
13528: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13529: push(@{$changes{'lonstatus'}},$key);
13530: last;
13531: }
13532: }
13533: }
13534: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13535: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13536: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13537: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13538: push(@{$changes{'lonstatus'}},$key);
13539: }
13540: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13541: push(@{$changes{'lonstatus'}},$key);
13542: }
13543: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13544: push(@{$changes{'lonstatus'}},$key);
13545: }
13546: }
13547: }
13548: } else {
13549: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13550: foreach my $key ('excluded','weights','threshold','sysmail') {
13551: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13552: push(@{$changes{'lonstatus'}},$key);
13553: }
13554: }
13555: }
13556: }
1.28 raeburn 13557: } else {
13558: my %default;
13559: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13560: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13561: $default{'errormail'} = 'adminemail';
13562: $default{'packagesmail'} = 'adminemail';
13563: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 13564: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13565: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13566: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 13567: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 13568: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13569: foreach my $item (@contacts) {
13570: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 13571: $changes{$item} = 1;
1.160.6.23 raeburn 13572: }
1.28 raeburn 13573: }
13574: foreach my $type (@mailings) {
13575: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13576: push(@{$changes{$type}},@{$newsetting{$type}});
13577: }
13578: if ($others{$type} ne '') {
13579: push(@{$changes{$type}},'others');
1.134 raeburn 13580: }
1.160.6.78 raeburn 13581: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13582: if ($bcc{$type} ne '') {
13583: push(@{$changes{$type}},'bcc');
13584: }
1.160.6.78 raeburn 13585: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13586: push(@{$changes{$type}},'include');
13587: }
13588: }
13589: }
13590: if (ref($fields) eq 'ARRAY') {
13591: foreach my $field (@{$fields}) {
13592: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13593: push(@{$changes{'helpform'}},$field);
13594: }
13595: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13596: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13597: push(@{$changes{'helpform'}},'maxsize');
13598: }
13599: }
1.134 raeburn 13600: }
1.28 raeburn 13601: }
1.160.6.107 raeburn 13602: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13603: foreach my $key ('excluded','weights','threshold','sysmail') {
13604: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13605: push(@{$changes{'lonstatus'}},$key);
13606: }
13607: }
13608: }
1.28 raeburn 13609: }
1.160.6.23 raeburn 13610: foreach my $item (@toggles) {
13611: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13612: $changes{$item} = 1;
13613: } elsif ((!$env{'form.'.$item}) &&
13614: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13615: $changes{$item} = 1;
13616: }
13617: }
1.28 raeburn 13618: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13619: $dom);
13620: if ($putresult eq 'ok') {
13621: if (keys(%changes) > 0) {
1.160.6.24 raeburn 13622: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13623: if (ref($lastactref) eq 'HASH') {
13624: $lastactref->{'domainconfig'} = 1;
13625: }
1.28 raeburn 13626: my ($titles,$short_titles) = &contact_titles();
13627: $resulttext = &mt('Changes made:').'<ul>';
13628: foreach my $item (@contacts) {
13629: if ($changes{$item}) {
13630: $resulttext .= '<li>'.$titles->{$item}.
13631: &mt(' set to: ').
13632: '<span class="LC_cusr_emph">'.
13633: $to{$item}.'</span></li>';
13634: }
13635: }
13636: foreach my $type (@mailings) {
13637: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 13638: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
13639: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
13640: } else {
13641: $resulttext .= '<li>'.$titles->{$type}.': ';
13642: }
1.28 raeburn 13643: my @text;
13644: foreach my $item (@{$newsetting{$type}}) {
13645: push(@text,$short_titles->{$item});
13646: }
13647: if ($others{$type} ne '') {
13648: push(@text,$others{$type});
13649: }
1.160.6.78 raeburn 13650: if (@text) {
13651: $resulttext .= '<span class="LC_cusr_emph">'.
13652: join(', ',@text).'</span>';
13653: }
13654: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13655: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 13656: my $bcctext;
13657: if (@text) {
13658: $bcctext = ' '.&mt('with Bcc to');
13659: } else {
13660: $bcctext = '(Bcc)';
13661: }
13662: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13663: } elsif (!@text) {
13664: $resulttext .= &mt('No one');
1.134 raeburn 13665: }
1.160.6.78 raeburn 13666: if ($includestr{$type} ne '') {
13667: if ($includeloc{$type} eq 'b') {
13668: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13669: } elsif ($includeloc{$type} eq 's') {
13670: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13671: }
13672: }
13673: } elsif (!@text) {
13674: $resulttext .= &mt('No recipients');
1.134 raeburn 13675: }
13676: $resulttext .= '</li>';
1.28 raeburn 13677: }
13678: }
1.160.6.101 raeburn 13679: if (ref($changes{'overrides'}) eq 'ARRAY') {
13680: my @deletions;
13681: foreach my $type (@{$changes{'overrides'}}) {
13682: if ($usertypeshash{$type}) {
13683: if (grep(/^\Q$type\E/,@overrides)) {
13684: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13685: $usertypeshash{$type}).'<ul><li>';
13686: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13687: my @text;
13688: foreach my $item (@contacts) {
13689: if ($newsetting{'override_'.$type}{$item}) {
13690: push(@text,$short_titles->{$item});
13691: }
13692: }
13693: if ($newsetting{'override_'.$type}{'others'} ne '') {
13694: push(@text,$newsetting{'override_'.$type}{'others'});
13695: }
13696:
13697: if (@text) {
13698: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13699: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13700: }
13701: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13702: my $bcctext;
13703: if (@text) {
13704: $bcctext = ' '.&mt('with Bcc to');
13705: } else {
13706: $bcctext = '(Bcc)';
13707: }
13708: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13709: } elsif (!@text) {
13710: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13711: }
13712: $resulttext .= '</li>';
13713: if ($newsetting{'override_'.$type}{'include'} ne '') {
13714: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13715: if ($loc eq 'b') {
13716: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13717: } elsif ($loc eq 's') {
13718: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13719: }
13720: }
13721: }
13722: $resulttext .= '</li></ul></li>';
13723: } else {
13724: push(@deletions,$usertypeshash{$type});
13725: }
13726: }
13727: }
13728: if (@deletions) {
13729: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13730: join(', ',@deletions)).'</li>';
13731: }
13732: }
1.160.6.23 raeburn 13733: my @offon = ('off','on');
1.160.6.107 raeburn 13734: my $corelink = &core_link_msu();
1.160.6.23 raeburn 13735: if ($changes{'reporterrors'}) {
13736: $resulttext .= '<li>'.
13737: &mt('E-mail error reports to [_1] set to "'.
13738: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 13739: $corelink).
1.160.6.23 raeburn 13740: '</li>';
13741: }
13742: if ($changes{'reportupdates'}) {
13743: $resulttext .= '<li>'.
13744: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13745: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 13746: $corelink).
1.160.6.23 raeburn 13747: '</li>';
13748: }
1.160.6.107 raeburn 13749: if ($changes{'reportstatus'}) {
13750: $resulttext .= '<li>'.
13751: &mt('E-mail status if errors above threshold to [_1] set to "'.
13752: $offon[$env{'form.reportstatus'}].'".',
13753: $corelink).
13754: '</li>';
13755: }
13756: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13757: $resulttext .= '<li>'.
13758: &mt('Nightly status check e-mail settings').':<ul>';
13759: my (%defval,%use_def,%shown);
13760: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13761: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13762: $defval{'weights'} =
13763: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
13764: $defval{'excluded'} = &mt('None');
13765: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13766: foreach my $item ('threshold','sysmail','weights','excluded') {
13767: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13768: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13769: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13770: } elsif ($item eq 'weights') {
13771: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
13772: foreach my $type ('E','W','N','U') {
13773: $shown{$item} .= $lonstatus_names->{$type}.'=';
13774: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13775: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13776: } else {
13777: $shown{$item} .= $lonstatus_defs->{$type};
13778: }
13779: $shown{$item} .= ', ';
13780: }
13781: $shown{$item} =~ s/, $//;
13782: } else {
13783: $shown{$item} = $defval{$item};
13784: }
13785: } elsif ($item eq 'excluded') {
13786: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13787: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13788: } else {
13789: $shown{$item} = $defval{$item};
13790: }
13791: }
13792: } else {
13793: $shown{$item} = $defval{$item};
13794: }
13795: }
13796: } else {
13797: foreach my $item ('threshold','weights','excluded','sysmail') {
13798: $shown{$item} = $defval{$item};
13799: }
13800: }
13801: foreach my $item ('threshold','weights','excluded','sysmail') {
13802: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13803: $shown{$item}).'</li>';
13804: }
13805: $resulttext .= '</ul></li>';
13806: }
1.160.6.78 raeburn 13807: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13808: my (@optional,@required,@unused,$maxsizechg);
13809: foreach my $field (@{$changes{'helpform'}}) {
13810: if ($field eq 'maxsize') {
13811: $maxsizechg = 1;
13812: next;
13813: }
13814: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
13815: push(@optional,$field);
13816: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13817: push(@unused,$field);
13818: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
13819: push(@required,$field);
13820: }
13821: }
13822: if (@optional) {
13823: $resulttext .= '<li>'.
13824: &mt('Help form fields changed to "Optional": [_1].',
13825: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13826: '</li>';
13827: }
13828: if (@required) {
13829: $resulttext .= '<li>'.
13830: &mt('Help form fields changed to "Required": [_1].',
13831: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13832: '</li>';
13833: }
13834: if (@unused) {
13835: $resulttext .= '<li>'.
13836: &mt('Help form fields changed to "Not shown": [_1].',
13837: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13838: '</li>';
13839: }
13840: if ($maxsizechg) {
13841: $resulttext .= '<li>'.
13842: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13843: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13844: '</li>';
13845: }
13846: }
1.28 raeburn 13847: $resulttext .= '</ul>';
13848: } else {
1.160.6.78 raeburn 13849: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13850: }
13851: } else {
13852: $resulttext = '<span class="LC_error">'.
13853: &mt('An error occurred: [_1].',$putresult).'</span>';
13854: }
13855: return $resulttext;
13856: }
13857:
1.160.6.98 raeburn 13858: sub modify_passwords {
13859: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
13860: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
13861: $updatedefaults,$updateconf);
13862: my $customfn = 'resetpw.html';
13863: if (ref($domconfig{'passwords'}) eq 'HASH') {
13864: %current = %{$domconfig{'passwords'}};
13865: }
13866: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13867: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13868: if (ref($types) eq 'ARRAY') {
13869: @oktypes = @{$types};
13870: }
13871: push(@oktypes,'default');
13872:
13873: my %titles = &Apache::lonlocal::texthash (
13874: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
13875: intauth_check => 'Check bcrypt cost if authenticated',
13876: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
13877: permanent => 'Permanent e-mail address',
13878: critical => 'Critical notification address',
13879: notify => 'Notification address',
13880: min => 'Minimum password length',
13881: max => 'Maximum password length',
13882: chars => 'Required characters',
13883: numsaved => 'Number of previous passwords to save',
13884: reset => 'Resetting Forgotten Password',
13885: intauth => 'Encryption of Stored Passwords (Internal Auth)',
13886: rules => 'Rules for LON-CAPA Passwords',
13887: crsownerchg => 'Course Owner Changing Student Passwords',
13888: username => 'Username',
13889: email => 'E-mail address',
13890: );
13891:
13892: #
13893: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
13894: #
13895: my (%curr_defaults,%save_defaults);
13896: if (ref($domconfig{'defaults'}) eq 'HASH') {
13897: foreach my $key (keys(%{$domconfig{'defaults'}})) {
13898: if ($key =~ /^intauth_(cost|check|switch)$/) {
13899: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
13900: } else {
13901: $save_defaults{$key} = $domconfig{'defaults'}{$key};
13902: }
13903: }
13904: }
13905: my %staticdefaults = (
13906: 'resetlink' => 2,
13907: 'resetcase' => \@oktypes,
13908: 'resetprelink' => 'both',
13909: 'resetemail' => ['critical','notify','permanent'],
13910: 'intauth_cost' => 10,
13911: 'intauth_check' => 0,
13912: 'intauth_switch' => 0,
13913: );
1.160.6.99 raeburn 13914: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 13915: foreach my $type (@oktypes) {
13916: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
13917: }
13918: my $linklife = $env{'form.passwords_link'};
13919: $linklife =~ s/^\s+|\s+$//g;
13920: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
13921: $newvalues{'resetlink'} = $linklife;
13922: if ($current{'resetlink'}) {
13923: if ($current{'resetlink'} ne $linklife) {
13924: $changes{'reset'} = 1;
13925: }
1.160.6.102 raeburn 13926: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13927: if ($staticdefaults{'resetlink'} ne $linklife) {
13928: $changes{'reset'} = 1;
13929: }
13930: }
13931: } elsif ($current{'resetlink'}) {
13932: $changes{'reset'} = 1;
13933: }
13934: my @casesens;
13935: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
13936: foreach my $case (sort(@posscase)) {
13937: if (grep(/^\Q$case\E$/,@oktypes)) {
13938: push(@casesens,$case);
13939: }
13940: }
13941: $newvalues{'resetcase'} = \@casesens;
13942: if (ref($current{'resetcase'}) eq 'ARRAY') {
13943: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
13944: if (@diffs > 0) {
13945: $changes{'reset'} = 1;
13946: }
1.160.6.102 raeburn 13947: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13948: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
13949: if (@diffs > 0) {
13950: $changes{'reset'} = 1;
13951: }
13952: }
13953: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
13954: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
13955: if (exists($current{'resetprelink'})) {
13956: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
13957: $changes{'reset'} = 1;
13958: }
1.160.6.102 raeburn 13959: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13960: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
13961: $changes{'reset'} = 1;
13962: }
13963: }
13964: } elsif ($current{'resetprelink'}) {
13965: $changes{'reset'} = 1;
13966: }
13967: foreach my $type (@oktypes) {
13968: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
13969: my @postlink;
13970: foreach my $item (sort(@possplink)) {
13971: if ($item =~ /^(email|username)$/) {
13972: push(@postlink,$item);
13973: }
13974: }
13975: $newvalues{'resetpostlink'}{$type} = \@postlink;
13976: unless ($changes{'reset'}) {
13977: if (ref($current{'resetpostlink'}) eq 'HASH') {
13978: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
13979: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
13980: if (@diffs > 0) {
13981: $changes{'reset'} = 1;
13982: }
13983: } else {
13984: $changes{'reset'} = 1;
13985: }
1.160.6.102 raeburn 13986: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13987: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
13988: if (@diffs > 0) {
13989: $changes{'reset'} = 1;
13990: }
13991: }
13992: }
13993: }
13994: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
13995: my @resetemail;
13996: foreach my $item (sort(@possemailsrc)) {
13997: if ($item =~ /^(permanent|critical|notify)$/) {
13998: push(@resetemail,$item);
13999: }
14000: }
14001: $newvalues{'resetemail'} = \@resetemail;
14002: unless ($changes{'reset'}) {
14003: if (ref($current{'resetemail'}) eq 'ARRAY') {
14004: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14005: if (@diffs > 0) {
14006: $changes{'reset'} = 1;
14007: }
1.160.6.102 raeburn 14008: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14009: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14010: if (@diffs > 0) {
14011: $changes{'reset'} = 1;
14012: }
14013: }
14014: }
14015: if ($env{'form.passwords_stdtext'} == 0) {
14016: $newvalues{'resetremove'} = 1;
14017: unless ($current{'resetremove'}) {
14018: $changes{'reset'} = 1;
14019: }
14020: } elsif ($current{'resetremove'}) {
14021: $changes{'reset'} = 1;
14022: }
14023: if ($env{'form.passwords_customfile.filename'} ne '') {
14024: my $servadm = $r->dir_config('lonAdmEMail');
14025: my $servadm = $r->dir_config('lonAdmEMail');
14026: my ($configuserok,$author_ok,$switchserver) =
14027: &config_check($dom,$confname,$servadm);
14028: my $error;
14029: if ($configuserok eq 'ok') {
14030: if ($switchserver) {
14031: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14032: } else {
14033: if ($author_ok eq 'ok') {
14034: my ($result,$customurl) =
14035: &publishlogo($r,'upload','passwords_customfile',$dom,
14036: $confname,'customtext/resetpw','','',$customfn);
14037: if ($result eq 'ok') {
14038: $newvalues{'resetcustom'} = $customurl;
14039: $changes{'reset'} = 1;
14040: } else {
14041: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14042: }
14043: } else {
14044: $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);
14045: }
14046: }
14047: } else {
14048: $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);
14049: }
14050: if ($error) {
14051: &Apache::lonnet::logthis($error);
14052: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14053: }
14054: } elsif ($current{'resetcustom'}) {
14055: if ($env{'form.passwords_custom_del'}) {
14056: $changes{'reset'} = 1;
14057: } else {
14058: $newvalues{'resetcustom'} = $current{'resetcustom'};
14059: }
14060: }
14061: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14062: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14063: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14064: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14065: $changes{'intauth'} = 1;
14066: }
14067: } else {
14068: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14069: }
14070: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14071: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14072: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14073: $changes{'intauth'} = 1;
14074: }
14075: } else {
14076: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14077: }
14078: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14079: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14080: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14081: $changes{'intauth'} = 1;
14082: }
14083: } else {
14084: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14085: }
14086: foreach my $item ('cost','check','switch') {
14087: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14088: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14089: $updatedefaults = 1;
14090: }
14091: }
14092: foreach my $rule ('min','max','numsaved') {
14093: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 14094: my $ruleok;
14095: if ($rule eq 'min') {
14096: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
14097: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
14098: $ruleok = 1;
14099: }
14100: }
14101: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
14102: ($env{'form.passwords_'.$rule} ne '0')) {
14103: $ruleok = 1;
14104: }
14105: if ($ruleok) {
1.160.6.98 raeburn 14106: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14107: if (exists($current{$rule})) {
14108: if ($newvalues{$rule} ne $current{$rule}) {
14109: $changes{'rules'} = 1;
14110: }
14111: } elsif ($rule eq 'min') {
14112: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14113: $changes{'rules'} = 1;
14114: }
1.160.6.104 raeburn 14115: } else {
14116: $changes{'rules'} = 1;
1.160.6.98 raeburn 14117: }
14118: } elsif (exists($current{$rule})) {
14119: $changes{'rules'} = 1;
14120: }
14121: }
14122: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14123: my @chars;
14124: foreach my $item (sort(@posschars)) {
14125: if ($item =~ /^(uc|lc|num|spec)$/) {
14126: push(@chars,$item);
14127: }
14128: }
14129: $newvalues{'chars'} = \@chars;
14130: unless ($changes{'rules'}) {
14131: if (ref($current{'chars'}) eq 'ARRAY') {
14132: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14133: if (@diffs > 0) {
14134: $changes{'rules'} = 1;
14135: }
14136: } else {
14137: if (@chars > 0) {
14138: $changes{'rules'} = 1;
14139: }
14140: }
14141: }
14142: my %crsownerchg = (
14143: by => [],
14144: for => [],
14145: );
14146: foreach my $item ('by','for') {
14147: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14148: foreach my $type (sort(@posstypes)) {
14149: if (grep(/^\Q$type\E$/,@oktypes)) {
14150: push(@{$crsownerchg{$item}},$type);
14151: }
14152: }
14153: }
14154: $newvalues{'crsownerchg'} = \%crsownerchg;
14155: if (ref($current{'crsownerchg'}) eq 'HASH') {
14156: foreach my $item ('by','for') {
14157: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14158: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14159: if (@diffs > 0) {
14160: $changes{'crsownerchg'} = 1;
14161: last;
14162: }
14163: }
14164: }
1.160.6.102 raeburn 14165: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 14166: foreach my $item ('by','for') {
14167: if (@{$crsownerchg{$item}} > 0) {
14168: $changes{'crsownerchg'} = 1;
14169: last;
14170: }
14171: }
14172: }
14173:
14174: my %confighash = (
14175: defaults => \%save_defaults,
14176: passwords => \%newvalues,
14177: );
14178: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14179:
14180: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14181: if ($putresult eq 'ok') {
14182: if (keys(%changes) > 0) {
14183: $resulttext = &mt('Changes made: ').'<ul>';
14184: foreach my $key ('reset','intauth','rules','crsownerchg') {
14185: if ($changes{$key}) {
14186: unless ($key eq 'intauth') {
14187: $updateconf = 1;
14188: }
14189: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14190: if ($key eq 'reset') {
14191: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14192: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14193: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14194: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 14195: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14196: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14197: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14198: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14199: }
1.160.6.98 raeburn 14200: } else {
14201: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14202: }
14203: if ($confighash{'passwords'}{'resetlink'}) {
14204: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14205: } else {
14206: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14207: &mt('Will default to 2 hours').'</li>';
14208: }
14209: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14210: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14211: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14212: } else {
14213: my $casesens;
14214: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14215: if ($type eq 'default') {
14216: $casesens .= $othertitle.', ';
14217: } elsif ($usertypes->{$type} ne '') {
14218: $casesens .= $usertypes->{$type}.', ';
14219: }
14220: }
14221: $casesens =~ s/\Q, \E$//;
14222: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14223: }
14224: } else {
14225: $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>';
14226: }
14227: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14228: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14229: } else {
14230: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14231: }
14232: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14233: my $output;
14234: if (ref($types) eq 'ARRAY') {
14235: foreach my $type (@{$types}) {
14236: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14237: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14238: $output .= $usertypes->{$type}.' -- '.&mt('none');
14239: } else {
14240: $output .= $usertypes->{$type}.' -- '.
14241: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14242: }
14243: }
14244: }
14245: }
14246: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14247: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14248: $output .= $othertitle.' -- '.&mt('none');
14249: } else {
14250: $output .= $othertitle.' -- '.
14251: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14252: }
14253: }
14254: if ($output) {
14255: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14256: } else {
14257: $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>';
14258: }
14259: } else {
14260: $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>';
14261: }
14262: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14263: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14264: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14265: } else {
14266: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14267: }
14268: } else {
1.160.6.110 raeburn 14269: $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 14270: }
14271: if ($confighash{'passwords'}{'resetremove'}) {
14272: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14273: } else {
14274: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14275: }
14276: if ($confighash{'passwords'}{'resetcustom'}) {
14277: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 14278: &mt('custom text'),600,500,undef,undef,
14279: undef,undef,'background-color:#ffffff');
14280: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 14281: } else {
14282: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14283: }
14284: } elsif ($key eq 'intauth') {
14285: foreach my $item ('cost','switch','check') {
14286: my $value = $save_defaults{$key.'_'.$item};
14287: if ($item eq 'switch') {
14288: my %optiondesc = &Apache::lonlocal::texthash (
14289: 0 => 'No',
14290: 1 => 'Yes',
14291: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14292: );
14293: if ($value =~ /^(0|1|2)$/) {
14294: $value = $optiondesc{$value};
14295: } else {
14296: $value = &mt('none -- defaults to No');
14297: }
14298: } elsif ($item eq 'check') {
14299: my %optiondesc = &Apache::lonlocal::texthash (
14300: 0 => 'No',
14301: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14302: 2 => 'Yes, disallow login if stored cost is less than domain default',
14303: );
14304: if ($value =~ /^(0|1|2)$/) {
14305: $value = $optiondesc{$value};
14306: } else {
14307: $value = &mt('none -- defaults to No');
14308: }
14309: }
14310: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14311: }
14312: } elsif ($key eq 'rules') {
14313: foreach my $rule ('min','max','numsaved') {
14314: if ($confighash{'passwords'}{$rule} eq '') {
14315: if ($rule eq 'min') {
14316: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 14317: ' '.&mt('Default of [_1] will be used',
14318: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 14319: } else {
14320: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14321: }
14322: } else {
14323: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14324: }
14325: }
1.160.6.104 raeburn 14326: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14327: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14328: my %rulenames = &Apache::lonlocal::texthash(
14329: uc => 'At least one upper case letter',
14330: lc => 'At least one lower case letter',
14331: num => 'At least one number',
14332: spec => 'At least one non-alphanumeric',
14333: );
14334: my $needed = '<ul><li>'.
14335: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14336: '</li></ul>';
14337: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14338: } else {
14339: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14340: }
14341: } else {
14342: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14343: }
1.160.6.98 raeburn 14344: } elsif ($key eq 'crsownerchg') {
14345: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14346: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14347: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14348: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14349: } else {
14350: my %crsownerstr;
14351: foreach my $item ('by','for') {
14352: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14353: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14354: if ($type eq 'default') {
14355: $crsownerstr{$item} .= $othertitle.', ';
14356: } elsif ($usertypes->{$type} ne '') {
14357: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14358: }
14359: }
14360: $crsownerstr{$item} =~ s/\Q, \E$//;
14361: }
14362: }
14363: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14364: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14365: }
14366: } else {
14367: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14368: }
14369: }
14370: $resulttext .= '</ul></li>';
14371: }
14372: }
14373: $resulttext .= '</ul>';
14374: } else {
14375: $resulttext = &mt('No changes made to password settings');
14376: }
14377: my $cachetime = 24*60*60;
14378: if ($updatedefaults) {
14379: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14380: if (ref($lastactref) eq 'HASH') {
14381: $lastactref->{'domdefaults'} = 1;
14382: }
14383: }
14384: if ($updateconf) {
14385: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14386: if (ref($lastactref) eq 'HASH') {
14387: $lastactref->{'passwdconf'} = 1;
14388: }
14389: }
14390: } else {
14391: $resulttext = '<span class="LC_error">'.
14392: &mt('An error occurred: [_1]',$putresult).'</span>';
14393: }
14394: if ($errors) {
14395: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14396: $errors.'</ul></p>';
14397: }
14398: return $resulttext;
14399: }
14400:
1.28 raeburn 14401: sub modify_usercreation {
1.27 raeburn 14402: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14403: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14404: my $warningmsg;
1.27 raeburn 14405: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14406: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 14407: if ($key eq 'cancreate') {
14408: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14409: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 14410: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 14411: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 14412: } else {
14413: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 14414: }
1.50 raeburn 14415: }
1.43 raeburn 14416: }
1.160.6.34 raeburn 14417: } elsif ($key eq 'email_rule') {
14418: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14419: } else {
14420: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 14421: }
14422: }
1.34 raeburn 14423: }
1.160.6.34 raeburn 14424: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
14425: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
14426: my @contexts = ('author','course','requestcrs');
14427: foreach my $item(@contexts) {
14428: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14429: }
1.34 raeburn 14430: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14431: foreach my $item (@contexts) {
1.160.6.34 raeburn 14432: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14433: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14434: }
1.27 raeburn 14435: }
1.34 raeburn 14436: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14437: foreach my $item (@contexts) {
1.43 raeburn 14438: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14439: if ($cancreate{$item} ne 'any') {
14440: push(@{$changes{'cancreate'}},$item);
14441: }
14442: } else {
14443: if ($cancreate{$item} ne 'none') {
14444: push(@{$changes{'cancreate'}},$item);
14445: }
1.27 raeburn 14446: }
14447: }
14448: } else {
1.43 raeburn 14449: foreach my $item (@contexts) {
1.34 raeburn 14450: push(@{$changes{'cancreate'}},$item);
14451: }
1.27 raeburn 14452: }
1.34 raeburn 14453:
1.27 raeburn 14454: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14455: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14456: if (!grep(/^\Q$type\E$/,@username_rule)) {
14457: push(@{$changes{'username_rule'}},$type);
14458: }
14459: }
14460: foreach my $type (@username_rule) {
14461: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14462: push(@{$changes{'username_rule'}},$type);
14463: }
14464: }
14465: } else {
14466: push(@{$changes{'username_rule'}},@username_rule);
14467: }
14468:
1.32 raeburn 14469: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14470: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14471: if (!grep(/^\Q$type\E$/,@id_rule)) {
14472: push(@{$changes{'id_rule'}},$type);
14473: }
14474: }
14475: foreach my $type (@id_rule) {
14476: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14477: push(@{$changes{'id_rule'}},$type);
14478: }
14479: }
14480: } else {
14481: push(@{$changes{'id_rule'}},@id_rule);
14482: }
14483:
1.43 raeburn 14484: my @authen_contexts = ('author','course','domain');
1.28 raeburn 14485: my @authtypes = ('int','krb4','krb5','loc');
14486: my %authhash;
1.43 raeburn 14487: foreach my $item (@authen_contexts) {
1.28 raeburn 14488: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
14489: foreach my $auth (@authtypes) {
14490: if (grep(/^\Q$auth\E$/,@authallowed)) {
14491: $authhash{$item}{$auth} = 1;
14492: } else {
14493: $authhash{$item}{$auth} = 0;
14494: }
14495: }
14496: }
14497: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 14498: foreach my $item (@authen_contexts) {
1.28 raeburn 14499: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
14500: foreach my $auth (@authtypes) {
14501: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
14502: push(@{$changes{'authtypes'}},$item);
14503: last;
14504: }
14505: }
14506: }
14507: }
14508: } else {
1.43 raeburn 14509: foreach my $item (@authen_contexts) {
1.28 raeburn 14510: push(@{$changes{'authtypes'}},$item);
14511: }
14512: }
14513:
1.160.6.34 raeburn 14514: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
14515: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
14516: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
14517: $save_usercreate{'id_rule'} = \@id_rule;
14518: $save_usercreate{'username_rule'} = \@username_rule,
14519: $save_usercreate{'authtypes'} = \%authhash;
14520:
1.27 raeburn 14521: my %usercreation_hash = (
1.160.6.34 raeburn 14522: usercreation => \%save_usercreate,
14523: );
1.27 raeburn 14524:
14525: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
14526: $dom);
1.50 raeburn 14527:
1.160.6.34 raeburn 14528: if ($putresult eq 'ok') {
14529: if (keys(%changes) > 0) {
14530: $resulttext = &mt('Changes made:').'<ul>';
14531: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14532: my %lt = &usercreation_types();
14533: foreach my $type (@{$changes{'cancreate'}}) {
14534: my $chgtext = $lt{$type}.', ';
14535: if ($cancreate{$type} eq 'none') {
14536: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
14537: } elsif ($cancreate{$type} eq 'any') {
14538: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
14539: } elsif ($cancreate{$type} eq 'official') {
14540: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
14541: } elsif ($cancreate{$type} eq 'unofficial') {
14542: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
14543: }
14544: $resulttext .= '<li>'.$chgtext.'</li>';
14545: }
14546: }
14547: if (ref($changes{'username_rule'}) eq 'ARRAY') {
14548: my ($rules,$ruleorder) =
14549: &Apache::lonnet::inst_userrules($dom,'username');
14550: my $chgtext = '<ul>';
14551: foreach my $type (@username_rule) {
14552: if (ref($rules->{$type}) eq 'HASH') {
14553: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
14554: }
14555: }
14556: $chgtext .= '</ul>';
14557: if (@username_rule > 0) {
14558: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14559: } else {
14560: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
14561: }
14562: }
14563: if (ref($changes{'id_rule'}) eq 'ARRAY') {
14564: my ($idrules,$idruleorder) =
14565: &Apache::lonnet::inst_userrules($dom,'id');
14566: my $chgtext = '<ul>';
14567: foreach my $type (@id_rule) {
14568: if (ref($idrules->{$type}) eq 'HASH') {
14569: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
14570: }
14571: }
14572: $chgtext .= '</ul>';
14573: if (@id_rule > 0) {
14574: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14575: } else {
14576: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
14577: }
14578: }
14579: my %authname = &authtype_names();
14580: my %context_title = &context_names();
14581: if (ref($changes{'authtypes'}) eq 'ARRAY') {
14582: my $chgtext = '<ul>';
14583: foreach my $type (@{$changes{'authtypes'}}) {
14584: my @allowed;
14585: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
14586: foreach my $auth (@authtypes) {
14587: if ($authhash{$type}{$auth}) {
14588: push(@allowed,$authname{$auth});
14589: }
14590: }
14591: if (@allowed > 0) {
14592: $chgtext .= join(', ',@allowed).'</li>';
14593: } else {
14594: $chgtext .= &mt('none').'</li>';
14595: }
14596: }
14597: $chgtext .= '</ul>';
14598: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
14599: $resulttext .= '</li>';
14600: }
14601: $resulttext .= '</ul>';
14602: } else {
14603: $resulttext = &mt('No changes made to user creation settings');
14604: }
14605: } else {
14606: $resulttext = '<span class="LC_error">'.
14607: &mt('An error occurred: [_1]',$putresult).'</span>';
14608: }
14609: if ($warningmsg ne '') {
14610: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14611: }
14612: return $resulttext;
14613: }
14614:
14615: sub modify_selfcreation {
1.160.6.93 raeburn 14616: my ($dom,$lastactref,%domconfig) = @_;
14617: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
14618: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
14619: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14620: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
14621: if (ref($typesref) eq 'ARRAY') {
14622: @types = @{$typesref};
14623: }
14624: if (ref($usertypesref) eq 'HASH') {
14625: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 14626: }
1.160.6.93 raeburn 14627: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 14628: #
14629: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
14630: #
14631: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14632: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
14633: if ($key eq 'cancreate') {
14634: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14635: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
14636: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 14637: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
14638: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
14639: ($item eq 'emailusername') || ($item eq 'shibenv') ||
14640: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
14641: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 14642: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14643: } else {
14644: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14645: }
14646: }
14647: }
14648: } elsif ($key eq 'email_rule') {
14649: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14650: } else {
14651: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14652: }
14653: }
14654: }
14655: #
14656: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
14657: #
14658: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14659: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14660: if ($key eq 'selfcreate') {
14661: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
14662: } else {
14663: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
14664: }
14665: }
14666: }
1.160.6.93 raeburn 14667: #
14668: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
14669: #
14670: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14671: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
14672: if ($key eq 'inststatusguest') {
14673: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
14674: } else {
14675: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
14676: }
14677: }
14678: }
1.160.6.34 raeburn 14679:
14680: my @contexts = ('selfcreate');
14681: @{$cancreate{'selfcreate'}} = ();
14682: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 14683: if (@types) {
14684: @{$cancreate{'statustocreate'}} = ();
14685: }
1.160.6.40 raeburn 14686: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 14687: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 14688: %{$cancreate{'emailverified'}} = ();
14689: %{$cancreate{'emailoptions'}} = ();
14690: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 14691: my %selfcreatetypes = (
14692: sso => 'users authenticated by institutional single sign on',
14693: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 14694: email => 'users verified by e-mail',
1.50 raeburn 14695: );
1.160.6.34 raeburn 14696: #
14697: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
14698: # is permitted.
14699: #
1.160.6.40 raeburn 14700:
1.160.6.93 raeburn 14701: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 14702:
1.160.6.93 raeburn 14703: my (@statuses,%email_rule);
1.160.6.35 raeburn 14704: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 14705: if ($item eq 'email') {
1.160.6.40 raeburn 14706: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 14707: if (@types) {
14708: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
14709: foreach my $status (@poss_statuses) {
14710: if (grep(/^\Q$status\E$/,(@types,'default'))) {
14711: push(@statuses,$status);
14712: }
14713: }
14714: $save_inststatus{'inststatusguest'} = \@statuses;
14715: } else {
14716: push(@statuses,'default');
14717: }
14718: if (@statuses) {
14719: my %curr_rule;
14720: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
14721: foreach my $type (@statuses) {
14722: $curr_rule{$type} = $curr_usercreation{'email_rule'};
14723: }
14724: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
14725: foreach my $type (@statuses) {
14726: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
14727: }
14728: }
14729: push(@{$cancreate{'selfcreate'}},'email');
14730: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
14731: my %curremaildom;
14732: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
14733: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
14734: }
14735: foreach my $type (@statuses) {
14736: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
14737: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
14738: }
14739: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
14740: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
14741: }
14742: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
14743: #
14744: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
14745: #
14746: my $chosen = $1;
14747: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
14748: my $emaildom;
14749: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
14750: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
14751: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
14752: if (ref($curremaildom{$type}) eq 'HASH') {
14753: if (exists($curremaildom{$type}{$chosen})) {
14754: if ($curremaildom{$type}{$chosen} ne $emaildom) {
14755: push(@{$changes{'cancreate'}},'emaildomain');
14756: }
14757: } elsif ($emaildom ne '') {
14758: push(@{$changes{'cancreate'}},'emaildomain');
14759: }
14760: } elsif ($emaildom ne '') {
14761: push(@{$changes{'cancreate'}},'emaildomain');
14762: }
14763: }
14764: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14765: } elsif ($chosen eq 'custom') {
14766: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
14767: $email_rule{$type} = [];
14768: if (ref($emailrules) eq 'HASH') {
14769: foreach my $rule (@possemail_rules) {
14770: if (exists($emailrules->{$rule})) {
14771: push(@{$email_rule{$type}},$rule);
14772: }
14773: }
14774: }
14775: if (@{$email_rule{$type}}) {
14776: $cancreate{'emailoptions'}{$type} = 'custom';
14777: if (ref($curr_rule{$type}) eq 'ARRAY') {
14778: if (@{$curr_rule{$type}} > 0) {
14779: foreach my $rule (@{$curr_rule{$type}}) {
14780: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
14781: push(@{$changes{'email_rule'}},$type);
14782: }
14783: }
14784: }
14785: foreach my $type (@{$email_rule{$type}}) {
14786: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14787: push(@{$changes{'email_rule'}},$type);
14788: }
14789: }
14790: } else {
14791: push(@{$changes{'email_rule'}},$type);
14792: }
14793: }
14794: } else {
14795: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14796: }
14797: }
14798: }
14799: if (@types) {
14800: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14801: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14802: if (@changed) {
14803: push(@{$changes{'inststatus'}},'inststatusguest');
14804: }
14805: } else {
14806: push(@{$changes{'inststatus'}},'inststatusguest');
14807: }
14808: }
14809: } else {
14810: delete($env{'form.cancreate_email'});
14811: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14812: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14813: push(@{$changes{'inststatus'}},'inststatusguest');
14814: }
14815: }
14816: }
14817: } else {
14818: $save_inststatus{'inststatusguest'} = [];
14819: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14820: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14821: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 14822: }
14823: }
1.160.6.34 raeburn 14824: }
14825: } else {
14826: if ($env{'form.cancreate_'.$item}) {
14827: push(@{$cancreate{'selfcreate'}},$item);
14828: }
14829: }
14830: }
1.160.6.93 raeburn 14831: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 14832: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14833: #
1.160.6.35 raeburn 14834: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14835: # 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 14836: #
1.160.6.40 raeburn 14837:
1.160.6.48 raeburn 14838: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 14839: push(@contexts,'emailusername');
1.160.6.93 raeburn 14840: if (@statuses) {
14841: foreach my $type (@statuses) {
1.160.6.35 raeburn 14842: if (ref($infofields) eq 'ARRAY') {
14843: foreach my $field (@{$infofields}) {
14844: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14845: $cancreate{'emailusername'}{$type}{$field} = $1;
14846: }
14847: }
1.160.6.34 raeburn 14848: }
14849: }
14850: }
14851: #
14852: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 14853: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 14854: #
14855:
14856: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14857: @approvalnotify = sort(@approvalnotify);
14858: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14859: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14860: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14861: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14862: push(@{$changes{'cancreate'}},'notify');
14863: }
14864: } else {
14865: if ($cancreate{'notify'}{'approval'}) {
14866: push(@{$changes{'cancreate'}},'notify');
14867: }
14868: }
14869: } elsif ($cancreate{'notify'}{'approval'}) {
14870: push(@{$changes{'cancreate'}},'notify');
14871: }
14872:
14873: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14874: }
14875: #
1.160.6.40 raeburn 14876: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 14877: # institutional log-in.
14878: #
14879: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14880: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14881: ($domdefaults{'auth_def'} eq 'localauth'))) {
14882: $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.').' '.
14883: &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.');
14884: }
14885: }
14886: my @fields = ('lastname','firstname','middlename','generation',
14887: 'permanentemail','id');
1.160.6.44 raeburn 14888: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 14889: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14890: #
14891: # Where usernames may created for institutional log-in and/or institutional single sign on:
14892: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14893: # may self-create accounts
14894: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14895: # which the user may supply, if institutional data is unavailable.
14896: #
14897: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 14898: if (@types) {
14899: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14900: push(@contexts,'statustocreate');
14901: foreach my $type (@types) {
1.160.6.34 raeburn 14902: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14903: foreach my $field (@fields) {
14904: if (grep(/^\Q$field\E$/,@modifiable)) {
14905: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14906: } else {
14907: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14908: }
14909: }
14910: }
14911: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 14912: foreach my $type (@types) {
1.160.6.34 raeburn 14913: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14914: foreach my $field (@fields) {
14915: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14916: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14917: push(@{$changes{'selfcreate'}},$type);
14918: last;
14919: }
14920: }
14921: }
14922: }
14923: } else {
1.160.6.93 raeburn 14924: foreach my $type (@types) {
1.160.6.34 raeburn 14925: push(@{$changes{'selfcreate'}},$type);
14926: }
14927: }
14928: }
1.160.6.44 raeburn 14929: foreach my $field (@shibfields) {
14930: if ($env{'form.shibenv_'.$field} ne '') {
14931: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14932: }
14933: }
14934: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14935: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14936: foreach my $field (@shibfields) {
14937: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14938: push(@{$changes{'cancreate'}},'shibenv');
14939: }
14940: }
14941: } else {
14942: foreach my $field (@shibfields) {
14943: if ($env{'form.shibenv_'.$field}) {
14944: push(@{$changes{'cancreate'}},'shibenv');
14945: last;
14946: }
14947: }
14948: }
14949: }
1.160.6.34 raeburn 14950: }
14951: foreach my $item (@contexts) {
14952: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14953: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14954: if (ref($cancreate{$item}) eq 'ARRAY') {
14955: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
14956: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14957: push(@{$changes{'cancreate'}},$item);
14958: }
14959: }
14960: }
14961: }
14962: if (ref($cancreate{$item}) eq 'ARRAY') {
14963: foreach my $type (@{$cancreate{$item}}) {
14964: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
14965: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14966: push(@{$changes{'cancreate'}},$item);
14967: }
14968: }
14969: }
14970: }
14971: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
14972: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 14973: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
14974: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14975: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
14976: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 14977: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14978: push(@{$changes{'cancreate'}},$item);
14979: }
14980: }
14981: }
1.160.6.93 raeburn 14982: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14983: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 14984: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14985: push(@{$changes{'cancreate'}},$item);
14986: }
1.160.6.34 raeburn 14987: }
14988: }
14989: }
1.160.6.93 raeburn 14990: foreach my $type (keys(%{$cancreate{$item}})) {
14991: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14992: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14993: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14994: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 14995: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14996: push(@{$changes{'cancreate'}},$item);
14997: }
14998: }
14999: } else {
15000: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15001: push(@{$changes{'cancreate'}},$item);
15002: }
15003: }
15004: }
1.160.6.93 raeburn 15005: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15006: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15007: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15008: push(@{$changes{'cancreate'}},$item);
15009: }
1.160.6.34 raeburn 15010: }
15011: }
15012: }
15013: }
15014: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15015: if (ref($cancreate{$item}) eq 'ARRAY') {
15016: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15017: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15018: push(@{$changes{'cancreate'}},$item);
15019: }
15020: }
1.160.6.93 raeburn 15021: }
15022: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15023: if (ref($cancreate{$item}) eq 'HASH') {
15024: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15025: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 15026: }
15027: }
15028: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 15029: if (ref($cancreate{$item}) eq 'HASH') {
15030: foreach my $type (keys(%{$cancreate{$item}})) {
15031: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15032: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15033: if ($cancreate{$item}{$type}{$field}) {
15034: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15035: push(@{$changes{'cancreate'}},$item);
15036: }
15037: last;
15038: }
15039: }
15040: }
15041: }
1.160.6.34 raeburn 15042: }
15043: }
15044: }
15045: #
15046: # Populate %save_usercreate hash with updates to self-creation configuration.
15047: #
15048: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15049: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 15050: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 15051: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15052: if (ref($cancreate{'notify'}) eq 'HASH') {
15053: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15054: }
1.160.6.40 raeburn 15055: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15056: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15057: }
1.160.6.93 raeburn 15058: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15059: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15060: }
15061: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15062: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15063: }
15064: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15065: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15066: }
1.160.6.34 raeburn 15067: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15068: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15069: }
1.160.6.44 raeburn 15070: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15071: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15072: }
1.160.6.34 raeburn 15073: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 15074: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 15075:
15076: my %userconfig_hash = (
15077: usercreation => \%save_usercreate,
15078: usermodification => \%save_usermodify,
1.160.6.93 raeburn 15079: inststatus => \%save_inststatus,
1.160.6.34 raeburn 15080: );
1.160.6.93 raeburn 15081:
1.160.6.34 raeburn 15082: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15083: $dom);
15084: #
1.160.6.93 raeburn 15085: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 15086: #
1.27 raeburn 15087: if ($putresult eq 'ok') {
15088: if (keys(%changes) > 0) {
15089: $resulttext = &mt('Changes made:').'<ul>';
15090: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 15091: my %lt = &selfcreation_types();
1.34 raeburn 15092: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 15093: my $chgtext = '';
1.45 raeburn 15094: if ($type eq 'selfcreate') {
1.50 raeburn 15095: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 15096: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15097: } else {
1.160.6.34 raeburn 15098: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15099: '<ul>';
1.50 raeburn 15100: foreach my $case (@{$cancreate{$type}}) {
15101: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15102: }
15103: $chgtext .= '</ul>';
1.100 raeburn 15104: if (ref($cancreate{$type}) eq 'ARRAY') {
15105: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15106: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15107: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 15108: $chgtext .= '<span class="LC_warning">'.
15109: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15110: '</span><br />';
1.100 raeburn 15111: }
15112: }
15113: }
1.160.6.93 raeburn 15114: if (grep(/^email$/,@{$cancreate{$type}})) {
15115: if (!@statuses) {
15116: $chgtext .= '<span class="LC_warning">'.
15117: &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.").
15118: '</span><br />';
15119:
15120: }
15121: }
1.100 raeburn 15122: }
1.43 raeburn 15123: }
1.160.6.44 raeburn 15124: } elsif ($type eq 'shibenv') {
15125: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 15126: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 15127: } else {
15128: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15129: '<ul>';
15130: foreach my $field (@shibfields) {
15131: next if ($cancreate{$type}{$field} eq '');
15132: if ($field eq 'inststatus') {
15133: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15134: } else {
15135: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15136: }
15137: }
15138: $chgtext .= '</ul>';
1.160.6.93 raeburn 15139: }
1.93 raeburn 15140: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15141: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15142: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15143: if (@{$cancreate{'selfcreate'}} > 0) {
15144: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15145: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15146: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 15147: $chgtext .= '<br />'.
15148: '<span class="LC_warning">'.
15149: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15150: '</span>';
15151: }
1.160.6.93 raeburn 15152: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15153: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15154: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15155: } else {
15156: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15157: }
15158: $chgtext .= '<ul>';
15159: foreach my $case (@{$cancreate{$type}}) {
15160: if ($case eq 'default') {
15161: $chgtext .= '<li>'.$othertitle.'</li>';
15162: } else {
1.160.6.93 raeburn 15163: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15164: }
15165: }
1.100 raeburn 15166: $chgtext .= '</ul>';
15167: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 15168: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 15169: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15170: '</span>';
1.100 raeburn 15171: }
15172: }
15173: } else {
15174: if (@{$cancreate{$type}} == 0) {
15175: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15176: } else {
15177: $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 15178: }
15179: }
1.160.6.93 raeburn 15180: $chgtext .= '<br />';
1.93 raeburn 15181: }
1.160.6.40 raeburn 15182: } elsif ($type eq 'selfcreateprocessing') {
15183: my %choices = &Apache::lonlocal::texthash (
15184: automatic => 'Automatic approval',
15185: approval => 'Queued for approval',
15186: );
1.160.6.93 raeburn 15187: if (@types) {
15188: if (@statuses) {
15189: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15190: '<ul>';
15191: foreach my $status (@statuses) {
15192: if ($status eq 'default') {
15193: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15194: } else {
15195: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15196: }
15197: }
15198: $chgtext .= '</ul>';
15199: }
15200: } else {
15201: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15202: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15203: }
15204: } elsif ($type eq 'emailverified') {
15205: my %options = &Apache::lonlocal::texthash (
15206: all => 'Same as e-mail',
15207: first => 'Omit @domain',
15208: free => 'Free to choose',
15209: );
15210: if (@types) {
15211: if (@statuses) {
15212: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15213: '<ul>';
15214: foreach my $status (@statuses) {
15215: if ($status eq 'default') {
15216: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15217: } else {
15218: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15219: }
15220: }
15221: $chgtext .= '</ul>';
15222: }
1.160.6.40 raeburn 15223: } else {
1.160.6.93 raeburn 15224: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15225: $options{$cancreate{'emailverified'}{'default'}});
15226: }
15227: } elsif ($type eq 'emailoptions') {
15228: my %options = &Apache::lonlocal::texthash (
15229: any => 'Any e-mail',
15230: inst => 'Institutional only',
15231: noninst => 'Non-institutional only',
15232: custom => 'Custom restrictions',
15233: );
15234: if (@types) {
15235: if (@statuses) {
15236: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15237: '<ul>';
15238: foreach my $status (@statuses) {
15239: if ($type eq 'default') {
15240: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15241: } else {
15242: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15243: }
15244: }
15245: $chgtext .= '</ul>';
15246: }
15247: } else {
15248: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15249: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15250: } else {
15251: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15252: $options{$cancreate{'emailoptions'}{'default'}});
15253: }
15254: }
15255: } elsif ($type eq 'emaildomain') {
15256: my $output;
15257: if (@statuses) {
15258: foreach my $type (@statuses) {
15259: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15260: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15261: if ($type eq 'default') {
15262: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15263: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15264: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15265: } else {
15266: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15267: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15268: }
15269: } else {
15270: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15271: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15272: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15273: } else {
15274: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15275: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15276: }
15277: }
15278: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15279: if ($type eq 'default') {
15280: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15281: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15282: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15283: } else {
15284: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15285: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15286: }
15287: } else {
15288: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15289: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15290: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15291: } else {
15292: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15293: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15294: }
15295: }
15296: }
15297: }
15298: }
15299: }
15300: if ($output ne '') {
15301: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15302: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 15303: }
1.160.6.5 raeburn 15304: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 15305: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 15306: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15307: } else {
15308: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 15309: if ($captchas{$savecaptcha{$type}}) {
15310: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 15311: } else {
15312: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
15313: }
15314: }
15315: } elsif ($type eq 'recaptchakeys') {
15316: my ($privkey,$pubkey);
1.160.6.34 raeburn 15317: if (ref($savecaptcha{$type}) eq 'HASH') {
15318: $pubkey = $savecaptcha{$type}{'public'};
15319: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 15320: }
15321: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15322: if (!$pubkey) {
15323: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15324: } else {
15325: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15326: }
15327: if (!$privkey) {
15328: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15329: } else {
15330: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15331: }
15332: $chgtext .= '</ul>';
1.160.6.69 raeburn 15333: } elsif ($type eq 'recaptchaversion') {
15334: if ($savecaptcha{'captcha'} eq 'recaptcha') {
15335: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
15336: }
1.160.6.34 raeburn 15337: } elsif ($type eq 'emailusername') {
15338: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 15339: if (@statuses) {
15340: foreach my $type (@statuses) {
1.160.6.35 raeburn 15341: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15342: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 15343: $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 15344: '<ul>';
15345: foreach my $field (@{$infofields}) {
15346: if ($cancreate{'emailusername'}{$type}{$field}) {
15347: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15348: }
15349: }
1.160.6.50 raeburn 15350: $chgtext .= '</ul>';
15351: } else {
1.160.6.93 raeburn 15352: $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 15353: }
15354: } else {
1.160.6.93 raeburn 15355: $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 15356: }
15357: }
15358: }
15359: }
15360: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 15361: my $numapprove = 0;
1.160.6.34 raeburn 15362: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15363: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15364: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 15365: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15366: $numapprove ++;
1.160.6.34 raeburn 15367: }
15368: }
1.43 raeburn 15369: }
1.160.6.93 raeburn 15370: unless ($numapprove) {
15371: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15372: }
1.34 raeburn 15373: }
1.160.6.34 raeburn 15374: if ($chgtext) {
15375: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15376: }
15377: }
15378: }
1.160.6.93 raeburn 15379: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15380: my ($emailrules,$emailruleorder) =
15381: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 15382: foreach my $type (@{$changes{'email_rule'}}) {
15383: if (ref($email_rule{$type}) eq 'ARRAY') {
15384: my $chgtext = '<ul>';
15385: foreach my $rule (@{$email_rule{$type}}) {
15386: if (ref($emailrules->{$rule}) eq 'HASH') {
15387: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15388: }
15389: }
15390: $chgtext .= '</ul>';
15391: my $typename;
15392: if (@types) {
15393: if ($type eq 'default') {
15394: $typename = $othertitle;
15395: } else {
15396: $typename = $usertypes{$type};
15397: }
15398: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15399: }
15400: if (@{$email_rule{$type}} > 0) {
15401: $resulttext .= '<li>'.
15402: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15403: $usertypes{$type}).
15404: $chgtext.
15405: '</li>';
15406: } else {
15407: $resulttext .= '<li>'.
15408: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
15409: '</li>'.
15410: &mt('(Affiliation: [_1])',$typename);
15411: }
1.43 raeburn 15412: }
15413: }
1.160.6.93 raeburn 15414: }
15415: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15416: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15417: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15418: my $chgtext = '<ul>';
15419: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15420: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15421: }
15422: $chgtext .= '</ul>';
15423: $resulttext .= '<li>'.
15424: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15425: $chgtext.
15426: '</li>';
15427: } else {
15428: $resulttext .= '<li>'.
15429: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15430: '</li>';
15431: }
1.43 raeburn 15432: }
15433: }
1.160.6.34 raeburn 15434: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15435: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15436: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15437: foreach my $type (@{$changes{'selfcreate'}}) {
15438: my $typename = $type;
1.160.6.93 raeburn 15439: if (keys(%usertypes) > 0) {
15440: if ($usertypes{$type} ne '') {
15441: $typename = $usertypes{$type};
1.28 raeburn 15442: }
15443: }
1.160.6.34 raeburn 15444: my @modifiable;
15445: $resulttext .= '<li>'.
15446: &mt('Self-creation of account by users with status: [_1]',
15447: '<span class="LC_cusr_emph">'.$typename.'</span>').
15448: ' - '.&mt('modifiable fields (if institutional data blank): ');
15449: foreach my $field (@fields) {
15450: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15451: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
15452: }
15453: }
15454: if (@modifiable > 0) {
15455: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15456: } else {
1.160.6.34 raeburn 15457: $resulttext .= &mt('none');
1.43 raeburn 15458: }
1.160.6.34 raeburn 15459: $resulttext .= '</li>';
1.28 raeburn 15460: }
1.160.6.34 raeburn 15461: $resulttext .= '</ul></li>';
1.28 raeburn 15462: }
1.27 raeburn 15463: $resulttext .= '</ul>';
1.160.6.93 raeburn 15464: my $cachetime = 24*60*60;
15465: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15466: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15467: if (ref($lastactref) eq 'HASH') {
15468: $lastactref->{'domdefaults'} = 1;
15469: }
1.27 raeburn 15470: } else {
1.160.6.34 raeburn 15471: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15472: }
15473: } else {
15474: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15475: &mt('An error occurred: [_1]',$putresult).'</span>';
15476: }
1.43 raeburn 15477: if ($warningmsg ne '') {
15478: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15479: }
1.23 raeburn 15480: return $resulttext;
15481: }
15482:
1.160.6.5 raeburn 15483: sub process_captcha {
1.160.6.104 raeburn 15484: my ($container,$changes,$newsettings,$currsettings) = @_;
15485: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 15486: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
15487: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
15488: $newsettings->{'captcha'} = 'original';
15489: }
1.160.6.104 raeburn 15490: my %current;
15491: if (ref($currsettings) eq 'HASH') {
15492: %current = %{$currsettings};
15493: }
15494: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 15495: if ($container eq 'cancreate') {
15496: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15497: push(@{$changes->{'cancreate'}},'captcha');
15498: } elsif (!defined($changes->{'cancreate'})) {
15499: $changes->{'cancreate'} = ['captcha'];
15500: }
1.160.6.102 raeburn 15501: } elsif ($container eq 'passwords') {
15502: $changes->{'reset'} = 1;
1.160.6.5 raeburn 15503: } else {
15504: $changes->{'captcha'} = 1;
15505: }
15506: }
1.160.6.69 raeburn 15507: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 15508: if ($newsettings->{'captcha'} eq 'recaptcha') {
15509: $newpub = $env{'form.'.$container.'_recaptchapub'};
15510: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 15511: $newpub =~ s/[^\w\-]//g;
15512: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 15513: $newsettings->{'recaptchakeys'} = {
15514: public => $newpub,
15515: private => $newpriv,
15516: };
1.160.6.69 raeburn 15517: $newversion = $env{'form.'.$container.'_recaptchaversion'};
15518: $newversion =~ s/\D//g;
15519: if ($newversion ne '2') {
15520: $newversion = 1;
15521: }
15522: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 15523: }
1.160.6.104 raeburn 15524: if (ref($current{'recaptchakeys'}) eq 'HASH') {
15525: $currpub = $current{'recaptchakeys'}{'public'};
15526: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 15527: unless ($newsettings->{'captcha'} eq 'recaptcha') {
15528: $newsettings->{'recaptchakeys'} = {
15529: public => '',
15530: private => '',
15531: }
15532: }
1.160.6.5 raeburn 15533: }
1.160.6.104 raeburn 15534: if ($current{'captcha'} eq 'recaptcha') {
15535: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 15536: if ($currversion ne '2') {
15537: $currversion = 1;
15538: }
15539: }
15540: if ($currversion ne $newversion) {
15541: if ($container eq 'cancreate') {
15542: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15543: push(@{$changes->{'cancreate'}},'recaptchaversion');
15544: } elsif (!defined($changes->{'cancreate'})) {
15545: $changes->{'cancreate'} = ['recaptchaversion'];
15546: }
1.160.6.102 raeburn 15547: } elsif ($container eq 'passwords') {
15548: $changes->{'reset'} = 1;
1.160.6.69 raeburn 15549: } else {
15550: $changes->{'recaptchaversion'} = 1;
15551: }
15552: }
1.160.6.5 raeburn 15553: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
15554: if ($container eq 'cancreate') {
15555: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15556: push(@{$changes->{'cancreate'}},'recaptchakeys');
15557: } elsif (!defined($changes->{'cancreate'})) {
15558: $changes->{'cancreate'} = ['recaptchakeys'];
15559: }
1.160.6.102 raeburn 15560: } elsif ($container eq 'passwords') {
15561: $changes->{'reset'} = 1;
1.160.6.5 raeburn 15562: } else {
15563: $changes->{'recaptchakeys'} = 1;
15564: }
15565: }
15566: return;
15567: }
15568:
1.33 raeburn 15569: sub modify_usermodification {
15570: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15571: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 15572: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15573: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 15574: if ($key eq 'selfcreate') {
15575: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
15576: } else {
15577: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
15578: }
1.33 raeburn 15579: }
15580: }
1.160.6.34 raeburn 15581: my @contexts = ('author','course');
1.33 raeburn 15582: my %context_title = (
15583: author => 'In author context',
15584: course => 'In course context',
15585: );
15586: my @fields = ('lastname','firstname','middlename','generation',
15587: 'permanentemail','id');
15588: my %roles = (
15589: author => ['ca','aa'],
15590: course => ['st','ep','ta','in','cr'],
15591: );
15592: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15593: foreach my $context (@contexts) {
15594: foreach my $role (@{$roles{$context}}) {
15595: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
15596: foreach my $item (@fields) {
15597: if (grep(/^\Q$item\E$/,@modifiable)) {
15598: $modifyhash{$context}{$role}{$item} = 1;
15599: } else {
15600: $modifyhash{$context}{$role}{$item} = 0;
15601: }
15602: }
15603: }
15604: if (ref($curr_usermodification{$context}) eq 'HASH') {
15605: foreach my $role (@{$roles{$context}}) {
15606: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
15607: foreach my $field (@fields) {
15608: if ($modifyhash{$context}{$role}{$field} ne
15609: $curr_usermodification{$context}{$role}{$field}) {
15610: push(@{$changes{$context}},$role);
15611: last;
15612: }
15613: }
15614: }
15615: }
15616: } else {
15617: foreach my $context (@contexts) {
15618: foreach my $role (@{$roles{$context}}) {
15619: push(@{$changes{$context}},$role);
15620: }
15621: }
15622: }
15623: }
15624: my %usermodification_hash = (
15625: usermodification => \%modifyhash,
15626: );
15627: my $putresult = &Apache::lonnet::put_dom('configuration',
15628: \%usermodification_hash,$dom);
15629: if ($putresult eq 'ok') {
15630: if (keys(%changes) > 0) {
15631: $resulttext = &mt('Changes made: ').'<ul>';
15632: foreach my $context (@contexts) {
15633: if (ref($changes{$context}) eq 'ARRAY') {
15634: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
15635: if (ref($changes{$context}) eq 'ARRAY') {
15636: foreach my $role (@{$changes{$context}}) {
15637: my $rolename;
1.160.6.34 raeburn 15638: if ($role eq 'cr') {
15639: $rolename = &mt('Custom');
1.33 raeburn 15640: } else {
1.160.6.34 raeburn 15641: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 15642: }
15643: my @modifiable;
1.160.6.34 raeburn 15644: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 15645: foreach my $field (@fields) {
15646: if ($modifyhash{$context}{$role}{$field}) {
15647: push(@modifiable,$fieldtitles{$field});
15648: }
15649: }
15650: if (@modifiable > 0) {
15651: $resulttext .= join(', ',@modifiable);
15652: } else {
15653: $resulttext .= &mt('none');
15654: }
15655: $resulttext .= '</li>';
15656: }
15657: $resulttext .= '</ul></li>';
15658: }
15659: }
15660: }
15661: $resulttext .= '</ul>';
15662: } else {
15663: $resulttext = &mt('No changes made to user modification settings');
15664: }
15665: } else {
15666: $resulttext = '<span class="LC_error">'.
15667: &mt('An error occurred: [_1]',$putresult).'</span>';
15668: }
15669: return $resulttext;
15670: }
15671:
1.43 raeburn 15672: sub modify_defaults {
1.160.6.27 raeburn 15673: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 15674: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 15675: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 15676: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 15677: 'portal_def');
1.43 raeburn 15678: my @authtypes = ('internal','krb4','krb5','localauth');
15679: foreach my $item (@items) {
15680: $newvalues{$item} = $env{'form.'.$item};
15681: if ($item eq 'auth_def') {
15682: if ($newvalues{$item} ne '') {
15683: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
15684: push(@errors,$item);
15685: }
15686: }
15687: } elsif ($item eq 'lang_def') {
15688: if ($newvalues{$item} ne '') {
15689: if ($newvalues{$item} =~ /^(\w+)/) {
15690: my $langcode = $1;
1.103 raeburn 15691: if ($langcode ne 'x_chef') {
15692: if (code2language($langcode) eq '') {
15693: push(@errors,$item);
15694: }
1.43 raeburn 15695: }
15696: } else {
15697: push(@errors,$item);
15698: }
15699: }
1.54 raeburn 15700: } elsif ($item eq 'timezone_def') {
15701: if ($newvalues{$item} ne '') {
1.62 raeburn 15702: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 15703: push(@errors,$item);
15704: }
15705: }
1.68 raeburn 15706: } elsif ($item eq 'datelocale_def') {
15707: if ($newvalues{$item} ne '') {
15708: my @datelocale_ids = DateTime::Locale->ids();
15709: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
15710: push(@errors,$item);
15711: }
15712: }
1.141 raeburn 15713: } elsif ($item eq 'portal_def') {
15714: if ($newvalues{$item} ne '') {
15715: 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])\/?$/) {
15716: push(@errors,$item);
15717: }
15718: }
1.43 raeburn 15719: }
15720: if (grep(/^\Q$item\E$/,@errors)) {
15721: $newvalues{$item} = $domdefaults{$item};
15722: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
15723: $changes{$item} = 1;
15724: }
1.72 raeburn 15725: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 15726: }
1.160.6.98 raeburn 15727: my %staticdefaults = (
15728: 'intauth_cost' => 10,
15729: 'intauth_check' => 0,
15730: 'intauth_switch' => 0,
15731: );
15732: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
15733: if (exists($domdefaults{$item})) {
15734: $newvalues{$item} = $domdefaults{$item};
15735: } else {
15736: $newvalues{$item} = $staticdefaults{$item};
15737: }
15738: }
1.43 raeburn 15739: my %defaults_hash = (
1.72 raeburn 15740: defaults => \%newvalues,
15741: );
1.43 raeburn 15742: my $title = &defaults_titles();
1.160.6.40 raeburn 15743:
15744: my $currinststatus;
15745: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15746: $currinststatus = $domconfig{'inststatus'};
15747: } else {
15748: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15749: $currinststatus = {
15750: inststatustypes => $usertypes,
15751: inststatusorder => $types,
15752: inststatusguest => [],
15753: };
15754: }
15755: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
15756: my @allpos;
15757: my %alltypes;
1.160.6.93 raeburn 15758: my @inststatusguest;
15759: if (ref($currinststatus) eq 'HASH') {
15760: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
15761: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
15762: unless (grep(/^\Q$type\E$/,@todelete)) {
15763: push(@inststatusguest,$type);
15764: }
15765: }
15766: }
15767: }
15768: my ($currtitles,$currorder);
1.160.6.40 raeburn 15769: if (ref($currinststatus) eq 'HASH') {
15770: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
15771: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
15772: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
15773: if ($currinststatus->{inststatustypes}->{$type} ne '') {
15774: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
15775: }
15776: }
15777: unless (grep(/^\Q$type\E$/,@todelete)) {
15778: my $position = $env{'form.inststatus_pos_'.$type};
15779: $position =~ s/\D+//g;
15780: $allpos[$position] = $type;
15781: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
15782: $alltypes{$type} =~ s/`//g;
15783: }
15784: }
15785: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
15786: $currtitles =~ s/,$//;
15787: }
15788: }
15789: if ($env{'form.addinststatus'}) {
15790: my $newtype = $env{'form.addinststatus'};
15791: $newtype =~ s/\W//g;
15792: unless (exists($alltypes{$newtype})) {
15793: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15794: $alltypes{$newtype} =~ s/`//g;
15795: my $position = $env{'form.addinststatus_pos'};
15796: $position =~ s/\D+//g;
15797: if ($position ne '') {
15798: $allpos[$position] = $newtype;
15799: }
15800: }
15801: }
1.160.6.93 raeburn 15802: my @orderedstatus;
1.160.6.40 raeburn 15803: foreach my $type (@allpos) {
15804: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15805: push(@orderedstatus,$type);
15806: }
15807: }
15808: foreach my $type (keys(%alltypes)) {
15809: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15810: delete($alltypes{$type});
15811: }
15812: }
15813: $defaults_hash{'inststatus'} = {
15814: inststatustypes => \%alltypes,
15815: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 15816: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 15817: };
15818: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15819: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15820: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15821: }
15822: }
15823: if ($currorder ne join(',',@orderedstatus)) {
15824: $changes{'inststatus'}{'inststatusorder'} = 1;
15825: }
15826: my $newtitles;
15827: foreach my $item (@orderedstatus) {
15828: $newtitles .= $alltypes{$item}.',';
15829: }
15830: $newtitles =~ s/,$//;
15831: if ($currtitles ne $newtitles) {
15832: $changes{'inststatus'}{'inststatustypes'} = 1;
15833: }
1.43 raeburn 15834: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15835: $dom);
15836: if ($putresult eq 'ok') {
15837: if (keys(%changes) > 0) {
15838: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 15839: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15840: 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";
15841: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 15842: if ($item eq 'inststatus') {
15843: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 15844: if (@orderedstatus) {
1.160.6.40 raeburn 15845: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15846: foreach my $type (@orderedstatus) {
15847: $resulttext .= $alltypes{$type}.', ';
15848: }
15849: $resulttext =~ s/, $//;
15850: $resulttext .= '</li>';
1.160.6.93 raeburn 15851: } else {
15852: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 15853: }
15854: }
15855: } else {
15856: my $value = $env{'form.'.$item};
15857: if ($value eq '') {
15858: $value = &mt('none');
15859: } elsif ($item eq 'auth_def') {
15860: my %authnames = &authtype_names();
15861: my %shortauth = (
15862: internal => 'int',
15863: krb4 => 'krb4',
15864: krb5 => 'krb5',
15865: localauth => 'loc',
15866: );
15867: $value = $authnames{$shortauth{$value}};
15868: }
15869: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15870: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15871: }
15872: }
15873: $resulttext .= '</ul>';
15874: $mailmsgtext .= "\n";
15875: my $cachetime = 24*60*60;
1.72 raeburn 15876: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15877: if (ref($lastactref) eq 'HASH') {
15878: $lastactref->{'domdefaults'} = 1;
15879: }
1.68 raeburn 15880: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 15881: my $notify = 1;
15882: if (ref($domconfig{'contacts'}) eq 'HASH') {
15883: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15884: $notify = 0;
15885: }
15886: }
15887: if ($notify) {
15888: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15889: "LON-CAPA Domain Settings Change - $dom",
15890: $mailmsgtext);
15891: }
1.54 raeburn 15892: }
1.43 raeburn 15893: } else {
1.54 raeburn 15894: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15895: }
15896: } else {
15897: $resulttext = '<span class="LC_error">'.
15898: &mt('An error occurred: [_1]',$putresult).'</span>';
15899: }
15900: if (@errors > 0) {
15901: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15902: foreach my $item (@errors) {
15903: $resulttext .= ' "'.$title->{$item}.'",';
15904: }
15905: $resulttext =~ s/,$//;
15906: }
15907: return $resulttext;
15908: }
15909:
1.46 raeburn 15910: sub modify_scantron {
1.160.6.24 raeburn 15911: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15912: my ($resulttext,%confhash,%changes,$errors);
15913: my $custom = 'custom.tab';
15914: my $default = 'default.tab';
15915: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 15916: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15917: &config_check($dom,$confname,$servadm);
15918: if ($env{'form.scantronformat.filename'} ne '') {
15919: my $error;
15920: if ($configuserok eq 'ok') {
15921: if ($switchserver) {
1.130 raeburn 15922: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15923: } else {
15924: if ($author_ok eq 'ok') {
15925: my ($result,$scantronurl) =
15926: &publishlogo($r,'upload','scantronformat',$dom,
15927: $confname,'scantron','','',$custom);
15928: if ($result eq 'ok') {
15929: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15930: $changes{'scantronformat'} = 1;
1.46 raeburn 15931: } else {
15932: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15933: }
15934: } else {
15935: $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);
15936: }
15937: }
15938: } else {
15939: $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);
15940: }
15941: if ($error) {
15942: &Apache::lonnet::logthis($error);
15943: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15944: }
15945: }
1.48 raeburn 15946: if (ref($domconfig{'scantron'}) eq 'HASH') {
15947: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15948: if ($env{'form.scantronformat_del'}) {
15949: $confhash{'scantron'}{'scantronformat'} = '';
15950: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 15951: } else {
15952: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
15953: }
15954: }
15955: }
15956: my @options = ('hdr','pad','rem');
15957: my @fields = &scantroncsv_fields();
15958: my %titles = &scantronconfig_titles();
15959: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
15960: my ($newdat,$currdat,%newcol,%currcol);
15961: if (grep(/^dat$/,@formats)) {
15962: $confhash{'scantron'}{config}{dat} = 1;
15963: $newdat = 1;
15964: } else {
15965: $newdat = 0;
15966: }
15967: if (grep(/^csv$/,@formats)) {
15968: my %bynum;
15969: foreach my $field (@fields) {
15970: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
15971: my $posscol = $1;
15972: if (($posscol < 20) && (!$bynum{$posscol})) {
15973: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
15974: $bynum{$posscol} = $field;
15975: $newcol{$field} = $posscol;
15976: }
15977: }
15978: }
15979: if (keys(%newcol)) {
15980: foreach my $option (@options) {
15981: if ($env{'form.scantroncsv_'.$option}) {
15982: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
15983: }
15984: }
15985: }
15986: }
15987: $currdat = 1;
15988: if (ref($domconfig{'scantron'}) eq 'HASH') {
15989: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
15990: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
15991: $currdat = 0;
15992: }
15993: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
15994: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
15995: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
15996: }
15997: }
15998: }
15999: }
16000: if ($currdat != $newdat) {
16001: $changes{'config'} = 1;
16002: } else {
16003: foreach my $field (@fields) {
16004: if ($currcol{$field} ne '') {
16005: if ($currcol{$field} ne $newcol{$field}) {
16006: $changes{'config'} = 1;
16007: last;
16008: }
16009: } elsif ($newcol{$field} ne '') {
16010: $changes{'config'} = 1;
16011: last;
1.46 raeburn 16012: }
16013: }
16014: }
16015: if (keys(%confhash) > 0) {
16016: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16017: $dom);
16018: if ($putresult eq 'ok') {
16019: if (keys(%changes) > 0) {
1.48 raeburn 16020: if (ref($confhash{'scantron'}) eq 'HASH') {
16021: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 16022: if ($changes{'scantronformat'}) {
16023: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16024: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16025: } else {
16026: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16027: }
16028: }
16029: if ($changes{'config'}) {
16030: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16031: if ($confhash{'scantron'}{'config'}{'dat'}) {
16032: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16033: }
16034: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16035: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16036: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16037: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16038: foreach my $field (@fields) {
16039: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16040: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16041: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16042: }
16043: }
16044: $resulttext .= '</ul></li>';
16045: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16046: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16047: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16048: foreach my $option (@options) {
16049: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16050: $resulttext .= '<li>'.$titles{$option}.'</li>';
16051: }
16052: }
16053: $resulttext .= '</ul></li>';
16054: }
16055: }
16056: }
16057: }
16058: }
16059: } else {
16060: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16061: }
1.46 raeburn 16062: }
1.48 raeburn 16063: $resulttext .= '</ul>';
16064: } else {
1.130 raeburn 16065: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16066: }
16067: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 16068: if (ref($lastactref) eq 'HASH') {
16069: $lastactref->{'domainconfig'} = 1;
16070: }
1.46 raeburn 16071: } else {
1.160.6.97 raeburn 16072: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16073: }
16074: } else {
16075: $resulttext = '<span class="LC_error">'.
16076: &mt('An error occurred: [_1]',$putresult).'</span>';
16077: }
16078: } else {
1.160.6.97 raeburn 16079: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16080: }
16081: if ($errors) {
16082: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16083: $errors.'</ul>';
16084: }
16085: return $resulttext;
16086: }
16087:
1.48 raeburn 16088: sub modify_coursecategories {
1.160.6.43 raeburn 16089: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16090: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16091: $cathash);
1.48 raeburn 16092: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 16093: my @catitems = ('unauth','auth');
16094: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16095: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16096: $cathash = $domconfig{'coursecategories'}{'cats'};
16097: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16098: $changes{'togglecats'} = 1;
16099: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16100: }
16101: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16102: $changes{'categorize'} = 1;
16103: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16104: }
1.120 raeburn 16105: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16106: $changes{'togglecatscomm'} = 1;
16107: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16108: }
16109: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16110: $changes{'categorizecomm'} = 1;
16111: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16112: }
1.160.6.42 raeburn 16113: foreach my $item (@catitems) {
16114: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16115: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16116: $changes{$item} = 1;
16117: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16118: }
16119: }
16120: }
1.57 raeburn 16121: } else {
16122: $changes{'togglecats'} = 1;
16123: $changes{'categorize'} = 1;
1.124 raeburn 16124: $changes{'togglecatscomm'} = 1;
16125: $changes{'categorizecomm'} = 1;
1.87 raeburn 16126: $domconfig{'coursecategories'} = {
16127: togglecats => $env{'form.togglecats'},
16128: categorize => $env{'form.categorize'},
1.124 raeburn 16129: togglecatscomm => $env{'form.togglecatscomm'},
16130: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 16131: };
1.160.6.42 raeburn 16132: foreach my $item (@catitems) {
16133: if ($env{'form.coursecat_'.$item} ne 'std') {
16134: $changes{$item} = 1;
16135: }
16136: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16137: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16138: }
16139: }
1.57 raeburn 16140: }
16141: if (ref($cathash) eq 'HASH') {
16142: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16143: push (@deletecategory,'instcode::0');
16144: }
1.120 raeburn 16145: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16146: push(@deletecategory,'communities::0');
16147: }
1.48 raeburn 16148: }
1.57 raeburn 16149: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16150: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16151: if (@deletecategory > 0) {
16152: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16153: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16154: foreach my $item (@deletecategory) {
1.57 raeburn 16155: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16156: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16157: $deletions{$item} = 1;
1.57 raeburn 16158: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16159: }
16160: }
16161: }
1.57 raeburn 16162: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16163: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16164: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16165: $reorderings{$item} = 1;
1.57 raeburn 16166: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16167: }
16168: if ($env{'form.addcategory_name_'.$item} ne '') {
16169: my $newcat = $env{'form.addcategory_name_'.$item};
16170: my $newdepth = $depth+1;
16171: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16172: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16173: $adds{$newitem} = 1;
16174: }
16175: if ($env{'form.subcat_'.$item} ne '') {
16176: my $newcat = $env{'form.subcat_'.$item};
16177: my $newdepth = $depth+1;
16178: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16179: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16180: $adds{$newitem} = 1;
16181: }
16182: }
16183: }
16184: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16185: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16186: my $newitem = 'instcode::0';
1.57 raeburn 16187: if ($cathash->{$newitem} eq '') {
16188: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16189: $adds{$newitem} = 1;
16190: }
16191: } else {
16192: my $newitem = 'instcode::0';
1.57 raeburn 16193: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16194: $adds{$newitem} = 1;
16195: }
16196: }
1.120 raeburn 16197: if ($env{'form.communities'} eq '1') {
16198: if (ref($cathash) eq 'HASH') {
16199: my $newitem = 'communities::0';
16200: if ($cathash->{$newitem} eq '') {
16201: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16202: $adds{$newitem} = 1;
16203: }
16204: } else {
16205: my $newitem = 'communities::0';
16206: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16207: $adds{$newitem} = 1;
16208: }
16209: }
1.48 raeburn 16210: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16211: if (($env{'form.addcategory_name'} ne 'instcode') &&
16212: ($env{'form.addcategory_name'} ne 'communities')) {
16213: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16214: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16215: $adds{$newitem} = 1;
16216: }
1.48 raeburn 16217: }
1.57 raeburn 16218: my $putresult;
1.48 raeburn 16219: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16220: if (keys(%deletions) > 0) {
16221: foreach my $key (keys(%deletions)) {
16222: if ($predelallitems{$key} ne '') {
16223: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16224: }
16225: }
16226: }
16227: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16228: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16229: if (ref($chkcats[0]) eq 'ARRAY') {
16230: my $depth = 0;
16231: my $chg = 0;
16232: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16233: my $name = $chkcats[0][$i];
16234: my $item;
16235: if ($name eq '') {
16236: $chg ++;
16237: } else {
16238: $item = &escape($name).'::0';
16239: if ($chg) {
1.57 raeburn 16240: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16241: }
16242: $depth ++;
1.57 raeburn 16243: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16244: $depth --;
16245: }
16246: }
16247: }
1.57 raeburn 16248: }
16249: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16250: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16251: if ($putresult eq 'ok') {
1.57 raeburn 16252: my %title = (
1.120 raeburn 16253: togglecats => 'Show/Hide a course in catalog',
16254: categorize => 'Assign a category to a course',
16255: togglecatscomm => 'Show/Hide a community in catalog',
16256: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16257: );
16258: my %level = (
1.120 raeburn 16259: dom => 'set in Domain ("Modify Course/Community")',
16260: crs => 'set in Course ("Course Configuration")',
16261: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 16262: none => 'No catalog',
16263: std => 'Standard catalog',
16264: domonly => 'Domain-only catalog',
16265: codesrch => 'Code search form',
1.57 raeburn 16266: );
1.48 raeburn 16267: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16268: if ($changes{'togglecats'}) {
16269: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16270: }
16271: if ($changes{'categorize'}) {
16272: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16273: }
1.120 raeburn 16274: if ($changes{'togglecatscomm'}) {
16275: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16276: }
16277: if ($changes{'categorizecomm'}) {
16278: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16279: }
1.160.6.42 raeburn 16280: if ($changes{'unauth'}) {
16281: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16282: }
16283: if ($changes{'auth'}) {
16284: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16285: }
1.57 raeburn 16286: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16287: my $cathash;
16288: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16289: $cathash = $domconfig{'coursecategories'}{'cats'};
16290: } else {
16291: $cathash = {};
16292: }
16293: my (@cats,@trails,%allitems);
16294: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16295: if (keys(%deletions) > 0) {
16296: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16297: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16298: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16299: }
16300: $resulttext .= '</ul></li>';
16301: }
16302: if (keys(%reorderings) > 0) {
16303: my %sort_by_trail;
16304: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16305: foreach my $key (keys(%reorderings)) {
16306: if ($allitems{$key} ne '') {
16307: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16308: }
1.48 raeburn 16309: }
1.57 raeburn 16310: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16311: $resulttext .= '<li>'.$trails[$trail].'</li>';
16312: }
16313: $resulttext .= '</ul></li>';
1.48 raeburn 16314: }
1.57 raeburn 16315: if (keys(%adds) > 0) {
16316: my %sort_by_trail;
16317: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16318: foreach my $key (keys(%adds)) {
16319: if ($allitems{$key} ne '') {
16320: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16321: }
16322: }
16323: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16324: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16325: }
1.57 raeburn 16326: $resulttext .= '</ul></li>';
1.48 raeburn 16327: }
1.160.6.92 raeburn 16328: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
16329: if (ref($lastactref) eq 'HASH') {
16330: $lastactref->{'cats'} = 1;
16331: }
1.48 raeburn 16332: }
16333: $resulttext .= '</ul>';
1.160.6.43 raeburn 16334: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 16335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16336: if ($changes{'auth'}) {
16337: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16338: }
16339: if ($changes{'unauth'}) {
16340: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16341: }
16342: my $cachetime = 24*60*60;
16343: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 16344: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 16345: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 16346: }
16347: }
1.48 raeburn 16348: } else {
16349: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16350: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16351: }
16352: } else {
1.120 raeburn 16353: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16354: }
16355: return $resulttext;
16356: }
16357:
1.69 raeburn 16358: sub modify_serverstatuses {
16359: my ($dom,%domconfig) = @_;
16360: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16361: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16362: %currserverstatus = %{$domconfig{'serverstatuses'}};
16363: }
16364: my @pages = &serverstatus_pages();
16365: foreach my $type (@pages) {
16366: $newserverstatus{$type}{'namedusers'} = '';
16367: $newserverstatus{$type}{'machines'} = '';
16368: if (defined($env{'form.'.$type.'_namedusers'})) {
16369: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16370: my @okusers;
16371: foreach my $user (@users) {
16372: my ($uname,$udom) = split(/:/,$user);
16373: if (($udom =~ /^$match_domain$/) &&
16374: (&Apache::lonnet::domain($udom)) &&
16375: ($uname =~ /^$match_username$/)) {
16376: if (!grep(/^\Q$user\E/,@okusers)) {
16377: push(@okusers,$user);
16378: }
16379: }
16380: }
16381: if (@okusers > 0) {
16382: @okusers = sort(@okusers);
16383: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16384: }
16385: }
16386: if (defined($env{'form.'.$type.'_machines'})) {
16387: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16388: my @okmachines;
16389: foreach my $ip (@machines) {
16390: my @parts = split(/\./,$ip);
16391: next if (@parts < 4);
16392: my $badip = 0;
16393: for (my $i=0; $i<4; $i++) {
16394: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16395: $badip = 1;
16396: last;
16397: }
16398: }
16399: if (!$badip) {
16400: push(@okmachines,$ip);
16401: }
16402: }
16403: @okmachines = sort(@okmachines);
16404: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16405: }
16406: }
16407: my %serverstatushash = (
16408: serverstatuses => \%newserverstatus,
16409: );
16410: foreach my $type (@pages) {
1.83 raeburn 16411: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16412: my (@current,@new);
1.83 raeburn 16413: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16414: if ($currserverstatus{$type}{$setting} ne '') {
16415: @current = split(/,/,$currserverstatus{$type}{$setting});
16416: }
16417: }
16418: if ($newserverstatus{$type}{$setting} ne '') {
16419: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16420: }
16421: if (@current > 0) {
16422: if (@new > 0) {
16423: foreach my $item (@current) {
16424: if (!grep(/^\Q$item\E$/,@new)) {
16425: $changes{$type}{$setting} = 1;
1.82 raeburn 16426: last;
16427: }
16428: }
1.84 raeburn 16429: foreach my $item (@new) {
16430: if (!grep(/^\Q$item\E$/,@current)) {
16431: $changes{$type}{$setting} = 1;
16432: last;
1.82 raeburn 16433: }
16434: }
16435: } else {
1.83 raeburn 16436: $changes{$type}{$setting} = 1;
1.69 raeburn 16437: }
1.83 raeburn 16438: } elsif (@new > 0) {
16439: $changes{$type}{$setting} = 1;
1.69 raeburn 16440: }
16441: }
16442: }
16443: if (keys(%changes) > 0) {
1.81 raeburn 16444: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16445: my $putresult = &Apache::lonnet::put_dom('configuration',
16446: \%serverstatushash,$dom);
16447: if ($putresult eq 'ok') {
16448: $resulttext .= &mt('Changes made:').'<ul>';
16449: foreach my $type (@pages) {
1.84 raeburn 16450: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16451: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16452: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16453: if ($newserverstatus{$type}{'namedusers'} eq '') {
16454: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16455: } else {
16456: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16457: }
1.84 raeburn 16458: }
16459: if ($changes{$type}{'machines'}) {
1.69 raeburn 16460: if ($newserverstatus{$type}{'machines'} eq '') {
16461: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16462: } else {
16463: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16464: }
16465:
16466: }
16467: $resulttext .= '</ul></li>';
16468: }
16469: }
16470: $resulttext .= '</ul>';
16471: } else {
16472: $resulttext = '<span class="LC_error">'.
16473: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
16474:
16475: }
16476: } else {
16477: $resulttext = &mt('No changes made to access to server status pages');
16478: }
16479: return $resulttext;
16480: }
16481:
1.118 jms 16482: sub modify_helpsettings {
1.160.6.77 raeburn 16483: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 16484: my ($resulttext,$errors,%changes,%helphash);
16485: my %defaultchecked = ('submitbugs' => 'on');
16486: my @offon = ('off','on');
1.118 jms 16487: my @toggles = ('submitbugs');
1.160.6.77 raeburn 16488: my %current = ('submitbugs' => '',
16489: 'adhoc' => {},
16490: );
1.118 jms 16491: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 16492: %current = %{$domconfig{'helpsettings'}};
16493: }
1.160.6.77 raeburn 16494: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 16495: foreach my $item (@toggles) {
16496: if ($defaultchecked{$item} eq 'on') {
16497: if ($current{$item} eq '') {
16498: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 16499: $changes{$item} = 1;
16500: }
1.160.6.73 raeburn 16501: } elsif ($current{$item} ne $env{'form.'.$item}) {
16502: $changes{$item} = 1;
16503: }
16504: } elsif ($defaultchecked{$item} eq 'off') {
16505: if ($current{$item} eq '') {
16506: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 16507: $changes{$item} = 1;
16508: }
1.160.6.73 raeburn 16509: } elsif ($current{$item} ne $env{'form.'.$item}) {
16510: $changes{$item} = 1;
16511: }
16512: }
16513: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
16514: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
16515: }
16516: }
1.160.6.77 raeburn 16517: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 16518: my $confname = $dom.'-domainconfig';
16519: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 16520: my (@allpos,%newsettings,%changedprivs,$newrole);
16521: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 16522: my @accesstypes = ('all','dh','da','none','status','inc','exc');
16523: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 16524: my %lt = &Apache::lonlocal::texthash(
16525: s => 'system',
16526: d => 'domain',
16527: order => 'Display order',
16528: access => 'Role usage',
1.160.6.79 raeburn 16529: all => 'All with domain helpdesk or helpdesk assistant role',
16530: dh => 'All with domain helpdesk role',
16531: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 16532: none => 'None',
16533: status => 'Determined based on institutional status',
16534: inc => 'Include all, but exclude specific personnel',
16535: exc => 'Exclude all, but include specific personnel',
16536: );
16537: for (my $num=0; $num<=$maxnum; $num++) {
16538: my ($prefix,$identifier,$rolename,%curr);
16539: if ($num == $maxnum) {
16540: next unless ($env{'form.newcusthelp'} == $maxnum);
16541: $identifier = 'custhelp'.$num;
16542: $prefix = 'helproles_'.$num;
16543: $rolename = $env{'form.custhelpname'.$num};
16544: $rolename=~s/[^A-Za-z0-9]//gs;
16545: next if ($rolename eq '');
16546: next if (exists($existing{'rolesdef_'.$rolename}));
16547: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16548: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16549: $newprivs{'c'},$confname,$dom);
16550: if ($result ne 'ok') {
16551: $errors .= '<li><span class="LC_error">'.
16552: &mt('An error occurred storing the new custom role: [_1]',
16553: $result).'</span></li>';
16554: next;
16555: } else {
16556: $changedprivs{$rolename} = \%newprivs;
16557: $newrole = $rolename;
16558: }
16559: } else {
16560: $prefix = 'helproles_'.$num;
16561: $rolename = $env{'form.'.$prefix};
16562: next if ($rolename eq '');
16563: next unless (exists($existing{'rolesdef_'.$rolename}));
16564: $identifier = 'custhelp'.$num;
16565: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16566: my %currprivs;
16567: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
16568: split(/\_/,$existing{'rolesdef_'.$rolename});
16569: foreach my $level ('c','d','s') {
16570: if ($newprivs{$level} ne $currprivs{$level}) {
16571: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16572: $newprivs{'c'},$confname,$dom);
16573: if ($result ne 'ok') {
16574: $errors .= '<li><span class="LC_error">'.
16575: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
16576: $rolename,$result).'</span></li>';
16577: } else {
16578: $changedprivs{$rolename} = \%newprivs;
16579: }
16580: last;
16581: }
16582: }
16583: if (ref($current{'adhoc'}) eq 'HASH') {
16584: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16585: %curr = %{$current{'adhoc'}{$rolename}};
16586: }
16587: }
16588: }
16589: my $newpos = $env{'form.'.$prefix.'_pos'};
16590: $newpos =~ s/\D+//g;
16591: $allpos[$newpos] = $rolename;
16592: my $newdesc = $env{'form.'.$prefix.'_desc'};
16593: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
16594: if ($curr{'desc'}) {
16595: if ($curr{'desc'} ne $newdesc) {
16596: $changes{'customrole'}{$rolename}{'desc'} = 1;
16597: $newsettings{$rolename}{'desc'} = $newdesc;
16598: }
16599: } elsif ($newdesc ne '') {
16600: $changes{'customrole'}{$rolename}{'desc'} = 1;
16601: $newsettings{$rolename}{'desc'} = $newdesc;
16602: }
16603: my $access = $env{'form.'.$prefix.'_access'};
16604: if (grep(/^\Q$access\E$/,@accesstypes)) {
16605: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
16606: if ($access eq 'status') {
16607: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
16608: if (scalar(@statuses) == 0) {
16609: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
16610: } else {
16611: my (@shownstatus,$numtypes);
16612: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16613: if (ref($types) eq 'ARRAY') {
16614: $numtypes = scalar(@{$types});
16615: foreach my $type (sort(@statuses)) {
16616: if ($type eq 'default') {
16617: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16618: } elsif (grep(/^\Q$type\E$/,@{$types})) {
16619: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16620: push(@shownstatus,$usertypes->{$type});
16621: }
1.160.6.73 raeburn 16622: }
16623: }
1.160.6.77 raeburn 16624: if (grep(/^default$/,@statuses)) {
16625: push(@shownstatus,$othertitle);
16626: }
16627: if (scalar(@shownstatus) == 1+$numtypes) {
16628: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
16629: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
16630: } else {
16631: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
16632: if (ref($curr{'status'}) eq 'ARRAY') {
16633: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16634: if (@diffs) {
16635: $changes{'customrole'}{$rolename}{$access} = 1;
16636: }
16637: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16638: $changes{'customrole'}{$rolename}{$access} = 1;
16639: }
16640: }
16641: }
16642: } elsif (($access eq 'inc') || ($access eq 'exc')) {
16643: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
16644: my @newspecstaff;
16645: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16646: foreach my $person (sort(@personnel)) {
16647: if ($domhelpdesk{$person}) {
16648: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
16649: }
16650: }
16651: if (ref($curr{$access}) eq 'ARRAY') {
16652: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16653: if (@diffs) {
16654: $changes{'customrole'}{$rolename}{$access} = 1;
16655: }
16656: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16657: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 16658: }
1.160.6.77 raeburn 16659: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16660: my ($uname,$udom) = split(/:/,$person);
16661: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
16662: }
16663: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 16664: }
1.160.6.77 raeburn 16665: } else {
16666: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
16667: }
16668: unless ($curr{'access'} eq $access) {
16669: $changes{'customrole'}{$rolename}{'access'} = 1;
16670: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 16671: }
16672: }
1.160.6.77 raeburn 16673: if (@allpos > 0) {
16674: my $idx = 0;
16675: foreach my $rolename (@allpos) {
16676: if ($rolename ne '') {
16677: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
16678: if (ref($current{'adhoc'}) eq 'HASH') {
16679: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16680: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
16681: $changes{'customrole'}{$rolename}{'order'} = 1;
16682: $newsettings{$rolename}{'order'} = $idx+1;
16683: }
16684: }
1.160.6.73 raeburn 16685: }
1.160.6.77 raeburn 16686: $idx ++;
1.122 jms 16687: }
16688: }
1.118 jms 16689: }
1.123 jms 16690: my $putresult;
16691: if (keys(%changes) > 0) {
1.160.6.5 raeburn 16692: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
16693: if ($putresult eq 'ok') {
1.160.6.77 raeburn 16694: if (ref($helphash{'helpsettings'}) eq 'HASH') {
16695: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
16696: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
16697: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
16698: }
16699: }
16700: my $cachetime = 24*60*60;
16701: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16702: if (ref($lastactref) eq 'HASH') {
16703: $lastactref->{'domdefaults'} = 1;
16704: }
16705: } else {
16706: $errors .= '<li><span class="LC_error">'.
16707: &mt('An error occurred storing the settings: [_1]',
16708: $putresult).'</span></li>';
16709: }
16710: }
16711: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
16712: $resulttext = &mt('Changes made:').'<ul>';
16713: my (%shownprivs,@levelorder);
16714: @levelorder = ('c','d','s');
16715: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 16716: foreach my $item (sort(keys(%changes))) {
16717: if ($item eq 'submitbugs') {
16718: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
16719: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
16720: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 16721: } elsif ($item eq 'customrole') {
16722: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 16723: my @keyorder = ('order','desc','access','status','exc','inc');
16724: my %keytext = &Apache::lonlocal::texthash(
16725: order => 'Order',
16726: desc => 'Role description',
16727: access => 'Role usage',
1.160.6.83 raeburn 16728: status => 'Allowed institutional types',
1.160.6.77 raeburn 16729: exc => 'Allowed personnel',
16730: inc => 'Disallowed personnel',
16731: );
1.160.6.73 raeburn 16732: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 16733: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
16734: if ($role eq $newrole) {
16735: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
16736: $role).'<ul>';
16737: } else {
16738: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16739: $role).'<ul>';
16740: }
16741: foreach my $key (@keyorder) {
16742: if ($changes{'customrole'}{$role}{$key}) {
16743: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16744: $keytext{$key},$newsettings{$role}{$key}).
16745: '</li>';
16746: }
16747: }
16748: if (ref($changedprivs{$role}) eq 'HASH') {
16749: $shownprivs{$role} = 1;
16750: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16751: foreach my $level (@levelorder) {
16752: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16753: next if ($item eq '');
16754: my ($priv) = split(/\&/,$item,2);
16755: if (&Apache::lonnet::plaintext($priv)) {
16756: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16757: unless ($level eq 'c') {
16758: $resulttext .= ' ('.$lt{$level}.')';
16759: }
16760: $resulttext .= '</li>';
16761: }
16762: }
16763: }
16764: $resulttext .= '</ul>';
16765: }
16766: $resulttext .= '</ul></li>';
16767: }
1.160.6.73 raeburn 16768: }
16769: }
1.160.6.5 raeburn 16770: }
16771: }
16772: }
1.160.6.77 raeburn 16773: if (keys(%changedprivs)) {
16774: foreach my $role (sort(keys(%changedprivs))) {
16775: unless ($shownprivs{$role}) {
16776: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16777: $role).'<ul>'.
16778: '<li>'.&mt('Privileges set to :').'<ul>';
16779: foreach my $level (@levelorder) {
16780: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16781: next if ($item eq '');
16782: my ($priv) = split(/\&/,$item,2);
16783: if (&Apache::lonnet::plaintext($priv)) {
16784: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16785: unless ($level eq 'c') {
16786: $resulttext .= ' ('.$lt{$level}.')';
16787: }
16788: $resulttext .= '</li>';
16789: }
16790: }
16791: }
16792: $resulttext .= '</ul></li></ul></li>';
16793: }
16794: }
16795: }
16796: $resulttext .= '</ul>';
16797: } else {
16798: $resulttext = &mt('No changes made to help settings');
1.118 jms 16799: }
16800: if ($errors) {
1.160.6.5 raeburn 16801: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 16802: $errors.'</ul>';
1.118 jms 16803: }
16804: return $resulttext;
16805: }
16806:
1.121 raeburn 16807: sub modify_coursedefaults {
1.160.6.27 raeburn 16808: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16809: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 16810: my %defaultchecked = (
16811: 'uselcmath' => 'on',
1.160.6.115 raeburn 16812: 'usejsme' => 'on',
16813: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 16814:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 16815: );
1.160.6.118.2 4(raebur 16816:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 16817: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 16818: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
16819: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 16820: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 16821: my %staticdefaults = (
16822: anonsurvey_threshold => 10,
16823: uploadquota => 500,
1.160.6.57 raeburn 16824: postsubmit => 60,
1.160.6.70 raeburn 16825: mysqltables => 172800,
1.160.6.21 raeburn 16826: );
1.160.6.90 raeburn 16827: my %texoptions = (
16828: MathJax => 'MathJax',
16829: mimetex => &mt('Convert to Images'),
16830: tth => &mt('TeX to HTML'),
16831: );
1.121 raeburn 16832: $defaultshash{'coursedefaults'} = {};
16833:
16834: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16835: if ($domconfig{'coursedefaults'} eq '') {
16836: $domconfig{'coursedefaults'} = {};
16837: }
16838: }
16839:
16840: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16841: foreach my $item (@toggles) {
16842: if ($defaultchecked{$item} eq 'on') {
16843: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16844: ($env{'form.'.$item} eq '0')) {
16845: $changes{$item} = 1;
1.160.6.16 raeburn 16846: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16847: $changes{$item} = 1;
16848: }
16849: } elsif ($defaultchecked{$item} eq 'off') {
16850: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16851: ($env{'form.'.$item} eq '1')) {
16852: $changes{$item} = 1;
16853: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16854: $changes{$item} = 1;
16855: }
16856: }
16857: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16858: }
1.160.6.21 raeburn 16859: foreach my $item (@numbers) {
16860: my ($currdef,$newdef);
1.160.6.26 raeburn 16861: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 16862: if ($item eq 'anonsurvey_threshold') {
16863: $currdef = $domconfig{'coursedefaults'}{$item};
16864: $newdef =~ s/\D//g;
16865: if ($newdef eq '' || $newdef < 1) {
16866: $newdef = 1;
16867: }
16868: $defaultshash{'coursedefaults'}{$item} = $newdef;
16869: } else {
1.160.6.70 raeburn 16870: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16871: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16872: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 16873: }
16874: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 16875: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 16876: }
16877: if ($currdef ne $newdef) {
16878: if ($item eq 'anonsurvey_threshold') {
16879: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16880: $changes{$item} = 1;
16881: }
1.160.6.70 raeburn 16882: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
16883: my $setting = $1;
16884: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16885: $changes{$setting} = 1;
1.160.6.21 raeburn 16886: }
16887: }
1.139 raeburn 16888: }
16889: }
1.160.6.90 raeburn 16890: my $texengine;
16891: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16892: $texengine = $env{'form.texengine'};
16893: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
16894: if ($currdef eq '') {
16895: unless ($texengine eq $Apache::lonnet::deftex) {
16896: $changes{'texengine'} = 1;
16897: }
16898: } elsif ($currdef ne $texengine) {
16899: $changes{'texengine'} = 1;
16900: }
16901: }
16902: if ($texengine ne '') {
16903: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16904: }
1.160.6.64 raeburn 16905: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16906: my @currclonecode;
16907: if (ref($currclone) eq 'HASH') {
16908: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16909: @currclonecode = @{$currclone->{'instcode'}};
16910: }
16911: }
16912: my $newclone;
16913: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
16914: $newclone = $env{'form.canclone'};
16915: }
16916: if ($newclone eq 'instcode') {
16917: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16918: my (%codedefaults,@code_order,@clonecode);
16919: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16920: \@code_order);
16921: foreach my $item (@code_order) {
16922: if (grep(/^\Q$item\E$/,@newcodes)) {
16923: push(@clonecode,$item);
16924: }
16925: }
16926: if (@clonecode) {
16927: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16928: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16929: if (@diffs) {
16930: $changes{'canclone'} = 1;
16931: }
16932: } else {
16933: $newclone eq '';
16934: }
16935: } elsif ($newclone ne '') {
16936: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16937: }
16938: if ($newclone ne $currclone) {
16939: $changes{'canclone'} = 1;
16940: }
1.160.6.57 raeburn 16941: my %credits;
16942: foreach my $type (@types) {
16943: unless ($type eq 'community') {
16944: $credits{$type} = $env{'form.'.$type.'_credits'};
16945: $credits{$type} =~ s/[^\d.]+//g;
16946: }
16947: }
16948: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
16949: ($env{'form.coursecredits'} eq '1')) {
16950: $changes{'coursecredits'} = 1;
16951: foreach my $type (keys(%credits)) {
16952: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16953: }
16954: } else {
16955: if ($env{'form.coursecredits'} eq '1') {
16956: foreach my $type (@types) {
16957: unless ($type eq 'community') {
16958: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
16959: $changes{'coursecredits'} = 1;
16960: }
16961: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16962: }
16963: }
16964: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16965: foreach my $type (@types) {
16966: unless ($type eq 'community') {
16967: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
16968: $changes{'coursecredits'} = 1;
16969: last;
16970: }
16971: }
16972: }
16973: }
16974: }
16975: if ($env{'form.postsubmit'} eq '1') {
16976: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
16977: my %currtimeout;
16978: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16979: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
16980: $changes{'postsubmit'} = 1;
16981: }
16982: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16983: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
16984: }
16985: } else {
16986: $changes{'postsubmit'} = 1;
16987: }
16988: foreach my $type (@types) {
16989: my $timeout = $env{'form.'.$type.'_timeout'};
16990: $timeout =~ s/\D//g;
16991: if ($timeout == $staticdefaults{'postsubmit'}) {
16992: $timeout = '';
16993: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
16994: $timeout = '0';
16995: }
16996: unless ($timeout eq '') {
16997: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
16998: }
16999: if (exists($currtimeout{$type})) {
17000: if ($timeout ne $currtimeout{$type}) {
17001: $changes{'postsubmit'} = 1;
17002: }
17003: } elsif ($timeout ne '') {
17004: $changes{'postsubmit'} = 1;
17005: }
17006: }
17007: } else {
17008: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17009: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17010: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17011: $changes{'postsubmit'} = 1;
17012: }
17013: } else {
17014: $changes{'postsubmit'} = 1;
17015: }
1.160.6.16 raeburn 17016: }
1.121 raeburn 17017: }
17018: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17019: $dom);
17020: if ($putresult eq 'ok') {
17021: if (keys(%changes) > 0) {
1.160.6.27 raeburn 17022: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 17023: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 17024: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 17025: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 4(raebur 17026:2): ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
17027:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 17028: if ($changes{$item}) {
17029: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17030: }
1.160.6.16 raeburn 17031: }
17032: if ($changes{'coursecredits'}) {
17033: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 17034: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17035: $domdefaults{$type.'credits'} =
17036: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17037: }
17038: }
17039: }
17040: if ($changes{'postsubmit'}) {
17041: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17042: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17043: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17044: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17045: $domdefaults{$type.'postsubtimeout'} =
17046: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17047: }
17048: }
1.160.6.16 raeburn 17049: }
17050: }
1.160.6.21 raeburn 17051: if ($changes{'uploadquota'}) {
17052: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17053: foreach my $type (@types) {
17054: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17055: }
17056: }
17057: }
1.160.6.64 raeburn 17058: if ($changes{'canclone'}) {
17059: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17060: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17061: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17062: if (@clonecodes) {
17063: $domdefaults{'canclone'} = join('+',@clonecodes);
17064: }
17065: }
17066: } else {
17067: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17068: }
17069: }
1.121 raeburn 17070: my $cachetime = 24*60*60;
17071: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17072: if (ref($lastactref) eq 'HASH') {
17073: $lastactref->{'domdefaults'} = 1;
17074: }
1.121 raeburn 17075: }
17076: $resulttext = &mt('Changes made:').'<ul>';
17077: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 17078: if ($item eq 'uselcmath') {
1.121 raeburn 17079: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 17080: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 17081: } else {
1.160.6.57 raeburn 17082: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17083: }
17084: } elsif ($item eq 'usejsme') {
17085: if ($env{'form.'.$item} eq '1') {
17086: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17087: } else {
17088: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 17089: }
1.160.6.115 raeburn 17090: } elsif ($item eq 'inline_chem') {
17091: if ($env{'form.'.$item} eq '1') {
17092: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17093: } else {
17094: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17095: }
1.160.6.90 raeburn 17096: } elsif ($item eq 'texengine') {
17097: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17098: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17099: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17100: }
1.139 raeburn 17101: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 17102: $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 17103: } elsif ($item eq 'uploadquota') {
17104: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17105: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17106: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17107: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 17108: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17109:
1.160.6.21 raeburn 17110: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17111: '</ul>'.
17112: '</li>';
17113: } else {
17114: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17115: }
1.160.6.70 raeburn 17116: } elsif ($item eq 'mysqltables') {
17117: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17118: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17119: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17120: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17121: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17122: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17123: '</ul>'.
17124: '</li>';
17125: } else {
17126: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17127: }
1.160.6.57 raeburn 17128: } elsif ($item eq 'postsubmit') {
17129: if ($domdefaults{'postsubmit'} eq 'off') {
17130: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17131: } else {
17132: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17133: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17134: $resulttext .= &mt('durations:').'<ul>';
17135: foreach my $type (@types) {
17136: $resulttext .= '<li>';
17137: my $timeout;
17138: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17139: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17140: }
17141: my $display;
17142: if ($timeout eq '0') {
17143: $display = &mt('unlimited');
17144: } elsif ($timeout eq '') {
17145: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17146: } else {
17147: $display = &mt('[quant,_1,second]',$timeout);
17148: }
17149: if ($type eq 'community') {
17150: $resulttext .= &mt('Communities');
17151: } elsif ($type eq 'official') {
17152: $resulttext .= &mt('Official courses');
17153: } elsif ($type eq 'unofficial') {
17154: $resulttext .= &mt('Unofficial courses');
17155: } elsif ($type eq 'textbook') {
17156: $resulttext .= &mt('Textbook courses');
17157: }
17158: $resulttext .= ' -- '.$display.'</li>';
17159: }
17160: $resulttext .= '</ul>';
17161: }
17162: $resulttext .= '</li>';
17163: }
1.160.6.16 raeburn 17164: } elsif ($item eq 'coursecredits') {
17165: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17166: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 17167: ($domdefaults{'unofficialcredits'} eq '') &&
17168: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 17169: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17170: } else {
17171: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17172: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17173: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 17174: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 17175: '</ul>'.
17176: '</li>';
17177: }
17178: } else {
17179: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17180: }
1.160.6.64 raeburn 17181: } elsif ($item eq 'canclone') {
17182: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17183: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17184: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17185: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17186: }
17187: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17188: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17189: } else {
17190: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
17191: }
1.160.6.118.2 4(raebur 17192:2): } elsif ($item eq 'ltiauth') {
17193:2): if ($env{'form.'.$item} eq '1') {
17194:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
17195:2): } else {
17196:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
17197:2): }
1.140 raeburn 17198: }
1.121 raeburn 17199: }
17200: $resulttext .= '</ul>';
17201: } else {
17202: $resulttext = &mt('No changes made to course defaults');
17203: }
17204: } else {
17205: $resulttext = '<span class="LC_error">'.
17206: &mt('An error occurred: [_1]',$putresult).'</span>';
17207: }
17208: return $resulttext;
17209: }
17210:
1.160.6.37 raeburn 17211: sub modify_selfenrollment {
17212: my ($dom,$lastactref,%domconfig) = @_;
17213: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
17214: my @types = ('official','unofficial','community','textbook');
17215: my %titles = &tool_titles();
17216: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17217: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
17218: $ordered{'default'} = ['types','registered','approval','limit'];
17219:
17220: my (%roles,%shown,%toplevel);
17221: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17222:
17223: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17224: if ($domconfig{'selfenrollment'} eq '') {
17225: $domconfig{'selfenrollment'} = {};
17226: }
17227: }
17228: %toplevel = (
17229: admin => 'Configuration Rights',
17230: default => 'Default settings',
17231: validation => 'Validation of self-enrollment requests',
17232: );
17233: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
17234:
17235: if (ref($ordered{'admin'}) eq 'ARRAY') {
17236: foreach my $item (@{$ordered{'admin'}}) {
17237: foreach my $type (@types) {
17238: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17239: $selfenrollhash{'admin'}{$type}{$item} = 1;
17240: } else {
17241: $selfenrollhash{'admin'}{$type}{$item} = 0;
17242: }
17243: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17244: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17245: if ($selfenrollhash{'admin'}{$type}{$item} ne
17246: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17247: push(@{$changes{'admin'}{$type}},$item);
17248: }
17249: } else {
17250: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17251: push(@{$changes{'admin'}{$type}},$item);
17252: }
17253: }
17254: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17255: push(@{$changes{'admin'}{$type}},$item);
17256: }
17257: }
17258: }
17259: }
17260:
17261: foreach my $item (@{$ordered{'default'}}) {
17262: foreach my $type (@types) {
17263: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17264: if ($item eq 'types') {
17265: unless (($value eq 'all') || ($value eq 'dom')) {
17266: $value = '';
17267: }
17268: } elsif ($item eq 'registered') {
17269: unless ($value eq '1') {
17270: $value = 0;
17271: }
17272: } elsif ($item eq 'approval') {
17273: unless ($value =~ /^[012]$/) {
17274: $value = 0;
17275: }
17276: } else {
17277: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17278: $value = 'none';
17279: }
17280: }
17281: $selfenrollhash{'default'}{$type}{$item} = $value;
17282: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17283: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17284: if ($selfenrollhash{'default'}{$type}{$item} ne
17285: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17286: push(@{$changes{'default'}{$type}},$item);
17287: }
17288: } else {
17289: push(@{$changes{'default'}{$type}},$item);
17290: }
17291: } else {
17292: push(@{$changes{'default'}{$type}},$item);
17293: }
17294: if ($item eq 'limit') {
17295: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17296: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17297: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17298: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17299: }
17300: } else {
17301: $selfenrollhash{'default'}{$type}{'cap'} = '';
17302: }
17303: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17304: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17305: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17306: push(@{$changes{'default'}{$type}},'cap');
17307: }
17308: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17309: push(@{$changes{'default'}{$type}},'cap');
17310: }
17311: }
17312: }
17313: }
17314:
17315: foreach my $item (@{$itemsref}) {
17316: if ($item eq 'fields') {
17317: my @changed;
17318: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17319: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17320: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17321: }
17322: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17323: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17324: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17325: $domconfig{'selfenrollment'}{'validation'}{$item});
17326: } else {
17327: @changed = @{$selfenrollhash{'validation'}{$item}};
17328: }
17329: } else {
17330: @changed = @{$selfenrollhash{'validation'}{$item}};
17331: }
17332: if (@changed) {
17333: if ($selfenrollhash{'validation'}{$item}) {
17334: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17335: } else {
17336: $changes{'validation'}{$item} = &mt('None');
17337: }
17338: }
17339: } else {
17340: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17341: if ($item eq 'markup') {
17342: if ($env{'form.selfenroll_validation_'.$item}) {
17343: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17344: }
17345: }
17346: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17347: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17348: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17349: }
17350: }
17351: }
17352: }
17353:
17354: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17355: $dom);
17356: if ($putresult eq 'ok') {
17357: if (keys(%changes) > 0) {
17358: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17359: $resulttext = &mt('Changes made:').'<ul>';
17360: foreach my $key ('admin','default','validation') {
17361: if (ref($changes{$key}) eq 'HASH') {
17362: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17363: if ($key eq 'validation') {
17364: foreach my $item (@{$itemsref}) {
17365: if (exists($changes{$key}{$item})) {
17366: if ($item eq 'markup') {
17367: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17368: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17369: } else {
17370: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17371: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17372: }
17373: }
17374: }
17375: } else {
17376: foreach my $type (@types) {
17377: if ($type eq 'community') {
17378: $roles{'1'} = &mt('Community personnel');
17379: } else {
17380: $roles{'1'} = &mt('Course personnel');
17381: }
17382: if (ref($changes{$key}{$type}) eq 'ARRAY') {
17383: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17384: if ($key eq 'admin') {
17385: my @mgrdc = ();
17386: if (ref($ordered{$key}) eq 'ARRAY') {
17387: foreach my $item (@{$ordered{'admin'}}) {
17388: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17389: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17390: push(@mgrdc,$item);
17391: }
17392: }
17393: }
17394: if (@mgrdc) {
17395: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17396: } else {
17397: delete($domdefaults{$type.'selfenrolladmdc'});
17398: }
17399: }
17400: } else {
17401: if (ref($ordered{$key}) eq 'ARRAY') {
17402: foreach my $item (@{$ordered{$key}}) {
17403: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17404: $domdefaults{$type.'selfenroll'.$item} =
17405: $selfenrollhash{$key}{$type}{$item};
17406: }
17407: }
17408: }
17409: }
17410: }
17411: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17412: foreach my $item (@{$ordered{$key}}) {
17413: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17414: $resulttext .= '<li>';
17415: if ($key eq 'admin') {
17416: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17417: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17418: } else {
17419: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17420: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17421: }
17422: $resulttext .= '</li>';
17423: }
17424: }
17425: $resulttext .= '</ul></li>';
17426: }
17427: }
17428: $resulttext .= '</ul></li>';
17429: }
17430: }
1.160.6.93 raeburn 17431: }
17432: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17433: my $cachetime = 24*60*60;
17434: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17435: if (ref($lastactref) eq 'HASH') {
17436: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 17437: }
17438: }
17439: $resulttext .= '</ul>';
17440: } else {
17441: $resulttext = &mt('No changes made to self-enrollment settings');
17442: }
17443: } else {
17444: $resulttext = '<span class="LC_error">'.
17445: &mt('An error occurred: [_1]',$putresult).'</span>';
17446: }
17447: return $resulttext;
17448: }
17449:
1.160.6.113 raeburn 17450: sub modify_wafproxy {
17451: my ($dom,$action,$lastactref,%domconfig) = @_;
17452: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17453: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
17454: %wafproxy,%changes,%expirecache,%expiresaml);
17455: foreach my $server (sort(keys(%servers))) {
17456: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17457: if ($serverhome eq $server) {
17458: my $serverdom = &Apache::lonnet::host_domain($server);
17459: if ($serverdom eq $dom) {
17460: $canset{$server} = 1;
17461: }
17462: }
17463: }
17464: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
17465: %{$values{$dom}} = ();
17466: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
17467: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
17468: }
17469: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
17470: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
17471: }
17472: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
17473: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
17474: }
17475: }
17476: my $output;
17477: if (keys(%canset)) {
17478: %{$wafproxy{'alias'}} = ();
17479: %{$wafproxy{'saml'}} = ();
17480: foreach my $key (sort(keys(%canset))) {
17481: if ($env{'form.wafproxy_'.$dom}) {
17482: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
17483: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
17484: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
17485: $changes{'alias'} = 1;
17486: }
17487: if ($env{'form.wafproxy_alias_saml_'.$key}) {
17488: $wafproxy{'saml'}{$key} = 1;
17489: }
17490: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
17491: $changes{'saml'} = 1;
17492: }
17493: } else {
17494: $wafproxy{'alias'}{$key} = '';
17495: $wafproxy{'saml'}{$key} = '';
17496: if ($curralias{$key}) {
17497: $changes{'alias'} = 1;
17498: }
17499: if ($currsaml{$key}) {
17500: $changes{'saml'} = 1;
17501: }
17502: }
17503: if ($wafproxy{'alias'}{$key} eq '') {
17504: if ($curralias{$key}) {
17505: $expirecache{$key} = 1;
17506: }
17507: delete($wafproxy{'alias'}{$key});
17508: }
17509: if ($wafproxy{'saml'}{$key} eq '') {
17510: if ($currsaml{$key}) {
17511: $expiresaml{$key} = 1;
17512: }
17513: delete($wafproxy{'saml'}{$key});
17514: }
17515: }
17516: unless (keys(%{$wafproxy{'alias'}})) {
17517: delete($wafproxy{'alias'});
17518: }
17519: unless (keys(%{$wafproxy{'saml'}})) {
17520: delete($wafproxy{'saml'});
17521: }
17522: # Localization for values in %warn occurs in &mt() calls separately.
17523: my %warn = (
17524: trusted => 'trusted IP range(s)',
17525: vpnint => 'internal IP range(s) for VPN sessions(s)',
17526: vpnext => 'IP range(s) for backend WAF connections',
17527: );
17528: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
17529: my $possible = $env{'form.wafproxy_'.$item};
17530: $possible =~ s/^\s+|\s+$//g;
17531: if ($possible ne '') {
17532: if ($item eq 'remoteip') {
17533: if ($possible =~ /^[mhn]$/) {
17534: $wafproxy{$item} = $possible;
17535: }
17536: } elsif ($item eq 'ipheader') {
17537: if ($wafproxy{'remoteip'} eq 'h') {
17538: $wafproxy{$item} = $possible;
17539: }
17540: } elsif ($item eq 'sslopt') {
17541: if ($possible =~ /^0|1$/) {
17542: $wafproxy{$item} = $possible;
17543: }
17544: } else {
17545: my (@ok,$count);
17546: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
17547: unless ($env{'form.wafproxy_vpnaccess'}) {
17548: $possible = '';
17549: }
17550: } elsif ($item eq 'trusted') {
17551: unless ($wafproxy{'remoteip'} eq 'h') {
17552: $possible = '';
17553: }
17554: }
17555: unless ($possible eq '') {
17556: $possible =~ s/[\r\n]+/\s/g;
17557: $possible =~ s/\s*-\s*/-/g;
17558: $possible =~ s/\s+/,/g;
17559: $possible =~ s/,+/,/g;
17560: }
17561: $count = 0;
17562: if ($possible ne '') {
17563: foreach my $poss (split(/\,/,$possible)) {
17564: $count ++;
17565: $poss = &validate_ip_pattern($poss);
17566: if ($poss ne '') {
17567: push(@ok,$poss);
17568: }
17569: }
17570: my $diff = $count - scalar(@ok);
17571: if ($diff) {
17572: push(@warnings,'<li>'.
17573: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
17574: $diff,$warn{$item}).
17575: '</li>');
17576: }
17577: if (@ok) {
17578: my @cidr_list;
17579: foreach my $item (@ok) {
17580: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
17581: }
17582: $wafproxy{$item} = join(',',@cidr_list);
17583: }
17584: }
17585: }
17586: if ($wafproxy{$item} ne $currvalue{$item}) {
17587: $changes{$item} = 1;
17588: }
17589: } elsif ($currvalue{$item}) {
17590: $changes{$item} = 1;
17591: }
17592: }
17593: } else {
17594: if (keys(%curralias)) {
17595: $changes{'alias'} = 1;
17596: }
17597: if (keys(%currsaml)) {
17598: $changes{'saml'} = 1;
17599: }
17600: if (keys(%currvalue)) {
17601: foreach my $key (keys(%currvalue)) {
17602: $changes{$key} = 1;
17603: }
17604: }
17605: }
17606: if (keys(%changes)) {
17607: my %defaultshash = (
17608: wafproxy => \%wafproxy,
17609: );
17610: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17611: $dom);
17612: if ($putresult eq 'ok') {
17613: my $cachetime = 24*60*60;
17614: my (%domdefaults,$updatedomdefs);
17615: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
17616: if ($changes{$item}) {
17617: unless ($updatedomdefs) {
17618: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17619: $updatedomdefs = 1;
17620: }
17621: if ($wafproxy{$item}) {
17622: $domdefaults{'waf_'.$item} = $wafproxy{$item};
17623: } elsif (exists($domdefaults{'waf_'.$item})) {
17624: delete($domdefaults{'waf_'.$item});
17625: }
17626: }
17627: }
17628: if ($updatedomdefs) {
17629: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17630: if (ref($lastactref) eq 'HASH') {
17631: $lastactref->{'domdefaults'} = 1;
17632: }
17633: }
17634: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
17635: my %updates = %expirecache;
17636: foreach my $key (keys(%expirecache)) {
17637: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
17638: }
17639: if (ref($wafproxy{'alias'}) eq 'HASH') {
17640: my $cachetime = 24*60*60;
17641: foreach my $key (keys(%{$wafproxy{'alias'}})) {
17642: $updates{$key} = 1;
17643: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
17644: $cachetime);
17645: }
17646: }
17647: if (ref($lastactref) eq 'HASH') {
17648: $lastactref->{'proxyalias'} = \%updates;
17649: }
17650: }
17651: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
17652: my %samlupdates = %expiresaml;
17653: foreach my $key (keys(%expiresaml)) {
17654: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
17655: }
17656: if (ref($wafproxy{'saml'}) eq 'HASH') {
17657: my $cachetime = 24*60*60;
17658: foreach my $key (keys(%{$wafproxy{'saml'}})) {
17659: $samlupdates{$key} = 1;
17660: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
17661: $cachetime);
17662: }
17663: }
17664: if (ref($lastactref) eq 'HASH') {
17665: $lastactref->{'proxysaml'} = \%samlupdates;
17666: }
17667: }
17668: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 17669: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 17670: if ($changes{$item}) {
17671: if ($item eq 'alias') {
17672: my $numaliased = 0;
17673: if (ref($wafproxy{'alias'}) eq 'HASH') {
17674: my $shown;
17675: if (keys(%{$wafproxy{'alias'}})) {
17676: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
17677: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
17678: &Apache::lonnet::hostname($server),
17679: $wafproxy{'alias'}{$server}).'</li>';
17680: $numaliased ++;
17681: }
17682: if ($numaliased) {
17683: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
17684: '<ul>'.$shown.'</ul>').'</li>';
17685: }
17686: }
17687: }
17688: unless ($numaliased) {
17689: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
17690: }
17691: } elsif ($item eq 'saml') {
17692: my $shown;
17693: if (ref($wafproxy{'saml'}) eq 'HASH') {
17694: if (keys(%{$wafproxy{'saml'}})) {
17695: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
17696: }
17697: }
17698: if ($shown) {
17699: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
17700: $shown).'</li>';
17701: } else {
17702: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
17703: }
17704: } else {
17705: if ($item eq 'remoteip') {
17706: my %ip_methods = &remoteip_methods();
17707: if ($wafproxy{$item} =~ /^[mh]$/) {
17708: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
17709: $ip_methods{$wafproxy{$item}}).'</li>';
17710: } else {
17711: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
17712: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
17713: '</li>';
17714: } else {
17715: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
17716: }
17717: }
17718: } elsif ($item eq 'ipheader') {
17719: if ($wafproxy{$item}) {
17720: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
17721: $wafproxy{$item}).'</li>';
17722: } else {
17723: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
17724: }
17725: } elsif ($item eq 'trusted') {
17726: if ($wafproxy{$item}) {
17727: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
17728: $wafproxy{$item}).'</li>';
17729: } else {
17730: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
17731: }
17732: } elsif ($item eq 'vpnint') {
17733: if ($wafproxy{$item}) {
17734: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
17735: $wafproxy{$item}).'</li>';
17736: } else {
17737: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
17738: }
17739: } elsif ($item eq 'vpnext') {
17740: if ($wafproxy{$item}) {
17741: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
17742: $wafproxy{$item}).'</li>';
17743: } else {
17744: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
17745: }
17746: } elsif ($item eq 'sslopt') {
17747: if ($wafproxy{$item}) {
17748: $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>';
17749: } else {
17750: $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>';
17751: }
17752: }
17753: }
17754: }
17755: }
17756: } else {
17757: $output = '<span class="LC_error">'.
17758: &mt('An error occurred: [_1]',$putresult).'</span>';
17759: }
17760: } elsif (keys(%canset)) {
17761: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
17762: }
17763: if (@warnings) {
17764: $output .= '<br />'.&mt('Warnings:').'<ul>'.
17765: join("\n",@warnings).'</ul>';
17766: }
17767: return $output;
17768: }
17769:
17770: sub validate_ip_pattern {
17771: my ($pattern) = @_;
17772: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
17773: my ($start,$end) = ($1,$2);
17774: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
17775: if (($start !~ m{/}) && ($end !~ m{/})) {
17776: return $start.'-'.$end;
17777: }
17778: }
17779: } elsif ($pattern ne '') {
17780: $pattern = &Net::CIDR::cidrvalidate($pattern);
17781: if ($pattern ne '') {
17782: return $pattern;
17783: }
17784: }
17785: return;
17786: }
17787:
1.137 raeburn 17788: sub modify_usersessions {
1.160.6.27 raeburn 17789: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17790: my @hostingtypes = ('version','excludedomain','includedomain');
17791: my @offloadtypes = ('primary','default');
17792: my %types = (
17793: remote => \@hostingtypes,
17794: hosted => \@hostingtypes,
17795: spares => \@offloadtypes,
17796: );
17797: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17798: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 17799: my (%by_ip,%by_location,@intdoms);
17800: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
17801: my @locations = sort(keys(%by_location));
1.137 raeburn 17802: my (%defaultshash,%changes);
17803: foreach my $prefix (@prefixes) {
17804: $defaultshash{'usersessions'}{$prefix} = {};
17805: }
1.160.6.27 raeburn 17806: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17807: my $resulttext;
1.138 raeburn 17808: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17809: foreach my $prefix (@prefixes) {
1.145 raeburn 17810: next if ($prefix eq 'spares');
17811: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 17812: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17813: if ($type eq 'version') {
17814: my $value = $env{'form.'.$prefix.'_'.$type};
17815: my $okvalue;
17816: if ($value ne '') {
17817: if (grep(/^\Q$value\E$/,@lcversions)) {
17818: $okvalue = $value;
17819: }
17820: }
17821: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17822: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17823: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
17824: if ($inuse == 0) {
17825: $changes{$prefix}{$type} = 1;
17826: } else {
17827: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
17828: $changes{$prefix}{$type} = 1;
17829: }
17830: if ($okvalue ne '') {
17831: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17832: }
17833: }
17834: } else {
17835: if (($inuse == 1) && ($okvalue ne '')) {
17836: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17837: $changes{$prefix}{$type} = 1;
17838: }
17839: }
17840: } else {
17841: if (($inuse == 1) && ($okvalue ne '')) {
17842: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17843: $changes{$prefix}{$type} = 1;
17844: }
17845: }
17846: } else {
17847: if (($inuse == 1) && ($okvalue ne '')) {
17848: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17849: $changes{$prefix}{$type} = 1;
17850: }
17851: }
17852: } else {
17853: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17854: my @okvals;
17855: foreach my $val (@vals) {
1.138 raeburn 17856: if ($val =~ /:/) {
17857: my @items = split(/:/,$val);
17858: foreach my $item (@items) {
17859: if (ref($by_location{$item}) eq 'ARRAY') {
17860: push(@okvals,$item);
17861: }
17862: }
17863: } else {
17864: if (ref($by_location{$val}) eq 'ARRAY') {
17865: push(@okvals,$val);
17866: }
1.137 raeburn 17867: }
17868: }
17869: @okvals = sort(@okvals);
17870: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17871: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17872: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17873: if ($inuse == 0) {
17874: $changes{$prefix}{$type} = 1;
17875: } else {
17876: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17877: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
17878: if (@changed > 0) {
17879: $changes{$prefix}{$type} = 1;
17880: }
17881: }
17882: } else {
17883: if ($inuse == 1) {
17884: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17885: $changes{$prefix}{$type} = 1;
17886: }
17887: }
17888: } else {
17889: if ($inuse == 1) {
17890: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17891: $changes{$prefix}{$type} = 1;
17892: }
17893: }
17894: } else {
17895: if ($inuse == 1) {
17896: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17897: $changes{$prefix}{$type} = 1;
17898: }
17899: }
17900: }
17901: }
17902: }
1.145 raeburn 17903:
17904: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 17905: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 17906: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
17907: my $savespares;
17908:
17909: foreach my $lonhost (sort(keys(%servers))) {
17910: my $serverhomeID =
17911: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 17912: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 17913: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
17914: my %spareschg;
17915: foreach my $type (@{$types{'spares'}}) {
17916: my @okspares;
17917: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
17918: foreach my $server (@checked) {
1.152 raeburn 17919: if (&Apache::lonnet::hostname($server) ne '') {
17920: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
17921: unless (grep(/^\Q$server\E$/,@okspares)) {
17922: push(@okspares,$server);
17923: }
1.145 raeburn 17924: }
17925: }
17926: }
17927: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
17928: my $newspare;
1.152 raeburn 17929: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
17930: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 17931: $newspare = $new;
17932: }
17933: }
1.152 raeburn 17934: my @spares;
17935: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
17936: @spares = sort(@okspares,$newspare);
17937: } else {
17938: @spares = sort(@okspares);
17939: }
17940: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 17941: if (ref($spareid{$lonhost}) eq 'HASH') {
17942: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 17943: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 17944: if (@diffs > 0) {
17945: $spareschg{$type} = 1;
17946: }
17947: }
17948: }
17949: }
17950: if (keys(%spareschg) > 0) {
17951: $changes{'spares'}{$lonhost} = \%spareschg;
17952: }
17953: }
1.160.6.61 raeburn 17954: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 17955: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 17956: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
17957: my @okoffload;
17958: if (@offloadnow) {
17959: foreach my $server (@offloadnow) {
17960: if (&Apache::lonnet::hostname($server) ne '') {
17961: unless (grep(/^\Q$server\E$/,@okoffload)) {
17962: push(@okoffload,$server);
17963: }
17964: }
17965: }
17966: if (@okoffload) {
17967: foreach my $lonhost (@okoffload) {
17968: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
17969: }
17970: }
17971: }
1.160.6.105 raeburn 17972: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
17973: my @okoffloadoth;
17974: if (@offloadoth) {
17975: foreach my $server (@offloadoth) {
17976: if (&Apache::lonnet::hostname($server) ne '') {
17977: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
17978: push(@okoffloadoth,$server);
17979: }
17980: }
17981: }
17982: if (@okoffloadoth) {
17983: foreach my $lonhost (@okoffloadoth) {
17984: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
17985: }
17986: }
17987: }
1.145 raeburn 17988: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17989: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
17990: if (ref($changes{'spares'}) eq 'HASH') {
17991: if (keys(%{$changes{'spares'}}) > 0) {
17992: $savespares = 1;
17993: }
17994: }
17995: } else {
17996: $savespares = 1;
17997: }
1.160.6.105 raeburn 17998: foreach my $offload ('offloadnow','offloadoth') {
17999: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
18000: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
18001: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
18002: $changes{$offload} = 1;
1.160.6.61 raeburn 18003: last;
18004: }
18005: }
1.160.6.105 raeburn 18006: unless ($changes{$offload}) {
18007: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
18008: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
18009: $changes{$offload} = 1;
18010: last;
18011: }
18012: }
18013: }
18014: } else {
18015: if (($offload eq 'offloadnow') && (@okoffload)) {
18016: $changes{'offloadnow'} = 1;
18017: }
18018: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
18019: $changes{'offloadoth'} = 1;
18020: }
1.160.6.61 raeburn 18021: }
1.160.6.105 raeburn 18022: }
18023: } else {
18024: if (@okoffload) {
1.160.6.61 raeburn 18025: $changes{'offloadnow'} = 1;
18026: }
1.160.6.105 raeburn 18027: if (@okoffloadoth) {
18028: $changes{'offloadoth'} = 1;
18029: }
1.145 raeburn 18030: }
1.147 raeburn 18031: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18032: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18033: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18034: $dom);
18035: if ($putresult eq 'ok') {
18036: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18037: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18038: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18039: }
18040: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18041: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18042: }
1.160.6.61 raeburn 18043: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18044: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18045: }
1.160.6.105 raeburn 18046: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18047: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18048: }
1.137 raeburn 18049: }
18050: my $cachetime = 24*60*60;
18051: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 18052: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 18053: if (ref($lastactref) eq 'HASH') {
18054: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 18055: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 18056: }
1.147 raeburn 18057: if (keys(%changes) > 0) {
18058: my %lt = &usersession_titles();
18059: $resulttext = &mt('Changes made:').'<ul>';
18060: foreach my $prefix (@prefixes) {
18061: if (ref($changes{$prefix}) eq 'HASH') {
18062: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18063: if ($prefix eq 'spares') {
18064: if (ref($changes{$prefix}) eq 'HASH') {
18065: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18066: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18067: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 18068: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18069: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18070: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18071: foreach my $type (@{$types{$prefix}}) {
18072: if ($changes{$prefix}{$lonhost}{$type}) {
18073: my $offloadto = &mt('None');
18074: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18075: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18076: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18077: }
1.145 raeburn 18078: }
1.147 raeburn 18079: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18080: }
1.137 raeburn 18081: }
18082: }
1.147 raeburn 18083: $resulttext .= '</li>';
1.137 raeburn 18084: }
18085: }
1.147 raeburn 18086: } else {
18087: foreach my $type (@{$types{$prefix}}) {
18088: if (defined($changes{$prefix}{$type})) {
18089: my $newvalue;
18090: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18091: if (ref($defaultshash{'usersessions'}{$prefix})) {
18092: if ($type eq 'version') {
18093: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18094: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18095: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18096: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18097: }
1.145 raeburn 18098: }
18099: }
18100: }
1.147 raeburn 18101: if ($newvalue eq '') {
18102: if ($type eq 'version') {
18103: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18104: } else {
18105: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18106: }
1.145 raeburn 18107: } else {
1.147 raeburn 18108: if ($type eq 'version') {
18109: $newvalue .= ' '.&mt('(or later)');
18110: }
18111: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18112: }
1.137 raeburn 18113: }
18114: }
18115: }
1.147 raeburn 18116: $resulttext .= '</ul>';
1.137 raeburn 18117: }
18118: }
1.160.6.61 raeburn 18119: if ($changes{'offloadnow'}) {
18120: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18121: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 18122: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 18123: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18124: $resulttext .= '<li>'.$lonhost.'</li>';
18125: }
18126: $resulttext .= '</ul>';
18127: } else {
1.160.6.105 raeburn 18128: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18129: }
18130: } else {
18131: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18132: }
18133: }
18134: if ($changes{'offloadoth'}) {
18135: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18136: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18137: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18138: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18139: $resulttext .= '<li>'.$lonhost.'</li>';
18140: }
18141: $resulttext .= '</ul>';
18142: } else {
18143: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 18144: }
18145: } else {
1.160.6.105 raeburn 18146: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 18147: }
18148: }
1.147 raeburn 18149: $resulttext .= '</ul>';
18150: } else {
18151: $resulttext = $nochgmsg;
1.137 raeburn 18152: }
18153: } else {
18154: $resulttext = '<span class="LC_error">'.
18155: &mt('An error occurred: [_1]',$putresult).'</span>';
18156: }
18157: } else {
1.147 raeburn 18158: $resulttext = $nochgmsg;
1.137 raeburn 18159: }
18160: return $resulttext;
18161: }
18162:
1.150 raeburn 18163: sub modify_loadbalancing {
18164: my ($dom,%domconfig) = @_;
18165: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18166: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18167: my ($othertitle,$usertypes,$types) =
18168: &Apache::loncommon::sorted_inst_types($dom);
18169: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 18170: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18171: my @sparestypes = ('primary','default');
18172: my %typetitles = &sparestype_titles();
18173: my $resulttext;
1.160.6.94 raeburn 18174: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18175: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18176: %existing = %{$domconfig{'loadbalancing'}};
18177: }
18178: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18179: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18180: my ($saveloadbalancing,%defaultshash,%changes);
18181: my ($alltypes,$othertypes,$titles) =
18182: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18183: my %ruletitles = &offloadtype_text();
18184: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18185: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18186: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18187: if ($balancer eq '') {
18188: next;
18189: }
18190: if (!exists($servers{$balancer})) {
18191: if (exists($currbalancer{$balancer})) {
18192: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18193: }
1.160.6.7 raeburn 18194: next;
18195: }
18196: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18197: push(@{$changes{'delete'}},$balancer);
18198: next;
18199: }
18200: if (!exists($currbalancer{$balancer})) {
18201: push(@{$changes{'add'}},$balancer);
18202: }
18203: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18204: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18205: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18206: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18207: $saveloadbalancing = 1;
18208: }
18209: foreach my $sparetype (@sparestypes) {
18210: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18211: my @offloadto;
18212: foreach my $target (@targets) {
18213: if (($servers{$target}) && ($target ne $balancer)) {
18214: if ($sparetype eq 'default') {
18215: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18216: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18217: }
18218: }
1.160.6.7 raeburn 18219: unless(grep(/^\Q$target\E$/,@offloadto)) {
18220: push(@offloadto,$target);
18221: }
1.150 raeburn 18222: }
18223: }
1.160.6.76 raeburn 18224: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18225: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18226: push(@offloadto,$balancer);
18227: }
18228: }
18229: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18230: }
1.160.6.94 raeburn 18231: if ($env{'form.loadbalancing_cookie_'.$i}) {
18232: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18233: if (exists($currbalancer{$balancer})) {
18234: unless ($currcookies{$balancer}) {
18235: $changes{'curr'}{$balancer}{'cookie'} = 1;
18236: }
18237: }
18238: } elsif (exists($currbalancer{$balancer})) {
18239: if ($currcookies{$balancer}) {
18240: $changes{'curr'}{$balancer}{'cookie'} = 1;
18241: }
18242: }
1.160.6.7 raeburn 18243: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18244: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 18245: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18246: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18247: if (@targetdiffs > 0) {
1.160.6.7 raeburn 18248: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18249: }
1.160.6.7 raeburn 18250: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18251: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18252: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18253: }
18254: }
18255: }
18256: } else {
1.160.6.7 raeburn 18257: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
18258: foreach my $sparetype (@sparestypes) {
18259: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18260: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18261: $changes{'curr'}{$balancer}{'targets'} = 1;
18262: }
1.150 raeburn 18263: }
18264: }
1.160.6.7 raeburn 18265: }
1.150 raeburn 18266: }
18267: my $ishomedom;
1.160.6.7 raeburn 18268: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18269: $ishomedom = 1;
1.150 raeburn 18270: }
18271: if (ref($alltypes) eq 'ARRAY') {
18272: foreach my $type (@{$alltypes}) {
18273: my $rule;
1.160.6.7 raeburn 18274: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18275: (!$ishomedom)) {
1.160.6.7 raeburn 18276: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18277: }
18278: if ($rule eq 'specific') {
1.160.6.55 raeburn 18279: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
18280: if (exists($servers{$specifiedhost})) {
18281: $rule = $specifiedhost;
18282: }
1.150 raeburn 18283: }
1.160.6.7 raeburn 18284: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18285: if (ref($currrules{$balancer}) eq 'HASH') {
18286: if ($rule ne $currrules{$balancer}{$type}) {
18287: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18288: }
18289: } elsif ($rule ne '') {
1.160.6.7 raeburn 18290: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18291: }
18292: }
18293: }
1.160.6.7 raeburn 18294: }
18295: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18296: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18297: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18298: $defaultshash{'loadbalancing'} = {};
18299: }
18300: my $putresult = &Apache::lonnet::put_dom('configuration',
18301: \%defaultshash,$dom);
18302: if ($putresult eq 'ok') {
18303: if (keys(%changes) > 0) {
1.160.6.54 raeburn 18304: my %toupdate;
1.160.6.7 raeburn 18305: if (ref($changes{'delete'}) eq 'ARRAY') {
18306: foreach my $balancer (sort(@{$changes{'delete'}})) {
18307: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 18308: $toupdate{$balancer} = 1;
1.150 raeburn 18309: }
1.160.6.7 raeburn 18310: }
18311: if (ref($changes{'add'}) eq 'ARRAY') {
18312: foreach my $balancer (sort(@{$changes{'add'}})) {
18313: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 18314: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18315: }
18316: }
18317: if (ref($changes{'curr'}) eq 'HASH') {
18318: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 18319: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18320: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18321: if ($changes{'curr'}{$balancer}{'targets'}) {
18322: my %offloadstr;
18323: foreach my $sparetype (@sparestypes) {
18324: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18325: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18326: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18327: }
18328: }
1.150 raeburn 18329: }
1.160.6.7 raeburn 18330: if (keys(%offloadstr) == 0) {
18331: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18332: } else {
1.160.6.7 raeburn 18333: my $showoffload;
18334: foreach my $sparetype (@sparestypes) {
18335: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18336: if (defined($offloadstr{$sparetype})) {
18337: $showoffload .= $offloadstr{$sparetype};
18338: } else {
18339: $showoffload .= &mt('None');
18340: }
18341: $showoffload .= (' 'x3);
18342: }
18343: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18344: }
18345: }
18346: }
1.160.6.7 raeburn 18347: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18348: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18349: foreach my $type (@{$alltypes}) {
18350: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18351: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18352: my $balancetext;
18353: if ($rule eq '') {
18354: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 18355: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 18356: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
18357: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 18358: foreach my $sparetype (@sparestypes) {
18359: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18360: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18361: }
18362: }
1.160.6.55 raeburn 18363: foreach my $item (@{$alltypes}) {
18364: next if ($item =~ /^_LC_ipchange/);
18365: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18366: if ($hasrule eq 'homeserver') {
18367: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18368: } else {
18369: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18370: if ($servers{$hasrule}) {
18371: $toupdate{$hasrule} = 1;
18372: }
18373: }
18374: }
18375: }
18376: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18377: $balancetext = $ruletitles{$rule};
18378: } else {
18379: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18380: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18381: if ($receiver) {
18382: $toupdate{$receiver};
18383: }
18384: }
18385: } else {
18386: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 18387: }
1.160.6.7 raeburn 18388: } else {
18389: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18390: }
1.160.6.26 raeburn 18391: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18392: }
18393: }
18394: }
18395: }
1.160.6.94 raeburn 18396: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 18397: if ($currcookies{$balancer}) {
18398: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
18399: $balancer).'</li>';
18400: } else {
18401: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18402: $balancer).'</li>';
18403: }
1.160.6.94 raeburn 18404: }
1.160.6.106 raeburn 18405: }
18406: }
18407: if (keys(%toupdate)) {
18408: my %thismachine;
18409: my $updatedhere;
18410: my $cachetime = 60*60*24;
18411: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18412: foreach my $lonhost (keys(%toupdate)) {
18413: if ($thismachine{$lonhost}) {
18414: unless ($updatedhere) {
18415: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18416: $defaultshash{'loadbalancing'},
18417: $cachetime);
18418: $updatedhere = 1;
1.160.6.54 raeburn 18419: }
1.160.6.106 raeburn 18420: } else {
18421: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18422: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 18423: }
1.150 raeburn 18424: }
1.160.6.7 raeburn 18425: }
18426: if ($resulttext ne '') {
18427: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18428: } else {
18429: $resulttext = $nochgmsg;
18430: }
18431: } else {
1.160.6.7 raeburn 18432: $resulttext = $nochgmsg;
1.150 raeburn 18433: }
18434: } else {
1.160.6.7 raeburn 18435: $resulttext = '<span class="LC_error">'.
18436: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18437: }
18438: } else {
1.160.6.7 raeburn 18439: $resulttext = $nochgmsg;
1.150 raeburn 18440: }
18441: return $resulttext;
18442: }
18443:
1.48 raeburn 18444: sub recurse_check {
18445: my ($chkcats,$categories,$depth,$name) = @_;
18446: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18447: my $chg = 0;
18448: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18449: my $category = $chkcats->[$depth]{$name}[$j];
18450: my $item;
18451: if ($category eq '') {
18452: $chg ++;
18453: } else {
18454: my $deeper = $depth + 1;
18455: $item = &escape($category).':'.&escape($name).':'.$depth;
18456: if ($chg) {
18457: $categories->{$item} -= $chg;
18458: }
18459: &recurse_check($chkcats,$categories,$deeper,$category);
18460: $deeper --;
18461: }
18462: }
18463: }
18464: return;
18465: }
18466:
18467: sub recurse_cat_deletes {
18468: my ($item,$coursecategories,$deletions) = @_;
18469: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18470: my $subdepth = $depth + 1;
18471: if (ref($coursecategories) eq 'HASH') {
18472: foreach my $subitem (keys(%{$coursecategories})) {
18473: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18474: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18475: delete($coursecategories->{$subitem});
18476: $deletions->{$subitem} = 1;
18477: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 18478: }
1.48 raeburn 18479: }
18480: }
18481: return;
18482: }
18483:
1.125 raeburn 18484: sub active_dc_picker {
1.160.6.16 raeburn 18485: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 18486: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 18487: my @domcoord = keys(%domcoords);
18488: if (keys(%currhash)) {
18489: foreach my $dc (keys(%currhash)) {
18490: unless (exists($domcoords{$dc})) {
18491: push(@domcoord,$dc);
18492: }
18493: }
18494: }
18495: @domcoord = sort(@domcoord);
18496: my $numdcs = scalar(@domcoord);
18497: my $rows = 0;
18498: my $table;
1.125 raeburn 18499: if ($numdcs > 1) {
1.160.6.16 raeburn 18500: $table = '<table>';
18501: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18502: my $rem = $i%($numinrow);
18503: if ($rem == 0) {
18504: if ($i > 0) {
1.160.6.16 raeburn 18505: $table .= '</tr>';
1.125 raeburn 18506: }
1.160.6.16 raeburn 18507: $table .= '<tr>';
18508: $rows ++;
1.125 raeburn 18509: }
1.160.6.16 raeburn 18510: my $check = '';
18511: if ($inputtype eq 'radio') {
18512: if (keys(%currhash) == 0) {
18513: if (!$i) {
18514: $check = ' checked="checked"';
18515: }
18516: } elsif (exists($currhash{$domcoord[$i]})) {
18517: $check = ' checked="checked"';
18518: }
18519: } else {
18520: if (exists($currhash{$domcoord[$i]})) {
18521: $check = ' checked="checked"';
1.125 raeburn 18522: }
18523: }
1.160.6.16 raeburn 18524: if ($i == @domcoord - 1) {
1.125 raeburn 18525: my $colsleft = $numinrow - $rem;
18526: if ($colsleft > 1) {
1.160.6.16 raeburn 18527: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18528: } else {
1.160.6.16 raeburn 18529: $table .= '<td class="LC_left_item">';
1.125 raeburn 18530: }
18531: } else {
1.160.6.16 raeburn 18532: $table .= '<td class="LC_left_item">';
18533: }
18534: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18535: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18536: $table .= '<span class="LC_nobreak"><label>'.
18537: '<input type="'.$inputtype.'" name="'.$name.'"'.
18538: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
18539: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 18540: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 18541: }
1.160.6.33 raeburn 18542: $table .= '</label></span></td>';
1.125 raeburn 18543: }
1.160.6.16 raeburn 18544: $table .= '</tr></table>';
18545: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 18546: my ($dcname,$dcdom) = split(':',$domcoord[0]);
18547: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 18548: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 18549: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 18550: if ($user ne $dcname.':'.$dcdom) {
18551: $table .= ' ('.$dcname.':'.$dcdom.')';
18552: }
1.160.6.16 raeburn 18553: } else {
18554: my $check;
18555: if (exists($currhash{$domcoord[0]})) {
18556: $check = ' checked="checked"';
18557: }
1.160.6.50 raeburn 18558: $table = '<span class="LC_nobreak"><label>'.
18559: '<input type="checkbox" name="'.$name.'" '.
18560: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 18561: if ($user ne $dcname.':'.$dcdom) {
18562: $table .= ' ('.$dcname.':'.$dcdom.')';
18563: }
18564: $table .= '</label></span>';
1.160.6.16 raeburn 18565: $rows ++;
18566: }
1.125 raeburn 18567: }
1.160.6.16 raeburn 18568: return ($numdcs,$table,$rows);
1.125 raeburn 18569: }
18570:
1.137 raeburn 18571: sub usersession_titles {
18572: return &Apache::lonlocal::texthash(
18573: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
18574: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 18575: spares => 'Servers offloaded to, when busy',
1.137 raeburn 18576: version => 'LON-CAPA version requirement',
1.138 raeburn 18577: excludedomain => 'Allow all, but exclude specific domains',
18578: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 18579: primary => 'Primary (checked first)',
1.154 raeburn 18580: default => 'Default',
1.137 raeburn 18581: );
18582: }
18583:
1.152 raeburn 18584: sub id_for_thisdom {
18585: my (%servers) = @_;
18586: my %altids;
18587: foreach my $server (keys(%servers)) {
18588: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18589: if ($serverhome ne $server) {
18590: $altids{$serverhome} = $server;
18591: }
18592: }
18593: return %altids;
18594: }
18595:
1.150 raeburn 18596: sub count_servers {
18597: my ($currbalancer,%servers) = @_;
18598: my (@spares,$numspares);
18599: foreach my $lonhost (sort(keys(%servers))) {
18600: next if ($currbalancer eq $lonhost);
18601: push(@spares,$lonhost);
18602: }
18603: if ($currbalancer) {
18604: $numspares = scalar(@spares);
18605: } else {
18606: $numspares = scalar(@spares) - 1;
18607: }
18608: return ($numspares,@spares);
18609: }
18610:
18611: sub lonbalance_targets_js {
1.160.6.7 raeburn 18612: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 18613: my $select = &mt('Select');
18614: my ($alltargets,$allishome,$allinsttypes,@alltypes);
18615: if (ref($servers) eq 'HASH') {
18616: $alltargets = join("','",sort(keys(%{$servers})));
18617: my @homedoms;
18618: foreach my $server (sort(keys(%{$servers}))) {
18619: if (&Apache::lonnet::host_domain($server) eq $dom) {
18620: push(@homedoms,'1');
18621: } else {
18622: push(@homedoms,'0');
18623: }
18624: }
18625: $allishome = join("','",@homedoms);
18626: }
18627: if (ref($types) eq 'ARRAY') {
18628: if (@{$types} > 0) {
18629: @alltypes = @{$types};
18630: }
18631: }
18632: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
18633: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 18634: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18635: if (ref($settings) eq 'HASH') {
18636: %existing = %{$settings};
18637: }
18638: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18639: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18640: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 18641: return <<"END";
18642:
18643: <script type="text/javascript">
18644: // <![CDATA[
18645:
1.160.6.7 raeburn 18646: currBalancers = new Array('$balancers');
18647:
18648: function toggleTargets(balnum) {
18649: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18650: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
18651: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
18652: var prevbalancer = prevhostitem.value;
18653: var baltotal = document.getElementById('loadbalancing_total').value;
18654: prevhostitem.value = balancer;
18655: if (prevbalancer != '') {
18656: var prevIdx = currBalancers.indexOf(prevbalancer);
18657: if (prevIdx != -1) {
18658: currBalancers.splice(prevIdx,1);
18659: }
18660: }
1.150 raeburn 18661: if (balancer == '') {
1.160.6.7 raeburn 18662: hideSpares(balnum);
1.150 raeburn 18663: } else {
1.160.6.7 raeburn 18664: var currIdx = currBalancers.indexOf(balancer);
18665: if (currIdx == -1) {
18666: currBalancers.push(balancer);
18667: }
1.150 raeburn 18668: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 18669: var ishomedom = homedoms[lonhostitem.selectedIndex];
18670: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 18671: }
1.160.6.7 raeburn 18672: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 18673: return;
18674: }
18675:
1.160.6.7 raeburn 18676: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 18677: var alltargets = new Array('$alltargets');
18678: var insttypes = new Array('$allinsttypes');
1.151 raeburn 18679: var offloadtypes = new Array('primary','default');
18680:
1.160.6.7 raeburn 18681: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
18682: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 18683:
1.151 raeburn 18684: for (var i=0; i<offloadtypes.length; i++) {
18685: var count = 0;
18686: for (var j=0; j<alltargets.length; j++) {
18687: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 18688: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
18689: item.value = alltargets[j];
18690: item.style.textAlign='left';
18691: item.style.textFace='normal';
18692: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
18693: if (currBalancers.indexOf(alltargets[j]) == -1) {
18694: item.disabled = '';
18695: } else {
18696: item.disabled = 'disabled';
18697: item.checked = false;
18698: }
1.151 raeburn 18699: count ++;
18700: }
1.150 raeburn 18701: }
18702: }
1.151 raeburn 18703: for (var k=0; k<insttypes.length; k++) {
18704: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 18705: if (ishomedom == 1) {
1.160.6.7 raeburn 18706: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18707: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18708: } else {
1.160.6.7 raeburn 18709: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18710: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 18711: }
18712: } else {
1.160.6.7 raeburn 18713: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18714: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18715: }
1.151 raeburn 18716: if ((insttypes[k] != '_LC_external') &&
18717: ((insttypes[k] != '_LC_internetdom') ||
18718: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 18719: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
18720: item.options.length = 0;
18721: item.options[0] = new Option("","",true,true);
18722: var idx = 0;
1.151 raeburn 18723: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 18724: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
18725: idx ++;
18726: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 18727: }
18728: }
18729: }
18730: }
18731: return;
18732: }
18733:
1.160.6.7 raeburn 18734: function hideSpares(balnum) {
1.150 raeburn 18735: var alltargets = new Array('$alltargets');
18736: var insttypes = new Array('$allinsttypes');
18737: var offloadtypes = new Array('primary','default');
18738:
1.160.6.7 raeburn 18739: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
18740: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 18741:
18742: var total = alltargets.length - 1;
18743: for (var i=0; i<offloadtypes; i++) {
18744: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 18745: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
18746: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
18747: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 18748: }
1.150 raeburn 18749: }
18750: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 18751: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18752: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 18753: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 18754: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
18755: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 18756: }
18757: }
18758: return;
18759: }
18760:
1.160.6.7 raeburn 18761: function checkOffloads(item,balnum,type) {
1.150 raeburn 18762: var alltargets = new Array('$alltargets');
18763: var offloadtypes = new Array('primary','default');
18764: if (item.checked) {
18765: var total = alltargets.length - 1;
18766: var other;
18767: if (type == offloadtypes[0]) {
1.151 raeburn 18768: other = offloadtypes[1];
1.150 raeburn 18769: } else {
1.151 raeburn 18770: other = offloadtypes[0];
1.150 raeburn 18771: }
18772: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 18773: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 18774: if (server == item.value) {
1.160.6.7 raeburn 18775: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
18776: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 18777: }
18778: }
18779: }
18780: }
18781: return;
18782: }
18783:
1.160.6.7 raeburn 18784: function singleServerToggle(balnum,type) {
18785: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 18786: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 18787: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
18788: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18789:
18790: } else {
1.160.6.7 raeburn 18791: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
18792: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 18793: }
18794: return;
18795: }
18796:
1.160.6.7 raeburn 18797: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 18798: if (type == '_LC_external') {
1.160.6.26 raeburn 18799: return;
1.150 raeburn 18800: }
1.160.6.7 raeburn 18801: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 18802: for (var i=0; i<typesRules.length; i++) {
18803: if (formname.elements[typesRules[i]].checked) {
18804: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 18805: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
18806: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18807: } else {
1.160.6.7 raeburn 18808: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
18809: }
18810: }
18811: }
18812: return;
18813: }
18814:
18815: function balancerDeleteChange(balnum) {
18816: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18817: var baltotal = document.getElementById('loadbalancing_total').value;
18818: var addtarget;
18819: var removetarget;
18820: var action = 'delete';
18821: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18822: var lonhost = hostitem.value;
18823: var currIdx = currBalancers.indexOf(lonhost);
18824: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18825: if (currIdx != -1) {
18826: currBalancers.splice(currIdx,1);
18827: }
18828: addtarget = lonhost;
18829: } else {
18830: if (currIdx == -1) {
18831: currBalancers.push(lonhost);
18832: }
18833: removetarget = lonhost;
18834: action = 'undelete';
18835: }
18836: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18837: }
18838: return;
18839: }
18840:
18841: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18842: if (baltotal > 1) {
18843: var offloadtypes = new Array('primary','default');
18844: var alltargets = new Array('$alltargets');
18845: var insttypes = new Array('$allinsttypes');
18846: for (var i=0; i<baltotal; i++) {
18847: if (i != balnum) {
18848: for (var j=0; j<offloadtypes.length; j++) {
18849: var total = alltargets.length - 1;
18850: for (var k=0; k<total; k++) {
18851: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18852: var server = serveritem.value;
18853: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18854: if (server == addtarget) {
18855: serveritem.disabled = '';
18856: }
18857: }
18858: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18859: if (server == removetarget) {
18860: serveritem.disabled = 'disabled';
18861: serveritem.checked = false;
18862: }
18863: }
18864: }
18865: }
18866: for (var j=0; j<insttypes.length; j++) {
18867: if (insttypes[j] != '_LC_external') {
18868: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18869: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18870: var currSel = singleserver.selectedIndex;
18871: var currVal = singleserver.options[currSel].value;
18872: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18873: var numoptions = singleserver.options.length;
18874: var needsnew = 1;
18875: for (var k=0; k<numoptions; k++) {
18876: if (singleserver.options[k] == addtarget) {
18877: needsnew = 0;
18878: break;
18879: }
18880: }
18881: if (needsnew == 1) {
18882: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18883: }
18884: }
18885: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18886: singleserver.options.length = 0;
18887: if ((currVal) && (currVal != removetarget)) {
18888: singleserver.options[0] = new Option("","",false,false);
18889: } else {
18890: singleserver.options[0] = new Option("","",true,true);
18891: }
18892: var idx = 0;
18893: for (var m=0; m<alltargets.length; m++) {
18894: if (currBalancers.indexOf(alltargets[m]) == -1) {
18895: idx ++;
18896: if (currVal == alltargets[m]) {
18897: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18898: } else {
18899: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18900: }
18901: }
18902: }
18903: }
18904: }
18905: }
18906: }
1.150 raeburn 18907: }
18908: }
18909: }
18910: return;
18911: }
18912:
1.152 raeburn 18913: // ]]>
18914: </script>
18915:
18916: END
18917: }
18918:
18919: sub new_spares_js {
18920: my @sparestypes = ('primary','default');
18921: my $types = join("','",@sparestypes);
18922: my $select = &mt('Select');
18923: return <<"END";
18924:
18925: <script type="text/javascript">
18926: // <![CDATA[
18927:
18928: function updateNewSpares(formname,lonhost) {
18929: var types = new Array('$types');
18930: var include = new Array();
18931: var exclude = new Array();
18932: for (var i=0; i<types.length; i++) {
18933: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18934: for (var j=0; j<spareboxes.length; j++) {
18935: if (formname.elements[spareboxes[j]].checked) {
18936: exclude.push(formname.elements[spareboxes[j]].value);
18937: } else {
18938: include.push(formname.elements[spareboxes[j]].value);
18939: }
18940: }
18941: }
18942: for (var i=0; i<types.length; i++) {
18943: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18944: var selIdx = newSpare.selectedIndex;
18945: var currnew = newSpare.options[selIdx].value;
18946: var okSpares = new Array();
18947: for (var j=0; j<newSpare.options.length; j++) {
18948: var possible = newSpare.options[j].value;
18949: if (possible != '') {
18950: if (exclude.indexOf(possible) == -1) {
18951: okSpares.push(possible);
18952: } else {
18953: if (currnew == possible) {
18954: selIdx = 0;
18955: }
18956: }
18957: }
18958: }
18959: for (var k=0; k<include.length; k++) {
18960: if (okSpares.indexOf(include[k]) == -1) {
18961: okSpares.push(include[k]);
18962: }
18963: }
18964: okSpares.sort();
18965: newSpare.options.length = 0;
18966: if (selIdx == 0) {
18967: newSpare.options[0] = new Option("$select","",true,true);
18968: } else {
18969: newSpare.options[0] = new Option("$select","",false,false);
18970: }
18971: for (var m=0; m<okSpares.length; m++) {
18972: var idx = m+1;
18973: var selThis = 0;
18974: if (selIdx != 0) {
18975: if (okSpares[m] == currnew) {
18976: selThis = 1;
18977: }
18978: }
18979: if (selThis == 1) {
18980: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18981: } else {
18982: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18983: }
18984: }
18985: }
18986: return;
18987: }
18988:
18989: function checkNewSpares(lonhost,type) {
18990: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18991: var chosen = newSpare.options[newSpare.selectedIndex].value;
18992: if (chosen != '') {
18993: var othertype;
18994: var othernewSpare;
18995: if (type == 'primary') {
18996: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18997: }
18998: if (type == 'default') {
18999: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19000: }
19001: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19002: othernewSpare.selectedIndex = 0;
19003: }
19004: }
19005: return;
19006: }
19007:
19008: // ]]>
19009: </script>
19010:
19011: END
19012:
19013: }
19014:
19015: sub common_domprefs_js {
19016: return <<"END";
19017:
19018: <script type="text/javascript">
19019: // <![CDATA[
19020:
1.150 raeburn 19021: function getIndicesByName(formname,item) {
1.152 raeburn 19022: var group = new Array();
1.150 raeburn 19023: for (var i=0;i<formname.elements.length;i++) {
19024: if (formname.elements[i].name == item) {
1.152 raeburn 19025: group.push(formname.elements[i].id);
1.150 raeburn 19026: }
19027: }
1.152 raeburn 19028: return group;
1.150 raeburn 19029: }
19030:
19031: // ]]>
19032: </script>
19033:
19034: END
1.152 raeburn 19035:
1.150 raeburn 19036: }
19037:
1.160.6.5 raeburn 19038: sub recaptcha_js {
19039: my %lt = &captcha_phrases();
19040: return <<"END";
19041:
19042: <script type="text/javascript">
19043: // <![CDATA[
19044:
19045: function updateCaptcha(caller,context) {
19046: var privitem;
19047: var pubitem;
19048: var privtext;
19049: var pubtext;
1.160.6.69 raeburn 19050: var versionitem;
19051: var versiontext;
1.160.6.5 raeburn 19052: if (document.getElementById(context+'_recaptchapub')) {
19053: pubitem = document.getElementById(context+'_recaptchapub');
19054: } else {
19055: return;
19056: }
19057: if (document.getElementById(context+'_recaptchapriv')) {
19058: privitem = document.getElementById(context+'_recaptchapriv');
19059: } else {
19060: return;
19061: }
19062: if (document.getElementById(context+'_recaptchapubtxt')) {
19063: pubtext = document.getElementById(context+'_recaptchapubtxt');
19064: } else {
19065: return;
19066: }
19067: if (document.getElementById(context+'_recaptchaprivtxt')) {
19068: privtext = document.getElementById(context+'_recaptchaprivtxt');
19069: } else {
19070: return;
19071: }
1.160.6.69 raeburn 19072: if (document.getElementById(context+'_recaptchaversion')) {
19073: versionitem = document.getElementById(context+'_recaptchaversion');
19074: } else {
19075: return;
19076: }
19077: if (document.getElementById(context+'_recaptchavertxt')) {
19078: versiontext = document.getElementById(context+'_recaptchavertxt');
19079: } else {
19080: return;
19081: }
1.160.6.5 raeburn 19082: if (caller.checked) {
19083: if (caller.value == 'recaptcha') {
19084: pubitem.type = 'text';
19085: privitem.type = 'text';
19086: pubitem.size = '40';
19087: privitem.size = '40';
19088: pubtext.innerHTML = "$lt{'pub'}";
19089: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 19090: versionitem.type = 'text';
19091: versionitem.size = '3';
19092: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 19093: } else {
19094: pubitem.type = 'hidden';
19095: privitem.type = 'hidden';
1.160.6.69 raeburn 19096: versionitem.type = 'hidden';
1.160.6.5 raeburn 19097: pubtext.innerHTML = '';
19098: privtext.innerHTML = '';
1.160.6.69 raeburn 19099: versiontext.innerHTML = '';
1.160.6.5 raeburn 19100: }
19101: }
19102: return;
19103: }
19104:
19105: // ]]>
19106: </script>
19107:
19108: END
19109:
19110: }
19111:
1.160.6.40 raeburn 19112: sub toggle_display_js {
1.160.6.16 raeburn 19113: return <<"END";
19114:
19115: <script type="text/javascript">
19116: // <![CDATA[
19117:
1.160.6.40 raeburn 19118: function toggleDisplay(domForm,caller) {
19119: if (document.getElementById(caller)) {
19120: var divitem = document.getElementById(caller);
19121: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 19122: var checkval = 1;
19123: var dispval = 'block';
1.160.6.93 raeburn 19124: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 19125: if (caller == 'emailoptions') {
19126: optionsElement = domForm.cancreate_email;
19127: }
1.160.6.57 raeburn 19128: if (caller == 'studentsubmission') {
19129: optionsElement = domForm.postsubmit;
19130: }
1.160.6.64 raeburn 19131: if (caller == 'cloneinstcode') {
19132: optionsElement = domForm.canclone;
19133: checkval = 'instcode';
19134: }
1.160.6.93 raeburn 19135: if (selfcreateRegExp.test(caller)) {
19136: optionsElement = domForm.elements[caller];
19137: checkval = 'other';
19138: dispval = 'inline'
19139: }
1.160.6.40 raeburn 19140: if (optionsElement.length) {
1.160.6.16 raeburn 19141: var currval;
1.160.6.40 raeburn 19142: for (var i=0; i<optionsElement.length; i++) {
19143: if (optionsElement[i].checked) {
19144: currval = optionsElement[i].value;
1.160.6.16 raeburn 19145: }
19146: }
1.160.6.64 raeburn 19147: if (currval == checkval) {
19148: divitem.style.display = dispval;
1.160.6.16 raeburn 19149: } else {
1.160.6.40 raeburn 19150: divitem.style.display = 'none';
1.160.6.16 raeburn 19151: }
19152: }
19153: }
19154: return;
19155: }
19156:
19157: // ]]>
19158: </script>
19159:
19160: END
19161:
19162: }
19163:
1.160.6.5 raeburn 19164: sub captcha_phrases {
19165: return &Apache::lonlocal::texthash (
19166: priv => 'Private key',
19167: pub => 'Public key',
19168: original => 'original (CAPTCHA)',
19169: recaptcha => 'successor (ReCAPTCHA)',
19170: notused => 'unused',
1.160.6.69 raeburn 19171: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 19172: );
19173: }
19174:
1.160.6.24 raeburn 19175: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 19176: my ($dom,$cachekeys) = @_;
19177: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 19178: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19179: my %thismachine;
19180: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 19181:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 19182: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19183: 'ipaccess');
19184: my %cache_by_lonhost;
19185: if (exists($cachekeys->{'samllanding'})) {
19186: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19187: my %landing = %{$cachekeys->{'samllanding'}};
19188: my %domservers = &Apache::lonnet::get_servers($dom);
19189: if (keys(%domservers)) {
19190: foreach my $server (keys(%domservers)) {
19191: my @cached;
19192: next if ($thismachine{$server});
19193: if ($landing{$server}) {
19194: push(@cached,&escape('samllanding').':'.&escape($server));
19195: }
19196: if (@cached) {
19197: $cache_by_lonhost{$server} = \@cached;
19198: }
19199: }
19200: }
19201: }
19202: }
1.160.6.61 raeburn 19203: if (keys(%servers)) {
1.160.6.24 raeburn 19204: foreach my $server (keys(%servers)) {
19205: next if ($thismachine{$server});
1.160.6.27 raeburn 19206: my @cached;
19207: foreach my $name (@posscached) {
19208: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 19209: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
19210: if (ref($cachekeys->{$name}) eq 'HASH') {
19211: foreach my $key (keys(%{$cachekeys->{$name}})) {
19212: push(@cached,&escape($name).':'.&escape($key));
19213: }
19214: }
19215: } else {
19216: push(@cached,&escape($name).':'.&escape($dom));
19217: }
1.160.6.27 raeburn 19218: }
19219: }
1.160.6.113 raeburn 19220: if ((exists($cache_by_lonhost{$server})) &&
19221: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
19222: push(@cached,@{$cache_by_lonhost{$server}});
19223: }
1.160.6.27 raeburn 19224: if (@cached) {
19225: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19226: }
1.160.6.24 raeburn 19227: }
19228: }
19229: return;
19230: }
19231:
1.3 raeburn 19232: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>