Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.3
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 3(raebur 4:2): # $Id: domainprefs.pm,v 1.160.6.118.2.2 2022/01/16 23:23:40 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.16 raeburn 5066: );
1.160.6.21 raeburn 5067: my %staticdefaults = (
5068: anonsurvey_threshold => 10,
5069: uploadquota => 500,
1.160.6.57 raeburn 5070: postsubmit => 60,
1.160.6.70 raeburn 5071: mysqltables => 172800,
1.160.6.21 raeburn 5072: );
1.139 raeburn 5073: if ($position eq 'top') {
1.160.6.57 raeburn 5074: %defaultchecked = (
5075: 'uselcmath' => 'on',
5076: 'usejsme' => 'on',
1.160.6.115 raeburn 5077: 'inline_chem' => 'on',
1.160.6.64 raeburn 5078: 'canclone' => 'none',
1.160.6.57 raeburn 5079: );
1.160.6.115 raeburn 5080: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5081: my $deftex = $Apache::lonnet::deftex;
5082: if (ref($settings) eq 'HASH') {
5083: if ($settings->{'texengine'}) {
5084: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5085: $deftex = $settings->{'texengine'};
5086: }
5087: }
5088: }
5089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5090: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5091: '<span class="LC_nobreak">'.$choices{'texengine'}.
5092: '</span></td><td class="LC_right_item">'.
5093: '<select name="texengine">'."\n";
5094: my %texoptions = (
5095: MathJax => 'MathJax',
5096: mimetex => &mt('Convert to Images'),
5097: tth => &mt('TeX to HTML'),
5098: );
5099: foreach my $renderer ('MathJax','mimetex','tth') {
5100: my $selected = '';
5101: if ($renderer eq $deftex) {
5102: $selected = ' selected="selected"';
5103: }
5104: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5105: }
5106: $mathdisp .= '</select></td></tr>'."\n";
5107: $itemcount ++;
1.139 raeburn 5108: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5109: \%choices,$itemcount);
1.160.6.90 raeburn 5110: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5111: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5112: $datatable .=
5113: '<tr'.$css_class.'><td valign="top">'.
5114: '<span class="LC_nobreak">'.$choices{'canclone'}.
5115: '</span></td><td class="LC_left_item">';
5116: my $currcanclone = 'none';
5117: my $onclick;
5118: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5119: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5120: none => 'No additional course requesters',
5121: domain => "Any course requester in course's domain",
5122: instcode => 'Course requests for official courses ...',
5123: );
5124: my (%codedefaults,@code_order,@posscodes);
5125: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5126: \@code_order) eq 'ok') {
5127: if (@code_order > 0) {
5128: push(@cloneoptions,'instcode');
5129: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5130: }
5131: }
5132: if (ref($settings) eq 'HASH') {
5133: if ($settings->{'canclone'}) {
5134: if (ref($settings->{'canclone'}) eq 'HASH') {
5135: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5136: if (@code_order > 0) {
5137: $currcanclone = 'instcode';
5138: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5139: }
5140: }
5141: } elsif ($settings->{'canclone'} eq 'domain') {
5142: $currcanclone = $settings->{'canclone'};
5143: }
5144: }
5145: }
5146: foreach my $option (@cloneoptions) {
5147: my ($checked,$additional);
5148: if ($currcanclone eq $option) {
5149: $checked = ' checked="checked"';
5150: }
5151: if ($option eq 'instcode') {
5152: if (@code_order) {
5153: my $show = 'none';
5154: if ($checked) {
5155: $show = 'block';
5156: }
5157: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5158: &mt('Institutional codes for new and cloned course have identical:').
5159: '<br />';
5160: foreach my $item (@code_order) {
5161: my $codechk;
5162: if ($checked) {
5163: if (grep(/^\Q$item\E$/,@posscodes)) {
5164: $codechk = ' checked="checked"';
5165: }
5166: }
5167: $additional .= '<label>'.
5168: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5169: $item.'</label>';
5170: }
5171: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5172: }
5173: }
5174: $datatable .=
5175: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5176: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5177: '</label> '.$additional.'</span><br />';
5178: }
5179: $datatable .= '</td>'.
5180: '</tr>';
5181: $itemcount ++;
1.139 raeburn 5182: } else {
5183: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 5184: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 5185: my $currusecredits = 0;
1.160.6.57 raeburn 5186: my $postsubmitclient = 1;
1.160.6.30 raeburn 5187: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 5188: if (ref($settings) eq 'HASH') {
5189: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 5190: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5191: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5192: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5193: }
5194: }
1.160.6.16 raeburn 5195: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 5196: foreach my $type (@types) {
5197: next if ($type eq 'community');
5198: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5199: if ($defcredits{$type} ne '') {
5200: $currusecredits = 1;
5201: }
5202: }
5203: }
5204: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5205: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5206: $postsubmitclient = 0;
5207: foreach my $type (@types) {
5208: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5209: }
5210: } else {
5211: foreach my $type (@types) {
5212: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5213: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5214: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5215: } else {
5216: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5217: }
5218: } else {
5219: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5220: }
5221: }
5222: }
5223: } else {
5224: foreach my $type (@types) {
5225: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 5226: }
5227: }
1.160.6.70 raeburn 5228: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5229: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5230: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5231: }
5232: } else {
5233: foreach my $type (@types) {
5234: $currmysql{$type} = $staticdefaults{'mysqltables'};
5235: }
5236: }
1.160.6.58 raeburn 5237: } else {
5238: foreach my $type (@types) {
5239: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5240: }
1.139 raeburn 5241: }
5242: if (!$currdefresponder) {
1.160.6.21 raeburn 5243: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5244: } elsif ($currdefresponder < 1) {
5245: $currdefresponder = 1;
5246: }
1.160.6.21 raeburn 5247: foreach my $type (@types) {
5248: if ($curruploadquota{$type} eq '') {
5249: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5250: }
5251: }
1.139 raeburn 5252: $datatable .=
1.160.6.16 raeburn 5253: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5254: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5255: '</span></td>'.
5256: '<td class="LC_right_item"><span class="LC_nobreak">'.
5257: '<input type="text" name="anonsurvey_threshold"'.
5258: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 5259: '</td></tr>'."\n";
5260: $itemcount ++;
5261: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5262: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5263: $choices{'uploadquota'}.
5264: '</span></td>'.
5265: '<td align="right" class="LC_right_item">'.
5266: '<table><tr>';
1.160.6.21 raeburn 5267: foreach my $type (@types) {
5268: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5269: '<input type="text" name="uploadquota_'.$type.'"'.
5270: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5271: }
5272: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 5273: $itemcount ++;
1.160.6.40 raeburn 5274: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 5275: my $display = 'none';
5276: if ($currusecredits) {
5277: $display = 'block';
5278: }
5279: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 5280: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5281: foreach my $type (@types) {
5282: next if ($type eq 'community');
5283: $additional .= '<td align="center">'.&mt($type).'<br />'.
5284: '<input type="text" name="'.$type.'_credits"'.
5285: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5286: }
5287: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 5288: %defaultchecked = ('coursecredits' => 'off');
5289: @toggles = ('coursecredits');
5290: my $current = {
5291: 'coursecredits' => $currusecredits,
5292: };
5293: (my $table,$itemcount) =
5294: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5295: \%choices,$itemcount,$onclick,$additional,'left');
5296: $datatable .= $table;
5297: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5298: my $display = 'none';
5299: if ($postsubmitclient) {
5300: $display = 'block';
5301: }
5302: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 5303: &mt('Number of seconds submit is disabled').'<br />'.
5304: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5305: '<table><tr>';
1.160.6.57 raeburn 5306: foreach my $type (@types) {
5307: $additional .= '<td align="center">'.&mt($type).'<br />'.
5308: '<input type="text" name="'.$type.'_timeout" value="'.
5309: $deftimeout{$type}.'" size="5" /></td>';
5310: }
5311: $additional .= '</tr></table></div>'."\n";
5312: %defaultchecked = ('postsubmit' => 'on');
5313: @toggles = ('postsubmit');
1.160.6.70 raeburn 5314: $current = {
5315: 'postsubmit' => $postsubmitclient,
5316: };
1.160.6.57 raeburn 5317: ($table,$itemcount) =
5318: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5319: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 5320: $datatable .= $table;
1.160.6.70 raeburn 5321: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5322: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5323: $choices{'mysqltables'}.
5324: '</span></td>'.
5325: '<td align="right" class="LC_right_item">'.
5326: '<table><tr>';
5327: foreach my $type (@types) {
5328: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5329: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 5330: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 5331: }
5332: $datatable .= '</tr></table></td></tr>'."\n";
5333: $itemcount ++;
5334:
1.160.6.37 raeburn 5335: }
5336: $$rowtotal += $itemcount;
5337: return $datatable;
5338: }
5339:
5340: sub print_selfenrollment {
5341: my ($position,$dom,$settings,$rowtotal) = @_;
5342: my ($css_class,$datatable);
5343: my $itemcount = 1;
5344: my @types = ('official','unofficial','community','textbook');
5345: if (($position eq 'top') || ($position eq 'middle')) {
5346: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5347: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5348: my @rows;
5349: my $key;
5350: if ($position eq 'top') {
5351: $key = 'admin';
5352: if (ref($rowsref) eq 'ARRAY') {
5353: @rows = @{$rowsref};
5354: }
5355: } elsif ($position eq 'middle') {
5356: $key = 'default';
5357: @rows = ('types','registered','approval','limit');
5358: }
5359: foreach my $row (@rows) {
5360: if (defined($titlesref->{$row})) {
5361: $itemcount ++;
5362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5363: $datatable .= '<tr'.$css_class.'>'.
5364: '<td>'.$titlesref->{$row}.'</td>'.
5365: '<td class="LC_left_item">'.
5366: '<table><tr>';
5367: my (%current,%currentcap);
5368: if (ref($settings) eq 'HASH') {
5369: if (ref($settings->{$key}) eq 'HASH') {
5370: foreach my $type (@types) {
5371: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5372: $current{$type} = $settings->{$key}->{$type}->{$row};
5373: }
5374: if (($row eq 'limit') && ($key eq 'default')) {
5375: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5376: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5377: }
5378: }
5379: }
5380: }
5381: }
5382: my %roles = (
5383: '0' => &Apache::lonnet::plaintext('dc'),
5384: );
5385:
5386: foreach my $type (@types) {
5387: unless (($row eq 'registered') && ($key eq 'default')) {
5388: $datatable .= '<th>'.&mt($type).'</th>';
5389: }
5390: }
5391: unless (($row eq 'registered') && ($key eq 'default')) {
5392: $datatable .= '</tr><tr>';
5393: }
5394: foreach my $type (@types) {
5395: if ($type eq 'community') {
5396: $roles{'1'} = &mt('Community personnel');
5397: } else {
5398: $roles{'1'} = &mt('Course personnel');
5399: }
5400: $datatable .= '<td style="vertical-align: top">';
5401: if ($position eq 'top') {
5402: my %checked;
5403: if ($current{$type} eq '0') {
5404: $checked{'0'} = ' checked="checked"';
5405: } else {
5406: $checked{'1'} = ' checked="checked"';
5407: }
5408: foreach my $role ('1','0') {
5409: $datatable .= '<span class="LC_nobreak"><label>'.
5410: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5411: 'value="'.$role.'"'.$checked{$role}.' />'.
5412: $roles{$role}.'</label></span> ';
5413: }
5414: } else {
5415: if ($row eq 'types') {
5416: my %checked;
5417: if ($current{$type} =~ /^(all|dom)$/) {
5418: $checked{$1} = ' checked="checked"';
5419: } else {
5420: $checked{''} = ' checked="checked"';
5421: }
5422: foreach my $val ('','dom','all') {
5423: $datatable .= '<span class="LC_nobreak"><label>'.
5424: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5425: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5426: }
5427: } elsif ($row eq 'registered') {
5428: my %checked;
5429: if ($current{$type} eq '1') {
5430: $checked{'1'} = ' checked="checked"';
5431: } else {
5432: $checked{'0'} = ' checked="checked"';
5433: }
5434: foreach my $val ('0','1') {
5435: $datatable .= '<span class="LC_nobreak"><label>'.
5436: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5437: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5438: }
5439: } elsif ($row eq 'approval') {
5440: my %checked;
5441: if ($current{$type} =~ /^([12])$/) {
5442: $checked{$1} = ' checked="checked"';
5443: } else {
5444: $checked{'0'} = ' checked="checked"';
5445: }
5446: for my $val (0..2) {
5447: $datatable .= '<span class="LC_nobreak"><label>'.
5448: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5449: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5450: }
5451: } elsif ($row eq 'limit') {
5452: my %checked;
5453: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5454: $checked{$1} = ' checked="checked"';
5455: } else {
5456: $checked{'none'} = ' checked="checked"';
5457: }
5458: my $cap;
5459: if ($currentcap{$type} =~ /^\d+$/) {
5460: $cap = $currentcap{$type};
5461: }
5462: foreach my $val ('none','allstudents','selfenrolled') {
5463: $datatable .= '<span class="LC_nobreak"><label>'.
5464: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5465: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5466: }
5467: $datatable .= '<br />'.
5468: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5469: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5470: '</span>';
5471: }
5472: }
5473: $datatable .= '</td>';
5474: }
5475: $datatable .= '</tr>';
5476: }
5477: $datatable .= '</table></td></tr>';
5478: }
5479: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 5480: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5481: }
5482: $$rowtotal += $itemcount;
5483: return $datatable;
5484: }
5485:
5486: sub print_validation_rows {
5487: my ($caller,$dom,$settings,$rowtotal) = @_;
5488: my ($itemsref,$namesref,$fieldsref);
5489: if ($caller eq 'selfenroll') {
5490: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5491: } elsif ($caller eq 'requestcourses') {
5492: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5493: }
5494: my %currvalidation;
5495: if (ref($settings) eq 'HASH') {
5496: if (ref($settings->{'validation'}) eq 'HASH') {
5497: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 5498: }
1.160.6.39 raeburn 5499: }
5500: my $datatable;
5501: my $itemcount = 0;
5502: foreach my $item (@{$itemsref}) {
5503: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5504: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5505: $namesref->{$item}.
5506: '</span></td>'.
5507: '<td class="LC_left_item">';
5508: if (($item eq 'url') || ($item eq 'button')) {
5509: $datatable .= '<span class="LC_nobreak">'.
5510: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5511: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5512: } elsif ($item eq 'fields') {
5513: my @currfields;
5514: if (ref($currvalidation{$item}) eq 'ARRAY') {
5515: @currfields = @{$currvalidation{$item}};
5516: }
5517: foreach my $field (@{$fieldsref}) {
5518: my $check = '';
5519: if (grep(/^\Q$field\E$/,@currfields)) {
5520: $check = ' checked="checked"';
5521: }
5522: $datatable .= '<span class="LC_nobreak"><label>'.
5523: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5524: ' value="'.$field.'"'.$check.' />'.$field.
5525: '</label></span> ';
5526: }
5527: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 5528: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 5529: $currvalidation{$item}.
1.160.6.37 raeburn 5530: '</textarea>';
1.160.6.39 raeburn 5531: }
5532: $datatable .= '</td></tr>'."\n";
5533: if (ref($rowtotal)) {
1.160.6.37 raeburn 5534: $itemcount ++;
5535: }
1.139 raeburn 5536: }
1.160.6.39 raeburn 5537: if ($caller eq 'requestcourses') {
5538: my %currhash;
1.160.6.51 raeburn 5539: if (ref($settings) eq 'HASH') {
5540: if (ref($settings->{'validation'}) eq 'HASH') {
5541: if ($settings->{'validation'}{'dc'} ne '') {
5542: $currhash{$settings->{'validation'}{'dc'}} = 1;
5543: }
1.160.6.39 raeburn 5544: }
5545: }
5546: my $numinrow = 2;
5547: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5548: 'validationdc',%currhash);
1.160.6.50 raeburn 5549: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5550: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5551: if ($numdc > 1) {
1.160.6.50 raeburn 5552: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5553: } else {
1.160.6.50 raeburn 5554: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5555: }
1.160.6.50 raeburn 5556: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5557: $itemcount ++;
5558: }
5559: if (ref($rowtotal)) {
5560: $$rowtotal += $itemcount;
5561: }
1.121 raeburn 5562: return $datatable;
1.118 jms 5563: }
5564:
1.160.6.98 raeburn 5565: sub print_passwords {
5566: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5567: my ($datatable,$css_class);
5568: my $itemcount = 0;
5569: my %titles = &Apache::lonlocal::texthash (
5570: captcha => '"Forgot Password" CAPTCHA validation',
5571: link => 'Reset link expiration (hours)',
5572: case => 'Case-sensitive usernames/e-mail',
5573: prelink => 'Information required (form 1)',
5574: postlink => 'Information required (form 2)',
5575: emailsrc => 'LON-CAPA e-mail address type(s)',
5576: customtext => 'Domain specific text (HTML)',
5577: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5578: intauth_check => 'Check bcrypt cost if authenticated',
5579: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5580: permanent => 'Permanent e-mail address',
5581: critical => 'Critical notification address',
5582: notify => 'Notification address',
5583: min => 'Minimum password length',
5584: max => 'Maximum password length',
5585: chars => 'Required characters',
5586: numsaved => 'Number of previous passwords to save and disallow reuse',
5587: );
5588: if ($position eq 'top') {
5589: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5590: my $shownlinklife = 2;
5591: my $prelink = 'both';
5592: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5593: if (ref($settings) eq 'HASH') {
5594: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5595: $shownlinklife = $settings->{resetlink};
5596: }
5597: if (ref($settings->{resetcase}) eq 'ARRAY') {
5598: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5599: }
5600: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5601: $prelink = $settings->{resetprelink};
5602: }
5603: if (ref($settings->{resetpostlink}) eq 'HASH') {
5604: %postlink = %{$settings->{resetpostlink}};
5605: }
5606: if (ref($settings->{resetemail}) eq 'ARRAY') {
5607: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5608: }
5609: if ($settings->{resetremove}) {
5610: $nostdtext = 1;
5611: }
5612: if ($settings->{resetcustom}) {
5613: $customurl = $settings->{resetcustom};
5614: }
5615: } else {
5616: if (ref($types) eq 'ARRAY') {
5617: foreach my $item (@{$types}) {
5618: $casesens{$item} = 1;
5619: $postlink{$item} = ['username','email'];
5620: }
5621: }
5622: $casesens{'default'} = 1;
5623: $postlink{'default'} = ['username','email'];
5624: $prelink = 'both';
5625: %emailsrc = (
5626: permanent => 1,
5627: critical => 1,
5628: notify => 1,
5629: );
5630: }
5631: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5632: $itemcount ++;
5633: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5634: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5635: '<td class="LC_left_item">'.
5636: '<input type="textbox" value="'.$shownlinklife.'" '.
5637: 'name="passwords_link" size="3" /></td></tr>';
5638: $itemcount ++;
5639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5640: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5641: '<td class="LC_left_item">';
5642: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5643: foreach my $item (@{$types}) {
5644: my $checkedcase;
5645: if ($casesens{$item}) {
5646: $checkedcase = ' checked="checked"';
5647: }
5648: $datatable .= '<span class="LC_nobreak"><label>'.
5649: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5650: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5651: '</span> ';
1.160.6.98 raeburn 5652: }
5653: }
5654: my $checkedcase;
5655: if ($casesens{'default'}) {
5656: $checkedcase = ' checked="checked"';
5657: }
5658: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5659: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5660: $othertitle.'</label></span></td>';
5661: $itemcount ++;
5662: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5663: my %checkedpre = (
5664: both => ' checked="checked"',
5665: either => '',
5666: );
5667: if ($prelink eq 'either') {
5668: $checkedpre{either} = ' checked="checked"';
5669: $checkedpre{both} = '';
5670: }
5671: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5672: '<td class="LC_left_item"><span class="LC_nobreak">'.
5673: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5674: &mt('Both username and e-mail address').'</label></span> '.
5675: '<span class="LC_nobreak"><label>'.
5676: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5677: &mt('Either username or e-mail address').'</label></span></td></tr>';
5678: $itemcount ++;
5679: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5680: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5681: '<td class="LC_left_item">';
5682: my %postlinked;
5683: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5684: foreach my $item (@{$types}) {
5685: undef(%postlinked);
5686: $datatable .= '<fieldset style="display: inline-block;">'.
5687: '<legend>'.$usertypes->{$item}.'</legend>';
5688: if (ref($postlink{$item}) eq 'ARRAY') {
5689: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5690: }
5691: foreach my $field ('email','username') {
5692: my $checked;
5693: if ($postlinked{$field}) {
5694: $checked = ' checked="checked"';
5695: }
5696: $datatable .= '<span class="LC_nobreak"><label>'.
5697: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5698: $field.'"'.$checked.' />'.$field.'</label>'.
5699: '<span> ';
5700: }
5701: $datatable .= '</fieldset>';
5702: }
5703: }
5704: if (ref($postlink{'default'}) eq 'ARRAY') {
5705: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5706: }
5707: $datatable .= '<fieldset style="display: inline-block;">'.
5708: '<legend>'.$othertitle.'</legend>';
5709: foreach my $field ('email','username') {
5710: my $checked;
5711: if ($postlinked{$field}) {
5712: $checked = ' checked="checked"';
5713: }
5714: $datatable .= '<span class="LC_nobreak"><label>'.
5715: '<input type="checkbox" name="passwords_postlink_default" value="'.
5716: $field.'"'.$checked.' />'.$field.'</label>'.
5717: '<span> ';
5718: }
5719: $datatable .= '</fieldset></td></tr>';
5720: $itemcount ++;
5721: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5722: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5723: '<td class="LC_left_item">';
5724: foreach my $type ('permanent','critical','notify') {
5725: my $checkedemail;
5726: if ($emailsrc{$type}) {
5727: $checkedemail = ' checked="checked"';
5728: }
5729: $datatable .= '<span class="LC_nobreak"><label>'.
5730: '<input type="checkbox" name="passwords_emailsrc" value="'.
5731: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5732: '<span> ';
5733: }
5734: $datatable .= '</td></tr>';
5735: $itemcount ++;
5736: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5737: my $switchserver = &check_switchserver($dom,$confname);
5738: my ($showstd,$noshowstd);
5739: if ($nostdtext) {
5740: $noshowstd = ' checked="checked"';
5741: } else {
5742: $showstd = ' checked="checked"';
5743: }
5744: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5745: '<td class="LC_left_item"><span class="LC_nobreak">'.
5746: &mt('Retain standard text:').
5747: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5748: &mt('Yes').'</label>'.' '.
5749: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5750: &mt('No').'</label></span><br />'.
5751: '<span class="LC_fontsize_small">'.
5752: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5753: &mt('Include custom text:');
5754: if ($customurl) {
1.160.6.104 raeburn 5755: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 5756: undef,undef,undef,undef,'background-color:#ffffff');
5757: $datatable .= '<span class="LC_nobreak"> '.$link.
5758: '<label><input type="checkbox" name="passwords_custom_del"'.
5759: ' value="1" />'.&mt('Delete?').'</label></span>'.
5760: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5761: }
5762: if ($switchserver) {
5763: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
5764: } else {
5765: $datatable .='<span class="LC_nobreak"> '.
5766: '<input type="file" name="passwords_customfile" /></span>';
5767: }
5768: $datatable .= '</td></tr>';
5769: } elsif ($position eq 'middle') {
5770: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
5771: my @items = ('intauth_cost','intauth_check','intauth_switch');
5772: my %defaults;
5773: if (ref($domconf{'defaults'}) eq 'HASH') {
5774: %defaults = %{$domconf{'defaults'}};
5775: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5776: $defaults{'intauth_cost'} = 10;
5777: }
5778: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5779: $defaults{'intauth_check'} = 0;
5780: }
5781: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5782: $defaults{'intauth_switch'} = 0;
5783: }
5784: } else {
5785: %defaults = (
5786: 'intauth_cost' => 10,
5787: 'intauth_check' => 0,
5788: 'intauth_switch' => 0,
5789: );
5790: }
5791: foreach my $item (@items) {
5792: if ($itemcount%2) {
5793: $css_class = '';
5794: } else {
5795: $css_class = ' class="LC_odd_row" ';
5796: }
5797: $datatable .= '<tr'.$css_class.'>'.
5798: '<td><span class="LC_nobreak">'.$titles{$item}.
5799: '</span></td><td class="LC_left_item" colspan="3">';
5800: if ($item eq 'intauth_switch') {
5801: my @options = (0,1,2);
5802: my %optiondesc = &Apache::lonlocal::texthash (
5803: 0 => 'No',
5804: 1 => 'Yes',
5805: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5806: );
5807: $datatable .= '<table width="100%">';
5808: foreach my $option (@options) {
5809: my $checked = ' ';
5810: if ($defaults{$item} eq $option) {
5811: $checked = ' checked="checked"';
5812: }
5813: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5814: '<label><input type="radio" name="'.$item.
5815: '" value="'.$option.'"'.$checked.' />'.
5816: $optiondesc{$option}.'</label></span></td></tr>';
5817: }
5818: $datatable .= '</table>';
5819: } elsif ($item eq 'intauth_check') {
5820: my @options = (0,1,2);
5821: my %optiondesc = &Apache::lonlocal::texthash (
5822: 0 => 'No',
5823: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5824: 2 => 'Yes, disallow login if stored cost is less than domain default',
5825: );
5826: $datatable .= '<table width="100%">';
5827: foreach my $option (@options) {
5828: my $checked = ' ';
5829: my $onclick;
5830: if ($defaults{$item} eq $option) {
5831: $checked = ' checked="checked"';
5832: }
5833: if ($option == 2) {
5834: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5835: }
5836: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5837: '<label><input type="radio" name="'.$item.
5838: '" value="'.$option.'"'.$checked.$onclick.' />'.
5839: $optiondesc{$option}.'</label></span></td></tr>';
5840: }
5841: $datatable .= '</table>';
5842: } else {
5843: $datatable .= '<input type="text" name="'.$item.'" value="'.
5844: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5845: }
5846: $datatable .= '</td></tr>';
5847: $itemcount ++;
5848: }
5849: } elsif ($position eq 'lower') {
5850: my ($min,$max,%chars,$numsaved);
1.160.6.99 raeburn 5851: $min = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 5852: if (ref($settings) eq 'HASH') {
5853: if ($settings->{min}) {
5854: $min = $settings->{min};
5855: }
5856: if ($settings->{max}) {
5857: $max = $settings->{max};
5858: }
5859: if (ref($settings->{chars}) eq 'ARRAY') {
5860: map { $chars{$_} = 1; } (@{$settings->{chars}});
5861: }
5862: if ($settings->{numsaved}) {
5863: $numsaved = $settings->{numsaved};
5864: }
5865: }
5866: my %rulenames = &Apache::lonlocal::texthash(
5867: uc => 'At least one upper case letter',
5868: lc => 'At least one lower case letter',
5869: num => 'At least one number',
5870: spec => 'At least one non-alphanumeric',
5871: );
5872: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5873: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
5874: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5875: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
5876: 'onblur="javascript:warnIntPass(this);" />'.
5877: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98 raeburn 5878: '</span></td></tr>';
5879: $itemcount ++;
5880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5881: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
5882: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99 raeburn 5883: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
5884: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5885: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
5886: '</span></td></tr>';
5887: $itemcount ++;
5888: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5889: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
5890: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
5891: '</span></td>';
5892: my $numinrow = 2;
5893: my @possrules = ('uc','lc','num','spec');
5894: $datatable .= '<td class="LC_left_item"><table>';
5895: for (my $i=0; $i<@possrules; $i++) {
5896: my ($rem,$checked);
5897: if ($chars{$possrules[$i]}) {
5898: $checked = ' checked="checked"';
5899: }
5900: $rem = $i%($numinrow);
5901: if ($rem == 0) {
5902: if ($i > 0) {
5903: $datatable .= '</tr>';
5904: }
5905: $datatable .= '<tr>';
5906: }
5907: $datatable .= '<td><span class="LC_nobreak"><label>'.
5908: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
5909: $rulenames{$possrules[$i]}.'</label></span></td>';
5910: }
5911: my $rem = @possrules%($numinrow);
5912: my $colsleft = $numinrow - $rem;
5913: if ($colsleft > 1 ) {
5914: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5915: ' </td>';
5916: } elsif ($colsleft == 1) {
5917: $datatable .= '<td class="LC_left_item"> </td>';
5918: }
5919: $datatable .='</table></td></tr>';
5920: $itemcount ++;
5921: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5922: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
5923: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100 raeburn 5924: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99 raeburn 5925: 'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98 raeburn 5926: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
5927: '</span></td></tr>';
5928: } else {
5929: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5930: my %ownerchg = (
5931: by => {},
5932: for => {},
5933: );
5934: my %ownertitles = &Apache::lonlocal::texthash (
5935: by => 'Course owner status(es) allowed',
5936: for => 'Student status(es) allowed',
5937: );
5938: if (ref($settings) eq 'HASH') {
5939: if (ref($settings->{crsownerchg}) eq 'HASH') {
5940: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
5941: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
5942: }
5943: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
5944: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
5945: }
5946: }
5947: }
5948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5949: $datatable .= '<tr '.$css_class.'>'.
5950: '<td>'.
5951: &mt('Requirements').'<ul>'.
5952: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
5953: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
5954: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
5955: '<li>'.&mt('User, course, and student share same domain').'</li>'.
5956: '</ul>'.
5957: '</td>'.
5958: '<td class="LC_left_item">';
5959: foreach my $item ('by','for') {
5960: $datatable .= '<fieldset style="display: inline-block;">'.
5961: '<legend>'.$ownertitles{$item}.'</legend>';
5962: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5963: foreach my $type (@{$types}) {
5964: my $checked;
5965: if ($ownerchg{$item}{$type}) {
5966: $checked = ' checked="checked"';
5967: }
5968: $datatable .= '<span class="LC_nobreak"><label>'.
5969: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
5970: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 5971: '</span> ';
1.160.6.98 raeburn 5972: }
5973: }
5974: my $checked;
5975: if ($ownerchg{$item}{'default'}) {
5976: $checked = ' checked="checked"';
5977: }
5978: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5979: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
5980: $othertitle.'</label></span></fieldset>';
5981: }
5982: $datatable .= '</td></tr>';
5983: }
5984: return $datatable;
5985: }
5986:
1.160.6.113 raeburn 5987: sub print_wafproxy {
5988: my ($position,$dom,$settings,$rowtotal) = @_;
5989: my $css_class;
5990: my $itemcount = 0;
5991: my $datatable;
5992: my %servers = &Apache::lonnet::internet_dom_servers($dom);
5993: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
5994: my %lt = &wafproxy_titles();
5995: foreach my $server (sort(keys(%servers))) {
5996: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
5997: next if ($serverhome eq '');
5998: my $serverdom;
5999: if ($serverhome ne $server) {
6000: $serverdom = &Apache::lonnet::host_domain($serverhome);
6001: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6002: $othercontrol{$server} = $serverdom;
6003: }
6004: } else {
6005: $serverdom = &Apache::lonnet::host_domain($server);
6006: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6007: if ($serverdom ne $dom) {
6008: $othercontrol{$server} = $serverdom;
6009: } else {
6010: $setdom = 1;
6011: if (ref($settings) eq 'HASH') {
6012: if (ref($settings->{'alias'}) eq 'HASH') {
6013: $aliases{$dom} = $settings->{'alias'};
6014: if ($aliases{$dom} ne '') {
6015: $showdom = 1;
6016: }
6017: }
6018: if (ref($settings->{'saml'}) eq 'HASH') {
6019: $saml{$dom} = $settings->{'saml'};
6020: }
6021: }
6022: }
6023: }
6024: }
6025: if ($setdom) {
6026: %{$values{$dom}} = ();
6027: if (ref($settings) eq 'HASH') {
6028: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6029: $values{$dom}{$item} = $settings->{$item};
6030: }
6031: }
6032: }
6033: if (keys(%othercontrol)) {
6034: %otherdoms = reverse(%othercontrol);
6035: foreach my $domain (keys(%otherdoms)) {
6036: %{$values{$domain}} = ();
6037: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6038: if (ref($config{'wafproxy'}) eq 'HASH') {
6039: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6040: if (exists($config{'wafproxy'}{'saml'})) {
6041: $saml{$domain} = $config{'wafproxy'}{'saml'};
6042: }
6043: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6044: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6045: }
6046: }
6047: }
6048: }
6049: if ($position eq 'top') {
6050: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6051: my %aliasinfo;
6052: foreach my $server (sort(keys(%servers))) {
6053: $itemcount ++;
6054: my $dom_in_effect;
6055: my $aliasrows = '<tr>'.
6056: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6057: &mt('Hostname').': '.
6058: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6059: if ($othercontrol{$server}) {
6060: $dom_in_effect = $othercontrol{$server};
6061: my ($current,$forsaml);
6062: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6063: $current = $aliases{$dom_in_effect}{$server};
6064: }
6065: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6066: if ($saml{$dom_in_effect}{$server}) {
6067: $forsaml = 1;
6068: }
6069: }
6070: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6071: &mt('Alias').': ';
6072: if ($current) {
6073: $aliasrows .= $current;
6074: if ($forsaml) {
6075: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6076: }
6077: } else {
6078: $aliasrows .= &mt('None');
6079: }
6080: $aliasrows .= ' <span class="LC_small">('.
6081: &mt('controlled by domain: [_1]',
6082: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6083: } else {
6084: $dom_in_effect = $dom;
6085: my ($current,$samlon,$samloff);
6086: $samloff = ' checked="checked"';
6087: if (ref($aliases{$dom}) eq 'HASH') {
6088: if ($aliases{$dom}{$server}) {
6089: $current = $aliases{$dom}{$server};
6090: }
6091: }
6092: if (ref($saml{$dom}) eq 'HASH') {
6093: if ($saml{$dom}{$server}) {
6094: $samlon = $samloff;
6095: undef($samloff);
6096: }
6097: }
6098: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6099: &mt('Alias').': '.
6100: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6101: 'value="'.$current.'" size="30" />'.
6102: (' 'x2).'<span class="LC_nobreak">'.
6103: &mt('Alias used for SSO Auth').': <label>'.
6104: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6105: &mt('No').'</label> <label>'.
6106: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6107: &mt('Yes').'</label></span>'.
6108: '</td>';
6109: }
6110: $aliasrows .= '</tr>';
6111: $aliasinfo{$dom_in_effect} .= $aliasrows;
6112: }
6113: if ($aliasinfo{$dom}) {
6114: my ($onclick,$wafon,$wafoff,$showtable);
6115: $onclick = ' onclick="javascript:toggleWAF();"';
6116: $wafoff = ' checked="checked"';
6117: $showtable = ' style="display:none";';
6118: if ($showdom) {
6119: $wafon = $wafoff;
6120: $wafoff = '';
6121: $showtable = ' style="display:inline;"';
6122: }
6123: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6124: $datatable = '<tr'.$css_class.'>'.
6125: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6126: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6127: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6128: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6129: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6130: &mt('No').'</label></span></td>'.
6131: '<td class="LC_left_item">'.
6132: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6133: '</table></td></tr>';
6134: $itemcount++;
6135: }
6136: if (keys(%otherdoms)) {
6137: foreach my $key (sort(keys(%otherdoms))) {
6138: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6139: $datatable .= '<tr'.$css_class.'>'.
6140: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6141: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6142: '</table></td></tr>';
6143: $itemcount++;
6144: }
6145: }
6146: } else {
6147: my %ip_methods = &remoteip_methods();
6148: if ($setdom) {
6149: $itemcount ++;
6150: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6151: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6152: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6153: $wafstyle = ' style="display:none;"';
6154: $nowafstyle = ' style="display:table-row;"';
6155: $currwafdisplay = ' style="display: none"';
6156: $wafrangestyle = ' style="display: none"';
6157: $curr_remotip = 'n';
6158: $ssltossl = ' checked="checked"';
6159: if ($showdom) {
6160: $wafstyle = ' style="display:table-row;"';
6161: $nowafstyle = ' style="display:none;"';
6162: if (keys(%{$values{$dom}})) {
6163: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6164: $curr_remotip = $values{$dom}{remoteip};
6165: }
6166: if ($curr_remotip eq 'h') {
6167: $currwafdisplay = ' style="display:table-row"';
6168: $wafrangestyle = ' style="display:inline-block;"';
6169: }
6170: if ($values{$dom}{'sslopt'}) {
6171: $alltossl = ' checked="checked"';
6172: $ssltossl = '';
6173: }
6174: }
6175: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6176: $vpndircheck = ' checked="checked"';
6177: $currwafvpn = ' style="display:table-row;"';
6178: $wafrangestyle = ' style="display:inline-block;"';
6179: } else {
6180: $vpnaliascheck = ' checked="checked"';
6181: $currwafvpn = ' style="display:none;"';
6182: }
6183: }
6184: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6185: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6186: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6187: '</tr>'.
6188: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6189: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6190: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6191: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6192: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6193: '<td class="LC_left_item"><table>'.
6194: '<tr>'.
6195: '<td valign="top">'.$lt{'remoteip'}.': '.
6196: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6197: foreach my $option ('m','h','n') {
6198: my $sel;
1.160.6.114 raeburn 6199: if ($option eq $curr_remotip) {
6200: $sel = ' selected="selected"';
6201: }
6202: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6203: $ip_methods{$option}.'</option>';
6204: }
6205: $datatable .= '</select></td></tr>'."\n".
6206: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6207: $lt{'ipheader'}.': '.
6208: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6209: 'name="wafproxy_ipheader" />'.
6210: '</td></tr>'."\n".
6211: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6212: $lt{'trusted'}.':<br />'.
6213: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6214: $values{$dom}{'trusted'}.'</textarea>'.
6215: '</td></tr>'."\n".
6216: '<tr><td><hr /></td></tr>'."\n".
6217: '<tr>'.
1.160.6.113 raeburn 6218: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6219: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6220: $lt{'vpndirect'}.'</label>'.(' 'x2).
6221: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6222: $lt{'vpnaliased'}.'</label></span></td></tr>';
6223: foreach my $item ('vpnint','vpnext') {
6224: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6225: '<td valign="top">'.$lt{$item}.':<br />'.
6226: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6227: $values{$dom}{$item}.'</textarea>'.
6228: '</td></tr>'."\n";
6229: }
6230: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6231: '<tr>'.
6232: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6233: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6234: $lt{'alltossl'}.'</label>'.(' 'x2).
6235: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6236: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6237: '</table></td></tr>';
6238: }
6239: if (keys(%otherdoms)) {
6240: foreach my $domain (sort(keys(%otherdoms))) {
6241: $itemcount ++;
6242: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6243: $datatable .= '<tr'.$css_class.'>'.
6244: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6245: '<td class="LC_left_item"><table>';
6246: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6247: my $showval = &mt('None');
6248: if ($item eq 'ssl') {
6249: $showval = $lt{'ssltossl'};
6250: }
6251: if ($values{$domain}{$item}) {
6252: $showval = $values{$domain}{$item};
6253: if ($item eq 'ssl') {
6254: $showval = $lt{'alltossl'};
6255: } elsif ($item eq 'remoteip') {
6256: $showval = $ip_methods{$values{$domain}{$item}};
6257: }
6258: }
6259: $datatable .= '<tr>'.
6260: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6261: }
6262: $datatable .= '</table></td></tr>';
6263: }
6264: }
6265: }
6266: $$rowtotal += $itemcount;
6267: return $datatable;
6268: }
6269:
6270: sub wafproxy_titles {
6271: return &Apache::lonlocal::texthash(
6272: remoteip => "Method for determining user's IP",
6273: ipheader => 'Request header containing remote IP',
6274: trusted => 'Trusted IP range(s)',
6275: vpnaccess => 'Access from institutional VPN',
6276: vpndirect => 'via regular hostname (no WAF)',
6277: vpnaliased => 'via aliased hostname (WAF)',
6278: vpnint => 'Internal IP Range(s) for VPN sessions',
6279: vpnext => 'IP Range(s) for backend WAF connections',
6280: sslopt => 'Forwarding http/https',
6281: alltossl => 'WAF forwards both http and https requests to https',
6282: ssltossl => 'WAF forwards http requests to http and https to https',
6283: );
6284: }
6285:
6286: sub remoteip_methods {
6287: return &Apache::lonlocal::texthash(
6288: m => 'Use Apache mod_remoteip',
6289: h => 'Use headers parsed by LON-CAPA',
6290: n => 'Not in use',
6291: );
6292: }
6293:
1.137 raeburn 6294: sub print_usersessions {
6295: my ($position,$dom,$settings,$rowtotal) = @_;
6296: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 6297: my (%by_ip,%by_location,@intdoms);
6298: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 6299:
6300: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6301: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6302: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6303: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6304: my $itemcount = 1;
6305: if ($position eq 'top') {
1.152 raeburn 6306: if (keys(%serverhomes) > 1) {
1.145 raeburn 6307: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 6308: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 6309: if (ref($settings) eq 'HASH') {
6310: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6311: $curroffloadnow = $settings->{'offloadnow'};
6312: }
1.160.6.105 raeburn 6313: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6314: $curroffloadoth = $settings->{'offloadoth'};
6315: }
1.160.6.61 raeburn 6316: }
1.160.6.105 raeburn 6317: my $other_insts = scalar(keys(%by_location));
6318: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6319: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 6320: } else {
1.140 raeburn 6321: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6322: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 6323: }
1.137 raeburn 6324: } else {
1.145 raeburn 6325: if (keys(%by_location) == 0) {
6326: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6327: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 6328: } else {
6329: my %lt = &usersession_titles();
6330: my $numinrow = 5;
6331: my $prefix;
6332: my @types;
6333: if ($position eq 'bottom') {
6334: $prefix = 'remote';
6335: @types = ('version','excludedomain','includedomain');
6336: } else {
6337: $prefix = 'hosted';
6338: @types = ('excludedomain','includedomain');
6339: }
6340: my (%current,%checkedon,%checkedoff);
6341: my @lcversions = &Apache::lonnet::all_loncaparevs();
6342: my @locations = sort(keys(%by_location));
6343: foreach my $type (@types) {
6344: $checkedon{$type} = '';
6345: $checkedoff{$type} = ' checked="checked"';
6346: }
6347: if (ref($settings) eq 'HASH') {
6348: if (ref($settings->{$prefix}) eq 'HASH') {
6349: foreach my $key (keys(%{$settings->{$prefix}})) {
6350: $current{$key} = $settings->{$prefix}{$key};
6351: if ($key eq 'version') {
6352: if ($current{$key} ne '') {
6353: $checkedon{$key} = ' checked="checked"';
6354: $checkedoff{$key} = '';
6355: }
6356: } elsif (ref($current{$key}) eq 'ARRAY') {
6357: $checkedon{$key} = ' checked="checked"';
6358: $checkedoff{$key} = '';
6359: }
1.137 raeburn 6360: }
6361: }
6362: }
1.145 raeburn 6363: foreach my $type (@types) {
6364: next if ($type ne 'version' && !@locations);
6365: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6366: $datatable .= '<tr'.$css_class.'>
6367: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6368: <span class="LC_nobreak">
6369: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6370: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6371: if ($type eq 'version') {
6372: my $selector = '<select name="'.$prefix.'_version">';
6373: foreach my $version (@lcversions) {
6374: my $selected = '';
6375: if ($current{'version'} eq $version) {
6376: $selected = ' selected="selected"';
6377: }
6378: $selector .= ' <option value="'.$version.'"'.
6379: $selected.'>'.$version.'</option>';
6380: }
6381: $selector .= '</select> ';
6382: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6383: } else {
6384: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6385: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6386: ' />'.(' 'x2).
6387: '<input type="button" value="'.&mt('uncheck all').'" '.
6388: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6389: "\n".
6390: '</div><div><table>';
6391: my $rem;
6392: for (my $i=0; $i<@locations; $i++) {
6393: my ($showloc,$value,$checkedtype);
6394: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6395: my $ip = $by_location{$locations[$i]}->[0];
6396: if (ref($by_ip{$ip}) eq 'ARRAY') {
6397: $value = join(':',@{$by_ip{$ip}});
6398: $showloc = join(', ',@{$by_ip{$ip}});
6399: if (ref($current{$type}) eq 'ARRAY') {
6400: foreach my $loc (@{$by_ip{$ip}}) {
6401: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6402: $checkedtype = ' checked="checked"';
6403: last;
6404: }
6405: }
1.138 raeburn 6406: }
6407: }
6408: }
1.145 raeburn 6409: $rem = $i%($numinrow);
6410: if ($rem == 0) {
6411: if ($i > 0) {
6412: $datatable .= '</tr>';
6413: }
6414: $datatable .= '<tr>';
6415: }
6416: $datatable .= '<td class="LC_left_item">'.
6417: '<span class="LC_nobreak"><label>'.
6418: '<input type="checkbox" name="'.$prefix.'_'.$type.
6419: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6420: '</label></span></td>';
1.137 raeburn 6421: }
1.145 raeburn 6422: $rem = @locations%($numinrow);
6423: my $colsleft = $numinrow - $rem;
6424: if ($colsleft > 1 ) {
6425: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6426: ' </td>';
6427: } elsif ($colsleft == 1) {
6428: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6429: }
1.145 raeburn 6430: $datatable .= '</tr></table>';
1.137 raeburn 6431: }
1.145 raeburn 6432: $datatable .= '</td></tr>';
6433: $itemcount ++;
1.137 raeburn 6434: }
6435: }
6436: }
6437: $$rowtotal += $itemcount;
6438: return $datatable;
6439: }
6440:
1.138 raeburn 6441: sub build_location_hashes {
6442: my ($intdoms,$by_ip,$by_location) = @_;
6443: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6444: (ref($by_location) eq 'HASH'));
6445: my %iphost = &Apache::lonnet::get_iphost();
6446: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6447: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6448: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6449: foreach my $id (@{$iphost{$primary_ip}}) {
6450: my $intdom = &Apache::lonnet::internet_dom($id);
6451: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6452: push(@{$intdoms},$intdom);
6453: }
6454: }
6455: }
6456: foreach my $ip (keys(%iphost)) {
6457: if (ref($iphost{$ip}) eq 'ARRAY') {
6458: foreach my $id (@{$iphost{$ip}}) {
6459: my $location = &Apache::lonnet::internet_dom($id);
6460: if ($location) {
6461: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6462: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6463: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6464: push(@{$by_ip->{$ip}},$location);
6465: }
6466: } else {
6467: $by_ip->{$ip} = [$location];
6468: }
6469: }
6470: }
6471: }
6472: }
6473: foreach my $ip (sort(keys(%{$by_ip}))) {
6474: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6475: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6476: my $first = $by_ip->{$ip}->[0];
6477: if (ref($by_location->{$first}) eq 'ARRAY') {
6478: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6479: push(@{$by_location->{$first}},$ip);
6480: }
6481: } else {
6482: $by_location->{$first} = [$ip];
6483: }
6484: }
6485: }
6486: return;
6487: }
6488:
1.145 raeburn 6489: sub current_offloads_to {
6490: my ($dom,$settings,$servers) = @_;
6491: my (%spareid,%otherdomconfigs);
1.152 raeburn 6492: if (ref($servers) eq 'HASH') {
1.145 raeburn 6493: foreach my $lonhost (sort(keys(%{$servers}))) {
6494: my $gotspares;
1.152 raeburn 6495: if (ref($settings) eq 'HASH') {
6496: if (ref($settings->{'spares'}) eq 'HASH') {
6497: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6498: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6499: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6500: $gotspares = 1;
6501: }
1.145 raeburn 6502: }
6503: }
6504: unless ($gotspares) {
6505: my $gotspares;
6506: my $serverhomeID =
6507: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6508: my $serverhomedom =
6509: &Apache::lonnet::host_domain($serverhomeID);
6510: if ($serverhomedom ne $dom) {
6511: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6512: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6513: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6514: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6515: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6516: $gotspares = 1;
6517: }
6518: }
6519: } else {
6520: $otherdomconfigs{$serverhomedom} =
6521: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6522: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6523: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6524: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6525: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6526: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6527: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6528: $gotspares = 1;
6529: }
6530: }
6531: }
6532: }
6533: }
6534: }
6535: }
6536: unless ($gotspares) {
6537: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6538: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6539: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6540: } else {
6541: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6542: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6543: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6544: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6545: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6546: } else {
1.150 raeburn 6547: my %what = (
6548: spareid => 1,
6549: );
6550: my ($result,$returnhash) =
6551: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6552: if ($result eq 'ok') {
6553: if (ref($returnhash) eq 'HASH') {
6554: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6555: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6556: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6557: }
6558: }
1.145 raeburn 6559: }
6560: }
6561: }
6562: }
6563: }
6564: }
6565: return %spareid;
6566: }
6567:
6568: sub spares_row {
1.160.6.105 raeburn 6569: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6570: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6571: my $css_class;
6572: my $numinrow = 4;
6573: my $itemcount = 1;
6574: my $datatable;
1.152 raeburn 6575: my %typetitles = &sparestype_titles();
6576: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6577: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6578: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6579: my ($othercontrol,$serverdom);
6580: if ($serverhome ne $server) {
6581: $serverdom = &Apache::lonnet::host_domain($serverhome);
6582: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6583: } else {
6584: $serverdom = &Apache::lonnet::host_domain($server);
6585: if ($serverdom ne $dom) {
6586: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6587: }
6588: }
6589: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6590: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6591: if (ref($curroffloadnow) eq 'HASH') {
6592: if ($curroffloadnow->{$server}) {
6593: $checkednow = ' checked="checked"';
6594: }
6595: }
1.160.6.105 raeburn 6596: if (ref($curroffloadoth) eq 'HASH') {
6597: if ($curroffloadoth->{$server}) {
6598: $checkedoth = ' checked="checked"';
6599: }
6600: }
1.145 raeburn 6601: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6602: $datatable .= '<tr'.$css_class.'>
6603: <td rowspan="2">
1.160.6.13 raeburn 6604: <span class="LC_nobreak">'.
6605: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6606: ,'<b>'.$server.'</b>').'</span><br />'.
6607: '<span class="LC_nobreak">'."\n".
6608: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6609: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6610: "\n";
1.160.6.105 raeburn 6611: if ($other_insts) {
6612: $datatable .= '<br />'.
6613: '<span class="LC_nobreak">'."\n".
6614: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6615: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6616: "\n";
6617: }
1.145 raeburn 6618: my (%current,%canselect);
1.152 raeburn 6619: my @choices =
6620: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6621: foreach my $type ('primary','default') {
6622: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6623: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6624: my @spares = @{$spareid->{$server}{$type}};
6625: if (@spares > 0) {
1.152 raeburn 6626: if ($othercontrol) {
6627: $current{$type} = join(', ',@spares);
6628: } else {
6629: $current{$type} .= '<table>';
6630: my $numspares = scalar(@spares);
6631: for (my $i=0; $i<@spares; $i++) {
6632: my $rem = $i%($numinrow);
6633: if ($rem == 0) {
6634: if ($i > 0) {
6635: $current{$type} .= '</tr>';
6636: }
6637: $current{$type} .= '<tr>';
1.145 raeburn 6638: }
1.152 raeburn 6639: $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'".');" /> '.
6640: $spareid->{$server}{$type}[$i].
6641: '</label></td>'."\n";
6642: }
6643: my $rem = @spares%($numinrow);
6644: my $colsleft = $numinrow - $rem;
6645: if ($colsleft > 1 ) {
6646: $current{$type} .= '<td colspan="'.$colsleft.
6647: '" class="LC_left_item">'.
6648: ' </td>';
6649: } elsif ($colsleft == 1) {
6650: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6651: }
1.152 raeburn 6652: $current{$type} .= '</tr></table>';
1.150 raeburn 6653: }
1.145 raeburn 6654: }
6655: }
6656: if ($current{$type} eq '') {
6657: $current{$type} = &mt('None specified');
6658: }
1.152 raeburn 6659: if ($othercontrol) {
6660: if ($type eq 'primary') {
6661: $canselect{$type} = $othercontrol;
6662: }
6663: } else {
6664: $canselect{$type} =
6665: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6666: '<select name="newspare_'.$type.'_'.$server.'" '.
6667: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6668: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6669: if (@choices > 0) {
6670: foreach my $lonhost (@choices) {
6671: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6672: }
6673: }
6674: $canselect{$type} .= '</select>'."\n";
6675: }
6676: } else {
6677: $current{$type} = &mt('Could not be determined');
6678: if ($type eq 'primary') {
6679: $canselect{$type} = $othercontrol;
6680: }
1.145 raeburn 6681: }
1.152 raeburn 6682: if ($type eq 'default') {
6683: $datatable .= '<tr'.$css_class.'>';
6684: }
6685: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6686: '<td>'.$current{$type}.'</td>'."\n".
6687: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6688: }
6689: $itemcount ++;
6690: }
6691: }
6692: $$rowtotal += $itemcount;
6693: return $datatable;
6694: }
6695:
1.152 raeburn 6696: sub possible_newspares {
6697: my ($server,$currspares,$serverhomes,$altids) = @_;
6698: my $serverhostname = &Apache::lonnet::hostname($server);
6699: my %excluded;
6700: if ($serverhostname ne '') {
6701: %excluded = (
6702: $serverhostname => 1,
6703: );
6704: }
6705: if (ref($currspares) eq 'HASH') {
6706: foreach my $type (keys(%{$currspares})) {
6707: if (ref($currspares->{$type}) eq 'ARRAY') {
6708: if (@{$currspares->{$type}} > 0) {
6709: foreach my $curr (@{$currspares->{$type}}) {
6710: my $hostname = &Apache::lonnet::hostname($curr);
6711: $excluded{$hostname} = 1;
6712: }
6713: }
6714: }
6715: }
6716: }
6717: my @choices;
6718: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6719: if (keys(%{$serverhomes}) > 1) {
6720: foreach my $name (sort(keys(%{$serverhomes}))) {
6721: unless ($excluded{$name}) {
6722: if (exists($altids->{$serverhomes->{$name}})) {
6723: push(@choices,$altids->{$serverhomes->{$name}});
6724: } else {
6725: push(@choices,$serverhomes->{$name});
1.145 raeburn 6726: }
6727: }
6728: }
6729: }
6730: }
1.152 raeburn 6731: return sort(@choices);
1.145 raeburn 6732: }
6733:
1.150 raeburn 6734: sub print_loadbalancing {
6735: my ($dom,$settings,$rowtotal) = @_;
6736: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6737: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6738: my $numinrow = 1;
6739: my $datatable;
6740: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 6741: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 6742: if (ref($settings) eq 'HASH') {
6743: %existing = %{$settings};
6744: }
6745: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6746: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 6747: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6748: } else {
6749: return;
6750: }
6751: my ($othertitle,$usertypes,$types) =
6752: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 6753: my $rownum = 8;
1.150 raeburn 6754: if (ref($types) eq 'ARRAY') {
6755: $rownum += scalar(@{$types});
6756: }
1.160.6.7 raeburn 6757: my @css_class = ('LC_odd_row','LC_even_row');
6758: my $balnum = 0;
6759: my $islast;
6760: my (@toshow,$disabledtext);
6761: if (keys(%currbalancer) > 0) {
6762: @toshow = sort(keys(%currbalancer));
6763: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6764: push(@toshow,'');
6765: }
6766: } else {
6767: @toshow = ('');
6768: $disabledtext = &mt('No existing load balancer');
6769: }
6770: foreach my $lonhost (@toshow) {
6771: if ($balnum == scalar(@toshow)-1) {
6772: $islast = 1;
6773: } else {
6774: $islast = 0;
6775: }
6776: my $cssidx = $balnum%2;
6777: my $targets_div_style = 'display: none';
6778: my $disabled_div_style = 'display: block';
6779: my $homedom_div_style = 'display: none';
6780: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
6781: '<td rowspan="'.$rownum.'" valign="top">'.
6782: '<p>';
6783: if ($lonhost eq '') {
6784: $datatable .= '<span class="LC_nobreak">';
6785: if (keys(%currbalancer) > 0) {
6786: $datatable .= &mt('Add balancer:');
6787: } else {
6788: $datatable .= &mt('Enable balancer:');
6789: }
6790: $datatable .= ' '.
6791: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6792: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6793: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6794: '<option value="" selected="selected">'.&mt('None').
6795: '</option>'."\n";
6796: foreach my $server (sort(keys(%servers))) {
6797: next if ($currbalancer{$server});
6798: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6799: }
6800: $datatable .=
6801: '</select>'."\n".
6802: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6803: } else {
6804: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6805: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6806: &mt('Stop balancing').'</label>'.
6807: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6808: $targets_div_style = 'display: block';
6809: $disabled_div_style = 'display: none';
6810: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6811: $homedom_div_style = 'display: block';
6812: }
6813: }
6814: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
6815: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6816: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6817: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6818: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6819: my @sparestypes = ('primary','default');
6820: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 6821: my %hostherechecked = (
6822: no => ' checked="checked"',
6823: );
1.160.6.94 raeburn 6824: my %balcookiechecked = (
6825: no => ' checked="checked"',
6826: );
1.160.6.7 raeburn 6827: foreach my $sparetype (@sparestypes) {
6828: my $targettable;
6829: for (my $i=0; $i<$numspares; $i++) {
6830: my $checked;
6831: if (ref($currtargets{$lonhost}) eq 'HASH') {
6832: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6833: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6834: $checked = ' checked="checked"';
6835: }
6836: }
6837: }
6838: my ($chkboxval,$disabled);
6839: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6840: $chkboxval = $spares[$i];
6841: }
6842: if (exists($currbalancer{$spares[$i]})) {
6843: $disabled = ' disabled="disabled"';
6844: }
6845: $targettable .=
1.160.6.55 raeburn 6846: '<td><span class="LC_nobreak"><label>'.
6847: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 6848: $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 6849: '</span></label></span></td>';
1.160.6.7 raeburn 6850: my $rem = $i%($numinrow);
6851: if ($rem == 0) {
6852: if (($i > 0) && ($i < $numspares-1)) {
6853: $targettable .= '</tr>';
6854: }
6855: if ($i < $numspares-1) {
6856: $targettable .= '<tr>';
1.150 raeburn 6857: }
6858: }
6859: }
1.160.6.7 raeburn 6860: if ($targettable ne '') {
6861: my $rem = $numspares%($numinrow);
6862: my $colsleft = $numinrow - $rem;
6863: if ($colsleft > 1 ) {
6864: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6865: ' </td>';
6866: } elsif ($colsleft == 1) {
6867: $targettable .= '<td class="LC_left_item"> </td>';
6868: }
6869: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6870: '<table><tr>'.$targettable.'</tr></table><br />';
6871: }
1.160.6.76 raeburn 6872: $hostherechecked{$sparetype} = '';
6873: if (ref($currtargets{$lonhost}) eq 'HASH') {
6874: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6875: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6876: $hostherechecked{$sparetype} = ' checked="checked"';
6877: $hostherechecked{'no'} = '';
6878: }
6879: }
6880: }
6881: }
1.160.6.94 raeburn 6882: if ($currcookies{$lonhost}) {
6883: %balcookiechecked = (
6884: yes => ' checked="checked"',
6885: );
6886: }
1.160.6.76 raeburn 6887: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6888: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6889: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6890: foreach my $sparetype (@sparestypes) {
6891: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6892: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6893: '</i></label><br />';
1.160.6.7 raeburn 6894: }
1.160.6.94 raeburn 6895: $datatable .= &mt('Use balancer cookie').'<br />'.
6896: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6897: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6898: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6899: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6900: '</div></td></tr>'.
1.160.6.7 raeburn 6901: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6902: $othertitle,$usertypes,$types,\%servers,
6903: \%currbalancer,$lonhost,
6904: $targets_div_style,$homedom_div_style,
6905: $css_class[$cssidx],$balnum,$islast);
6906: $$rowtotal += $rownum;
6907: $balnum ++;
6908: }
6909: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6910: return $datatable;
6911: }
6912:
6913: sub get_loadbalancers_config {
1.160.6.94 raeburn 6914: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 6915: return unless ((ref($servers) eq 'HASH') &&
6916: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 6917: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6918: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 6919: if (keys(%{$existing}) > 0) {
6920: my $oldlonhost;
6921: foreach my $key (sort(keys(%{$existing}))) {
6922: if ($key eq 'lonhost') {
6923: $oldlonhost = $existing->{'lonhost'};
6924: $currbalancer->{$oldlonhost} = 1;
6925: } elsif ($key eq 'targets') {
6926: if ($oldlonhost) {
6927: $currtargets->{$oldlonhost} = $existing->{'targets'};
6928: }
6929: } elsif ($key eq 'rules') {
6930: if ($oldlonhost) {
6931: $currrules->{$oldlonhost} = $existing->{'rules'};
6932: }
6933: } elsif (ref($existing->{$key}) eq 'HASH') {
6934: $currbalancer->{$key} = 1;
6935: $currtargets->{$key} = $existing->{$key}{'targets'};
6936: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 6937: if ($existing->{$key}{'cookie'}) {
6938: $currcookies->{$key} = 1;
6939: }
1.150 raeburn 6940: }
6941: }
1.160.6.7 raeburn 6942: } else {
6943: my ($balancerref,$targetsref) =
6944: &Apache::lonnet::get_lonbalancer_config($servers);
6945: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
6946: foreach my $server (sort(keys(%{$balancerref}))) {
6947: $currbalancer->{$server} = 1;
6948: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 6949: }
6950: }
6951: }
1.160.6.7 raeburn 6952: return;
1.150 raeburn 6953: }
6954:
6955: sub loadbalancing_rules {
6956: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 6957: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
6958: $css_class,$balnum,$islast) = @_;
1.150 raeburn 6959: my $output;
1.160.6.7 raeburn 6960: my $num = 0;
6961: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 6962: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
6963: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
6964: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 6965: $num ++;
1.150 raeburn 6966: my $current;
6967: if (ref($currrules) eq 'HASH') {
6968: $current = $currrules->{$type};
6969: }
1.160.6.55 raeburn 6970: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 6971: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 6972: $current = '';
6973: }
6974: }
6975: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 6976: $servers,$currbalancer,$lonhost,$dom,
6977: $targets_div_style,$homedom_div_style,
6978: $css_class,$balnum,$num,$islast);
1.150 raeburn 6979: }
6980: }
6981: return $output;
6982: }
6983:
6984: sub loadbalancing_titles {
6985: my ($dom,$intdom,$usertypes,$types) = @_;
6986: my %othertypes = (
6987: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
6988: '_LC_author' => &mt('Users from [_1] with author role',$dom),
6989: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
6990: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 6991: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
6992: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 6993: );
1.160.6.26 raeburn 6994: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 6995: my @available;
1.150 raeburn 6996: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 6997: @available = @{$types};
1.150 raeburn 6998: }
1.160.6.89 raeburn 6999: unless (grep(/^default$/,@available)) {
7000: push(@available,'default');
7001: }
7002: unshift(@alltypes,@available);
1.150 raeburn 7003: my %titles;
7004: foreach my $type (@alltypes) {
7005: if ($type =~ /^_LC_/) {
7006: $titles{$type} = $othertypes{$type};
7007: } elsif ($type eq 'default') {
7008: $titles{$type} = &mt('All users from [_1]',$dom);
7009: if (ref($types) eq 'ARRAY') {
7010: if (@{$types} > 0) {
7011: $titles{$type} = &mt('Other users from [_1]',$dom);
7012: }
7013: }
7014: } elsif (ref($usertypes) eq 'HASH') {
7015: $titles{$type} = $usertypes->{$type};
7016: }
7017: }
7018: return (\@alltypes,\%othertypes,\%titles);
7019: }
7020:
7021: sub loadbalance_rule_row {
1.160.6.7 raeburn 7022: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7023: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 7024: my @rulenames;
1.150 raeburn 7025: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 7026: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 7027: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7028: } else {
1.160.6.26 raeburn 7029: @rulenames = ('default','homeserver');
7030: if ($type eq '_LC_external') {
7031: push(@rulenames,'externalbalancer');
7032: } else {
7033: push(@rulenames,'specific');
7034: }
7035: push(@rulenames,'none');
1.150 raeburn 7036: }
7037: my $style = $targets_div_style;
1.160.6.55 raeburn 7038: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7039: $style = $homedom_div_style;
7040: }
1.160.6.7 raeburn 7041: my $space;
7042: if ($islast && $num == 1) {
7043: $space = '<div display="inline-block"> </div>';
7044: }
7045: my $output =
7046: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7047: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7048: '<td valaign="top">'.$space.
7049: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7050: for (my $i=0; $i<@rulenames; $i++) {
7051: my $rule = $rulenames[$i];
7052: my ($checked,$extra);
7053: if ($rulenames[$i] eq 'default') {
7054: $rule = '';
7055: }
7056: if ($rulenames[$i] eq 'specific') {
7057: if (ref($servers) eq 'HASH') {
7058: my $default;
7059: if (($current ne '') && (exists($servers->{$current}))) {
7060: $checked = ' checked="checked"';
7061: }
7062: unless ($checked) {
7063: $default = ' selected="selected"';
7064: }
1.160.6.7 raeburn 7065: $extra =
7066: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7067: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7068: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7069: '<option value=""'.$default.'></option>'."\n";
7070: foreach my $server (sort(keys(%{$servers}))) {
7071: if (ref($currbalancer) eq 'HASH') {
7072: next if (exists($currbalancer->{$server}));
7073: }
1.150 raeburn 7074: my $selected;
1.160.6.7 raeburn 7075: if ($server eq $current) {
1.150 raeburn 7076: $selected = ' selected="selected"';
7077: }
1.160.6.7 raeburn 7078: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7079: }
7080: $extra .= '</select>';
7081: }
7082: } elsif ($rule eq $current) {
7083: $checked = ' checked="checked"';
7084: }
7085: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 7086: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7087: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7088: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 7089: ')"'.$checked.' /> ';
1.160.6.56 raeburn 7090: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 7091: $output .= $ruletitles{'particular'};
7092: } else {
7093: $output .= $ruletitles{$rulenames[$i]};
7094: }
7095: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7096: }
7097: $output .= '</div></td></tr>'."\n";
7098: return $output;
7099: }
7100:
7101: sub offloadtype_text {
7102: my %ruletitles = &Apache::lonlocal::texthash (
7103: 'default' => 'Offloads to default destinations',
7104: 'homeserver' => "Offloads to user's home server",
7105: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7106: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 7107: 'none' => 'No offload',
1.160.6.26 raeburn 7108: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7109: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 7110: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7111: );
7112: return %ruletitles;
7113: }
7114:
7115: sub sparestype_titles {
7116: my %typestitles = &Apache::lonlocal::texthash (
7117: 'primary' => 'primary',
7118: 'default' => 'default',
7119: );
7120: return %typestitles;
7121: }
7122:
1.28 raeburn 7123: sub contact_titles {
7124: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 7125: 'supportemail' => 'Support E-mail address',
7126: 'adminemail' => 'Default Server Admin E-mail address',
7127: 'errormail' => 'Error reports to be e-mailed to',
7128: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 7129: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7130: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 7131: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7132: 'requestsmail' => 'E-mail from course requests requiring approval',
7133: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 7134: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 7135: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 7136: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7137: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 7138: 'errorweights' => 'Weights used to compute error count',
7139: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7140: );
7141: my %short_titles = &Apache::lonlocal::texthash (
7142: adminemail => 'Admin E-mail address',
7143: supportemail => 'Support E-mail',
7144: );
7145: return (\%titles,\%short_titles);
7146: }
7147:
1.160.6.78 raeburn 7148: sub helpform_fields {
7149: my %titles = &Apache::lonlocal::texthash (
7150: 'username' => 'Name',
7151: 'user' => 'Username/domain',
7152: 'phone' => 'Phone',
7153: 'cc' => 'Cc e-mail',
7154: 'course' => 'Course Details',
7155: 'section' => 'Sections',
7156: 'screenshot' => 'File upload',
7157: );
7158: my @fields = ('username','phone','user','course','section','cc','screenshot');
7159: my %possoptions = (
7160: username => ['yes','no','req'],
7161: phone => ['yes','no','req'],
7162: user => ['yes','no'],
7163: cc => ['yes','no'],
7164: course => ['yes','no'],
7165: section => ['yes','no'],
7166: screenshot => ['yes','no'],
7167: );
7168: my %fieldoptions = &Apache::lonlocal::texthash (
7169: 'yes' => 'Optional',
7170: 'req' => 'Required',
7171: 'no' => "Not shown",
7172: );
7173: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7174: }
7175:
1.72 raeburn 7176: sub tool_titles {
7177: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 7178: aboutme => 'Personal web page',
1.86 raeburn 7179: blog => 'Blog',
1.160.6.4 raeburn 7180: webdav => 'WebDAV',
1.86 raeburn 7181: portfolio => 'Portfolio',
1.88 bisitz 7182: official => 'Official courses (with institutional codes)',
7183: unofficial => 'Unofficial courses',
1.98 raeburn 7184: community => 'Communities',
1.160.6.30 raeburn 7185: textbook => 'Textbook courses',
1.86 raeburn 7186: );
1.72 raeburn 7187: return %titles;
7188: }
7189:
1.101 raeburn 7190: sub courserequest_titles {
7191: my %titles = &Apache::lonlocal::texthash (
7192: official => 'Official',
7193: unofficial => 'Unofficial',
7194: community => 'Communities',
1.160.6.30 raeburn 7195: textbook => 'Textbook',
1.101 raeburn 7196: norequest => 'Not allowed',
1.104 raeburn 7197: approval => 'Approval by Dom. Coord.',
1.101 raeburn 7198: validate => 'With validation',
7199: autolimit => 'Numerical limit',
1.103 raeburn 7200: unlimited => '(blank for unlimited)',
1.101 raeburn 7201: );
7202: return %titles;
7203: }
7204:
1.160.6.5 raeburn 7205: sub authorrequest_titles {
7206: my %titles = &Apache::lonlocal::texthash (
7207: norequest => 'Not allowed',
7208: approval => 'Approval by Dom. Coord.',
7209: automatic => 'Automatic approval',
7210: );
7211: return %titles;
7212: }
7213:
1.101 raeburn 7214: sub courserequest_conditions {
7215: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7216: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 7217: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7218: );
7219: return %conditions;
7220: }
7221:
7222:
1.27 raeburn 7223: sub print_usercreation {
1.30 raeburn 7224: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7225: my $numinrow = 4;
1.28 raeburn 7226: my $datatable;
7227: if ($position eq 'top') {
1.30 raeburn 7228: $$rowtotal ++;
1.34 raeburn 7229: my $rowcount = 0;
1.32 raeburn 7230: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7231: if (ref($rules) eq 'HASH') {
7232: if (keys(%{$rules}) > 0) {
1.32 raeburn 7233: $datatable .= &user_formats_row('username',$settings,$rules,
7234: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7235: $$rowtotal ++;
1.32 raeburn 7236: $rowcount ++;
7237: }
7238: }
7239: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7240: if (ref($idrules) eq 'HASH') {
7241: if (keys(%{$idrules}) > 0) {
7242: $datatable .= &user_formats_row('id',$settings,$idrules,
7243: $idruleorder,$numinrow,$rowcount);
7244: $$rowtotal ++;
7245: $rowcount ++;
1.28 raeburn 7246: }
7247: }
1.39 raeburn 7248: if ($rowcount == 0) {
7249: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7250: $$rowtotal ++;
7251: $rowcount ++;
7252: }
1.34 raeburn 7253: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 7254: my @creators = ('author','course','requestcrs');
1.37 raeburn 7255: my ($rules,$ruleorder) =
7256: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7257: my %lt = &usercreation_types();
7258: my %checked;
7259: if (ref($settings) eq 'HASH') {
7260: if (ref($settings->{'cancreate'}) eq 'HASH') {
7261: foreach my $item (@creators) {
7262: $checked{$item} = $settings->{'cancreate'}{$item};
7263: }
7264: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7265: foreach my $item (@creators) {
7266: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7267: $checked{$item} = 'none';
7268: }
7269: }
7270: }
7271: }
7272: my $rownum = 0;
7273: foreach my $item (@creators) {
7274: $rownum ++;
1.160.6.34 raeburn 7275: if ($checked{$item} eq '') {
7276: $checked{$item} = 'any';
1.34 raeburn 7277: }
7278: my $css_class;
7279: if ($rownum%2) {
7280: $css_class = '';
7281: } else {
7282: $css_class = ' class="LC_odd_row" ';
7283: }
7284: $datatable .= '<tr'.$css_class.'>'.
7285: '<td><span class="LC_nobreak">'.$lt{$item}.
7286: '</span></td><td align="right">';
1.160.6.34 raeburn 7287: my @options = ('any');
7288: if (ref($rules) eq 'HASH') {
7289: if (keys(%{$rules}) > 0) {
7290: push(@options,('official','unofficial'));
1.37 raeburn 7291: }
7292: }
1.160.6.34 raeburn 7293: push(@options,'none');
1.37 raeburn 7294: foreach my $option (@options) {
1.50 raeburn 7295: my $type = 'radio';
1.34 raeburn 7296: my $check = ' ';
1.160.6.34 raeburn 7297: if ($checked{$item} eq $option) {
7298: $check = ' checked="checked" ';
1.34 raeburn 7299: }
7300: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7301: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7302: $item.'" value="'.$option.'"'.$check.'/> '.
7303: $lt{$option}.'</label> </span>';
7304: }
7305: $datatable .= '</td></tr>';
7306: }
1.28 raeburn 7307: } else {
7308: my @contexts = ('author','course','domain');
7309: my @authtypes = ('int','krb4','krb5','loc');
7310: my %checked;
7311: if (ref($settings) eq 'HASH') {
7312: if (ref($settings->{'authtypes'}) eq 'HASH') {
7313: foreach my $item (@contexts) {
7314: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7315: foreach my $auth (@authtypes) {
7316: if ($settings->{'authtypes'}{$item}{$auth}) {
7317: $checked{$item}{$auth} = ' checked="checked" ';
7318: }
7319: }
7320: }
7321: }
1.27 raeburn 7322: }
1.35 raeburn 7323: } else {
7324: foreach my $item (@contexts) {
1.36 raeburn 7325: foreach my $auth (@authtypes) {
1.35 raeburn 7326: $checked{$item}{$auth} = ' checked="checked" ';
7327: }
7328: }
1.27 raeburn 7329: }
1.28 raeburn 7330: my %title = &context_names();
7331: my %authname = &authtype_names();
7332: my $rownum = 0;
7333: my $css_class;
7334: foreach my $item (@contexts) {
7335: if ($rownum%2) {
7336: $css_class = '';
7337: } else {
7338: $css_class = ' class="LC_odd_row" ';
7339: }
1.30 raeburn 7340: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7341: '<td>'.$title{$item}.
7342: '</td><td class="LC_left_item">'.
7343: '<span class="LC_nobreak">';
7344: foreach my $auth (@authtypes) {
7345: $datatable .= '<label>'.
7346: '<input type="checkbox" name="'.$item.'_auth" '.
7347: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7348: $authname{$auth}.'</label> ';
7349: }
7350: $datatable .= '</span></td></tr>';
7351: $rownum ++;
1.27 raeburn 7352: }
1.30 raeburn 7353: $$rowtotal += $rownum;
1.27 raeburn 7354: }
7355: return $datatable;
7356: }
7357:
1.160.6.34 raeburn 7358: sub print_selfcreation {
7359: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 7360: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7361: $emaildomain,$datatable);
1.160.6.34 raeburn 7362: if (ref($settings) eq 'HASH') {
7363: if (ref($settings->{'cancreate'}) eq 'HASH') {
7364: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 7365: if (ref($createsettings) eq 'HASH') {
7366: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7367: @selfcreate = @{$createsettings->{'selfcreate'}};
7368: } elsif ($createsettings->{'selfcreate'} ne '') {
7369: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7370: @selfcreate = ('email','login','sso');
7371: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7372: @selfcreate = ($createsettings->{'selfcreate'});
7373: }
7374: }
7375: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7376: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 7377: }
1.160.6.93 raeburn 7378: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7379: $emailoptions = $createsettings->{'emailoptions'};
7380: }
7381: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7382: $emailverified = $createsettings->{'emailverified'};
7383: }
7384: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7385: $emaildomain = $createsettings->{'emaildomain'};
7386: }
1.160.6.34 raeburn 7387: }
7388: }
7389: }
7390: my %radiohash;
7391: my $numinrow = 4;
7392: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 7393: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 7394: if ($position eq 'top') {
7395: my %choices = &Apache::lonlocal::texthash (
7396: cancreate_login => 'Institutional Login',
7397: cancreate_sso => 'Institutional Single Sign On',
7398: );
7399: my @toggles = sort(keys(%choices));
7400: my %defaultchecked = (
7401: 'cancreate_login' => 'off',
7402: 'cancreate_sso' => 'off',
7403: );
1.160.6.35 raeburn 7404: my ($onclick,$itemcount);
1.160.6.34 raeburn 7405: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7406: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 7407: $$rowtotal += $itemcount;
1.160.6.34 raeburn 7408:
7409: if (ref($usertypes) eq 'HASH') {
7410: if (keys(%{$usertypes}) > 0) {
7411: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7412: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 7413: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 7414: $$rowtotal ++;
7415: }
7416: }
1.160.6.44 raeburn 7417: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7418: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7419: $fieldtitles{'inststatus'} = &mt('Institutional status');
7420: my $rem;
7421: my $numperrow = 2;
7422: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7423: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 7424: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 7425: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 7426: '<table>'."\n";
1.160.6.44 raeburn 7427: for (my $i=0; $i<@fields; $i++) {
7428: $rem = $i%($numperrow);
7429: if ($rem == 0) {
7430: if ($i > 0) {
7431: $datatable .= '</tr>';
7432: }
7433: $datatable .= '<tr>';
7434: }
7435: my $currval;
1.160.6.51 raeburn 7436: if (ref($createsettings) eq 'HASH') {
7437: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7438: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7439: }
1.160.6.44 raeburn 7440: }
7441: $datatable .= '<td class="LC_left_item">'.
7442: '<span class="LC_nobreak">'.
7443: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7444: 'value="'.$currval.'" size="10" /> '.
7445: $fieldtitles{$fields[$i]}.'</span></td>';
7446: }
7447: my $colsleft = $numperrow - $rem;
7448: if ($colsleft > 1 ) {
7449: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7450: ' </td>';
7451: } elsif ($colsleft == 1) {
7452: $datatable .= '<td class="LC_left_item"> </td>';
7453: }
7454: $datatable .= '</tr></table></td></tr>';
7455: $$rowtotal ++;
1.160.6.34 raeburn 7456: } elsif ($position eq 'middle') {
7457: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 7458: my @posstypes;
1.160.6.34 raeburn 7459: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7460: @posstypes = @{$types};
7461: }
7462: unless (grep(/^default$/,@posstypes)) {
7463: push(@posstypes,'default');
7464: }
7465: my %usertypeshash;
7466: if (ref($usertypes) eq 'HASH') {
7467: %usertypeshash = %{$usertypes};
7468: }
7469: $usertypeshash{'default'} = $othertitle;
7470: foreach my $status (@posstypes) {
7471: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7472: $numinrow,$$rowtotal,\%usertypeshash);
7473: $$rowtotal ++;
1.160.6.34 raeburn 7474: }
7475: } else {
1.160.6.40 raeburn 7476: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 7477: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 7478: );
7479: my @toggles = sort(keys(%choices));
7480: my %defaultchecked = (
7481: 'cancreate_email' => 'off',
7482: );
1.160.6.93 raeburn 7483: my $customclass = 'LC_selfcreate_email';
7484: my $classprefix = 'LC_canmodify_emailusername_';
7485: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 7486: my $display = 'none';
1.160.6.93 raeburn 7487: my $rowstyle = 'display:none';
1.160.6.40 raeburn 7488: if (grep(/^\Qemail\E$/,@selfcreate)) {
7489: $display = 'block';
1.160.6.93 raeburn 7490: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 7491: }
1.160.6.93 raeburn 7492: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7493: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7494: \%choices,$$rowtotal,$onclick);
7495: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7496: $rowstyle);
7497: $$rowtotal ++;
7498: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7499: $rowstyle);
7500: $$rowtotal ++;
7501: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 7502: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 7503: my ($emailrules,$emailruleorder) =
7504: &Apache::lonnet::inst_userrules($dom,'email');
7505: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7506: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7507: if (ref($types) eq 'ARRAY') {
7508: @posstypes = @{$types};
7509: }
7510: if (@posstypes) {
7511: unless (grep(/^default$/,@posstypes)) {
7512: push(@posstypes,'default');
1.160.6.89 raeburn 7513: }
7514: if (ref($usertypes) eq 'HASH') {
7515: %usertypeshash = %{$usertypes};
7516: }
1.160.6.93 raeburn 7517: my $currassign;
7518: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7519: $currassign = {
7520: selfassign => $domdefaults{'inststatusguest'},
7521: };
7522: @ordered = @{$domdefaults{'inststatusguest'}};
7523: } else {
7524: $currassign = { selfassign => [] };
7525: }
7526: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7527: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7528: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7529: $numinrow,$othertitle,'selfassign',
7530: $rowtotal,$onclicktypes,$customclass,
7531: $rowstyle);
7532: $$rowtotal ++;
1.160.6.89 raeburn 7533: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7534: foreach my $status (@posstypes) {
7535: my $css_class;
7536: if ($$rowtotal%2) {
7537: $css_class = 'LC_odd_row ';
7538: }
7539: $css_class .= $customclass;
7540: my $rowid = $optionsprefix.$status;
7541: my $hidden = 1;
7542: my $currstyle = 'display:none';
7543: if (grep(/^\Q$status\E$/,@ordered)) {
7544: $currstyle = $rowstyle;
7545: $hidden = 0;
7546: }
7547: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7548: $emailrules,$emailruleorder,$settings,$status,$rowid,
7549: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7550: unless ($hidden) {
7551: $$rowtotal ++;
7552: }
1.160.6.89 raeburn 7553: }
7554: } else {
1.160.6.93 raeburn 7555: my $css_class;
7556: if ($$rowtotal%2) {
7557: $css_class = 'LC_odd_row ';
7558: }
7559: $css_class .= $customclass;
1.160.6.89 raeburn 7560: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7561: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7562: $emailrules,$emailruleorder,$settings,'default','',
7563: $othertitle,$css_class,$rowstyle,$intdom);
7564: $$rowtotal ++;
1.160.6.34 raeburn 7565: }
1.160.6.35 raeburn 7566: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7567: $numinrow = 1;
1.160.6.93 raeburn 7568: if (@posstypes) {
7569: foreach my $status (@posstypes) {
7570: my $rowid = $classprefix.$status;
7571: my $datarowstyle = 'display:none';
7572: if (grep(/^\Q$status\E$/,@ordered)) {
7573: $datarowstyle = $rowstyle;
7574: }
7575: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7576: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7577: $infotitles,$rowid,$customclass,$datarowstyle);
7578: unless ($datarowstyle eq 'display:none') {
7579: $$rowtotal ++;
7580: }
1.160.6.34 raeburn 7581: }
1.160.6.93 raeburn 7582: } else {
7583: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7584: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7585: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7586: }
7587: }
7588: return $datatable;
7589: }
7590:
1.160.6.93 raeburn 7591: sub selfcreate_javascript {
7592: return <<"ENDSCRIPT";
7593:
7594: <script type="text/javascript">
7595: // <![CDATA[
7596:
7597: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7598: var x = document.getElementsByClassName(target);
7599: var insttypes = 0;
7600: var insttypeRegExp = new RegExp(prefix);
7601: if ((x.length != undefined) && (x.length > 0)) {
7602: if (form.elements[radio].length != undefined) {
7603: for (var i=0; i<form.elements[radio].length; i++) {
7604: if (form.elements[radio][i].checked) {
7605: if (form.elements[radio][i].value == 1) {
7606: for (var j=0; j<x.length; j++) {
7607: if (x[j].id == 'undefined') {
7608: x[j].style.display = 'table-row';
7609: } else if (insttypeRegExp.test(x[j].id)) {
7610: insttypes ++;
7611: } else {
7612: x[j].style.display = 'table-row';
7613: }
7614: }
7615: } else {
7616: for (var j=0; j<x.length; j++) {
7617: x[j].style.display = 'none';
7618: }
1.160.6.40 raeburn 7619: }
1.160.6.93 raeburn 7620: break;
7621: }
7622: }
7623: if (insttypes > 0) {
7624: toggleDataRow(form,checkbox,target,altprefix);
7625: toggleDataRow(form,checkbox,target,prefix,1);
7626: }
7627: }
7628: }
7629: return;
7630: }
7631:
7632: function toggleDataRow(form,checkbox,target,prefix,docount) {
7633: if (form.elements[checkbox].length != undefined) {
7634: var count = 0;
7635: if (docount) {
7636: for (var i=0; i<form.elements[checkbox].length; i++) {
7637: if (form.elements[checkbox][i].checked) {
7638: count ++;
7639: }
7640: }
7641: }
7642: for (var i=0; i<form.elements[checkbox].length; i++) {
7643: var type = form.elements[checkbox][i].value;
7644: if (document.getElementById(prefix+type)) {
7645: if (form.elements[checkbox][i].checked) {
7646: document.getElementById(prefix+type).style.display = 'table-row';
7647: if (count % 2 == 1) {
7648: document.getElementById(prefix+type).className = target+' LC_odd_row';
7649: } else {
7650: document.getElementById(prefix+type).className = target;
7651: }
7652: count ++;
1.160.6.40 raeburn 7653: } else {
1.160.6.93 raeburn 7654: document.getElementById(prefix+type).style.display = 'none';
7655: }
7656: }
7657: }
7658: }
7659: return;
7660: }
7661:
7662: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7663: var caller = radio+'_'+status;
7664: if (form.elements[caller].length != undefined) {
7665: for (var i=0; i<form.elements[caller].length; i++) {
7666: if (form.elements[caller][i].checked) {
7667: if (document.getElementById(altprefix+'_inst_'+status)) {
7668: var curr = form.elements[caller][i].value;
7669: if (prefix) {
7670: document.getElementById(prefix+'_'+status).style.display = 'none';
7671: }
7672: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7673: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7674: if (curr == 'custom') {
7675: if (prefix) {
7676: document.getElementById(prefix+'_'+status).style.display = 'inline';
7677: }
7678: } else if (curr == 'inst') {
7679: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7680: } else if (curr == 'noninst') {
7681: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 7682: }
1.160.6.93 raeburn 7683: break;
1.160.6.40 raeburn 7684: }
1.160.6.93 raeburn 7685: }
7686: }
7687: }
7688: }
7689:
7690: // ]]>
7691: </script>
7692:
7693: ENDSCRIPT
7694: }
7695:
7696: sub noninst_users {
7697: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7698: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7699: my $class = 'LC_left_item';
7700: if ($css_class) {
7701: $css_class = ' class="'.$css_class.'"';
7702: }
7703: if ($rowid) {
7704: $rowid = ' id="'.$rowid.'"';
7705: }
7706: if ($rowstyle) {
7707: $rowstyle = ' style="'.$rowstyle.'"';
7708: }
7709: my ($output,$description);
7710: if ($type eq 'default') {
7711: $description = &mt('Requests for: [_1]',$typetitle);
7712: } else {
7713: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7714: }
7715: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7716: "<td>$description</td>\n".
7717: '<td class="'.$class.'" colspan="2">'.
7718: '<table><tr>';
7719: my %headers = &Apache::lonlocal::texthash(
7720: approve => 'Processing',
7721: email => 'E-mail',
7722: username => 'Username',
7723: );
7724: foreach my $item ('approve','email','username') {
7725: $output .= '<th>'.$headers{$item}.'</th>';
7726: }
7727: $output .= '</tr><tr>';
7728: foreach my $item ('approve','email','username') {
7729: $output .= '<td valign="top">';
7730: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7731: if ($item eq 'approve') {
7732: %choices = &Apache::lonlocal::texthash (
7733: automatic => 'Automatically approved',
7734: approval => 'Queued for approval',
7735: );
7736: @options = ('automatic','approval');
7737: $hashref = $processing;
7738: $defoption = 'automatic';
7739: $name = 'cancreate_emailprocess_'.$type;
7740: } elsif ($item eq 'email') {
7741: %choices = &Apache::lonlocal::texthash (
7742: any => 'Any e-mail',
7743: inst => 'Institutional only',
7744: noninst => 'Non-institutional only',
7745: custom => 'Custom restrictions',
7746: );
7747: @options = ('any','inst','noninst');
7748: my $showcustom;
7749: if (ref($emailrules) eq 'HASH') {
7750: if (keys(%{$emailrules}) > 0) {
7751: push(@options,'custom');
7752: $showcustom = 'cancreate_emailrule';
7753: if (ref($settings) eq 'HASH') {
7754: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7755: foreach my $rule (@{$settings->{'email_rule'}}) {
7756: if (exists($emailrules->{$rule})) {
7757: $hascustom ++;
7758: }
7759: }
7760: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7761: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7762: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7763: if (exists($emailrules->{$rule})) {
7764: $hascustom ++;
7765: }
7766: }
7767: }
7768: }
7769: }
7770: }
7771: }
7772: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7773: "'cancreate_emaildomain','$type'".');"';
7774: $hashref = $emailoptions;
7775: $defoption = 'any';
7776: $name = 'cancreate_emailoptions_'.$type;
7777: } elsif ($item eq 'username') {
7778: %choices = &Apache::lonlocal::texthash (
7779: all => 'Same as e-mail',
7780: first => 'Omit @domain',
7781: free => 'Free to choose',
7782: );
7783: @options = ('all','first','free');
7784: $hashref = $emailverified;
7785: $defoption = 'all';
7786: $name = 'cancreate_usernameoptions_'.$type;
7787: }
7788: foreach my $option (@options) {
7789: my $checked;
7790: if (ref($hashref) eq 'HASH') {
7791: if ($type eq '') {
7792: if (!exists($hashref->{'default'})) {
7793: if ($option eq $defoption) {
7794: $checked = ' checked="checked"';
7795: }
7796: } else {
7797: if ($hashref->{'default'} eq $option) {
7798: $checked = ' checked="checked"';
7799: }
1.160.6.40 raeburn 7800: }
7801: } else {
1.160.6.93 raeburn 7802: if (!exists($hashref->{$type})) {
7803: if ($option eq $defoption) {
7804: $checked = ' checked="checked"';
7805: }
7806: } else {
7807: if ($hashref->{$type} eq $option) {
7808: $checked = ' checked="checked"';
7809: }
1.160.6.40 raeburn 7810: }
7811: }
1.160.6.93 raeburn 7812: } elsif (($item eq 'email') && ($hascustom)) {
7813: if ($option eq 'custom') {
7814: $checked = ' checked="checked"';
7815: }
7816: } elsif ($option eq $defoption) {
7817: $checked = ' checked="checked"';
7818: }
7819: $output .= '<span class="LC_nobreak"><label>'.
7820: '<input type="radio" name="'.$name.'"'.
7821: $checked.' value="'.$option.'"'.$onclick.' />'.
7822: $choices{$option}.'</label></span><br />';
7823: if ($item eq 'email') {
7824: if ($option eq 'custom') {
7825: my $id = 'cancreate_emailrule_'.$type;
7826: my $display = 'none';
7827: if ($checked) {
7828: $display = 'inline';
7829: }
7830: my $numinrow = 2;
7831: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7832: '<legend>'.&mt('Disallow').'</legend><table>'.
7833: &user_formats_row('email',$settings,$emailrules,
7834: $emailruleorder,$numinrow,'',$type);
7835: '</table></fieldset>';
7836: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7837: my %text = &Apache::lonlocal::texthash (
7838: inst => 'must end:',
7839: noninst => 'cannot end:',
7840: );
7841: my $value;
7842: if (ref($emaildomain) eq 'HASH') {
7843: if (ref($emaildomain->{$type}) eq 'HASH') {
7844: $value = $emaildomain->{$type}->{$option};
7845: }
7846: }
7847: if ($value eq '') {
7848: $value = '@'.$intdom;
7849: }
7850: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7851: my $display = 'none';
7852: if ($checked) {
7853: $display = 'inline';
7854: }
7855: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7856: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7857: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7858: '</div>';
7859: }
1.160.6.40 raeburn 7860: }
7861: }
1.160.6.93 raeburn 7862: $output .= '</td>'."\n";
1.160.6.40 raeburn 7863: }
1.160.6.93 raeburn 7864: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 7865: return $output;
7866: }
7867:
1.160.6.5 raeburn 7868: sub captcha_choice {
1.160.6.93 raeburn 7869: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 7870: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7871: $vertext,$currver);
1.160.6.5 raeburn 7872: my %lt = &captcha_phrases();
7873: $keyentry = 'hidden';
1.160.6.98 raeburn 7874: my $colspan=2;
1.160.6.5 raeburn 7875: if ($context eq 'cancreate') {
1.160.6.34 raeburn 7876: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 7877: } elsif ($context eq 'login') {
7878: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 7879: } elsif ($context eq 'passwords') {
7880: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7881: $colspan=1;
1.160.6.5 raeburn 7882: }
7883: if (ref($settings) eq 'HASH') {
7884: if ($settings->{'captcha'}) {
7885: $checked{$settings->{'captcha'}} = ' checked="checked"';
7886: } else {
7887: $checked{'original'} = ' checked="checked"';
7888: }
7889: if ($settings->{'captcha'} eq 'recaptcha') {
7890: $pubtext = $lt{'pub'};
7891: $privtext = $lt{'priv'};
7892: $keyentry = 'text';
1.160.6.69 raeburn 7893: $vertext = $lt{'ver'};
7894: $currver = $settings->{'recaptchaversion'};
7895: if ($currver ne '2') {
7896: $currver = 1;
7897: }
1.160.6.5 raeburn 7898: }
7899: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7900: $currpub = $settings->{'recaptchakeys'}{'public'};
7901: $currpriv = $settings->{'recaptchakeys'}{'private'};
7902: }
7903: } else {
7904: $checked{'original'} = ' checked="checked"';
7905: }
1.160.6.93 raeburn 7906: my $css_class;
7907: if ($itemcount%2) {
7908: $css_class = 'LC_odd_row';
7909: }
7910: if ($customcss) {
7911: $css_class .= " $customcss";
7912: }
7913: $css_class =~ s/^\s+//;
7914: if ($css_class) {
7915: $css_class = ' class="'.$css_class.'"';
7916: }
7917: if ($rowstyle) {
7918: $css_class .= ' style="'.$rowstyle.'"';
7919: }
1.160.6.5 raeburn 7920: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 7921: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 7922: '<table><tr><td>'."\n";
7923: foreach my $option ('original','recaptcha','notused') {
7924: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
7925: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
7926: $lt{$option}.'</label></span>';
7927: unless ($option eq 'notused') {
7928: $output .= (' 'x2)."\n";
7929: }
7930: }
7931: #
7932: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
7933: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
7934: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
7935: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
7936: #
7937: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 7938: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 7939: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
7940: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
7941: $currpub.'" size="40" /></span><br />'."\n".
7942: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
7943: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 7944: $currpriv.'" size="40" /></span><br />'.
7945: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
7946: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
7947: $currver.'" size="3" /></span><br />'.
7948: '</td></tr></table>'."\n".
1.160.6.5 raeburn 7949: '</td></tr>';
7950: return $output;
7951: }
7952:
1.32 raeburn 7953: sub user_formats_row {
1.160.6.93 raeburn 7954: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 7955: my $output;
7956: my %text = (
7957: 'username' => 'new usernames',
7958: 'id' => 'IDs',
7959: );
1.160.6.93 raeburn 7960: unless ($type eq 'email') {
7961: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7962: $output = '<tr '.$css_class.'>'.
7963: '<td><span class="LC_nobreak">'.
7964: &mt("Format rules to check for $text{$type}: ").
7965: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 7966: }
1.27 raeburn 7967: my $rem;
7968: if (ref($ruleorder) eq 'ARRAY') {
7969: for (my $i=0; $i<@{$ruleorder}; $i++) {
7970: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
7971: my $rem = $i%($numinrow);
7972: if ($rem == 0) {
7973: if ($i > 0) {
7974: $output .= '</tr>';
7975: }
7976: $output .= '<tr>';
7977: }
7978: my $check = ' ';
1.39 raeburn 7979: if (ref($settings) eq 'HASH') {
7980: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
7981: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
7982: $check = ' checked="checked" ';
7983: }
1.160.6.93 raeburn 7984: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
7985: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
7986: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
7987: $check = ' checked="checked" ';
7988: }
7989: }
1.27 raeburn 7990: }
7991: }
1.160.6.93 raeburn 7992: my $name = $type.'_rule';
7993: if ($type eq 'email') {
7994: $name .= '_'.$status;
7995: }
1.27 raeburn 7996: $output .= '<td class="LC_left_item">'.
7997: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 7998: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 7999: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8000: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8001: }
8002: }
8003: $rem = @{$ruleorder}%($numinrow);
8004: }
1.160.6.93 raeburn 8005: my $colsleft;
8006: if ($rem) {
8007: $colsleft = $numinrow - $rem;
8008: }
1.27 raeburn 8009: if ($colsleft > 1 ) {
8010: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8011: ' </td>';
8012: } elsif ($colsleft == 1) {
8013: $output .= '<td class="LC_left_item"> </td>';
8014: }
1.160.6.93 raeburn 8015: $output .= '</tr></table>';
8016: unless ($type eq 'email') {
8017: $output .= '</td></tr>';
8018: }
1.27 raeburn 8019: return $output;
8020: }
8021:
1.34 raeburn 8022: sub usercreation_types {
8023: my %lt = &Apache::lonlocal::texthash (
8024: author => 'When adding a co-author',
8025: course => 'When adding a user to a course',
1.100 raeburn 8026: requestcrs => 'When requesting a course',
1.34 raeburn 8027: any => 'Any',
8028: official => 'Institutional only ',
8029: unofficial => 'Non-institutional only',
8030: none => 'None',
8031: );
8032: return %lt;
1.48 raeburn 8033: }
1.34 raeburn 8034:
1.160.6.34 raeburn 8035: sub selfcreation_types {
8036: my %lt = &Apache::lonlocal::texthash (
8037: selfcreate => 'User creates own account',
8038: any => 'Any',
8039: official => 'Institutional only ',
8040: unofficial => 'Non-institutional only',
8041: email => 'E-mail address',
8042: login => 'Institutional Login',
8043: sso => 'SSO',
8044: );
8045: }
8046:
1.28 raeburn 8047: sub authtype_names {
8048: my %lt = &Apache::lonlocal::texthash(
8049: int => 'Internal',
8050: krb4 => 'Kerberos 4',
8051: krb5 => 'Kerberos 5',
8052: loc => 'Local',
8053: );
8054: return %lt;
8055: }
8056:
8057: sub context_names {
8058: my %context_title = &Apache::lonlocal::texthash(
8059: author => 'Creating users when an Author',
8060: course => 'Creating users when in a course',
8061: domain => 'Creating users when a Domain Coordinator',
8062: );
8063: return %context_title;
8064: }
8065:
1.33 raeburn 8066: sub print_usermodification {
8067: my ($position,$dom,$settings,$rowtotal) = @_;
8068: my $numinrow = 4;
8069: my ($context,$datatable,$rowcount);
8070: if ($position eq 'top') {
8071: $rowcount = 0;
8072: $context = 'author';
8073: foreach my $role ('ca','aa') {
8074: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8075: $numinrow,$rowcount);
8076: $$rowtotal ++;
8077: $rowcount ++;
8078: }
1.160.6.37 raeburn 8079: } elsif ($position eq 'bottom') {
1.33 raeburn 8080: $context = 'course';
8081: $rowcount = 0;
8082: foreach my $role ('st','ep','ta','in','cr') {
8083: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8084: $numinrow,$rowcount);
8085: $$rowtotal ++;
8086: $rowcount ++;
8087: }
8088: }
8089: return $datatable;
8090: }
8091:
1.43 raeburn 8092: sub print_defaults {
1.160.6.40 raeburn 8093: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8094: my $rownum = 0;
1.160.6.80 raeburn 8095: my ($datatable,$css_class,$titles);
8096: unless ($position eq 'bottom') {
8097: $titles = &defaults_titles($dom);
8098: }
1.160.6.40 raeburn 8099: if ($position eq 'top') {
8100: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8101: 'datelocale_def','portal_def');
8102: my %defaults;
8103: if (ref($settings) eq 'HASH') {
8104: %defaults = %{$settings};
1.43 raeburn 8105: } else {
1.160.6.40 raeburn 8106: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8107: foreach my $item (@items) {
8108: $defaults{$item} = $domdefaults{$item};
8109: }
1.43 raeburn 8110: }
1.160.6.40 raeburn 8111: foreach my $item (@items) {
8112: if ($rownum%2) {
8113: $css_class = '';
8114: } else {
8115: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 8116: }
1.160.6.40 raeburn 8117: $datatable .= '<tr'.$css_class.'>'.
8118: '<td><span class="LC_nobreak">'.$titles->{$item}.
8119: '</span></td><td class="LC_right_item" colspan="3">';
8120: if ($item eq 'auth_def') {
8121: my @authtypes = ('internal','krb4','krb5','localauth');
8122: my %shortauth = (
8123: internal => 'int',
8124: krb4 => 'krb4',
8125: krb5 => 'krb5',
8126: localauth => 'loc'
8127: );
8128: my %authnames = &authtype_names();
8129: foreach my $auth (@authtypes) {
8130: my $checked = ' ';
8131: if ($defaults{$item} eq $auth) {
8132: $checked = ' checked="checked" ';
8133: }
8134: $datatable .= '<label><input type="radio" name="'.$item.
8135: '" value="'.$auth.'"'.$checked.'/>'.
8136: $authnames{$shortauth{$auth}}.'</label> ';
8137: }
8138: } elsif ($item eq 'timezone_def') {
8139: my $includeempty = 1;
8140: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8141: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 8142: my $includeempty = 1;
8143: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8144: } elsif ($item eq 'lang_def') {
8145: my $includeempty = 1;
8146: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 8147: } else {
1.160.6.98 raeburn 8148: my $size;
8149: if ($item eq 'portal_def') {
8150: $size = ' size="25"';
8151: }
1.160.6.80 raeburn 8152: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 8153: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 8154: }
8155: $datatable .= '</td></tr>';
8156: $rownum ++;
8157: }
1.160.6.40 raeburn 8158: } else {
1.160.6.80 raeburn 8159: my %defaults;
1.160.6.40 raeburn 8160: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 8161: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 8162: my $maxnum = @{$settings->{'inststatusorder'}};
8163: for (my $i=0; $i<$maxnum; $i++) {
8164: $css_class = $rownum%2?' class="LC_odd_row"':'';
8165: my $item = $settings->{'inststatusorder'}->[$i];
8166: my $title = $settings->{'inststatustypes'}->{$item};
8167: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8168: $datatable .= '<tr'.$css_class.'>'.
8169: '<td><span class="LC_nobreak">'.
8170: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8171: for (my $k=0; $k<=$maxnum; $k++) {
8172: my $vpos = $k+1;
8173: my $selstr;
8174: if ($k == $i) {
8175: $selstr = ' selected="selected" ';
8176: }
8177: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8178: }
8179: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8180: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8181: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 8182: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 8183: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 8184: '</span></td></tr>';
1.160.6.40 raeburn 8185: }
8186: $css_class = $rownum%2?' class="LC_odd_row"':'';
8187: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8188: $datatable .= '<tr '.$css_class.'>'.
8189: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8190: for (my $k=0; $k<=$maxnum; $k++) {
8191: my $vpos = $k+1;
8192: my $selstr;
8193: if ($k == $maxnum) {
8194: $selstr = ' selected="selected" ';
8195: }
8196: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8197: }
8198: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 8199: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 8200: ' '.&mt('(new)').
8201: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 8202: &mt('Name displayed').':'.
1.160.6.40 raeburn 8203: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8204: '</tr>'."\n";
8205: $rownum ++;
1.141 raeburn 8206: }
1.43 raeburn 8207: }
8208: }
8209: $$rowtotal += $rownum;
8210: return $datatable;
8211: }
8212:
1.160.6.5 raeburn 8213: sub get_languages_hash {
8214: my %langchoices;
8215: foreach my $id (&Apache::loncommon::languageids()) {
8216: my $code = &Apache::loncommon::supportedlanguagecode($id);
8217: if ($code ne '') {
8218: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8219: }
8220: }
8221: return %langchoices;
8222: }
8223:
1.43 raeburn 8224: sub defaults_titles {
1.141 raeburn 8225: my ($dom) = @_;
1.43 raeburn 8226: my %titles = &Apache::lonlocal::texthash (
8227: 'auth_def' => 'Default authentication type',
8228: 'auth_arg_def' => 'Default authentication argument',
8229: 'lang_def' => 'Default language',
1.54 raeburn 8230: 'timezone_def' => 'Default timezone',
1.68 raeburn 8231: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8232: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 8233: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8234: 'intauth_check' => 'Check bcrypt cost if authenticated',
8235: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8236: );
1.141 raeburn 8237: if ($dom) {
8238: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8239: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8240: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8241: $protocol = 'http' if ($protocol ne 'https');
8242: if ($uint_dom) {
8243: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8244: $uint_dom);
8245: }
8246: }
1.43 raeburn 8247: return (\%titles);
8248: }
8249:
1.160.6.97 raeburn 8250: sub print_scantron {
8251: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8252: if ($position eq 'top') {
8253: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8254: } else {
8255: return &print_scantronconfig($dom,$settings,\$rowtotal);
8256: }
8257: }
8258:
8259: sub scantron_javascript {
8260: return <<"ENDSCRIPT";
8261:
8262: <script type="text/javascript">
8263: // <![CDATA[
8264:
8265: function toggleScantron(form) {
8266: var csvfieldset = new Array();
8267: if (document.getElementById('scantroncsv_cols')) {
8268: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8269: }
8270: if (document.getElementById('scantroncsv_options')) {
8271: csvfieldset.push(document.getElementById('scantroncsv_options'));
8272: }
8273: if (csvfieldset.length) {
8274: if (document.getElementById('scantronconfcsv')) {
8275: var scantroncsv = document.getElementById('scantronconfcsv');
8276: if (scantroncsv.checked) {
8277: for (var i=0; i<csvfieldset.length; i++) {
8278: csvfieldset[i].style.display = 'block';
8279: }
8280: } else {
8281: for (var i=0; i<csvfieldset.length; i++) {
8282: csvfieldset[i].style.display = 'none';
8283: }
8284: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8285: if (csvselects.length) {
8286: for (var j=0; j<csvselects.length; j++) {
8287: csvselects[j].selectedIndex = 0;
8288: }
8289: }
8290: }
8291: }
8292: }
8293: return;
8294: }
8295: // ]]>
8296: </script>
8297:
8298: ENDSCRIPT
8299:
8300: }
8301:
1.46 raeburn 8302: sub print_scantronformat {
8303: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8304: my $itemcount = 1;
1.60 raeburn 8305: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8306: %confhash);
1.46 raeburn 8307: my $switchserver = &check_switchserver($dom,$confname);
8308: my %lt = &Apache::lonlocal::texthash (
1.95 www 8309: default => 'Default bubblesheet format file error',
8310: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8311: );
8312: my %scantronfiles = (
8313: default => 'default.tab',
8314: custom => 'custom.tab',
8315: );
8316: foreach my $key (keys(%scantronfiles)) {
8317: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8318: .$scantronfiles{$key};
8319: }
8320: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8321: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8322: if (!$switchserver) {
8323: my $servadm = $r->dir_config('lonAdmEMail');
8324: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8325: if ($configuserok eq 'ok') {
8326: if ($author_ok eq 'ok') {
8327: my %legacyfile = (
1.160.6.97 raeburn 8328: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8329: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8330: );
8331: my %md5chk;
8332: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8333: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8334: chomp($md5chk{$type});
1.46 raeburn 8335: }
8336: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8337: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 8338: ($scantronurls{$type},my $error) =
1.46 raeburn 8339: &legacy_scantronformat($r,$dom,$confname,
8340: $type,$legacyfile{$type},
8341: $scantronurls{$type},
8342: $scantronfiles{$type});
1.60 raeburn 8343: if ($error ne '') {
8344: $error{$type} = $error;
8345: }
8346: }
8347: if (keys(%error) == 0) {
8348: $is_custom = 1;
1.160.6.97 raeburn 8349: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8350: $scantronurls{'custom'};
1.160.6.97 raeburn 8351: my $putresult =
1.60 raeburn 8352: &Apache::lonnet::put_dom('configuration',
8353: \%confhash,$dom);
8354: if ($putresult ne 'ok') {
1.160.6.97 raeburn 8355: $error{'custom'} =
1.60 raeburn 8356: '<span class="LC_error">'.
8357: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8358: }
1.46 raeburn 8359: }
8360: } else {
1.60 raeburn 8361: ($scantronurls{'default'},my $error) =
1.46 raeburn 8362: &legacy_scantronformat($r,$dom,$confname,
8363: 'default',$legacyfile{'default'},
8364: $scantronurls{'default'},
8365: $scantronfiles{'default'});
1.60 raeburn 8366: if ($error eq '') {
8367: $confhash{'scantron'}{'scantronformat'} = '';
8368: my $putresult =
8369: &Apache::lonnet::put_dom('configuration',
8370: \%confhash,$dom);
8371: if ($putresult ne 'ok') {
8372: $error{'default'} =
8373: '<span class="LC_error">'.
8374: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8375: }
8376: } else {
8377: $error{'default'} = $error;
8378: }
1.46 raeburn 8379: }
8380: }
8381: }
8382: } else {
1.95 www 8383: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8384: }
8385: }
8386: if (ref($settings) eq 'HASH') {
8387: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8388: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8389: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8390: $scantronurl = '';
8391: } else {
8392: $scantronurl = $settings->{'scantronformat'};
8393: }
8394: $is_custom = 1;
8395: } else {
8396: $scantronurl = $scantronurls{'default'};
8397: }
8398: } else {
1.60 raeburn 8399: if ($is_custom) {
8400: $scantronurl = $scantronurls{'custom'};
8401: } else {
8402: $scantronurl = $scantronurls{'default'};
8403: }
1.46 raeburn 8404: }
8405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8406: $datatable .= '<tr'.$css_class.'>';
8407: if (!$is_custom) {
1.65 raeburn 8408: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8409: '<span class="LC_nobreak">';
1.46 raeburn 8410: if ($scantronurl) {
1.160.6.21 raeburn 8411: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8412: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8413: } else {
8414: $datatable = &mt('File unavailable for display');
8415: }
1.65 raeburn 8416: $datatable .= '</span></td>';
1.60 raeburn 8417: if (keys(%error) == 0) {
8418: $datatable .= '<td valign="bottom">';
8419: if (!$switchserver) {
8420: $datatable .= &mt('Upload:').'<br />';
8421: }
8422: } else {
8423: my $errorstr;
8424: foreach my $key (sort(keys(%error))) {
8425: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8426: }
8427: $datatable .= '<td>'.$errorstr;
8428: }
1.46 raeburn 8429: } else {
8430: if (keys(%error) > 0) {
8431: my $errorstr;
8432: foreach my $key (sort(keys(%error))) {
8433: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8434: }
1.60 raeburn 8435: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8436: } elsif ($scantronurl) {
1.160.6.26 raeburn 8437: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 8438: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8439: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 8440: $link.
8441: '<label><input type="checkbox" name="scantronformat_del"'.
8442: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8443: '<td><span class="LC_nobreak"> '.
8444: &mt('Replace:').'</span><br />';
1.46 raeburn 8445: }
8446: }
8447: if (keys(%error) == 0) {
8448: if ($switchserver) {
8449: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8450: } else {
1.65 raeburn 8451: $datatable .='<span class="LC_nobreak"> '.
8452: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8453: }
8454: }
8455: $datatable .= '</td></tr>';
8456: $$rowtotal ++;
8457: return $datatable;
8458: }
8459:
8460: sub legacy_scantronformat {
8461: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8462: my ($url,$error);
8463: my @statinfo = &Apache::lonnet::stat_file($newurl);
8464: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8465: (my $result,$url) =
8466: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8467: '','',$newfile);
8468: if ($result ne 'ok') {
1.130 raeburn 8469: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8470: }
8471: }
8472: return ($url,$error);
8473: }
1.43 raeburn 8474:
1.160.6.97 raeburn 8475: sub print_scantronconfig {
8476: my ($dom,$settings,$rowtotal) = @_;
8477: my $itemcount = 2;
8478: my $is_checked = ' checked="checked"';
8479: my %optionson = (
8480: hdr => ' checked="checked"',
8481: pad => ' checked="checked"',
8482: rem => ' checked="checked"',
8483: );
8484: my %optionsoff = (
8485: hdr => '',
8486: pad => '',
8487: rem => '',
8488: );
8489: my $currcsvsty = 'none';
8490: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8491: my @fields = &scantroncsv_fields();
8492: my %titles = &scantronconfig_titles();
8493: if (ref($settings) eq 'HASH') {
8494: if (ref($settings->{config}) eq 'HASH') {
8495: if ($settings->{config}->{dat}) {
8496: $checked{'dat'} = $is_checked;
8497: }
8498: if (ref($settings->{config}->{csv}) eq 'HASH') {
8499: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8500: %csvfields = %{$settings->{config}->{csv}->{fields}};
8501: if (keys(%csvfields) > 0) {
8502: $checked{'csv'} = $is_checked;
8503: $currcsvsty = 'block';
8504: }
8505: }
8506: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8507: %csvoptions = %{$settings->{config}->{csv}->{options}};
8508: foreach my $option (keys(%optionson)) {
8509: unless ($csvoptions{$option}) {
8510: $optionsoff{$option} = $optionson{$option};
8511: $optionson{$option} = '';
8512: }
8513: }
8514: }
8515: }
8516: } else {
8517: $checked{'dat'} = $is_checked;
8518: }
8519: } else {
8520: $checked{'dat'} = $is_checked;
8521: }
8522: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8523: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8524: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8525: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8526: foreach my $item ('dat','csv') {
8527: my $id;
8528: if ($item eq 'csv') {
8529: $id = 'id="scantronconfcsv" ';
8530: }
8531: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8532: $titles{$item}.'</label>'.(' 'x3);
8533: if ($item eq 'csv') {
8534: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8535: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8536: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8537: foreach my $col (@fields) {
8538: my $selnone;
8539: if ($csvfields{$col} eq '') {
8540: $selnone = ' selected="selected"';
8541: }
8542: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8543: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8544: '<option value=""'.$selnone.'></option>';
8545: for (my $i=0; $i<20; $i++) {
8546: my $shown = $i+1;
8547: my $sel;
8548: unless ($selnone) {
8549: if (exists($csvfields{$col})) {
8550: if ($csvfields{$col} == $i) {
8551: $sel = ' selected="selected"';
8552: }
8553: }
8554: }
8555: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8556: }
8557: $datatable .= '</select></td></tr>';
8558: }
8559: $datatable .= '</table></fieldset>'.
8560: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8561: '<legend>'.&mt('CSV Options').'</legend>';
8562: foreach my $option ('hdr','pad','rem') {
8563: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8564: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8565: &mt('Yes').'</label>'.(' 'x2)."\n".
8566: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8567: }
8568: $datatable .= '</fieldset>';
8569: $itemcount ++;
8570: }
8571: }
8572: $datatable .= '</td></tr>';
8573: $$rowtotal ++;
8574: return $datatable;
8575: }
8576:
8577: sub scantronconfig_titles {
8578: return &Apache::lonlocal::texthash(
8579: dat => 'Standard format (.dat)',
8580: csv => 'Comma separated values (.csv)',
8581: hdr => 'Remove first line in file (contains column titles)',
8582: pad => 'Prepend 0s to PaperID',
8583: rem => 'Remove leading spaces (except Question Response columns)',
8584: CODE => 'CODE',
8585: ID => 'Student ID',
8586: PaperID => 'Paper ID',
8587: FirstName => 'First Name',
8588: LastName => 'Last Name',
8589: FirstQuestion => 'First Question Response',
8590: Section => 'Section',
8591: );
8592: }
8593:
8594: sub scantroncsv_fields {
8595: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8596: }
8597:
1.49 raeburn 8598: sub print_coursecategories {
1.57 raeburn 8599: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8600: my $datatable;
8601: if ($position eq 'top') {
1.160.6.42 raeburn 8602: my (%checked);
8603: my @catitems = ('unauth','auth');
8604: my @cattypes = ('std','domonly','codesrch','none');
8605: $checked{'unauth'} = 'std';
8606: $checked{'auth'} = 'std';
8607: if (ref($settings) eq 'HASH') {
8608: foreach my $type (@cattypes) {
8609: if ($type eq $settings->{'unauth'}) {
8610: $checked{'unauth'} = $type;
8611: }
8612: if ($type eq $settings->{'auth'}) {
8613: $checked{'auth'} = $type;
8614: }
8615: }
8616: }
8617: my %lt = &Apache::lonlocal::texthash (
8618: unauth => 'Catalog type for unauthenticated users',
8619: auth => 'Catalog type for authenticated users',
8620: none => 'No catalog',
8621: std => 'Standard catalog',
8622: domonly => 'Domain-only catalog',
8623: codesrch => "Code search form",
8624: );
8625: my $itemcount = 0;
8626: foreach my $item (@catitems) {
8627: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8628: $datatable .= '<tr '.$css_class.'>'.
8629: '<td>'.$lt{$item}.'</td>'.
8630: '<td class="LC_right_item"><span class="LC_nobreak">';
8631: foreach my $type (@cattypes) {
8632: my $ischecked;
8633: if ($checked{$item} eq $type) {
8634: $ischecked=' checked="checked"';
8635: }
8636: $datatable .= '<label>'.
8637: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8638: ' />'.$lt{$type}.'</label> ';
8639: }
1.160.6.87 raeburn 8640: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 8641: $itemcount ++;
8642: }
8643: $$rowtotal += $itemcount;
8644: } elsif ($position eq 'middle') {
1.57 raeburn 8645: my $toggle_cats_crs = ' ';
8646: my $toggle_cats_dom = ' checked="checked" ';
8647: my $can_cat_crs = ' ';
8648: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8649: my $toggle_catscomm_comm = ' ';
8650: my $toggle_catscomm_dom = ' checked="checked" ';
8651: my $can_catcomm_comm = ' ';
8652: my $can_catcomm_dom = ' checked="checked" ';
8653:
1.57 raeburn 8654: if (ref($settings) eq 'HASH') {
8655: if ($settings->{'togglecats'} eq 'crs') {
8656: $toggle_cats_crs = $toggle_cats_dom;
8657: $toggle_cats_dom = ' ';
8658: }
8659: if ($settings->{'categorize'} eq 'crs') {
8660: $can_cat_crs = $can_cat_dom;
8661: $can_cat_dom = ' ';
8662: }
1.120 raeburn 8663: if ($settings->{'togglecatscomm'} eq 'comm') {
8664: $toggle_catscomm_comm = $toggle_catscomm_dom;
8665: $toggle_catscomm_dom = ' ';
8666: }
8667: if ($settings->{'categorizecomm'} eq 'comm') {
8668: $can_catcomm_comm = $can_catcomm_dom;
8669: $can_catcomm_dom = ' ';
8670: }
1.57 raeburn 8671: }
8672: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 8673: togglecats => 'Show/Hide a course in catalog',
8674: togglecatscomm => 'Show/Hide a community in catalog',
8675: categorize => 'Assign a category to a course',
8676: categorizecomm => 'Assign a category to a community',
1.57 raeburn 8677: );
8678: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 8679: dom => 'Set in Domain',
8680: crs => 'Set in Course',
8681: comm => 'Set in Community',
1.57 raeburn 8682: );
8683: $datatable = '<tr class="LC_odd_row">'.
8684: '<td>'.$title{'togglecats'}.'</td>'.
8685: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8686: '<input type="radio" name="togglecats"'.
8687: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8688: '<label><input type="radio" name="togglecats"'.
8689: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8690: '</tr><tr>'.
8691: '<td>'.$title{'categorize'}.'</td>'.
8692: '<td class="LC_right_item"><span class="LC_nobreak">'.
8693: '<label><input type="radio" name="categorize"'.
8694: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8695: '<label><input type="radio" name="categorize"'.
8696: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8697: '</tr><tr class="LC_odd_row">'.
8698: '<td>'.$title{'togglecatscomm'}.'</td>'.
8699: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8700: '<input type="radio" name="togglecatscomm"'.
8701: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8702: '<label><input type="radio" name="togglecatscomm"'.
8703: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8704: '</tr><tr>'.
8705: '<td>'.$title{'categorizecomm'}.'</td>'.
8706: '<td class="LC_right_item"><span class="LC_nobreak">'.
8707: '<label><input type="radio" name="categorizecomm"'.
8708: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8709: '<label><input type="radio" name="categorizecomm"'.
8710: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 8711: '</tr>';
1.120 raeburn 8712: $$rowtotal += 4;
1.57 raeburn 8713: } else {
8714: my $css_class;
8715: my $itemcount = 1;
8716: my $cathash;
8717: if (ref($settings) eq 'HASH') {
8718: $cathash = $settings->{'cats'};
8719: }
8720: if (ref($cathash) eq 'HASH') {
8721: my (@cats,@trails,%allitems,%idx,@jsarray);
8722: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8723: \%allitems,\%idx,\@jsarray);
8724: my $maxdepth = scalar(@cats);
8725: my $colattrib = '';
8726: if ($maxdepth > 2) {
8727: $colattrib = ' colspan="2" ';
8728: }
8729: my @path;
8730: if (@cats > 0) {
8731: if (ref($cats[0]) eq 'ARRAY') {
8732: my $numtop = @{$cats[0]};
8733: my $maxnum = $numtop;
1.120 raeburn 8734: my %default_names = (
8735: instcode => &mt('Official courses'),
8736: communities => &mt('Communities'),
8737: );
8738:
8739: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8740: ($cathash->{'instcode::0'} eq '') ||
8741: (!grep(/^communities$/,@{$cats[0]})) ||
8742: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 8743: $maxnum ++;
8744: }
8745: my $lastidx;
8746: for (my $i=0; $i<$numtop; $i++) {
8747: my $parent = $cats[0][$i];
8748: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8749: my $item = &escape($parent).'::0';
8750: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8751: $lastidx = $idx{$item};
8752: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8753: .'<select name="'.$item.'"'.$chgstr.'>';
8754: for (my $k=0; $k<=$maxnum; $k++) {
8755: my $vpos = $k+1;
8756: my $selstr;
8757: if ($k == $i) {
8758: $selstr = ' selected="selected" ';
8759: }
8760: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8761: }
1.160.6.29 raeburn 8762: $datatable .= '</select></span></td><td>';
1.120 raeburn 8763: if ($parent eq 'instcode' || $parent eq 'communities') {
8764: $datatable .= '<span class="LC_nobreak">'
8765: .$default_names{$parent}.'</span>';
8766: if ($parent eq 'instcode') {
8767: $datatable .= '<br /><span class="LC_nobreak">('
8768: .&mt('with institutional codes')
8769: .')</span></td><td'.$colattrib.'>';
8770: } else {
8771: $datatable .= '<table><tr><td>';
8772: }
8773: $datatable .= '<span class="LC_nobreak">'
8774: .'<label><input type="radio" name="'
8775: .$parent.'" value="1" checked="checked" />'
8776: .&mt('Display').'</label>';
8777: if ($parent eq 'instcode') {
8778: $datatable .= ' ';
8779: } else {
8780: $datatable .= '</span></td></tr><tr><td>'
8781: .'<span class="LC_nobreak">';
8782: }
8783: $datatable .= '<label><input type="radio" name="'
8784: .$parent.'" value="0" />'
8785: .&mt('Do not display').'</label></span>';
8786: if ($parent eq 'communities') {
8787: $datatable .= '</td></tr></table>';
8788: }
8789: $datatable .= '</td>';
1.57 raeburn 8790: } else {
8791: $datatable .= $parent
1.160.6.29 raeburn 8792: .' <span class="LC_nobreak"><label>'
8793: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8794: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8795: }
8796: my $depth = 1;
8797: push(@path,$parent);
8798: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8799: pop(@path);
8800: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8801: $itemcount ++;
8802: }
1.48 raeburn 8803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8804: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8805: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8806: for (my $k=0; $k<=$maxnum; $k++) {
8807: my $vpos = $k+1;
8808: my $selstr;
1.57 raeburn 8809: if ($k == $numtop) {
1.48 raeburn 8810: $selstr = ' selected="selected" ';
8811: }
8812: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8813: }
1.59 bisitz 8814: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8815: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8816: .'</tr>'."\n";
1.48 raeburn 8817: $itemcount ++;
1.120 raeburn 8818: foreach my $default ('instcode','communities') {
8819: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8820: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8821: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8822: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8823: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8824: for (my $k=0; $k<=$maxnum; $k++) {
8825: my $vpos = $k+1;
8826: my $selstr;
8827: if ($k == $maxnum) {
8828: $selstr = ' selected="selected" ';
8829: }
8830: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8831: }
1.120 raeburn 8832: $datatable .= '</select></span></td>'.
8833: '<td><span class="LC_nobreak">'.
8834: $default_names{$default}.'</span>';
8835: if ($default eq 'instcode') {
8836: $datatable .= '<br /><span class="LC_nobreak">('
8837: .&mt('with institutional codes').')</span>';
8838: }
8839: $datatable .= '</td>'
8840: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8841: .&mt('Display').'</label> '
8842: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8843: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8844: }
8845: }
8846: }
1.57 raeburn 8847: } else {
8848: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8849: }
8850: } else {
1.160.6.87 raeburn 8851: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8852: .&initialize_categories($itemcount);
1.48 raeburn 8853: }
1.57 raeburn 8854: $$rowtotal += $itemcount;
1.48 raeburn 8855: }
8856: return $datatable;
8857: }
8858:
1.69 raeburn 8859: sub print_serverstatuses {
8860: my ($dom,$settings,$rowtotal) = @_;
8861: my $datatable;
8862: my @pages = &serverstatus_pages();
8863: my (%namedaccess,%machineaccess);
8864: foreach my $type (@pages) {
8865: $namedaccess{$type} = '';
8866: $machineaccess{$type}= '';
8867: }
8868: if (ref($settings) eq 'HASH') {
8869: foreach my $type (@pages) {
8870: if (exists($settings->{$type})) {
8871: if (ref($settings->{$type}) eq 'HASH') {
8872: foreach my $key (keys(%{$settings->{$type}})) {
8873: if ($key eq 'namedusers') {
8874: $namedaccess{$type} = $settings->{$type}->{$key};
8875: } elsif ($key eq 'machines') {
8876: $machineaccess{$type} = $settings->{$type}->{$key};
8877: }
8878: }
8879: }
8880: }
8881: }
8882: }
1.81 raeburn 8883: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8884: my $rownum = 0;
8885: my $css_class;
8886: foreach my $type (@pages) {
8887: $rownum ++;
8888: $css_class = $rownum%2?' class="LC_odd_row"':'';
8889: $datatable .= '<tr'.$css_class.'>'.
8890: '<td><span class="LC_nobreak">'.
8891: $titles->{$type}.'</span></td>'.
8892: '<td class="LC_left_item">'.
8893: '<input type="text" name="'.$type.'_namedusers" '.
8894: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
8895: '<td class="LC_right_item">'.
8896: '<span class="LC_nobreak">'.
8897: '<input type="text" name="'.$type.'_machines" '.
8898: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 8899: '</span></td></tr>'."\n";
1.69 raeburn 8900: }
8901: $$rowtotal += $rownum;
8902: return $datatable;
8903: }
8904:
8905: sub serverstatus_pages {
8906: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 8907: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 8908: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 8909: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 8910: }
8911:
1.160.6.40 raeburn 8912: sub defaults_javascript {
8913: my ($settings) = @_;
1.160.6.98 raeburn 8914: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 8915: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8916: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
8917: if ($maxnum eq '') {
8918: $maxnum = 0;
8919: }
8920: $maxnum ++;
1.160.6.51 raeburn 8921: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 8922: return <<"ENDSCRIPT";
8923: <script type="text/javascript">
8924: // <![CDATA[
8925: function reorderTypes(form,caller) {
8926: var changedVal;
8927: $jstext
8928: var newpos = 'addinststatus_pos';
8929: var current = new Array;
8930: var maxh = $maxnum;
8931: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
8932: var oldVal;
8933: if (caller == newpos) {
8934: changedVal = newitemVal;
8935: } else {
8936: var curritem = 'inststatus_pos_'+caller;
8937: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
8938: current[newitemVal] = newpos;
8939: }
8940: for (var i=0; i<inststatuses.length; i++) {
8941: if (inststatuses[i] != caller) {
8942: var elementName = 'inststatus_pos_'+inststatuses[i];
8943: if (form.elements[elementName]) {
8944: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
8945: current[currVal] = elementName;
8946: }
8947: }
8948: }
8949: for (var j=0; j<maxh; j++) {
8950: if (current[j] == undefined) {
8951: oldVal = j;
8952: }
8953: }
8954: if (oldVal < changedVal) {
8955: for (var k=oldVal+1; k<=changedVal ; k++) {
8956: var elementName = current[k];
8957: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
8958: }
8959: } else {
8960: for (var k=changedVal; k<oldVal; k++) {
8961: var elementName = current[k];
8962: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
8963: }
8964: }
8965: return;
8966: }
8967:
8968: // ]]>
8969: </script>
8970:
8971: ENDSCRIPT
8972: }
8973: }
8974:
1.160.6.98 raeburn 8975: sub passwords_javascript {
1.160.6.99 raeburn 8976: my %intalert = &Apache::lonlocal::texthash (
8977: 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.',
8978: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
8979: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
8980: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
8981: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
8982: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
8983: );
8984: &js_escape(\%intalert);
8985: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 8986: my $intauthjs = <<"ENDSCRIPT";
8987:
8988: function warnIntAuth(field) {
8989: if (field.name == 'intauth_check') {
8990: if (field.value == '2') {
1.160.6.99 raeburn 8991: alert('$intalert{authcheck}');
1.160.6.98 raeburn 8992: }
8993: }
8994: if (field.name == 'intauth_cost') {
8995: field.value.replace(/\s/g,'');
8996: if (field.value != '') {
8997: var regexdigit=/^\\d+\$/;
8998: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 8999: alert('$intalert{authcost}');
9000: }
9001: }
9002: }
9003: return;
9004: }
9005:
9006: function warnIntPass(field) {
9007: field.value.replace(/^\s+/,'');
9008: field.value.replace(/\s+\$/,'');
9009: var regexdigit=/^\\d+\$/;
9010: if (field.name == 'passwords_min') {
9011: if (field.value == '') {
9012: alert('$intalert{passmin}');
9013: field.value = '$defmin';
9014: } else {
9015: if (!regexdigit.test(field.value)) {
9016: alert('$intalert{passmin}');
9017: field.value = '$defmin';
9018: }
9019: var minval = parseInt(field.value,10);
9020: if (minval < $defmin) {
9021: alert('$intalert{passmin}');
9022: field.value = '$defmin';
9023: }
9024: }
9025: } else {
9026: if (field.value == '0') {
9027: field.value = '';
9028: }
9029: if (field.value != '') {
9030: if (field.name == 'passwords_expire') {
9031: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
9032: if (!regexpposnum.test(field.value)) {
9033: alert('$intalert{passexp}');
9034: field.value = '';
9035: } else {
9036: var expval = parseFloat(field.value);
9037: if (expval == 0) {
9038: alert('$intalert{passexp}');
9039: field.value = '';
9040: }
9041: }
9042: } else {
9043: if (!regexdigit.test(field.value)) {
9044: if (field.name == 'passwords_max') {
9045: alert('$intalert{passmax}');
9046: } else {
9047: if (field.name == 'passwords_numsaved') {
9048: alert('$intalert{passnum}');
9049: }
9050: }
1.160.6.104 raeburn 9051: field.value = '';
1.160.6.99 raeburn 9052: }
1.160.6.98 raeburn 9053: }
9054: }
9055: }
9056: return;
9057: }
9058:
9059: ENDSCRIPT
9060: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9061: }
9062:
1.49 raeburn 9063: sub coursecategories_javascript {
9064: my ($settings) = @_;
1.57 raeburn 9065: my ($output,$jstext,$cathash);
1.49 raeburn 9066: if (ref($settings) eq 'HASH') {
1.57 raeburn 9067: $cathash = $settings->{'cats'};
9068: }
9069: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9070: my (@cats,@jsarray,%idx);
1.57 raeburn 9071: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9072: if (@jsarray > 0) {
9073: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9074: for (my $i=0; $i<@jsarray; $i++) {
9075: if (ref($jsarray[$i]) eq 'ARRAY') {
9076: my $catstr = join('","',@{$jsarray[$i]});
9077: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9078: }
9079: }
9080: }
9081: } else {
9082: $jstext = ' var categories = Array(1);'."\n".
9083: ' categories[0] = Array("instcode_pos");'."\n";
9084: }
1.160.6.42 raeburn 9085: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9086: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 9087: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9088: &js_escape(\$instcode_reserved);
9089: &js_escape(\$communities_reserved);
9090: &js_escape(\$choose_again);
1.49 raeburn 9091: $output = <<"ENDSCRIPT";
9092: <script type="text/javascript">
1.109 raeburn 9093: // <![CDATA[
1.49 raeburn 9094: function reorderCats(form,parent,item,idx) {
9095: var changedVal;
9096: $jstext
9097: var newpos = 'addcategory_pos';
9098: if (parent == '') {
9099: var has_instcode = 0;
9100: var maxtop = categories[idx].length;
9101: for (var j=0; j<maxtop; j++) {
9102: if (categories[idx][j] == 'instcode::0') {
9103: has_instcode == 1;
9104: }
9105: }
9106: if (has_instcode == 0) {
9107: categories[idx][maxtop] = 'instcode_pos';
9108: }
9109: } else {
9110: newpos += '_'+parent;
9111: }
9112: var maxh = 1 + categories[idx].length;
9113: var current = new Array;
9114: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9115: if (item == newpos) {
9116: changedVal = newitemVal;
9117: } else {
9118: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9119: current[newitemVal] = newpos;
9120: }
9121: for (var i=0; i<categories[idx].length; i++) {
9122: var elementName = categories[idx][i];
9123: if (elementName != item) {
9124: if (form.elements[elementName]) {
9125: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9126: current[currVal] = elementName;
9127: }
9128: }
9129: }
9130: var oldVal;
9131: for (var j=0; j<maxh; j++) {
9132: if (current[j] == undefined) {
9133: oldVal = j;
9134: }
9135: }
9136: if (oldVal < changedVal) {
9137: for (var k=oldVal+1; k<=changedVal ; k++) {
9138: var elementName = current[k];
9139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9140: }
9141: } else {
9142: for (var k=changedVal; k<oldVal; k++) {
9143: var elementName = current[k];
9144: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9145: }
9146: }
9147: return;
9148: }
1.120 raeburn 9149:
9150: function categoryCheck(form) {
9151: if (form.elements['addcategory_name'].value == 'instcode') {
9152: alert('$instcode_reserved\\n$choose_again');
9153: return false;
9154: }
9155: if (form.elements['addcategory_name'].value == 'communities') {
9156: alert('$communities_reserved\\n$choose_again');
9157: return false;
9158: }
9159: return true;
9160: }
9161:
1.109 raeburn 9162: // ]]>
1.49 raeburn 9163: </script>
9164:
9165: ENDSCRIPT
9166: return $output;
9167: }
9168:
1.48 raeburn 9169: sub initialize_categories {
9170: my ($itemcount) = @_;
1.120 raeburn 9171: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 9172: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 9173: instcode => 'Official courses (with institutional codes)',
9174: communities => 'Communities',
9175: );
9176: my $select0 = ' selected="selected"';
9177: my $select1 = '';
9178: foreach my $default ('instcode','communities') {
9179: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 9180: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 9181: if ($default eq 'communities') {
9182: $select1 = $select0;
9183: $select0 = '';
9184: }
9185: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9186: .'<select name="'.$default.'_pos">'
9187: .'<option value="0"'.$select0.'>1</option>'
9188: .'<option value="1"'.$select1.'>2</option>'
9189: .'<option value="2">3</option></select> '
9190: .$default_names{$default}
9191: .'</span></td><td><span class="LC_nobreak">'
9192: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9193: .&mt('Display').'</label> <label>'
9194: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9195: .'</label></span></td></tr>';
1.120 raeburn 9196: $itemcount ++;
9197: }
1.48 raeburn 9198: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9199: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9200: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9201: .'<select name="addcategory_pos"'.$chgstr.'>'
9202: .'<option value="0">1</option>'
9203: .'<option value="1">2</option>'
9204: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 9205: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 9206: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9207: .'</td></tr>';
1.48 raeburn 9208: return $datatable;
9209: }
9210:
9211: sub build_category_rows {
1.49 raeburn 9212: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9213: my ($text,$name,$item,$chgstr);
1.48 raeburn 9214: if (ref($cats) eq 'ARRAY') {
9215: my $maxdepth = scalar(@{$cats});
9216: if (ref($cats->[$depth]) eq 'HASH') {
9217: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9218: my $numchildren = @{$cats->[$depth]{$parent}};
9219: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 9220: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9221: my ($idxnum,$parent_name,$parent_item);
9222: my $higher = $depth - 1;
9223: if ($higher == 0) {
9224: $parent_name = &escape($parent).'::'.$higher;
9225: } else {
9226: if (ref($path) eq 'ARRAY') {
9227: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9228: }
9229: }
9230: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9231: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9232: if ($j < $numchildren) {
1.48 raeburn 9233: $name = $cats->[$depth]{$parent}[$j];
9234: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9235: $idxnum = $idx->{$item};
9236: } else {
9237: $name = $parent_name;
9238: $item = $parent_item;
1.48 raeburn 9239: }
1.49 raeburn 9240: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9241: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9242: for (my $i=0; $i<=$numchildren; $i++) {
9243: my $vpos = $i+1;
9244: my $selstr;
9245: if ($j == $i) {
9246: $selstr = ' selected="selected" ';
9247: }
9248: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9249: }
9250: $text .= '</select> ';
9251: if ($j < $numchildren) {
9252: my $deeper = $depth+1;
9253: $text .= $name.' '
9254: .'<label><input type="checkbox" name="deletecategory" value="'
9255: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9256: if(ref($path) eq 'ARRAY') {
9257: push(@{$path},$name);
1.49 raeburn 9258: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9259: pop(@{$path});
9260: }
9261: } else {
1.160.6.87 raeburn 9262: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9263: if ($j == $numchildren) {
9264: $text .= $name;
9265: } else {
9266: $text .= $item;
9267: }
9268: $text .= '" value="" />';
9269: }
9270: $text .= '</td></tr>';
9271: }
9272: $text .= '</table></td>';
9273: } else {
9274: my $higher = $depth-1;
9275: if ($higher == 0) {
9276: $name = &escape($parent).'::'.$higher;
9277: } else {
9278: if (ref($path) eq 'ARRAY') {
9279: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9280: }
9281: }
9282: my $colspan;
9283: if ($parent ne 'instcode') {
9284: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 9285: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9286: }
9287: }
9288: }
9289: }
9290: return $text;
9291: }
9292:
1.33 raeburn 9293: sub modifiable_userdata_row {
1.160.6.93 raeburn 9294: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9295: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 9296: my ($role,$rolename,$statustype);
9297: $role = $item;
1.160.6.34 raeburn 9298: if ($context eq 'cancreate') {
1.160.6.93 raeburn 9299: if ($item =~ /^(emailusername)_(.+)$/) {
9300: $role = $1;
9301: $statustype = $2;
1.160.6.35 raeburn 9302: if (ref($usertypes) eq 'HASH') {
9303: if ($usertypes->{$statustype}) {
9304: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9305: } else {
9306: $rolename = &mt('Data provided by user');
9307: }
9308: }
1.160.6.34 raeburn 9309: }
9310: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9311: if (ref($usertypes) eq 'HASH') {
9312: $rolename = $usertypes->{$role};
9313: } else {
9314: $rolename = $role;
9315: }
1.33 raeburn 9316: } else {
1.63 raeburn 9317: if ($role eq 'cr') {
9318: $rolename = &mt('Custom role');
9319: } else {
9320: $rolename = &Apache::lonnet::plaintext($role);
9321: }
1.33 raeburn 9322: }
1.160.6.34 raeburn 9323: my (@fields,%fieldtitles);
9324: if (ref($fieldsref) eq 'ARRAY') {
9325: @fields = @{$fieldsref};
9326: } else {
9327: @fields = ('lastname','firstname','middlename','generation',
9328: 'permanentemail','id');
9329: }
9330: if ((ref($titlesref) eq 'HASH')) {
9331: %fieldtitles = %{$titlesref};
9332: } else {
9333: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9334: }
1.33 raeburn 9335: my $output;
1.160.6.93 raeburn 9336: my $css_class;
9337: if ($rowcount%2) {
9338: $css_class = 'LC_odd_row';
9339: }
9340: if ($customcss) {
9341: $css_class .= " $customcss";
9342: }
9343: $css_class =~ s/^\s+//;
9344: if ($css_class) {
9345: $css_class = ' class="'.$css_class.'"';
9346: }
9347: if ($rowstyle) {
9348: $css_class .= ' style="'.$rowstyle.'"';
9349: }
9350: if ($rowid) {
9351: $rowid = ' id="'.$rowid.'"';
9352: }
9353:
9354: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9355: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9356: '<td class="LC_left_item" colspan="2"><table>';
9357: my $rem;
9358: my %checks;
9359: if (ref($settings) eq 'HASH') {
9360: if (ref($settings->{$context}) eq 'HASH') {
9361: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 9362: my $hashref = $settings->{$context}->{$role};
9363: if ($role eq 'emailusername') {
9364: if ($statustype) {
9365: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9366: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 9367: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 9368: foreach my $field (@fields) {
9369: if ($hashref->{$field}) {
9370: $checks{$field} = $hashref->{$field};
9371: }
9372: }
9373: }
9374: }
9375: }
9376: } else {
9377: if (ref($hashref) eq 'HASH') {
9378: foreach my $field (@fields) {
9379: if ($hashref->{$field}) {
9380: $checks{$field} = ' checked="checked" ';
9381: }
9382: }
1.33 raeburn 9383: }
9384: }
9385: }
9386: }
9387: }
1.160.6.93 raeburn 9388:
9389: my $total = scalar(@fields);
9390: for (my $i=0; $i<$total; $i++) {
9391: $rem = $i%($numinrow);
1.33 raeburn 9392: if ($rem == 0) {
9393: if ($i > 0) {
9394: $output .= '</tr>';
9395: }
9396: $output .= '<tr>';
9397: }
9398: my $check = ' ';
1.160.6.35 raeburn 9399: unless ($role eq 'emailusername') {
9400: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 9401: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 9402: } else {
9403: if ($role eq 'st') {
9404: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 9405: $check = ' checked="checked" ';
1.160.6.35 raeburn 9406: }
1.33 raeburn 9407: }
9408: }
9409: }
9410: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 9411: '<span class="LC_nobreak">';
9412: if ($role eq 'emailusername') {
9413: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9414: $checks{$fields[$i]} = 'omit';
9415: }
9416: foreach my $option ('required','optional','omit') {
9417: my $checked='';
9418: if ($checks{$fields[$i]} eq $option) {
9419: $checked='checked="checked" ';
9420: }
9421: $output .= '<label>'.
9422: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9423: &mt($option).'</label>'.(' ' x2);
9424: }
9425: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9426: } else {
9427: $output .= '<label>'.
9428: '<input type="checkbox" name="canmodify_'.$role.'" '.
9429: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9430: '</label>';
9431: }
9432: $output .= '</span></td>';
1.33 raeburn 9433: }
1.160.6.93 raeburn 9434: $rem = $total%$numinrow;
9435: my $colsleft;
9436: if ($rem) {
9437: $colsleft = $numinrow - $rem;
9438: }
9439: if ($colsleft > 1) {
1.33 raeburn 9440: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9441: ' </td>';
9442: } elsif ($colsleft == 1) {
9443: $output .= '<td class="LC_left_item"> </td>';
9444: }
9445: $output .= '</tr></table></td></tr>';
9446: return $output;
9447: }
1.28 raeburn 9448:
1.93 raeburn 9449: sub insttypes_row {
1.160.6.93 raeburn 9450: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9451: $customcss,$rowstyle) = @_;
1.93 raeburn 9452: my %lt = &Apache::lonlocal::texthash (
9453: cansearch => 'Users allowed to search',
9454: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9455: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 9456: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 9457: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9458: );
9459: my $showdom;
9460: if ($context eq 'cansearch') {
9461: $showdom = ' ('.$dom.')';
9462: }
1.160.6.5 raeburn 9463: my $class = 'LC_left_item';
9464: if ($context eq 'statustocreate') {
9465: $class = 'LC_right_item';
9466: }
1.160.6.93 raeburn 9467: my $css_class;
9468: if ($$rowtotal%2) {
9469: $css_class = 'LC_odd_row';
9470: }
9471: if ($customcss) {
9472: $css_class .= ' '.$customcss;
9473: }
9474: $css_class =~ s/^\s+//;
9475: if ($css_class) {
9476: $css_class = ' class="'.$css_class.'"';
9477: }
9478: if ($rowstyle) {
9479: $css_class .= ' style="'.$rowstyle.'"';
9480: }
9481: if ($onclick) {
9482: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 9483: }
9484: my $output = '<tr'.$css_class.'>'.
9485: '<td>'.$lt{$context}.$showdom.
9486: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9487: my $rem;
9488: if (ref($types) eq 'ARRAY') {
9489: for (my $i=0; $i<@{$types}; $i++) {
9490: if (defined($usertypes->{$types->[$i]})) {
9491: my $rem = $i%($numinrow);
9492: if ($rem == 0) {
9493: if ($i > 0) {
9494: $output .= '</tr>';
9495: }
9496: $output .= '<tr>';
1.23 raeburn 9497: }
1.26 raeburn 9498: my $check = ' ';
1.99 raeburn 9499: if (ref($settings) eq 'HASH') {
9500: if (ref($settings->{$context}) eq 'ARRAY') {
9501: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9502: $check = ' checked="checked" ';
9503: }
1.160.6.101 raeburn 9504: } elsif (ref($settings->{$context}) eq 'HASH') {
9505: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9506: $check = ' checked="checked" ';
9507: }
1.99 raeburn 9508: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9509: $check = ' checked="checked" ';
9510: }
1.23 raeburn 9511: }
1.26 raeburn 9512: $output .= '<td class="LC_left_item">'.
9513: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9514: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9515: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9516: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9517: }
9518: }
1.26 raeburn 9519: $rem = @{$types}%($numinrow);
1.23 raeburn 9520: }
9521: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9522: if ($context eq 'overrides') {
9523: if ($colsleft > 1) {
9524: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9525: } else {
9526: $output .= '<td class="LC_left_item">';
9527: }
9528: $output .= ' ';
1.23 raeburn 9529: } else {
1.160.6.101 raeburn 9530: if ($rem == 0) {
9531: $output .= '<tr>';
9532: }
9533: if ($colsleft > 1) {
9534: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9535: } else {
9536: $output .= '<td class="LC_left_item">';
9537: }
9538: my $defcheck = ' ';
9539: if (ref($settings) eq 'HASH') {
9540: if (ref($settings->{$context}) eq 'ARRAY') {
9541: if (grep(/^default$/,@{$settings->{$context}})) {
9542: $defcheck = ' checked="checked" ';
9543: }
9544: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9545: $defcheck = ' checked="checked" ';
9546: }
1.26 raeburn 9547: }
1.160.6.101 raeburn 9548: $output .= '<span class="LC_nobreak"><label>'.
9549: '<input type="checkbox" name="'.$context.'" '.
9550: 'value="default"'.$defcheck.$onclick.' />'.
9551: $othertitle.'</label></span>';
1.23 raeburn 9552: }
1.160.6.101 raeburn 9553: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9554: return $output;
1.23 raeburn 9555: }
9556:
9557: sub sorted_searchtitles {
9558: my %searchtitles = &Apache::lonlocal::texthash(
9559: 'uname' => 'username',
9560: 'lastname' => 'last name',
9561: 'lastfirst' => 'last name, first name',
9562: );
9563: my @titleorder = ('uname','lastname','lastfirst');
9564: return (\%searchtitles,\@titleorder);
9565: }
9566:
1.25 raeburn 9567: sub sorted_searchtypes {
9568: my %srchtypes_desc = (
9569: exact => 'is exact match',
9570: contains => 'contains ..',
9571: begins => 'begins with ..',
9572: );
9573: my @srchtypeorder = ('exact','begins','contains');
9574: return (\%srchtypes_desc,\@srchtypeorder);
9575: }
9576:
1.3 raeburn 9577: sub usertype_update_row {
9578: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9579: my $datatable;
9580: my $numinrow = 4;
9581: foreach my $type (@{$types}) {
9582: if (defined($usertypes->{$type})) {
9583: $$rownums ++;
9584: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9585: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9586: '</td><td class="LC_left_item"><table>';
9587: for (my $i=0; $i<@{$fields}; $i++) {
9588: my $rem = $i%($numinrow);
9589: if ($rem == 0) {
9590: if ($i > 0) {
9591: $datatable .= '</tr>';
9592: }
9593: $datatable .= '<tr>';
9594: }
9595: my $check = ' ';
1.39 raeburn 9596: if (ref($settings) eq 'HASH') {
9597: if (ref($settings->{'fields'}) eq 'HASH') {
9598: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9599: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9600: $check = ' checked="checked" ';
9601: }
1.3 raeburn 9602: }
9603: }
9604: }
9605:
9606: if ($i == @{$fields}-1) {
9607: my $colsleft = $numinrow - $rem;
9608: if ($colsleft > 1) {
9609: $datatable .= '<td colspan="'.$colsleft.'">';
9610: } else {
9611: $datatable .= '<td>';
9612: }
9613: } else {
9614: $datatable .= '<td>';
9615: }
1.8 raeburn 9616: $datatable .= '<span class="LC_nobreak"><label>'.
9617: '<input type="checkbox" name="updateable_'.$type.
9618: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9619: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9620: }
9621: $datatable .= '</tr></table></td></tr>';
9622: }
9623: }
9624: return $datatable;
1.1 raeburn 9625: }
9626:
9627: sub modify_login {
1.160.6.24 raeburn 9628: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 9629: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 9630: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
9631: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 9632: %title = ( coursecatalog => 'Display course catalog',
9633: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 9634: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 9635: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 9636: loginheader => 'Log-in box header',
9637: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 9638: @offon = ('off','on');
1.112 raeburn 9639: if (ref($domconfig{login}) eq 'HASH') {
9640: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9641: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9642: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9643: }
9644: }
1.160.6.113 raeburn 9645: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
9646: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
9647: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
9648: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
9649: $saml{$lonhost} = 1;
9650: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
9651: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
9652: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
9653: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
9654: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
9655: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
9656: }
9657: }
9658: }
1.112 raeburn 9659: }
1.9 raeburn 9660: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9661: \%domconfig,\%loginhash);
1.160.6.14 raeburn 9662: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9663: foreach my $item (@toggles) {
9664: $loginhash{login}{$item} = $env{'form.'.$item};
9665: }
1.41 raeburn 9666: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9667: if (ref($colchanges{'login'}) eq 'HASH') {
9668: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9669: \%loginhash);
9670: }
1.110 raeburn 9671:
1.149 raeburn 9672: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 9673: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9674: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9675: if (keys(%servers) > 1) {
9676: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9677: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9678: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9679: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9680: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9681: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9682: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9683: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9684: $changes{'loginvia'}{$lonhost} = 1;
9685: } else {
9686: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9687: $changes{'loginvia'}{$lonhost} = 1;
9688: }
9689: } else {
9690: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9691: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9692: $changes{'loginvia'}{$lonhost} = 1;
9693: }
9694: }
9695: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9696: foreach my $item (@loginvia_attribs) {
9697: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9698: }
9699: } else {
9700: foreach my $item (@loginvia_attribs) {
9701: my $new = $env{'form.'.$lonhost.'_'.$item};
9702: if (($item eq 'serverpath') && ($new eq 'custom')) {
9703: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9704: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9705: $new = '/';
9706: }
9707: }
9708: if (($item eq 'custompath') &&
9709: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9710: $new = '';
9711: }
9712: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9713: $changes{'loginvia'}{$lonhost} = 1;
9714: }
9715: if ($item eq 'exempt') {
1.160.6.56 raeburn 9716: $new = &check_exempt_addresses($new);
1.128 raeburn 9717: }
9718: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9719: }
9720: }
1.112 raeburn 9721: } else {
1.128 raeburn 9722: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9723: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9724: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9725: foreach my $item (@loginvia_attribs) {
9726: my $new = $env{'form.'.$lonhost.'_'.$item};
9727: if (($item eq 'serverpath') && ($new eq 'custom')) {
9728: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9729: $new = '/';
9730: }
9731: }
9732: if (($item eq 'custompath') &&
9733: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9734: $new = '';
9735: }
9736: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9737: }
1.110 raeburn 9738: }
9739: }
9740: }
9741: }
1.119 raeburn 9742:
1.160.6.5 raeburn 9743: my $servadm = $r->dir_config('lonAdmEMail');
9744: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9745: if (ref($domconfig{'login'}) eq 'HASH') {
9746: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9747: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9748: if ($lang eq 'nolang') {
9749: push(@currlangs,$lang);
9750: } elsif (defined($langchoices{$lang})) {
9751: push(@currlangs,$lang);
9752: } else {
9753: next;
9754: }
9755: }
9756: }
9757: }
9758: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9759: if (@currlangs > 0) {
9760: foreach my $lang (@currlangs) {
9761: if (grep(/^\Q$lang\E$/,@delurls)) {
9762: $changes{'helpurl'}{$lang} = 1;
9763: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9764: $changes{'helpurl'}{$lang} = 1;
9765: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9766: push(@newlangs,$lang);
9767: } else {
9768: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9769: }
9770: }
9771: }
9772: unless (grep(/^nolang$/,@currlangs)) {
9773: if ($env{'form.loginhelpurl_nolang.filename'}) {
9774: $changes{'helpurl'}{'nolang'} = 1;
9775: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9776: push(@newlangs,'nolang');
9777: }
9778: }
9779: if ($env{'form.loginhelpurl_add_lang'}) {
9780: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9781: ($env{'form.loginhelpurl_add_file.filename'})) {
9782: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9783: $addedfile = $env{'form.loginhelpurl_add_lang'};
9784: }
9785: }
9786: if ((@newlangs > 0) || ($addedfile)) {
9787: my $error;
9788: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9789: if ($configuserok eq 'ok') {
9790: if ($switchserver) {
9791: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9792: } elsif ($author_ok eq 'ok') {
9793: my @allnew = @newlangs;
9794: if ($addedfile ne '') {
9795: push(@allnew,$addedfile);
9796: }
9797: foreach my $lang (@allnew) {
9798: my $formelem = 'loginhelpurl_'.$lang;
9799: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9800: $formelem = 'loginhelpurl_add_file';
9801: }
9802: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9803: "help/$lang",'','',$newfile{$lang});
9804: if ($result eq 'ok') {
9805: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9806: $changes{'helpurl'}{$lang} = 1;
9807: } else {
9808: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9809: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9810: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
9811: (!grep(/^\Q$lang\E$/,@delurls))) {
9812: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9813: }
9814: }
9815: }
9816: } else {
9817: $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);
9818: }
9819: } else {
9820: $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);
9821: }
9822: if ($error) {
9823: &Apache::lonnet::logthis($error);
9824: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9825: }
9826: }
1.160.6.56 raeburn 9827:
9828: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9829: if (ref($domconfig{'login'}) eq 'HASH') {
9830: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9831: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9832: if ($domservers{$lonhost}) {
9833: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9834: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 9835: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 9836: }
9837: }
9838: }
9839: }
9840: }
9841: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9842: foreach my $lonhost (sort(keys(%domservers))) {
9843: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9844: $changes{'headtag'}{$lonhost} = 1;
9845: } else {
9846: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9847: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9848: }
9849: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9850: push(@newhosts,$lonhost);
9851: } elsif ($currheadtagurls{$lonhost}) {
9852: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9853: if ($currexempt{$lonhost}) {
9854: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
9855: $changes{'headtag'}{$lonhost} = 1;
9856: }
9857: } elsif ($possexempt{$lonhost}) {
9858: $changes{'headtag'}{$lonhost} = 1;
9859: }
9860: if ($possexempt{$lonhost}) {
9861: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9862: }
9863: }
9864: }
9865: }
9866: if (@newhosts) {
9867: my $error;
9868: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9869: if ($configuserok eq 'ok') {
9870: if ($switchserver) {
9871: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9872: } elsif ($author_ok eq 'ok') {
9873: foreach my $lonhost (@newhosts) {
9874: my $formelem = 'loginheadtag_'.$lonhost;
9875: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9876: "login/headtag/$lonhost",'','',
9877: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9878: if ($result eq 'ok') {
1.160.6.113 raeburn 9879: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9880: $changes{'headtag'}{$lonhost} = 1;
9881: if ($possexempt{$lonhost}) {
9882: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9883: }
9884: } else {
9885: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9886: $newheadtagurls{$lonhost},$result);
9887: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9888: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9889: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9890: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9891: }
9892: }
9893: }
9894: } else {
9895: $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);
9896: }
9897: } else {
9898: $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);
9899: }
9900: if ($error) {
9901: &Apache::lonnet::logthis($error);
9902: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9903: }
9904: }
9905: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
9906: my @newsamlimgs;
9907: foreach my $lonhost (keys(%domservers)) {
9908: if ($env{'form.saml_'.$lonhost}) {
9909: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
9910: push(@newsamlimgs,$lonhost);
9911: }
9912: foreach my $item ('text','alt','url','title','notsso') {
9913: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
9914: }
9915: if ($saml{$lonhost}) {
9916: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
9917: #FIXME Need to obsolete published image
9918: delete($currsaml{$lonhost}{'img'});
9919: $changes{'saml'}{$lonhost} = 1;
9920: }
9921: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
9922: $changes{'saml'}{$lonhost} = 1;
9923: }
9924: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
9925: $changes{'saml'}{$lonhost} = 1;
9926: }
9927: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
9928: $changes{'saml'}{$lonhost} = 1;
9929: }
9930: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
9931: $changes{'saml'}{$lonhost} = 1;
9932: }
9933: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
9934: $changes{'saml'}{$lonhost} = 1;
9935: }
9936: } else {
9937: $changes{'saml'}{$lonhost} = 1;
9938: }
9939: foreach my $item ('text','alt','url','title','notsso') {
9940: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
9941: }
9942: } else {
9943: if ($saml{$lonhost}) {
9944: $changes{'saml'}{$lonhost} = 1;
9945: delete($currsaml{$lonhost});
9946: }
9947: }
9948: }
9949: foreach my $posshost (keys(%currsaml)) {
9950: unless (exists($domservers{$posshost})) {
9951: delete($currsaml{$posshost});
9952: }
9953: }
9954: %{$loginhash{'login'}{'saml'}} = %currsaml;
9955: if (@newsamlimgs) {
9956: my $error;
9957: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9958: if ($configuserok eq 'ok') {
9959: if ($switchserver) {
9960: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
9961: } elsif ($author_ok eq 'ok') {
9962: foreach my $lonhost (@newsamlimgs) {
9963: my $formelem = 'saml_img_'.$lonhost;
9964: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9965: "login/saml/$lonhost",'','',
9966: $env{'form.saml_img_'.$lonhost.'.filename'});
9967: if ($result eq 'ok') {
9968: $currsaml{$lonhost}{'img'} = $imgurl;
9969: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
9970: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 9971: } else {
1.160.6.113 raeburn 9972: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
9973: $lonhost,$result);
1.160.6.56 raeburn 9974: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9975: }
9976: }
9977: } else {
1.160.6.113 raeburn 9978: $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 9979: }
9980: } else {
1.160.6.113 raeburn 9981: $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 9982: }
9983: if ($error) {
9984: &Apache::lonnet::logthis($error);
9985: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9986: }
9987: }
1.160.6.5 raeburn 9988: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
9989:
9990: my $defaulthelpfile = '/adm/loginproblems.html';
9991: my $defaulttext = &mt('Default in use');
9992:
1.1 raeburn 9993: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9994: $dom);
9995: if ($putresult eq 'ok') {
1.160.6.14 raeburn 9996: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9997: my %defaultchecked = (
9998: 'coursecatalog' => 'on',
1.160.6.14 raeburn 9999: 'helpdesk' => 'on',
1.42 raeburn 10000: 'adminmail' => 'off',
1.43 raeburn 10001: 'newuser' => 'off',
1.42 raeburn 10002: );
1.55 raeburn 10003: if (ref($domconfig{'login'}) eq 'HASH') {
10004: foreach my $item (@toggles) {
10005: if ($defaultchecked{$item} eq 'on') {
10006: if (($domconfig{'login'}{$item} eq '0') &&
10007: ($env{'form.'.$item} eq '1')) {
10008: $changes{$item} = 1;
10009: } elsif (($domconfig{'login'}{$item} eq '' ||
10010: $domconfig{'login'}{$item} eq '1') &&
10011: ($env{'form.'.$item} eq '0')) {
10012: $changes{$item} = 1;
10013: }
10014: } elsif ($defaultchecked{$item} eq 'off') {
10015: if (($domconfig{'login'}{$item} eq '1') &&
10016: ($env{'form.'.$item} eq '0')) {
10017: $changes{$item} = 1;
10018: } elsif (($domconfig{'login'}{$item} eq '' ||
10019: $domconfig{'login'}{$item} eq '0') &&
10020: ($env{'form.'.$item} eq '1')) {
10021: $changes{$item} = 1;
10022: }
1.42 raeburn 10023: }
10024: }
1.41 raeburn 10025: }
1.6 raeburn 10026: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10027: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 10028: if (exists($changes{'saml'})) {
10029: my $hostid_in_use;
10030: my @hosts = &Apache::lonnet::current_machine_ids();
10031: if (@hosts > 1) {
10032: foreach my $hostid (@hosts) {
10033: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10034: $hostid_in_use = $hostid;
10035: last;
10036: }
10037: }
10038: } else {
10039: $hostid_in_use = $r->dir_config('lonHostID');
10040: }
10041: if (($hostid_in_use) &&
10042: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10043: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10044: }
10045: if (ref($lastactref) eq 'HASH') {
10046: if (ref($changes{'saml'}) eq 'HASH') {
10047: my %updates;
10048: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10049: $lastactref->{'samllanding'} = \%updates;
10050: }
10051: }
10052: }
1.160.6.27 raeburn 10053: if (ref($lastactref) eq 'HASH') {
10054: $lastactref->{'domainconfig'} = 1;
10055: }
1.1 raeburn 10056: $resulttext = &mt('Changes made:').'<ul>';
10057: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10058: if ($item eq 'loginvia') {
1.112 raeburn 10059: if (ref($changes{$item}) eq 'HASH') {
10060: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10061: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10062: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10063: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10064: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10065: $protocol = 'http' if ($protocol ne 'https');
10066: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10067:
10068: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10069: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10070: } else {
10071: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10072: }
10073: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10074: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10075: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10076: }
10077: $resulttext .= '</li>';
10078: } else {
10079: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10080: }
1.112 raeburn 10081: } else {
1.128 raeburn 10082: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10083: }
10084: }
1.128 raeburn 10085: $resulttext .= '</ul></li>';
1.112 raeburn 10086: }
1.160.6.5 raeburn 10087: } elsif ($item eq 'helpurl') {
10088: if (ref($changes{$item}) eq 'HASH') {
10089: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10090: if (grep(/^\Q$lang\E$/,@delurls)) {
10091: my ($chg,$link);
10092: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10093: if ($lang eq 'nolang') {
10094: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10095: } else {
10096: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10097: }
10098: $resulttext .= '<li>'.$chg.'</li>';
10099: } else {
10100: my $chg;
10101: if ($lang eq 'nolang') {
10102: $chg = &mt('custom log-in help file for no preferred language');
10103: } else {
10104: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10105: }
10106: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10107: $loginhash{'login'}{'helpurl'}{$lang}.
10108: '?inhibitmenu=yes',$chg,600,500).
10109: '</li>';
10110: }
10111: }
10112: }
1.160.6.56 raeburn 10113: } elsif ($item eq 'headtag') {
10114: if (ref($changes{$item}) eq 'HASH') {
10115: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10116: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10117: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10118: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10119: $resulttext .= '<li><a href="'.
10120: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10121: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10122: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10123: if ($possexempt{$lonhost}) {
10124: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10125: } else {
10126: $resulttext .= &mt('included for any client IP');
10127: }
10128: $resulttext .= '</li>';
10129: }
10130: }
10131: }
1.160.6.113 raeburn 10132: } elsif ($item eq 'saml') {
10133: if (ref($changes{$item}) eq 'HASH') {
10134: my %notlt = (
10135: text => 'Text for log-in by SSO',
10136: img => 'SSO button image',
10137: alt => 'Alt text for button image',
10138: url => 'SSO URL',
10139: title => 'Tooltip for SSO link',
10140: notsso => 'Text for non-SSO log-in',
10141: );
10142: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10143: if (ref($currsaml{$lonhost}) eq 'HASH') {
10144: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10145: '<ul>';
10146: foreach my $key ('text','img','alt','url','title','notsso') {
10147: if ($currsaml{$lonhost}{$key} eq '') {
10148: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10149: } else {
10150: my $value = "'$currsaml{$lonhost}{$key}'";
10151: if ($key eq 'img') {
10152: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
10153: }
10154: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10155: $value).'</li>';
10156: }
10157: }
10158: $resulttext .= '</ul></li>';
10159: } else {
10160: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10161: }
10162: }
10163: }
1.160.6.5 raeburn 10164: } elsif ($item eq 'captcha') {
10165: if (ref($loginhash{'login'}) eq 'HASH') {
10166: my $chgtxt;
10167: if ($loginhash{'login'}{$item} eq 'notused') {
10168: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10169: } else {
10170: my %captchas = &captcha_phrases();
10171: if ($captchas{$loginhash{'login'}{$item}}) {
10172: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10173: } else {
10174: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10175: }
10176: }
10177: $resulttext .= '<li>'.$chgtxt.'</li>';
10178: }
10179: } elsif ($item eq 'recaptchakeys') {
10180: if (ref($loginhash{'login'}) eq 'HASH') {
10181: my ($privkey,$pubkey);
10182: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10183: $pubkey = $loginhash{'login'}{$item}{'public'};
10184: $privkey = $loginhash{'login'}{$item}{'private'};
10185: }
10186: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10187: if (!$pubkey) {
10188: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10189: } else {
10190: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10191: }
10192: if (!$privkey) {
10193: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10194: } else {
1.160.6.53 raeburn 10195: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 10196: }
10197: $chgtxt .= '</ul>';
10198: $resulttext .= '<li>'.$chgtxt.'</li>';
10199: }
1.160.6.69 raeburn 10200: } elsif ($item eq 'recaptchaversion') {
10201: if (ref($loginhash{'login'}) eq 'HASH') {
10202: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10203: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10204: '</li>';
10205: }
10206: }
1.41 raeburn 10207: } else {
10208: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10209: }
1.1 raeburn 10210: }
1.6 raeburn 10211: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10212: } else {
10213: $resulttext = &mt('No changes made to log-in page settings');
10214: }
10215: } else {
1.11 albertel 10216: $resulttext = '<span class="LC_error">'.
10217: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10218: }
1.6 raeburn 10219: if ($errors) {
1.9 raeburn 10220: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10221: $errors.'</ul>';
10222: }
10223: return $resulttext;
10224: }
10225:
1.160.6.56 raeburn 10226: sub check_exempt_addresses {
10227: my ($iplist) = @_;
10228: $iplist =~ s/^\s+//;
10229: $iplist =~ s/\s+$//;
10230: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10231: my (@okips,$new);
10232: foreach my $ip (@poss_ips) {
10233: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10234: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10235: push(@okips,$ip);
10236: }
10237: }
10238: }
10239: if (@okips > 0) {
10240: $new = join(',',@okips);
10241: } else {
10242: $new = '';
10243: }
10244: return $new;
10245: }
10246:
1.6 raeburn 10247: sub color_font_choices {
10248: my %choices =
10249: &Apache::lonlocal::texthash (
10250: img => "Header",
10251: bgs => "Background colors",
10252: links => "Link colors",
1.55 raeburn 10253: images => "Images",
1.6 raeburn 10254: font => "Font color",
1.160.6.22 raeburn 10255: fontmenu => "Font menu",
1.76 raeburn 10256: pgbg => "Page",
1.6 raeburn 10257: tabbg => "Header",
10258: sidebg => "Border",
10259: link => "Link",
10260: alink => "Active link",
10261: vlink => "Visited link",
10262: );
10263: return %choices;
10264: }
10265:
1.160.6.113 raeburn 10266: sub modify_ipaccess {
10267: my ($dom,$lastactref,%domconfig) = @_;
10268: my (@allpos,%changes,%confhash,$errors,$resulttext);
10269: my (@items,%deletions,%itemids,@warnings);
10270: my ($typeorder,$types) = &commblocktype_text();
10271: if ($env{'form.ipaccess_add'}) {
10272: my $name = $env{'form.ipaccess_name_add'};
10273: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10274: if ($newid) {
10275: $itemids{'add'} = $newid;
10276: push(@items,'add');
10277: $changes{$newid} = 1;
10278: } else {
10279: $error = &mt('Failed to acquire unique ID for new IP access control item');
10280: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10281: }
10282: }
10283: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10284: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10285: if (@todelete) {
10286: map { $deletions{$_} = 1; } @todelete;
10287: }
10288: my $maxnum = $env{'form.ipaccess_maxnum'};
10289: for (my $i=0; $i<$maxnum; $i++) {
10290: my $itemid = $env{'form.ipaccess_id_'.$i};
10291: $itemid =~ s/\D+//g;
10292: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10293: if ($deletions{$itemid}) {
10294: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10295: } else {
10296: push(@items,$i);
10297: $itemids{$i} = $itemid;
10298: }
10299: }
10300: }
10301: }
10302: foreach my $idx (@items) {
10303: my $itemid = $itemids{$idx};
10304: next unless ($itemid);
10305: my %current;
10306: unless ($idx eq 'add') {
10307: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10308: %current = %{$domconfig{'ipaccess'}{$itemid}};
10309: }
10310: }
10311: my $position = $env{'form.ipaccess_pos_'.$itemid};
10312: $position =~ s/\D+//g;
10313: if ($position ne '') {
10314: $allpos[$position] = $itemid;
10315: }
10316: my $name = $env{'form.ipaccess_name_'.$idx};
10317: $name =~ s/^\s+|\s+$//g;
10318: $confhash{$itemid}{'name'} = $name;
10319: my $possrange = $env{'form.ipaccess_range_'.$idx};
10320: $possrange =~ s/^\s+|\s+$//g;
10321: unless ($possrange eq '') {
10322: $possrange =~ s/[\r\n]+/\s/g;
10323: $possrange =~ s/\s*-\s*/-/g;
10324: $possrange =~ s/\s+/,/g;
10325: $possrange =~ s/,+/,/g;
10326: if ($possrange ne '') {
10327: my (@ok,$count);
10328: $count = 0;
10329: foreach my $poss (split(/\,/,$possrange)) {
10330: $count ++;
10331: $poss = &validate_ip_pattern($poss);
10332: if ($poss ne '') {
10333: push(@ok,$poss);
10334: }
10335: }
10336: my $diff = $count - scalar(@ok);
10337: if ($diff) {
10338: $errors .= '<li><span class="LC_error">'.
10339: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10340: $diff,$name).
10341: '</span></li>';
10342: }
10343: if (@ok) {
10344: my @cidr_list;
10345: foreach my $item (@ok) {
10346: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10347: }
10348: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10349: }
10350: }
10351: }
10352: foreach my $field ('name','ip') {
10353: unless (($idx eq 'add') || ($changes{$itemid})) {
10354: if ($current{$field} ne $confhash{$itemid}{$field}) {
10355: $changes{$itemid} = 1;
10356: last;
10357: }
10358: }
10359: }
10360: $confhash{$itemid}{'commblocks'} = {};
10361:
10362: my %commblocks;
10363: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10364: foreach my $type (@{$typeorder}) {
10365: if ($commblocks{$type}) {
10366: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10367: }
10368: unless (($idx eq 'add') || ($changes{$itemid})) {
10369: if (ref($current{'commblocks'}) eq 'HASH') {
10370: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10371: $changes{$itemid} = 1;
10372: }
10373: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10374: $changes{$itemid} = 1;
10375: }
10376: }
10377: }
10378: $confhash{$itemid}{'courses'} = {};
10379: my %crsdeletions;
10380: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10381: if (@delcrs) {
10382: map { $crsdeletions{$_} = 1; } @delcrs;
10383: }
10384: if (ref($current{'courses'}) eq 'HASH') {
10385: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10386: if ($crsdeletions{$cid}) {
10387: $changes{$itemid} = 1;
10388: } else {
10389: $confhash{$itemid}{'courses'}{$cid} = 1;
10390: }
10391: }
10392: }
10393: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10394: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10395: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10396: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10397: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10398: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10399: $errors .= '<li><span class="LC_error">'.
10400: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10401: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10402: '</span></li>';
10403: } else {
10404: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10405: $changes{$itemid} = 1;
10406: }
10407: }
10408: }
10409: if (@allpos > 0) {
10410: my $idx = 0;
10411: foreach my $itemid (@allpos) {
10412: if ($itemid ne '') {
10413: $confhash{$itemid}{'order'} = $idx;
10414: unless ($changes{$itemid}) {
10415: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10416: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10417: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10418: $changes{$itemid} = 1;
10419: }
10420: }
10421: }
10422: }
10423: $idx ++;
10424: }
10425: }
10426: }
10427: if (keys(%changes)) {
10428: my %defaultshash = (
10429: ipaccess => \%confhash,
10430: );
10431: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10432: $dom);
10433: if ($putresult eq 'ok') {
10434: my $cachetime = 1800;
10435: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10436: if (ref($lastactref) eq 'HASH') {
10437: $lastactref->{'ipaccess'} = 1;
10438: }
10439: $resulttext = &mt('Changes made:').'<ul>';
10440: my %bynum;
10441: foreach my $itemid (sort(keys(%changes))) {
10442: if (ref($confhash{$itemid}) eq 'HASH') {
10443: my $position = $confhash{$itemid}{'order'};
10444: if ($position =~ /^\d+$/) {
10445: $bynum{$position} = $itemid;
10446: }
10447: }
10448: }
10449: if (keys(%deletions)) {
10450: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10451: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10452: }
10453: }
10454: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10455: my $itemid = $bynum{$pos};
10456: if (ref($confhash{$itemid}) eq 'HASH') {
10457: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10458: my $position = $pos + 1;
10459: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10460: if ($confhash{$itemid}{'ip'} eq '') {
10461: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10462: } else {
10463: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10464: }
10465: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10466: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10467: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10468: '</li>';
10469: } else {
10470: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10471: }
10472: if (keys(%{$confhash{$itemid}{'courses'}})) {
10473: my @courses;
10474: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10475: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10476: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10477: }
10478: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10479: join('</li><li>',@courses).'</li></ul>';
10480: } else {
10481: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10482: }
10483: $resulttext .= '</ul></li>';
10484: }
10485: }
10486: $resulttext .= '</ul>';
10487: } else {
10488: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10489: }
10490: } else {
10491: $resulttext = &mt('No changes made');
10492: }
10493: if ($errors) {
10494: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10495: $errors.'</ul></p>';
10496: }
10497: return $resulttext;
10498: }
10499:
10500: sub get_ipaccess_id {
10501: my ($domain,$location) = @_;
10502: # get lock on ipaccess db
10503: my $lockhash = {
10504: lock => $env{'user.name'}.
10505: ':'.$env{'user.domain'},
10506: };
10507: my $tries = 0;
10508: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10509: my ($id,$error);
10510:
10511: while (($gotlock ne 'ok') && ($tries<10)) {
10512: $tries ++;
10513: sleep (0.1);
10514: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10515: }
10516: if ($gotlock eq 'ok') {
10517: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10518: if ($currids{'lock'}) {
10519: delete($currids{'lock'});
10520: if (keys(%currids)) {
10521: my @curr = sort { $a <=> $b } keys(%currids);
10522: if ($curr[-1] =~ /^\d+$/) {
10523: $id = 1 + $curr[-1];
10524: }
10525: } else {
10526: $id = 1;
10527: }
10528: if ($id) {
10529: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10530: $error = 'nostore';
10531: }
10532: } else {
10533: $error = 'nonumber';
10534: }
10535: }
10536: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10537: } else {
10538: $error = 'nolock';
10539: }
10540: return ($id,$error);
10541: }
10542:
1.6 raeburn 10543: sub modify_rolecolors {
1.160.6.24 raeburn 10544: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10545: my ($resulttext,%rolehash);
10546: $rolehash{'rolecolors'} = {};
1.55 raeburn 10547: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10548: if ($domconfig{'rolecolors'} eq '') {
10549: $domconfig{'rolecolors'} = {};
10550: }
10551: }
1.9 raeburn 10552: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10553: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10554: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10555: $dom);
10556: if ($putresult eq 'ok') {
10557: if (keys(%changes) > 0) {
1.41 raeburn 10558: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10559: if (ref($lastactref) eq 'HASH') {
10560: $lastactref->{'domainconfig'} = 1;
10561: }
1.6 raeburn 10562: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10563: $rolehash{'rolecolors'});
10564: } else {
10565: $resulttext = &mt('No changes made to default color schemes');
10566: }
10567: } else {
1.11 albertel 10568: $resulttext = '<span class="LC_error">'.
10569: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10570: }
10571: if ($errors) {
10572: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10573: $errors.'</ul>';
10574: }
10575: return $resulttext;
10576: }
10577:
10578: sub modify_colors {
1.9 raeburn 10579: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10580: my (%changes,%choices);
1.51 raeburn 10581: my @bgs;
1.6 raeburn 10582: my @links = ('link','alink','vlink');
1.41 raeburn 10583: my @logintext;
1.6 raeburn 10584: my @images;
10585: my $servadm = $r->dir_config('lonAdmEMail');
10586: my $errors;
1.160.6.22 raeburn 10587: my %defaults;
1.6 raeburn 10588: foreach my $role (@{$roles}) {
10589: if ($role eq 'login') {
1.12 raeburn 10590: %choices = &login_choices();
1.41 raeburn 10591: @logintext = ('textcol','bgcol');
1.12 raeburn 10592: } else {
10593: %choices = &color_font_choices();
10594: }
10595: if ($role eq 'login') {
1.41 raeburn 10596: @images = ('img','logo','domlogo','login');
1.51 raeburn 10597: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10598: } else {
10599: @images = ('img');
1.160.6.22 raeburn 10600: @bgs = ('pgbg','tabbg','sidebg');
10601: }
10602: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10603: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10604: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10605: }
10606: if ($role eq 'login') {
10607: foreach my $item (@logintext) {
1.160.6.39 raeburn 10608: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10609: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10610: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10611: }
10612: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10613: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10614: }
10615: }
10616: } else {
1.160.6.39 raeburn 10617: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10618: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10619: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10620: }
10621: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10622: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10623: }
1.6 raeburn 10624: }
1.160.6.22 raeburn 10625: foreach my $item (@bgs) {
1.160.6.39 raeburn 10626: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10627: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10628: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10629: }
10630: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 10631: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10632: }
10633: }
10634: foreach my $item (@links) {
1.160.6.39 raeburn 10635: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10636: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10637: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10638: }
10639: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 10640: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10641: }
1.6 raeburn 10642: }
1.46 raeburn 10643: my ($configuserok,$author_ok,$switchserver) =
10644: &config_check($dom,$confname,$servadm);
1.9 raeburn 10645: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10646: if (ref($domconfig->{$role}) ne 'HASH') {
10647: $domconfig->{$role} = {};
10648: }
1.8 raeburn 10649: foreach my $img (@images) {
1.160.6.118.2 2(raebur 10650:2): if ($role eq 'login') {
10651:2): if (($img eq 'img') || ($img eq 'logo')) {
10652:2): if (defined($env{'form.login_showlogo_'.$img})) {
10653:2): $confhash->{$role}{'showlogo'}{$img} = 1;
10654:2): } else {
10655:2): $confhash->{$role}{'showlogo'}{$img} = 0;
10656:2): }
1.70 raeburn 10657: }
1.160.6.118.2 2(raebur 10658:2): if ($env{'form.login_alt_'.$img} ne '') {
10659:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
10660:2): }
10661:2): }
1.18 albertel 10662: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10663: && !defined($domconfig->{$role}{$img})
10664: && !$env{'form.'.$role.'_del_'.$img}
10665: && $env{'form.'.$role.'_import_'.$img}) {
10666: # import the old configured image from the .tab setting
10667: # if they haven't provided a new one
10668: $domconfig->{$role}{$img} =
10669: $env{'form.'.$role.'_import_'.$img};
10670: }
1.6 raeburn 10671: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10672: my $error;
1.6 raeburn 10673: if ($configuserok eq 'ok') {
1.9 raeburn 10674: if ($switchserver) {
1.12 raeburn 10675: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10676: } else {
10677: if ($author_ok eq 'ok') {
10678: my ($result,$logourl) =
10679: &publishlogo($r,'upload',$role.'_'.$img,
10680: $dom,$confname,$img,$width,$height);
10681: if ($result eq 'ok') {
10682: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10683: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10684: } else {
1.12 raeburn 10685: $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 10686: }
10687: } else {
1.46 raeburn 10688: $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 10689: }
10690: }
10691: } else {
1.46 raeburn 10692: $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 10693: }
10694: if ($error) {
1.8 raeburn 10695: &Apache::lonnet::logthis($error);
1.11 albertel 10696: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10697: }
10698: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10699: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10700: my $error;
10701: if ($configuserok eq 'ok') {
10702: # is confname an author?
10703: if ($switchserver eq '') {
10704: if ($author_ok eq 'ok') {
10705: my ($result,$logourl) =
10706: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10707: $dom,$confname,$img,$width,$height);
10708: if ($result eq 'ok') {
10709: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10710: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10711: }
10712: }
10713: }
10714: }
1.6 raeburn 10715: }
10716: }
10717: }
10718: if (ref($domconfig) eq 'HASH') {
10719: if (ref($domconfig->{$role}) eq 'HASH') {
10720: foreach my $img (@images) {
10721: if ($domconfig->{$role}{$img} ne '') {
10722: if ($env{'form.'.$role.'_del_'.$img}) {
10723: $confhash->{$role}{$img} = '';
1.12 raeburn 10724: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10725: } else {
1.9 raeburn 10726: if ($confhash->{$role}{$img} eq '') {
10727: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10728: }
1.6 raeburn 10729: }
10730: } else {
10731: if ($env{'form.'.$role.'_del_'.$img}) {
10732: $confhash->{$role}{$img} = '';
1.12 raeburn 10733: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10734: }
10735: }
1.160.6.118.2 2(raebur 10736:2): if ($role eq 'login') {
10737:2): if (($img eq 'logo') || ($img eq 'img')) {
10738:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10739:2): if ($confhash->{$role}{'showlogo'}{$img} ne
10740:2): $domconfig->{$role}{'showlogo'}{$img}) {
10741:2): $changes{$role}{'showlogo'}{$img} = 1;
10742:2): }
10743:2): } else {
10744:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10745:2): $changes{$role}{'showlogo'}{$img} = 1;
10746:2): }
1.70 raeburn 10747: }
1.160.6.118.2 2(raebur 10748:2): }
10749:2): if ($img ne 'login') {
10750:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
10751:2): if ($confhash->{$role}{'alttext'}{$img} ne
10752:2): $domconfig->{$role}{'alttext'}{$img}) {
10753:2): $changes{$role}{'alttext'}{$img} = 1;
10754:2): }
10755:2): } else {
10756:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
10757:2): $changes{$role}{'alttext'}{$img} = 1;
10758:2): }
1.70 raeburn 10759: }
10760: }
10761: }
10762: }
1.6 raeburn 10763: if ($domconfig->{$role}{'font'} ne '') {
10764: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10765: $changes{$role}{'font'} = 1;
10766: }
10767: } else {
10768: if ($confhash->{$role}{'font'}) {
10769: $changes{$role}{'font'} = 1;
10770: }
10771: }
1.107 raeburn 10772: if ($role ne 'login') {
10773: if ($domconfig->{$role}{'fontmenu'} ne '') {
10774: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10775: $changes{$role}{'fontmenu'} = 1;
10776: }
10777: } else {
10778: if ($confhash->{$role}{'fontmenu'}) {
10779: $changes{$role}{'fontmenu'} = 1;
10780: }
1.97 tempelho 10781: }
10782: }
1.6 raeburn 10783: foreach my $item (@bgs) {
10784: if ($domconfig->{$role}{$item} ne '') {
10785: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10786: $changes{$role}{'bgs'}{$item} = 1;
10787: }
10788: } else {
10789: if ($confhash->{$role}{$item}) {
10790: $changes{$role}{'bgs'}{$item} = 1;
10791: }
10792: }
10793: }
10794: foreach my $item (@links) {
10795: if ($domconfig->{$role}{$item} ne '') {
10796: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10797: $changes{$role}{'links'}{$item} = 1;
10798: }
10799: } else {
10800: if ($confhash->{$role}{$item}) {
10801: $changes{$role}{'links'}{$item} = 1;
10802: }
10803: }
10804: }
1.41 raeburn 10805: foreach my $item (@logintext) {
10806: if ($domconfig->{$role}{$item} ne '') {
10807: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10808: $changes{$role}{'logintext'}{$item} = 1;
10809: }
10810: } else {
10811: if ($confhash->{$role}{$item}) {
10812: $changes{$role}{'logintext'}{$item} = 1;
10813: }
10814: }
10815: }
1.6 raeburn 10816: } else {
10817: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10818: \@logintext,$confhash,\%changes);
1.6 raeburn 10819: }
10820: } else {
10821: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10822: \@logintext,$confhash,\%changes);
1.6 raeburn 10823: }
10824: }
10825: return ($errors,%changes);
10826: }
10827:
1.46 raeburn 10828: sub config_check {
10829: my ($dom,$confname,$servadm) = @_;
10830: my ($configuserok,$author_ok,$switchserver,%currroles);
10831: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10832: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10833: $confname,$servadm);
10834: if ($configuserok eq 'ok') {
10835: $switchserver = &check_switchserver($dom,$confname);
10836: if ($switchserver eq '') {
10837: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10838: }
10839: }
10840: return ($configuserok,$author_ok,$switchserver);
10841: }
10842:
1.6 raeburn 10843: sub default_change_checker {
1.41 raeburn 10844: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10845: foreach my $item (@{$links}) {
10846: if ($confhash->{$role}{$item}) {
10847: $changes->{$role}{'links'}{$item} = 1;
10848: }
10849: }
10850: foreach my $item (@{$bgs}) {
10851: if ($confhash->{$role}{$item}) {
10852: $changes->{$role}{'bgs'}{$item} = 1;
10853: }
10854: }
1.41 raeburn 10855: foreach my $item (@{$logintext}) {
10856: if ($confhash->{$role}{$item}) {
10857: $changes->{$role}{'logintext'}{$item} = 1;
10858: }
10859: }
1.6 raeburn 10860: foreach my $img (@{$images}) {
10861: if ($env{'form.'.$role.'_del_'.$img}) {
10862: $confhash->{$role}{$img} = '';
1.12 raeburn 10863: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10864: }
1.70 raeburn 10865: if ($role eq 'login') {
10866: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10867: $changes->{$role}{'showlogo'}{$img} = 1;
10868: }
1.160.6.118.2 2(raebur 10869:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
10870:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
10871:2): $changes->{$role}{'alttext'}{$img} = 1;
10872:2): }
10873:2): }
1.70 raeburn 10874: }
1.6 raeburn 10875: }
10876: if ($confhash->{$role}{'font'}) {
10877: $changes->{$role}{'font'} = 1;
10878: }
1.48 raeburn 10879: }
1.6 raeburn 10880:
10881: sub display_colorchgs {
10882: my ($dom,$changes,$roles,$confhash) = @_;
10883: my (%choices,$resulttext);
10884: if (!grep(/^login$/,@{$roles})) {
10885: $resulttext = &mt('Changes made:').'<br />';
10886: }
10887: foreach my $role (@{$roles}) {
10888: if ($role eq 'login') {
10889: %choices = &login_choices();
10890: } else {
10891: %choices = &color_font_choices();
10892: }
10893: if (ref($changes->{$role}) eq 'HASH') {
10894: if ($role ne 'login') {
10895: $resulttext .= '<h4>'.&mt($role).'</h4>';
10896: }
10897: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10898: if ($role ne 'login') {
10899: $resulttext .= '<ul>';
10900: }
10901: if (ref($changes->{$role}{$key}) eq 'HASH') {
10902: if ($role ne 'login') {
10903: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10904: }
10905: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10906: if (($role eq 'login') && ($key eq 'showlogo')) {
10907: if ($confhash->{$role}{$key}{$item}) {
10908: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10909: } else {
10910: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10911: }
1.160.6.118.2 2(raebur 10912:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
10913:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 10914:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 10915:2): $confhash->{$role}{$key}{$item}).'</li>';
10916:2): } else {
10917:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
10918:2): }
1.70 raeburn 10919: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10920: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10921: } else {
1.12 raeburn 10922: my $newitem = $confhash->{$role}{$item};
10923: if ($key eq 'images') {
10924: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
10925: }
10926: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10927: }
10928: }
10929: if ($role ne 'login') {
10930: $resulttext .= '</ul></li>';
10931: }
10932: } else {
10933: if ($confhash->{$role}{$key} eq '') {
10934: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10935: } else {
10936: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10937: }
10938: }
10939: if ($role ne 'login') {
10940: $resulttext .= '</ul>';
10941: }
10942: }
10943: }
10944: }
1.3 raeburn 10945: return $resulttext;
1.1 raeburn 10946: }
10947:
1.9 raeburn 10948: sub thumb_dimensions {
10949: return ('200','50');
10950: }
10951:
1.16 raeburn 10952: sub check_dimensions {
10953: my ($inputfile) = @_;
10954: my ($fullwidth,$fullheight);
10955: if ($inputfile =~ m|^[/\w.\-]+$|) {
10956: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10957: my $imageinfo = <PIPE>;
10958: if (!close(PIPE)) {
10959: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10960: }
10961: chomp($imageinfo);
10962: my ($fullsize) =
1.21 raeburn 10963: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10964: if ($fullsize) {
10965: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10966: }
10967: }
10968: }
10969: return ($fullwidth,$fullheight);
10970: }
10971:
1.9 raeburn 10972: sub check_configuser {
10973: my ($uhome,$dom,$confname,$servadm) = @_;
10974: my ($configuserok,%currroles);
10975: if ($uhome eq 'no_host') {
10976: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 10977: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10978: $configuserok =
10979: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10980: $configpass,'','','','','',undef,$servadm);
10981: } else {
10982: $configuserok = 'ok';
10983: %currroles =
10984: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10985: }
10986: return ($configuserok,%currroles);
10987: }
10988:
10989: sub check_authorstatus {
10990: my ($dom,$confname,%currroles) = @_;
10991: my $author_ok;
1.40 raeburn 10992: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10993: my $start = time;
10994: my $end = 0;
10995: $author_ok =
10996: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10997: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10998: } else {
10999: $author_ok = 'ok';
11000: }
11001: return $author_ok;
11002: }
11003:
11004: sub publishlogo {
1.46 raeburn 11005: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 11006: my ($output,$fname,$logourl);
11007: if ($action eq 'upload') {
11008: $fname=$env{'form.'.$formname.'.filename'};
11009: chop($env{'form.'.$formname});
11010: } else {
11011: ($fname) = ($formname =~ /([^\/]+)$/);
11012: }
1.46 raeburn 11013: if ($savefileas ne '') {
11014: $fname = $savefileas;
11015: }
1.9 raeburn 11016: $fname=&Apache::lonnet::clean_filename($fname);
11017: # See if there is anything left
11018: unless ($fname) { return ('error: no uploaded file'); }
11019: $fname="$subdir/$fname";
1.160.6.5 raeburn 11020: my $docroot=$r->dir_config('lonDocRoot');
11021: my $filepath="$docroot/priv";
11022: my $relpath = "$dom/$confname";
1.9 raeburn 11023: my ($fnamepath,$file,$fetchthumb);
11024: $file=$fname;
11025: if ($fname=~m|/|) {
11026: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11027: }
1.160.6.26 raeburn 11028: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11029: my $count;
1.160.6.5 raeburn 11030: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11031: $filepath.="/$parts[$count]";
11032: if ((-e $filepath)!=1) {
11033: mkdir($filepath,02770);
11034: }
11035: }
11036: # Check for bad extension and disallow upload
11037: if ($file=~/\.(\w+)$/ &&
11038: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11039: $output =
1.160.6.25 raeburn 11040: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11041: } elsif ($file=~/\.(\w+)$/ &&
11042: !defined(&Apache::loncommon::fileembstyle($1))) {
11043: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11044: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 11045: $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 11046: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 11047: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11048: } else {
11049: my $source = $filepath.'/'.$file;
11050: my $logfile;
1.160.6.88 raeburn 11051: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 11052: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11053: }
11054: print $logfile
11055: "\n================= Publish ".localtime()." ================\n".
11056: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11057: # Save the file
1.160.6.88 raeburn 11058: if (!open(FH,">",$source)) {
1.9 raeburn 11059: &Apache::lonnet::logthis('Failed to create '.$source);
11060: return (&mt('Failed to create file'));
11061: }
11062: if ($action eq 'upload') {
11063: if (!print FH ($env{'form.'.$formname})) {
11064: &Apache::lonnet::logthis('Failed to write to '.$source);
11065: return (&mt('Failed to write file'));
11066: }
11067: } else {
11068: my $original = &Apache::lonnet::filelocation('',$formname);
11069: if(!copy($original,$source)) {
11070: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11071: return (&mt('Failed to write file'));
11072: }
11073: }
11074: close(FH);
11075: chmod(0660, $source); # Permissions to rw-rw---.
11076:
11077: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11078: my $copyfile=$targetdir.'/'.$file;
11079:
11080: my @parts=split(/\//,$targetdir);
11081: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11082: for (my $count=5;$count<=$#parts;$count++) {
11083: $path.="/$parts[$count]";
11084: if (!-e $path) {
11085: print $logfile "\nCreating directory ".$path;
11086: mkdir($path,02770);
11087: }
11088: }
11089: my $versionresult;
11090: if (-e $copyfile) {
11091: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11092: } else {
11093: $versionresult = 'ok';
11094: }
11095: if ($versionresult eq 'ok') {
11096: if (copy($source,$copyfile)) {
11097: print $logfile "\nCopied original source to ".$copyfile."\n";
11098: $output = 'ok';
11099: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11100: push(@{$modified_urls},[$copyfile,$source]);
11101: my $metaoutput =
11102: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11103: unless ($registered_cleanup) {
11104: my $handlers = $r->get_handlers('PerlCleanupHandler');
11105: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11106: $registered_cleanup=1;
11107: }
1.9 raeburn 11108: } else {
11109: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11110: $output = &mt('Failed to copy file to RES space').", $!";
11111: }
11112: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11113: my $inputfile = $filepath.'/'.$file;
11114: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11115: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11116: if ($fullwidth ne '' && $fullheight ne '') {
11117: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11118: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 11119: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11120: system({$args[0]} @args);
1.16 raeburn 11121: chmod(0660, $filepath.'/tn-'.$file);
11122: if (-e $outfile) {
11123: my $copyfile=$targetdir.'/tn-'.$file;
11124: if (copy($outfile,$copyfile)) {
11125: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11126: my $thumb_metaoutput =
11127: &write_metadata($dom,$confname,$formname,
11128: $targetdir,'tn-'.$file,$logfile);
11129: push(@{$modified_urls},[$copyfile,$outfile]);
11130: unless ($registered_cleanup) {
11131: my $handlers = $r->get_handlers('PerlCleanupHandler');
11132: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11133: $registered_cleanup=1;
11134: }
1.16 raeburn 11135: } else {
11136: print $logfile "\nUnable to write ".$copyfile.
11137: ':'.$!."\n";
11138: }
11139: }
1.9 raeburn 11140: }
11141: }
11142: }
11143: } else {
11144: $output = $versionresult;
11145: }
11146: }
11147: return ($output,$logourl);
11148: }
11149:
11150: sub logo_versioning {
11151: my ($targetdir,$file,$logfile) = @_;
11152: my $target = $targetdir.'/'.$file;
11153: my ($maxversion,$fn,$extn,$output);
11154: $maxversion = 0;
11155: if ($file =~ /^(.+)\.(\w+)$/) {
11156: $fn=$1;
11157: $extn=$2;
11158: }
11159: opendir(DIR,$targetdir);
11160: while (my $filename=readdir(DIR)) {
11161: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11162: $maxversion=($1>$maxversion)?$1:$maxversion;
11163: }
11164: }
11165: $maxversion++;
11166: print $logfile "\nCreating old version ".$maxversion."\n";
11167: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11168: if (copy($target,$copyfile)) {
11169: print $logfile "Copied old target to ".$copyfile."\n";
11170: $copyfile=$copyfile.'.meta';
11171: if (copy($target.'.meta',$copyfile)) {
11172: print $logfile "Copied old target metadata to ".$copyfile."\n";
11173: $output = 'ok';
11174: } else {
11175: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11176: $output = &mt('Failed to copy old meta').", $!, ";
11177: }
11178: } else {
11179: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11180: $output = &mt('Failed to copy old target').", $!, ";
11181: }
11182: return $output;
11183: }
11184:
11185: sub write_metadata {
11186: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11187: my (%metadatafields,%metadatakeys,$output);
11188: $metadatafields{'title'}=$formname;
11189: $metadatafields{'creationdate'}=time;
11190: $metadatafields{'lastrevisiondate'}=time;
11191: $metadatafields{'copyright'}='public';
11192: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11193: $env{'user.domain'};
11194: $metadatafields{'authorspace'}=$confname.':'.$dom;
11195: $metadatafields{'domain'}=$dom;
11196: {
11197: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11198: my $mfh;
1.160.6.88 raeburn 11199: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 11200: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11201: unless ($_=~/\./) {
11202: my $unikey=$_;
11203: $unikey=~/^([A-Za-z]+)/;
11204: my $tag=$1;
11205: $tag=~tr/A-Z/a-z/;
11206: print $mfh "\n\<$tag";
11207: foreach (split(/\,/,$metadatakeys{$unikey})) {
11208: my $value=$metadatafields{$unikey.'.'.$_};
11209: $value=~s/\"/\'\'/g;
11210: print $mfh ' '.$_.'="'.$value.'"';
11211: }
11212: print $mfh '>'.
11213: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11214: .'</'.$tag.'>';
11215: }
11216: }
11217: $output = 'ok';
11218: print $logfile "\nWrote metadata";
11219: close($mfh);
11220: } else {
11221: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11222: $output = &mt('Could not write metadata');
11223: }
11224: }
1.155 raeburn 11225: return $output;
11226: }
11227:
11228: sub notifysubscribed {
11229: foreach my $targetsource (@{$modified_urls}){
11230: next unless (ref($targetsource) eq 'ARRAY');
11231: my ($target,$source)=@{$targetsource};
11232: if ($source ne '') {
1.160.6.88 raeburn 11233: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11234: print $logfh "\nCleanup phase: Notifications\n";
11235: my @subscribed=&subscribed_hosts($target);
11236: foreach my $subhost (@subscribed) {
11237: print $logfh "\nNotifying host ".$subhost.':';
11238: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11239: print $logfh $reply;
11240: }
11241: my @subscribedmeta=&subscribed_hosts("$target.meta");
11242: foreach my $subhost (@subscribedmeta) {
11243: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11244: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11245: $subhost);
11246: print $logfh $reply;
11247: }
11248: print $logfh "\n============ Done ============\n";
1.160 raeburn 11249: close($logfh);
1.155 raeburn 11250: }
11251: }
11252: }
11253: return OK;
11254: }
11255:
11256: sub subscribed_hosts {
11257: my ($target) = @_;
11258: my @subscribed;
1.160.6.88 raeburn 11259: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11260: while (my $subline=<$fh>) {
11261: if ($subline =~ /^($match_lonid):/) {
11262: my $host = $1;
11263: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11264: unless (grep(/^\Q$host\E$/,@subscribed)) {
11265: push(@subscribed,$host);
11266: }
11267: }
11268: }
11269: }
11270: }
11271: return @subscribed;
1.9 raeburn 11272: }
11273:
11274: sub check_switchserver {
11275: my ($dom,$confname) = @_;
11276: my ($allowed,$switchserver);
11277: my $home = &Apache::lonnet::homeserver($confname,$dom);
11278: if ($home eq 'no_host') {
11279: $home = &Apache::lonnet::domain($dom,'primary');
11280: }
11281: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11282: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11283: if (!$allowed) {
1.160.6.11 raeburn 11284: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11285: }
11286: return $switchserver;
11287: }
11288:
1.1 raeburn 11289: sub modify_quotas {
1.160.6.30 raeburn 11290: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11291: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 11292: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 11293: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11294: $validationfieldsref);
1.86 raeburn 11295: if ($action eq 'quotas') {
11296: $context = 'tools';
1.160.6.26 raeburn 11297: } else {
1.86 raeburn 11298: $context = $action;
11299: }
11300: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 11301: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 11302: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11303: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11304: %titles = &courserequest_titles();
11305: $toolregexp = join('|',@usertools);
11306: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 11307: $confname = $dom.'-domainconfig';
11308: my $servadm = $r->dir_config('lonAdmEMail');
11309: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 11310: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11311: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 11312: } elsif ($context eq 'requestauthor') {
11313: @usertools = ('author');
11314: %titles = &authorrequest_titles();
1.86 raeburn 11315: } else {
1.160.6.4 raeburn 11316: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11317: %titles = &tool_titles();
1.86 raeburn 11318: }
1.160.6.27 raeburn 11319: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11320: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11321: foreach my $key (keys(%env)) {
1.101 raeburn 11322: if ($context eq 'requestcourses') {
11323: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11324: my $item = $1;
11325: my $type = $2;
11326: if ($type =~ /^limit_(.+)/) {
11327: $limithash{$item}{$1} = $env{$key};
11328: } else {
11329: $confhash{$item}{$type} = $env{$key};
11330: }
11331: }
1.160.6.5 raeburn 11332: } elsif ($context eq 'requestauthor') {
11333: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11334: $confhash{$1} = $env{$key};
11335: }
1.101 raeburn 11336: } else {
1.86 raeburn 11337: if ($key =~ /^form\.quota_(.+)$/) {
11338: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 11339: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11340: $confhash{'authorquota'}{$1} = $env{$key};
11341: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11342: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11343: }
1.72 raeburn 11344: }
11345: }
1.160.6.5 raeburn 11346: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 11347: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11348: @approvalnotify = sort(@approvalnotify);
11349: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 11350: my @crstypes = ('official','unofficial','community','textbook');
11351: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11352: foreach my $type (@hasuniquecode) {
11353: if (grep(/^\Q$type\E$/,@crstypes)) {
11354: $confhash{'uniquecode'}{$type} = 1;
11355: }
11356: }
1.160.6.46 raeburn 11357: my (%newbook,%allpos);
1.160.6.30 raeburn 11358: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11359: foreach my $type ('textbooks','templates') {
11360: @{$allpos{$type}} = ();
11361: my $invalid;
11362: if ($type eq 'textbooks') {
11363: $invalid = &mt('Invalid LON-CAPA course for textbook');
11364: } else {
11365: $invalid = &mt('Invalid LON-CAPA course for template');
11366: }
11367: if ($env{'form.'.$type.'_addbook'}) {
11368: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11369: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11370: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11371: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11372: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11373: } else {
11374: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11375: my $position = $env{'form.'.$type.'_addbook_pos'};
11376: $position =~ s/\D+//g;
11377: if ($position ne '') {
11378: $allpos{$type}[$position] = $newbook{$type};
11379: }
1.160.6.30 raeburn 11380: }
1.160.6.46 raeburn 11381: } else {
11382: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 11383: }
11384: }
1.160.6.46 raeburn 11385: }
1.160.6.30 raeburn 11386: }
1.102 raeburn 11387: if (ref($domconfig{$action}) eq 'HASH') {
11388: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11389: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11390: $changes{'notify'}{'approval'} = 1;
11391: }
11392: } else {
1.144 raeburn 11393: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11394: $changes{'notify'}{'approval'} = 1;
11395: }
11396: }
1.160.6.30 raeburn 11397: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11398: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11399: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11400: unless ($confhash{'uniquecode'}{$crstype}) {
11401: $changes{'uniquecode'} = 1;
11402: }
11403: }
11404: unless ($changes{'uniquecode'}) {
11405: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11406: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11407: $changes{'uniquecode'} = 1;
11408: }
11409: }
11410: }
11411: } else {
11412: $changes{'uniquecode'} = 1;
11413: }
11414: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11415: $changes{'uniquecode'} = 1;
11416: }
11417: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11418: foreach my $type ('textbooks','templates') {
11419: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11420: my %deletions;
11421: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11422: if (@todelete) {
11423: map { $deletions{$_} = 1; } @todelete;
11424: }
11425: my %imgdeletions;
11426: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11427: if (@todeleteimages) {
11428: map { $imgdeletions{$_} = 1; } @todeleteimages;
11429: }
11430: my $maxnum = $env{'form.'.$type.'_maxnum'};
11431: for (my $i=0; $i<=$maxnum; $i++) {
11432: my $itemid = $env{'form.'.$type.'_id_'.$i};
11433: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11434: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11435: if ($deletions{$key}) {
11436: if ($domconfig{$action}{$type}{$key}{'image'}) {
11437: #FIXME need to obsolete item in RES space
11438: }
11439: next;
11440: } else {
11441: my $newpos = $env{'form.'.$itemid};
11442: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 11443: foreach my $item ('subject','title','publisher','author') {
11444: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11445: ($type eq 'templates'));
1.160.6.46 raeburn 11446: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11447: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11448: $changes{$type}{$key} = 1;
11449: }
11450: }
11451: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 11452: }
1.160.6.46 raeburn 11453: if ($imgdeletions{$key}) {
11454: $changes{$type}{$key} = 1;
11455: #FIXME need to obsolete item in RES space
11456: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11457: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 11458: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11459: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11460: } else {
11461: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11462: $cdom,$cnum,$type,$configuserok,
11463: $switchserver,$author_ok);
11464: if ($imgurl) {
11465: $confhash{$type}{$key}{'image'} = $imgurl;
11466: $changes{$type}{$key} = 1;
11467: }
11468: if ($error) {
11469: &Apache::lonnet::logthis($error);
11470: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11471: }
1.160.6.46 raeburn 11472: }
11473: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11474: $confhash{$type}{$key}{'image'} =
11475: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 11476: }
11477: }
11478: }
11479: }
11480: }
11481: }
1.102 raeburn 11482: } else {
1.144 raeburn 11483: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11484: $changes{'notify'}{'approval'} = 1;
11485: }
1.160.6.30 raeburn 11486: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11487: $changes{'uniquecode'} = 1;
11488: }
11489: }
11490: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11491: foreach my $type ('textbooks','templates') {
11492: if ($newbook{$type}) {
11493: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 11494: foreach my $item ('subject','title','publisher','author') {
11495: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11496: ($type eq 'template'));
1.160.6.46 raeburn 11497: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11498: if ($env{'form.'.$type.'_addbook_'.$item}) {
11499: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11500: }
11501: }
11502: if ($type eq 'textbooks') {
11503: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11504: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 11505: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11506: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11507: } else {
11508: my ($imageurl,$error) =
11509: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11510: $configuserok,$switchserver,$author_ok);
11511: if ($imageurl) {
11512: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11513: }
11514: if ($error) {
11515: &Apache::lonnet::logthis($error);
11516: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11517: }
1.160.6.46 raeburn 11518: }
11519: }
1.160.6.30 raeburn 11520: }
11521: }
1.160.6.46 raeburn 11522: if (@{$allpos{$type}} > 0) {
11523: my $idx = 0;
11524: foreach my $item (@{$allpos{$type}}) {
11525: if ($item ne '') {
11526: $confhash{$type}{$item}{'order'} = $idx;
11527: if (ref($domconfig{$action}) eq 'HASH') {
11528: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11529: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11530: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11531: $changes{$type}{$item} = 1;
11532: }
1.160.6.30 raeburn 11533: }
11534: }
11535: }
1.160.6.46 raeburn 11536: $idx ++;
1.160.6.30 raeburn 11537: }
11538: }
11539: }
11540: }
1.160.6.39 raeburn 11541: if (ref($validationitemsref) eq 'ARRAY') {
11542: foreach my $item (@{$validationitemsref}) {
11543: if ($item eq 'fields') {
11544: my @changed;
11545: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11546: if (@{$confhash{'validation'}{$item}} > 0) {
11547: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11548: }
1.160.6.65 raeburn 11549: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11550: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11551: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11552: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11553: $domconfig{'requestcourses'}{'validation'}{$item});
11554: } else {
11555: @changed = @{$confhash{'validation'}{$item}};
11556: }
1.160.6.39 raeburn 11557: } else {
11558: @changed = @{$confhash{'validation'}{$item}};
11559: }
11560: } else {
11561: @changed = @{$confhash{'validation'}{$item}};
11562: }
11563: if (@changed) {
11564: if ($confhash{'validation'}{$item}) {
11565: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11566: } else {
11567: $changes{'validation'}{$item} = &mt('None');
11568: }
11569: }
11570: } else {
11571: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11572: if ($item eq 'markup') {
11573: if ($env{'form.requestcourses_validation_'.$item}) {
11574: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11575: }
11576: }
1.160.6.65 raeburn 11577: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11578: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11579: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11580: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11581: }
11582: } else {
11583: if ($confhash{'validation'}{$item} ne '') {
11584: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11585: }
1.160.6.39 raeburn 11586: }
11587: } else {
11588: if ($confhash{'validation'}{$item} ne '') {
11589: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11590: }
11591: }
11592: }
11593: }
11594: }
11595: if ($env{'form.validationdc'}) {
11596: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11597: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11598: if (exists($domcoords{$newval})) {
11599: $confhash{'validation'}{'dc'} = $newval;
11600: }
11601: }
11602: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11603: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11604: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11605: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11606: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11607: if ($confhash{'validation'}{'dc'} eq '') {
11608: $changes{'validation'}{'dc'} = &mt('None');
11609: } else {
11610: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11611: }
1.160.6.39 raeburn 11612: }
1.160.6.65 raeburn 11613: } elsif ($confhash{'validation'}{'dc'} ne '') {
11614: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11615: }
11616: } elsif ($confhash{'validation'}{'dc'} ne '') {
11617: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11618: }
11619: } elsif ($confhash{'validation'}{'dc'} ne '') {
11620: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11621: }
1.160.6.65 raeburn 11622: } else {
11623: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11624: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11625: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11626: $changes{'validation'}{'dc'} = &mt('None');
11627: }
11628: }
1.160.6.39 raeburn 11629: }
11630: }
1.102 raeburn 11631: }
11632: } else {
1.86 raeburn 11633: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 11634: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11635: }
1.72 raeburn 11636: foreach my $item (@usertools) {
11637: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11638: my $unset;
1.101 raeburn 11639: if ($context eq 'requestcourses') {
1.104 raeburn 11640: $unset = '0';
11641: if ($type eq '_LC_adv') {
11642: $unset = '';
11643: }
1.101 raeburn 11644: if ($confhash{$item}{$type} eq 'autolimit') {
11645: $confhash{$item}{$type} .= '=';
11646: unless ($limithash{$item}{$type} =~ /\D/) {
11647: $confhash{$item}{$type} .= $limithash{$item}{$type};
11648: }
11649: }
1.160.6.5 raeburn 11650: } elsif ($context eq 'requestauthor') {
11651: $unset = '0';
11652: if ($type eq '_LC_adv') {
11653: $unset = '';
11654: }
1.72 raeburn 11655: } else {
1.101 raeburn 11656: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11657: $confhash{$item}{$type} = 1;
11658: } else {
11659: $confhash{$item}{$type} = 0;
11660: }
1.72 raeburn 11661: }
1.86 raeburn 11662: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 11663: if ($action eq 'requestauthor') {
11664: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11665: $changes{$type} = 1;
11666: }
11667: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11668: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11669: $changes{$item}{$type} = 1;
11670: }
11671: } else {
11672: if ($context eq 'requestcourses') {
1.104 raeburn 11673: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11674: $changes{$item}{$type} = 1;
11675: }
11676: } else {
11677: if (!$confhash{$item}{$type}) {
11678: $changes{$item}{$type} = 1;
11679: }
11680: }
11681: }
11682: } else {
11683: if ($context eq 'requestcourses') {
1.104 raeburn 11684: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11685: $changes{$item}{$type} = 1;
11686: }
1.160.6.5 raeburn 11687: } elsif ($context eq 'requestauthor') {
11688: if ($confhash{$type} ne $unset) {
11689: $changes{$type} = 1;
11690: }
1.72 raeburn 11691: } else {
11692: if (!$confhash{$item}{$type}) {
11693: $changes{$item}{$type} = 1;
11694: }
11695: }
11696: }
1.1 raeburn 11697: }
11698: }
1.160.6.5 raeburn 11699: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11700: if (ref($domconfig{'quotas'}) eq 'HASH') {
11701: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11702: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11703: if (exists($confhash{'defaultquota'}{$key})) {
11704: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11705: $changes{'defaultquota'}{$key} = 1;
11706: }
11707: } else {
11708: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11709: }
11710: }
1.86 raeburn 11711: } else {
11712: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11713: if (exists($confhash{'defaultquota'}{$key})) {
11714: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11715: $changes{'defaultquota'}{$key} = 1;
11716: }
11717: } else {
11718: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11719: }
1.1 raeburn 11720: }
11721: }
1.160.6.20 raeburn 11722: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11723: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11724: if (exists($confhash{'authorquota'}{$key})) {
11725: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11726: $changes{'authorquota'}{$key} = 1;
11727: }
11728: } else {
11729: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11730: }
11731: }
11732: }
1.1 raeburn 11733: }
1.86 raeburn 11734: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11735: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11736: if (ref($domconfig{'quotas'}) eq 'HASH') {
11737: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11738: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11739: $changes{'defaultquota'}{$key} = 1;
11740: }
11741: } else {
11742: if (!exists($domconfig{'quotas'}{$key})) {
11743: $changes{'defaultquota'}{$key} = 1;
11744: }
1.72 raeburn 11745: }
11746: } else {
1.86 raeburn 11747: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11748: }
1.1 raeburn 11749: }
11750: }
1.160.6.20 raeburn 11751: if (ref($confhash{'authorquota'}) eq 'HASH') {
11752: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11753: if (ref($domconfig{'quotas'}) eq 'HASH') {
11754: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11755: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11756: $changes{'authorquota'}{$key} = 1;
11757: }
11758: } else {
11759: $changes{'authorquota'}{$key} = 1;
11760: }
11761: } else {
11762: $changes{'authorquota'}{$key} = 1;
11763: }
11764: }
11765: }
1.1 raeburn 11766: }
1.72 raeburn 11767:
1.160.6.5 raeburn 11768: if ($context eq 'requestauthor') {
11769: $domdefaults{'requestauthor'} = \%confhash;
11770: } else {
11771: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 11772: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 11773: $domdefaults{$key} = $confhash{$key};
11774: }
1.160.6.5 raeburn 11775: }
1.72 raeburn 11776: }
1.160.6.5 raeburn 11777:
1.1 raeburn 11778: my %quotahash = (
1.86 raeburn 11779: $action => { %confhash }
1.1 raeburn 11780: );
11781: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11782: $dom);
11783: if ($putresult eq 'ok') {
11784: if (keys(%changes) > 0) {
1.72 raeburn 11785: my $cachetime = 24*60*60;
11786: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11787: if (ref($lastactref) eq 'HASH') {
11788: $lastactref->{'domdefaults'} = 1;
11789: }
1.1 raeburn 11790: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 11791: unless (($context eq 'requestcourses') ||
11792: ($context eq 'requestauthor')) {
1.86 raeburn 11793: if (ref($changes{'defaultquota'}) eq 'HASH') {
11794: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11795: foreach my $type (@{$types},'default') {
11796: if (defined($changes{'defaultquota'}{$type})) {
11797: my $typetitle = $usertypes->{$type};
11798: if ($type eq 'default') {
11799: $typetitle = $othertitle;
11800: }
1.160.6.28 raeburn 11801: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11802: }
11803: }
1.86 raeburn 11804: $resulttext .= '</ul></li>';
1.72 raeburn 11805: }
1.160.6.20 raeburn 11806: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 11807: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 11808: foreach my $type (@{$types},'default') {
11809: if (defined($changes{'authorquota'}{$type})) {
11810: my $typetitle = $usertypes->{$type};
11811: if ($type eq 'default') {
11812: $typetitle = $othertitle;
11813: }
1.160.6.28 raeburn 11814: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 11815: }
11816: }
11817: $resulttext .= '</ul></li>';
11818: }
1.72 raeburn 11819: }
1.80 raeburn 11820: my %newenv;
1.72 raeburn 11821: foreach my $item (@usertools) {
1.160.6.5 raeburn 11822: my (%haschgs,%inconf);
11823: if ($context eq 'requestauthor') {
11824: %haschgs = %changes;
11825: %inconf = %confhash;
11826: } else {
11827: if (ref($changes{$item}) eq 'HASH') {
11828: %haschgs = %{$changes{$item}};
11829: }
11830: if (ref($confhash{$item}) eq 'HASH') {
11831: %inconf = %{$confhash{$item}};
11832: }
11833: }
11834: if (keys(%haschgs) > 0) {
1.80 raeburn 11835: my $newacc =
11836: &Apache::lonnet::usertools_access($env{'user.name'},
11837: $env{'user.domain'},
1.86 raeburn 11838: $item,'reload',$context);
1.160.6.5 raeburn 11839: if (($context eq 'requestcourses') ||
11840: ($context eq 'requestauthor')) {
1.108 raeburn 11841: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11842: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11843: }
11844: } else {
11845: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11846: $newenv{'environment.availabletools.'.$item} = $newacc;
11847: }
1.80 raeburn 11848: }
1.160.6.5 raeburn 11849: unless ($context eq 'requestauthor') {
11850: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11851: }
1.72 raeburn 11852: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 11853: if ($haschgs{$type}) {
1.72 raeburn 11854: my $typetitle = $usertypes->{$type};
11855: if ($type eq 'default') {
11856: $typetitle = $othertitle;
11857: } elsif ($type eq '_LC_adv') {
11858: $typetitle = 'LON-CAPA Advanced Users';
11859: }
1.160.6.5 raeburn 11860: if ($inconf{$type}) {
1.101 raeburn 11861: if ($context eq 'requestcourses') {
11862: my $cond;
1.160.6.5 raeburn 11863: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11864: if ($1 eq '') {
11865: $cond = &mt('(Automatic processing of any request).');
11866: } else {
11867: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11868: }
11869: } else {
1.160.6.5 raeburn 11870: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11871: }
11872: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 11873: } elsif ($context eq 'requestauthor') {
11874: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11875: $titles{$inconf{$type}},$typetitle);
11876:
1.101 raeburn 11877: } else {
11878: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11879: }
1.72 raeburn 11880: } else {
1.104 raeburn 11881: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 11882: if ($inconf{$type} eq '0') {
1.104 raeburn 11883: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11884: } else {
11885: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11886: }
11887: } else {
11888: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11889: }
1.72 raeburn 11890: }
11891: }
1.26 raeburn 11892: }
1.160.6.5 raeburn 11893: unless ($context eq 'requestauthor') {
11894: $resulttext .= '</ul></li>';
11895: }
1.26 raeburn 11896: }
1.1 raeburn 11897: }
1.160.6.5 raeburn 11898: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11899: if (ref($changes{'notify'}) eq 'HASH') {
11900: if ($changes{'notify'}{'approval'}) {
11901: if (ref($confhash{'notify'}) eq 'HASH') {
11902: if ($confhash{'notify'}{'approval'}) {
11903: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11904: } else {
1.160.6.5 raeburn 11905: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11906: }
11907: }
11908: }
11909: }
11910: }
1.160.6.30 raeburn 11911: if ($action eq 'requestcourses') {
11912: my @offon = ('off','on');
11913: if ($changes{'uniquecode'}) {
11914: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11915: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11916: $resulttext .= '<li>'.
11917: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11918: '</li>';
11919: } else {
11920: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11921: '</li>';
11922: }
11923: }
1.160.6.46 raeburn 11924: foreach my $type ('textbooks','templates') {
11925: if (ref($changes{$type}) eq 'HASH') {
11926: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11927: foreach my $key (sort(keys(%{$changes{$type}}))) {
11928: my %coursehash = &Apache::lonnet::coursedescription($key);
11929: my $coursetitle = $coursehash{'description'};
11930: my $position = $confhash{$type}{$key}{'order'} + 1;
11931: $resulttext .= '<li>';
1.160.6.47 raeburn 11932: foreach my $item ('subject','title','publisher','author') {
11933: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11934: ($type eq 'templates'));
1.160.6.46 raeburn 11935: my $name = $item.':';
11936: $name =~ s/^(\w)/\U$1/;
11937: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11938: }
11939: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11940: if ($type eq 'textbooks') {
11941: if ($confhash{$type}{$key}{'image'}) {
11942: $resulttext .= ' '.&mt('Image: [_1]',
11943: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11944: ' alt="Textbook cover" />').'<br />';
11945: }
11946: }
11947: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 11948: }
1.160.6.46 raeburn 11949: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 11950: }
11951: }
1.160.6.39 raeburn 11952: if (ref($changes{'validation'}) eq 'HASH') {
11953: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11954: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11955: foreach my $item (@{$validationitemsref}) {
11956: if (exists($changes{'validation'}{$item})) {
11957: if ($item eq 'markup') {
11958: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11959: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11960: } else {
11961: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11962: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11963: }
11964: }
11965: }
11966: if (exists($changes{'validation'}{'dc'})) {
11967: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11968: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11969: }
11970: }
11971: }
1.160.6.30 raeburn 11972: }
1.1 raeburn 11973: $resulttext .= '</ul>';
1.80 raeburn 11974: if (keys(%newenv)) {
11975: &Apache::lonnet::appenv(\%newenv);
11976: }
1.1 raeburn 11977: } else {
1.86 raeburn 11978: if ($context eq 'requestcourses') {
11979: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 11980: } elsif ($context eq 'requestauthor') {
11981: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11982: } else {
1.90 weissno 11983: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11984: }
1.1 raeburn 11985: }
11986: } else {
1.11 albertel 11987: $resulttext = '<span class="LC_error">'.
11988: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11989: }
1.160.6.30 raeburn 11990: if ($errors) {
11991: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11992: '<ul>'.$errors.'</ul></p>';
11993: }
1.3 raeburn 11994: return $resulttext;
1.1 raeburn 11995: }
11996:
1.160.6.30 raeburn 11997: sub process_textbook_image {
1.160.6.46 raeburn 11998: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 11999: my $filename = $env{'form.'.$caller.'.filename'};
12000: my ($error,$url);
12001: my ($width,$height) = (50,50);
12002: if ($configuserok eq 'ok') {
12003: if ($switchserver) {
12004: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12005: $switchserver);
12006: } elsif ($author_ok eq 'ok') {
12007: my ($result,$imageurl) =
12008: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 12009: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 12010: if ($result eq 'ok') {
12011: $url = $imageurl;
12012: } else {
12013: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12014: }
12015: } else {
12016: $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);
12017: }
12018: } else {
12019: $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);
12020: }
12021: return ($url,$error);
12022: }
12023:
1.160.6.118.2 1(raebur 12024:1): sub modify_ltitools {
12025:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12026:1): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12027:1): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12028:1): my $confname = $dom.'-domainconfig';
12029:1): my $servadm = $r->dir_config('lonAdmEMail');
12030:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12031:1): my (%posslti,%possfield);
12032:1): my @courseroles = ('cc','in','ta','ep','st');
12033:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12034:1): map { $posslti{$_} = 1; } @ltiroles;
12035:1): my @allfields = ('fullname','firstname','lastname','email','user','roles');
12036:1): map { $possfield{$_} = 1; } @allfields;
12037:1): my %lt = <itools_names();
12038:1): if ($env{'form.ltitools_add'}) {
12039:1): my $title = $env{'form.ltitools_add_title'};
12040:1): $title =~ s/(`)/'/g;
12041:1): ($newid,my $error) = &get_ltitools_id($dom,$title);
12042:1): if ($newid) {
12043:1): my $position = $env{'form.ltitools_add_pos'};
12044:1): $position =~ s/\D+//g;
12045:1): if ($position ne '') {
12046:1): $allpos[$position] = $newid;
12047:1): }
12048:1): $changes{$newid} = 1;
12049:1): foreach my $item ('title','url','key','secret','lifetime') {
12050:1): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12051:1): if ($item eq 'lifetime') {
12052:1): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12053:1): }
12054:1): if ($env{'form.ltitools_add_'.$item}) {
12055:1): if (($item eq 'key') || ($item eq 'secret')) {
12056:1): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12057:1): } else {
12058:1): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12059:1): }
12060:1): }
12061:1): }
12062:1): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12063:1): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12064:1): }
12065:1): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12066:1): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12067:1): }
12068:1): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12069:1): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12070:1): } else {
12071:1): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12072:1): }
12073:1): foreach my $item ('width','height','linktext','explanation') {
12074:1): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12075:1): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12076:1): if (($item eq 'width') || ($item eq 'height')) {
12077:1): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12078:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12079:1): }
12080:1): } else {
12081:1): if ($env{'form.ltitools_add_'.$item} ne '') {
12082:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12083:1): }
12084:1): }
12085:1): }
12086:1): if ($env{'form.ltitools_add_target'} eq 'window') {
12087:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12088:1): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12089:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12090:1): } else {
12091:1): $confhash{$newid}{'display'}{'target'} = 'iframe';
12092:1): }
12093:1): if ($env{'form.ltitools_add_image.filename'} ne '') {
12094:1): my ($imageurl,$error) =
12095:1): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12096:1): $configuserok,$switchserver,$author_ok);
12097:1): if ($imageurl) {
12098:1): $confhash{$newid}{'image'} = $imageurl;
12099:1): }
12100:1): if ($error) {
12101:1): &Apache::lonnet::logthis($error);
12102:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12103:1): }
12104:1): }
12105:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12106:1): foreach my $field (@fields) {
12107:1): if ($possfield{$field}) {
12108:1): if ($field eq 'roles') {
12109:1): foreach my $role (@courseroles) {
12110:1): my $choice = $env{'form.ltitools_add_roles_'.$role};
12111:1): if (($choice ne '') && ($posslti{$choice})) {
12112:1): $confhash{$newid}{'roles'}{$role} = $choice;
12113:1): if ($role eq 'cc') {
12114:1): $confhash{$newid}{'roles'}{'co'} = $choice;
12115:1): }
12116:1): }
12117:1): }
12118:1): } else {
12119:1): $confhash{$newid}{'fields'}{$field} = 1;
12120:1): }
12121:1): }
12122:1): }
12123:1): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12124:1): if ($confhash{$newid}{'fields'}{'user'}) {
12125:1): if ($env{'form.ltitools_userincdom_add'}) {
12126:1): $confhash{$newid}{'incdom'} = 1;
12127:1): }
12128:1): }
12129:1): }
12130:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12131:1): foreach my $item (@courseconfig) {
12132:1): $confhash{$newid}{'crsconf'}{$item} = 1;
12133:1): }
12134:1): if ($env{'form.ltitools_add_custom'}) {
12135:1): my $name = $env{'form.ltitools_add_custom_name'};
12136:1): my $value = $env{'form.ltitools_add_custom_value'};
12137:1): $value =~ s/(`)/'/g;
12138:1): $name =~ s/(`)/'/g;
12139:1): $confhash{$newid}{'custom'}{$name} = $value;
12140:1): }
12141:1): } else {
12142:1): my $error = &mt('Failed to acquire unique ID for new external tool');
12143:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12144:1): }
12145:1): }
12146:1): if (ref($domconfig{$action}) eq 'HASH') {
12147:1): my %deletions;
12148:1): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12149:1): if (@todelete) {
12150:1): map { $deletions{$_} = 1; } @todelete;
12151:1): }
12152:1): my %customadds;
12153:1): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12154:1): if (@newcustom) {
12155:1): map { $customadds{$_} = 1; } @newcustom;
12156:1): }
12157:1): my %imgdeletions;
12158:1): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12159:1): if (@todeleteimages) {
12160:1): map { $imgdeletions{$_} = 1; } @todeleteimages;
12161:1): }
12162:1): my $maxnum = $env{'form.ltitools_maxnum'};
12163:1): for (my $i=0; $i<=$maxnum; $i++) {
12164:1): my $itemid = $env{'form.ltitools_id_'.$i};
12165:1): $itemid =~ s/\D+//g;
12166:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12167:1): if ($deletions{$itemid}) {
12168:1): if ($domconfig{$action}{$itemid}{'image'}) {
12169:1): #FIXME need to obsolete item in RES space
12170:1): }
12171:1): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12172:1): next;
12173:1): } else {
12174:1): my $newpos = $env{'form.ltitools_'.$itemid};
12175:1): $newpos =~ s/\D+//g;
12176:1): foreach my $item ('title','url','lifetime') {
12177:1): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12178:1): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12179:1): $changes{$itemid} = 1;
12180:1): }
12181:1): }
12182:1): foreach my $item ('key','secret') {
12183:1): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12184:1): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12185:1): $changes{$itemid} = 1;
12186:1): }
12187:1): }
12188:1): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12189:1): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12190:1): }
12191:1): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12192:1): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12193:1): }
12194:1): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12195:1): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12196:1): } else {
12197:1): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12198:1): }
12199:1): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12200:1): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12201:1): $changes{$itemid} = 1;
12202:1): }
12203:1): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12204:1): $changes{$itemid} = 1;
12205:1): }
12206:1): foreach my $size ('width','height') {
12207:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12208:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12209:1): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12210:1): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12211:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12212:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12213:1): $changes{$itemid} = 1;
12214:1): }
12215:1): } else {
12216:1): $changes{$itemid} = 1;
12217:1): }
12218:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12219:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12220:1): $changes{$itemid} = 1;
12221:1): }
12222:1): }
12223:1): }
12224:1): foreach my $item ('linktext','explanation') {
12225:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12226:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12227:1): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12228:1): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12229:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12230:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12231:1): $changes{$itemid} = 1;
12232:1): }
12233:1): } else {
12234:1): $changes{$itemid} = 1;
12235:1): }
12236:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12237:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12238:1): $changes{$itemid} = 1;
12239:1): }
12240:1): }
12241:1): }
12242:1): if ($env{'form.ltitools_target_'.$i} eq 'window') {
12243:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12244:1): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12245:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12246:1): } else {
12247:1): $confhash{$itemid}{'display'}{'target'} = 'iframe';
12248:1): }
12249:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12250:1): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12251:1): $changes{$itemid} = 1;
12252:1): }
12253:1): } else {
12254:1): $changes{$itemid} = 1;
12255:1): }
12256:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12257:1): foreach my $item ('label','title','target','linktext','explanation','append') {
12258:1): if (grep(/^\Q$item\E$/,@courseconfig)) {
12259:1): $confhash{$itemid}{'crsconf'}{$item} = 1;
12260:1): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12261:1): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12262:1): $changes{$itemid} = 1;
12263:1): }
12264:1): } else {
12265:1): $changes{$itemid} = 1;
12266:1): }
12267:1): }
12268:1): }
12269:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12270:1): foreach my $field (@fields) {
12271:1): if ($possfield{$field}) {
12272:1): if ($field eq 'roles') {
12273:1): foreach my $role (@courseroles) {
12274:1): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12275:1): if (($choice ne '') && ($posslti{$choice})) {
12276:1): $confhash{$itemid}{'roles'}{$role} = $choice;
12277:1): if ($role eq 'cc') {
12278:1): $confhash{$itemid}{'roles'}{'co'} = $choice;
12279:1): }
12280:1): }
12281:1): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12282:1): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12283:1): $changes{$itemid} = 1;
12284:1): }
12285:1): } elsif ($confhash{$itemid}{'roles'}{$role}) {
12286:1): $changes{$itemid} = 1;
12287:1): }
12288:1): }
12289:1): } else {
12290:1): $confhash{$itemid}{'fields'}{$field} = 1;
12291:1): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12292:1): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12293:1): $changes{$itemid} = 1;
12294:1): }
12295:1): } else {
12296:1): $changes{$itemid} = 1;
12297:1): }
12298:1): }
12299:1): }
12300:1): }
12301:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12302:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12303:1): if ($env{'form.ltitools_userincdom_'.$i}) {
12304:1): $confhash{$itemid}{'incdom'} = 1;
12305:1): }
12306:1): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12307:1): $changes{$itemid} = 1;
12308:1): }
12309:1): }
12310:1): }
12311:1): $allpos[$newpos] = $itemid;
12312:1): }
12313:1): if ($imgdeletions{$itemid}) {
12314:1): $changes{$itemid} = 1;
12315:1): #FIXME need to obsolete item in RES space
12316:1): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12317:1): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12318:1): $itemid,$configuserok,$switchserver,
12319:1): $author_ok);
12320:1): if ($imgurl) {
12321:1): $confhash{$itemid}{'image'} = $imgurl;
12322:1): $changes{$itemid} = 1;
12323:1): }
12324:1): if ($error) {
12325:1): &Apache::lonnet::logthis($error);
12326:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12327:1): }
12328:1): } elsif ($domconfig{$action}{$itemid}{'image'}) {
12329:1): $confhash{$itemid}{'image'} =
12330:1): $domconfig{$action}{$itemid}{'image'};
12331:1): }
12332:1): if ($customadds{$i}) {
12333:1): my $name = $env{'form.ltitools_custom_name_'.$i};
12334:1): $name =~ s/(`)/'/g;
12335:1): $name =~ s/^\s+//;
12336:1): $name =~ s/\s+$//;
12337:1): my $value = $env{'form.ltitools_custom_value_'.$i};
12338:1): $value =~ s/(`)/'/g;
12339:1): $value =~ s/^\s+//;
12340:1): $value =~ s/\s+$//;
12341:1): if ($name ne '') {
12342:1): $confhash{$itemid}{'custom'}{$name} = $value;
12343:1): $changes{$itemid} = 1;
12344:1): }
12345:1): }
12346:1): my %customdels;
12347:1): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12348:1): if (@customdeletions) {
12349:1): $changes{$itemid} = 1;
12350:1): }
12351:1): map { $customdels{$_} = 1; } @customdeletions;
12352:1): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12353:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12354:1): unless ($customdels{$key}) {
12355:1): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12356:1): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12357:1): }
12358:1): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12359:1): $changes{$itemid} = 1;
12360:1): }
12361:1): }
12362:1): }
12363:1): }
12364:1): unless ($changes{$itemid}) {
12365:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12366:1): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12367:1): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12368:1): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12369:1): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12370:1): $changes{$itemid} = 1;
12371:1): last;
12372:1): }
12373:1): }
12374:1): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12375:1): $changes{$itemid} = 1;
12376:1): }
12377:1): }
12378:1): last if ($changes{$itemid});
12379:1): }
12380:1): }
12381:1): }
12382:1): }
12383:1): }
12384:1): if (@allpos > 0) {
12385:1): my $idx = 0;
12386:1): foreach my $itemid (@allpos) {
12387:1): if ($itemid ne '') {
12388:1): $confhash{$itemid}{'order'} = $idx;
12389:1): if (ref($domconfig{$action}) eq 'HASH') {
12390:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12391:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12392:1): $changes{$itemid} = 1;
12393:1): }
12394:1): }
12395:1): }
12396:1): $idx ++;
12397:1): }
12398:1): }
12399:1): }
12400:1): my %ltitoolshash = (
12401:1): $action => { %confhash }
12402:1): );
12403:1): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12404:1): $dom);
12405:1): if ($putresult eq 'ok') {
12406:1): my %ltienchash = (
12407:1): $action => { %encconfig }
12408:1): );
12409:1): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12410:1): if (keys(%changes) > 0) {
12411:1): my $cachetime = 24*60*60;
12412:1): my %ltiall = %confhash;
12413:1): foreach my $id (keys(%ltiall)) {
12414:1): if (ref($encconfig{$id}) eq 'HASH') {
12415:1): foreach my $item ('key','secret') {
12416:1): $ltiall{$id}{$item} = $encconfig{$id}{$item};
12417:1): }
12418:1): }
12419:1): }
12420:1): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12421:1): if (ref($lastactref) eq 'HASH') {
12422:1): $lastactref->{'ltitools'} = 1;
12423:1): }
12424:1): $resulttext = &mt('Changes made:').'<ul>';
12425:1): my %bynum;
12426:1): foreach my $itemid (sort(keys(%changes))) {
12427:1): my $position = $confhash{$itemid}{'order'};
12428:1): $bynum{$position} = $itemid;
12429:1): }
12430:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12431:1): my $itemid = $bynum{$pos};
12432:1): if (ref($confhash{$itemid}) ne 'HASH') {
12433:1): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12434:1): } else {
12435:1): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12436:1): if ($confhash{$itemid}{'image'}) {
12437:1): $resulttext .= ' '.
12438:1): '<img src="'.$confhash{$itemid}{'image'}.'"'.
12439:1): ' alt="'.&mt('Tool Provider icon').'" />';
12440:1): }
12441:1): $resulttext .= '</li><ul>';
12442:1): my $position = $pos + 1;
12443:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12444:1): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12445:1): if ($confhash{$itemid}{$item} ne '') {
12446:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12447:1): }
12448:1): }
12449:1): if ($encconfig{$itemid}{'key'} ne '') {
12450:1): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12451:1): }
12452:1): if ($encconfig{$itemid}{'secret'} ne '') {
12453:1): $resulttext .= '<li>'.$lt{'secret'}.': ';
12454:1): my $num = length($encconfig{$itemid}{'secret'});
12455:1): $resulttext .= ('*'x$num).'</li>';
12456:1): }
12457:1): $resulttext .= '<li>'.&mt('Configurable in course:');
12458:1): my @possconfig = ('label','title','target','linktext','explanation','append');
12459:1): my $numconfig = 0;
12460:1): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12461:1): foreach my $item (@possconfig) {
12462:1): if ($confhash{$itemid}{'crsconf'}{$item}) {
12463:1): $numconfig ++;
12464:1): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12465:1): }
12466:1): }
12467:1): }
12468:1): if (!$numconfig) {
12469:1): $resulttext .= &mt('None');
12470:1): }
12471:1): $resulttext .= '</li>';
12472:1): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12473:1): my $displaylist;
12474:1): if ($confhash{$itemid}{'display'}{'target'}) {
12475:1): $displaylist = &mt('Display target').': '.
12476:1): $confhash{$itemid}{'display'}{'target'}.',';
12477:1): }
12478:1): foreach my $size ('width','height') {
12479:1): if ($confhash{$itemid}{'display'}{$size}) {
12480:1): $displaylist .= (' 'x2).$lt{$size}.': '.
12481:1): $confhash{$itemid}{'display'}{$size}.',';
12482:1): }
12483:1): }
12484:1): if ($displaylist) {
12485:1): $displaylist =~ s/,$//;
12486:1): $resulttext .= '<li>'.$displaylist.'</li>';
12487:1): }
12488:1): foreach my $item ('linktext','explanation') {
12489:1): if ($confhash{$itemid}{'display'}{$item}) {
12490:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12491:1): }
12492:1): }
12493:1): }
12494:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12495:1): my $fieldlist;
12496:1): foreach my $field (@allfields) {
12497:1): if ($confhash{$itemid}{'fields'}{$field}) {
12498:1): $fieldlist .= (' 'x2).$lt{$field}.',';
12499:1): }
12500:1): }
12501:1): if ($fieldlist) {
12502:1): $fieldlist =~ s/,$//;
12503:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12504:1): if ($confhash{$itemid}{'incdom'}) {
12505:1): $fieldlist .= ' ('.&mt('username:domain').')';
12506:1): } else {
12507:1): $fieldlist .= ' ('.&mt('username').')';
12508:1): }
12509:1): }
12510:1): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12511:1): }
12512:1): }
12513:1): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12514:1): my $rolemaps;
12515:1): foreach my $role (@courseroles) {
12516:1): if ($confhash{$itemid}{'roles'}{$role}) {
12517:1): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12518:1): $confhash{$itemid}{'roles'}{$role}.',';
12519:1): }
12520:1): }
12521:1): if ($rolemaps) {
12522:1): $rolemaps =~ s/,$//;
12523:1): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12524:1): }
12525:1): }
12526:1): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12527:1): my $customlist;
12528:1): if (keys(%{$confhash{$itemid}{'custom'}})) {
12529:1): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12530:1): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12531:1): }
12532:1): }
12533:1): if ($customlist) {
12534:1): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12535:1): }
12536:1): }
12537:1): $resulttext .= '</ul></li>';
12538:1): }
12539:1): }
12540:1): $resulttext .= '</ul>';
12541:1): } else {
12542:1): $resulttext = &mt('No changes made.');
12543:1): }
12544:1): } else {
12545:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12546:1): }
12547:1): if ($errors) {
12548:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12549:1): $errors.'</ul>';
12550:1): }
12551:1): return $resulttext;
12552:1): }
12553:1):
12554:1): sub process_ltitools_image {
12555:1): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12556:1): my $filename = $env{'form.'.$caller.'.filename'};
12557:1): my ($error,$url);
12558:1): my ($width,$height) = (21,21);
12559:1): if ($configuserok eq 'ok') {
12560:1): if ($switchserver) {
12561:1): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12562:1): $switchserver);
12563:1): } elsif ($author_ok eq 'ok') {
12564:1): my ($result,$imageurl,$madethumb) =
12565:1): &publishlogo($r,'upload',$caller,$dom,$confname,
12566:1): "ltitools/$itemid/icon",$width,$height);
12567:1): if ($result eq 'ok') {
12568:1): if ($madethumb) {
12569:1): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12570:1): my $imagethumb = "$path/tn-".$imagefile;
12571:1): $url = $imagethumb;
12572:1): } else {
12573:1): $url = $imageurl;
12574:1): }
12575:1): } else {
12576:1): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12577:1): }
12578:1): } else {
12579: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);
12580:1): }
12581:1): } else {
12582: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);
12583:1): }
12584:1): return ($url,$error);
12585:1): }
12586:1):
12587:1): sub get_ltitools_id {
12588:1): my ($cdom,$title) = @_;
12589:1): # get lock on ltitools db
12590:1): my $lockhash = {
12591:1): lock => $env{'user.name'}.
12592:1): ':'.$env{'user.domain'},
12593:1): };
12594:1): my $tries = 0;
12595:1): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12596:1): my ($id,$error);
12597:1):
12598:1): while (($gotlock ne 'ok') && ($tries<10)) {
12599:1): $tries ++;
12600:1): sleep (0.1);
12601:1): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12602:1): }
12603:1): if ($gotlock eq 'ok') {
12604:1): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12605:1): if ($currids{'lock'}) {
12606:1): delete($currids{'lock'});
12607:1): if (keys(%currids)) {
12608:1): my @curr = sort { $a <=> $b } keys(%currids);
12609:1): if ($curr[-1] =~ /^\d+$/) {
12610:1): $id = 1 + $curr[-1];
12611:1): }
12612:1): } else {
12613:1): $id = 1;
12614:1): }
12615:1): if ($id) {
12616:1): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12617:1): $error = 'nostore';
12618:1): }
12619:1): } else {
12620:1): $error = 'nonumber';
12621:1): }
12622:1): }
12623:1): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12624:1): } else {
12625:1): $error = 'nolock';
12626:1): }
12627:1): return ($id,$error);
12628:1): }
12629:1):
1.3 raeburn 12630: sub modify_autoenroll {
1.160.6.24 raeburn 12631: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12632: my ($resulttext,%changes);
12633: my %currautoenroll;
12634: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12635: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12636: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12637: }
12638: }
12639: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12640: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12641: sender => 'Sender for notification messages',
1.160.6.68 raeburn 12642: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 12643: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12644: my @offon = ('off','on');
1.17 raeburn 12645: my $sender_uname = $env{'form.sender_uname'};
12646: my $sender_domain = $env{'form.sender_domain'};
12647: if ($sender_domain eq '') {
12648: $sender_uname = '';
12649: } elsif ($sender_uname eq '') {
12650: $sender_domain = '';
12651: }
1.129 raeburn 12652: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 12653: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
12654: $autofailsafe =~ s{^\s+|\s+$}{}g;
12655: if ($autofailsafe =~ /\D/) {
12656: undef($autofailsafe);
12657: }
1.160.6.68 raeburn 12658: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 12659: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
12660: $failsafe = 'off';
12661: undef($autofailsafe);
1.160.6.68 raeburn 12662: }
1.1 raeburn 12663: my %autoenrollhash = (
1.129 raeburn 12664: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12665: 'sender_uname' => $sender_uname,
12666: 'sender_domain' => $sender_domain,
12667: 'co-owners' => $coowners,
1.160.6.116 raeburn 12668: 'autofailsafe' => $autofailsafe,
12669: 'failsafe' => $failsafe,
1.1 raeburn 12670: }
12671: );
1.4 raeburn 12672: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12673: $dom);
1.1 raeburn 12674: if ($putresult eq 'ok') {
12675: if (exists($currautoenroll{'run'})) {
12676: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12677: $changes{'run'} = 1;
12678: }
12679: } elsif ($autorun) {
12680: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12681: $changes{'run'} = 1;
1.1 raeburn 12682: }
12683: }
1.17 raeburn 12684: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12685: $changes{'sender'} = 1;
12686: }
1.17 raeburn 12687: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12688: $changes{'sender'} = 1;
12689: }
1.129 raeburn 12690: if ($currautoenroll{'co-owners'} ne '') {
12691: if ($currautoenroll{'co-owners'} ne $coowners) {
12692: $changes{'coowners'} = 1;
12693: }
12694: } elsif ($coowners) {
12695: $changes{'coowners'} = 1;
1.160.6.68 raeburn 12696: }
1.160.6.116 raeburn 12697: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 12698: $changes{'autofailsafe'} = 1;
12699: }
1.160.6.116 raeburn 12700: if ($currautoenroll{'failsafe'} ne $failsafe) {
12701: $changes{'failsafe'} = 1;
12702: }
1.1 raeburn 12703: if (keys(%changes) > 0) {
12704: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12705: if ($changes{'run'}) {
1.1 raeburn 12706: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12707: }
12708: if ($changes{'sender'}) {
1.17 raeburn 12709: if ($sender_uname eq '' || $sender_domain eq '') {
12710: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12711: } else {
12712: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12713: }
1.1 raeburn 12714: }
1.129 raeburn 12715: if ($changes{'coowners'}) {
12716: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12717: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12718: if (ref($lastactref) eq 'HASH') {
12719: $lastactref->{'domainconfig'} = 1;
12720: }
1.129 raeburn 12721: }
1.160.6.68 raeburn 12722: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 12723: if ($autofailsafe ne '') {
12724: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 12725: } else {
1.160.6.116 raeburn 12726: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 12727: }
1.160.6.116 raeburn 12728: }
12729: if ($changes{'failsafe'}) {
12730: if ($failsafe eq 'off') {
12731: unless ($changes{'autofailsafe'}) {
12732: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
12733: }
12734: } elsif ($failsafe eq 'zero') {
12735: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
12736: } else {
12737: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
12738: }
12739: }
12740: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 12741: &Apache::lonnet::get_domain_defaults($dom,1);
12742: if (ref($lastactref) eq 'HASH') {
12743: $lastactref->{'domdefaults'} = 1;
12744: }
12745: }
1.1 raeburn 12746: $resulttext .= '</ul>';
12747: } else {
12748: $resulttext = &mt('No changes made to auto-enrollment settings');
12749: }
12750: } else {
1.11 albertel 12751: $resulttext = '<span class="LC_error">'.
12752: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12753: }
1.3 raeburn 12754: return $resulttext;
1.1 raeburn 12755: }
12756:
12757: sub modify_autoupdate {
1.3 raeburn 12758: my ($dom,%domconfig) = @_;
1.1 raeburn 12759: my ($resulttext,%currautoupdate,%fields,%changes);
12760: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12761: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12762: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12763: }
12764: }
12765: my @offon = ('off','on');
12766: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 12767: run => 'Auto-update:',
12768: classlists => 'Updates to user information in classlists?',
12769: unexpired => 'Skip updates for users without active or future roles?',
12770: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 12771: );
1.44 raeburn 12772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12773: my %fieldtitles = &Apache::lonlocal::texthash (
12774: id => 'Student/Employee ID',
1.20 raeburn 12775: permanentemail => 'E-mail address',
1.1 raeburn 12776: lastname => 'Last Name',
12777: firstname => 'First Name',
12778: middlename => 'Middle Name',
1.132 raeburn 12779: generation => 'Generation',
1.1 raeburn 12780: );
1.142 raeburn 12781: $othertitle = &mt('All users');
1.1 raeburn 12782: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12783: $othertitle = &mt('Other users');
1.1 raeburn 12784: }
12785: foreach my $key (keys(%env)) {
12786: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12787: my ($usertype,$item) = ($1,$2);
12788: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12789: if ($usertype eq 'default') {
12790: push(@{$fields{$1}},$2);
12791: } elsif (ref($types) eq 'ARRAY') {
12792: if (grep(/^\Q$usertype\E$/,@{$types})) {
12793: push(@{$fields{$1}},$2);
12794: }
12795: }
12796: }
1.1 raeburn 12797: }
12798: }
1.131 raeburn 12799: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12800: @lockablenames = sort(@lockablenames);
12801: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12802: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12803: if (@changed) {
12804: $changes{'lockablenames'} = 1;
12805: }
12806: } else {
12807: if (@lockablenames) {
12808: $changes{'lockablenames'} = 1;
12809: }
12810: }
1.1 raeburn 12811: my %updatehash = (
12812: autoupdate => { run => $env{'form.autoupdate_run'},
12813: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 12814: unexpired => $env{'form.unexpired'},
1.1 raeburn 12815: fields => {%fields},
1.131 raeburn 12816: lockablenames => \@lockablenames,
1.1 raeburn 12817: }
12818: );
1.160.6.113 raeburn 12819: my $lastactivedays;
12820: if ($env{'form.lastactive'}) {
12821: $lastactivedays = $env{'form.lastactivedays'};
12822: $lastactivedays =~ s/^\s+|\s+$//g;
12823: unless ($lastactivedays =~ /^\d+$/) {
12824: undef($lastactivedays);
12825: $env{'form.lastactive'} = 0;
12826: }
12827: }
12828: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 12829: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 12830: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 12831: if (exists($updatehash{autoupdate}{$key})) {
12832: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12833: $changes{$key} = 1;
12834: }
12835: }
12836: } elsif ($key eq 'fields') {
12837: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12838: foreach my $item (@{$types},'default') {
1.1 raeburn 12839: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12840: my $change = 0;
12841: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12842: if (!exists($fields{$item})) {
12843: $change = 1;
1.132 raeburn 12844: last;
1.1 raeburn 12845: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12846: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12847: $change = 1;
1.132 raeburn 12848: last;
1.1 raeburn 12849: }
12850: }
12851: }
12852: if ($change) {
12853: push(@{$changes{$key}},$item);
12854: }
1.26 raeburn 12855: }
1.1 raeburn 12856: }
12857: }
1.131 raeburn 12858: } elsif ($key eq 'lockablenames') {
12859: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12860: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12861: if (@changed) {
12862: $changes{'lockablenames'} = 1;
12863: }
12864: } else {
12865: if (@lockablenames) {
12866: $changes{'lockablenames'} = 1;
12867: }
12868: }
12869: }
12870: }
12871: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
12872: if (@lockablenames) {
12873: $changes{'lockablenames'} = 1;
1.1 raeburn 12874: }
12875: }
1.160.6.113 raeburn 12876: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
12877: if ($updatehash{'autoupdate'}{'unexpired'}) {
12878: $changes{'unexpired'} = 1;
12879: }
12880: }
12881: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
12882: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
12883: $changes{'lastactive'} = 1;
12884: }
12885: }
1.26 raeburn 12886: foreach my $item (@{$types},'default') {
12887: if (defined($fields{$item})) {
12888: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 12889: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
12890: my $change = 0;
12891: if (ref($fields{$item}) eq 'ARRAY') {
12892: foreach my $type (@{$fields{$item}}) {
12893: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
12894: $change = 1;
12895: last;
12896: }
12897: }
12898: }
12899: if ($change) {
12900: push(@{$changes{'fields'}},$item);
12901: }
12902: } else {
1.26 raeburn 12903: push(@{$changes{'fields'}},$item);
12904: }
12905: } else {
12906: push(@{$changes{'fields'}},$item);
1.1 raeburn 12907: }
12908: }
12909: }
12910: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
12911: $dom);
12912: if ($putresult eq 'ok') {
12913: if (keys(%changes) > 0) {
12914: $resulttext = &mt('Changes made:').'<ul>';
12915: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 12916: if ($key eq 'lockablenames') {
12917: $resulttext .= '<li>';
12918: if (@lockablenames) {
12919: $usertypes->{'default'} = $othertitle;
12920: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
12921: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
12922: } else {
12923: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
12924: }
12925: $resulttext .= '</li>';
12926: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 12927: foreach my $item (@{$changes{$key}}) {
12928: my @newvalues;
12929: foreach my $type (@{$fields{$item}}) {
12930: push(@newvalues,$fieldtitles{$type});
12931: }
1.3 raeburn 12932: my $newvaluestr;
12933: if (@newvalues > 0) {
12934: $newvaluestr = join(', ',@newvalues);
12935: } else {
12936: $newvaluestr = &mt('none');
1.6 raeburn 12937: }
1.1 raeburn 12938: if ($item eq 'default') {
1.26 raeburn 12939: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 12940: } else {
1.26 raeburn 12941: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 12942: }
12943: }
12944: } else {
12945: my $newvalue;
12946: if ($key eq 'run') {
12947: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 12948: } elsif ($key eq 'lastactive') {
12949: $newvalue = $offon[$env{'form.lastactive'}];
12950: unless ($lastactivedays eq '') {
12951: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
12952: }
1.1 raeburn 12953: } else {
12954: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 12955: }
1.1 raeburn 12956: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
12957: }
12958: }
12959: $resulttext .= '</ul>';
12960: } else {
1.3 raeburn 12961: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 12962: }
12963: } else {
1.11 albertel 12964: $resulttext = '<span class="LC_error">'.
12965: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12966: }
1.3 raeburn 12967: return $resulttext;
1.1 raeburn 12968: }
12969:
1.125 raeburn 12970: sub modify_autocreate {
12971: my ($dom,%domconfig) = @_;
12972: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
12973: if (ref($domconfig{'autocreate'}) eq 'HASH') {
12974: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
12975: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
12976: }
12977: }
12978: my %title= ( xml => 'Auto-creation of courses in XML course description files',
12979: req => 'Auto-creation of validated requests for official courses',
12980: xmldc => 'Identity of course creator of courses from XML files',
12981: );
12982: my @types = ('xml','req');
12983: foreach my $item (@types) {
12984: $newvals{$item} = $env{'form.autocreate_'.$item};
12985: $newvals{$item} =~ s/\D//g;
12986: $newvals{$item} = 0 if ($newvals{$item} eq '');
12987: }
12988: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 12989: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 12990: unless (exists($domcoords{$newvals{'xmldc'}})) {
12991: $newvals{'xmldc'} = '';
12992: }
12993: %autocreatehash = (
12994: autocreate => { xml => $newvals{'xml'},
12995: req => $newvals{'req'},
12996: }
12997: );
12998: if ($newvals{'xmldc'} ne '') {
12999: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13000: }
13001: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13002: $dom);
13003: if ($putresult eq 'ok') {
13004: my @items = @types;
13005: if ($newvals{'xml'}) {
13006: push(@items,'xmldc');
13007: }
13008: foreach my $item (@items) {
13009: if (exists($currautocreate{$item})) {
13010: if ($currautocreate{$item} ne $newvals{$item}) {
13011: $changes{$item} = 1;
13012: }
13013: } elsif ($newvals{$item}) {
13014: $changes{$item} = 1;
13015: }
13016: }
13017: if (keys(%changes) > 0) {
13018: my @offon = ('off','on');
13019: $resulttext = &mt('Changes made:').'<ul>';
13020: foreach my $item (@types) {
13021: if ($changes{$item}) {
13022: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 13023: $resulttext .= '<li>'.
13024: &mt("$title{$item} set to [_1]$newtxt [_2]",
13025: '<b>','</b>').
13026: '</li>';
1.125 raeburn 13027: }
13028: }
13029: if ($changes{'xmldc'}) {
13030: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13031: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 13032: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13033: }
13034: $resulttext .= '</ul>';
13035: } else {
13036: $resulttext = &mt('No changes made to auto-creation settings');
13037: }
13038: } else {
13039: $resulttext = '<span class="LC_error">'.
13040: &mt('An error occurred: [_1]',$putresult).'</span>';
13041: }
13042: return $resulttext;
13043: }
13044:
1.23 raeburn 13045: sub modify_directorysrch {
1.160.6.81 raeburn 13046: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13047: my ($resulttext,%changes);
13048: my %currdirsrch;
13049: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13050: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13051: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13052: }
13053: }
1.160.6.72 raeburn 13054: my %title = ( available => 'Institutional directory search available',
13055: localonly => 'Other domains can search institution',
13056: lcavailable => 'LON-CAPA directory search available',
13057: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13058: searchby => 'Search types',
13059: searchtypes => 'Search latitude');
13060: my @offon = ('off','on');
1.24 raeburn 13061: my @otherdoms = ('Yes','No');
1.23 raeburn 13062:
1.25 raeburn 13063: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13064: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13065: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13066:
1.44 raeburn 13067: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13068: if (keys(%{$usertypes}) == 0) {
13069: @cansearch = ('default');
13070: } else {
13071: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13072: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13073: if (!grep(/^\Q$type\E$/,@cansearch)) {
13074: push(@{$changes{'cansearch'}},$type);
13075: }
1.23 raeburn 13076: }
1.26 raeburn 13077: foreach my $type (@cansearch) {
13078: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13079: push(@{$changes{'cansearch'}},$type);
13080: }
1.23 raeburn 13081: }
1.26 raeburn 13082: } else {
13083: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13084: }
13085: }
13086:
13087: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13088: foreach my $by (@{$currdirsrch{'searchby'}}) {
13089: if (!grep(/^\Q$by\E$/,@searchby)) {
13090: push(@{$changes{'searchby'}},$by);
13091: }
13092: }
13093: foreach my $by (@searchby) {
13094: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13095: push(@{$changes{'searchby'}},$by);
13096: }
13097: }
13098: } else {
13099: push(@{$changes{'searchby'}},@searchby);
13100: }
1.25 raeburn 13101:
13102: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13103: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13104: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13105: push(@{$changes{'searchtypes'}},$type);
13106: }
13107: }
13108: foreach my $type (@searchtypes) {
13109: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13110: push(@{$changes{'searchtypes'}},$type);
13111: }
13112: }
13113: } else {
13114: if (exists($currdirsrch{'searchtypes'})) {
13115: foreach my $type (@searchtypes) {
13116: if ($type ne $currdirsrch{'searchtypes'}) {
13117: push(@{$changes{'searchtypes'}},$type);
13118: }
13119: }
13120: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13121: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13122: }
13123: } else {
13124: push(@{$changes{'searchtypes'}},@searchtypes);
13125: }
13126: }
13127:
1.23 raeburn 13128: my %dirsrch_hash = (
13129: directorysrch => { available => $env{'form.dirsrch_available'},
13130: cansearch => \@cansearch,
1.160.6.72 raeburn 13131: localonly => $env{'form.dirsrch_instlocalonly'},
13132: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13133: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13134: searchby => \@searchby,
1.25 raeburn 13135: searchtypes => \@searchtypes,
1.23 raeburn 13136: }
13137: );
13138: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13139: $dom);
13140: if ($putresult eq 'ok') {
13141: if (exists($currdirsrch{'available'})) {
13142: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13143: $changes{'available'} = 1;
13144: }
13145: } else {
13146: if ($env{'form.dirsrch_available'} eq '1') {
13147: $changes{'available'} = 1;
13148: }
13149: }
1.160.6.72 raeburn 13150: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 13151: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13152: $changes{'lcavailable'} = 1;
13153: }
1.24 raeburn 13154: } else {
1.160.6.72 raeburn 13155: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13156: $changes{'lcavailable'} = 1;
13157: }
13158: }
13159: if (exists($currdirsrch{'localonly'})) {
13160: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 13161: $changes{'localonly'} = 1;
13162: }
1.160.6.72 raeburn 13163: } else {
13164: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13165: $changes{'localonly'} = 1;
13166: }
13167: }
13168: if (exists($currdirsrch{'lclocalonly'})) {
13169: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13170: $changes{'lclocalonly'} = 1;
13171: }
13172: } else {
13173: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13174: $changes{'lclocalonly'} = 1;
13175: }
1.24 raeburn 13176: }
1.23 raeburn 13177: if (keys(%changes) > 0) {
13178: $resulttext = &mt('Changes made:').'<ul>';
13179: if ($changes{'available'}) {
13180: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13181: }
1.160.6.72 raeburn 13182: if ($changes{'lcavailable'}) {
13183: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13184: }
1.24 raeburn 13185: if ($changes{'localonly'}) {
1.160.6.72 raeburn 13186: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13187: }
13188: if ($changes{'lclocalonly'}) {
13189: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 13190: }
1.23 raeburn 13191: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13192: my $chgtext;
1.26 raeburn 13193: if (ref($usertypes) eq 'HASH') {
13194: if (keys(%{$usertypes}) > 0) {
13195: foreach my $type (@{$types}) {
13196: if (grep(/^\Q$type\E$/,@cansearch)) {
13197: $chgtext .= $usertypes->{$type}.'; ';
13198: }
13199: }
13200: if (grep(/^default$/,@cansearch)) {
13201: $chgtext .= $othertitle;
13202: } else {
13203: $chgtext =~ s/\; $//;
13204: }
1.160.6.13 raeburn 13205: $resulttext .=
13206: '<li>'.
13207: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13208: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13209: '</li>';
1.23 raeburn 13210: }
13211: }
13212: }
13213: if (ref($changes{'searchby'}) eq 'ARRAY') {
13214: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13215: my $chgtext;
13216: foreach my $type (@{$titleorder}) {
13217: if (grep(/^\Q$type\E$/,@searchby)) {
13218: if (defined($searchtitles->{$type})) {
13219: $chgtext .= $searchtitles->{$type}.'; ';
13220: }
13221: }
13222: }
13223: $chgtext =~ s/\; $//;
13224: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13225: }
1.25 raeburn 13226: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13227: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13228: my $chgtext;
13229: foreach my $type (@{$srchtypeorder}) {
13230: if (grep(/^\Q$type\E$/,@searchtypes)) {
13231: if (defined($srchtypes_desc->{$type})) {
13232: $chgtext .= $srchtypes_desc->{$type}.'; ';
13233: }
13234: }
13235: }
13236: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 13237: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13238: }
13239: $resulttext .= '</ul>';
1.160.6.81 raeburn 13240: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13241: if (ref($lastactref) eq 'HASH') {
13242: $lastactref->{'directorysrch'} = 1;
13243: }
1.23 raeburn 13244: } else {
1.160.6.72 raeburn 13245: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13246: }
13247: } else {
13248: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13249: &mt('An error occurred: [_1]',$putresult).'</span>';
13250: }
13251: return $resulttext;
13252: }
13253:
1.28 raeburn 13254: sub modify_contacts {
1.160.6.24 raeburn 13255: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13256: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13257: if (ref($domconfig{'contacts'}) eq 'HASH') {
13258: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13259: $currsetting{$key} = $domconfig{'contacts'}{$key};
13260: }
13261: }
1.160.6.78 raeburn 13262: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13263: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 13264: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 13265: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 13266: my @toggles = ('reporterrors','reportupdates','reportstatus');
13267: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 13268: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13269: foreach my $type (@mailings) {
13270: @{$newsetting{$type}} =
13271: &Apache::loncommon::get_env_multiple('form.'.$type);
13272: foreach my $item (@contacts) {
13273: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13274: $contacts_hash{contacts}{$type}{$item} = 1;
13275: } else {
13276: $contacts_hash{contacts}{$type}{$item} = 0;
13277: }
1.160.6.78 raeburn 13278: }
1.28 raeburn 13279: $others{$type} = $env{'form.'.$type.'_others'};
13280: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 13281: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13282: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13283: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 13284: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13285: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13286: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13287: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13288: }
1.134 raeburn 13289: }
1.28 raeburn 13290: }
13291: foreach my $item (@contacts) {
13292: $to{$item} = $env{'form.'.$item};
13293: $contacts_hash{'contacts'}{$item} = $to{$item};
13294: }
1.160.6.23 raeburn 13295: foreach my $item (@toggles) {
13296: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13297: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13298: }
13299: }
1.160.6.107 raeburn 13300: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13301: foreach my $item (@lonstatus) {
13302: if ($item eq 'excluded') {
13303: my (%serverhomes,@excluded);
13304: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13305: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13306: if (@possexcluded) {
13307: foreach my $id (sort(@possexcluded)) {
13308: if ($serverhomes{$id}) {
13309: push(@excluded,$id);
13310: }
13311: }
13312: }
13313: if (@excluded) {
13314: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13315: }
13316: } elsif ($item eq 'weights') {
13317: foreach my $type ('E','W','N','U') {
13318: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13319: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13320: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13321: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13322: $env{'form.error'.$item.'_'.$type};
13323: }
13324: }
13325: }
13326: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13327: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13328: if ($env{'form.error'.$item} =~ /^\d+$/) {
13329: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13330: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13331: }
13332: }
13333: }
13334: }
1.160.6.78 raeburn 13335: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13336: foreach my $field (@{$fields}) {
13337: if (ref($possoptions->{$field}) eq 'ARRAY') {
13338: my $value = $env{'form.helpform_'.$field};
13339: $value =~ s/^\s+|\s+$//g;
13340: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 13341: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 13342: if ($field eq 'screenshot') {
13343: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13344: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 13345: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 13346: }
13347: }
13348: }
13349: }
13350: }
13351: }
1.160.6.101 raeburn 13352: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13353: my (@statuses,%usertypeshash,@overrides);
13354: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13355: @statuses = @{$types};
13356: if (ref($usertypes) eq 'HASH') {
13357: %usertypeshash = %{$usertypes};
13358: }
13359: }
13360: if (@statuses) {
13361: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13362: foreach my $type (@possoverrides) {
13363: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13364: push(@overrides,$type);
13365: }
13366: }
13367: if (@overrides) {
13368: foreach my $type (@overrides) {
13369: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13370: foreach my $item (@contacts) {
13371: if (grep(/^\Q$item\E$/,@standard)) {
13372: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13373: $newsetting{'override_'.$type}{$item} = 1;
13374: } else {
13375: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13376: $newsetting{'override_'.$type}{$item} = 0;
13377: }
13378: }
13379: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13380: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13381: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13382: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13383: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13384: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13385: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13386: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13387: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13388: }
13389: }
13390: }
13391: }
1.28 raeburn 13392: if (keys(%currsetting) > 0) {
13393: foreach my $item (@contacts) {
13394: if ($to{$item} ne $currsetting{$item}) {
13395: $changes{$item} = 1;
13396: }
13397: }
13398: foreach my $type (@mailings) {
13399: foreach my $item (@contacts) {
13400: if (ref($currsetting{$type}) eq 'HASH') {
13401: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13402: push(@{$changes{$type}},$item);
13403: }
13404: } else {
13405: push(@{$changes{$type}},@{$newsetting{$type}});
13406: }
13407: }
13408: if ($others{$type} ne $currsetting{$type}{'others'}) {
13409: push(@{$changes{$type}},'others');
13410: }
1.160.6.78 raeburn 13411: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13412: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13413: push(@{$changes{$type}},'bcc');
13414: }
1.160.6.78 raeburn 13415: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13416: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13417: push(@{$changes{$type}},'include');
13418: }
13419: }
13420: }
13421: if (ref($fields) eq 'ARRAY') {
13422: if (ref($currsetting{'helpform'}) eq 'HASH') {
13423: foreach my $field (@{$fields}) {
13424: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13425: push(@{$changes{'helpform'}},$field);
13426: }
13427: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13428: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13429: push(@{$changes{'helpform'}},'maxsize');
13430: }
13431: }
13432: }
13433: } else {
13434: foreach my $field (@{$fields}) {
13435: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13436: push(@{$changes{'helpform'}},$field);
13437: }
13438: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13439: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13440: push(@{$changes{'helpform'}},'maxsize');
13441: }
13442: }
13443: }
1.134 raeburn 13444: }
1.28 raeburn 13445: }
1.160.6.101 raeburn 13446: if (@statuses) {
13447: if (ref($currsetting{'overrides'}) eq 'HASH') {
13448: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13449: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13450: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13451: foreach my $item (@contacts,'bcc','others','include') {
13452: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13453: push(@{$changes{'overrides'}},$key);
13454: last;
13455: }
13456: }
13457: } else {
13458: push(@{$changes{'overrides'}},$key);
13459: }
13460: }
13461: }
13462: foreach my $key (@overrides) {
13463: unless (exists($currsetting{'overrides'}{$key})) {
13464: push(@{$changes{'overrides'}},$key);
13465: }
13466: }
13467: } else {
13468: foreach my $key (@overrides) {
13469: push(@{$changes{'overrides'}},$key);
13470: }
13471: }
13472: }
1.160.6.107 raeburn 13473: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13474: foreach my $key ('excluded','weights','threshold','sysmail') {
13475: if ($key eq 'excluded') {
13476: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13477: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13478: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13479: (@{$currsetting{'lonstatus'}{$key}})) {
13480: my @diffs =
13481: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13482: $currsetting{'lonstatus'}{$key});
13483: if (@diffs) {
13484: push(@{$changes{'lonstatus'}},$key);
13485: }
13486: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13487: push(@{$changes{'lonstatus'}},$key);
13488: }
13489: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13490: (@{$currsetting{'lonstatus'}{$key}})) {
13491: push(@{$changes{'lonstatus'}},$key);
13492: }
13493: } elsif ($key eq 'weights') {
13494: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13495: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13496: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
13497: foreach my $type ('E','W','N','U') {
13498: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13499: $currsetting{'lonstatus'}{$key}{$type}) {
13500: push(@{$changes{'lonstatus'}},$key);
13501: last;
13502: }
13503: }
13504: } else {
13505: foreach my $type ('E','W','N','U') {
13506: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13507: push(@{$changes{'lonstatus'}},$key);
13508: last;
13509: }
13510: }
13511: }
13512: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
13513: foreach my $type ('E','W','N','U') {
13514: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13515: push(@{$changes{'lonstatus'}},$key);
13516: last;
13517: }
13518: }
13519: }
13520: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13521: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13522: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13523: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13524: push(@{$changes{'lonstatus'}},$key);
13525: }
13526: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13527: push(@{$changes{'lonstatus'}},$key);
13528: }
13529: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13530: push(@{$changes{'lonstatus'}},$key);
13531: }
13532: }
13533: }
13534: } else {
13535: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13536: foreach my $key ('excluded','weights','threshold','sysmail') {
13537: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13538: push(@{$changes{'lonstatus'}},$key);
13539: }
13540: }
13541: }
13542: }
1.28 raeburn 13543: } else {
13544: my %default;
13545: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13546: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13547: $default{'errormail'} = 'adminemail';
13548: $default{'packagesmail'} = 'adminemail';
13549: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 13550: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13551: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13552: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 13553: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 13554: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13555: foreach my $item (@contacts) {
13556: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 13557: $changes{$item} = 1;
1.160.6.23 raeburn 13558: }
1.28 raeburn 13559: }
13560: foreach my $type (@mailings) {
13561: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13562: push(@{$changes{$type}},@{$newsetting{$type}});
13563: }
13564: if ($others{$type} ne '') {
13565: push(@{$changes{$type}},'others');
1.134 raeburn 13566: }
1.160.6.78 raeburn 13567: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13568: if ($bcc{$type} ne '') {
13569: push(@{$changes{$type}},'bcc');
13570: }
1.160.6.78 raeburn 13571: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13572: push(@{$changes{$type}},'include');
13573: }
13574: }
13575: }
13576: if (ref($fields) eq 'ARRAY') {
13577: foreach my $field (@{$fields}) {
13578: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13579: push(@{$changes{'helpform'}},$field);
13580: }
13581: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13582: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13583: push(@{$changes{'helpform'}},'maxsize');
13584: }
13585: }
1.134 raeburn 13586: }
1.28 raeburn 13587: }
1.160.6.107 raeburn 13588: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13589: foreach my $key ('excluded','weights','threshold','sysmail') {
13590: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13591: push(@{$changes{'lonstatus'}},$key);
13592: }
13593: }
13594: }
1.28 raeburn 13595: }
1.160.6.23 raeburn 13596: foreach my $item (@toggles) {
13597: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13598: $changes{$item} = 1;
13599: } elsif ((!$env{'form.'.$item}) &&
13600: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13601: $changes{$item} = 1;
13602: }
13603: }
1.28 raeburn 13604: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13605: $dom);
13606: if ($putresult eq 'ok') {
13607: if (keys(%changes) > 0) {
1.160.6.24 raeburn 13608: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13609: if (ref($lastactref) eq 'HASH') {
13610: $lastactref->{'domainconfig'} = 1;
13611: }
1.28 raeburn 13612: my ($titles,$short_titles) = &contact_titles();
13613: $resulttext = &mt('Changes made:').'<ul>';
13614: foreach my $item (@contacts) {
13615: if ($changes{$item}) {
13616: $resulttext .= '<li>'.$titles->{$item}.
13617: &mt(' set to: ').
13618: '<span class="LC_cusr_emph">'.
13619: $to{$item}.'</span></li>';
13620: }
13621: }
13622: foreach my $type (@mailings) {
13623: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 13624: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
13625: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
13626: } else {
13627: $resulttext .= '<li>'.$titles->{$type}.': ';
13628: }
1.28 raeburn 13629: my @text;
13630: foreach my $item (@{$newsetting{$type}}) {
13631: push(@text,$short_titles->{$item});
13632: }
13633: if ($others{$type} ne '') {
13634: push(@text,$others{$type});
13635: }
1.160.6.78 raeburn 13636: if (@text) {
13637: $resulttext .= '<span class="LC_cusr_emph">'.
13638: join(', ',@text).'</span>';
13639: }
13640: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13641: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 13642: my $bcctext;
13643: if (@text) {
13644: $bcctext = ' '.&mt('with Bcc to');
13645: } else {
13646: $bcctext = '(Bcc)';
13647: }
13648: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13649: } elsif (!@text) {
13650: $resulttext .= &mt('No one');
1.134 raeburn 13651: }
1.160.6.78 raeburn 13652: if ($includestr{$type} ne '') {
13653: if ($includeloc{$type} eq 'b') {
13654: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13655: } elsif ($includeloc{$type} eq 's') {
13656: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13657: }
13658: }
13659: } elsif (!@text) {
13660: $resulttext .= &mt('No recipients');
1.134 raeburn 13661: }
13662: $resulttext .= '</li>';
1.28 raeburn 13663: }
13664: }
1.160.6.101 raeburn 13665: if (ref($changes{'overrides'}) eq 'ARRAY') {
13666: my @deletions;
13667: foreach my $type (@{$changes{'overrides'}}) {
13668: if ($usertypeshash{$type}) {
13669: if (grep(/^\Q$type\E/,@overrides)) {
13670: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13671: $usertypeshash{$type}).'<ul><li>';
13672: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13673: my @text;
13674: foreach my $item (@contacts) {
13675: if ($newsetting{'override_'.$type}{$item}) {
13676: push(@text,$short_titles->{$item});
13677: }
13678: }
13679: if ($newsetting{'override_'.$type}{'others'} ne '') {
13680: push(@text,$newsetting{'override_'.$type}{'others'});
13681: }
13682:
13683: if (@text) {
13684: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13685: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13686: }
13687: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13688: my $bcctext;
13689: if (@text) {
13690: $bcctext = ' '.&mt('with Bcc to');
13691: } else {
13692: $bcctext = '(Bcc)';
13693: }
13694: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13695: } elsif (!@text) {
13696: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13697: }
13698: $resulttext .= '</li>';
13699: if ($newsetting{'override_'.$type}{'include'} ne '') {
13700: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13701: if ($loc eq 'b') {
13702: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13703: } elsif ($loc eq 's') {
13704: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13705: }
13706: }
13707: }
13708: $resulttext .= '</li></ul></li>';
13709: } else {
13710: push(@deletions,$usertypeshash{$type});
13711: }
13712: }
13713: }
13714: if (@deletions) {
13715: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13716: join(', ',@deletions)).'</li>';
13717: }
13718: }
1.160.6.23 raeburn 13719: my @offon = ('off','on');
1.160.6.107 raeburn 13720: my $corelink = &core_link_msu();
1.160.6.23 raeburn 13721: if ($changes{'reporterrors'}) {
13722: $resulttext .= '<li>'.
13723: &mt('E-mail error reports to [_1] set to "'.
13724: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 13725: $corelink).
1.160.6.23 raeburn 13726: '</li>';
13727: }
13728: if ($changes{'reportupdates'}) {
13729: $resulttext .= '<li>'.
13730: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13731: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 13732: $corelink).
1.160.6.23 raeburn 13733: '</li>';
13734: }
1.160.6.107 raeburn 13735: if ($changes{'reportstatus'}) {
13736: $resulttext .= '<li>'.
13737: &mt('E-mail status if errors above threshold to [_1] set to "'.
13738: $offon[$env{'form.reportstatus'}].'".',
13739: $corelink).
13740: '</li>';
13741: }
13742: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13743: $resulttext .= '<li>'.
13744: &mt('Nightly status check e-mail settings').':<ul>';
13745: my (%defval,%use_def,%shown);
13746: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13747: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13748: $defval{'weights'} =
13749: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
13750: $defval{'excluded'} = &mt('None');
13751: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13752: foreach my $item ('threshold','sysmail','weights','excluded') {
13753: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13754: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13755: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13756: } elsif ($item eq 'weights') {
13757: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
13758: foreach my $type ('E','W','N','U') {
13759: $shown{$item} .= $lonstatus_names->{$type}.'=';
13760: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13761: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13762: } else {
13763: $shown{$item} .= $lonstatus_defs->{$type};
13764: }
13765: $shown{$item} .= ', ';
13766: }
13767: $shown{$item} =~ s/, $//;
13768: } else {
13769: $shown{$item} = $defval{$item};
13770: }
13771: } elsif ($item eq 'excluded') {
13772: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13773: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13774: } else {
13775: $shown{$item} = $defval{$item};
13776: }
13777: }
13778: } else {
13779: $shown{$item} = $defval{$item};
13780: }
13781: }
13782: } else {
13783: foreach my $item ('threshold','weights','excluded','sysmail') {
13784: $shown{$item} = $defval{$item};
13785: }
13786: }
13787: foreach my $item ('threshold','weights','excluded','sysmail') {
13788: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13789: $shown{$item}).'</li>';
13790: }
13791: $resulttext .= '</ul></li>';
13792: }
1.160.6.78 raeburn 13793: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13794: my (@optional,@required,@unused,$maxsizechg);
13795: foreach my $field (@{$changes{'helpform'}}) {
13796: if ($field eq 'maxsize') {
13797: $maxsizechg = 1;
13798: next;
13799: }
13800: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
13801: push(@optional,$field);
13802: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13803: push(@unused,$field);
13804: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
13805: push(@required,$field);
13806: }
13807: }
13808: if (@optional) {
13809: $resulttext .= '<li>'.
13810: &mt('Help form fields changed to "Optional": [_1].',
13811: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13812: '</li>';
13813: }
13814: if (@required) {
13815: $resulttext .= '<li>'.
13816: &mt('Help form fields changed to "Required": [_1].',
13817: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13818: '</li>';
13819: }
13820: if (@unused) {
13821: $resulttext .= '<li>'.
13822: &mt('Help form fields changed to "Not shown": [_1].',
13823: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13824: '</li>';
13825: }
13826: if ($maxsizechg) {
13827: $resulttext .= '<li>'.
13828: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13829: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13830: '</li>';
13831: }
13832: }
1.28 raeburn 13833: $resulttext .= '</ul>';
13834: } else {
1.160.6.78 raeburn 13835: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13836: }
13837: } else {
13838: $resulttext = '<span class="LC_error">'.
13839: &mt('An error occurred: [_1].',$putresult).'</span>';
13840: }
13841: return $resulttext;
13842: }
13843:
1.160.6.98 raeburn 13844: sub modify_passwords {
13845: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
13846: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
13847: $updatedefaults,$updateconf);
13848: my $customfn = 'resetpw.html';
13849: if (ref($domconfig{'passwords'}) eq 'HASH') {
13850: %current = %{$domconfig{'passwords'}};
13851: }
13852: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13853: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13854: if (ref($types) eq 'ARRAY') {
13855: @oktypes = @{$types};
13856: }
13857: push(@oktypes,'default');
13858:
13859: my %titles = &Apache::lonlocal::texthash (
13860: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
13861: intauth_check => 'Check bcrypt cost if authenticated',
13862: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
13863: permanent => 'Permanent e-mail address',
13864: critical => 'Critical notification address',
13865: notify => 'Notification address',
13866: min => 'Minimum password length',
13867: max => 'Maximum password length',
13868: chars => 'Required characters',
13869: numsaved => 'Number of previous passwords to save',
13870: reset => 'Resetting Forgotten Password',
13871: intauth => 'Encryption of Stored Passwords (Internal Auth)',
13872: rules => 'Rules for LON-CAPA Passwords',
13873: crsownerchg => 'Course Owner Changing Student Passwords',
13874: username => 'Username',
13875: email => 'E-mail address',
13876: );
13877:
13878: #
13879: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
13880: #
13881: my (%curr_defaults,%save_defaults);
13882: if (ref($domconfig{'defaults'}) eq 'HASH') {
13883: foreach my $key (keys(%{$domconfig{'defaults'}})) {
13884: if ($key =~ /^intauth_(cost|check|switch)$/) {
13885: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
13886: } else {
13887: $save_defaults{$key} = $domconfig{'defaults'}{$key};
13888: }
13889: }
13890: }
13891: my %staticdefaults = (
13892: 'resetlink' => 2,
13893: 'resetcase' => \@oktypes,
13894: 'resetprelink' => 'both',
13895: 'resetemail' => ['critical','notify','permanent'],
13896: 'intauth_cost' => 10,
13897: 'intauth_check' => 0,
13898: 'intauth_switch' => 0,
13899: );
1.160.6.99 raeburn 13900: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 13901: foreach my $type (@oktypes) {
13902: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
13903: }
13904: my $linklife = $env{'form.passwords_link'};
13905: $linklife =~ s/^\s+|\s+$//g;
13906: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
13907: $newvalues{'resetlink'} = $linklife;
13908: if ($current{'resetlink'}) {
13909: if ($current{'resetlink'} ne $linklife) {
13910: $changes{'reset'} = 1;
13911: }
1.160.6.102 raeburn 13912: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13913: if ($staticdefaults{'resetlink'} ne $linklife) {
13914: $changes{'reset'} = 1;
13915: }
13916: }
13917: } elsif ($current{'resetlink'}) {
13918: $changes{'reset'} = 1;
13919: }
13920: my @casesens;
13921: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
13922: foreach my $case (sort(@posscase)) {
13923: if (grep(/^\Q$case\E$/,@oktypes)) {
13924: push(@casesens,$case);
13925: }
13926: }
13927: $newvalues{'resetcase'} = \@casesens;
13928: if (ref($current{'resetcase'}) eq 'ARRAY') {
13929: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
13930: if (@diffs > 0) {
13931: $changes{'reset'} = 1;
13932: }
1.160.6.102 raeburn 13933: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13934: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
13935: if (@diffs > 0) {
13936: $changes{'reset'} = 1;
13937: }
13938: }
13939: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
13940: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
13941: if (exists($current{'resetprelink'})) {
13942: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
13943: $changes{'reset'} = 1;
13944: }
1.160.6.102 raeburn 13945: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13946: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
13947: $changes{'reset'} = 1;
13948: }
13949: }
13950: } elsif ($current{'resetprelink'}) {
13951: $changes{'reset'} = 1;
13952: }
13953: foreach my $type (@oktypes) {
13954: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
13955: my @postlink;
13956: foreach my $item (sort(@possplink)) {
13957: if ($item =~ /^(email|username)$/) {
13958: push(@postlink,$item);
13959: }
13960: }
13961: $newvalues{'resetpostlink'}{$type} = \@postlink;
13962: unless ($changes{'reset'}) {
13963: if (ref($current{'resetpostlink'}) eq 'HASH') {
13964: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
13965: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
13966: if (@diffs > 0) {
13967: $changes{'reset'} = 1;
13968: }
13969: } else {
13970: $changes{'reset'} = 1;
13971: }
1.160.6.102 raeburn 13972: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13973: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
13974: if (@diffs > 0) {
13975: $changes{'reset'} = 1;
13976: }
13977: }
13978: }
13979: }
13980: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
13981: my @resetemail;
13982: foreach my $item (sort(@possemailsrc)) {
13983: if ($item =~ /^(permanent|critical|notify)$/) {
13984: push(@resetemail,$item);
13985: }
13986: }
13987: $newvalues{'resetemail'} = \@resetemail;
13988: unless ($changes{'reset'}) {
13989: if (ref($current{'resetemail'}) eq 'ARRAY') {
13990: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
13991: if (@diffs > 0) {
13992: $changes{'reset'} = 1;
13993: }
1.160.6.102 raeburn 13994: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 13995: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
13996: if (@diffs > 0) {
13997: $changes{'reset'} = 1;
13998: }
13999: }
14000: }
14001: if ($env{'form.passwords_stdtext'} == 0) {
14002: $newvalues{'resetremove'} = 1;
14003: unless ($current{'resetremove'}) {
14004: $changes{'reset'} = 1;
14005: }
14006: } elsif ($current{'resetremove'}) {
14007: $changes{'reset'} = 1;
14008: }
14009: if ($env{'form.passwords_customfile.filename'} ne '') {
14010: my $servadm = $r->dir_config('lonAdmEMail');
14011: my $servadm = $r->dir_config('lonAdmEMail');
14012: my ($configuserok,$author_ok,$switchserver) =
14013: &config_check($dom,$confname,$servadm);
14014: my $error;
14015: if ($configuserok eq 'ok') {
14016: if ($switchserver) {
14017: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14018: } else {
14019: if ($author_ok eq 'ok') {
14020: my ($result,$customurl) =
14021: &publishlogo($r,'upload','passwords_customfile',$dom,
14022: $confname,'customtext/resetpw','','',$customfn);
14023: if ($result eq 'ok') {
14024: $newvalues{'resetcustom'} = $customurl;
14025: $changes{'reset'} = 1;
14026: } else {
14027: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14028: }
14029: } else {
14030: $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);
14031: }
14032: }
14033: } else {
14034: $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);
14035: }
14036: if ($error) {
14037: &Apache::lonnet::logthis($error);
14038: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14039: }
14040: } elsif ($current{'resetcustom'}) {
14041: if ($env{'form.passwords_custom_del'}) {
14042: $changes{'reset'} = 1;
14043: } else {
14044: $newvalues{'resetcustom'} = $current{'resetcustom'};
14045: }
14046: }
14047: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14048: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14049: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14050: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14051: $changes{'intauth'} = 1;
14052: }
14053: } else {
14054: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14055: }
14056: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14057: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14058: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14059: $changes{'intauth'} = 1;
14060: }
14061: } else {
14062: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14063: }
14064: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14065: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14066: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14067: $changes{'intauth'} = 1;
14068: }
14069: } else {
14070: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14071: }
14072: foreach my $item ('cost','check','switch') {
14073: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14074: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14075: $updatedefaults = 1;
14076: }
14077: }
14078: foreach my $rule ('min','max','numsaved') {
14079: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99 raeburn 14080: my $ruleok;
14081: if ($rule eq 'min') {
14082: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
14083: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
14084: $ruleok = 1;
14085: }
14086: }
14087: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
14088: ($env{'form.passwords_'.$rule} ne '0')) {
14089: $ruleok = 1;
14090: }
14091: if ($ruleok) {
1.160.6.98 raeburn 14092: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14093: if (exists($current{$rule})) {
14094: if ($newvalues{$rule} ne $current{$rule}) {
14095: $changes{'rules'} = 1;
14096: }
14097: } elsif ($rule eq 'min') {
14098: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14099: $changes{'rules'} = 1;
14100: }
1.160.6.104 raeburn 14101: } else {
14102: $changes{'rules'} = 1;
1.160.6.98 raeburn 14103: }
14104: } elsif (exists($current{$rule})) {
14105: $changes{'rules'} = 1;
14106: }
14107: }
14108: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14109: my @chars;
14110: foreach my $item (sort(@posschars)) {
14111: if ($item =~ /^(uc|lc|num|spec)$/) {
14112: push(@chars,$item);
14113: }
14114: }
14115: $newvalues{'chars'} = \@chars;
14116: unless ($changes{'rules'}) {
14117: if (ref($current{'chars'}) eq 'ARRAY') {
14118: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14119: if (@diffs > 0) {
14120: $changes{'rules'} = 1;
14121: }
14122: } else {
14123: if (@chars > 0) {
14124: $changes{'rules'} = 1;
14125: }
14126: }
14127: }
14128: my %crsownerchg = (
14129: by => [],
14130: for => [],
14131: );
14132: foreach my $item ('by','for') {
14133: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14134: foreach my $type (sort(@posstypes)) {
14135: if (grep(/^\Q$type\E$/,@oktypes)) {
14136: push(@{$crsownerchg{$item}},$type);
14137: }
14138: }
14139: }
14140: $newvalues{'crsownerchg'} = \%crsownerchg;
14141: if (ref($current{'crsownerchg'}) eq 'HASH') {
14142: foreach my $item ('by','for') {
14143: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14144: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14145: if (@diffs > 0) {
14146: $changes{'crsownerchg'} = 1;
14147: last;
14148: }
14149: }
14150: }
1.160.6.102 raeburn 14151: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 14152: foreach my $item ('by','for') {
14153: if (@{$crsownerchg{$item}} > 0) {
14154: $changes{'crsownerchg'} = 1;
14155: last;
14156: }
14157: }
14158: }
14159:
14160: my %confighash = (
14161: defaults => \%save_defaults,
14162: passwords => \%newvalues,
14163: );
14164: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14165:
14166: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14167: if ($putresult eq 'ok') {
14168: if (keys(%changes) > 0) {
14169: $resulttext = &mt('Changes made: ').'<ul>';
14170: foreach my $key ('reset','intauth','rules','crsownerchg') {
14171: if ($changes{$key}) {
14172: unless ($key eq 'intauth') {
14173: $updateconf = 1;
14174: }
14175: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14176: if ($key eq 'reset') {
14177: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14178: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14179: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14180: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 14181: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14182: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14183: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14184: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14185: }
1.160.6.98 raeburn 14186: } else {
14187: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14188: }
14189: if ($confighash{'passwords'}{'resetlink'}) {
14190: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14191: } else {
14192: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14193: &mt('Will default to 2 hours').'</li>';
14194: }
14195: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14196: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14197: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14198: } else {
14199: my $casesens;
14200: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14201: if ($type eq 'default') {
14202: $casesens .= $othertitle.', ';
14203: } elsif ($usertypes->{$type} ne '') {
14204: $casesens .= $usertypes->{$type}.', ';
14205: }
14206: }
14207: $casesens =~ s/\Q, \E$//;
14208: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14209: }
14210: } else {
14211: $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>';
14212: }
14213: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14214: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14215: } else {
14216: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14217: }
14218: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14219: my $output;
14220: if (ref($types) eq 'ARRAY') {
14221: foreach my $type (@{$types}) {
14222: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14223: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14224: $output .= $usertypes->{$type}.' -- '.&mt('none');
14225: } else {
14226: $output .= $usertypes->{$type}.' -- '.
14227: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14228: }
14229: }
14230: }
14231: }
14232: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14233: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14234: $output .= $othertitle.' -- '.&mt('none');
14235: } else {
14236: $output .= $othertitle.' -- '.
14237: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14238: }
14239: }
14240: if ($output) {
14241: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14242: } else {
14243: $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>';
14244: }
14245: } else {
14246: $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>';
14247: }
14248: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14249: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14250: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14251: } else {
14252: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14253: }
14254: } else {
1.160.6.110 raeburn 14255: $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 14256: }
14257: if ($confighash{'passwords'}{'resetremove'}) {
14258: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14259: } else {
14260: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14261: }
14262: if ($confighash{'passwords'}{'resetcustom'}) {
14263: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 14264: &mt('custom text'),600,500,undef,undef,
14265: undef,undef,'background-color:#ffffff');
14266: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 14267: } else {
14268: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14269: }
14270: } elsif ($key eq 'intauth') {
14271: foreach my $item ('cost','switch','check') {
14272: my $value = $save_defaults{$key.'_'.$item};
14273: if ($item eq 'switch') {
14274: my %optiondesc = &Apache::lonlocal::texthash (
14275: 0 => 'No',
14276: 1 => 'Yes',
14277: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14278: );
14279: if ($value =~ /^(0|1|2)$/) {
14280: $value = $optiondesc{$value};
14281: } else {
14282: $value = &mt('none -- defaults to No');
14283: }
14284: } elsif ($item eq 'check') {
14285: my %optiondesc = &Apache::lonlocal::texthash (
14286: 0 => 'No',
14287: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14288: 2 => 'Yes, disallow login if stored cost is less than domain default',
14289: );
14290: if ($value =~ /^(0|1|2)$/) {
14291: $value = $optiondesc{$value};
14292: } else {
14293: $value = &mt('none -- defaults to No');
14294: }
14295: }
14296: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14297: }
14298: } elsif ($key eq 'rules') {
14299: foreach my $rule ('min','max','numsaved') {
14300: if ($confighash{'passwords'}{$rule} eq '') {
14301: if ($rule eq 'min') {
14302: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 14303: ' '.&mt('Default of [_1] will be used',
14304: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 14305: } else {
14306: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14307: }
14308: } else {
14309: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14310: }
14311: }
1.160.6.104 raeburn 14312: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14313: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14314: my %rulenames = &Apache::lonlocal::texthash(
14315: uc => 'At least one upper case letter',
14316: lc => 'At least one lower case letter',
14317: num => 'At least one number',
14318: spec => 'At least one non-alphanumeric',
14319: );
14320: my $needed = '<ul><li>'.
14321: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14322: '</li></ul>';
14323: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14324: } else {
14325: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14326: }
14327: } else {
14328: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14329: }
1.160.6.98 raeburn 14330: } elsif ($key eq 'crsownerchg') {
14331: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14332: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14333: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14334: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14335: } else {
14336: my %crsownerstr;
14337: foreach my $item ('by','for') {
14338: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14339: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14340: if ($type eq 'default') {
14341: $crsownerstr{$item} .= $othertitle.', ';
14342: } elsif ($usertypes->{$type} ne '') {
14343: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14344: }
14345: }
14346: $crsownerstr{$item} =~ s/\Q, \E$//;
14347: }
14348: }
14349: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14350: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14351: }
14352: } else {
14353: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14354: }
14355: }
14356: $resulttext .= '</ul></li>';
14357: }
14358: }
14359: $resulttext .= '</ul>';
14360: } else {
14361: $resulttext = &mt('No changes made to password settings');
14362: }
14363: my $cachetime = 24*60*60;
14364: if ($updatedefaults) {
14365: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14366: if (ref($lastactref) eq 'HASH') {
14367: $lastactref->{'domdefaults'} = 1;
14368: }
14369: }
14370: if ($updateconf) {
14371: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14372: if (ref($lastactref) eq 'HASH') {
14373: $lastactref->{'passwdconf'} = 1;
14374: }
14375: }
14376: } else {
14377: $resulttext = '<span class="LC_error">'.
14378: &mt('An error occurred: [_1]',$putresult).'</span>';
14379: }
14380: if ($errors) {
14381: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14382: $errors.'</ul></p>';
14383: }
14384: return $resulttext;
14385: }
14386:
1.28 raeburn 14387: sub modify_usercreation {
1.27 raeburn 14388: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 14389: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14390: my $warningmsg;
1.27 raeburn 14391: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14392: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 14393: if ($key eq 'cancreate') {
14394: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14395: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 14396: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 14397: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 14398: } else {
14399: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 14400: }
1.50 raeburn 14401: }
1.43 raeburn 14402: }
1.160.6.34 raeburn 14403: } elsif ($key eq 'email_rule') {
14404: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14405: } else {
14406: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 14407: }
14408: }
1.34 raeburn 14409: }
1.160.6.34 raeburn 14410: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
14411: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
14412: my @contexts = ('author','course','requestcrs');
14413: foreach my $item(@contexts) {
14414: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14415: }
1.34 raeburn 14416: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14417: foreach my $item (@contexts) {
1.160.6.34 raeburn 14418: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14419: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14420: }
1.27 raeburn 14421: }
1.34 raeburn 14422: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14423: foreach my $item (@contexts) {
1.43 raeburn 14424: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14425: if ($cancreate{$item} ne 'any') {
14426: push(@{$changes{'cancreate'}},$item);
14427: }
14428: } else {
14429: if ($cancreate{$item} ne 'none') {
14430: push(@{$changes{'cancreate'}},$item);
14431: }
1.27 raeburn 14432: }
14433: }
14434: } else {
1.43 raeburn 14435: foreach my $item (@contexts) {
1.34 raeburn 14436: push(@{$changes{'cancreate'}},$item);
14437: }
1.27 raeburn 14438: }
1.34 raeburn 14439:
1.27 raeburn 14440: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14441: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14442: if (!grep(/^\Q$type\E$/,@username_rule)) {
14443: push(@{$changes{'username_rule'}},$type);
14444: }
14445: }
14446: foreach my $type (@username_rule) {
14447: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14448: push(@{$changes{'username_rule'}},$type);
14449: }
14450: }
14451: } else {
14452: push(@{$changes{'username_rule'}},@username_rule);
14453: }
14454:
1.32 raeburn 14455: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14456: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14457: if (!grep(/^\Q$type\E$/,@id_rule)) {
14458: push(@{$changes{'id_rule'}},$type);
14459: }
14460: }
14461: foreach my $type (@id_rule) {
14462: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14463: push(@{$changes{'id_rule'}},$type);
14464: }
14465: }
14466: } else {
14467: push(@{$changes{'id_rule'}},@id_rule);
14468: }
14469:
1.43 raeburn 14470: my @authen_contexts = ('author','course','domain');
1.28 raeburn 14471: my @authtypes = ('int','krb4','krb5','loc');
14472: my %authhash;
1.43 raeburn 14473: foreach my $item (@authen_contexts) {
1.28 raeburn 14474: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
14475: foreach my $auth (@authtypes) {
14476: if (grep(/^\Q$auth\E$/,@authallowed)) {
14477: $authhash{$item}{$auth} = 1;
14478: } else {
14479: $authhash{$item}{$auth} = 0;
14480: }
14481: }
14482: }
14483: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 14484: foreach my $item (@authen_contexts) {
1.28 raeburn 14485: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
14486: foreach my $auth (@authtypes) {
14487: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
14488: push(@{$changes{'authtypes'}},$item);
14489: last;
14490: }
14491: }
14492: }
14493: }
14494: } else {
1.43 raeburn 14495: foreach my $item (@authen_contexts) {
1.28 raeburn 14496: push(@{$changes{'authtypes'}},$item);
14497: }
14498: }
14499:
1.160.6.34 raeburn 14500: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
14501: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
14502: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
14503: $save_usercreate{'id_rule'} = \@id_rule;
14504: $save_usercreate{'username_rule'} = \@username_rule,
14505: $save_usercreate{'authtypes'} = \%authhash;
14506:
1.27 raeburn 14507: my %usercreation_hash = (
1.160.6.34 raeburn 14508: usercreation => \%save_usercreate,
14509: );
1.27 raeburn 14510:
14511: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
14512: $dom);
1.50 raeburn 14513:
1.160.6.34 raeburn 14514: if ($putresult eq 'ok') {
14515: if (keys(%changes) > 0) {
14516: $resulttext = &mt('Changes made:').'<ul>';
14517: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14518: my %lt = &usercreation_types();
14519: foreach my $type (@{$changes{'cancreate'}}) {
14520: my $chgtext = $lt{$type}.', ';
14521: if ($cancreate{$type} eq 'none') {
14522: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
14523: } elsif ($cancreate{$type} eq 'any') {
14524: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
14525: } elsif ($cancreate{$type} eq 'official') {
14526: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
14527: } elsif ($cancreate{$type} eq 'unofficial') {
14528: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
14529: }
14530: $resulttext .= '<li>'.$chgtext.'</li>';
14531: }
14532: }
14533: if (ref($changes{'username_rule'}) eq 'ARRAY') {
14534: my ($rules,$ruleorder) =
14535: &Apache::lonnet::inst_userrules($dom,'username');
14536: my $chgtext = '<ul>';
14537: foreach my $type (@username_rule) {
14538: if (ref($rules->{$type}) eq 'HASH') {
14539: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
14540: }
14541: }
14542: $chgtext .= '</ul>';
14543: if (@username_rule > 0) {
14544: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14545: } else {
14546: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
14547: }
14548: }
14549: if (ref($changes{'id_rule'}) eq 'ARRAY') {
14550: my ($idrules,$idruleorder) =
14551: &Apache::lonnet::inst_userrules($dom,'id');
14552: my $chgtext = '<ul>';
14553: foreach my $type (@id_rule) {
14554: if (ref($idrules->{$type}) eq 'HASH') {
14555: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
14556: }
14557: }
14558: $chgtext .= '</ul>';
14559: if (@id_rule > 0) {
14560: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14561: } else {
14562: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
14563: }
14564: }
14565: my %authname = &authtype_names();
14566: my %context_title = &context_names();
14567: if (ref($changes{'authtypes'}) eq 'ARRAY') {
14568: my $chgtext = '<ul>';
14569: foreach my $type (@{$changes{'authtypes'}}) {
14570: my @allowed;
14571: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
14572: foreach my $auth (@authtypes) {
14573: if ($authhash{$type}{$auth}) {
14574: push(@allowed,$authname{$auth});
14575: }
14576: }
14577: if (@allowed > 0) {
14578: $chgtext .= join(', ',@allowed).'</li>';
14579: } else {
14580: $chgtext .= &mt('none').'</li>';
14581: }
14582: }
14583: $chgtext .= '</ul>';
14584: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
14585: $resulttext .= '</li>';
14586: }
14587: $resulttext .= '</ul>';
14588: } else {
14589: $resulttext = &mt('No changes made to user creation settings');
14590: }
14591: } else {
14592: $resulttext = '<span class="LC_error">'.
14593: &mt('An error occurred: [_1]',$putresult).'</span>';
14594: }
14595: if ($warningmsg ne '') {
14596: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14597: }
14598: return $resulttext;
14599: }
14600:
14601: sub modify_selfcreation {
1.160.6.93 raeburn 14602: my ($dom,$lastactref,%domconfig) = @_;
14603: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
14604: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
14605: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14606: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
14607: if (ref($typesref) eq 'ARRAY') {
14608: @types = @{$typesref};
14609: }
14610: if (ref($usertypesref) eq 'HASH') {
14611: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 14612: }
1.160.6.93 raeburn 14613: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 14614: #
14615: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
14616: #
14617: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14618: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
14619: if ($key eq 'cancreate') {
14620: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14621: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
14622: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 14623: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
14624: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
14625: ($item eq 'emailusername') || ($item eq 'shibenv') ||
14626: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
14627: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 14628: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14629: } else {
14630: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14631: }
14632: }
14633: }
14634: } elsif ($key eq 'email_rule') {
14635: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14636: } else {
14637: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14638: }
14639: }
14640: }
14641: #
14642: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
14643: #
14644: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14645: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14646: if ($key eq 'selfcreate') {
14647: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
14648: } else {
14649: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
14650: }
14651: }
14652: }
1.160.6.93 raeburn 14653: #
14654: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
14655: #
14656: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14657: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
14658: if ($key eq 'inststatusguest') {
14659: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
14660: } else {
14661: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
14662: }
14663: }
14664: }
1.160.6.34 raeburn 14665:
14666: my @contexts = ('selfcreate');
14667: @{$cancreate{'selfcreate'}} = ();
14668: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 14669: if (@types) {
14670: @{$cancreate{'statustocreate'}} = ();
14671: }
1.160.6.40 raeburn 14672: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 14673: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 14674: %{$cancreate{'emailverified'}} = ();
14675: %{$cancreate{'emailoptions'}} = ();
14676: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 14677: my %selfcreatetypes = (
14678: sso => 'users authenticated by institutional single sign on',
14679: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 14680: email => 'users verified by e-mail',
1.50 raeburn 14681: );
1.160.6.34 raeburn 14682: #
14683: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
14684: # is permitted.
14685: #
1.160.6.40 raeburn 14686:
1.160.6.93 raeburn 14687: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 14688:
1.160.6.93 raeburn 14689: my (@statuses,%email_rule);
1.160.6.35 raeburn 14690: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 14691: if ($item eq 'email') {
1.160.6.40 raeburn 14692: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 14693: if (@types) {
14694: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
14695: foreach my $status (@poss_statuses) {
14696: if (grep(/^\Q$status\E$/,(@types,'default'))) {
14697: push(@statuses,$status);
14698: }
14699: }
14700: $save_inststatus{'inststatusguest'} = \@statuses;
14701: } else {
14702: push(@statuses,'default');
14703: }
14704: if (@statuses) {
14705: my %curr_rule;
14706: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
14707: foreach my $type (@statuses) {
14708: $curr_rule{$type} = $curr_usercreation{'email_rule'};
14709: }
14710: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
14711: foreach my $type (@statuses) {
14712: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
14713: }
14714: }
14715: push(@{$cancreate{'selfcreate'}},'email');
14716: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
14717: my %curremaildom;
14718: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
14719: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
14720: }
14721: foreach my $type (@statuses) {
14722: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
14723: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
14724: }
14725: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
14726: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
14727: }
14728: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
14729: #
14730: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
14731: #
14732: my $chosen = $1;
14733: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
14734: my $emaildom;
14735: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
14736: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
14737: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
14738: if (ref($curremaildom{$type}) eq 'HASH') {
14739: if (exists($curremaildom{$type}{$chosen})) {
14740: if ($curremaildom{$type}{$chosen} ne $emaildom) {
14741: push(@{$changes{'cancreate'}},'emaildomain');
14742: }
14743: } elsif ($emaildom ne '') {
14744: push(@{$changes{'cancreate'}},'emaildomain');
14745: }
14746: } elsif ($emaildom ne '') {
14747: push(@{$changes{'cancreate'}},'emaildomain');
14748: }
14749: }
14750: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14751: } elsif ($chosen eq 'custom') {
14752: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
14753: $email_rule{$type} = [];
14754: if (ref($emailrules) eq 'HASH') {
14755: foreach my $rule (@possemail_rules) {
14756: if (exists($emailrules->{$rule})) {
14757: push(@{$email_rule{$type}},$rule);
14758: }
14759: }
14760: }
14761: if (@{$email_rule{$type}}) {
14762: $cancreate{'emailoptions'}{$type} = 'custom';
14763: if (ref($curr_rule{$type}) eq 'ARRAY') {
14764: if (@{$curr_rule{$type}} > 0) {
14765: foreach my $rule (@{$curr_rule{$type}}) {
14766: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
14767: push(@{$changes{'email_rule'}},$type);
14768: }
14769: }
14770: }
14771: foreach my $type (@{$email_rule{$type}}) {
14772: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14773: push(@{$changes{'email_rule'}},$type);
14774: }
14775: }
14776: } else {
14777: push(@{$changes{'email_rule'}},$type);
14778: }
14779: }
14780: } else {
14781: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14782: }
14783: }
14784: }
14785: if (@types) {
14786: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14787: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14788: if (@changed) {
14789: push(@{$changes{'inststatus'}},'inststatusguest');
14790: }
14791: } else {
14792: push(@{$changes{'inststatus'}},'inststatusguest');
14793: }
14794: }
14795: } else {
14796: delete($env{'form.cancreate_email'});
14797: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14798: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14799: push(@{$changes{'inststatus'}},'inststatusguest');
14800: }
14801: }
14802: }
14803: } else {
14804: $save_inststatus{'inststatusguest'} = [];
14805: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14806: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14807: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 14808: }
14809: }
1.160.6.34 raeburn 14810: }
14811: } else {
14812: if ($env{'form.cancreate_'.$item}) {
14813: push(@{$cancreate{'selfcreate'}},$item);
14814: }
14815: }
14816: }
1.160.6.93 raeburn 14817: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 14818: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14819: #
1.160.6.35 raeburn 14820: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14821: # 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 14822: #
1.160.6.40 raeburn 14823:
1.160.6.48 raeburn 14824: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 14825: push(@contexts,'emailusername');
1.160.6.93 raeburn 14826: if (@statuses) {
14827: foreach my $type (@statuses) {
1.160.6.35 raeburn 14828: if (ref($infofields) eq 'ARRAY') {
14829: foreach my $field (@{$infofields}) {
14830: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14831: $cancreate{'emailusername'}{$type}{$field} = $1;
14832: }
14833: }
1.160.6.34 raeburn 14834: }
14835: }
14836: }
14837: #
14838: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 14839: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 14840: #
14841:
14842: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14843: @approvalnotify = sort(@approvalnotify);
14844: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14845: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14846: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14847: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14848: push(@{$changes{'cancreate'}},'notify');
14849: }
14850: } else {
14851: if ($cancreate{'notify'}{'approval'}) {
14852: push(@{$changes{'cancreate'}},'notify');
14853: }
14854: }
14855: } elsif ($cancreate{'notify'}{'approval'}) {
14856: push(@{$changes{'cancreate'}},'notify');
14857: }
14858:
14859: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14860: }
14861: #
1.160.6.40 raeburn 14862: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 14863: # institutional log-in.
14864: #
14865: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14866: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14867: ($domdefaults{'auth_def'} eq 'localauth'))) {
14868: $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.').' '.
14869: &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.');
14870: }
14871: }
14872: my @fields = ('lastname','firstname','middlename','generation',
14873: 'permanentemail','id');
1.160.6.44 raeburn 14874: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 14875: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14876: #
14877: # Where usernames may created for institutional log-in and/or institutional single sign on:
14878: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14879: # may self-create accounts
14880: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14881: # which the user may supply, if institutional data is unavailable.
14882: #
14883: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 14884: if (@types) {
14885: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14886: push(@contexts,'statustocreate');
14887: foreach my $type (@types) {
1.160.6.34 raeburn 14888: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14889: foreach my $field (@fields) {
14890: if (grep(/^\Q$field\E$/,@modifiable)) {
14891: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14892: } else {
14893: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14894: }
14895: }
14896: }
14897: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 14898: foreach my $type (@types) {
1.160.6.34 raeburn 14899: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14900: foreach my $field (@fields) {
14901: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14902: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14903: push(@{$changes{'selfcreate'}},$type);
14904: last;
14905: }
14906: }
14907: }
14908: }
14909: } else {
1.160.6.93 raeburn 14910: foreach my $type (@types) {
1.160.6.34 raeburn 14911: push(@{$changes{'selfcreate'}},$type);
14912: }
14913: }
14914: }
1.160.6.44 raeburn 14915: foreach my $field (@shibfields) {
14916: if ($env{'form.shibenv_'.$field} ne '') {
14917: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14918: }
14919: }
14920: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14921: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14922: foreach my $field (@shibfields) {
14923: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14924: push(@{$changes{'cancreate'}},'shibenv');
14925: }
14926: }
14927: } else {
14928: foreach my $field (@shibfields) {
14929: if ($env{'form.shibenv_'.$field}) {
14930: push(@{$changes{'cancreate'}},'shibenv');
14931: last;
14932: }
14933: }
14934: }
14935: }
1.160.6.34 raeburn 14936: }
14937: foreach my $item (@contexts) {
14938: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14939: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14940: if (ref($cancreate{$item}) eq 'ARRAY') {
14941: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
14942: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14943: push(@{$changes{'cancreate'}},$item);
14944: }
14945: }
14946: }
14947: }
14948: if (ref($cancreate{$item}) eq 'ARRAY') {
14949: foreach my $type (@{$cancreate{$item}}) {
14950: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
14951: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14952: push(@{$changes{'cancreate'}},$item);
14953: }
14954: }
14955: }
14956: }
14957: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
14958: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 14959: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
14960: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14961: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
14962: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 14963: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14964: push(@{$changes{'cancreate'}},$item);
14965: }
14966: }
14967: }
1.160.6.93 raeburn 14968: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14969: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 14970: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14971: push(@{$changes{'cancreate'}},$item);
14972: }
1.160.6.34 raeburn 14973: }
14974: }
14975: }
1.160.6.93 raeburn 14976: foreach my $type (keys(%{$cancreate{$item}})) {
14977: if (ref($cancreate{$item}{$type}) eq 'HASH') {
14978: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
14979: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14980: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 14981: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14982: push(@{$changes{'cancreate'}},$item);
14983: }
14984: }
14985: } else {
14986: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14987: push(@{$changes{'cancreate'}},$item);
14988: }
14989: }
14990: }
1.160.6.93 raeburn 14991: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
14992: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 14993: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14994: push(@{$changes{'cancreate'}},$item);
14995: }
1.160.6.34 raeburn 14996: }
14997: }
14998: }
14999: }
15000: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15001: if (ref($cancreate{$item}) eq 'ARRAY') {
15002: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15003: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15004: push(@{$changes{'cancreate'}},$item);
15005: }
15006: }
1.160.6.93 raeburn 15007: }
15008: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15009: if (ref($cancreate{$item}) eq 'HASH') {
15010: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15011: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 15012: }
15013: }
15014: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 15015: if (ref($cancreate{$item}) eq 'HASH') {
15016: foreach my $type (keys(%{$cancreate{$item}})) {
15017: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15018: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15019: if ($cancreate{$item}{$type}{$field}) {
15020: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15021: push(@{$changes{'cancreate'}},$item);
15022: }
15023: last;
15024: }
15025: }
15026: }
15027: }
1.160.6.34 raeburn 15028: }
15029: }
15030: }
15031: #
15032: # Populate %save_usercreate hash with updates to self-creation configuration.
15033: #
15034: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15035: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 15036: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 15037: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15038: if (ref($cancreate{'notify'}) eq 'HASH') {
15039: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15040: }
1.160.6.40 raeburn 15041: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15042: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15043: }
1.160.6.93 raeburn 15044: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15045: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15046: }
15047: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15048: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15049: }
15050: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15051: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15052: }
1.160.6.34 raeburn 15053: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15054: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15055: }
1.160.6.44 raeburn 15056: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15057: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15058: }
1.160.6.34 raeburn 15059: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 15060: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 15061:
15062: my %userconfig_hash = (
15063: usercreation => \%save_usercreate,
15064: usermodification => \%save_usermodify,
1.160.6.93 raeburn 15065: inststatus => \%save_inststatus,
1.160.6.34 raeburn 15066: );
1.160.6.93 raeburn 15067:
1.160.6.34 raeburn 15068: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15069: $dom);
15070: #
1.160.6.93 raeburn 15071: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 15072: #
1.27 raeburn 15073: if ($putresult eq 'ok') {
15074: if (keys(%changes) > 0) {
15075: $resulttext = &mt('Changes made:').'<ul>';
15076: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 15077: my %lt = &selfcreation_types();
1.34 raeburn 15078: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 15079: my $chgtext = '';
1.45 raeburn 15080: if ($type eq 'selfcreate') {
1.50 raeburn 15081: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 15082: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15083: } else {
1.160.6.34 raeburn 15084: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15085: '<ul>';
1.50 raeburn 15086: foreach my $case (@{$cancreate{$type}}) {
15087: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15088: }
15089: $chgtext .= '</ul>';
1.100 raeburn 15090: if (ref($cancreate{$type}) eq 'ARRAY') {
15091: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15092: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15093: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 15094: $chgtext .= '<span class="LC_warning">'.
15095: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15096: '</span><br />';
1.100 raeburn 15097: }
15098: }
15099: }
1.160.6.93 raeburn 15100: if (grep(/^email$/,@{$cancreate{$type}})) {
15101: if (!@statuses) {
15102: $chgtext .= '<span class="LC_warning">'.
15103: &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.").
15104: '</span><br />';
15105:
15106: }
15107: }
1.100 raeburn 15108: }
1.43 raeburn 15109: }
1.160.6.44 raeburn 15110: } elsif ($type eq 'shibenv') {
15111: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 15112: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 15113: } else {
15114: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15115: '<ul>';
15116: foreach my $field (@shibfields) {
15117: next if ($cancreate{$type}{$field} eq '');
15118: if ($field eq 'inststatus') {
15119: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15120: } else {
15121: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15122: }
15123: }
15124: $chgtext .= '</ul>';
1.160.6.93 raeburn 15125: }
1.93 raeburn 15126: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15127: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15128: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15129: if (@{$cancreate{'selfcreate'}} > 0) {
15130: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15131: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15132: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 15133: $chgtext .= '<br />'.
15134: '<span class="LC_warning">'.
15135: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15136: '</span>';
15137: }
1.160.6.93 raeburn 15138: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15139: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15140: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15141: } else {
15142: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15143: }
15144: $chgtext .= '<ul>';
15145: foreach my $case (@{$cancreate{$type}}) {
15146: if ($case eq 'default') {
15147: $chgtext .= '<li>'.$othertitle.'</li>';
15148: } else {
1.160.6.93 raeburn 15149: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15150: }
15151: }
1.100 raeburn 15152: $chgtext .= '</ul>';
15153: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 15154: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 15155: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15156: '</span>';
1.100 raeburn 15157: }
15158: }
15159: } else {
15160: if (@{$cancreate{$type}} == 0) {
15161: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15162: } else {
15163: $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 15164: }
15165: }
1.160.6.93 raeburn 15166: $chgtext .= '<br />';
1.93 raeburn 15167: }
1.160.6.40 raeburn 15168: } elsif ($type eq 'selfcreateprocessing') {
15169: my %choices = &Apache::lonlocal::texthash (
15170: automatic => 'Automatic approval',
15171: approval => 'Queued for approval',
15172: );
1.160.6.93 raeburn 15173: if (@types) {
15174: if (@statuses) {
15175: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15176: '<ul>';
15177: foreach my $status (@statuses) {
15178: if ($status eq 'default') {
15179: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15180: } else {
15181: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15182: }
15183: }
15184: $chgtext .= '</ul>';
15185: }
15186: } else {
15187: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15188: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15189: }
15190: } elsif ($type eq 'emailverified') {
15191: my %options = &Apache::lonlocal::texthash (
15192: all => 'Same as e-mail',
15193: first => 'Omit @domain',
15194: free => 'Free to choose',
15195: );
15196: if (@types) {
15197: if (@statuses) {
15198: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15199: '<ul>';
15200: foreach my $status (@statuses) {
15201: if ($status eq 'default') {
15202: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15203: } else {
15204: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15205: }
15206: }
15207: $chgtext .= '</ul>';
15208: }
1.160.6.40 raeburn 15209: } else {
1.160.6.93 raeburn 15210: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15211: $options{$cancreate{'emailverified'}{'default'}});
15212: }
15213: } elsif ($type eq 'emailoptions') {
15214: my %options = &Apache::lonlocal::texthash (
15215: any => 'Any e-mail',
15216: inst => 'Institutional only',
15217: noninst => 'Non-institutional only',
15218: custom => 'Custom restrictions',
15219: );
15220: if (@types) {
15221: if (@statuses) {
15222: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15223: '<ul>';
15224: foreach my $status (@statuses) {
15225: if ($type eq 'default') {
15226: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15227: } else {
15228: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15229: }
15230: }
15231: $chgtext .= '</ul>';
15232: }
15233: } else {
15234: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15235: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15236: } else {
15237: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15238: $options{$cancreate{'emailoptions'}{'default'}});
15239: }
15240: }
15241: } elsif ($type eq 'emaildomain') {
15242: my $output;
15243: if (@statuses) {
15244: foreach my $type (@statuses) {
15245: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15246: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15247: if ($type eq 'default') {
15248: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15249: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15250: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15251: } else {
15252: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15253: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15254: }
15255: } else {
15256: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15257: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15258: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15259: } else {
15260: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15261: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15262: }
15263: }
15264: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15265: if ($type eq 'default') {
15266: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15267: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15268: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15269: } else {
15270: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15271: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15272: }
15273: } else {
15274: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15275: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15276: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15277: } else {
15278: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15279: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15280: }
15281: }
15282: }
15283: }
15284: }
15285: }
15286: if ($output ne '') {
15287: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15288: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 15289: }
1.160.6.5 raeburn 15290: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 15291: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 15292: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15293: } else {
15294: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 15295: if ($captchas{$savecaptcha{$type}}) {
15296: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 15297: } else {
15298: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
15299: }
15300: }
15301: } elsif ($type eq 'recaptchakeys') {
15302: my ($privkey,$pubkey);
1.160.6.34 raeburn 15303: if (ref($savecaptcha{$type}) eq 'HASH') {
15304: $pubkey = $savecaptcha{$type}{'public'};
15305: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 15306: }
15307: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15308: if (!$pubkey) {
15309: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15310: } else {
15311: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15312: }
15313: if (!$privkey) {
15314: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15315: } else {
15316: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15317: }
15318: $chgtext .= '</ul>';
1.160.6.69 raeburn 15319: } elsif ($type eq 'recaptchaversion') {
15320: if ($savecaptcha{'captcha'} eq 'recaptcha') {
15321: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
15322: }
1.160.6.34 raeburn 15323: } elsif ($type eq 'emailusername') {
15324: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 15325: if (@statuses) {
15326: foreach my $type (@statuses) {
1.160.6.35 raeburn 15327: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15328: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 15329: $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 15330: '<ul>';
15331: foreach my $field (@{$infofields}) {
15332: if ($cancreate{'emailusername'}{$type}{$field}) {
15333: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15334: }
15335: }
1.160.6.50 raeburn 15336: $chgtext .= '</ul>';
15337: } else {
1.160.6.93 raeburn 15338: $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 15339: }
15340: } else {
1.160.6.93 raeburn 15341: $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 15342: }
15343: }
15344: }
15345: }
15346: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 15347: my $numapprove = 0;
1.160.6.34 raeburn 15348: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15349: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15350: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 15351: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15352: $numapprove ++;
1.160.6.34 raeburn 15353: }
15354: }
1.43 raeburn 15355: }
1.160.6.93 raeburn 15356: unless ($numapprove) {
15357: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15358: }
1.34 raeburn 15359: }
1.160.6.34 raeburn 15360: if ($chgtext) {
15361: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15362: }
15363: }
15364: }
1.160.6.93 raeburn 15365: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15366: my ($emailrules,$emailruleorder) =
15367: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 15368: foreach my $type (@{$changes{'email_rule'}}) {
15369: if (ref($email_rule{$type}) eq 'ARRAY') {
15370: my $chgtext = '<ul>';
15371: foreach my $rule (@{$email_rule{$type}}) {
15372: if (ref($emailrules->{$rule}) eq 'HASH') {
15373: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15374: }
15375: }
15376: $chgtext .= '</ul>';
15377: my $typename;
15378: if (@types) {
15379: if ($type eq 'default') {
15380: $typename = $othertitle;
15381: } else {
15382: $typename = $usertypes{$type};
15383: }
15384: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15385: }
15386: if (@{$email_rule{$type}} > 0) {
15387: $resulttext .= '<li>'.
15388: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15389: $usertypes{$type}).
15390: $chgtext.
15391: '</li>';
15392: } else {
15393: $resulttext .= '<li>'.
15394: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
15395: '</li>'.
15396: &mt('(Affiliation: [_1])',$typename);
15397: }
1.43 raeburn 15398: }
15399: }
1.160.6.93 raeburn 15400: }
15401: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15402: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15403: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15404: my $chgtext = '<ul>';
15405: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15406: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15407: }
15408: $chgtext .= '</ul>';
15409: $resulttext .= '<li>'.
15410: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15411: $chgtext.
15412: '</li>';
15413: } else {
15414: $resulttext .= '<li>'.
15415: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15416: '</li>';
15417: }
1.43 raeburn 15418: }
15419: }
1.160.6.34 raeburn 15420: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15421: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15422: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15423: foreach my $type (@{$changes{'selfcreate'}}) {
15424: my $typename = $type;
1.160.6.93 raeburn 15425: if (keys(%usertypes) > 0) {
15426: if ($usertypes{$type} ne '') {
15427: $typename = $usertypes{$type};
1.28 raeburn 15428: }
15429: }
1.160.6.34 raeburn 15430: my @modifiable;
15431: $resulttext .= '<li>'.
15432: &mt('Self-creation of account by users with status: [_1]',
15433: '<span class="LC_cusr_emph">'.$typename.'</span>').
15434: ' - '.&mt('modifiable fields (if institutional data blank): ');
15435: foreach my $field (@fields) {
15436: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15437: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
15438: }
15439: }
15440: if (@modifiable > 0) {
15441: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15442: } else {
1.160.6.34 raeburn 15443: $resulttext .= &mt('none');
1.43 raeburn 15444: }
1.160.6.34 raeburn 15445: $resulttext .= '</li>';
1.28 raeburn 15446: }
1.160.6.34 raeburn 15447: $resulttext .= '</ul></li>';
1.28 raeburn 15448: }
1.27 raeburn 15449: $resulttext .= '</ul>';
1.160.6.93 raeburn 15450: my $cachetime = 24*60*60;
15451: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15452: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15453: if (ref($lastactref) eq 'HASH') {
15454: $lastactref->{'domdefaults'} = 1;
15455: }
1.27 raeburn 15456: } else {
1.160.6.34 raeburn 15457: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15458: }
15459: } else {
15460: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15461: &mt('An error occurred: [_1]',$putresult).'</span>';
15462: }
1.43 raeburn 15463: if ($warningmsg ne '') {
15464: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15465: }
1.23 raeburn 15466: return $resulttext;
15467: }
15468:
1.160.6.5 raeburn 15469: sub process_captcha {
1.160.6.104 raeburn 15470: my ($container,$changes,$newsettings,$currsettings) = @_;
15471: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 15472: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
15473: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
15474: $newsettings->{'captcha'} = 'original';
15475: }
1.160.6.104 raeburn 15476: my %current;
15477: if (ref($currsettings) eq 'HASH') {
15478: %current = %{$currsettings};
15479: }
15480: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 15481: if ($container eq 'cancreate') {
15482: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15483: push(@{$changes->{'cancreate'}},'captcha');
15484: } elsif (!defined($changes->{'cancreate'})) {
15485: $changes->{'cancreate'} = ['captcha'];
15486: }
1.160.6.102 raeburn 15487: } elsif ($container eq 'passwords') {
15488: $changes->{'reset'} = 1;
1.160.6.5 raeburn 15489: } else {
15490: $changes->{'captcha'} = 1;
15491: }
15492: }
1.160.6.69 raeburn 15493: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 15494: if ($newsettings->{'captcha'} eq 'recaptcha') {
15495: $newpub = $env{'form.'.$container.'_recaptchapub'};
15496: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 15497: $newpub =~ s/[^\w\-]//g;
15498: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 15499: $newsettings->{'recaptchakeys'} = {
15500: public => $newpub,
15501: private => $newpriv,
15502: };
1.160.6.69 raeburn 15503: $newversion = $env{'form.'.$container.'_recaptchaversion'};
15504: $newversion =~ s/\D//g;
15505: if ($newversion ne '2') {
15506: $newversion = 1;
15507: }
15508: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 15509: }
1.160.6.104 raeburn 15510: if (ref($current{'recaptchakeys'}) eq 'HASH') {
15511: $currpub = $current{'recaptchakeys'}{'public'};
15512: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 15513: unless ($newsettings->{'captcha'} eq 'recaptcha') {
15514: $newsettings->{'recaptchakeys'} = {
15515: public => '',
15516: private => '',
15517: }
15518: }
1.160.6.5 raeburn 15519: }
1.160.6.104 raeburn 15520: if ($current{'captcha'} eq 'recaptcha') {
15521: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 15522: if ($currversion ne '2') {
15523: $currversion = 1;
15524: }
15525: }
15526: if ($currversion ne $newversion) {
15527: if ($container eq 'cancreate') {
15528: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15529: push(@{$changes->{'cancreate'}},'recaptchaversion');
15530: } elsif (!defined($changes->{'cancreate'})) {
15531: $changes->{'cancreate'} = ['recaptchaversion'];
15532: }
1.160.6.102 raeburn 15533: } elsif ($container eq 'passwords') {
15534: $changes->{'reset'} = 1;
1.160.6.69 raeburn 15535: } else {
15536: $changes->{'recaptchaversion'} = 1;
15537: }
15538: }
1.160.6.5 raeburn 15539: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
15540: if ($container eq 'cancreate') {
15541: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15542: push(@{$changes->{'cancreate'}},'recaptchakeys');
15543: } elsif (!defined($changes->{'cancreate'})) {
15544: $changes->{'cancreate'} = ['recaptchakeys'];
15545: }
1.160.6.102 raeburn 15546: } elsif ($container eq 'passwords') {
15547: $changes->{'reset'} = 1;
1.160.6.5 raeburn 15548: } else {
15549: $changes->{'recaptchakeys'} = 1;
15550: }
15551: }
15552: return;
15553: }
15554:
1.33 raeburn 15555: sub modify_usermodification {
15556: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15557: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 15558: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15559: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 15560: if ($key eq 'selfcreate') {
15561: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
15562: } else {
15563: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
15564: }
1.33 raeburn 15565: }
15566: }
1.160.6.34 raeburn 15567: my @contexts = ('author','course');
1.33 raeburn 15568: my %context_title = (
15569: author => 'In author context',
15570: course => 'In course context',
15571: );
15572: my @fields = ('lastname','firstname','middlename','generation',
15573: 'permanentemail','id');
15574: my %roles = (
15575: author => ['ca','aa'],
15576: course => ['st','ep','ta','in','cr'],
15577: );
15578: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15579: foreach my $context (@contexts) {
15580: foreach my $role (@{$roles{$context}}) {
15581: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
15582: foreach my $item (@fields) {
15583: if (grep(/^\Q$item\E$/,@modifiable)) {
15584: $modifyhash{$context}{$role}{$item} = 1;
15585: } else {
15586: $modifyhash{$context}{$role}{$item} = 0;
15587: }
15588: }
15589: }
15590: if (ref($curr_usermodification{$context}) eq 'HASH') {
15591: foreach my $role (@{$roles{$context}}) {
15592: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
15593: foreach my $field (@fields) {
15594: if ($modifyhash{$context}{$role}{$field} ne
15595: $curr_usermodification{$context}{$role}{$field}) {
15596: push(@{$changes{$context}},$role);
15597: last;
15598: }
15599: }
15600: }
15601: }
15602: } else {
15603: foreach my $context (@contexts) {
15604: foreach my $role (@{$roles{$context}}) {
15605: push(@{$changes{$context}},$role);
15606: }
15607: }
15608: }
15609: }
15610: my %usermodification_hash = (
15611: usermodification => \%modifyhash,
15612: );
15613: my $putresult = &Apache::lonnet::put_dom('configuration',
15614: \%usermodification_hash,$dom);
15615: if ($putresult eq 'ok') {
15616: if (keys(%changes) > 0) {
15617: $resulttext = &mt('Changes made: ').'<ul>';
15618: foreach my $context (@contexts) {
15619: if (ref($changes{$context}) eq 'ARRAY') {
15620: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
15621: if (ref($changes{$context}) eq 'ARRAY') {
15622: foreach my $role (@{$changes{$context}}) {
15623: my $rolename;
1.160.6.34 raeburn 15624: if ($role eq 'cr') {
15625: $rolename = &mt('Custom');
1.33 raeburn 15626: } else {
1.160.6.34 raeburn 15627: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 15628: }
15629: my @modifiable;
1.160.6.34 raeburn 15630: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 15631: foreach my $field (@fields) {
15632: if ($modifyhash{$context}{$role}{$field}) {
15633: push(@modifiable,$fieldtitles{$field});
15634: }
15635: }
15636: if (@modifiable > 0) {
15637: $resulttext .= join(', ',@modifiable);
15638: } else {
15639: $resulttext .= &mt('none');
15640: }
15641: $resulttext .= '</li>';
15642: }
15643: $resulttext .= '</ul></li>';
15644: }
15645: }
15646: }
15647: $resulttext .= '</ul>';
15648: } else {
15649: $resulttext = &mt('No changes made to user modification settings');
15650: }
15651: } else {
15652: $resulttext = '<span class="LC_error">'.
15653: &mt('An error occurred: [_1]',$putresult).'</span>';
15654: }
15655: return $resulttext;
15656: }
15657:
1.43 raeburn 15658: sub modify_defaults {
1.160.6.27 raeburn 15659: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 15660: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 15661: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 15662: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 15663: 'portal_def');
1.43 raeburn 15664: my @authtypes = ('internal','krb4','krb5','localauth');
15665: foreach my $item (@items) {
15666: $newvalues{$item} = $env{'form.'.$item};
15667: if ($item eq 'auth_def') {
15668: if ($newvalues{$item} ne '') {
15669: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
15670: push(@errors,$item);
15671: }
15672: }
15673: } elsif ($item eq 'lang_def') {
15674: if ($newvalues{$item} ne '') {
15675: if ($newvalues{$item} =~ /^(\w+)/) {
15676: my $langcode = $1;
1.103 raeburn 15677: if ($langcode ne 'x_chef') {
15678: if (code2language($langcode) eq '') {
15679: push(@errors,$item);
15680: }
1.43 raeburn 15681: }
15682: } else {
15683: push(@errors,$item);
15684: }
15685: }
1.54 raeburn 15686: } elsif ($item eq 'timezone_def') {
15687: if ($newvalues{$item} ne '') {
1.62 raeburn 15688: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 15689: push(@errors,$item);
15690: }
15691: }
1.68 raeburn 15692: } elsif ($item eq 'datelocale_def') {
15693: if ($newvalues{$item} ne '') {
15694: my @datelocale_ids = DateTime::Locale->ids();
15695: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
15696: push(@errors,$item);
15697: }
15698: }
1.141 raeburn 15699: } elsif ($item eq 'portal_def') {
15700: if ($newvalues{$item} ne '') {
15701: 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])\/?$/) {
15702: push(@errors,$item);
15703: }
15704: }
1.43 raeburn 15705: }
15706: if (grep(/^\Q$item\E$/,@errors)) {
15707: $newvalues{$item} = $domdefaults{$item};
15708: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
15709: $changes{$item} = 1;
15710: }
1.72 raeburn 15711: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 15712: }
1.160.6.98 raeburn 15713: my %staticdefaults = (
15714: 'intauth_cost' => 10,
15715: 'intauth_check' => 0,
15716: 'intauth_switch' => 0,
15717: );
15718: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
15719: if (exists($domdefaults{$item})) {
15720: $newvalues{$item} = $domdefaults{$item};
15721: } else {
15722: $newvalues{$item} = $staticdefaults{$item};
15723: }
15724: }
1.43 raeburn 15725: my %defaults_hash = (
1.72 raeburn 15726: defaults => \%newvalues,
15727: );
1.43 raeburn 15728: my $title = &defaults_titles();
1.160.6.40 raeburn 15729:
15730: my $currinststatus;
15731: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15732: $currinststatus = $domconfig{'inststatus'};
15733: } else {
15734: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15735: $currinststatus = {
15736: inststatustypes => $usertypes,
15737: inststatusorder => $types,
15738: inststatusguest => [],
15739: };
15740: }
15741: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
15742: my @allpos;
15743: my %alltypes;
1.160.6.93 raeburn 15744: my @inststatusguest;
15745: if (ref($currinststatus) eq 'HASH') {
15746: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
15747: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
15748: unless (grep(/^\Q$type\E$/,@todelete)) {
15749: push(@inststatusguest,$type);
15750: }
15751: }
15752: }
15753: }
15754: my ($currtitles,$currorder);
1.160.6.40 raeburn 15755: if (ref($currinststatus) eq 'HASH') {
15756: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
15757: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
15758: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
15759: if ($currinststatus->{inststatustypes}->{$type} ne '') {
15760: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
15761: }
15762: }
15763: unless (grep(/^\Q$type\E$/,@todelete)) {
15764: my $position = $env{'form.inststatus_pos_'.$type};
15765: $position =~ s/\D+//g;
15766: $allpos[$position] = $type;
15767: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
15768: $alltypes{$type} =~ s/`//g;
15769: }
15770: }
15771: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
15772: $currtitles =~ s/,$//;
15773: }
15774: }
15775: if ($env{'form.addinststatus'}) {
15776: my $newtype = $env{'form.addinststatus'};
15777: $newtype =~ s/\W//g;
15778: unless (exists($alltypes{$newtype})) {
15779: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15780: $alltypes{$newtype} =~ s/`//g;
15781: my $position = $env{'form.addinststatus_pos'};
15782: $position =~ s/\D+//g;
15783: if ($position ne '') {
15784: $allpos[$position] = $newtype;
15785: }
15786: }
15787: }
1.160.6.93 raeburn 15788: my @orderedstatus;
1.160.6.40 raeburn 15789: foreach my $type (@allpos) {
15790: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15791: push(@orderedstatus,$type);
15792: }
15793: }
15794: foreach my $type (keys(%alltypes)) {
15795: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15796: delete($alltypes{$type});
15797: }
15798: }
15799: $defaults_hash{'inststatus'} = {
15800: inststatustypes => \%alltypes,
15801: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 15802: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 15803: };
15804: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15805: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15806: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15807: }
15808: }
15809: if ($currorder ne join(',',@orderedstatus)) {
15810: $changes{'inststatus'}{'inststatusorder'} = 1;
15811: }
15812: my $newtitles;
15813: foreach my $item (@orderedstatus) {
15814: $newtitles .= $alltypes{$item}.',';
15815: }
15816: $newtitles =~ s/,$//;
15817: if ($currtitles ne $newtitles) {
15818: $changes{'inststatus'}{'inststatustypes'} = 1;
15819: }
1.43 raeburn 15820: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15821: $dom);
15822: if ($putresult eq 'ok') {
15823: if (keys(%changes) > 0) {
15824: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 15825: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15826: 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";
15827: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 15828: if ($item eq 'inststatus') {
15829: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 15830: if (@orderedstatus) {
1.160.6.40 raeburn 15831: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15832: foreach my $type (@orderedstatus) {
15833: $resulttext .= $alltypes{$type}.', ';
15834: }
15835: $resulttext =~ s/, $//;
15836: $resulttext .= '</li>';
1.160.6.93 raeburn 15837: } else {
15838: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 15839: }
15840: }
15841: } else {
15842: my $value = $env{'form.'.$item};
15843: if ($value eq '') {
15844: $value = &mt('none');
15845: } elsif ($item eq 'auth_def') {
15846: my %authnames = &authtype_names();
15847: my %shortauth = (
15848: internal => 'int',
15849: krb4 => 'krb4',
15850: krb5 => 'krb5',
15851: localauth => 'loc',
15852: );
15853: $value = $authnames{$shortauth{$value}};
15854: }
15855: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15856: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15857: }
15858: }
15859: $resulttext .= '</ul>';
15860: $mailmsgtext .= "\n";
15861: my $cachetime = 24*60*60;
1.72 raeburn 15862: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 15863: if (ref($lastactref) eq 'HASH') {
15864: $lastactref->{'domdefaults'} = 1;
15865: }
1.68 raeburn 15866: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 15867: my $notify = 1;
15868: if (ref($domconfig{'contacts'}) eq 'HASH') {
15869: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15870: $notify = 0;
15871: }
15872: }
15873: if ($notify) {
15874: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15875: "LON-CAPA Domain Settings Change - $dom",
15876: $mailmsgtext);
15877: }
1.54 raeburn 15878: }
1.43 raeburn 15879: } else {
1.54 raeburn 15880: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15881: }
15882: } else {
15883: $resulttext = '<span class="LC_error">'.
15884: &mt('An error occurred: [_1]',$putresult).'</span>';
15885: }
15886: if (@errors > 0) {
15887: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15888: foreach my $item (@errors) {
15889: $resulttext .= ' "'.$title->{$item}.'",';
15890: }
15891: $resulttext =~ s/,$//;
15892: }
15893: return $resulttext;
15894: }
15895:
1.46 raeburn 15896: sub modify_scantron {
1.160.6.24 raeburn 15897: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15898: my ($resulttext,%confhash,%changes,$errors);
15899: my $custom = 'custom.tab';
15900: my $default = 'default.tab';
15901: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 15902: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15903: &config_check($dom,$confname,$servadm);
15904: if ($env{'form.scantronformat.filename'} ne '') {
15905: my $error;
15906: if ($configuserok eq 'ok') {
15907: if ($switchserver) {
1.130 raeburn 15908: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15909: } else {
15910: if ($author_ok eq 'ok') {
15911: my ($result,$scantronurl) =
15912: &publishlogo($r,'upload','scantronformat',$dom,
15913: $confname,'scantron','','',$custom);
15914: if ($result eq 'ok') {
15915: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15916: $changes{'scantronformat'} = 1;
1.46 raeburn 15917: } else {
15918: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15919: }
15920: } else {
15921: $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);
15922: }
15923: }
15924: } else {
15925: $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);
15926: }
15927: if ($error) {
15928: &Apache::lonnet::logthis($error);
15929: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15930: }
15931: }
1.48 raeburn 15932: if (ref($domconfig{'scantron'}) eq 'HASH') {
15933: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15934: if ($env{'form.scantronformat_del'}) {
15935: $confhash{'scantron'}{'scantronformat'} = '';
15936: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 15937: } else {
15938: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
15939: }
15940: }
15941: }
15942: my @options = ('hdr','pad','rem');
15943: my @fields = &scantroncsv_fields();
15944: my %titles = &scantronconfig_titles();
15945: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
15946: my ($newdat,$currdat,%newcol,%currcol);
15947: if (grep(/^dat$/,@formats)) {
15948: $confhash{'scantron'}{config}{dat} = 1;
15949: $newdat = 1;
15950: } else {
15951: $newdat = 0;
15952: }
15953: if (grep(/^csv$/,@formats)) {
15954: my %bynum;
15955: foreach my $field (@fields) {
15956: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
15957: my $posscol = $1;
15958: if (($posscol < 20) && (!$bynum{$posscol})) {
15959: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
15960: $bynum{$posscol} = $field;
15961: $newcol{$field} = $posscol;
15962: }
15963: }
15964: }
15965: if (keys(%newcol)) {
15966: foreach my $option (@options) {
15967: if ($env{'form.scantroncsv_'.$option}) {
15968: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
15969: }
15970: }
15971: }
15972: }
15973: $currdat = 1;
15974: if (ref($domconfig{'scantron'}) eq 'HASH') {
15975: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
15976: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
15977: $currdat = 0;
15978: }
15979: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
15980: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
15981: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
15982: }
15983: }
15984: }
15985: }
15986: if ($currdat != $newdat) {
15987: $changes{'config'} = 1;
15988: } else {
15989: foreach my $field (@fields) {
15990: if ($currcol{$field} ne '') {
15991: if ($currcol{$field} ne $newcol{$field}) {
15992: $changes{'config'} = 1;
15993: last;
15994: }
15995: } elsif ($newcol{$field} ne '') {
15996: $changes{'config'} = 1;
15997: last;
1.46 raeburn 15998: }
15999: }
16000: }
16001: if (keys(%confhash) > 0) {
16002: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16003: $dom);
16004: if ($putresult eq 'ok') {
16005: if (keys(%changes) > 0) {
1.48 raeburn 16006: if (ref($confhash{'scantron'}) eq 'HASH') {
16007: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 16008: if ($changes{'scantronformat'}) {
16009: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16010: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16011: } else {
16012: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16013: }
16014: }
16015: if ($changes{'config'}) {
16016: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16017: if ($confhash{'scantron'}{'config'}{'dat'}) {
16018: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16019: }
16020: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16021: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16022: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16023: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16024: foreach my $field (@fields) {
16025: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16026: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16027: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16028: }
16029: }
16030: $resulttext .= '</ul></li>';
16031: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16032: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16033: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16034: foreach my $option (@options) {
16035: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16036: $resulttext .= '<li>'.$titles{$option}.'</li>';
16037: }
16038: }
16039: $resulttext .= '</ul></li>';
16040: }
16041: }
16042: }
16043: }
16044: }
16045: } else {
16046: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16047: }
1.46 raeburn 16048: }
1.48 raeburn 16049: $resulttext .= '</ul>';
16050: } else {
1.130 raeburn 16051: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16052: }
16053: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 16054: if (ref($lastactref) eq 'HASH') {
16055: $lastactref->{'domainconfig'} = 1;
16056: }
1.46 raeburn 16057: } else {
1.160.6.97 raeburn 16058: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16059: }
16060: } else {
16061: $resulttext = '<span class="LC_error">'.
16062: &mt('An error occurred: [_1]',$putresult).'</span>';
16063: }
16064: } else {
1.160.6.97 raeburn 16065: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16066: }
16067: if ($errors) {
16068: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16069: $errors.'</ul>';
16070: }
16071: return $resulttext;
16072: }
16073:
1.48 raeburn 16074: sub modify_coursecategories {
1.160.6.43 raeburn 16075: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16076: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16077: $cathash);
1.48 raeburn 16078: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 16079: my @catitems = ('unauth','auth');
16080: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16081: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16082: $cathash = $domconfig{'coursecategories'}{'cats'};
16083: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16084: $changes{'togglecats'} = 1;
16085: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16086: }
16087: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16088: $changes{'categorize'} = 1;
16089: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16090: }
1.120 raeburn 16091: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16092: $changes{'togglecatscomm'} = 1;
16093: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16094: }
16095: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16096: $changes{'categorizecomm'} = 1;
16097: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16098: }
1.160.6.42 raeburn 16099: foreach my $item (@catitems) {
16100: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16101: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16102: $changes{$item} = 1;
16103: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16104: }
16105: }
16106: }
1.57 raeburn 16107: } else {
16108: $changes{'togglecats'} = 1;
16109: $changes{'categorize'} = 1;
1.124 raeburn 16110: $changes{'togglecatscomm'} = 1;
16111: $changes{'categorizecomm'} = 1;
1.87 raeburn 16112: $domconfig{'coursecategories'} = {
16113: togglecats => $env{'form.togglecats'},
16114: categorize => $env{'form.categorize'},
1.124 raeburn 16115: togglecatscomm => $env{'form.togglecatscomm'},
16116: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 16117: };
1.160.6.42 raeburn 16118: foreach my $item (@catitems) {
16119: if ($env{'form.coursecat_'.$item} ne 'std') {
16120: $changes{$item} = 1;
16121: }
16122: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16123: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16124: }
16125: }
1.57 raeburn 16126: }
16127: if (ref($cathash) eq 'HASH') {
16128: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16129: push (@deletecategory,'instcode::0');
16130: }
1.120 raeburn 16131: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16132: push(@deletecategory,'communities::0');
16133: }
1.48 raeburn 16134: }
1.57 raeburn 16135: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16136: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16137: if (@deletecategory > 0) {
16138: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16139: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16140: foreach my $item (@deletecategory) {
1.57 raeburn 16141: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16142: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16143: $deletions{$item} = 1;
1.57 raeburn 16144: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16145: }
16146: }
16147: }
1.57 raeburn 16148: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16149: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16150: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16151: $reorderings{$item} = 1;
1.57 raeburn 16152: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16153: }
16154: if ($env{'form.addcategory_name_'.$item} ne '') {
16155: my $newcat = $env{'form.addcategory_name_'.$item};
16156: my $newdepth = $depth+1;
16157: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16158: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16159: $adds{$newitem} = 1;
16160: }
16161: if ($env{'form.subcat_'.$item} ne '') {
16162: my $newcat = $env{'form.subcat_'.$item};
16163: my $newdepth = $depth+1;
16164: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16165: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16166: $adds{$newitem} = 1;
16167: }
16168: }
16169: }
16170: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16171: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16172: my $newitem = 'instcode::0';
1.57 raeburn 16173: if ($cathash->{$newitem} eq '') {
16174: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16175: $adds{$newitem} = 1;
16176: }
16177: } else {
16178: my $newitem = 'instcode::0';
1.57 raeburn 16179: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16180: $adds{$newitem} = 1;
16181: }
16182: }
1.120 raeburn 16183: if ($env{'form.communities'} eq '1') {
16184: if (ref($cathash) eq 'HASH') {
16185: my $newitem = 'communities::0';
16186: if ($cathash->{$newitem} eq '') {
16187: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16188: $adds{$newitem} = 1;
16189: }
16190: } else {
16191: my $newitem = 'communities::0';
16192: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16193: $adds{$newitem} = 1;
16194: }
16195: }
1.48 raeburn 16196: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16197: if (($env{'form.addcategory_name'} ne 'instcode') &&
16198: ($env{'form.addcategory_name'} ne 'communities')) {
16199: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16200: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16201: $adds{$newitem} = 1;
16202: }
1.48 raeburn 16203: }
1.57 raeburn 16204: my $putresult;
1.48 raeburn 16205: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16206: if (keys(%deletions) > 0) {
16207: foreach my $key (keys(%deletions)) {
16208: if ($predelallitems{$key} ne '') {
16209: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16210: }
16211: }
16212: }
16213: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16214: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16215: if (ref($chkcats[0]) eq 'ARRAY') {
16216: my $depth = 0;
16217: my $chg = 0;
16218: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16219: my $name = $chkcats[0][$i];
16220: my $item;
16221: if ($name eq '') {
16222: $chg ++;
16223: } else {
16224: $item = &escape($name).'::0';
16225: if ($chg) {
1.57 raeburn 16226: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16227: }
16228: $depth ++;
1.57 raeburn 16229: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16230: $depth --;
16231: }
16232: }
16233: }
1.57 raeburn 16234: }
16235: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16236: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16237: if ($putresult eq 'ok') {
1.57 raeburn 16238: my %title = (
1.120 raeburn 16239: togglecats => 'Show/Hide a course in catalog',
16240: categorize => 'Assign a category to a course',
16241: togglecatscomm => 'Show/Hide a community in catalog',
16242: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16243: );
16244: my %level = (
1.120 raeburn 16245: dom => 'set in Domain ("Modify Course/Community")',
16246: crs => 'set in Course ("Course Configuration")',
16247: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 16248: none => 'No catalog',
16249: std => 'Standard catalog',
16250: domonly => 'Domain-only catalog',
16251: codesrch => 'Code search form',
1.57 raeburn 16252: );
1.48 raeburn 16253: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16254: if ($changes{'togglecats'}) {
16255: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16256: }
16257: if ($changes{'categorize'}) {
16258: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16259: }
1.120 raeburn 16260: if ($changes{'togglecatscomm'}) {
16261: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16262: }
16263: if ($changes{'categorizecomm'}) {
16264: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16265: }
1.160.6.42 raeburn 16266: if ($changes{'unauth'}) {
16267: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16268: }
16269: if ($changes{'auth'}) {
16270: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16271: }
1.57 raeburn 16272: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16273: my $cathash;
16274: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16275: $cathash = $domconfig{'coursecategories'}{'cats'};
16276: } else {
16277: $cathash = {};
16278: }
16279: my (@cats,@trails,%allitems);
16280: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16281: if (keys(%deletions) > 0) {
16282: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16283: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16284: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16285: }
16286: $resulttext .= '</ul></li>';
16287: }
16288: if (keys(%reorderings) > 0) {
16289: my %sort_by_trail;
16290: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16291: foreach my $key (keys(%reorderings)) {
16292: if ($allitems{$key} ne '') {
16293: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16294: }
1.48 raeburn 16295: }
1.57 raeburn 16296: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16297: $resulttext .= '<li>'.$trails[$trail].'</li>';
16298: }
16299: $resulttext .= '</ul></li>';
1.48 raeburn 16300: }
1.57 raeburn 16301: if (keys(%adds) > 0) {
16302: my %sort_by_trail;
16303: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16304: foreach my $key (keys(%adds)) {
16305: if ($allitems{$key} ne '') {
16306: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16307: }
16308: }
16309: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16310: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16311: }
1.57 raeburn 16312: $resulttext .= '</ul></li>';
1.48 raeburn 16313: }
1.160.6.92 raeburn 16314: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
16315: if (ref($lastactref) eq 'HASH') {
16316: $lastactref->{'cats'} = 1;
16317: }
1.48 raeburn 16318: }
16319: $resulttext .= '</ul>';
1.160.6.43 raeburn 16320: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 16321: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16322: if ($changes{'auth'}) {
16323: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16324: }
16325: if ($changes{'unauth'}) {
16326: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16327: }
16328: my $cachetime = 24*60*60;
16329: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 16330: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 16331: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 16332: }
16333: }
1.48 raeburn 16334: } else {
16335: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16336: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16337: }
16338: } else {
1.120 raeburn 16339: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16340: }
16341: return $resulttext;
16342: }
16343:
1.69 raeburn 16344: sub modify_serverstatuses {
16345: my ($dom,%domconfig) = @_;
16346: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16347: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16348: %currserverstatus = %{$domconfig{'serverstatuses'}};
16349: }
16350: my @pages = &serverstatus_pages();
16351: foreach my $type (@pages) {
16352: $newserverstatus{$type}{'namedusers'} = '';
16353: $newserverstatus{$type}{'machines'} = '';
16354: if (defined($env{'form.'.$type.'_namedusers'})) {
16355: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16356: my @okusers;
16357: foreach my $user (@users) {
16358: my ($uname,$udom) = split(/:/,$user);
16359: if (($udom =~ /^$match_domain$/) &&
16360: (&Apache::lonnet::domain($udom)) &&
16361: ($uname =~ /^$match_username$/)) {
16362: if (!grep(/^\Q$user\E/,@okusers)) {
16363: push(@okusers,$user);
16364: }
16365: }
16366: }
16367: if (@okusers > 0) {
16368: @okusers = sort(@okusers);
16369: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16370: }
16371: }
16372: if (defined($env{'form.'.$type.'_machines'})) {
16373: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16374: my @okmachines;
16375: foreach my $ip (@machines) {
16376: my @parts = split(/\./,$ip);
16377: next if (@parts < 4);
16378: my $badip = 0;
16379: for (my $i=0; $i<4; $i++) {
16380: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16381: $badip = 1;
16382: last;
16383: }
16384: }
16385: if (!$badip) {
16386: push(@okmachines,$ip);
16387: }
16388: }
16389: @okmachines = sort(@okmachines);
16390: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16391: }
16392: }
16393: my %serverstatushash = (
16394: serverstatuses => \%newserverstatus,
16395: );
16396: foreach my $type (@pages) {
1.83 raeburn 16397: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16398: my (@current,@new);
1.83 raeburn 16399: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16400: if ($currserverstatus{$type}{$setting} ne '') {
16401: @current = split(/,/,$currserverstatus{$type}{$setting});
16402: }
16403: }
16404: if ($newserverstatus{$type}{$setting} ne '') {
16405: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16406: }
16407: if (@current > 0) {
16408: if (@new > 0) {
16409: foreach my $item (@current) {
16410: if (!grep(/^\Q$item\E$/,@new)) {
16411: $changes{$type}{$setting} = 1;
1.82 raeburn 16412: last;
16413: }
16414: }
1.84 raeburn 16415: foreach my $item (@new) {
16416: if (!grep(/^\Q$item\E$/,@current)) {
16417: $changes{$type}{$setting} = 1;
16418: last;
1.82 raeburn 16419: }
16420: }
16421: } else {
1.83 raeburn 16422: $changes{$type}{$setting} = 1;
1.69 raeburn 16423: }
1.83 raeburn 16424: } elsif (@new > 0) {
16425: $changes{$type}{$setting} = 1;
1.69 raeburn 16426: }
16427: }
16428: }
16429: if (keys(%changes) > 0) {
1.81 raeburn 16430: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16431: my $putresult = &Apache::lonnet::put_dom('configuration',
16432: \%serverstatushash,$dom);
16433: if ($putresult eq 'ok') {
16434: $resulttext .= &mt('Changes made:').'<ul>';
16435: foreach my $type (@pages) {
1.84 raeburn 16436: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16437: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16438: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16439: if ($newserverstatus{$type}{'namedusers'} eq '') {
16440: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16441: } else {
16442: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16443: }
1.84 raeburn 16444: }
16445: if ($changes{$type}{'machines'}) {
1.69 raeburn 16446: if ($newserverstatus{$type}{'machines'} eq '') {
16447: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16448: } else {
16449: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16450: }
16451:
16452: }
16453: $resulttext .= '</ul></li>';
16454: }
16455: }
16456: $resulttext .= '</ul>';
16457: } else {
16458: $resulttext = '<span class="LC_error">'.
16459: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
16460:
16461: }
16462: } else {
16463: $resulttext = &mt('No changes made to access to server status pages');
16464: }
16465: return $resulttext;
16466: }
16467:
1.118 jms 16468: sub modify_helpsettings {
1.160.6.77 raeburn 16469: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 16470: my ($resulttext,$errors,%changes,%helphash);
16471: my %defaultchecked = ('submitbugs' => 'on');
16472: my @offon = ('off','on');
1.118 jms 16473: my @toggles = ('submitbugs');
1.160.6.77 raeburn 16474: my %current = ('submitbugs' => '',
16475: 'adhoc' => {},
16476: );
1.118 jms 16477: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 16478: %current = %{$domconfig{'helpsettings'}};
16479: }
1.160.6.77 raeburn 16480: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 16481: foreach my $item (@toggles) {
16482: if ($defaultchecked{$item} eq 'on') {
16483: if ($current{$item} eq '') {
16484: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 16485: $changes{$item} = 1;
16486: }
1.160.6.73 raeburn 16487: } elsif ($current{$item} ne $env{'form.'.$item}) {
16488: $changes{$item} = 1;
16489: }
16490: } elsif ($defaultchecked{$item} eq 'off') {
16491: if ($current{$item} eq '') {
16492: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 16493: $changes{$item} = 1;
16494: }
1.160.6.73 raeburn 16495: } elsif ($current{$item} ne $env{'form.'.$item}) {
16496: $changes{$item} = 1;
16497: }
16498: }
16499: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
16500: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
16501: }
16502: }
1.160.6.77 raeburn 16503: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 16504: my $confname = $dom.'-domainconfig';
16505: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 16506: my (@allpos,%newsettings,%changedprivs,$newrole);
16507: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 16508: my @accesstypes = ('all','dh','da','none','status','inc','exc');
16509: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 16510: my %lt = &Apache::lonlocal::texthash(
16511: s => 'system',
16512: d => 'domain',
16513: order => 'Display order',
16514: access => 'Role usage',
1.160.6.79 raeburn 16515: all => 'All with domain helpdesk or helpdesk assistant role',
16516: dh => 'All with domain helpdesk role',
16517: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 16518: none => 'None',
16519: status => 'Determined based on institutional status',
16520: inc => 'Include all, but exclude specific personnel',
16521: exc => 'Exclude all, but include specific personnel',
16522: );
16523: for (my $num=0; $num<=$maxnum; $num++) {
16524: my ($prefix,$identifier,$rolename,%curr);
16525: if ($num == $maxnum) {
16526: next unless ($env{'form.newcusthelp'} == $maxnum);
16527: $identifier = 'custhelp'.$num;
16528: $prefix = 'helproles_'.$num;
16529: $rolename = $env{'form.custhelpname'.$num};
16530: $rolename=~s/[^A-Za-z0-9]//gs;
16531: next if ($rolename eq '');
16532: next if (exists($existing{'rolesdef_'.$rolename}));
16533: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16534: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16535: $newprivs{'c'},$confname,$dom);
16536: if ($result ne 'ok') {
16537: $errors .= '<li><span class="LC_error">'.
16538: &mt('An error occurred storing the new custom role: [_1]',
16539: $result).'</span></li>';
16540: next;
16541: } else {
16542: $changedprivs{$rolename} = \%newprivs;
16543: $newrole = $rolename;
16544: }
16545: } else {
16546: $prefix = 'helproles_'.$num;
16547: $rolename = $env{'form.'.$prefix};
16548: next if ($rolename eq '');
16549: next unless (exists($existing{'rolesdef_'.$rolename}));
16550: $identifier = 'custhelp'.$num;
16551: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16552: my %currprivs;
16553: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
16554: split(/\_/,$existing{'rolesdef_'.$rolename});
16555: foreach my $level ('c','d','s') {
16556: if ($newprivs{$level} ne $currprivs{$level}) {
16557: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16558: $newprivs{'c'},$confname,$dom);
16559: if ($result ne 'ok') {
16560: $errors .= '<li><span class="LC_error">'.
16561: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
16562: $rolename,$result).'</span></li>';
16563: } else {
16564: $changedprivs{$rolename} = \%newprivs;
16565: }
16566: last;
16567: }
16568: }
16569: if (ref($current{'adhoc'}) eq 'HASH') {
16570: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16571: %curr = %{$current{'adhoc'}{$rolename}};
16572: }
16573: }
16574: }
16575: my $newpos = $env{'form.'.$prefix.'_pos'};
16576: $newpos =~ s/\D+//g;
16577: $allpos[$newpos] = $rolename;
16578: my $newdesc = $env{'form.'.$prefix.'_desc'};
16579: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
16580: if ($curr{'desc'}) {
16581: if ($curr{'desc'} ne $newdesc) {
16582: $changes{'customrole'}{$rolename}{'desc'} = 1;
16583: $newsettings{$rolename}{'desc'} = $newdesc;
16584: }
16585: } elsif ($newdesc ne '') {
16586: $changes{'customrole'}{$rolename}{'desc'} = 1;
16587: $newsettings{$rolename}{'desc'} = $newdesc;
16588: }
16589: my $access = $env{'form.'.$prefix.'_access'};
16590: if (grep(/^\Q$access\E$/,@accesstypes)) {
16591: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
16592: if ($access eq 'status') {
16593: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
16594: if (scalar(@statuses) == 0) {
16595: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
16596: } else {
16597: my (@shownstatus,$numtypes);
16598: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16599: if (ref($types) eq 'ARRAY') {
16600: $numtypes = scalar(@{$types});
16601: foreach my $type (sort(@statuses)) {
16602: if ($type eq 'default') {
16603: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16604: } elsif (grep(/^\Q$type\E$/,@{$types})) {
16605: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16606: push(@shownstatus,$usertypes->{$type});
16607: }
1.160.6.73 raeburn 16608: }
16609: }
1.160.6.77 raeburn 16610: if (grep(/^default$/,@statuses)) {
16611: push(@shownstatus,$othertitle);
16612: }
16613: if (scalar(@shownstatus) == 1+$numtypes) {
16614: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
16615: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
16616: } else {
16617: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
16618: if (ref($curr{'status'}) eq 'ARRAY') {
16619: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16620: if (@diffs) {
16621: $changes{'customrole'}{$rolename}{$access} = 1;
16622: }
16623: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16624: $changes{'customrole'}{$rolename}{$access} = 1;
16625: }
16626: }
16627: }
16628: } elsif (($access eq 'inc') || ($access eq 'exc')) {
16629: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
16630: my @newspecstaff;
16631: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16632: foreach my $person (sort(@personnel)) {
16633: if ($domhelpdesk{$person}) {
16634: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
16635: }
16636: }
16637: if (ref($curr{$access}) eq 'ARRAY') {
16638: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16639: if (@diffs) {
16640: $changes{'customrole'}{$rolename}{$access} = 1;
16641: }
16642: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16643: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 16644: }
1.160.6.77 raeburn 16645: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16646: my ($uname,$udom) = split(/:/,$person);
16647: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
16648: }
16649: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 16650: }
1.160.6.77 raeburn 16651: } else {
16652: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
16653: }
16654: unless ($curr{'access'} eq $access) {
16655: $changes{'customrole'}{$rolename}{'access'} = 1;
16656: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 16657: }
16658: }
1.160.6.77 raeburn 16659: if (@allpos > 0) {
16660: my $idx = 0;
16661: foreach my $rolename (@allpos) {
16662: if ($rolename ne '') {
16663: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
16664: if (ref($current{'adhoc'}) eq 'HASH') {
16665: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16666: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
16667: $changes{'customrole'}{$rolename}{'order'} = 1;
16668: $newsettings{$rolename}{'order'} = $idx+1;
16669: }
16670: }
1.160.6.73 raeburn 16671: }
1.160.6.77 raeburn 16672: $idx ++;
1.122 jms 16673: }
16674: }
1.118 jms 16675: }
1.123 jms 16676: my $putresult;
16677: if (keys(%changes) > 0) {
1.160.6.5 raeburn 16678: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
16679: if ($putresult eq 'ok') {
1.160.6.77 raeburn 16680: if (ref($helphash{'helpsettings'}) eq 'HASH') {
16681: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
16682: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
16683: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
16684: }
16685: }
16686: my $cachetime = 24*60*60;
16687: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16688: if (ref($lastactref) eq 'HASH') {
16689: $lastactref->{'domdefaults'} = 1;
16690: }
16691: } else {
16692: $errors .= '<li><span class="LC_error">'.
16693: &mt('An error occurred storing the settings: [_1]',
16694: $putresult).'</span></li>';
16695: }
16696: }
16697: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
16698: $resulttext = &mt('Changes made:').'<ul>';
16699: my (%shownprivs,@levelorder);
16700: @levelorder = ('c','d','s');
16701: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 16702: foreach my $item (sort(keys(%changes))) {
16703: if ($item eq 'submitbugs') {
16704: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
16705: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
16706: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 16707: } elsif ($item eq 'customrole') {
16708: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 16709: my @keyorder = ('order','desc','access','status','exc','inc');
16710: my %keytext = &Apache::lonlocal::texthash(
16711: order => 'Order',
16712: desc => 'Role description',
16713: access => 'Role usage',
1.160.6.83 raeburn 16714: status => 'Allowed institutional types',
1.160.6.77 raeburn 16715: exc => 'Allowed personnel',
16716: inc => 'Disallowed personnel',
16717: );
1.160.6.73 raeburn 16718: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 16719: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
16720: if ($role eq $newrole) {
16721: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
16722: $role).'<ul>';
16723: } else {
16724: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16725: $role).'<ul>';
16726: }
16727: foreach my $key (@keyorder) {
16728: if ($changes{'customrole'}{$role}{$key}) {
16729: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16730: $keytext{$key},$newsettings{$role}{$key}).
16731: '</li>';
16732: }
16733: }
16734: if (ref($changedprivs{$role}) eq 'HASH') {
16735: $shownprivs{$role} = 1;
16736: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16737: foreach my $level (@levelorder) {
16738: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16739: next if ($item eq '');
16740: my ($priv) = split(/\&/,$item,2);
16741: if (&Apache::lonnet::plaintext($priv)) {
16742: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16743: unless ($level eq 'c') {
16744: $resulttext .= ' ('.$lt{$level}.')';
16745: }
16746: $resulttext .= '</li>';
16747: }
16748: }
16749: }
16750: $resulttext .= '</ul>';
16751: }
16752: $resulttext .= '</ul></li>';
16753: }
1.160.6.73 raeburn 16754: }
16755: }
1.160.6.5 raeburn 16756: }
16757: }
16758: }
1.160.6.77 raeburn 16759: if (keys(%changedprivs)) {
16760: foreach my $role (sort(keys(%changedprivs))) {
16761: unless ($shownprivs{$role}) {
16762: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16763: $role).'<ul>'.
16764: '<li>'.&mt('Privileges set to :').'<ul>';
16765: foreach my $level (@levelorder) {
16766: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16767: next if ($item eq '');
16768: my ($priv) = split(/\&/,$item,2);
16769: if (&Apache::lonnet::plaintext($priv)) {
16770: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16771: unless ($level eq 'c') {
16772: $resulttext .= ' ('.$lt{$level}.')';
16773: }
16774: $resulttext .= '</li>';
16775: }
16776: }
16777: }
16778: $resulttext .= '</ul></li></ul></li>';
16779: }
16780: }
16781: }
16782: $resulttext .= '</ul>';
16783: } else {
16784: $resulttext = &mt('No changes made to help settings');
1.118 jms 16785: }
16786: if ($errors) {
1.160.6.5 raeburn 16787: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 16788: $errors.'</ul>';
1.118 jms 16789: }
16790: return $resulttext;
16791: }
16792:
1.121 raeburn 16793: sub modify_coursedefaults {
1.160.6.27 raeburn 16794: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16795: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 16796: my %defaultchecked = (
16797: 'uselcmath' => 'on',
1.160.6.115 raeburn 16798: 'usejsme' => 'on',
16799: 'inline_chem' => 'on',
1.160.6.57 raeburn 16800: );
1.160.6.115 raeburn 16801: my @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.21 raeburn 16802: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 16803: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
16804: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 16805: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 16806: my %staticdefaults = (
16807: anonsurvey_threshold => 10,
16808: uploadquota => 500,
1.160.6.57 raeburn 16809: postsubmit => 60,
1.160.6.70 raeburn 16810: mysqltables => 172800,
1.160.6.21 raeburn 16811: );
1.160.6.90 raeburn 16812: my %texoptions = (
16813: MathJax => 'MathJax',
16814: mimetex => &mt('Convert to Images'),
16815: tth => &mt('TeX to HTML'),
16816: );
1.121 raeburn 16817: $defaultshash{'coursedefaults'} = {};
16818:
16819: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16820: if ($domconfig{'coursedefaults'} eq '') {
16821: $domconfig{'coursedefaults'} = {};
16822: }
16823: }
16824:
16825: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16826: foreach my $item (@toggles) {
16827: if ($defaultchecked{$item} eq 'on') {
16828: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16829: ($env{'form.'.$item} eq '0')) {
16830: $changes{$item} = 1;
1.160.6.16 raeburn 16831: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16832: $changes{$item} = 1;
16833: }
16834: } elsif ($defaultchecked{$item} eq 'off') {
16835: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16836: ($env{'form.'.$item} eq '1')) {
16837: $changes{$item} = 1;
16838: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16839: $changes{$item} = 1;
16840: }
16841: }
16842: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16843: }
1.160.6.21 raeburn 16844: foreach my $item (@numbers) {
16845: my ($currdef,$newdef);
1.160.6.26 raeburn 16846: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 16847: if ($item eq 'anonsurvey_threshold') {
16848: $currdef = $domconfig{'coursedefaults'}{$item};
16849: $newdef =~ s/\D//g;
16850: if ($newdef eq '' || $newdef < 1) {
16851: $newdef = 1;
16852: }
16853: $defaultshash{'coursedefaults'}{$item} = $newdef;
16854: } else {
1.160.6.70 raeburn 16855: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16856: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16857: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 16858: }
16859: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 16860: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 16861: }
16862: if ($currdef ne $newdef) {
16863: if ($item eq 'anonsurvey_threshold') {
16864: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16865: $changes{$item} = 1;
16866: }
1.160.6.70 raeburn 16867: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
16868: my $setting = $1;
16869: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16870: $changes{$setting} = 1;
1.160.6.21 raeburn 16871: }
16872: }
1.139 raeburn 16873: }
16874: }
1.160.6.90 raeburn 16875: my $texengine;
16876: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16877: $texengine = $env{'form.texengine'};
16878: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
16879: if ($currdef eq '') {
16880: unless ($texengine eq $Apache::lonnet::deftex) {
16881: $changes{'texengine'} = 1;
16882: }
16883: } elsif ($currdef ne $texengine) {
16884: $changes{'texengine'} = 1;
16885: }
16886: }
16887: if ($texengine ne '') {
16888: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16889: }
1.160.6.64 raeburn 16890: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16891: my @currclonecode;
16892: if (ref($currclone) eq 'HASH') {
16893: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16894: @currclonecode = @{$currclone->{'instcode'}};
16895: }
16896: }
16897: my $newclone;
16898: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
16899: $newclone = $env{'form.canclone'};
16900: }
16901: if ($newclone eq 'instcode') {
16902: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16903: my (%codedefaults,@code_order,@clonecode);
16904: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16905: \@code_order);
16906: foreach my $item (@code_order) {
16907: if (grep(/^\Q$item\E$/,@newcodes)) {
16908: push(@clonecode,$item);
16909: }
16910: }
16911: if (@clonecode) {
16912: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16913: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16914: if (@diffs) {
16915: $changes{'canclone'} = 1;
16916: }
16917: } else {
16918: $newclone eq '';
16919: }
16920: } elsif ($newclone ne '') {
16921: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16922: }
16923: if ($newclone ne $currclone) {
16924: $changes{'canclone'} = 1;
16925: }
1.160.6.57 raeburn 16926: my %credits;
16927: foreach my $type (@types) {
16928: unless ($type eq 'community') {
16929: $credits{$type} = $env{'form.'.$type.'_credits'};
16930: $credits{$type} =~ s/[^\d.]+//g;
16931: }
16932: }
16933: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
16934: ($env{'form.coursecredits'} eq '1')) {
16935: $changes{'coursecredits'} = 1;
16936: foreach my $type (keys(%credits)) {
16937: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16938: }
16939: } else {
16940: if ($env{'form.coursecredits'} eq '1') {
16941: foreach my $type (@types) {
16942: unless ($type eq 'community') {
16943: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
16944: $changes{'coursecredits'} = 1;
16945: }
16946: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16947: }
16948: }
16949: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
16950: foreach my $type (@types) {
16951: unless ($type eq 'community') {
16952: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
16953: $changes{'coursecredits'} = 1;
16954: last;
16955: }
16956: }
16957: }
16958: }
16959: }
16960: if ($env{'form.postsubmit'} eq '1') {
16961: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
16962: my %currtimeout;
16963: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16964: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
16965: $changes{'postsubmit'} = 1;
16966: }
16967: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
16968: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
16969: }
16970: } else {
16971: $changes{'postsubmit'} = 1;
16972: }
16973: foreach my $type (@types) {
16974: my $timeout = $env{'form.'.$type.'_timeout'};
16975: $timeout =~ s/\D//g;
16976: if ($timeout == $staticdefaults{'postsubmit'}) {
16977: $timeout = '';
16978: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
16979: $timeout = '0';
16980: }
16981: unless ($timeout eq '') {
16982: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
16983: }
16984: if (exists($currtimeout{$type})) {
16985: if ($timeout ne $currtimeout{$type}) {
16986: $changes{'postsubmit'} = 1;
16987: }
16988: } elsif ($timeout ne '') {
16989: $changes{'postsubmit'} = 1;
16990: }
16991: }
16992: } else {
16993: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
16994: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
16995: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
16996: $changes{'postsubmit'} = 1;
16997: }
16998: } else {
16999: $changes{'postsubmit'} = 1;
17000: }
1.160.6.16 raeburn 17001: }
1.121 raeburn 17002: }
17003: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17004: $dom);
17005: if ($putresult eq 'ok') {
17006: if (keys(%changes) > 0) {
1.160.6.27 raeburn 17007: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 17008: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 17009: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 17010: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
17011: ($changes{'inline_chem'})) {
17012: foreach my $item ('uselcmath','usejsme','inline_chem','texengine') {
1.160.6.57 raeburn 17013: if ($changes{$item}) {
17014: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17015: }
1.160.6.16 raeburn 17016: }
17017: if ($changes{'coursecredits'}) {
17018: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 17019: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17020: $domdefaults{$type.'credits'} =
17021: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17022: }
17023: }
17024: }
17025: if ($changes{'postsubmit'}) {
17026: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17027: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17028: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17029: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17030: $domdefaults{$type.'postsubtimeout'} =
17031: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17032: }
17033: }
1.160.6.16 raeburn 17034: }
17035: }
1.160.6.21 raeburn 17036: if ($changes{'uploadquota'}) {
17037: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17038: foreach my $type (@types) {
17039: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17040: }
17041: }
17042: }
1.160.6.64 raeburn 17043: if ($changes{'canclone'}) {
17044: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17045: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17046: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17047: if (@clonecodes) {
17048: $domdefaults{'canclone'} = join('+',@clonecodes);
17049: }
17050: }
17051: } else {
17052: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17053: }
17054: }
1.121 raeburn 17055: my $cachetime = 24*60*60;
17056: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17057: if (ref($lastactref) eq 'HASH') {
17058: $lastactref->{'domdefaults'} = 1;
17059: }
1.121 raeburn 17060: }
17061: $resulttext = &mt('Changes made:').'<ul>';
17062: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 17063: if ($item eq 'uselcmath') {
1.121 raeburn 17064: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 17065: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 17066: } else {
1.160.6.57 raeburn 17067: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17068: }
17069: } elsif ($item eq 'usejsme') {
17070: if ($env{'form.'.$item} eq '1') {
17071: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17072: } else {
17073: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 17074: }
1.160.6.115 raeburn 17075: } elsif ($item eq 'inline_chem') {
17076: if ($env{'form.'.$item} eq '1') {
17077: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17078: } else {
17079: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17080: }
1.160.6.90 raeburn 17081: } elsif ($item eq 'texengine') {
17082: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17083: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17084: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17085: }
1.139 raeburn 17086: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 17087: $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 17088: } elsif ($item eq 'uploadquota') {
17089: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17090: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17091: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17092: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 17093: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17094:
1.160.6.21 raeburn 17095: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17096: '</ul>'.
17097: '</li>';
17098: } else {
17099: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17100: }
1.160.6.70 raeburn 17101: } elsif ($item eq 'mysqltables') {
17102: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17103: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17104: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17105: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17106: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17107: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17108: '</ul>'.
17109: '</li>';
17110: } else {
17111: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17112: }
1.160.6.57 raeburn 17113: } elsif ($item eq 'postsubmit') {
17114: if ($domdefaults{'postsubmit'} eq 'off') {
17115: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17116: } else {
17117: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17118: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17119: $resulttext .= &mt('durations:').'<ul>';
17120: foreach my $type (@types) {
17121: $resulttext .= '<li>';
17122: my $timeout;
17123: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17124: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17125: }
17126: my $display;
17127: if ($timeout eq '0') {
17128: $display = &mt('unlimited');
17129: } elsif ($timeout eq '') {
17130: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17131: } else {
17132: $display = &mt('[quant,_1,second]',$timeout);
17133: }
17134: if ($type eq 'community') {
17135: $resulttext .= &mt('Communities');
17136: } elsif ($type eq 'official') {
17137: $resulttext .= &mt('Official courses');
17138: } elsif ($type eq 'unofficial') {
17139: $resulttext .= &mt('Unofficial courses');
17140: } elsif ($type eq 'textbook') {
17141: $resulttext .= &mt('Textbook courses');
17142: }
17143: $resulttext .= ' -- '.$display.'</li>';
17144: }
17145: $resulttext .= '</ul>';
17146: }
17147: $resulttext .= '</li>';
17148: }
1.160.6.16 raeburn 17149: } elsif ($item eq 'coursecredits') {
17150: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17151: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 17152: ($domdefaults{'unofficialcredits'} eq '') &&
17153: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 17154: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17155: } else {
17156: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17157: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17158: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 17159: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 17160: '</ul>'.
17161: '</li>';
17162: }
17163: } else {
17164: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17165: }
1.160.6.64 raeburn 17166: } elsif ($item eq 'canclone') {
17167: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17168: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17169: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17170: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17171: }
17172: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17173: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17174: } else {
17175: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
17176: }
1.140 raeburn 17177: }
1.121 raeburn 17178: }
17179: $resulttext .= '</ul>';
17180: } else {
17181: $resulttext = &mt('No changes made to course defaults');
17182: }
17183: } else {
17184: $resulttext = '<span class="LC_error">'.
17185: &mt('An error occurred: [_1]',$putresult).'</span>';
17186: }
17187: return $resulttext;
17188: }
17189:
1.160.6.37 raeburn 17190: sub modify_selfenrollment {
17191: my ($dom,$lastactref,%domconfig) = @_;
17192: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
17193: my @types = ('official','unofficial','community','textbook');
17194: my %titles = &tool_titles();
17195: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17196: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
17197: $ordered{'default'} = ['types','registered','approval','limit'];
17198:
17199: my (%roles,%shown,%toplevel);
17200: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17201:
17202: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17203: if ($domconfig{'selfenrollment'} eq '') {
17204: $domconfig{'selfenrollment'} = {};
17205: }
17206: }
17207: %toplevel = (
17208: admin => 'Configuration Rights',
17209: default => 'Default settings',
17210: validation => 'Validation of self-enrollment requests',
17211: );
17212: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
17213:
17214: if (ref($ordered{'admin'}) eq 'ARRAY') {
17215: foreach my $item (@{$ordered{'admin'}}) {
17216: foreach my $type (@types) {
17217: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17218: $selfenrollhash{'admin'}{$type}{$item} = 1;
17219: } else {
17220: $selfenrollhash{'admin'}{$type}{$item} = 0;
17221: }
17222: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17223: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17224: if ($selfenrollhash{'admin'}{$type}{$item} ne
17225: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17226: push(@{$changes{'admin'}{$type}},$item);
17227: }
17228: } else {
17229: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17230: push(@{$changes{'admin'}{$type}},$item);
17231: }
17232: }
17233: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17234: push(@{$changes{'admin'}{$type}},$item);
17235: }
17236: }
17237: }
17238: }
17239:
17240: foreach my $item (@{$ordered{'default'}}) {
17241: foreach my $type (@types) {
17242: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17243: if ($item eq 'types') {
17244: unless (($value eq 'all') || ($value eq 'dom')) {
17245: $value = '';
17246: }
17247: } elsif ($item eq 'registered') {
17248: unless ($value eq '1') {
17249: $value = 0;
17250: }
17251: } elsif ($item eq 'approval') {
17252: unless ($value =~ /^[012]$/) {
17253: $value = 0;
17254: }
17255: } else {
17256: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17257: $value = 'none';
17258: }
17259: }
17260: $selfenrollhash{'default'}{$type}{$item} = $value;
17261: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17262: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17263: if ($selfenrollhash{'default'}{$type}{$item} ne
17264: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17265: push(@{$changes{'default'}{$type}},$item);
17266: }
17267: } else {
17268: push(@{$changes{'default'}{$type}},$item);
17269: }
17270: } else {
17271: push(@{$changes{'default'}{$type}},$item);
17272: }
17273: if ($item eq 'limit') {
17274: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17275: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17276: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17277: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17278: }
17279: } else {
17280: $selfenrollhash{'default'}{$type}{'cap'} = '';
17281: }
17282: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17283: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17284: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17285: push(@{$changes{'default'}{$type}},'cap');
17286: }
17287: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17288: push(@{$changes{'default'}{$type}},'cap');
17289: }
17290: }
17291: }
17292: }
17293:
17294: foreach my $item (@{$itemsref}) {
17295: if ($item eq 'fields') {
17296: my @changed;
17297: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17298: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17299: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17300: }
17301: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17302: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17303: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17304: $domconfig{'selfenrollment'}{'validation'}{$item});
17305: } else {
17306: @changed = @{$selfenrollhash{'validation'}{$item}};
17307: }
17308: } else {
17309: @changed = @{$selfenrollhash{'validation'}{$item}};
17310: }
17311: if (@changed) {
17312: if ($selfenrollhash{'validation'}{$item}) {
17313: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17314: } else {
17315: $changes{'validation'}{$item} = &mt('None');
17316: }
17317: }
17318: } else {
17319: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17320: if ($item eq 'markup') {
17321: if ($env{'form.selfenroll_validation_'.$item}) {
17322: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17323: }
17324: }
17325: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17326: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17327: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17328: }
17329: }
17330: }
17331: }
17332:
17333: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17334: $dom);
17335: if ($putresult eq 'ok') {
17336: if (keys(%changes) > 0) {
17337: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17338: $resulttext = &mt('Changes made:').'<ul>';
17339: foreach my $key ('admin','default','validation') {
17340: if (ref($changes{$key}) eq 'HASH') {
17341: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17342: if ($key eq 'validation') {
17343: foreach my $item (@{$itemsref}) {
17344: if (exists($changes{$key}{$item})) {
17345: if ($item eq 'markup') {
17346: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17347: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17348: } else {
17349: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17350: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17351: }
17352: }
17353: }
17354: } else {
17355: foreach my $type (@types) {
17356: if ($type eq 'community') {
17357: $roles{'1'} = &mt('Community personnel');
17358: } else {
17359: $roles{'1'} = &mt('Course personnel');
17360: }
17361: if (ref($changes{$key}{$type}) eq 'ARRAY') {
17362: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17363: if ($key eq 'admin') {
17364: my @mgrdc = ();
17365: if (ref($ordered{$key}) eq 'ARRAY') {
17366: foreach my $item (@{$ordered{'admin'}}) {
17367: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17368: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17369: push(@mgrdc,$item);
17370: }
17371: }
17372: }
17373: if (@mgrdc) {
17374: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17375: } else {
17376: delete($domdefaults{$type.'selfenrolladmdc'});
17377: }
17378: }
17379: } else {
17380: if (ref($ordered{$key}) eq 'ARRAY') {
17381: foreach my $item (@{$ordered{$key}}) {
17382: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17383: $domdefaults{$type.'selfenroll'.$item} =
17384: $selfenrollhash{$key}{$type}{$item};
17385: }
17386: }
17387: }
17388: }
17389: }
17390: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17391: foreach my $item (@{$ordered{$key}}) {
17392: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17393: $resulttext .= '<li>';
17394: if ($key eq 'admin') {
17395: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17396: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17397: } else {
17398: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17399: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17400: }
17401: $resulttext .= '</li>';
17402: }
17403: }
17404: $resulttext .= '</ul></li>';
17405: }
17406: }
17407: $resulttext .= '</ul></li>';
17408: }
17409: }
1.160.6.93 raeburn 17410: }
17411: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17412: my $cachetime = 24*60*60;
17413: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17414: if (ref($lastactref) eq 'HASH') {
17415: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 17416: }
17417: }
17418: $resulttext .= '</ul>';
17419: } else {
17420: $resulttext = &mt('No changes made to self-enrollment settings');
17421: }
17422: } else {
17423: $resulttext = '<span class="LC_error">'.
17424: &mt('An error occurred: [_1]',$putresult).'</span>';
17425: }
17426: return $resulttext;
17427: }
17428:
1.160.6.113 raeburn 17429: sub modify_wafproxy {
17430: my ($dom,$action,$lastactref,%domconfig) = @_;
17431: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17432: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
17433: %wafproxy,%changes,%expirecache,%expiresaml);
17434: foreach my $server (sort(keys(%servers))) {
17435: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
17436: if ($serverhome eq $server) {
17437: my $serverdom = &Apache::lonnet::host_domain($server);
17438: if ($serverdom eq $dom) {
17439: $canset{$server} = 1;
17440: }
17441: }
17442: }
17443: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
17444: %{$values{$dom}} = ();
17445: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
17446: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
17447: }
17448: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
17449: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
17450: }
17451: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
17452: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
17453: }
17454: }
17455: my $output;
17456: if (keys(%canset)) {
17457: %{$wafproxy{'alias'}} = ();
17458: %{$wafproxy{'saml'}} = ();
17459: foreach my $key (sort(keys(%canset))) {
17460: if ($env{'form.wafproxy_'.$dom}) {
17461: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
17462: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
17463: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
17464: $changes{'alias'} = 1;
17465: }
17466: if ($env{'form.wafproxy_alias_saml_'.$key}) {
17467: $wafproxy{'saml'}{$key} = 1;
17468: }
17469: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
17470: $changes{'saml'} = 1;
17471: }
17472: } else {
17473: $wafproxy{'alias'}{$key} = '';
17474: $wafproxy{'saml'}{$key} = '';
17475: if ($curralias{$key}) {
17476: $changes{'alias'} = 1;
17477: }
17478: if ($currsaml{$key}) {
17479: $changes{'saml'} = 1;
17480: }
17481: }
17482: if ($wafproxy{'alias'}{$key} eq '') {
17483: if ($curralias{$key}) {
17484: $expirecache{$key} = 1;
17485: }
17486: delete($wafproxy{'alias'}{$key});
17487: }
17488: if ($wafproxy{'saml'}{$key} eq '') {
17489: if ($currsaml{$key}) {
17490: $expiresaml{$key} = 1;
17491: }
17492: delete($wafproxy{'saml'}{$key});
17493: }
17494: }
17495: unless (keys(%{$wafproxy{'alias'}})) {
17496: delete($wafproxy{'alias'});
17497: }
17498: unless (keys(%{$wafproxy{'saml'}})) {
17499: delete($wafproxy{'saml'});
17500: }
17501: # Localization for values in %warn occurs in &mt() calls separately.
17502: my %warn = (
17503: trusted => 'trusted IP range(s)',
17504: vpnint => 'internal IP range(s) for VPN sessions(s)',
17505: vpnext => 'IP range(s) for backend WAF connections',
17506: );
17507: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
17508: my $possible = $env{'form.wafproxy_'.$item};
17509: $possible =~ s/^\s+|\s+$//g;
17510: if ($possible ne '') {
17511: if ($item eq 'remoteip') {
17512: if ($possible =~ /^[mhn]$/) {
17513: $wafproxy{$item} = $possible;
17514: }
17515: } elsif ($item eq 'ipheader') {
17516: if ($wafproxy{'remoteip'} eq 'h') {
17517: $wafproxy{$item} = $possible;
17518: }
17519: } elsif ($item eq 'sslopt') {
17520: if ($possible =~ /^0|1$/) {
17521: $wafproxy{$item} = $possible;
17522: }
17523: } else {
17524: my (@ok,$count);
17525: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
17526: unless ($env{'form.wafproxy_vpnaccess'}) {
17527: $possible = '';
17528: }
17529: } elsif ($item eq 'trusted') {
17530: unless ($wafproxy{'remoteip'} eq 'h') {
17531: $possible = '';
17532: }
17533: }
17534: unless ($possible eq '') {
17535: $possible =~ s/[\r\n]+/\s/g;
17536: $possible =~ s/\s*-\s*/-/g;
17537: $possible =~ s/\s+/,/g;
17538: $possible =~ s/,+/,/g;
17539: }
17540: $count = 0;
17541: if ($possible ne '') {
17542: foreach my $poss (split(/\,/,$possible)) {
17543: $count ++;
17544: $poss = &validate_ip_pattern($poss);
17545: if ($poss ne '') {
17546: push(@ok,$poss);
17547: }
17548: }
17549: my $diff = $count - scalar(@ok);
17550: if ($diff) {
17551: push(@warnings,'<li>'.
17552: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
17553: $diff,$warn{$item}).
17554: '</li>');
17555: }
17556: if (@ok) {
17557: my @cidr_list;
17558: foreach my $item (@ok) {
17559: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
17560: }
17561: $wafproxy{$item} = join(',',@cidr_list);
17562: }
17563: }
17564: }
17565: if ($wafproxy{$item} ne $currvalue{$item}) {
17566: $changes{$item} = 1;
17567: }
17568: } elsif ($currvalue{$item}) {
17569: $changes{$item} = 1;
17570: }
17571: }
17572: } else {
17573: if (keys(%curralias)) {
17574: $changes{'alias'} = 1;
17575: }
17576: if (keys(%currsaml)) {
17577: $changes{'saml'} = 1;
17578: }
17579: if (keys(%currvalue)) {
17580: foreach my $key (keys(%currvalue)) {
17581: $changes{$key} = 1;
17582: }
17583: }
17584: }
17585: if (keys(%changes)) {
17586: my %defaultshash = (
17587: wafproxy => \%wafproxy,
17588: );
17589: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17590: $dom);
17591: if ($putresult eq 'ok') {
17592: my $cachetime = 24*60*60;
17593: my (%domdefaults,$updatedomdefs);
17594: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
17595: if ($changes{$item}) {
17596: unless ($updatedomdefs) {
17597: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17598: $updatedomdefs = 1;
17599: }
17600: if ($wafproxy{$item}) {
17601: $domdefaults{'waf_'.$item} = $wafproxy{$item};
17602: } elsif (exists($domdefaults{'waf_'.$item})) {
17603: delete($domdefaults{'waf_'.$item});
17604: }
17605: }
17606: }
17607: if ($updatedomdefs) {
17608: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17609: if (ref($lastactref) eq 'HASH') {
17610: $lastactref->{'domdefaults'} = 1;
17611: }
17612: }
17613: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
17614: my %updates = %expirecache;
17615: foreach my $key (keys(%expirecache)) {
17616: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
17617: }
17618: if (ref($wafproxy{'alias'}) eq 'HASH') {
17619: my $cachetime = 24*60*60;
17620: foreach my $key (keys(%{$wafproxy{'alias'}})) {
17621: $updates{$key} = 1;
17622: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
17623: $cachetime);
17624: }
17625: }
17626: if (ref($lastactref) eq 'HASH') {
17627: $lastactref->{'proxyalias'} = \%updates;
17628: }
17629: }
17630: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
17631: my %samlupdates = %expiresaml;
17632: foreach my $key (keys(%expiresaml)) {
17633: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
17634: }
17635: if (ref($wafproxy{'saml'}) eq 'HASH') {
17636: my $cachetime = 24*60*60;
17637: foreach my $key (keys(%{$wafproxy{'saml'}})) {
17638: $samlupdates{$key} = 1;
17639: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
17640: $cachetime);
17641: }
17642: }
17643: if (ref($lastactref) eq 'HASH') {
17644: $lastactref->{'proxysaml'} = \%samlupdates;
17645: }
17646: }
17647: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 17648: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 17649: if ($changes{$item}) {
17650: if ($item eq 'alias') {
17651: my $numaliased = 0;
17652: if (ref($wafproxy{'alias'}) eq 'HASH') {
17653: my $shown;
17654: if (keys(%{$wafproxy{'alias'}})) {
17655: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
17656: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
17657: &Apache::lonnet::hostname($server),
17658: $wafproxy{'alias'}{$server}).'</li>';
17659: $numaliased ++;
17660: }
17661: if ($numaliased) {
17662: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
17663: '<ul>'.$shown.'</ul>').'</li>';
17664: }
17665: }
17666: }
17667: unless ($numaliased) {
17668: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
17669: }
17670: } elsif ($item eq 'saml') {
17671: my $shown;
17672: if (ref($wafproxy{'saml'}) eq 'HASH') {
17673: if (keys(%{$wafproxy{'saml'}})) {
17674: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
17675: }
17676: }
17677: if ($shown) {
17678: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
17679: $shown).'</li>';
17680: } else {
17681: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
17682: }
17683: } else {
17684: if ($item eq 'remoteip') {
17685: my %ip_methods = &remoteip_methods();
17686: if ($wafproxy{$item} =~ /^[mh]$/) {
17687: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
17688: $ip_methods{$wafproxy{$item}}).'</li>';
17689: } else {
17690: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
17691: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
17692: '</li>';
17693: } else {
17694: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
17695: }
17696: }
17697: } elsif ($item eq 'ipheader') {
17698: if ($wafproxy{$item}) {
17699: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
17700: $wafproxy{$item}).'</li>';
17701: } else {
17702: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
17703: }
17704: } elsif ($item eq 'trusted') {
17705: if ($wafproxy{$item}) {
17706: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
17707: $wafproxy{$item}).'</li>';
17708: } else {
17709: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
17710: }
17711: } elsif ($item eq 'vpnint') {
17712: if ($wafproxy{$item}) {
17713: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
17714: $wafproxy{$item}).'</li>';
17715: } else {
17716: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
17717: }
17718: } elsif ($item eq 'vpnext') {
17719: if ($wafproxy{$item}) {
17720: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
17721: $wafproxy{$item}).'</li>';
17722: } else {
17723: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
17724: }
17725: } elsif ($item eq 'sslopt') {
17726: if ($wafproxy{$item}) {
17727: $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>';
17728: } else {
17729: $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>';
17730: }
17731: }
17732: }
17733: }
17734: }
17735: } else {
17736: $output = '<span class="LC_error">'.
17737: &mt('An error occurred: [_1]',$putresult).'</span>';
17738: }
17739: } elsif (keys(%canset)) {
17740: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
17741: }
17742: if (@warnings) {
17743: $output .= '<br />'.&mt('Warnings:').'<ul>'.
17744: join("\n",@warnings).'</ul>';
17745: }
17746: return $output;
17747: }
17748:
17749: sub validate_ip_pattern {
17750: my ($pattern) = @_;
17751: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
17752: my ($start,$end) = ($1,$2);
17753: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
17754: if (($start !~ m{/}) && ($end !~ m{/})) {
17755: return $start.'-'.$end;
17756: }
17757: }
17758: } elsif ($pattern ne '') {
17759: $pattern = &Net::CIDR::cidrvalidate($pattern);
17760: if ($pattern ne '') {
17761: return $pattern;
17762: }
17763: }
17764: return;
17765: }
17766:
1.137 raeburn 17767: sub modify_usersessions {
1.160.6.27 raeburn 17768: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17769: my @hostingtypes = ('version','excludedomain','includedomain');
17770: my @offloadtypes = ('primary','default');
17771: my %types = (
17772: remote => \@hostingtypes,
17773: hosted => \@hostingtypes,
17774: spares => \@offloadtypes,
17775: );
17776: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17777: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 17778: my (%by_ip,%by_location,@intdoms);
17779: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
17780: my @locations = sort(keys(%by_location));
1.137 raeburn 17781: my (%defaultshash,%changes);
17782: foreach my $prefix (@prefixes) {
17783: $defaultshash{'usersessions'}{$prefix} = {};
17784: }
1.160.6.27 raeburn 17785: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17786: my $resulttext;
1.138 raeburn 17787: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17788: foreach my $prefix (@prefixes) {
1.145 raeburn 17789: next if ($prefix eq 'spares');
17790: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 17791: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17792: if ($type eq 'version') {
17793: my $value = $env{'form.'.$prefix.'_'.$type};
17794: my $okvalue;
17795: if ($value ne '') {
17796: if (grep(/^\Q$value\E$/,@lcversions)) {
17797: $okvalue = $value;
17798: }
17799: }
17800: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17801: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17802: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
17803: if ($inuse == 0) {
17804: $changes{$prefix}{$type} = 1;
17805: } else {
17806: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
17807: $changes{$prefix}{$type} = 1;
17808: }
17809: if ($okvalue ne '') {
17810: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17811: }
17812: }
17813: } else {
17814: if (($inuse == 1) && ($okvalue ne '')) {
17815: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17816: $changes{$prefix}{$type} = 1;
17817: }
17818: }
17819: } else {
17820: if (($inuse == 1) && ($okvalue ne '')) {
17821: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17822: $changes{$prefix}{$type} = 1;
17823: }
17824: }
17825: } else {
17826: if (($inuse == 1) && ($okvalue ne '')) {
17827: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17828: $changes{$prefix}{$type} = 1;
17829: }
17830: }
17831: } else {
17832: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17833: my @okvals;
17834: foreach my $val (@vals) {
1.138 raeburn 17835: if ($val =~ /:/) {
17836: my @items = split(/:/,$val);
17837: foreach my $item (@items) {
17838: if (ref($by_location{$item}) eq 'ARRAY') {
17839: push(@okvals,$item);
17840: }
17841: }
17842: } else {
17843: if (ref($by_location{$val}) eq 'ARRAY') {
17844: push(@okvals,$val);
17845: }
1.137 raeburn 17846: }
17847: }
17848: @okvals = sort(@okvals);
17849: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17850: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17851: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17852: if ($inuse == 0) {
17853: $changes{$prefix}{$type} = 1;
17854: } else {
17855: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17856: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
17857: if (@changed > 0) {
17858: $changes{$prefix}{$type} = 1;
17859: }
17860: }
17861: } else {
17862: if ($inuse == 1) {
17863: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17864: $changes{$prefix}{$type} = 1;
17865: }
17866: }
17867: } else {
17868: if ($inuse == 1) {
17869: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17870: $changes{$prefix}{$type} = 1;
17871: }
17872: }
17873: } else {
17874: if ($inuse == 1) {
17875: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17876: $changes{$prefix}{$type} = 1;
17877: }
17878: }
17879: }
17880: }
17881: }
1.145 raeburn 17882:
17883: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 17884: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 17885: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
17886: my $savespares;
17887:
17888: foreach my $lonhost (sort(keys(%servers))) {
17889: my $serverhomeID =
17890: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 17891: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 17892: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
17893: my %spareschg;
17894: foreach my $type (@{$types{'spares'}}) {
17895: my @okspares;
17896: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
17897: foreach my $server (@checked) {
1.152 raeburn 17898: if (&Apache::lonnet::hostname($server) ne '') {
17899: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
17900: unless (grep(/^\Q$server\E$/,@okspares)) {
17901: push(@okspares,$server);
17902: }
1.145 raeburn 17903: }
17904: }
17905: }
17906: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
17907: my $newspare;
1.152 raeburn 17908: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
17909: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 17910: $newspare = $new;
17911: }
17912: }
1.152 raeburn 17913: my @spares;
17914: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
17915: @spares = sort(@okspares,$newspare);
17916: } else {
17917: @spares = sort(@okspares);
17918: }
17919: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 17920: if (ref($spareid{$lonhost}) eq 'HASH') {
17921: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 17922: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 17923: if (@diffs > 0) {
17924: $spareschg{$type} = 1;
17925: }
17926: }
17927: }
17928: }
17929: if (keys(%spareschg) > 0) {
17930: $changes{'spares'}{$lonhost} = \%spareschg;
17931: }
17932: }
1.160.6.61 raeburn 17933: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 17934: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 17935: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
17936: my @okoffload;
17937: if (@offloadnow) {
17938: foreach my $server (@offloadnow) {
17939: if (&Apache::lonnet::hostname($server) ne '') {
17940: unless (grep(/^\Q$server\E$/,@okoffload)) {
17941: push(@okoffload,$server);
17942: }
17943: }
17944: }
17945: if (@okoffload) {
17946: foreach my $lonhost (@okoffload) {
17947: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
17948: }
17949: }
17950: }
1.160.6.105 raeburn 17951: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
17952: my @okoffloadoth;
17953: if (@offloadoth) {
17954: foreach my $server (@offloadoth) {
17955: if (&Apache::lonnet::hostname($server) ne '') {
17956: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
17957: push(@okoffloadoth,$server);
17958: }
17959: }
17960: }
17961: if (@okoffloadoth) {
17962: foreach my $lonhost (@okoffloadoth) {
17963: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
17964: }
17965: }
17966: }
1.145 raeburn 17967: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17968: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
17969: if (ref($changes{'spares'}) eq 'HASH') {
17970: if (keys(%{$changes{'spares'}}) > 0) {
17971: $savespares = 1;
17972: }
17973: }
17974: } else {
17975: $savespares = 1;
17976: }
1.160.6.105 raeburn 17977: foreach my $offload ('offloadnow','offloadoth') {
17978: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
17979: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
17980: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
17981: $changes{$offload} = 1;
1.160.6.61 raeburn 17982: last;
17983: }
17984: }
1.160.6.105 raeburn 17985: unless ($changes{$offload}) {
17986: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
17987: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
17988: $changes{$offload} = 1;
17989: last;
17990: }
17991: }
17992: }
17993: } else {
17994: if (($offload eq 'offloadnow') && (@okoffload)) {
17995: $changes{'offloadnow'} = 1;
17996: }
17997: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
17998: $changes{'offloadoth'} = 1;
17999: }
1.160.6.61 raeburn 18000: }
1.160.6.105 raeburn 18001: }
18002: } else {
18003: if (@okoffload) {
1.160.6.61 raeburn 18004: $changes{'offloadnow'} = 1;
18005: }
1.160.6.105 raeburn 18006: if (@okoffloadoth) {
18007: $changes{'offloadoth'} = 1;
18008: }
1.145 raeburn 18009: }
1.147 raeburn 18010: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18011: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18012: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18013: $dom);
18014: if ($putresult eq 'ok') {
18015: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18016: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18017: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18018: }
18019: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18020: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18021: }
1.160.6.61 raeburn 18022: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18023: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18024: }
1.160.6.105 raeburn 18025: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18026: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18027: }
1.137 raeburn 18028: }
18029: my $cachetime = 24*60*60;
18030: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 18031: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 18032: if (ref($lastactref) eq 'HASH') {
18033: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 18034: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 18035: }
1.147 raeburn 18036: if (keys(%changes) > 0) {
18037: my %lt = &usersession_titles();
18038: $resulttext = &mt('Changes made:').'<ul>';
18039: foreach my $prefix (@prefixes) {
18040: if (ref($changes{$prefix}) eq 'HASH') {
18041: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18042: if ($prefix eq 'spares') {
18043: if (ref($changes{$prefix}) eq 'HASH') {
18044: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18045: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18046: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 18047: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18048: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18049: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18050: foreach my $type (@{$types{$prefix}}) {
18051: if ($changes{$prefix}{$lonhost}{$type}) {
18052: my $offloadto = &mt('None');
18053: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18054: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18055: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18056: }
1.145 raeburn 18057: }
1.147 raeburn 18058: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18059: }
1.137 raeburn 18060: }
18061: }
1.147 raeburn 18062: $resulttext .= '</li>';
1.137 raeburn 18063: }
18064: }
1.147 raeburn 18065: } else {
18066: foreach my $type (@{$types{$prefix}}) {
18067: if (defined($changes{$prefix}{$type})) {
18068: my $newvalue;
18069: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18070: if (ref($defaultshash{'usersessions'}{$prefix})) {
18071: if ($type eq 'version') {
18072: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18073: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18074: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18075: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18076: }
1.145 raeburn 18077: }
18078: }
18079: }
1.147 raeburn 18080: if ($newvalue eq '') {
18081: if ($type eq 'version') {
18082: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18083: } else {
18084: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18085: }
1.145 raeburn 18086: } else {
1.147 raeburn 18087: if ($type eq 'version') {
18088: $newvalue .= ' '.&mt('(or later)');
18089: }
18090: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18091: }
1.137 raeburn 18092: }
18093: }
18094: }
1.147 raeburn 18095: $resulttext .= '</ul>';
1.137 raeburn 18096: }
18097: }
1.160.6.61 raeburn 18098: if ($changes{'offloadnow'}) {
18099: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18100: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 18101: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 18102: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18103: $resulttext .= '<li>'.$lonhost.'</li>';
18104: }
18105: $resulttext .= '</ul>';
18106: } else {
1.160.6.105 raeburn 18107: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18108: }
18109: } else {
18110: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18111: }
18112: }
18113: if ($changes{'offloadoth'}) {
18114: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18115: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18116: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18117: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18118: $resulttext .= '<li>'.$lonhost.'</li>';
18119: }
18120: $resulttext .= '</ul>';
18121: } else {
18122: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 18123: }
18124: } else {
1.160.6.105 raeburn 18125: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 18126: }
18127: }
1.147 raeburn 18128: $resulttext .= '</ul>';
18129: } else {
18130: $resulttext = $nochgmsg;
1.137 raeburn 18131: }
18132: } else {
18133: $resulttext = '<span class="LC_error">'.
18134: &mt('An error occurred: [_1]',$putresult).'</span>';
18135: }
18136: } else {
1.147 raeburn 18137: $resulttext = $nochgmsg;
1.137 raeburn 18138: }
18139: return $resulttext;
18140: }
18141:
1.150 raeburn 18142: sub modify_loadbalancing {
18143: my ($dom,%domconfig) = @_;
18144: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18145: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18146: my ($othertitle,$usertypes,$types) =
18147: &Apache::loncommon::sorted_inst_types($dom);
18148: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 18149: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18150: my @sparestypes = ('primary','default');
18151: my %typetitles = &sparestype_titles();
18152: my $resulttext;
1.160.6.94 raeburn 18153: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18154: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18155: %existing = %{$domconfig{'loadbalancing'}};
18156: }
18157: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18158: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18159: my ($saveloadbalancing,%defaultshash,%changes);
18160: my ($alltypes,$othertypes,$titles) =
18161: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18162: my %ruletitles = &offloadtype_text();
18163: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18164: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18165: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18166: if ($balancer eq '') {
18167: next;
18168: }
18169: if (!exists($servers{$balancer})) {
18170: if (exists($currbalancer{$balancer})) {
18171: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18172: }
1.160.6.7 raeburn 18173: next;
18174: }
18175: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18176: push(@{$changes{'delete'}},$balancer);
18177: next;
18178: }
18179: if (!exists($currbalancer{$balancer})) {
18180: push(@{$changes{'add'}},$balancer);
18181: }
18182: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18183: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18184: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18185: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18186: $saveloadbalancing = 1;
18187: }
18188: foreach my $sparetype (@sparestypes) {
18189: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18190: my @offloadto;
18191: foreach my $target (@targets) {
18192: if (($servers{$target}) && ($target ne $balancer)) {
18193: if ($sparetype eq 'default') {
18194: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18195: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18196: }
18197: }
1.160.6.7 raeburn 18198: unless(grep(/^\Q$target\E$/,@offloadto)) {
18199: push(@offloadto,$target);
18200: }
1.150 raeburn 18201: }
18202: }
1.160.6.76 raeburn 18203: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18204: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18205: push(@offloadto,$balancer);
18206: }
18207: }
18208: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18209: }
1.160.6.94 raeburn 18210: if ($env{'form.loadbalancing_cookie_'.$i}) {
18211: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18212: if (exists($currbalancer{$balancer})) {
18213: unless ($currcookies{$balancer}) {
18214: $changes{'curr'}{$balancer}{'cookie'} = 1;
18215: }
18216: }
18217: } elsif (exists($currbalancer{$balancer})) {
18218: if ($currcookies{$balancer}) {
18219: $changes{'curr'}{$balancer}{'cookie'} = 1;
18220: }
18221: }
1.160.6.7 raeburn 18222: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18223: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 18224: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18225: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18226: if (@targetdiffs > 0) {
1.160.6.7 raeburn 18227: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18228: }
1.160.6.7 raeburn 18229: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18230: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18231: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18232: }
18233: }
18234: }
18235: } else {
1.160.6.7 raeburn 18236: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
18237: foreach my $sparetype (@sparestypes) {
18238: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18239: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18240: $changes{'curr'}{$balancer}{'targets'} = 1;
18241: }
1.150 raeburn 18242: }
18243: }
1.160.6.7 raeburn 18244: }
1.150 raeburn 18245: }
18246: my $ishomedom;
1.160.6.7 raeburn 18247: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18248: $ishomedom = 1;
1.150 raeburn 18249: }
18250: if (ref($alltypes) eq 'ARRAY') {
18251: foreach my $type (@{$alltypes}) {
18252: my $rule;
1.160.6.7 raeburn 18253: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18254: (!$ishomedom)) {
1.160.6.7 raeburn 18255: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18256: }
18257: if ($rule eq 'specific') {
1.160.6.55 raeburn 18258: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
18259: if (exists($servers{$specifiedhost})) {
18260: $rule = $specifiedhost;
18261: }
1.150 raeburn 18262: }
1.160.6.7 raeburn 18263: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18264: if (ref($currrules{$balancer}) eq 'HASH') {
18265: if ($rule ne $currrules{$balancer}{$type}) {
18266: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18267: }
18268: } elsif ($rule ne '') {
1.160.6.7 raeburn 18269: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18270: }
18271: }
18272: }
1.160.6.7 raeburn 18273: }
18274: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18275: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18276: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18277: $defaultshash{'loadbalancing'} = {};
18278: }
18279: my $putresult = &Apache::lonnet::put_dom('configuration',
18280: \%defaultshash,$dom);
18281: if ($putresult eq 'ok') {
18282: if (keys(%changes) > 0) {
1.160.6.54 raeburn 18283: my %toupdate;
1.160.6.7 raeburn 18284: if (ref($changes{'delete'}) eq 'ARRAY') {
18285: foreach my $balancer (sort(@{$changes{'delete'}})) {
18286: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 18287: $toupdate{$balancer} = 1;
1.150 raeburn 18288: }
1.160.6.7 raeburn 18289: }
18290: if (ref($changes{'add'}) eq 'ARRAY') {
18291: foreach my $balancer (sort(@{$changes{'add'}})) {
18292: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 18293: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18294: }
18295: }
18296: if (ref($changes{'curr'}) eq 'HASH') {
18297: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 18298: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18299: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18300: if ($changes{'curr'}{$balancer}{'targets'}) {
18301: my %offloadstr;
18302: foreach my $sparetype (@sparestypes) {
18303: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18304: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18305: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18306: }
18307: }
1.150 raeburn 18308: }
1.160.6.7 raeburn 18309: if (keys(%offloadstr) == 0) {
18310: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18311: } else {
1.160.6.7 raeburn 18312: my $showoffload;
18313: foreach my $sparetype (@sparestypes) {
18314: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18315: if (defined($offloadstr{$sparetype})) {
18316: $showoffload .= $offloadstr{$sparetype};
18317: } else {
18318: $showoffload .= &mt('None');
18319: }
18320: $showoffload .= (' 'x3);
18321: }
18322: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18323: }
18324: }
18325: }
1.160.6.7 raeburn 18326: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18327: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18328: foreach my $type (@{$alltypes}) {
18329: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18330: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18331: my $balancetext;
18332: if ($rule eq '') {
18333: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 18334: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 18335: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
18336: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 18337: foreach my $sparetype (@sparestypes) {
18338: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18339: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18340: }
18341: }
1.160.6.55 raeburn 18342: foreach my $item (@{$alltypes}) {
18343: next if ($item =~ /^_LC_ipchange/);
18344: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18345: if ($hasrule eq 'homeserver') {
18346: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18347: } else {
18348: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18349: if ($servers{$hasrule}) {
18350: $toupdate{$hasrule} = 1;
18351: }
18352: }
18353: }
18354: }
18355: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18356: $balancetext = $ruletitles{$rule};
18357: } else {
18358: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18359: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18360: if ($receiver) {
18361: $toupdate{$receiver};
18362: }
18363: }
18364: } else {
18365: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 18366: }
1.160.6.7 raeburn 18367: } else {
18368: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18369: }
1.160.6.26 raeburn 18370: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18371: }
18372: }
18373: }
18374: }
1.160.6.94 raeburn 18375: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 18376: if ($currcookies{$balancer}) {
18377: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
18378: $balancer).'</li>';
18379: } else {
18380: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18381: $balancer).'</li>';
18382: }
1.160.6.94 raeburn 18383: }
1.160.6.106 raeburn 18384: }
18385: }
18386: if (keys(%toupdate)) {
18387: my %thismachine;
18388: my $updatedhere;
18389: my $cachetime = 60*60*24;
18390: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18391: foreach my $lonhost (keys(%toupdate)) {
18392: if ($thismachine{$lonhost}) {
18393: unless ($updatedhere) {
18394: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18395: $defaultshash{'loadbalancing'},
18396: $cachetime);
18397: $updatedhere = 1;
1.160.6.54 raeburn 18398: }
1.160.6.106 raeburn 18399: } else {
18400: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18401: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 18402: }
1.150 raeburn 18403: }
1.160.6.7 raeburn 18404: }
18405: if ($resulttext ne '') {
18406: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18407: } else {
18408: $resulttext = $nochgmsg;
18409: }
18410: } else {
1.160.6.7 raeburn 18411: $resulttext = $nochgmsg;
1.150 raeburn 18412: }
18413: } else {
1.160.6.7 raeburn 18414: $resulttext = '<span class="LC_error">'.
18415: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18416: }
18417: } else {
1.160.6.7 raeburn 18418: $resulttext = $nochgmsg;
1.150 raeburn 18419: }
18420: return $resulttext;
18421: }
18422:
1.48 raeburn 18423: sub recurse_check {
18424: my ($chkcats,$categories,$depth,$name) = @_;
18425: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18426: my $chg = 0;
18427: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18428: my $category = $chkcats->[$depth]{$name}[$j];
18429: my $item;
18430: if ($category eq '') {
18431: $chg ++;
18432: } else {
18433: my $deeper = $depth + 1;
18434: $item = &escape($category).':'.&escape($name).':'.$depth;
18435: if ($chg) {
18436: $categories->{$item} -= $chg;
18437: }
18438: &recurse_check($chkcats,$categories,$deeper,$category);
18439: $deeper --;
18440: }
18441: }
18442: }
18443: return;
18444: }
18445:
18446: sub recurse_cat_deletes {
18447: my ($item,$coursecategories,$deletions) = @_;
18448: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18449: my $subdepth = $depth + 1;
18450: if (ref($coursecategories) eq 'HASH') {
18451: foreach my $subitem (keys(%{$coursecategories})) {
18452: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18453: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18454: delete($coursecategories->{$subitem});
18455: $deletions->{$subitem} = 1;
18456: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 18457: }
1.48 raeburn 18458: }
18459: }
18460: return;
18461: }
18462:
1.125 raeburn 18463: sub active_dc_picker {
1.160.6.16 raeburn 18464: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 18465: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 18466: my @domcoord = keys(%domcoords);
18467: if (keys(%currhash)) {
18468: foreach my $dc (keys(%currhash)) {
18469: unless (exists($domcoords{$dc})) {
18470: push(@domcoord,$dc);
18471: }
18472: }
18473: }
18474: @domcoord = sort(@domcoord);
18475: my $numdcs = scalar(@domcoord);
18476: my $rows = 0;
18477: my $table;
1.125 raeburn 18478: if ($numdcs > 1) {
1.160.6.16 raeburn 18479: $table = '<table>';
18480: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18481: my $rem = $i%($numinrow);
18482: if ($rem == 0) {
18483: if ($i > 0) {
1.160.6.16 raeburn 18484: $table .= '</tr>';
1.125 raeburn 18485: }
1.160.6.16 raeburn 18486: $table .= '<tr>';
18487: $rows ++;
1.125 raeburn 18488: }
1.160.6.16 raeburn 18489: my $check = '';
18490: if ($inputtype eq 'radio') {
18491: if (keys(%currhash) == 0) {
18492: if (!$i) {
18493: $check = ' checked="checked"';
18494: }
18495: } elsif (exists($currhash{$domcoord[$i]})) {
18496: $check = ' checked="checked"';
18497: }
18498: } else {
18499: if (exists($currhash{$domcoord[$i]})) {
18500: $check = ' checked="checked"';
1.125 raeburn 18501: }
18502: }
1.160.6.16 raeburn 18503: if ($i == @domcoord - 1) {
1.125 raeburn 18504: my $colsleft = $numinrow - $rem;
18505: if ($colsleft > 1) {
1.160.6.16 raeburn 18506: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18507: } else {
1.160.6.16 raeburn 18508: $table .= '<td class="LC_left_item">';
1.125 raeburn 18509: }
18510: } else {
1.160.6.16 raeburn 18511: $table .= '<td class="LC_left_item">';
18512: }
18513: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18514: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18515: $table .= '<span class="LC_nobreak"><label>'.
18516: '<input type="'.$inputtype.'" name="'.$name.'"'.
18517: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
18518: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 18519: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 18520: }
1.160.6.33 raeburn 18521: $table .= '</label></span></td>';
1.125 raeburn 18522: }
1.160.6.16 raeburn 18523: $table .= '</tr></table>';
18524: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 18525: my ($dcname,$dcdom) = split(':',$domcoord[0]);
18526: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 18527: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 18528: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 18529: if ($user ne $dcname.':'.$dcdom) {
18530: $table .= ' ('.$dcname.':'.$dcdom.')';
18531: }
1.160.6.16 raeburn 18532: } else {
18533: my $check;
18534: if (exists($currhash{$domcoord[0]})) {
18535: $check = ' checked="checked"';
18536: }
1.160.6.50 raeburn 18537: $table = '<span class="LC_nobreak"><label>'.
18538: '<input type="checkbox" name="'.$name.'" '.
18539: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 18540: if ($user ne $dcname.':'.$dcdom) {
18541: $table .= ' ('.$dcname.':'.$dcdom.')';
18542: }
18543: $table .= '</label></span>';
1.160.6.16 raeburn 18544: $rows ++;
18545: }
1.125 raeburn 18546: }
1.160.6.16 raeburn 18547: return ($numdcs,$table,$rows);
1.125 raeburn 18548: }
18549:
1.137 raeburn 18550: sub usersession_titles {
18551: return &Apache::lonlocal::texthash(
18552: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
18553: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 18554: spares => 'Servers offloaded to, when busy',
1.137 raeburn 18555: version => 'LON-CAPA version requirement',
1.138 raeburn 18556: excludedomain => 'Allow all, but exclude specific domains',
18557: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 18558: primary => 'Primary (checked first)',
1.154 raeburn 18559: default => 'Default',
1.137 raeburn 18560: );
18561: }
18562:
1.152 raeburn 18563: sub id_for_thisdom {
18564: my (%servers) = @_;
18565: my %altids;
18566: foreach my $server (keys(%servers)) {
18567: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18568: if ($serverhome ne $server) {
18569: $altids{$serverhome} = $server;
18570: }
18571: }
18572: return %altids;
18573: }
18574:
1.150 raeburn 18575: sub count_servers {
18576: my ($currbalancer,%servers) = @_;
18577: my (@spares,$numspares);
18578: foreach my $lonhost (sort(keys(%servers))) {
18579: next if ($currbalancer eq $lonhost);
18580: push(@spares,$lonhost);
18581: }
18582: if ($currbalancer) {
18583: $numspares = scalar(@spares);
18584: } else {
18585: $numspares = scalar(@spares) - 1;
18586: }
18587: return ($numspares,@spares);
18588: }
18589:
18590: sub lonbalance_targets_js {
1.160.6.7 raeburn 18591: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 18592: my $select = &mt('Select');
18593: my ($alltargets,$allishome,$allinsttypes,@alltypes);
18594: if (ref($servers) eq 'HASH') {
18595: $alltargets = join("','",sort(keys(%{$servers})));
18596: my @homedoms;
18597: foreach my $server (sort(keys(%{$servers}))) {
18598: if (&Apache::lonnet::host_domain($server) eq $dom) {
18599: push(@homedoms,'1');
18600: } else {
18601: push(@homedoms,'0');
18602: }
18603: }
18604: $allishome = join("','",@homedoms);
18605: }
18606: if (ref($types) eq 'ARRAY') {
18607: if (@{$types} > 0) {
18608: @alltypes = @{$types};
18609: }
18610: }
18611: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
18612: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 18613: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18614: if (ref($settings) eq 'HASH') {
18615: %existing = %{$settings};
18616: }
18617: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18618: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18619: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 18620: return <<"END";
18621:
18622: <script type="text/javascript">
18623: // <![CDATA[
18624:
1.160.6.7 raeburn 18625: currBalancers = new Array('$balancers');
18626:
18627: function toggleTargets(balnum) {
18628: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18629: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
18630: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
18631: var prevbalancer = prevhostitem.value;
18632: var baltotal = document.getElementById('loadbalancing_total').value;
18633: prevhostitem.value = balancer;
18634: if (prevbalancer != '') {
18635: var prevIdx = currBalancers.indexOf(prevbalancer);
18636: if (prevIdx != -1) {
18637: currBalancers.splice(prevIdx,1);
18638: }
18639: }
1.150 raeburn 18640: if (balancer == '') {
1.160.6.7 raeburn 18641: hideSpares(balnum);
1.150 raeburn 18642: } else {
1.160.6.7 raeburn 18643: var currIdx = currBalancers.indexOf(balancer);
18644: if (currIdx == -1) {
18645: currBalancers.push(balancer);
18646: }
1.150 raeburn 18647: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 18648: var ishomedom = homedoms[lonhostitem.selectedIndex];
18649: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 18650: }
1.160.6.7 raeburn 18651: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 18652: return;
18653: }
18654:
1.160.6.7 raeburn 18655: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 18656: var alltargets = new Array('$alltargets');
18657: var insttypes = new Array('$allinsttypes');
1.151 raeburn 18658: var offloadtypes = new Array('primary','default');
18659:
1.160.6.7 raeburn 18660: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
18661: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 18662:
1.151 raeburn 18663: for (var i=0; i<offloadtypes.length; i++) {
18664: var count = 0;
18665: for (var j=0; j<alltargets.length; j++) {
18666: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 18667: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
18668: item.value = alltargets[j];
18669: item.style.textAlign='left';
18670: item.style.textFace='normal';
18671: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
18672: if (currBalancers.indexOf(alltargets[j]) == -1) {
18673: item.disabled = '';
18674: } else {
18675: item.disabled = 'disabled';
18676: item.checked = false;
18677: }
1.151 raeburn 18678: count ++;
18679: }
1.150 raeburn 18680: }
18681: }
1.151 raeburn 18682: for (var k=0; k<insttypes.length; k++) {
18683: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 18684: if (ishomedom == 1) {
1.160.6.7 raeburn 18685: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18686: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18687: } else {
1.160.6.7 raeburn 18688: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18689: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 18690: }
18691: } else {
1.160.6.7 raeburn 18692: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18693: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18694: }
1.151 raeburn 18695: if ((insttypes[k] != '_LC_external') &&
18696: ((insttypes[k] != '_LC_internetdom') ||
18697: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 18698: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
18699: item.options.length = 0;
18700: item.options[0] = new Option("","",true,true);
18701: var idx = 0;
1.151 raeburn 18702: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 18703: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
18704: idx ++;
18705: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 18706: }
18707: }
18708: }
18709: }
18710: return;
18711: }
18712:
1.160.6.7 raeburn 18713: function hideSpares(balnum) {
1.150 raeburn 18714: var alltargets = new Array('$alltargets');
18715: var insttypes = new Array('$allinsttypes');
18716: var offloadtypes = new Array('primary','default');
18717:
1.160.6.7 raeburn 18718: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
18719: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 18720:
18721: var total = alltargets.length - 1;
18722: for (var i=0; i<offloadtypes; i++) {
18723: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 18724: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
18725: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
18726: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 18727: }
1.150 raeburn 18728: }
18729: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 18730: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18731: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 18732: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 18733: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
18734: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 18735: }
18736: }
18737: return;
18738: }
18739:
1.160.6.7 raeburn 18740: function checkOffloads(item,balnum,type) {
1.150 raeburn 18741: var alltargets = new Array('$alltargets');
18742: var offloadtypes = new Array('primary','default');
18743: if (item.checked) {
18744: var total = alltargets.length - 1;
18745: var other;
18746: if (type == offloadtypes[0]) {
1.151 raeburn 18747: other = offloadtypes[1];
1.150 raeburn 18748: } else {
1.151 raeburn 18749: other = offloadtypes[0];
1.150 raeburn 18750: }
18751: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 18752: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 18753: if (server == item.value) {
1.160.6.7 raeburn 18754: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
18755: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 18756: }
18757: }
18758: }
18759: }
18760: return;
18761: }
18762:
1.160.6.7 raeburn 18763: function singleServerToggle(balnum,type) {
18764: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 18765: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 18766: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
18767: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18768:
18769: } else {
1.160.6.7 raeburn 18770: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
18771: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 18772: }
18773: return;
18774: }
18775:
1.160.6.7 raeburn 18776: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 18777: if (type == '_LC_external') {
1.160.6.26 raeburn 18778: return;
1.150 raeburn 18779: }
1.160.6.7 raeburn 18780: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 18781: for (var i=0; i<typesRules.length; i++) {
18782: if (formname.elements[typesRules[i]].checked) {
18783: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 18784: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
18785: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18786: } else {
1.160.6.7 raeburn 18787: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
18788: }
18789: }
18790: }
18791: return;
18792: }
18793:
18794: function balancerDeleteChange(balnum) {
18795: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18796: var baltotal = document.getElementById('loadbalancing_total').value;
18797: var addtarget;
18798: var removetarget;
18799: var action = 'delete';
18800: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18801: var lonhost = hostitem.value;
18802: var currIdx = currBalancers.indexOf(lonhost);
18803: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18804: if (currIdx != -1) {
18805: currBalancers.splice(currIdx,1);
18806: }
18807: addtarget = lonhost;
18808: } else {
18809: if (currIdx == -1) {
18810: currBalancers.push(lonhost);
18811: }
18812: removetarget = lonhost;
18813: action = 'undelete';
18814: }
18815: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18816: }
18817: return;
18818: }
18819:
18820: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18821: if (baltotal > 1) {
18822: var offloadtypes = new Array('primary','default');
18823: var alltargets = new Array('$alltargets');
18824: var insttypes = new Array('$allinsttypes');
18825: for (var i=0; i<baltotal; i++) {
18826: if (i != balnum) {
18827: for (var j=0; j<offloadtypes.length; j++) {
18828: var total = alltargets.length - 1;
18829: for (var k=0; k<total; k++) {
18830: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18831: var server = serveritem.value;
18832: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18833: if (server == addtarget) {
18834: serveritem.disabled = '';
18835: }
18836: }
18837: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18838: if (server == removetarget) {
18839: serveritem.disabled = 'disabled';
18840: serveritem.checked = false;
18841: }
18842: }
18843: }
18844: }
18845: for (var j=0; j<insttypes.length; j++) {
18846: if (insttypes[j] != '_LC_external') {
18847: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18848: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18849: var currSel = singleserver.selectedIndex;
18850: var currVal = singleserver.options[currSel].value;
18851: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18852: var numoptions = singleserver.options.length;
18853: var needsnew = 1;
18854: for (var k=0; k<numoptions; k++) {
18855: if (singleserver.options[k] == addtarget) {
18856: needsnew = 0;
18857: break;
18858: }
18859: }
18860: if (needsnew == 1) {
18861: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18862: }
18863: }
18864: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18865: singleserver.options.length = 0;
18866: if ((currVal) && (currVal != removetarget)) {
18867: singleserver.options[0] = new Option("","",false,false);
18868: } else {
18869: singleserver.options[0] = new Option("","",true,true);
18870: }
18871: var idx = 0;
18872: for (var m=0; m<alltargets.length; m++) {
18873: if (currBalancers.indexOf(alltargets[m]) == -1) {
18874: idx ++;
18875: if (currVal == alltargets[m]) {
18876: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18877: } else {
18878: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18879: }
18880: }
18881: }
18882: }
18883: }
18884: }
18885: }
1.150 raeburn 18886: }
18887: }
18888: }
18889: return;
18890: }
18891:
1.152 raeburn 18892: // ]]>
18893: </script>
18894:
18895: END
18896: }
18897:
18898: sub new_spares_js {
18899: my @sparestypes = ('primary','default');
18900: my $types = join("','",@sparestypes);
18901: my $select = &mt('Select');
18902: return <<"END";
18903:
18904: <script type="text/javascript">
18905: // <![CDATA[
18906:
18907: function updateNewSpares(formname,lonhost) {
18908: var types = new Array('$types');
18909: var include = new Array();
18910: var exclude = new Array();
18911: for (var i=0; i<types.length; i++) {
18912: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18913: for (var j=0; j<spareboxes.length; j++) {
18914: if (formname.elements[spareboxes[j]].checked) {
18915: exclude.push(formname.elements[spareboxes[j]].value);
18916: } else {
18917: include.push(formname.elements[spareboxes[j]].value);
18918: }
18919: }
18920: }
18921: for (var i=0; i<types.length; i++) {
18922: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18923: var selIdx = newSpare.selectedIndex;
18924: var currnew = newSpare.options[selIdx].value;
18925: var okSpares = new Array();
18926: for (var j=0; j<newSpare.options.length; j++) {
18927: var possible = newSpare.options[j].value;
18928: if (possible != '') {
18929: if (exclude.indexOf(possible) == -1) {
18930: okSpares.push(possible);
18931: } else {
18932: if (currnew == possible) {
18933: selIdx = 0;
18934: }
18935: }
18936: }
18937: }
18938: for (var k=0; k<include.length; k++) {
18939: if (okSpares.indexOf(include[k]) == -1) {
18940: okSpares.push(include[k]);
18941: }
18942: }
18943: okSpares.sort();
18944: newSpare.options.length = 0;
18945: if (selIdx == 0) {
18946: newSpare.options[0] = new Option("$select","",true,true);
18947: } else {
18948: newSpare.options[0] = new Option("$select","",false,false);
18949: }
18950: for (var m=0; m<okSpares.length; m++) {
18951: var idx = m+1;
18952: var selThis = 0;
18953: if (selIdx != 0) {
18954: if (okSpares[m] == currnew) {
18955: selThis = 1;
18956: }
18957: }
18958: if (selThis == 1) {
18959: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18960: } else {
18961: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18962: }
18963: }
18964: }
18965: return;
18966: }
18967:
18968: function checkNewSpares(lonhost,type) {
18969: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18970: var chosen = newSpare.options[newSpare.selectedIndex].value;
18971: if (chosen != '') {
18972: var othertype;
18973: var othernewSpare;
18974: if (type == 'primary') {
18975: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18976: }
18977: if (type == 'default') {
18978: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
18979: }
18980: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
18981: othernewSpare.selectedIndex = 0;
18982: }
18983: }
18984: return;
18985: }
18986:
18987: // ]]>
18988: </script>
18989:
18990: END
18991:
18992: }
18993:
18994: sub common_domprefs_js {
18995: return <<"END";
18996:
18997: <script type="text/javascript">
18998: // <![CDATA[
18999:
1.150 raeburn 19000: function getIndicesByName(formname,item) {
1.152 raeburn 19001: var group = new Array();
1.150 raeburn 19002: for (var i=0;i<formname.elements.length;i++) {
19003: if (formname.elements[i].name == item) {
1.152 raeburn 19004: group.push(formname.elements[i].id);
1.150 raeburn 19005: }
19006: }
1.152 raeburn 19007: return group;
1.150 raeburn 19008: }
19009:
19010: // ]]>
19011: </script>
19012:
19013: END
1.152 raeburn 19014:
1.150 raeburn 19015: }
19016:
1.160.6.5 raeburn 19017: sub recaptcha_js {
19018: my %lt = &captcha_phrases();
19019: return <<"END";
19020:
19021: <script type="text/javascript">
19022: // <![CDATA[
19023:
19024: function updateCaptcha(caller,context) {
19025: var privitem;
19026: var pubitem;
19027: var privtext;
19028: var pubtext;
1.160.6.69 raeburn 19029: var versionitem;
19030: var versiontext;
1.160.6.5 raeburn 19031: if (document.getElementById(context+'_recaptchapub')) {
19032: pubitem = document.getElementById(context+'_recaptchapub');
19033: } else {
19034: return;
19035: }
19036: if (document.getElementById(context+'_recaptchapriv')) {
19037: privitem = document.getElementById(context+'_recaptchapriv');
19038: } else {
19039: return;
19040: }
19041: if (document.getElementById(context+'_recaptchapubtxt')) {
19042: pubtext = document.getElementById(context+'_recaptchapubtxt');
19043: } else {
19044: return;
19045: }
19046: if (document.getElementById(context+'_recaptchaprivtxt')) {
19047: privtext = document.getElementById(context+'_recaptchaprivtxt');
19048: } else {
19049: return;
19050: }
1.160.6.69 raeburn 19051: if (document.getElementById(context+'_recaptchaversion')) {
19052: versionitem = document.getElementById(context+'_recaptchaversion');
19053: } else {
19054: return;
19055: }
19056: if (document.getElementById(context+'_recaptchavertxt')) {
19057: versiontext = document.getElementById(context+'_recaptchavertxt');
19058: } else {
19059: return;
19060: }
1.160.6.5 raeburn 19061: if (caller.checked) {
19062: if (caller.value == 'recaptcha') {
19063: pubitem.type = 'text';
19064: privitem.type = 'text';
19065: pubitem.size = '40';
19066: privitem.size = '40';
19067: pubtext.innerHTML = "$lt{'pub'}";
19068: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 19069: versionitem.type = 'text';
19070: versionitem.size = '3';
19071: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 19072: } else {
19073: pubitem.type = 'hidden';
19074: privitem.type = 'hidden';
1.160.6.69 raeburn 19075: versionitem.type = 'hidden';
1.160.6.5 raeburn 19076: pubtext.innerHTML = '';
19077: privtext.innerHTML = '';
1.160.6.69 raeburn 19078: versiontext.innerHTML = '';
1.160.6.5 raeburn 19079: }
19080: }
19081: return;
19082: }
19083:
19084: // ]]>
19085: </script>
19086:
19087: END
19088:
19089: }
19090:
1.160.6.40 raeburn 19091: sub toggle_display_js {
1.160.6.16 raeburn 19092: return <<"END";
19093:
19094: <script type="text/javascript">
19095: // <![CDATA[
19096:
1.160.6.40 raeburn 19097: function toggleDisplay(domForm,caller) {
19098: if (document.getElementById(caller)) {
19099: var divitem = document.getElementById(caller);
19100: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 19101: var checkval = 1;
19102: var dispval = 'block';
1.160.6.93 raeburn 19103: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 19104: if (caller == 'emailoptions') {
19105: optionsElement = domForm.cancreate_email;
19106: }
1.160.6.57 raeburn 19107: if (caller == 'studentsubmission') {
19108: optionsElement = domForm.postsubmit;
19109: }
1.160.6.64 raeburn 19110: if (caller == 'cloneinstcode') {
19111: optionsElement = domForm.canclone;
19112: checkval = 'instcode';
19113: }
1.160.6.93 raeburn 19114: if (selfcreateRegExp.test(caller)) {
19115: optionsElement = domForm.elements[caller];
19116: checkval = 'other';
19117: dispval = 'inline'
19118: }
1.160.6.40 raeburn 19119: if (optionsElement.length) {
1.160.6.16 raeburn 19120: var currval;
1.160.6.40 raeburn 19121: for (var i=0; i<optionsElement.length; i++) {
19122: if (optionsElement[i].checked) {
19123: currval = optionsElement[i].value;
1.160.6.16 raeburn 19124: }
19125: }
1.160.6.64 raeburn 19126: if (currval == checkval) {
19127: divitem.style.display = dispval;
1.160.6.16 raeburn 19128: } else {
1.160.6.40 raeburn 19129: divitem.style.display = 'none';
1.160.6.16 raeburn 19130: }
19131: }
19132: }
19133: return;
19134: }
19135:
19136: // ]]>
19137: </script>
19138:
19139: END
19140:
19141: }
19142:
1.160.6.5 raeburn 19143: sub captcha_phrases {
19144: return &Apache::lonlocal::texthash (
19145: priv => 'Private key',
19146: pub => 'Public key',
19147: original => 'original (CAPTCHA)',
19148: recaptcha => 'successor (ReCAPTCHA)',
19149: notused => 'unused',
1.160.6.69 raeburn 19150: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 19151: );
19152: }
19153:
1.160.6.24 raeburn 19154: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 19155: my ($dom,$cachekeys) = @_;
19156: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 19157: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19158: my %thismachine;
19159: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 19160:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 19161: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19162: 'ipaccess');
19163: my %cache_by_lonhost;
19164: if (exists($cachekeys->{'samllanding'})) {
19165: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19166: my %landing = %{$cachekeys->{'samllanding'}};
19167: my %domservers = &Apache::lonnet::get_servers($dom);
19168: if (keys(%domservers)) {
19169: foreach my $server (keys(%domservers)) {
19170: my @cached;
19171: next if ($thismachine{$server});
19172: if ($landing{$server}) {
19173: push(@cached,&escape('samllanding').':'.&escape($server));
19174: }
19175: if (@cached) {
19176: $cache_by_lonhost{$server} = \@cached;
19177: }
19178: }
19179: }
19180: }
19181: }
1.160.6.61 raeburn 19182: if (keys(%servers)) {
1.160.6.24 raeburn 19183: foreach my $server (keys(%servers)) {
19184: next if ($thismachine{$server});
1.160.6.27 raeburn 19185: my @cached;
19186: foreach my $name (@posscached) {
19187: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 19188: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
19189: if (ref($cachekeys->{$name}) eq 'HASH') {
19190: foreach my $key (keys(%{$cachekeys->{$name}})) {
19191: push(@cached,&escape($name).':'.&escape($key));
19192: }
19193: }
19194: } else {
19195: push(@cached,&escape($name).':'.&escape($dom));
19196: }
1.160.6.27 raeburn 19197: }
19198: }
1.160.6.113 raeburn 19199: if ((exists($cache_by_lonhost{$server})) &&
19200: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
19201: push(@cached,@{$cache_by_lonhost{$server}});
19202: }
1.160.6.27 raeburn 19203: if (@cached) {
19204: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19205: }
1.160.6.24 raeburn 19206: }
19207: }
19208: return;
19209: }
19210:
1.3 raeburn 19211: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>