Annotation of loncom/interface/domainprefs.pm, revision 1.355
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.355 ! raeburn 4: # $Id: domainprefs.pm,v 1.354 2019/04/22 01:55:17 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.354 raeburn 222: 'ltitools','ssl','trust','lti','passwords'],$dom);
1.320 raeburn 223: my %encconfig =
224: &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297 raeburn 225: if (ref($domconfig{'ltitools'}) eq 'HASH') {
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 228: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
229: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297 raeburn 230: foreach my $item ('key','secret') {
231: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
232: }
233: }
234: }
235: }
236: }
1.320 raeburn 237: if (ref($domconfig{'lti'}) eq 'HASH') {
238: if (ref($encconfig{'lti'}) eq 'HASH') {
239: foreach my $id (keys(%{$domconfig{'lti'}})) {
240: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
241: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
242: foreach my $item ('key','secret') {
243: $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
244: }
245: }
246: }
247: }
248: }
1.354 raeburn 249: my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 251: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 252: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 253: 'serverstatuses','helpsettings','coursedefaults',
1.320 raeburn 254: 'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171 raeburn 255: my %existing;
256: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
257: %existing = %{$domconfig{'loadbalancing'}};
258: }
259: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 260: push(@prefs_order,'loadbalancing');
261: }
1.30 raeburn 262: my %prefs = (
263: 'rolecolors' =>
264: { text => 'Default color schemes',
1.67 raeburn 265: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 266: header => [{col1 => 'Student Settings',
267: col2 => '',},
268: {col1 => 'Coordinator Settings',
269: col2 => '',},
270: {col1 => 'Author Settings',
271: col2 => '',},
272: {col1 => 'Administrator Settings',
273: col2 => '',}],
1.230 raeburn 274: print => \&print_rolecolors,
275: modify => \&modify_rolecolors,
1.30 raeburn 276: },
1.110 raeburn 277: 'login' =>
1.30 raeburn 278: { text => 'Log-in page options',
1.67 raeburn 279: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 280: header => [{col1 => 'Log-in Page Items',
281: col2 => '',},
282: {col1 => 'Log-in Help',
1.256 raeburn 283: col2 => 'Value'},
284: {col1 => 'Custom HTML in document head',
1.168 raeburn 285: col2 => 'Value'}],
1.230 raeburn 286: print => \&print_login,
287: modify => \&modify_login,
1.30 raeburn 288: },
1.43 raeburn 289: 'defaults' =>
1.236 raeburn 290: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 291: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 292: header => [{col1 => 'Setting',
1.236 raeburn 293: col2 => 'Value'},
294: {col1 => 'Institutional user types',
1.305 raeburn 295: col2 => 'Name displayed'}],
1.230 raeburn 296: print => \&print_defaults,
297: modify => \&modify_defaults,
1.43 raeburn 298: },
1.354 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.197 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.213 raeburn 318: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 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.230 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.227 bisitz 338: col2 => 'Updatable user data'}],
1.230 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.230 raeburn 347: print => \&print_autocreate,
348: modify => \&modify_autocreate,
1.125 raeburn 349: },
1.30 raeburn 350: 'directorysrch' =>
1.277 raeburn 351: { text => 'Directory searches',
1.67 raeburn 352: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 353: header => [{col1 => 'Institutional Directory Setting',
354: col2 => 'Value',},
355: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 356: col2 => 'Value',}],
1.230 raeburn 357: print => \&print_directorysrch,
358: modify => \&modify_directorysrch,
1.30 raeburn 359: },
360: 'contacts' =>
1.286 raeburn 361: { text => 'E-mail addresses and helpform',
1.67 raeburn 362: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 363: header => [{col1 => 'Default e-mail addresses',
364: col2 => 'Value',},
365: {col1 => 'Recipient(s) for notifications',
366: col2 => 'Value',},
1.340 raeburn 367: {col1 => 'Nightly status check e-mail',
368: col2 => 'Settings',},
1.286 raeburn 369: {col1 => 'Ask helpdesk form settings',
370: col2 => 'Value',},],
1.230 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.230 raeburn 383: print => \&print_usercreation,
384: modify => \&modify_usercreation,
1.30 raeburn 385: },
1.224 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.303 raeburn 393: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 394: col2 => 'Settings'}],
1.230 raeburn 395: print => \&print_selfcreation,
396: modify => \&modify_selfcreation,
1.224 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.227 bisitz 402: col2 => 'User information updatable in author context'},
1.33 raeburn 403: {col1 => 'Target user has role',
1.227 bisitz 404: col2 => 'User information updatable in course context'}],
1.230 raeburn 405: print => \&print_usermodification,
406: modify => \&modify_usermodification,
1.33 raeburn 407: },
1.69 raeburn 408: 'scantron' =>
1.346 raeburn 409: { text => 'Bubblesheet format',
1.67 raeburn 410: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 411: header => [ {col1 => 'Bubblesheet format file',
412: col2 => ''},
413: {col1 => 'Bubblesheet data upload formats',
414: col2 => 'Settings'}],
1.230 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.216 raeburn 424: col2 => 'Value'},
425: {col1 => 'Available textbooks',
1.235 raeburn 426: col2 => ''},
1.242 raeburn 427: {col1 => 'Available templates',
428: col2 => ''},
1.235 raeburn 429: {col1 => 'Validation (not official courses)',
430: col2 => 'Value'},],
1.230 raeburn 431: print => \&print_quotas,
432: modify => \&modify_quotas,
1.86 raeburn 433: },
1.163 raeburn 434: 'requestauthor' =>
1.223 bisitz 435: {text => 'Request Authoring Space',
1.163 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.230 raeburn 441: print => \&print_quotas,
442: modify => \&modify_quotas,
1.163 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.238 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.230 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.230 raeburn 464: print => \&print_serverstatuses,
465: modify => \&modify_serverstatuses,
1.69 raeburn 466: },
1.118 jms 467: 'helpsettings' =>
1.282 raeburn 468: {text => 'Support settings',
1.118 jms 469: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 470: header => [{col1 => 'Help Page Settings (logged-in users)',
471: col2 => 'Value'},
472: {col1 => 'Helpdesk Roles',
473: col2 => 'Settings'},],
1.230 raeburn 474: print => \&print_helpsettings,
475: modify => \&modify_helpsettings,
1.118 jms 476: },
1.121 raeburn 477: 'coursedefaults' =>
478: {text => 'Course/Community defaults',
479: help => 'Domain_Configuration_Course_Defaults',
1.139 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',
483: col2 => 'Value',},],
1.230 raeburn 484: print => \&print_coursedefaults,
485: modify => \&modify_coursedefaults,
1.121 raeburn 486: },
1.231 raeburn 487: 'selfenrollment' =>
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,
498: },
1.120 raeburn 499: 'privacy' =>
500: {text => 'User Privacy',
501: help => 'Domain_Configuration_User_Privacy',
502: header => [{col1 => 'Setting',
503: col2 => 'Value',}],
1.230 raeburn 504: print => \&print_privacy,
505: modify => \&modify_privacy,
1.120 raeburn 506: },
1.141 raeburn 507: 'usersessions' =>
1.145 raeburn 508: {text => 'User session hosting/offloading',
1.137 raeburn 509: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 510: header => [{col1 => 'Domain server',
511: col2 => 'Servers to offload sessions to when busy'},
512: {col1 => 'Hosting of users from other domains',
1.137 raeburn 513: col2 => 'Rules'},
514: {col1 => "Hosting domain's own users elsewhere",
515: col2 => 'Rules'}],
1.230 raeburn 516: print => \&print_usersessions,
517: modify => \&modify_usersessions,
1.137 raeburn 518: },
1.279 raeburn 519: 'loadbalancing' =>
1.185 raeburn 520: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 521: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 522: header => [{col1 => 'Balancers',
1.150 raeburn 523: col2 => 'Default destinations',
1.183 bisitz 524: col3 => 'User affiliation',
1.150 raeburn 525: col4 => 'Overrides'},
526: ],
1.230 raeburn 527: print => \&print_loadbalancing,
528: modify => \&modify_loadbalancing,
1.150 raeburn 529: },
1.279 raeburn 530: 'ltitools' =>
1.267 raeburn 531: {text => 'External Tools (LTI)',
1.296 raeburn 532: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 533: header => [{col1 => 'Setting',
534: col2 => 'Value',}],
535: print => \&print_ltitools,
536: modify => \&modify_ltitools,
537: },
1.279 raeburn 538: 'ssl' =>
1.275 raeburn 539: {text => 'LON-CAPA Network (SSL)',
540: help => 'Domain_Configuration_Network_SSL',
541: header => [{col1 => 'Server',
542: col2 => 'Certificate Status'},
543: {col1 => 'Connections to other servers',
544: col2 => 'Rules'},
1.293 raeburn 545: {col1 => 'Connections from other servers',
546: col2 => 'Rules'},
1.275 raeburn 547: {col1 => "Replicating domain's published content",
548: col2 => 'Rules'}],
549: print => \&print_ssl,
550: modify => \&modify_ssl,
551: },
1.279 raeburn 552: 'trust' =>
553: {text => 'Trust Settings',
554: help => 'Domain_Configuration_Trust',
555: header => [{col1 => "Access to this domain's content by others",
556: col2 => 'Rules'},
557: {col1 => "Access to other domain's content by this domain",
558: col2 => 'Rules'},
559: {col1 => "Enrollment in this domain's courses by others",
560: col2 => 'Rules',},
561: {col1 => "Co-author roles in this domain for others",
562: col2 => 'Rules',},
563: {col1 => "Co-author roles for this domain's users elsewhere",
564: col2 => 'Rules',},
565: {col1 => "Domain roles in this domain assignable to others",
566: col2 => 'Rules'},
567: {col1 => "Course catalog for this domain displayed elsewhere",
568: col2 => 'Rules'},
569: {col1 => "Requests for creation of courses in this domain by others",
570: col2 => 'Rules'},
571: {col1 => "Users in other domains can send messages to this domain",
572: col2 => 'Rules'},],
573: print => \&print_trust,
574: modify => \&modify_trust,
575: },
1.320 raeburn 576: 'lti' =>
577: {text => 'LTI Provider',
578: help => 'Domain_Configuration_LTI_Provider',
579: header => [{col1 => 'Setting',
580: col2 => 'Value',}],
581: print => \&print_lti,
582: modify => \&modify_lti,
583: },
1.3 raeburn 584: );
1.110 raeburn 585: if (keys(%servers) > 1) {
586: $prefs{'login'} = { text => 'Log-in page options',
587: help => 'Domain_Configuration_Login_Page',
588: header => [{col1 => 'Log-in Service',
589: col2 => 'Server Setting',},
590: {col1 => 'Log-in Page Items',
1.168 raeburn 591: col2 => ''},
592: {col1 => 'Log-in Help',
1.256 raeburn 593: col2 => 'Value'},
594: {col1 => 'Custom HTML in document head',
1.168 raeburn 595: col2 => 'Value'}],
1.230 raeburn 596: print => \&print_login,
597: modify => \&modify_login,
1.110 raeburn 598: };
599: }
1.174 foxr 600:
1.6 raeburn 601: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 602: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 603: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 604: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 605: text=>"Settings to display/modify"});
1.9 raeburn 606: my $confname = $dom.'-domainconfig';
1.174 foxr 607:
1.3 raeburn 608: if ($phase eq 'process') {
1.212 raeburn 609: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
610: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 611: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 612: $r->rflush();
1.212 raeburn 613: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 614: }
1.30 raeburn 615: } elsif ($phase eq 'display') {
1.192 raeburn 616: my $js = &recaptcha_js().
1.236 raeburn 617: &toggle_display_js();
1.171 raeburn 618: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 619: my ($othertitle,$usertypes,$types) =
620: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 621: $js .= &lonbalance_targets_js($dom,$types,\%servers,
622: $domconfig{'loadbalancing'}).
1.170 raeburn 623: &new_spares_js().
624: &common_domprefs_js().
625: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 626: }
1.216 raeburn 627: if (grep(/^requestcourses$/,@actions)) {
628: my $javascript_validations;
629: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
630: $js .= <<END;
631: <script type="text/javascript">
632: $javascript_validations
633: </script>
634: $coursebrowserjs
635: END
636: }
1.305 raeburn 637: if (grep(/^selfcreation$/,@actions)) {
638: $js .= &selfcreate_javascript();
639: }
1.286 raeburn 640: if (grep(/^contacts$/,@actions)) {
641: $js .= &contacts_javascript();
642: }
1.346 raeburn 643: if (grep(/^scantron$/,@actions)) {
644: $js .= &scantron_javascript();
645: }
1.150 raeburn 646: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 647: } else {
1.180 raeburn 648: # check if domconfig user exists for the domain.
649: my $servadm = $r->dir_config('lonAdmEMail');
650: my ($configuserok,$author_ok,$switchserver) =
651: &config_check($dom,$confname,$servadm);
652: unless ($configuserok eq 'ok') {
1.181 raeburn 653: &Apache::lonconfigsettings::print_header($r,$phase,$context);
654: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 655: $confname).
1.181 raeburn 656: '<br />'
657: );
1.180 raeburn 658: if ($switchserver) {
1.181 raeburn 659: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
660: '<br />'.
661: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
662: '<br />'.
663: &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).
664: '<br />'.
665: &mt('To do that now, use the following link: [_1]',$switchserver)
666: );
667: } else {
668: $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.').
669: '<br />'.
670: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
671: );
1.180 raeburn 672: }
673: $r->print(&Apache::loncommon::end_page());
674: return OK;
675: }
1.21 raeburn 676: if (keys(%domconfig) == 0) {
677: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 678: my @ids=&Apache::lonnet::current_machine_ids();
679: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 680: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 681: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 682: my $custom_img_count = 0;
683: foreach my $img (@loginimages) {
684: if ($designhash{$dom.'.login.'.$img} ne '') {
685: $custom_img_count ++;
686: }
687: }
688: foreach my $role (@roles) {
689: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
690: $custom_img_count ++;
691: }
692: }
693: if ($custom_img_count > 0) {
1.94 raeburn 694: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 695: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 696: $r->print(
697: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
698: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
699: &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 />'.
700: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
701: if ($switch_server) {
1.30 raeburn 702: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 703: }
1.91 raeburn 704: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 705: return OK;
706: }
707: }
708: }
1.91 raeburn 709: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 710: }
711: return OK;
712: }
713:
714: sub process_changes {
1.205 raeburn 715: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 716: my %domconfig;
717: if (ref($values) eq 'HASH') {
718: %domconfig = %{$values};
719: }
1.3 raeburn 720: my $output;
721: if ($action eq 'login') {
1.205 raeburn 722: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 723: } elsif ($action eq 'rolecolors') {
1.9 raeburn 724: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 725: $lastactref,%domconfig);
1.3 raeburn 726: } elsif ($action eq 'quotas') {
1.216 raeburn 727: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 728: } elsif ($action eq 'autoenroll') {
1.205 raeburn 729: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 730: } elsif ($action eq 'autoupdate') {
731: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 732: } elsif ($action eq 'autocreate') {
733: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 734: } elsif ($action eq 'directorysrch') {
1.295 raeburn 735: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 736: } elsif ($action eq 'usercreation') {
1.28 raeburn 737: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 738: } elsif ($action eq 'selfcreation') {
1.305 raeburn 739: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 740: } elsif ($action eq 'usermodification') {
741: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 742: } elsif ($action eq 'contacts') {
1.205 raeburn 743: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 744: } elsif ($action eq 'defaults') {
1.212 raeburn 745: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 746: } elsif ($action eq 'scantron') {
1.205 raeburn 747: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 748: } elsif ($action eq 'coursecategories') {
1.239 raeburn 749: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 750: } elsif ($action eq 'serverstatuses') {
751: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 752: } elsif ($action eq 'requestcourses') {
1.216 raeburn 753: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 754: } elsif ($action eq 'requestauthor') {
1.216 raeburn 755: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 756: } elsif ($action eq 'helpsettings') {
1.285 raeburn 757: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 758: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 759: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 760: } elsif ($action eq 'selfenrollment') {
761: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 762: } elsif ($action eq 'usersessions') {
1.212 raeburn 763: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 764: } elsif ($action eq 'loadbalancing') {
765: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 766: } elsif ($action eq 'ltitools') {
767: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 768: } elsif ($action eq 'ssl') {
769: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 770: } elsif ($action eq 'trust') {
771: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 772: } elsif ($action eq 'lti') {
773: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.354 raeburn 774: } elsif ($action eq 'passwords') {
775: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 776: }
777: return $output;
778: }
779:
780: sub print_config_box {
1.9 raeburn 781: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 782: my $rowtotal = 0;
1.49 raeburn 783: my $output;
784: if ($action eq 'coursecategories') {
785: $output = &coursecategories_javascript($settings);
1.236 raeburn 786: } elsif ($action eq 'defaults') {
787: $output = &defaults_javascript($settings);
1.354 raeburn 788: } elsif ($action eq 'passwords') {
789: $output = &passwords_javascript();
1.282 raeburn 790: } elsif ($action eq 'helpsettings') {
791: my (%privs,%levelscurrent);
792: my %full=();
793: my %levels=(
794: course => {},
795: domain => {},
796: system => {},
797: );
798: my $context = 'domain';
799: my $crstype = 'Course';
800: my $formname = 'display';
801: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
802: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
803: $output =
804: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
805: \@templateroles);
1.334 raeburn 806: } elsif ($action eq 'ltitools') {
807: $output .= <itools_javascript($settings);
808: } elsif ($action eq 'lti') {
809: $output .= <i_javascript($settings);
1.91 raeburn 810: }
1.236 raeburn 811: $output .=
1.30 raeburn 812: '<table class="LC_nested_outer">
1.3 raeburn 813: <tr>
1.306 raeburn 814: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 815: &mt($item->{text}).' '.
816: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
817: '</tr>';
1.30 raeburn 818: $rowtotal ++;
1.110 raeburn 819: my $numheaders = 1;
820: if (ref($item->{'header'}) eq 'ARRAY') {
821: $numheaders = scalar(@{$item->{'header'}});
822: }
823: if ($numheaders > 1) {
1.64 raeburn 824: my $colspan = '';
1.145 raeburn 825: my $rightcolspan = '';
1.238 raeburn 826: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 827: ($action eq 'directorysrch') ||
1.256 raeburn 828: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 829: $colspan = ' colspan="2"';
830: }
1.145 raeburn 831: if ($action eq 'usersessions') {
832: $rightcolspan = ' colspan="3"';
833: }
1.30 raeburn 834: $output .= '
1.3 raeburn 835: <tr>
836: <td>
837: <table class="LC_nested">
838: <tr class="LC_info_row">
1.59 bisitz 839: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 840: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 841: </tr>';
1.69 raeburn 842: $rowtotal ++;
1.230 raeburn 843: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 844: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 845: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 846: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
847: ($action eq 'contacts')) {
1.230 raeburn 848: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 849: } elsif ($action eq 'passwords') {
850: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 851: } elsif ($action eq 'coursecategories') {
1.230 raeburn 852: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 853: } elsif ($action eq 'scantron') {
854: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 855: } elsif ($action eq 'login') {
1.256 raeburn 856: if ($numheaders == 4) {
1.168 raeburn 857: $colspan = ' colspan="2"';
858: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
859: } else {
860: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
861: }
1.230 raeburn 862: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 863: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 864: } elsif ($action eq 'rolecolors') {
1.30 raeburn 865: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 866: }
1.30 raeburn 867: $output .= '
1.6 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">
1.230 raeburn 875: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 876: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 877: </tr>';
878: $rowtotal ++;
1.230 raeburn 879: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
880: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 881: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.354 raeburn 882: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'passwords')) {
1.238 raeburn 883: if ($action eq 'coursecategories') {
884: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
885: $colspan = ' colspan="2"';
1.279 raeburn 886: } elsif ($action eq 'trust') {
887: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 888: } elsif ($action eq 'passwords') {
889: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 890: } else {
891: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
892: }
1.279 raeburn 893: if ($action eq 'trust') {
894: $output .= '
895: </table>
896: </td>
897: </tr>';
898: my @trusthdrs = qw(2 3 4 5 6 7);
899: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
900: for (my $i=0; $i<@trusthdrs; $i++) {
901: $output .= '
902: <tr>
903: <td>
904: <table class="LC_nested">
905: <tr class="LC_info_row">
906: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
907: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
908: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
909: </table>
910: </td>
911: </tr>';
912: }
913: $output .= '
914: <tr>
915: <td>
916: <table class="LC_nested">
917: <tr class="LC_info_row">
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
920: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
921: } else {
922: $output .= '
1.63 raeburn 923: </table>
924: </td>
925: </tr>
926: <tr>
927: <td>
928: <table class="LC_nested">
929: <tr class="LC_info_row">
930: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 931: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 932: </tr>'."\n";
1.279 raeburn 933: if ($action eq 'coursecategories') {
934: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.354 raeburn 935: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
936: if ($action eq 'passwords') {
937: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
938: } else {
939: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
940: }
941: $output .= '
1.340 raeburn 942: </tr>
943: </table>
944: </td>
945: </tr>
946: <tr>
947: <td>
948: <table class="LC_nested">
949: <tr class="LC_info_row">
950: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 951: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
952: if ($action eq 'passwords') {
953: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
954: } else {
955: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
956: }
957: $output .= '
1.340 raeburn 958: </table>
959: </td>
960: </tr>
961: <tr>';
1.279 raeburn 962: } else {
963: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
964: }
1.238 raeburn 965: }
1.63 raeburn 966: $rowtotal ++;
1.236 raeburn 967: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 968: ($action eq 'defaults') || ($action eq 'directorysrch') ||
969: ($action eq 'helpsettings')) {
1.230 raeburn 970: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 971: } elsif ($action eq 'scantron') {
972: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 973: } elsif ($action eq 'ssl') {
974: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
975: </table>
976: </td>
977: </tr>
978: <tr>
979: <td>
980: <table class="LC_nested">
981: <tr class="LC_info_row">
982: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
983: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
984: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
985: </table>
986: </td>
987: </tr>
988: <tr>
989: <td>
990: <table class="LC_nested">
991: <tr class="LC_info_row">
992: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
993: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
994: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 995: } elsif ($action eq 'login') {
1.256 raeburn 996: if ($numheaders == 4) {
1.168 raeburn 997: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1005: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1006: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1007: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1008: $rowtotal ++;
1009: } else {
1010: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1011: }
1.256 raeburn 1012: $output .= '
1013: </table>
1014: </td>
1015: </tr>
1016: <tr>
1017: <td>
1018: <table class="LC_nested">
1019: <tr class="LC_info_row">';
1020: if ($numheaders == 4) {
1021: $output .= '
1022: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1023: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1024: </tr>';
1025: } else {
1026: $output .= '
1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1029: </tr>';
1030: }
1031: $rowtotal ++;
1032: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1033: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1034: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1035: $rowtotal ++;
1036: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1037: </table>
1038: </td>
1039: </tr>
1040: <tr>
1041: <td>
1042: <table class="LC_nested">
1043: <tr class="LC_info_row">
1044: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1045: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1046: &textbookcourses_javascript($settings).
1047: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1048: </table>
1049: </td>
1050: </tr>
1051: <tr>
1052: <td>
1053: <table class="LC_nested">
1054: <tr class="LC_info_row">
1055: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1056: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1057: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1058: </table>
1059: </td>
1060: </tr>
1061: <tr>
1062: <td>
1063: <table class="LC_nested">
1064: <tr class="LC_info_row">
1.306 raeburn 1065: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1066: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1067: </tr>'.
1068: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1069: } elsif ($action eq 'requestauthor') {
1070: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1071: $rowtotal ++;
1.122 jms 1072: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1073: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1074: </table>
1075: </td>
1076: </tr>
1077: <tr>
1078: <td>
1079: <table class="LC_nested">
1080: <tr class="LC_info_row">
1.306 raeburn 1081: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1082: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1083: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1084: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1085: </tr>'.
1.30 raeburn 1086: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1087: </table>
1088: </td>
1089: </tr>
1090: <tr>
1091: <td>
1092: <table class="LC_nested">
1093: <tr class="LC_info_row">
1.59 bisitz 1094: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1095: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1096: </tr>'.
1.30 raeburn 1097: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1098: $rowtotal += 2;
1.6 raeburn 1099: }
1.3 raeburn 1100: } else {
1.30 raeburn 1101: $output .= '
1.3 raeburn 1102: <tr>
1103: <td>
1104: <table class="LC_nested">
1.30 raeburn 1105: <tr class="LC_info_row">';
1.277 raeburn 1106: if ($action eq 'login') {
1.30 raeburn 1107: $output .= '
1.59 bisitz 1108: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1109: } elsif ($action eq 'serverstatuses') {
1110: $output .= '
1.306 raeburn 1111: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1112: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1113:
1.6 raeburn 1114: } else {
1.30 raeburn 1115: $output .= '
1.306 raeburn 1116: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1117: }
1.72 raeburn 1118: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1119: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1120: &mt($item->{'header'}->[0]->{'col2'});
1121: if ($action eq 'serverstatuses') {
1122: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1123: }
1.69 raeburn 1124: } else {
1.306 raeburn 1125: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1126: &mt($item->{'header'}->[0]->{'col2'});
1127: }
1128: $output .= '</td>';
1129: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1130: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1131: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1132: &mt($item->{'header'}->[0]->{'col3'});
1133: } else {
1.306 raeburn 1134: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1135: &mt($item->{'header'}->[0]->{'col3'});
1136: }
1.69 raeburn 1137: if ($action eq 'serverstatuses') {
1138: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1139: }
1140: $output .= '</td>';
1.6 raeburn 1141: }
1.150 raeburn 1142: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1143: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1144: &mt($item->{'header'}->[0]->{'col4'});
1145: }
1.69 raeburn 1146: $output .= '</tr>';
1.48 raeburn 1147: $rowtotal ++;
1.168 raeburn 1148: if ($action eq 'quotas') {
1.86 raeburn 1149: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1150: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1151: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1152: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1153: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1154: }
1.3 raeburn 1155: }
1.30 raeburn 1156: $output .= '
1.3 raeburn 1157: </table>
1158: </td>
1159: </tr>
1.30 raeburn 1160: </table><br />';
1161: return ($output,$rowtotal);
1.1 raeburn 1162: }
1163:
1.3 raeburn 1164: sub print_login {
1.168 raeburn 1165: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1166: my ($css_class,$datatable);
1.6 raeburn 1167: my %choices = &login_choices();
1.110 raeburn 1168:
1.168 raeburn 1169: if ($caller eq 'service') {
1.149 raeburn 1170: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1171: my $choice = $choices{'disallowlogin'};
1172: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1173: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1174: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1175: '<th>'.$choices{'server'}.'</th>'.
1176: '<th>'.$choices{'serverpath'}.'</th>'.
1177: '<th>'.$choices{'custompath'}.'</th>'.
1178: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1179: my %disallowed;
1180: if (ref($settings) eq 'HASH') {
1181: if (ref($settings->{'loginvia'}) eq 'HASH') {
1182: %disallowed = %{$settings->{'loginvia'}};
1183: }
1184: }
1185: foreach my $lonhost (sort(keys(%servers))) {
1186: my $direct = 'selected="selected"';
1.128 raeburn 1187: if (ref($disallowed{$lonhost}) eq 'HASH') {
1188: if ($disallowed{$lonhost}{'server'} ne '') {
1189: $direct = '';
1190: }
1.110 raeburn 1191: }
1.115 raeburn 1192: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1193: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1194: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1195: '</option>';
1.184 raeburn 1196: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1197: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1198: my $selected = '';
1.128 raeburn 1199: if (ref($disallowed{$lonhost}) eq 'HASH') {
1200: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1201: $selected = 'selected="selected"';
1202: }
1.110 raeburn 1203: }
1204: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1205: $servers{$hostid}.'</option>';
1206: }
1.128 raeburn 1207: $datatable .= '</select></td>'.
1208: '<td><select name="'.$lonhost.'_serverpath">';
1209: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1210: my $pathname = $path;
1211: if ($path eq 'custom') {
1212: $pathname = &mt('Custom Path').' ->';
1213: }
1214: my $selected = '';
1215: if (ref($disallowed{$lonhost}) eq 'HASH') {
1216: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1217: $selected = 'selected="selected"';
1218: }
1219: } elsif ($path eq '') {
1220: $selected = 'selected="selected"';
1221: }
1222: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1223: }
1224: $datatable .= '</select></td>';
1225: my ($custom,$exempt);
1226: if (ref($disallowed{$lonhost}) eq 'HASH') {
1227: $custom = $disallowed{$lonhost}{'custompath'};
1228: $exempt = $disallowed{$lonhost}{'exempt'};
1229: }
1230: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1231: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1232: '</tr>';
1.110 raeburn 1233: }
1234: $datatable .= '</table></td></tr>';
1235: return $datatable;
1.168 raeburn 1236: } elsif ($caller eq 'page') {
1237: my %defaultchecked = (
1238: 'coursecatalog' => 'on',
1.188 raeburn 1239: 'helpdesk' => 'on',
1.168 raeburn 1240: 'adminmail' => 'off',
1241: 'newuser' => 'off',
1242: );
1.188 raeburn 1243: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1244: my (%checkedon,%checkedoff);
1.42 raeburn 1245: foreach my $item (@toggles) {
1.168 raeburn 1246: if ($defaultchecked{$item} eq 'on') {
1247: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1248: $checkedoff{$item} = ' ';
1.168 raeburn 1249: } elsif ($defaultchecked{$item} eq 'off') {
1250: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1251: $checkedon{$item} = ' ';
1252: }
1.1 raeburn 1253: }
1.168 raeburn 1254: my @images = ('img','logo','domlogo','login');
1255: my @logintext = ('textcol','bgcol');
1256: my @bgs = ('pgbg','mainbg','sidebg');
1257: my @links = ('link','alink','vlink');
1258: my %designhash = &Apache::loncommon::get_domainconf($dom);
1259: my %defaultdesign = %Apache::loncommon::defaultdesign;
1260: my (%is_custom,%designs);
1261: my %defaults = (
1262: font => $defaultdesign{'login.font'},
1263: );
1.6 raeburn 1264: foreach my $item (@images) {
1.168 raeburn 1265: $defaults{$item} = $defaultdesign{'login.'.$item};
1266: $defaults{'showlogo'}{$item} = 1;
1267: }
1268: foreach my $item (@bgs) {
1269: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1270: }
1.41 raeburn 1271: foreach my $item (@logintext) {
1.168 raeburn 1272: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1273: }
1.168 raeburn 1274: foreach my $item (@links) {
1275: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1276: }
1.168 raeburn 1277: if (ref($settings) eq 'HASH') {
1278: foreach my $item (@toggles) {
1279: if ($settings->{$item} eq '1') {
1280: $checkedon{$item} = ' checked="checked" ';
1281: $checkedoff{$item} = ' ';
1282: } elsif ($settings->{$item} eq '0') {
1283: $checkedoff{$item} = ' checked="checked" ';
1284: $checkedon{$item} = ' ';
1285: }
1286: }
1287: foreach my $item (@images) {
1288: if (defined($settings->{$item})) {
1289: $designs{$item} = $settings->{$item};
1290: $is_custom{$item} = 1;
1291: }
1292: if (defined($settings->{'showlogo'}{$item})) {
1293: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1294: }
1295: }
1296: foreach my $item (@logintext) {
1297: if ($settings->{$item} ne '') {
1298: $designs{'logintext'}{$item} = $settings->{$item};
1299: $is_custom{$item} = 1;
1300: }
1301: }
1302: if ($settings->{'font'} ne '') {
1303: $designs{'font'} = $settings->{'font'};
1304: $is_custom{'font'} = 1;
1305: }
1306: foreach my $item (@bgs) {
1307: if ($settings->{$item} ne '') {
1308: $designs{'bgs'}{$item} = $settings->{$item};
1309: $is_custom{$item} = 1;
1310: }
1311: }
1312: foreach my $item (@links) {
1313: if ($settings->{$item} ne '') {
1314: $designs{'links'}{$item} = $settings->{$item};
1315: $is_custom{$item} = 1;
1316: }
1317: }
1318: } else {
1319: if ($designhash{$dom.'.login.font'} ne '') {
1320: $designs{'font'} = $designhash{$dom.'.login.font'};
1321: $is_custom{'font'} = 1;
1322: }
1323: foreach my $item (@images) {
1324: if ($designhash{$dom.'.login.'.$item} ne '') {
1325: $designs{$item} = $designhash{$dom.'.login.'.$item};
1326: $is_custom{$item} = 1;
1327: }
1328: }
1329: foreach my $item (@bgs) {
1330: if ($designhash{$dom.'.login.'.$item} ne '') {
1331: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1332: $is_custom{$item} = 1;
1333: }
1.6 raeburn 1334: }
1.168 raeburn 1335: foreach my $item (@links) {
1336: if ($designhash{$dom.'.login.'.$item} ne '') {
1337: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1338: $is_custom{$item} = 1;
1339: }
1.6 raeburn 1340: }
1341: }
1.168 raeburn 1342: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1343: logo => 'Institution Logo',
1344: domlogo => 'Domain Logo',
1345: login => 'Login box');
1346: my $itemcount = 1;
1347: foreach my $item (@toggles) {
1348: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1349: $datatable .=
1350: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1351: '</td><td>'.
1352: '<span class="LC_nobreak"><label><input type="radio" name="'.
1353: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1354: '</label> <label><input type="radio" name="'.$item.'"'.
1355: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1356: '</tr>';
1357: $itemcount ++;
1.6 raeburn 1358: }
1.168 raeburn 1359: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1360: $datatable .= '</tr></table></td></tr>';
1361: } elsif ($caller eq 'help') {
1362: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1363: my $switchserver = &check_switchserver($dom,$confname);
1364: my $itemcount = 1;
1365: $defaulturl = '/adm/loginproblems.html';
1366: $defaulttype = 'default';
1367: %lt = &Apache::lonlocal::texthash (
1368: del => 'Delete?',
1369: rep => 'Replace:',
1370: upl => 'Upload:',
1371: default => 'Default',
1372: custom => 'Custom',
1373: );
1374: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1375: my @currlangs;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'helpurl'}) eq 'HASH') {
1378: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1379: next if ($settings->{'helpurl'}{$key} eq '');
1380: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1381: $type{$key} = 'custom';
1382: unless ($key eq 'nolang') {
1383: push(@currlangs,$key);
1384: }
1385: }
1386: } elsif ($settings->{'helpurl'} ne '') {
1387: $type{'nolang'} = 'custom';
1388: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1389: }
1390: }
1.168 raeburn 1391: foreach my $lang ('nolang',sort(@currlangs)) {
1392: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1393: $datatable .= '<tr'.$css_class.'>';
1394: if ($url{$lang} eq '') {
1395: $url{$lang} = $defaulturl;
1396: }
1397: if ($type{$lang} eq '') {
1398: $type{$lang} = $defaulttype;
1399: }
1400: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1401: if ($lang eq 'nolang') {
1402: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1403: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1404: } else {
1405: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1406: $langchoices{$lang},
1407: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1408: }
1409: $datatable .= '</span></td>'."\n".
1410: '<td class="LC_left_item">';
1411: if ($type{$lang} eq 'custom') {
1412: $datatable .= '<span class="LC_nobreak"><label>'.
1413: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1414: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1415: } else {
1416: $datatable .= $lt{'upl'};
1417: }
1418: $datatable .='<br />';
1419: if ($switchserver) {
1420: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1421: } else {
1422: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1423: }
1.168 raeburn 1424: $datatable .= '</td></tr>';
1425: $itemcount ++;
1.6 raeburn 1426: }
1.168 raeburn 1427: my @addlangs;
1428: foreach my $lang (sort(keys(%langchoices))) {
1429: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1430: push(@addlangs,$lang);
1431: }
1432: if (@addlangs > 0) {
1433: my %toadd;
1434: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1435: $toadd{''} = &mt('Select');
1436: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1437: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1438: &mt('Add log-in help page for a specific language:').' '.
1439: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1440: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1441: if ($switchserver) {
1442: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1443: } else {
1444: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1445: }
1.168 raeburn 1446: $datatable .= '</td></tr>';
1.169 raeburn 1447: $itemcount ++;
1.6 raeburn 1448: }
1.169 raeburn 1449: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1450: } elsif ($caller eq 'headtag') {
1451: my %domservers = &Apache::lonnet::get_servers($dom);
1452: my $choice = $choices{'headtag'};
1453: $css_class = ' class="LC_odd_row"';
1454: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1455: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1456: '<th>'.$choices{'current'}.'</th>'.
1457: '<th>'.$choices{'action'}.'</th>'.
1458: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1459: my (%currurls,%currexempt);
1460: if (ref($settings) eq 'HASH') {
1461: if (ref($settings->{'headtag'}) eq 'HASH') {
1462: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1463: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1464: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1465: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1466: }
1467: }
1468: }
1469: }
1470: my %lt = &Apache::lonlocal::texthash(
1471: del => 'Delete?',
1472: rep => 'Replace:',
1473: upl => 'Upload:',
1474: curr => 'View contents',
1475: none => 'None',
1476: );
1477: my $switchserver = &check_switchserver($dom,$confname);
1478: foreach my $lonhost (sort(keys(%domservers))) {
1479: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1480: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1481: if ($currurls{$lonhost}) {
1482: $datatable .= '<td class="LC_right_item"><a href="'.
1483: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1484: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1485: '">'.$lt{'curr'}.'</a></td>'.
1486: '<td><span class="LC_nobreak"><label>'.
1487: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1488: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1489: } else {
1490: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1491: }
1492: $datatable .='<br />';
1493: if ($switchserver) {
1494: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1495: } else {
1496: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1497: }
1.330 raeburn 1498: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1499: }
1500: $datatable .= '</table></td></tr>';
1.1 raeburn 1501: }
1.6 raeburn 1502: return $datatable;
1503: }
1504:
1505: sub login_choices {
1506: my %choices =
1507: &Apache::lonlocal::texthash (
1.116 bisitz 1508: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1509: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1510: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1511: disallowlogin => "Login page requests redirected",
1512: hostid => "Server",
1.128 raeburn 1513: server => "Redirect to:",
1514: serverpath => "Path",
1515: custompath => "Custom",
1516: exempt => "Exempt IP(s)",
1.110 raeburn 1517: directlogin => "No redirect",
1518: newuser => "Link to create a user account",
1519: img => "Header",
1520: logo => "Main Logo",
1521: domlogo => "Domain Logo",
1522: login => "Log-in Header",
1523: textcol => "Text color",
1524: bgcol => "Box color",
1525: bgs => "Background colors",
1526: links => "Link colors",
1527: font => "Font color",
1528: pgbg => "Header",
1529: mainbg => "Page",
1530: sidebg => "Login box",
1531: link => "Link",
1532: alink => "Active link",
1533: vlink => "Visited link",
1.256 raeburn 1534: headtag => "Custom markup",
1535: action => "Action",
1536: current => "Current",
1.6 raeburn 1537: );
1538: return %choices;
1539: }
1540:
1541: sub print_rolecolors {
1.30 raeburn 1542: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1543: my %choices = &color_font_choices();
1544: my @bgs = ('pgbg','tabbg','sidebg');
1545: my @links = ('link','alink','vlink');
1546: my @images = ('img');
1547: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1548: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1549: my %defaultdesign = %Apache::loncommon::defaultdesign;
1550: my (%is_custom,%designs);
1.200 raeburn 1551: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{$role}) eq 'HASH') {
1554: if ($settings->{$role}->{'img'} ne '') {
1555: $designs{'img'} = $settings->{$role}->{'img'};
1556: $is_custom{'img'} = 1;
1557: }
1558: if ($settings->{$role}->{'font'} ne '') {
1559: $designs{'font'} = $settings->{$role}->{'font'};
1560: $is_custom{'font'} = 1;
1561: }
1.97 tempelho 1562: if ($settings->{$role}->{'fontmenu'} ne '') {
1563: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1564: $is_custom{'fontmenu'} = 1;
1565: }
1.6 raeburn 1566: foreach my $item (@bgs) {
1567: if ($settings->{$role}->{$item} ne '') {
1568: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1569: $is_custom{$item} = 1;
1570: }
1571: }
1572: foreach my $item (@links) {
1573: if ($settings->{$role}->{$item} ne '') {
1574: $designs{'links'}{$item} = $settings->{$role}->{$item};
1575: $is_custom{$item} = 1;
1576: }
1577: }
1578: }
1579: } else {
1580: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1581: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1582: $is_custom{'img'} = 1;
1583: }
1.97 tempelho 1584: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1585: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1586: $is_custom{'fontmenu'} = 1;
1587: }
1.6 raeburn 1588: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1589: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1590: $is_custom{'font'} = 1;
1591: }
1592: foreach my $item (@bgs) {
1593: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1594: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1595: $is_custom{$item} = 1;
1596:
1597: }
1598: }
1599: foreach my $item (@links) {
1600: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1601: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1602: $is_custom{$item} = 1;
1603: }
1604: }
1605: }
1606: my $itemcount = 1;
1.30 raeburn 1607: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1608: $datatable .= '</tr></table></td></tr>';
1609: return $datatable;
1610: }
1611:
1.200 raeburn 1612: sub role_defaults {
1613: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1614: my %defaults;
1615: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1616: return %defaults;
1617: }
1618: my %defaultdesign = %Apache::loncommon::defaultdesign;
1619: if ($role eq 'login') {
1620: %defaults = (
1621: font => $defaultdesign{$role.'.font'},
1622: );
1623: if (ref($logintext) eq 'ARRAY') {
1624: foreach my $item (@{$logintext}) {
1625: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1626: }
1627: }
1628: foreach my $item (@{$images}) {
1629: $defaults{'showlogo'}{$item} = 1;
1630: }
1631: } else {
1632: %defaults = (
1633: img => $defaultdesign{$role.'.img'},
1634: font => $defaultdesign{$role.'.font'},
1635: fontmenu => $defaultdesign{$role.'.fontmenu'},
1636: );
1637: }
1638: foreach my $item (@{$bgs}) {
1639: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1640: }
1641: foreach my $item (@{$links}) {
1642: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1643: }
1644: foreach my $item (@{$images}) {
1645: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1646: }
1647: return %defaults;
1648: }
1649:
1.6 raeburn 1650: sub display_color_options {
1.9 raeburn 1651: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1652: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1653: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1654: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1655: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1656: '<td>'.$choices->{'font'}.'</td>';
1657: if (!$is_custom->{'font'}) {
1.329 raeburn 1658: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1659: } else {
1660: $datatable .= '<td> </td>';
1661: }
1.174 foxr 1662: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1663:
1.8 raeburn 1664: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1665: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1666: ' value="'.$current_color.'" /> '.
1.329 raeburn 1667: ' </span></td></tr>';
1.107 raeburn 1668: unless ($role eq 'login') {
1669: $datatable .= '<tr'.$css_class.'>'.
1670: '<td>'.$choices->{'fontmenu'}.'</td>';
1671: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1672: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1673: } else {
1674: $datatable .= '<td> </td>';
1675: }
1.202 raeburn 1676: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1677: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1678: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1679: '<input class="colorchooser" type="text" size="10" name="'
1680: .$role.'_fontmenu"'.
1681: ' value="'.$current_color.'" /> '.
1.329 raeburn 1682: ' </span></td></tr>';
1.97 tempelho 1683: }
1.9 raeburn 1684: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1685: foreach my $img (@{$images}) {
1.18 albertel 1686: $itemcount ++;
1.6 raeburn 1687: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1688: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1689: '<td>'.$choices->{$img};
1.41 raeburn 1690: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1691: if ($role eq 'login') {
1692: if ($img eq 'login') {
1693: $login_hdr_pick =
1.135 bisitz 1694: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1695: $logincolors =
1696: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1697: $designs,$defaults);
1.70 raeburn 1698: } elsif ($img ne 'domlogo') {
1699: $datatable.= &logo_display_options($img,$defaults,$designs);
1700: }
1701: }
1702: $datatable .= '</td>';
1.6 raeburn 1703: if ($designs->{$img} ne '') {
1704: $imgfile = $designs->{$img};
1.18 albertel 1705: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1706: } else {
1707: $imgfile = $defaults->{$img};
1708: }
1709: if ($imgfile) {
1.9 raeburn 1710: my ($showfile,$fullsize);
1711: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1712: my $urldir = $1;
1713: my $filename = $2;
1714: my @info = &Apache::lonnet::stat_file($designs->{$img});
1715: if (@info) {
1716: my $thumbfile = 'tn-'.$filename;
1717: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1718: if (@thumb) {
1719: $showfile = $urldir.'/'.$thumbfile;
1720: } else {
1721: $showfile = $imgfile;
1722: }
1723: } else {
1724: $showfile = '';
1725: }
1726: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1727: $showfile = $imgfile;
1.6 raeburn 1728: my $imgdir = $1;
1729: my $filename = $2;
1.159 raeburn 1730: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1731: $showfile = "/$imgdir/tn-".$filename;
1732: } else {
1.159 raeburn 1733: my $input = $londocroot.$imgfile;
1734: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1735: if (!-e $output) {
1.9 raeburn 1736: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1737: my ($fullwidth,$fullheight) = &check_dimensions($input);
1738: if ($fullwidth ne '' && $fullheight ne '') {
1739: if ($fullwidth > $width && $fullheight > $height) {
1740: my $size = $width.'x'.$height;
1.316 raeburn 1741: my @args = ('convert','-sample',$size,$input,$output);
1742: system({$args[0]} @args);
1.159 raeburn 1743: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1744: }
1745: }
1.6 raeburn 1746: }
1747: }
1.16 raeburn 1748: }
1.6 raeburn 1749: if ($showfile) {
1.40 raeburn 1750: if ($showfile =~ m{^/(adm|res)/}) {
1751: if ($showfile =~ m{^/res/}) {
1752: my $local_showfile =
1753: &Apache::lonnet::filelocation('',$showfile);
1754: &Apache::lonnet::repcopy($local_showfile);
1755: }
1756: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1757: }
1758: if ($imgfile) {
1759: if ($imgfile =~ m{^/(adm|res)/}) {
1760: if ($imgfile =~ m{^/res/}) {
1761: my $local_imgfile =
1762: &Apache::lonnet::filelocation('',$imgfile);
1763: &Apache::lonnet::repcopy($local_imgfile);
1764: }
1765: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1766: } else {
1767: $fullsize = $imgfile;
1768: }
1769: }
1.41 raeburn 1770: $datatable .= '<td>';
1771: if ($img eq 'login') {
1.135 bisitz 1772: $datatable .= $login_hdr_pick;
1773: }
1.41 raeburn 1774: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1775: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1776: } else {
1.201 raeburn 1777: $datatable .= '<td> </td><td class="LC_left_item">'.
1778: &mt('Upload:').'<br />';
1.6 raeburn 1779: }
1780: } else {
1.201 raeburn 1781: $datatable .= '<td> </td><td class="LC_left_item">'.
1782: &mt('Upload:').'<br />';
1.6 raeburn 1783: }
1.9 raeburn 1784: if ($switchserver) {
1785: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1786: } else {
1.135 bisitz 1787: if ($img ne 'login') { # suppress file selection for Log-in header
1788: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1789: }
1.9 raeburn 1790: }
1791: $datatable .= '</td></tr>';
1.6 raeburn 1792: }
1793: $itemcount ++;
1794: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1795: $datatable .= '<tr'.$css_class.'>'.
1796: '<td>'.$choices->{'bgs'}.'</td>';
1797: my $bgs_def;
1798: foreach my $item (@{$bgs}) {
1799: if (!$is_custom->{$item}) {
1.329 raeburn 1800: $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 1801: }
1802: }
1803: if ($bgs_def) {
1.8 raeburn 1804: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1805: } else {
1806: $datatable .= '<td> </td>';
1807: }
1808: $datatable .= '<td class="LC_right_item">'.
1809: '<table border="0"><tr>';
1.174 foxr 1810:
1.6 raeburn 1811: foreach my $item (@{$bgs}) {
1.306 raeburn 1812: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1813: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1814: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1815: $datatable .= ' ';
1.6 raeburn 1816: }
1.174 foxr 1817: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1818: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1819: }
1820: $datatable .= '</tr></table></td></tr>';
1821: $itemcount ++;
1822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1823: $datatable .= '<tr'.$css_class.'>'.
1824: '<td>'.$choices->{'links'}.'</td>';
1825: my $links_def;
1826: foreach my $item (@{$links}) {
1827: if (!$is_custom->{$item}) {
1.329 raeburn 1828: $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 1829: }
1830: }
1831: if ($links_def) {
1.8 raeburn 1832: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1833: } else {
1834: $datatable .= '<td> </td>';
1835: }
1836: $datatable .= '<td class="LC_right_item">'.
1837: '<table border="0"><tr>';
1838: foreach my $item (@{$links}) {
1.234 raeburn 1839: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1840: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1841: if ($designs->{'links'}{$item}) {
1.174 foxr 1842: $datatable.=' ';
1.6 raeburn 1843: }
1.174 foxr 1844: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1845: '" /></td>';
1846: }
1.30 raeburn 1847: $$rowtotal += $itemcount;
1.3 raeburn 1848: return $datatable;
1849: }
1850:
1.70 raeburn 1851: sub logo_display_options {
1852: my ($img,$defaults,$designs) = @_;
1853: my $checkedon;
1854: if (ref($defaults) eq 'HASH') {
1855: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1856: if ($defaults->{'showlogo'}{$img}) {
1857: $checkedon = 'checked="checked" ';
1858: }
1859: }
1860: }
1861: if (ref($designs) eq 'HASH') {
1862: if (ref($designs->{'showlogo'}) eq 'HASH') {
1863: if (defined($designs->{'showlogo'}{$img})) {
1864: if ($designs->{'showlogo'}{$img} == 0) {
1865: $checkedon = '';
1866: } elsif ($designs->{'showlogo'}{$img} == 1) {
1867: $checkedon = 'checked="checked" ';
1868: }
1869: }
1870: }
1871: }
1872: return '<br /><label> <input type="checkbox" name="'.
1873: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1874: &mt('show').'</label>'."\n";
1875: }
1876:
1.41 raeburn 1877: sub login_header_options {
1.135 bisitz 1878: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1879: my $output = '';
1.41 raeburn 1880: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1881: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1882: if (!$is_custom->{'textcol'}) {
1883: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1884: ' ';
1885: }
1886: if (!$is_custom->{'bgcol'}) {
1887: $output .= $choices->{'bgcol'}.': '.
1888: '<span id="css_'.$role.'_font" style="background-color: '.
1889: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1890: }
1891: $output .= '<br />';
1892: }
1893: $output .='<br />';
1894: return $output;
1895: }
1896:
1897: sub login_text_colors {
1.201 raeburn 1898: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1899: my $color_menu = '<table border="0"><tr>';
1900: foreach my $item (@{$logintext}) {
1.306 raeburn 1901: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1902: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1903: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1904: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1905: }
1906: $color_menu .= '</tr></table><br />';
1907: return $color_menu;
1908: }
1909:
1910: sub image_changes {
1911: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1912: my $output;
1.135 bisitz 1913: if ($img eq 'login') {
1.331 raeburn 1914: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1915: } elsif (!$is_custom) {
1.70 raeburn 1916: if ($img ne 'domlogo') {
1.331 raeburn 1917: $output = &mt('Default image:').'<br />';
1.41 raeburn 1918: } else {
1.331 raeburn 1919: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1920: }
1921: }
1.331 raeburn 1922: if ($img ne 'login') {
1.135 bisitz 1923: if ($img_import) {
1924: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1925: }
1926: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1927: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1928: if ($is_custom) {
1929: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1930: '<input type="checkbox" name="'.
1931: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1932: '</label> '.&mt('Replace:').'</span><br />';
1933: } else {
1.306 raeburn 1934: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1935: }
1.41 raeburn 1936: }
1937: return $output;
1938: }
1939:
1.3 raeburn 1940: sub print_quotas {
1.86 raeburn 1941: my ($dom,$settings,$rowtotal,$action) = @_;
1942: my $context;
1943: if ($action eq 'quotas') {
1944: $context = 'tools';
1945: } else {
1946: $context = $action;
1947: }
1.197 raeburn 1948: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1949: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1950: my $typecount = 0;
1.101 raeburn 1951: my ($css_class,%titles);
1.86 raeburn 1952: if ($context eq 'requestcourses') {
1.325 raeburn 1953: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1954: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1955: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1956: %titles = &courserequest_titles();
1.163 raeburn 1957: } elsif ($context eq 'requestauthor') {
1958: @usertools = ('author');
1959: @options = ('norequest','approval','automatic');
1.210 raeburn 1960: %titles = &authorrequest_titles();
1.86 raeburn 1961: } else {
1.162 raeburn 1962: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1963: %titles = &tool_titles();
1.86 raeburn 1964: }
1.26 raeburn 1965: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1966: foreach my $type (@{$types}) {
1.197 raeburn 1967: my ($currdefquota,$currauthorquota);
1.163 raeburn 1968: unless (($context eq 'requestcourses') ||
1969: ($context eq 'requestauthor')) {
1.86 raeburn 1970: if (ref($settings) eq 'HASH') {
1971: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1972: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1973: } else {
1974: $currdefquota = $settings->{$type};
1975: }
1.197 raeburn 1976: if (ref($settings->{authorquota}) eq 'HASH') {
1977: $currauthorquota = $settings->{authorquota}->{$type};
1978: }
1.78 raeburn 1979: }
1.72 raeburn 1980: }
1.3 raeburn 1981: if (defined($usertypes->{$type})) {
1982: $typecount ++;
1983: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1984: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1985: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1986: '<td class="LC_left_item">';
1.101 raeburn 1987: if ($context eq 'requestcourses') {
1988: $datatable .= '<table><tr>';
1989: }
1990: my %cell;
1.72 raeburn 1991: foreach my $item (@usertools) {
1.101 raeburn 1992: if ($context eq 'requestcourses') {
1993: my ($curroption,$currlimit);
1994: if (ref($settings) eq 'HASH') {
1995: if (ref($settings->{$item}) eq 'HASH') {
1996: $curroption = $settings->{$item}->{$type};
1997: if ($curroption =~ /^autolimit=(\d*)$/) {
1998: $currlimit = $1;
1999: }
2000: }
2001: }
2002: if (!$curroption) {
2003: $curroption = 'norequest';
2004: }
2005: $datatable .= '<th>'.$titles{$item}.'</th>';
2006: foreach my $option (@options) {
2007: my $val = $option;
2008: if ($option eq 'norequest') {
2009: $val = 0;
2010: }
2011: if ($option eq 'validate') {
2012: my $canvalidate = 0;
2013: if (ref($validations{$item}) eq 'HASH') {
2014: if ($validations{$item}{$type}) {
2015: $canvalidate = 1;
2016: }
2017: }
2018: next if (!$canvalidate);
2019: }
2020: my $checked = '';
2021: if ($option eq $curroption) {
2022: $checked = ' checked="checked"';
2023: } elsif ($option eq 'autolimit') {
2024: if ($curroption =~ /^autolimit/) {
2025: $checked = ' checked="checked"';
2026: }
2027: }
2028: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2029: '<input type="radio" name="crsreq_'.$item.
2030: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2031: $titles{$option}.'</label>';
1.101 raeburn 2032: if ($option eq 'autolimit') {
1.127 raeburn 2033: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2034: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2035: 'value="'.$currlimit.'" />';
1.101 raeburn 2036: }
1.127 raeburn 2037: $cell{$item} .= '</span> ';
1.103 raeburn 2038: if ($option eq 'autolimit') {
1.127 raeburn 2039: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2040: }
1.101 raeburn 2041: }
1.163 raeburn 2042: } elsif ($context eq 'requestauthor') {
2043: my $curroption;
2044: if (ref($settings) eq 'HASH') {
2045: $curroption = $settings->{$type};
2046: }
2047: if (!$curroption) {
2048: $curroption = 'norequest';
2049: }
2050: foreach my $option (@options) {
2051: my $val = $option;
2052: if ($option eq 'norequest') {
2053: $val = 0;
2054: }
2055: my $checked = '';
2056: if ($option eq $curroption) {
2057: $checked = ' checked="checked"';
2058: }
2059: $datatable .= '<span class="LC_nobreak"><label>'.
2060: '<input type="radio" name="authorreq_'.$type.
2061: '" value="'.$val.'"'.$checked.' />'.
2062: $titles{$option}.'</label></span> ';
2063: }
1.101 raeburn 2064: } else {
2065: my $checked = 'checked="checked" ';
2066: if (ref($settings) eq 'HASH') {
2067: if (ref($settings->{$item}) eq 'HASH') {
2068: if ($settings->{$item}->{$type} == 0) {
2069: $checked = '';
2070: } elsif ($settings->{$item}->{$type} == 1) {
2071: $checked = 'checked="checked" ';
2072: }
1.78 raeburn 2073: }
1.72 raeburn 2074: }
1.101 raeburn 2075: $datatable .= '<span class="LC_nobreak"><label>'.
2076: '<input type="checkbox" name="'.$context.'_'.$item.
2077: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2078: '</label></span> ';
1.72 raeburn 2079: }
1.101 raeburn 2080: }
2081: if ($context eq 'requestcourses') {
2082: $datatable .= '</tr><tr>';
2083: foreach my $item (@usertools) {
1.106 raeburn 2084: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2085: }
2086: $datatable .= '</tr></table>';
1.72 raeburn 2087: }
1.86 raeburn 2088: $datatable .= '</td>';
1.163 raeburn 2089: unless (($context eq 'requestcourses') ||
2090: ($context eq 'requestauthor')) {
1.86 raeburn 2091: $datatable .=
1.197 raeburn 2092: '<td class="LC_right_item">'.
2093: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2094: '<input type="text" name="quota_'.$type.
1.72 raeburn 2095: '" value="'.$currdefquota.
1.197 raeburn 2096: '" size="5" /></span>'.(' ' x 2).
2097: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2098: '<input type="text" name="authorquota_'.$type.
2099: '" value="'.$currauthorquota.
2100: '" size="5" /></span></td>';
1.86 raeburn 2101: }
2102: $datatable .= '</tr>';
1.3 raeburn 2103: }
2104: }
2105: }
1.163 raeburn 2106: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2107: $defaultquota = '20';
1.197 raeburn 2108: $authorquota = '500';
1.86 raeburn 2109: if (ref($settings) eq 'HASH') {
2110: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2111: $defaultquota = $settings->{'defaultquota'}->{'default'};
2112: } elsif (defined($settings->{'default'})) {
2113: $defaultquota = $settings->{'default'};
2114: }
1.197 raeburn 2115: if (ref($settings->{'authorquota'}) eq 'HASH') {
2116: $authorquota = $settings->{'authorquota'}->{'default'};
2117: }
1.3 raeburn 2118: }
2119: }
2120: $typecount ++;
2121: $css_class = $typecount%2?' class="LC_odd_row"':'';
2122: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2123: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2124: '<td class="LC_left_item">';
1.101 raeburn 2125: if ($context eq 'requestcourses') {
2126: $datatable .= '<table><tr>';
2127: }
2128: my %defcell;
1.72 raeburn 2129: foreach my $item (@usertools) {
1.101 raeburn 2130: if ($context eq 'requestcourses') {
2131: my ($curroption,$currlimit);
2132: if (ref($settings) eq 'HASH') {
2133: if (ref($settings->{$item}) eq 'HASH') {
2134: $curroption = $settings->{$item}->{'default'};
2135: if ($curroption =~ /^autolimit=(\d*)$/) {
2136: $currlimit = $1;
2137: }
2138: }
2139: }
2140: if (!$curroption) {
2141: $curroption = 'norequest';
2142: }
2143: $datatable .= '<th>'.$titles{$item}.'</th>';
2144: foreach my $option (@options) {
2145: my $val = $option;
2146: if ($option eq 'norequest') {
2147: $val = 0;
2148: }
2149: if ($option eq 'validate') {
2150: my $canvalidate = 0;
2151: if (ref($validations{$item}) eq 'HASH') {
2152: if ($validations{$item}{'default'}) {
2153: $canvalidate = 1;
2154: }
2155: }
2156: next if (!$canvalidate);
2157: }
2158: my $checked = '';
2159: if ($option eq $curroption) {
2160: $checked = ' checked="checked"';
2161: } elsif ($option eq 'autolimit') {
2162: if ($curroption =~ /^autolimit/) {
2163: $checked = ' checked="checked"';
2164: }
2165: }
2166: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2167: '<input type="radio" name="crsreq_'.$item.
2168: '_default" value="'.$val.'"'.$checked.' />'.
2169: $titles{$option}.'</label>';
2170: if ($option eq 'autolimit') {
1.127 raeburn 2171: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2172: $item.'_limit_default" size="1" '.
2173: 'value="'.$currlimit.'" />';
2174: }
1.127 raeburn 2175: $defcell{$item} .= '</span> ';
1.104 raeburn 2176: if ($option eq 'autolimit') {
1.127 raeburn 2177: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2178: }
1.101 raeburn 2179: }
1.163 raeburn 2180: } elsif ($context eq 'requestauthor') {
2181: my $curroption;
2182: if (ref($settings) eq 'HASH') {
1.172 raeburn 2183: $curroption = $settings->{'default'};
1.163 raeburn 2184: }
2185: if (!$curroption) {
2186: $curroption = 'norequest';
2187: }
2188: foreach my $option (@options) {
2189: my $val = $option;
2190: if ($option eq 'norequest') {
2191: $val = 0;
2192: }
2193: my $checked = '';
2194: if ($option eq $curroption) {
2195: $checked = ' checked="checked"';
2196: }
2197: $datatable .= '<span class="LC_nobreak"><label>'.
2198: '<input type="radio" name="authorreq_default"'.
2199: ' value="'.$val.'"'.$checked.' />'.
2200: $titles{$option}.'</label></span> ';
2201: }
1.101 raeburn 2202: } else {
2203: my $checked = 'checked="checked" ';
2204: if (ref($settings) eq 'HASH') {
2205: if (ref($settings->{$item}) eq 'HASH') {
2206: if ($settings->{$item}->{'default'} == 0) {
2207: $checked = '';
2208: } elsif ($settings->{$item}->{'default'} == 1) {
2209: $checked = 'checked="checked" ';
2210: }
1.78 raeburn 2211: }
1.72 raeburn 2212: }
1.101 raeburn 2213: $datatable .= '<span class="LC_nobreak"><label>'.
2214: '<input type="checkbox" name="'.$context.'_'.$item.
2215: '" value="default" '.$checked.'/>'.$titles{$item}.
2216: '</label></span> ';
2217: }
2218: }
2219: if ($context eq 'requestcourses') {
2220: $datatable .= '</tr><tr>';
2221: foreach my $item (@usertools) {
1.106 raeburn 2222: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2223: }
1.101 raeburn 2224: $datatable .= '</tr></table>';
1.72 raeburn 2225: }
1.86 raeburn 2226: $datatable .= '</td>';
1.163 raeburn 2227: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2228: $datatable .= '<td class="LC_right_item">'.
2229: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2230: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2231: $defaultquota.'" size="5" /></span>'.(' ' x2).
2232: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2233: '<input type="text" name="authorquota" value="'.
2234: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2235: }
2236: $datatable .= '</tr>';
1.72 raeburn 2237: $typecount ++;
2238: $css_class = $typecount%2?' class="LC_odd_row"':'';
2239: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2240: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2241: if ($context eq 'requestcourses') {
1.109 raeburn 2242: $datatable .= &mt('(overrides affiliation, if set)').
2243: '</td>'.
2244: '<td class="LC_left_item">'.
2245: '<table><tr>';
1.101 raeburn 2246: } else {
1.109 raeburn 2247: $datatable .= &mt('(overrides affiliation, if checked)').
2248: '</td>'.
2249: '<td class="LC_left_item" colspan="2">'.
2250: '<br />';
1.101 raeburn 2251: }
2252: my %advcell;
1.72 raeburn 2253: foreach my $item (@usertools) {
1.101 raeburn 2254: if ($context eq 'requestcourses') {
2255: my ($curroption,$currlimit);
2256: if (ref($settings) eq 'HASH') {
2257: if (ref($settings->{$item}) eq 'HASH') {
2258: $curroption = $settings->{$item}->{'_LC_adv'};
2259: if ($curroption =~ /^autolimit=(\d*)$/) {
2260: $currlimit = $1;
2261: }
2262: }
2263: }
2264: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2265: my $checked = '';
2266: if ($curroption eq '') {
2267: $checked = ' checked="checked"';
2268: }
2269: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2270: '<input type="radio" name="crsreq_'.$item.
2271: '__LC_adv" value=""'.$checked.' />'.
2272: &mt('No override set').'</label></span> ';
1.101 raeburn 2273: foreach my $option (@options) {
2274: my $val = $option;
2275: if ($option eq 'norequest') {
2276: $val = 0;
2277: }
2278: if ($option eq 'validate') {
2279: my $canvalidate = 0;
2280: if (ref($validations{$item}) eq 'HASH') {
2281: if ($validations{$item}{'_LC_adv'}) {
2282: $canvalidate = 1;
2283: }
2284: }
2285: next if (!$canvalidate);
2286: }
2287: my $checked = '';
1.104 raeburn 2288: if ($val eq $curroption) {
1.101 raeburn 2289: $checked = ' checked="checked"';
2290: } elsif ($option eq 'autolimit') {
2291: if ($curroption =~ /^autolimit/) {
2292: $checked = ' checked="checked"';
2293: }
2294: }
2295: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2296: '<input type="radio" name="crsreq_'.$item.
2297: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2298: $titles{$option}.'</label>';
2299: if ($option eq 'autolimit') {
1.127 raeburn 2300: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2301: $item.'_limit__LC_adv" size="1" '.
2302: 'value="'.$currlimit.'" />';
2303: }
1.127 raeburn 2304: $advcell{$item} .= '</span> ';
1.104 raeburn 2305: if ($option eq 'autolimit') {
1.127 raeburn 2306: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2307: }
1.101 raeburn 2308: }
1.163 raeburn 2309: } elsif ($context eq 'requestauthor') {
2310: my $curroption;
2311: if (ref($settings) eq 'HASH') {
2312: $curroption = $settings->{'_LC_adv'};
2313: }
2314: my $checked = '';
2315: if ($curroption eq '') {
2316: $checked = ' checked="checked"';
2317: }
2318: $datatable .= '<span class="LC_nobreak"><label>'.
2319: '<input type="radio" name="authorreq__LC_adv"'.
2320: ' value=""'.$checked.' />'.
2321: &mt('No override set').'</label></span> ';
2322: foreach my $option (@options) {
2323: my $val = $option;
2324: if ($option eq 'norequest') {
2325: $val = 0;
2326: }
2327: my $checked = '';
2328: if ($val eq $curroption) {
2329: $checked = ' checked="checked"';
2330: }
2331: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2332: '<input type="radio" name="authorreq__LC_adv"'.
2333: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2334: $titles{$option}.'</label></span> ';
2335: }
1.101 raeburn 2336: } else {
2337: my $checked = 'checked="checked" ';
2338: if (ref($settings) eq 'HASH') {
2339: if (ref($settings->{$item}) eq 'HASH') {
2340: if ($settings->{$item}->{'_LC_adv'} == 0) {
2341: $checked = '';
2342: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2343: $checked = 'checked="checked" ';
2344: }
1.79 raeburn 2345: }
1.72 raeburn 2346: }
1.101 raeburn 2347: $datatable .= '<span class="LC_nobreak"><label>'.
2348: '<input type="checkbox" name="'.$context.'_'.$item.
2349: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2350: '</label></span> ';
2351: }
2352: }
2353: if ($context eq 'requestcourses') {
2354: $datatable .= '</tr><tr>';
2355: foreach my $item (@usertools) {
1.106 raeburn 2356: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2357: }
1.101 raeburn 2358: $datatable .= '</tr></table>';
1.72 raeburn 2359: }
1.98 raeburn 2360: $datatable .= '</td></tr>';
1.30 raeburn 2361: $$rowtotal += $typecount;
1.3 raeburn 2362: return $datatable;
2363: }
2364:
1.163 raeburn 2365: sub print_requestmail {
1.305 raeburn 2366: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2367: my ($now,$datatable,%currapp);
1.102 raeburn 2368: $now = time;
2369: if (ref($settings) eq 'HASH') {
2370: if (ref($settings->{'notify'}) eq 'HASH') {
2371: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2372: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2373: }
2374: }
2375: }
1.191 raeburn 2376: my $numinrow = 2;
1.224 raeburn 2377: my $css_class;
1.305 raeburn 2378: if ($$rowtotal%2) {
2379: $css_class = 'LC_odd_row';
2380: }
2381: if ($customcss) {
2382: $css_class .= " $customcss";
2383: }
2384: $css_class =~ s/^\s+//;
2385: if ($css_class) {
2386: $css_class = ' class="'.$css_class.'"';
2387: }
2388: if ($rowstyle) {
2389: $css_class .= ' style="'.$rowstyle.'"';
2390: }
1.163 raeburn 2391: my $text;
2392: if ($action eq 'requestcourses') {
2393: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2394: } elsif ($action eq 'requestauthor') {
2395: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2396: } else {
1.224 raeburn 2397: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2398: }
1.224 raeburn 2399: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2400: ' <td>'.$text.'</td>'.
1.102 raeburn 2401: ' <td class="LC_left_item">';
1.191 raeburn 2402: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2403: $action.'notifyapproval',%currapp);
1.191 raeburn 2404: if ($numdc > 0) {
2405: $datatable .= $table;
1.102 raeburn 2406: } else {
2407: $datatable .= &mt('There are no active Domain Coordinators');
2408: }
2409: $datatable .='</td></tr>';
2410: return $datatable;
2411: }
2412:
1.216 raeburn 2413: sub print_studentcode {
2414: my ($settings,$rowtotal) = @_;
2415: my $rownum = 0;
1.218 raeburn 2416: my ($output,%current);
1.325 raeburn 2417: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2418: if (ref($settings) eq 'HASH') {
2419: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2420: foreach my $type (@crstypes) {
2421: $current{$type} = $settings->{'uniquecode'}{$type};
2422: }
1.218 raeburn 2423: }
2424: }
2425: $output .= '<tr>'.
2426: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2427: '<td class="LC_left_item">';
2428: foreach my $type (@crstypes) {
2429: my $check = ' ';
2430: if ($current{$type}) {
2431: $check = ' checked="checked" ';
2432: }
2433: $output .= '<span class="LC_nobreak"><label>'.
2434: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2435: &mt($type).'</label></span>'.(' 'x2).' ';
2436: }
2437: $output .= '</td></tr>';
2438: $$rowtotal ++;
2439: return $output;
1.216 raeburn 2440: }
2441:
2442: sub print_textbookcourses {
1.242 raeburn 2443: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2444: my $rownum = 0;
2445: my $css_class;
2446: my $itemcount = 1;
2447: my $maxnum = 0;
2448: my $bookshash;
2449: if (ref($settings) eq 'HASH') {
1.242 raeburn 2450: $bookshash = $settings->{$type};
1.216 raeburn 2451: }
2452: my %ordered;
2453: if (ref($bookshash) eq 'HASH') {
2454: foreach my $item (keys(%{$bookshash})) {
2455: if (ref($bookshash->{$item}) eq 'HASH') {
2456: my $num = $bookshash->{$item}{'order'};
2457: $ordered{$num} = $item;
2458: }
2459: }
2460: }
2461: my $confname = $dom.'-domainconfig';
2462: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2463: my $maxnum = scalar(keys(%ordered));
2464: my $datatable;
1.216 raeburn 2465: if (keys(%ordered)) {
2466: my @items = sort { $a <=> $b } keys(%ordered);
2467: for (my $i=0; $i<@items; $i++) {
2468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2469: my $key = $ordered{$items[$i]};
2470: my %coursehash=&Apache::lonnet::coursedescription($key);
2471: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2472: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2473: if (ref($bookshash->{$key}) eq 'HASH') {
2474: $subject = $bookshash->{$key}->{'subject'};
2475: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2476: if ($type eq 'textbooks') {
1.243 raeburn 2477: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2478: $author = $bookshash->{$key}->{'author'};
2479: $image = $bookshash->{$key}->{'image'};
2480: if ($image ne '') {
2481: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2482: my $imagethumb = "$path/tn-".$imagefile;
2483: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2484: }
1.216 raeburn 2485: }
2486: }
1.242 raeburn 2487: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2488: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2489: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2490: for (my $k=0; $k<=$maxnum; $k++) {
2491: my $vpos = $k+1;
2492: my $selstr;
2493: if ($k == $i) {
2494: $selstr = ' selected="selected" ';
2495: }
2496: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2497: }
2498: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2499: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2500: &mt('Delete?').'</label></span></td>'.
2501: '<td colspan="2">'.
1.242 raeburn 2502: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2503: (' 'x2).
1.242 raeburn 2504: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2505: if ($type eq 'textbooks') {
2506: $datatable .= (' 'x2).
1.243 raeburn 2507: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2508: (' 'x2).
1.242 raeburn 2509: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2510: (' 'x2).
2511: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2512: if ($image) {
1.267 raeburn 2513: $datatable .= $imgsrc.
1.242 raeburn 2514: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2515: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2516: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2517: }
2518: if ($switchserver) {
2519: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2520: } else {
2521: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2522: }
1.216 raeburn 2523: }
1.242 raeburn 2524: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2525: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2526: $coursetitle.'</span></td></tr>'."\n";
2527: $itemcount ++;
2528: }
2529: }
2530: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2531: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2532: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2533: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2534: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2535: for (my $k=0; $k<$maxnum+1; $k++) {
2536: my $vpos = $k+1;
2537: my $selstr;
2538: if ($k == $maxnum) {
2539: $selstr = ' selected="selected" ';
2540: }
2541: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2542: }
2543: $datatable .= '</select> '."\n".
1.334 raeburn 2544: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2545: '<td colspan="2">'.
1.242 raeburn 2546: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2547: (' 'x2).
1.242 raeburn 2548: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2549: (' 'x2);
2550: if ($type eq 'textbooks') {
1.243 raeburn 2551: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2552: (' 'x2).
2553: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2554: (' 'x2).
2555: '<span class="LC_nobreak">'.&mt('Image:').' ';
2556: if ($switchserver) {
2557: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2558: } else {
2559: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2560: }
1.334 raeburn 2561: $datatable .= '</span>'."\n";
1.216 raeburn 2562: }
1.334 raeburn 2563: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2564: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2565: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2566: &Apache::loncommon::selectcourse_link
1.334 raeburn 2567: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2568: '</span></td>'."\n".
2569: '</tr>'."\n";
2570: $itemcount ++;
2571: return $datatable;
2572: }
2573:
1.217 raeburn 2574: sub textbookcourses_javascript {
1.242 raeburn 2575: my ($settings) = @_;
2576: return unless(ref($settings) eq 'HASH');
2577: my (%ordered,%total,%jstext);
2578: foreach my $type ('textbooks','templates') {
2579: $total{$type} = 0;
2580: if (ref($settings->{$type}) eq 'HASH') {
2581: foreach my $item (keys(%{$settings->{$type}})) {
2582: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2583: my $num = $settings->{$type}->{$item}{'order'};
2584: $ordered{$type}{$num} = $item;
2585: }
2586: }
2587: $total{$type} = scalar(keys(%{$settings->{$type}}));
2588: }
2589: my @jsarray = ();
2590: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2591: push(@jsarray,$ordered{$type}{$item});
2592: }
2593: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2594: }
2595: return <<"ENDSCRIPT";
2596: <script type="text/javascript">
2597: // <![CDATA[
1.242 raeburn 2598: function reorderBooks(form,item,caller) {
1.217 raeburn 2599: var changedVal;
1.242 raeburn 2600: $jstext{'textbooks'};
2601: $jstext{'templates'};
2602: var newpos;
2603: var maxh;
2604: if (caller == 'textbooks') {
2605: newpos = 'textbooks_addbook_pos';
2606: maxh = 1 + $total{'textbooks'};
2607: } else {
2608: newpos = 'templates_addbook_pos';
2609: maxh = 1 + $total{'templates'};
2610: }
1.217 raeburn 2611: var current = new Array;
2612: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2613: if (item == newpos) {
2614: changedVal = newitemVal;
2615: } else {
2616: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2617: current[newitemVal] = newpos;
2618: }
1.242 raeburn 2619: if (caller == 'textbooks') {
2620: for (var i=0; i<textbooks.length; i++) {
2621: var elementName = 'textbooks_'+textbooks[i];
2622: if (elementName != item) {
2623: if (form.elements[elementName]) {
2624: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2625: current[currVal] = elementName;
2626: }
2627: }
2628: }
2629: }
2630: if (caller == 'templates') {
2631: for (var i=0; i<templates.length; i++) {
2632: var elementName = 'templates_'+templates[i];
2633: if (elementName != item) {
2634: if (form.elements[elementName]) {
2635: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2636: current[currVal] = elementName;
2637: }
1.217 raeburn 2638: }
2639: }
2640: }
2641: var oldVal;
2642: for (var j=0; j<maxh; j++) {
2643: if (current[j] == undefined) {
2644: oldVal = j;
2645: }
2646: }
2647: if (oldVal < changedVal) {
2648: for (var k=oldVal+1; k<=changedVal ; k++) {
2649: var elementName = current[k];
2650: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2651: }
2652: } else {
2653: for (var k=changedVal; k<oldVal; k++) {
2654: var elementName = current[k];
2655: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2656: }
2657: }
2658: return;
2659: }
2660:
2661: // ]]>
2662: </script>
2663:
2664: ENDSCRIPT
2665: }
2666:
1.267 raeburn 2667: sub ltitools_javascript {
2668: my ($settings) = @_;
1.319 raeburn 2669: my $togglejs = <itools_toggle_js();
2670: unless (ref($settings) eq 'HASH') {
2671: return $togglejs;
2672: }
1.267 raeburn 2673: my (%ordered,$total,%jstext);
2674: $total = 0;
2675: foreach my $item (keys(%{$settings})) {
2676: if (ref($settings->{$item}) eq 'HASH') {
2677: my $num = $settings->{$item}{'order'};
2678: $ordered{$num} = $item;
2679: }
2680: }
2681: $total = scalar(keys(%{$settings}));
2682: my @jsarray = ();
2683: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2684: push(@jsarray,$ordered{$item});
2685: }
2686: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2687: return <<"ENDSCRIPT";
2688: <script type="text/javascript">
2689: // <![CDATA[
1.319 raeburn 2690: function reorderLTITools(form,item) {
1.267 raeburn 2691: var changedVal;
2692: $jstext
2693: var newpos = 'ltitools_add_pos';
2694: var maxh = 1 + $total;
2695: var current = new Array;
2696: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2697: if (item == newpos) {
2698: changedVal = newitemVal;
2699: } else {
2700: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2701: current[newitemVal] = newpos;
2702: }
2703: for (var i=0; i<ltitools.length; i++) {
2704: var elementName = 'ltitools_'+ltitools[i];
2705: if (elementName != item) {
2706: if (form.elements[elementName]) {
2707: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2708: current[currVal] = elementName;
2709: }
2710: }
2711: }
2712: var oldVal;
2713: for (var j=0; j<maxh; j++) {
2714: if (current[j] == undefined) {
2715: oldVal = j;
2716: }
2717: }
2718: if (oldVal < changedVal) {
2719: for (var k=oldVal+1; k<=changedVal ; k++) {
2720: var elementName = current[k];
2721: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2722: }
2723: } else {
2724: for (var k=changedVal; k<oldVal; k++) {
2725: var elementName = current[k];
2726: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2727: }
2728: }
2729: return;
2730: }
2731:
2732: // ]]>
2733: </script>
2734:
1.319 raeburn 2735: $togglejs
2736:
2737: ENDSCRIPT
2738: }
2739:
2740: sub ltitools_toggle_js {
2741: return <<"ENDSCRIPT";
2742: <script type="text/javascript">
2743: // <![CDATA[
2744:
2745: function toggleLTITools(form,setting,item) {
2746: var radioname = '';
2747: var divid = '';
2748: if ((setting == 'passback') || (setting == 'roster')) {
2749: radioname = 'ltitools_'+setting+'_'+item;
2750: divid = 'ltitools_'+setting+'time_'+item;
2751: var num = form.elements[radioname].length;
2752: if (num) {
2753: var setvis = '';
2754: for (var i=0; i<num; i++) {
2755: if (form.elements[radioname][i].checked) {
2756: if (form.elements[radioname][i].value == '1') {
2757: if (document.getElementById(divid)) {
2758: document.getElementById(divid).style.display = 'inline-block';
2759: }
2760: setvis = 1;
2761: }
2762: break;
2763: }
2764: }
2765: }
2766: if (!setvis) {
2767: if (document.getElementById(divid)) {
2768: document.getElementById(divid).style.display = 'none';
2769: }
2770: }
2771: }
1.324 raeburn 2772: if (setting == 'user') {
2773: divid = 'ltitools_'+setting+'_div_'+item;
2774: var checkid = 'ltitools_'+setting+'_field_'+item;
2775: if (document.getElementById(divid)) {
2776: if (document.getElementById(checkid)) {
2777: if (document.getElementById(checkid).checked) {
2778: document.getElementById(divid).style.display = 'inline-block';
2779: } else {
2780: document.getElementById(divid).style.display = 'none';
2781: }
2782: }
2783: }
2784: }
1.319 raeburn 2785: return;
2786: }
2787: // ]]>
2788: </script>
2789:
1.267 raeburn 2790: ENDSCRIPT
2791: }
2792:
1.320 raeburn 2793: sub lti_javascript {
2794: my ($settings) = @_;
2795: my $togglejs = <i_toggle_js();
2796: unless (ref($settings) eq 'HASH') {
2797: return $togglejs;
2798: }
2799: my (%ordered,$total,%jstext);
2800: $total = 0;
2801: foreach my $item (keys(%{$settings})) {
2802: if (ref($settings->{$item}) eq 'HASH') {
2803: my $num = $settings->{$item}{'order'};
2804: $ordered{$num} = $item;
2805: }
2806: }
2807: $total = scalar(keys(%{$settings}));
2808: my @jsarray = ();
2809: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2810: push(@jsarray,$ordered{$item});
2811: }
2812: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2813: return <<"ENDSCRIPT";
2814: <script type="text/javascript">
2815: // <![CDATA[
2816: function reorderLTI(form,item) {
2817: var changedVal;
2818: $jstext
2819: var newpos = 'lti_pos_add';
2820: var maxh = 1 + $total;
2821: var current = new Array;
2822: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2823: if (item == newpos) {
2824: changedVal = newitemVal;
2825: } else {
2826: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2827: current[newitemVal] = newpos;
2828: }
2829: for (var i=0; i<lti.length; i++) {
2830: var elementName = 'lti_pos_'+lti[i];
2831: if (elementName != item) {
2832: if (form.elements[elementName]) {
2833: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2834: current[currVal] = elementName;
2835: }
2836: }
2837: }
2838: var oldVal;
2839: for (var j=0; j<maxh; j++) {
2840: if (current[j] == undefined) {
2841: oldVal = j;
2842: }
2843: }
2844: if (oldVal < changedVal) {
2845: for (var k=oldVal+1; k<=changedVal ; k++) {
2846: var elementName = current[k];
2847: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2848: }
2849: } else {
2850: for (var k=changedVal; k<oldVal; k++) {
2851: var elementName = current[k];
2852: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2853: }
2854: }
2855: return;
2856: }
2857: // ]]>
2858: </script>
2859:
2860: $togglejs
2861:
2862: ENDSCRIPT
2863: }
2864:
2865: sub lti_toggle_js {
1.325 raeburn 2866: my %lcauthparmtext = &Apache::lonlocal::texthash (
2867: localauth => 'Local auth argument',
2868: krb => 'Kerberos domain',
2869: );
1.320 raeburn 2870: return <<"ENDSCRIPT";
2871: <script type="text/javascript">
2872: // <![CDATA[
2873:
2874: function toggleLTI(form,setting,item) {
1.345 raeburn 2875: if (setting == 'requser') {
2876: var fieldsets = document.getElementsByClassName('ltioption_'+item);
2877: if (fieldsets.length) {
2878: var radioname = 'lti_'+setting+'_'+item;
2879: var num = form.elements[radioname].length;
2880: if (num) {
2881: var setvis = '';
2882: for (var i=0; i<num; i++) {
2883: if (form.elements[radioname][i].checked) {
2884: if (form.elements[radioname][i].value == '1') {
2885: setvis = 1;
2886: break;
2887: }
2888: }
2889: }
1.352 raeburn 2890: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 2891: if (setvis) {
2892: fieldsets[j].style.display = 'block';
2893: } else {
2894: fieldsets[j].style.display = 'none';
2895: }
2896: }
2897: }
2898: }
2899: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2900: var radioname = '';
2901: var divid = '';
2902: if (setting == 'user') {
2903: radioname = 'lti_mapuser_'+item;
2904: divid = 'lti_userfield_'+item;
1.343 raeburn 2905: } else if (setting == 'crs') {
1.320 raeburn 2906: radioname = 'lti_mapcrs_'+item;
2907: divid = 'lti_crsfield_'+item;
1.337 raeburn 2908: } else {
1.351 raeburn 2909: radioname = 'lti_passback_'+item;
1.337 raeburn 2910: divid = 'lti_passback_'+item;
1.320 raeburn 2911: }
2912: var num = form.elements[radioname].length;
2913: if (num) {
2914: var setvis = '';
2915: for (var i=0; i<num; i++) {
2916: if (form.elements[radioname][i].checked) {
1.337 raeburn 2917: if (setting == 'passback') {
2918: if (form.elements[radioname][i].value == '1') {
2919: if (document.getElementById(divid)) {
2920: document.getElementById(divid).style.display = 'inline-block';
2921: }
2922: setvis = 1;
2923: break;
2924: }
2925: } else {
2926: if (form.elements[radioname][i].value == 'other') {
2927: if (document.getElementById(divid)) {
2928: document.getElementById(divid).style.display = 'inline-block';
2929: }
2930: setvis = 1;
2931: break;
1.320 raeburn 2932: }
2933: }
2934: }
2935: }
2936: if (!setvis) {
2937: if (document.getElementById(divid)) {
2938: document.getElementById(divid).style.display = 'none';
2939: }
2940: }
2941: }
2942: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2943: var numsec = form.elements['lti_crssec_'+item].length;
2944: if (numsec) {
2945: var setvis = '';
2946: for (var i=0; i<numsec; i++) {
2947: if (form.elements['lti_crssec_'+item][i].checked) {
2948: if (form.elements['lti_crssec_'+item][i].value == '1') {
2949: if (document.getElementById('lti_crssecfield_'+item)) {
2950: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2951: setvis = 1;
2952: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2953: if (numsrcsec) {
2954: var setsrcvis = '';
2955: for (var j=0; j<numsrcsec; j++) {
2956: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2957: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2958: if (document.getElementById('lti_secsrcfield_'+item)) {
2959: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2960: setsrcvis = 1;
2961: }
2962: }
2963: }
2964: }
2965: if (!setsrcvis) {
2966: if (document.getElementById('lti_secsrcfield_'+item)) {
2967: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2968: }
2969: }
2970: }
2971: }
2972: }
2973: }
2974: }
2975: if (!setvis) {
2976: if (document.getElementById('lti_crssecfield_'+item)) {
2977: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2978: }
2979: if (document.getElementById('lti_secsrcfield_'+item)) {
2980: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2981: }
2982: }
2983: }
1.325 raeburn 2984: } else if (setting == 'lcauth') {
2985: var numauth = form.elements['lti_lcauth_'+item].length;
2986: if (numauth) {
2987: for (var i=0; i<numauth; i++) {
2988: if (form.elements['lti_lcauth_'+item][i].checked) {
2989: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2990: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
2991: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
2992: } else {
2993: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
2994: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
2995: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
2996: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
2997: } else {
2998: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
2999: }
3000: }
3001: }
3002: }
3003: }
3004: }
3005: }
1.326 raeburn 3006: } else if (setting == 'lcmenu') {
3007: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3008: var divid = 'lti_menufield_'+item;
3009: var setvis = '';
3010: for (var i=0; i<menus.length; i++) {
3011: var radioname = menus[i];
3012: var num = form.elements[radioname].length;
3013: if (num) {
3014: for (var j=0; j<num; j++) {
3015: if (form.elements[radioname][j].checked) {
3016: if (form.elements[radioname][j].value == '1') {
3017: if (document.getElementById(divid)) {
3018: document.getElementById(divid).style.display = 'inline-block';
3019: }
3020: setvis = 1;
3021: break;
3022: }
3023: }
3024: }
3025: }
3026: if (setvis == 1) {
3027: break;
3028: }
3029: }
3030: if (!setvis) {
3031: if (document.getElementById(divid)) {
3032: document.getElementById(divid).style.display = 'none';
3033: }
3034: }
1.320 raeburn 3035: }
3036: return;
3037: }
3038: // ]]>
3039: </script>
3040:
3041: ENDSCRIPT
3042: }
3043:
1.3 raeburn 3044: sub print_autoenroll {
1.30 raeburn 3045: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3046: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3047: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3048: if (ref($settings) eq 'HASH') {
3049: if (exists($settings->{'run'})) {
3050: if ($settings->{'run'} eq '0') {
3051: $runoff = ' checked="checked" ';
3052: $runon = ' ';
3053: } else {
3054: $runon = ' checked="checked" ';
3055: $runoff = ' ';
3056: }
3057: } else {
3058: if ($autorun) {
3059: $runon = ' checked="checked" ';
3060: $runoff = ' ';
3061: } else {
3062: $runoff = ' checked="checked" ';
3063: $runon = ' ';
3064: }
3065: }
1.129 raeburn 3066: if (exists($settings->{'co-owners'})) {
3067: if ($settings->{'co-owners'} eq '0') {
3068: $coownersoff = ' checked="checked" ';
3069: $coownerson = ' ';
3070: } else {
3071: $coownerson = ' checked="checked" ';
3072: $coownersoff = ' ';
3073: }
3074: } else {
3075: $coownersoff = ' checked="checked" ';
3076: $coownerson = ' ';
3077: }
1.3 raeburn 3078: if (exists($settings->{'sender_domain'})) {
3079: $defdom = $settings->{'sender_domain'};
3080: }
1.274 raeburn 3081: if (exists($settings->{'autofailsafe'})) {
3082: $failsafe = $settings->{'autofailsafe'};
3083: }
1.14 raeburn 3084: } else {
3085: if ($autorun) {
3086: $runon = ' checked="checked" ';
3087: $runoff = ' ';
3088: } else {
3089: $runoff = ' checked="checked" ';
3090: $runon = ' ';
3091: }
1.3 raeburn 3092: }
3093: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3094: my $notif_sender;
3095: if (ref($settings) eq 'HASH') {
3096: $notif_sender = $settings->{'sender_uname'};
3097: }
1.3 raeburn 3098: my $datatable='<tr class="LC_odd_row">'.
3099: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3100: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3101: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3102: $runon.' value="1" />'.&mt('Yes').'</label> '.
3103: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3104: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3105: '</tr><tr>'.
3106: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3107: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3108: &mt('username').': '.
3109: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3110: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3111: ': '.$domform.'</span></td></tr>'.
3112: '<tr class="LC_odd_row">'.
3113: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3114: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3115: '<input type="radio" name="autoassign_coowners"'.
3116: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3117: '<label><input type="radio" name="autoassign_coowners"'.
3118: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3119: '</tr><tr>'.
3120: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3121: '<td class="LC_right_item"><span class="LC_nobreak">'.
3122: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3123: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3124: $$rowtotal += 4;
1.3 raeburn 3125: return $datatable;
3126: }
3127:
3128: sub print_autoupdate {
1.30 raeburn 3129: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3130: my $datatable;
3131: if ($position eq 'top') {
3132: my $updateon = ' ';
3133: my $updateoff = ' checked="checked" ';
3134: my $classlistson = ' ';
3135: my $classlistsoff = ' checked="checked" ';
3136: if (ref($settings) eq 'HASH') {
3137: if ($settings->{'run'} eq '1') {
3138: $updateon = $updateoff;
3139: $updateoff = ' ';
3140: }
3141: if ($settings->{'classlists'} eq '1') {
3142: $classlistson = $classlistsoff;
3143: $classlistsoff = ' ';
3144: }
3145: }
3146: my %title = (
3147: run => 'Auto-update active?',
3148: classlists => 'Update information in classlists?',
3149: );
3150: $datatable = '<tr class="LC_odd_row">'.
3151: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3152: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3153: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3154: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3155: '<label><input type="radio" name="autoupdate_run"'.
3156: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3157: '</tr><tr>'.
3158: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3159: '<td class="LC_right_item"><span class="LC_nobreak">'.
3160: '<label><input type="radio" name="classlists"'.
3161: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3162: '<label><input type="radio" name="classlists"'.
3163: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3164: '</tr>';
1.30 raeburn 3165: $$rowtotal += 2;
1.131 raeburn 3166: } elsif ($position eq 'middle') {
3167: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3168: my $numinrow = 3;
3169: my $locknamesettings;
3170: $datatable .= &insttypes_row($settings,$types,$usertypes,
3171: $dom,$numinrow,$othertitle,
1.305 raeburn 3172: 'lockablenames',$rowtotal);
1.131 raeburn 3173: $$rowtotal ++;
1.3 raeburn 3174: } else {
1.44 raeburn 3175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3176: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3177: 'permanentemail','id');
1.33 raeburn 3178: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3179: my $numrows = 0;
1.26 raeburn 3180: if (ref($types) eq 'ARRAY') {
3181: if (@{$types} > 0) {
3182: $datatable =
3183: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3184: \@fields,$types,\$numrows);
1.30 raeburn 3185: $$rowtotal += @{$types};
1.26 raeburn 3186: }
1.3 raeburn 3187: }
3188: $datatable .=
3189: &usertype_update_row($settings,{'default' => $othertitle},
3190: \%fieldtitles,\@fields,['default'],
3191: \$numrows);
1.30 raeburn 3192: $$rowtotal ++;
1.3 raeburn 3193: }
3194: return $datatable;
3195: }
3196:
1.125 raeburn 3197: sub print_autocreate {
3198: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3199: my (%createon,%createoff,%currhash);
1.125 raeburn 3200: my @types = ('xml','req');
3201: if (ref($settings) eq 'HASH') {
3202: foreach my $item (@types) {
3203: $createoff{$item} = ' checked="checked" ';
3204: $createon{$item} = ' ';
3205: if (exists($settings->{$item})) {
3206: if ($settings->{$item}) {
3207: $createon{$item} = ' checked="checked" ';
3208: $createoff{$item} = ' ';
3209: }
3210: }
3211: }
1.210 raeburn 3212: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3213: $currhash{$settings->{'xmldc'}} = 1;
3214: }
1.125 raeburn 3215: } else {
3216: foreach my $item (@types) {
3217: $createoff{$item} = ' checked="checked" ';
3218: $createon{$item} = ' ';
3219: }
3220: }
3221: $$rowtotal += 2;
1.191 raeburn 3222: my $numinrow = 2;
1.125 raeburn 3223: my $datatable='<tr class="LC_odd_row">'.
3224: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3225: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3226: '<input type="radio" name="autocreate_xml"'.
3227: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3228: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3229: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3230: '</td></tr><tr>'.
3231: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3232: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3233: '<input type="radio" name="autocreate_req"'.
3234: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3235: '<label><input type="radio" name="autocreate_req"'.
3236: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3237: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3238: 'autocreate_xmldc',%currhash);
1.247 raeburn 3239: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3240: if ($numdc > 1) {
1.247 raeburn 3241: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3242: '</td><td class="LC_left_item">';
1.125 raeburn 3243: } else {
1.247 raeburn 3244: $datatable .= &mt('Course creation processed as:').
3245: '</td><td class="LC_right_item">';
1.125 raeburn 3246: }
1.247 raeburn 3247: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3248: $$rowtotal += $rows;
1.125 raeburn 3249: return $datatable;
3250: }
3251:
1.23 raeburn 3252: sub print_directorysrch {
1.277 raeburn 3253: my ($position,$dom,$settings,$rowtotal) = @_;
3254: my $datatable;
3255: if ($position eq 'top') {
3256: my $instsrchon = ' ';
3257: my $instsrchoff = ' checked="checked" ';
3258: my ($exacton,$containson,$beginson);
3259: my $instlocalon = ' ';
3260: my $instlocaloff = ' checked="checked" ';
3261: if (ref($settings) eq 'HASH') {
3262: if ($settings->{'available'} eq '1') {
3263: $instsrchon = $instsrchoff;
3264: $instsrchoff = ' ';
3265: }
3266: if ($settings->{'localonly'} eq '1') {
3267: $instlocalon = $instlocaloff;
3268: $instlocaloff = ' ';
3269: }
3270: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3271: foreach my $type (@{$settings->{'searchtypes'}}) {
3272: if ($type eq 'exact') {
3273: $exacton = ' checked="checked" ';
3274: } elsif ($type eq 'contains') {
3275: $containson = ' checked="checked" ';
3276: } elsif ($type eq 'begins') {
3277: $beginson = ' checked="checked" ';
3278: }
3279: }
3280: } else {
3281: if ($settings->{'searchtypes'} eq 'exact') {
3282: $exacton = ' checked="checked" ';
3283: } elsif ($settings->{'searchtypes'} eq 'contains') {
3284: $containson = ' checked="checked" ';
3285: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3286: $exacton = ' checked="checked" ';
3287: $containson = ' checked="checked" ';
3288: }
3289: }
1.277 raeburn 3290: }
3291: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3292: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3293:
3294: my $numinrow = 4;
3295: my $cansrchrow = 0;
3296: $datatable='<tr class="LC_odd_row">'.
3297: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3298: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3299: '<input type="radio" name="dirsrch_available"'.
3300: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3301: '<label><input type="radio" name="dirsrch_available"'.
3302: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3303: '</tr><tr>'.
3304: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3305: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3306: '<input type="radio" name="dirsrch_instlocalonly"'.
3307: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3308: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3309: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3310: '</tr>';
3311: $$rowtotal += 2;
3312: if (ref($usertypes) eq 'HASH') {
3313: if (keys(%{$usertypes}) > 0) {
3314: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3315: $numinrow,$othertitle,'cansearch',
3316: $rowtotal);
1.277 raeburn 3317: $cansrchrow = 1;
1.25 raeburn 3318: }
1.23 raeburn 3319: }
1.277 raeburn 3320: if ($cansrchrow) {
3321: $$rowtotal ++;
3322: $datatable .= '<tr>';
3323: } else {
3324: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3325: }
1.277 raeburn 3326: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3327: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3328: foreach my $title (@{$titleorder}) {
3329: if (defined($searchtitles->{$title})) {
3330: my $check = ' ';
3331: if (ref($settings) eq 'HASH') {
3332: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3333: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3334: $check = ' checked="checked" ';
3335: }
1.39 raeburn 3336: }
1.25 raeburn 3337: }
1.277 raeburn 3338: $datatable .= '<td class="LC_left_item">'.
3339: '<span class="LC_nobreak"><label>'.
3340: '<input type="checkbox" name="searchby" '.
3341: 'value="'.$title.'"'.$check.'/>'.
3342: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3343: }
3344: }
1.277 raeburn 3345: $datatable .= '</tr></table></td></tr>';
3346: $$rowtotal ++;
3347: if ($cansrchrow) {
3348: $datatable .= '<tr class="LC_odd_row">';
3349: } else {
3350: $datatable .= '<tr>';
3351: }
3352: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3353: '<td class="LC_left_item" colspan="2">'.
3354: '<span class="LC_nobreak"><label>'.
3355: '<input type="checkbox" name="searchtypes" '.
3356: $exacton.' value="exact" />'.&mt('Exact match').
3357: '</label> '.
3358: '<label><input type="checkbox" name="searchtypes" '.
3359: $beginson.' value="begins" />'.&mt('Begins with').
3360: '</label> '.
3361: '<label><input type="checkbox" name="searchtypes" '.
3362: $containson.' value="contains" />'.&mt('Contains').
3363: '</label></span></td></tr>';
3364: $$rowtotal ++;
1.26 raeburn 3365: } else {
1.277 raeburn 3366: my $domsrchon = ' checked="checked" ';
3367: my $domsrchoff = ' ';
3368: my $domlocalon = ' ';
3369: my $domlocaloff = ' checked="checked" ';
3370: if (ref($settings) eq 'HASH') {
3371: if ($settings->{'lclocalonly'} eq '1') {
3372: $domlocalon = $domlocaloff;
3373: $domlocaloff = ' ';
3374: }
3375: if ($settings->{'lcavailable'} eq '0') {
3376: $domsrchoff = $domsrchon;
3377: $domsrchon = ' ';
3378: }
3379: }
3380: $datatable='<tr class="LC_odd_row">'.
3381: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3382: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3383: '<input type="radio" name="dirsrch_domavailable"'.
3384: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3385: '<label><input type="radio" name="dirsrch_domavailable"'.
3386: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3387: '</tr><tr>'.
3388: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3389: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3390: '<input type="radio" name="dirsrch_domlocalonly"'.
3391: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3392: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3393: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3394: '</tr>';
3395: $$rowtotal += 2;
1.26 raeburn 3396: }
1.25 raeburn 3397: return $datatable;
3398: }
3399:
1.28 raeburn 3400: sub print_contacts {
1.286 raeburn 3401: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3402: my $datatable;
3403: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3404: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3405: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3406: if ($position eq 'top') {
3407: if (ref($settings) eq 'HASH') {
3408: foreach my $item (@contacts) {
3409: if (exists($settings->{$item})) {
3410: $to{$item} = $settings->{$item};
3411: }
3412: }
3413: }
3414: } elsif ($position eq 'middle') {
3415: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3416: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3417: foreach my $type (@mailings) {
3418: $otheremails{$type} = '';
3419: }
1.340 raeburn 3420: } elsif ($position eq 'lower') {
3421: if (ref($settings) eq 'HASH') {
3422: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3423: %lonstatus = %{$settings->{'lonstatus'}};
3424: }
3425: }
1.286 raeburn 3426: } else {
3427: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3428: foreach my $type (@mailings) {
3429: $otheremails{$type} = '';
3430: }
1.286 raeburn 3431: $bccemails{'helpdeskmail'} = '';
3432: $bccemails{'otherdomsmail'} = '';
3433: $includestr{'helpdeskmail'} = '';
3434: $includestr{'otherdomsmail'} = '';
3435: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3436: }
1.28 raeburn 3437: if (ref($settings) eq 'HASH') {
1.340 raeburn 3438: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3439: foreach my $type (@mailings) {
3440: if (exists($settings->{$type})) {
3441: if (ref($settings->{$type}) eq 'HASH') {
3442: foreach my $item (@contacts) {
3443: if ($settings->{$type}{$item}) {
3444: $checked{$type}{$item} = ' checked="checked" ';
3445: }
3446: }
3447: $otheremails{$type} = $settings->{$type}{'others'};
3448: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3449: $bccemails{$type} = $settings->{$type}{'bcc'};
3450: if ($settings->{$type}{'include'} ne '') {
3451: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3452: $includestr{$type} = &unescape($includestr{$type});
3453: }
3454: }
3455: }
3456: } elsif ($type eq 'lonstatusmail') {
3457: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3458: }
1.28 raeburn 3459: }
3460: }
1.286 raeburn 3461: if ($position eq 'bottom') {
3462: foreach my $type (@mailings) {
3463: $bccemails{$type} = $settings->{$type}{'bcc'};
3464: if ($settings->{$type}{'include'} ne '') {
3465: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3466: $includestr{$type} = &unescape($includestr{$type});
3467: }
3468: }
3469: if (ref($settings->{'helpform'}) eq 'HASH') {
3470: if (ref($fields) eq 'ARRAY') {
3471: foreach my $field (@{$fields}) {
3472: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3473: }
1.286 raeburn 3474: }
3475: if (exists($settings->{'helpform'}{'maxsize'})) {
3476: $maxsize = $settings->{'helpform'}{'maxsize'};
3477: } else {
1.289 raeburn 3478: $maxsize = '1.0';
1.286 raeburn 3479: }
3480: } else {
3481: if (ref($fields) eq 'ARRAY') {
3482: foreach my $field (@{$fields}) {
3483: $currfield{$field} = 'yes';
1.134 raeburn 3484: }
1.28 raeburn 3485: }
1.286 raeburn 3486: $maxsize = '1.0';
1.28 raeburn 3487: }
3488: }
3489: } else {
1.286 raeburn 3490: if ($position eq 'top') {
3491: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3492: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3493: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3494: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3495: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3496: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3497: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3498: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3499: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3500: } elsif ($position eq 'bottom') {
3501: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3502: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3503: if (ref($fields) eq 'ARRAY') {
3504: foreach my $field (@{$fields}) {
3505: $currfield{$field} = 'yes';
3506: }
3507: }
3508: $maxsize = '1.0';
3509: }
1.28 raeburn 3510: }
3511: my ($titles,$short_titles) = &contact_titles();
3512: my $rownum = 0;
3513: my $css_class;
1.286 raeburn 3514: if ($position eq 'top') {
3515: foreach my $item (@contacts) {
3516: $css_class = $rownum%2?' class="LC_odd_row"':'';
3517: $datatable .= '<tr'.$css_class.'>'.
3518: '<td><span class="LC_nobreak">'.$titles->{$item}.
3519: '</span></td><td class="LC_right_item">'.
3520: '<input type="text" name="'.$item.'" value="'.
3521: $to{$item}.'" /></td></tr>';
3522: $rownum ++;
3523: }
1.315 raeburn 3524: } elsif ($position eq 'bottom') {
3525: $css_class = $rownum%2?' class="LC_odd_row"':'';
3526: $datatable .= '<tr'.$css_class.'>'.
3527: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3528: &mt('(e-mail, subject, and description always shown)').
3529: '</td><td class="LC_left_item">';
3530: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3531: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3532: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3533: foreach my $field (@{$fields}) {
3534: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3535: if (($field eq 'screenshot') || ($field eq 'cc')) {
3536: $datatable .= ' '.&mt('(logged-in users)');
3537: }
3538: $datatable .='</td><td>';
3539: my $clickaction;
3540: if ($field eq 'screenshot') {
3541: $clickaction = ' onclick="screenshotSize(this);"';
3542: }
3543: if (ref($possoptions->{$field}) eq 'ARRAY') {
3544: foreach my $option (@{$possoptions->{$field}}) {
3545: my $checked;
3546: if ($currfield{$field} eq $option) {
3547: $checked = ' checked="checked"';
3548: }
3549: $datatable .= '<span class="LC_nobreak"><label>'.
3550: '<input type="radio" name="helpform_'.$field.'" '.
3551: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3552: '</label></span>'.(' 'x2);
3553: }
3554: }
3555: if ($field eq 'screenshot') {
3556: my $display;
3557: if ($currfield{$field} eq 'no') {
3558: $display = ' style="display:none"';
3559: }
1.334 raeburn 3560: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3561: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3562: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3563: }
3564: $datatable .= '</td></tr>';
3565: }
3566: $datatable .= '</table>';
3567: }
3568: $datatable .= '</td></tr>'."\n";
3569: $rownum ++;
3570: }
1.340 raeburn 3571: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3572: foreach my $type (@mailings) {
3573: $css_class = $rownum%2?' class="LC_odd_row"':'';
3574: $datatable .= '<tr'.$css_class.'>'.
3575: '<td><span class="LC_nobreak">'.
3576: $titles->{$type}.': </span></td>'.
3577: '<td class="LC_left_item">';
3578: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3579: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3580: }
3581: $datatable .= '<span class="LC_nobreak">';
3582: foreach my $item (@contacts) {
3583: $datatable .= '<label>'.
3584: '<input type="checkbox" name="'.$type.'"'.
3585: $checked{$type}{$item}.
3586: ' value="'.$item.'" />'.$short_titles->{$item}.
3587: '</label> ';
3588: }
3589: $datatable .= '</span><br />'.&mt('Others').': '.
3590: '<input type="text" name="'.$type.'_others" '.
3591: 'value="'.$otheremails{$type}.'" />';
3592: my %locchecked;
3593: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3594: foreach my $loc ('s','b') {
3595: if ($includeloc{$type} eq $loc) {
3596: $locchecked{$loc} = ' checked="checked"';
3597: last;
3598: }
3599: }
3600: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3601: '<input type="text" name="'.$type.'_bcc" '.
3602: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3603: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3604: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3605: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3606: '<span class="LC_nobreak">'.&mt('Location:').' '.
3607: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3608: (' 'x2).
3609: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3610: '</span></fieldset>';
3611: }
3612: $datatable .= '</td></tr>'."\n";
3613: $rownum ++;
3614: }
1.28 raeburn 3615: }
1.286 raeburn 3616: if ($position eq 'middle') {
3617: my %choices;
1.340 raeburn 3618: my $corelink = &core_link_msu();
3619: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3620: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3621: $corelink);
3622: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3623: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3624: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3625: 'reportupdates' => 'on',
3626: 'reportstatus' => 'on');
1.286 raeburn 3627: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3628: \%choices,$rownum);
3629: $datatable .= $reports;
1.340 raeburn 3630: } elsif ($position eq 'lower') {
3631: $css_class = $rownum%2?' class="LC_odd_row"':'';
3632: my ($threshold,$sysmail,%excluded,%weights);
3633: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3634: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3635: $threshold = $lonstatus{'threshold'};
3636: } else {
3637: $threshold = $defaults->{'threshold'};
3638: }
3639: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3640: $sysmail = $lonstatus{'sysmail'};
3641: } else {
3642: $sysmail = $defaults->{'sysmail'};
3643: }
3644: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3645: foreach my $type ('E','W','N','U') {
1.340 raeburn 3646: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3647: $weights{$type} = $lonstatus{'weights'}{$type};
3648: } else {
3649: $weights{$type} = $defaults->{$type};
3650: }
3651: }
3652: } else {
1.341 raeburn 3653: foreach my $type ('E','W','N','U') {
1.340 raeburn 3654: $weights{$type} = $defaults->{$type};
3655: }
3656: }
3657: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3658: if (@{$lonstatus{'excluded'}} > 0) {
3659: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3660: }
3661: }
3662: $datatable .= '<tr'.$css_class.'>'.
3663: '<td class="LC_left_item"><span class="LC_nobreak">'.
3664: $titles->{'errorthreshold'}.
3665: '</span></td><td class="LC_left_item">'.
3666: '<input type="text" name="errorthreshold" value="'.
3667: $threshold.'" size="5" /></td></tr>';
3668: $rownum ++;
3669: $css_class = $rownum%2?' class="LC_odd_row"':'';
3670: $datatable .= '<tr'.$css_class.'>'.
3671: '<td class="LC_left_item">'.
3672: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3673: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3674: foreach my $type ('E','W','N','U') {
1.340 raeburn 3675: $datatable .= '<td>'.$names->{$type}.'<br />'.
3676: '<input type="text" name="errorweights_'.$type.'" value="'.
3677: $weights{$type}.'" size="5" /></td>';
3678: }
3679: $datatable .= '</tr></table></tr>';
3680: $rownum ++;
3681: $css_class = $rownum%2?' class="LC_odd_row"':'';
3682: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3683: $titles->{'errorexcluded'}.'</td>'.
3684: '<td class="LC_left_item"><table>';
3685: my $numinrow = 4;
3686: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3687: for (my $i=0; $i<@ids; $i++) {
3688: my $rem = $i%($numinrow);
3689: if ($rem == 0) {
3690: if ($i > 0) {
3691: $datatable .= '</tr>';
3692: }
3693: $datatable .= '<tr>';
3694: }
3695: my $check;
3696: if ($excluded{$ids[$i]}) {
3697: $check = ' checked="checked" ';
3698: }
3699: $datatable .= '<td class="LC_left_item">'.
3700: '<span class="LC_nobreak"><label>'.
3701: '<input type="checkbox" name="errorexcluded" '.
3702: 'value="'.$ids[$i].'"'.$check.' />'.
3703: $ids[$i].'</label></span></td>';
3704: }
3705: my $colsleft = $numinrow - @ids%($numinrow);
3706: if ($colsleft > 1 ) {
3707: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3708: ' </td>';
3709: } elsif ($colsleft == 1) {
3710: $datatable .= '<td class="LC_left_item"> </td>';
3711: }
3712: $datatable .= '</tr></table></td></tr>';
3713: $rownum ++;
3714: $css_class = $rownum%2?' class="LC_odd_row"':'';
3715: $datatable .= '<tr'.$css_class.'>'.
3716: '<td class="LC_left_item"><span class="LC_nobreak">'.
3717: $titles->{'errorsysmail'}.
3718: '</span></td><td class="LC_left_item">'.
3719: '<input type="text" name="errorsysmail" value="'.
3720: $sysmail.'" size="5" /></td></tr>';
3721: $rownum ++;
1.286 raeburn 3722: } elsif ($position eq 'bottom') {
1.315 raeburn 3723: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3724: my (@posstypes,%usertypeshash);
3725: if (ref($types) eq 'ARRAY') {
3726: @posstypes = @{$types};
3727: }
3728: if (@posstypes) {
3729: if (ref($usertypes) eq 'HASH') {
3730: %usertypeshash = %{$usertypes};
3731: }
3732: my @overridden;
3733: my $numinrow = 4;
3734: if (ref($settings) eq 'HASH') {
3735: if (ref($settings->{'overrides'}) eq 'HASH') {
3736: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3737: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3738: push(@overridden,$key);
3739: foreach my $item (@contacts) {
3740: if ($settings->{'overrides'}{$key}{$item}) {
3741: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3742: }
3743: }
3744: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3745: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3746: $includeloc{'override_'.$key} = '';
3747: $includestr{'override_'.$key} = '';
3748: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3749: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3750: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3751: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3752: }
1.286 raeburn 3753: }
3754: }
3755: }
1.315 raeburn 3756: }
3757: my $customclass = 'LC_helpdesk_override';
3758: my $optionsprefix = 'LC_options_helpdesk_';
3759:
3760: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3761:
3762: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3763: $numinrow,$othertitle,'overrides',
3764: \$rownum,$onclicktypes,$customclass);
3765: $rownum ++;
3766: $usertypeshash{'default'} = $othertitle;
3767: foreach my $status (@posstypes) {
3768: my $css_class;
3769: if ($rownum%2) {
3770: $css_class = 'LC_odd_row ';
3771: }
3772: $css_class .= $customclass;
3773: my $rowid = $optionsprefix.$status;
3774: my $hidden = 1;
3775: my $currstyle = 'display:none';
3776: if (grep(/^\Q$status\E$/,@overridden)) {
3777: $currstyle = 'display:table-row';
3778: $hidden = 0;
3779: }
3780: my $key = 'override_'.$status;
3781: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3782: $includeloc{$key},$includestr{$key},$status,$rowid,
3783: $usertypeshash{$status},$css_class,$currstyle,
3784: \@contacts,$short_titles);
3785: unless ($hidden) {
3786: $rownum ++;
1.286 raeburn 3787: }
3788: }
1.134 raeburn 3789: }
1.28 raeburn 3790: }
1.30 raeburn 3791: $$rowtotal += $rownum;
1.28 raeburn 3792: return $datatable;
3793: }
3794:
1.340 raeburn 3795: sub core_link_msu {
3796: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3797: &mt('LON-CAPA core group - MSU'),600,500);
3798: }
3799:
1.315 raeburn 3800: sub overridden_helpdesk {
3801: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3802: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3803: my $class = 'LC_left_item';
3804: if ($css_class) {
3805: $css_class = ' class="'.$css_class.'"';
3806: }
3807: if ($rowid) {
3808: $rowid = ' id="'.$rowid.'"';
3809: }
3810: if ($rowstyle) {
3811: $rowstyle = ' style="'.$rowstyle.'"';
3812: }
3813: my ($output,$description);
3814: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3815: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3816: "<td>$description</td>\n".
3817: '<td class="'.$class.'" colspan="2">'.
3818: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3819: '<span class="LC_nobreak">';
3820: if (ref($contacts) eq 'ARRAY') {
3821: foreach my $item (@{$contacts}) {
3822: my $check;
3823: if (ref($checked) eq 'HASH') {
3824: $check = $checked->{$item};
3825: }
3826: my $title;
3827: if (ref($short_titles) eq 'HASH') {
3828: $title = $short_titles->{$item};
3829: }
3830: $output .= '<label>'.
3831: '<input type="checkbox" name="override_'.$type.'"'.$check.
3832: ' value="'.$item.'" />'.$title.'</label> ';
3833: }
3834: }
3835: $output .= '</span><br />'.&mt('Others').': '.
3836: '<input type="text" name="override_'.$type.'_others" '.
3837: 'value="'.$otheremails.'" />';
3838: my %locchecked;
3839: foreach my $loc ('s','b') {
3840: if ($includeloc eq $loc) {
3841: $locchecked{$loc} = ' checked="checked"';
3842: last;
3843: }
3844: }
3845: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3846: '<input type="text" name="override_'.$type.'_bcc" '.
3847: 'value="'.$bccemails.'" /></fieldset>'.
3848: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3849: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3850: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3851: '<span class="LC_nobreak">'.&mt('Location:').' '.
3852: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3853: (' 'x2).
3854: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3855: '</span></fieldset>'.
3856: '</td></tr>'."\n";
3857: return $output;
3858: }
3859:
1.286 raeburn 3860: sub contacts_javascript {
3861: return <<"ENDSCRIPT";
3862:
3863: <script type="text/javascript">
3864: // <![CDATA[
3865:
3866: function screenshotSize(field) {
3867: if (document.getElementById('help_screenshotsize')) {
3868: if (field.value == 'no') {
1.289 raeburn 3869: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3870: } else {
3871: document.getElementById('help_screenshotsize').style.display="";
3872: }
3873: }
3874: return;
3875: }
3876:
1.315 raeburn 3877: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3878: if (form.elements[checkbox].length != undefined) {
3879: var count = 0;
3880: if (docount) {
3881: for (var i=0; i<form.elements[checkbox].length; i++) {
3882: if (form.elements[checkbox][i].checked) {
3883: count ++;
3884: }
3885: }
3886: }
3887: for (var i=0; i<form.elements[checkbox].length; i++) {
3888: var type = form.elements[checkbox][i].value;
3889: if (document.getElementById(prefix+type)) {
3890: if (form.elements[checkbox][i].checked) {
3891: document.getElementById(prefix+type).style.display = 'table-row';
3892: if (count % 2 == 1) {
3893: document.getElementById(prefix+type).className = target+' LC_odd_row';
3894: } else {
3895: document.getElementById(prefix+type).className = target;
3896: }
3897: count ++;
3898: } else {
3899: document.getElementById(prefix+type).style.display = 'none';
3900: }
3901: }
3902: }
3903: }
3904: return;
3905: }
3906:
3907:
1.286 raeburn 3908: // ]]>
3909: </script>
3910:
3911: ENDSCRIPT
3912: }
3913:
1.118 jms 3914: sub print_helpsettings {
1.282 raeburn 3915: my ($position,$dom,$settings,$rowtotal) = @_;
3916: my $confname = $dom.'-domainconfig';
1.285 raeburn 3917: my $formname = 'display';
1.168 raeburn 3918: my ($datatable,$itemcount);
1.282 raeburn 3919: if ($position eq 'top') {
3920: $itemcount = 1;
3921: my (%choices,%defaultchecked,@toggles);
3922: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3924: &mt('LON-CAPA bug tracker'),600,500));
3925: %defaultchecked = ('submitbugs' => 'on');
3926: @toggles = ('submitbugs');
3927: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3928: \%choices,$itemcount);
3929: $$rowtotal ++;
3930: } else {
3931: my $css_class;
3932: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3933: my (%customroles,%ordered,%current);
1.301 raeburn 3934: if (ref($settings) eq 'HASH') {
3935: if (ref($settings->{'adhoc'}) eq 'HASH') {
3936: %current = %{$settings->{'adhoc'}};
3937: }
1.285 raeburn 3938: }
3939: my $count = 0;
3940: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3941: if ($key=~/^rolesdef\_(\w+)$/) {
3942: my $rolename = $1;
1.285 raeburn 3943: my (%privs,$order);
1.282 raeburn 3944: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3945: $customroles{$rolename} = \%privs;
1.285 raeburn 3946: if (ref($current{$rolename}) eq 'HASH') {
3947: $order = $current{$rolename}{'order'};
3948: }
3949: if ($order eq '') {
3950: $order = $count;
3951: }
3952: $ordered{$order} = $rolename;
3953: $count++;
3954: }
3955: }
3956: my $maxnum = scalar(keys(%ordered));
3957: my @roles_by_num = ();
3958: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3959: push(@roles_by_num,$item);
3960: }
3961: my $context = 'domprefs';
3962: my $crstype = 'Course';
3963: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3964: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3965: my ($numstatustypes,@jsarray);
3966: if (ref($types) eq 'ARRAY') {
3967: if (@{$types} > 0) {
3968: $numstatustypes = scalar(@{$types});
3969: push(@accesstypes,'status');
3970: @jsarray = ('bystatus');
1.282 raeburn 3971: }
3972: }
1.290 raeburn 3973: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3974: if (keys(%domhelpdesk)) {
3975: push(@accesstypes,('inc','exc'));
3976: push(@jsarray,('notinc','notexc'));
3977: }
3978: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3979: my $context = 'domprefs';
3980: my $crstype = 'Course';
1.285 raeburn 3981: my $prefix = 'helproles_';
3982: my $add_class = 'LC_hidden';
3983: foreach my $num (@roles_by_num) {
3984: my $role = $ordered{$num};
3985: my ($desc,$access,@statuses);
3986: if (ref($current{$role}) eq 'HASH') {
3987: $desc = $current{$role}{'desc'};
3988: $access = $current{$role}{'access'};
3989: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3990: @statuses = @{$current{$role}{'insttypes'}};
3991: }
3992: }
3993: if ($desc eq '') {
3994: $desc = $role;
3995: }
3996: my $identifier = 'custhelp'.$num;
1.282 raeburn 3997: my %full=();
3998: my %levels= (
3999: course => {},
4000: domain => {},
4001: system => {},
4002: );
4003: my %levelscurrent=(
4004: course => {},
4005: domain => {},
4006: system => {},
4007: );
4008: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4009: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4011: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4012: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4013: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4014: for (my $k=0; $k<=$maxnum; $k++) {
4015: my $vpos = $k+1;
4016: my $selstr;
4017: if ($k == $num) {
4018: $selstr = ' selected="selected" ';
4019: }
4020: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4021: }
4022: $datatable .= '</select>'.(' 'x2).
4023: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4024: '</td>'.
4025: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4026: &mt('Name shown to users:').
4027: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4028: '</fieldset>'.
4029: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4030: $othertitle,$usertypes,$types,\%domhelpdesk).
4031: '<fieldset>'.
4032: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4033: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4034: \%levelscurrent,$identifier,
4035: 'LC_hidden',$prefix.$num.'_privs').
4036: '</fieldset></td>';
1.282 raeburn 4037: $itemcount ++;
4038: }
4039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4040: my $newcust = 'custhelp'.$count;
4041: my (%privs,%levelscurrent);
4042: my %full=();
4043: my %levels= (
4044: course => {},
4045: domain => {},
4046: system => {},
4047: );
4048: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4049: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4050: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4051: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4052: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4053: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4054: for (my $k=0; $k<$maxnum+1; $k++) {
4055: my $vpos = $k+1;
4056: my $selstr;
4057: if ($k == $maxnum) {
4058: $selstr = ' selected="selected" ';
4059: }
4060: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4061: }
4062: $datatable .= '</select> '."\n".
1.282 raeburn 4063: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4064: '</label></span></td>'.
1.285 raeburn 4065: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4066: '<span class="LC_nobreak">'.
4067: &mt('Internal name:').
4068: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4069: '</span>'.(' 'x4).
4070: '<span class="LC_nobreak">'.
4071: &mt('Name shown to users:').
4072: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4073: '</span></fieldset>'.
4074: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4075: $usertypes,$types,\%domhelpdesk).
4076: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4077: &Apache::lonuserutils::custom_role_header($context,$crstype,
4078: \@templateroles,$newcust).
4079: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4080: \%levelscurrent,$newcust).
1.334 raeburn 4081: '</fieldset>'.
4082: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4083: '</td></tr>';
1.282 raeburn 4084: $count ++;
4085: $$rowtotal += $count;
4086: }
1.166 raeburn 4087: return $datatable;
1.121 raeburn 4088: }
4089:
1.285 raeburn 4090: sub adhocbutton {
4091: my ($prefix,$num,$field,$visibility) = @_;
4092: my %lt = &Apache::lonlocal::texthash(
4093: show => 'Show details',
4094: hide => 'Hide details',
4095: );
4096: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4097: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4098: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4099: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4100: }
4101:
4102: sub helpsettings_javascript {
4103: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4104: return unless(ref($roles_by_num) eq 'ARRAY');
4105: my %html_js_lt = &Apache::lonlocal::texthash(
4106: show => 'Show details',
4107: hide => 'Hide details',
4108: );
4109: &html_escape(\%html_js_lt);
4110: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4111: return <<"ENDSCRIPT";
4112: <script type="text/javascript">
4113: // <![CDATA[
4114:
4115: function reorderHelpRoles(form,item) {
4116: var changedVal;
4117: $jstext
4118: var newpos = 'helproles_${total}_pos';
4119: var maxh = 1 + $total;
4120: var current = new Array();
4121: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4122: if (item == newpos) {
4123: changedVal = newitemVal;
4124: } else {
4125: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4126: current[newitemVal] = newpos;
4127: }
4128: for (var i=0; i<helproles.length; i++) {
4129: var elementName = 'helproles_'+helproles[i]+'_pos';
4130: if (elementName != item) {
4131: if (form.elements[elementName]) {
4132: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4133: current[currVal] = elementName;
4134: }
4135: }
4136: }
4137: var oldVal;
4138: for (var j=0; j<maxh; j++) {
4139: if (current[j] == undefined) {
4140: oldVal = j;
4141: }
4142: }
4143: if (oldVal < changedVal) {
4144: for (var k=oldVal+1; k<=changedVal ; k++) {
4145: var elementName = current[k];
4146: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4147: }
4148: } else {
4149: for (var k=changedVal; k<oldVal; k++) {
4150: var elementName = current[k];
4151: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4152: }
4153: }
4154: return;
4155: }
4156:
4157: function helpdeskAccess(num) {
4158: var curraccess = null;
4159: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4160: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4161: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4162: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4163: }
4164: }
4165: }
4166: var shown = Array();
4167: var hidden = Array();
4168: if (curraccess == 'none') {
4169: hidden = Array('$hiddenstr');
4170: } else {
4171: if (curraccess == 'status') {
4172: shown = Array('bystatus');
4173: hidden = Array('notinc','notexc');
4174: } else {
4175: if (curraccess == 'exc') {
4176: shown = Array('notexc');
4177: hidden = Array('notinc','bystatus');
4178: }
4179: if (curraccess == 'inc') {
4180: shown = Array('notinc');
4181: hidden = Array('notexc','bystatus');
4182: }
1.293 raeburn 4183: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4184: hidden = Array('notinc','notexc','bystatus');
4185: }
4186: }
4187: }
4188: if (hidden.length > 0) {
4189: for (var i=0; i<hidden.length; i++) {
4190: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4191: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4192: }
4193: }
4194: }
4195: if (shown.length > 0) {
4196: for (var i=0; i<shown.length; i++) {
4197: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4198: if (shown[i] == 'privs') {
4199: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4200: } else {
4201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4202: }
4203: }
4204: }
4205: }
4206: return;
4207: }
4208:
4209: function toggleHelpdeskItem(num,field) {
4210: if (document.getElementById('helproles_'+num+'_'+field)) {
4211: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4212: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4213: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4214: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4215: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4216: }
4217: } else {
4218: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4219: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4220: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4221: }
4222: }
4223: }
4224: return;
4225: }
4226:
4227: // ]]>
4228: </script>
4229:
4230: ENDSCRIPT
4231: }
4232:
4233: sub helpdeskroles_access {
4234: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4235: $usertypes,$types,$domhelpdesk) = @_;
4236: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4237: my %lt = &Apache::lonlocal::texthash(
4238: 'rou' => 'Role usage',
4239: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4240: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4241: 'dh' => 'All with domain helpdesk role',
4242: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4243: 'none' => 'None',
4244: 'status' => 'Determined based on institutional status',
4245: 'inc' => 'Include all, but exclude specific personnel',
4246: 'exc' => 'Exclude all, but include specific personnel',
4247: );
4248: my %usecheck = (
4249: all => ' checked="checked"',
4250: );
4251: my %displaydiv = (
4252: status => 'none',
4253: inc => 'none',
4254: exc => 'none',
4255: priv => 'block',
4256: );
4257: my $output;
4258: if (ref($current) eq 'HASH') {
4259: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4260: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4261: $usecheck{$current->{access}} = $usecheck{'all'};
4262: delete($usecheck{'all'});
4263: if ($current->{access} =~ /^(status|inc|exc)$/) {
4264: my $access = $1;
4265: $displaydiv{$access} = 'inline';
4266: } elsif ($current->{access} eq 'none') {
4267: $displaydiv{'priv'} = 'none';
4268: }
4269: }
4270: }
4271: }
4272: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4273: '<p>'.$lt{'whi'}.'</p>';
4274: foreach my $access (@{$accesstypes}) {
4275: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4276: ' onclick="helpdeskAccess('."'$num'".');" />'.
4277: $lt{$access}.'</label>';
4278: if ($access eq 'status') {
4279: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4280: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4281: $othertitle,$usertypes,$types).
4282: '</div>';
4283: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4284: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4285: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4286: '</div>';
4287: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4288: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4289: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4290: '</div>';
4291: }
4292: $output .= '</p>';
4293: }
4294: $output .= '</fieldset>';
4295: return $output;
4296: }
4297:
1.121 raeburn 4298: sub radiobutton_prefs {
1.192 raeburn 4299: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4300: $additional,$align) = @_;
1.121 raeburn 4301: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4302: (ref($choices) eq 'HASH'));
4303:
1.170 raeburn 4304: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4305:
4306: foreach my $item (@{$toggles}) {
4307: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4308: $checkedon{$item} = ' checked="checked" ';
4309: $checkedoff{$item} = ' ';
1.121 raeburn 4310: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4311: $checkedoff{$item} = ' checked="checked" ';
4312: $checkedon{$item} = ' ';
4313: }
4314: }
4315: if (ref($settings) eq 'HASH') {
1.121 raeburn 4316: foreach my $item (@{$toggles}) {
1.118 jms 4317: if ($settings->{$item} eq '1') {
4318: $checkedon{$item} = ' checked="checked" ';
4319: $checkedoff{$item} = ' ';
4320: } elsif ($settings->{$item} eq '0') {
4321: $checkedoff{$item} = ' checked="checked" ';
4322: $checkedon{$item} = ' ';
4323: }
4324: }
1.121 raeburn 4325: }
1.192 raeburn 4326: if ($onclick) {
4327: $onclick = ' onclick="'.$onclick.'"';
4328: }
1.121 raeburn 4329: foreach my $item (@{$toggles}) {
1.118 jms 4330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4331: $datatable .=
1.306 raeburn 4332: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4333: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4334: '</span></td>';
4335: if ($align eq 'left') {
4336: $datatable .= '<td class="LC_left_item">';
4337: } else {
4338: $datatable .= '<td class="LC_right_item">';
4339: }
1.289 raeburn 4340: $datatable .=
1.257 raeburn 4341: '<span class="LC_nobreak">'.
1.118 jms 4342: '<label><input type="radio" name="'.
1.192 raeburn 4343: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4344: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4345: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4346: '</span>'.$additional.
4347: '</td>'.
1.118 jms 4348: '</tr>';
4349: $itemcount ++;
1.121 raeburn 4350: }
4351: return ($datatable,$itemcount);
4352: }
4353:
1.267 raeburn 4354: sub print_ltitools {
4355: my ($dom,$settings,$rowtotal) = @_;
4356: my $rownum = 0;
4357: my $css_class;
4358: my $itemcount = 1;
4359: my $maxnum = 0;
4360: my %ordered;
4361: if (ref($settings) eq 'HASH') {
4362: foreach my $item (keys(%{$settings})) {
4363: if (ref($settings->{$item}) eq 'HASH') {
4364: my $num = $settings->{$item}{'order'};
4365: $ordered{$num} = $item;
4366: }
4367: }
4368: }
4369: my $confname = $dom.'-domainconfig';
4370: my $switchserver = &check_switchserver($dom,$confname);
4371: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4372: my $datatable;
1.267 raeburn 4373: my %lt = <itools_names();
4374: my @courseroles = ('cc','in','ta','ep','st');
4375: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4376: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4377: if (keys(%ordered)) {
4378: my @items = sort { $a <=> $b } keys(%ordered);
4379: for (my $i=0; $i<@items; $i++) {
4380: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4381: my $item = $ordered{$items[$i]};
1.323 raeburn 4382: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4383: if (ref($settings->{$item}) eq 'HASH') {
4384: $title = $settings->{$item}->{'title'};
4385: $url = $settings->{$item}->{'url'};
4386: $key = $settings->{$item}->{'key'};
4387: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4388: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4389: my $image = $settings->{$item}->{'image'};
4390: if ($image ne '') {
4391: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4392: }
1.323 raeburn 4393: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4394: $sigsel{'HMAC-256'} = ' selected="selected"';
4395: } else {
4396: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4397: }
1.267 raeburn 4398: }
1.319 raeburn 4399: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4400: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4401: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4402: for (my $k=0; $k<=$maxnum; $k++) {
4403: my $vpos = $k+1;
4404: my $selstr;
4405: if ($k == $i) {
4406: $selstr = ' selected="selected" ';
4407: }
4408: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4409: }
4410: $datatable .= '</select>'.(' 'x2).
4411: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4412: &mt('Delete?').'</label></span></td>'.
4413: '<td colspan="2">'.
4414: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4415: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4416: (' 'x2).
4417: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4418: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4419: (' 'x2).
4420: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4421: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4422: (' 'x2).
4423: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4424: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4425: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4426: '<br /><br />'.
1.323 raeburn 4427: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4428: ' value="'.$url.'" /></span>'.
4429: (' 'x2).
1.319 raeburn 4430: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4431: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4432: (' 'x2).
1.322 raeburn 4433: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4434: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4435: (' 'x2).
1.267 raeburn 4436: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4437: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4438: '<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>'.
4439: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4440: '</fieldset>'.
4441: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4442: '<span class="LC_nobreak">'.&mt('Display target:');
4443: my %currdisp;
4444: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4445: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4446: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4447: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4448: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4449: } else {
4450: $currdisp{'iframe'} = ' checked="checked"';
4451: }
4452: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4453: $currdisp{'width'} = $1;
4454: }
4455: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4456: $currdisp{'height'} = $1;
4457: }
1.296 raeburn 4458: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4459: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4460: } else {
4461: $currdisp{'iframe'} = ' checked="checked"';
4462: }
1.298 raeburn 4463: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4464: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4465: $lt{$disp}.'</label>'.(' 'x2);
4466: }
4467: $datatable .= (' 'x4);
4468: foreach my $dimen ('width','height') {
4469: $datatable .= '<label>'.$lt{$dimen}.' '.
4470: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4471: (' 'x2);
4472: }
1.334 raeburn 4473: $datatable .= '</span><br />'.
1.296 raeburn 4474: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4475: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4476: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4477: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4478: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4479: my %units = (
4480: 'passback' => 'days',
4481: 'roster' => 'seconds',
4482: );
1.267 raeburn 4483: foreach my $extra ('passback','roster') {
1.319 raeburn 4484: my $validsty = 'none';
4485: my $currvalid;
1.267 raeburn 4486: my $checkedon = '';
4487: my $checkedoff = ' checked="checked"';
4488: if ($settings->{$item}->{$extra}) {
4489: $checkedon = $checkedoff;
4490: $checkedoff = '';
1.319 raeburn 4491: $validsty = 'inline-block';
4492: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4493: $currvalid = $settings->{$item}->{$extra.'valid'};
4494: }
4495: }
4496: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4497: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4498: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4499: &mt('No').'</label>'.(' 'x2).
4500: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4501: &mt('Yes').'</label></span></div>'.
4502: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4503: '<span class="LC_nobreak">'.
4504: &mt("at least [_1] $units{$extra} after launch",
4505: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4506: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4507: }
1.319 raeburn 4508: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4509: if ($imgsrc) {
4510: $datatable .= $imgsrc.
4511: '<label><input type="checkbox" name="ltitools_image_del"'.
4512: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4513: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4514: } else {
4515: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4516: }
4517: if ($switchserver) {
4518: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4519: } else {
4520: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4521: }
4522: $datatable .= '</span></fieldset>';
1.324 raeburn 4523: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4524: if (ref($settings->{$item}) eq 'HASH') {
4525: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4526: %checkedfields = %{$settings->{$item}->{'fields'}};
4527: }
1.324 raeburn 4528: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4529: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4530: %rolemaps = %{$settings->{$item}->{'roles'}};
4531: $checkedfields{'roles'} = 1;
4532: }
4533: }
4534: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4535: '<span class="LC_nobreak">';
1.324 raeburn 4536: my $userfieldstyle = 'display:none;';
4537: my $seluserdom = '';
4538: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4539: foreach my $field (@fields) {
1.324 raeburn 4540: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4541: if ($checkedfields{$field}) {
4542: $checked = ' checked="checked"';
4543: }
1.324 raeburn 4544: if ($field eq 'user') {
4545: $id = ' id="ltitools_user_field_'.$i.'"';
4546: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4547: if ($checked) {
4548: $userfieldstyle = 'display:inline-block';
4549: if ($userincdom) {
4550: $seluserdom = $unseluserdom;
4551: $unseluserdom = '';
4552: }
4553: }
4554: } else {
4555: $spacer = (' ' x2);
4556: }
1.267 raeburn 4557: $datatable .= '<label>'.
1.324 raeburn 4558: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4559: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4560: }
1.324 raeburn 4561: $datatable .= '</span>';
4562: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4563: '<span class="LC_nobreak"> : '.
4564: '<select name="ltitools_userincdom_'.$i.'">'.
4565: '<option value="">'.&mt('Select').'</option>'.
4566: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4567: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4568: '</select></span></div>';
4569: $datatable .= '</fieldset>'.
1.267 raeburn 4570: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4571: foreach my $role (@courseroles) {
4572: my ($selected,$selectnone);
4573: if (!$rolemaps{$role}) {
4574: $selectnone = ' selected="selected"';
4575: }
1.306 raeburn 4576: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4577: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4578: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4579: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4580: foreach my $ltirole (@ltiroles) {
4581: unless ($selectnone) {
4582: if ($rolemaps{$role} eq $ltirole) {
4583: $selected = ' selected="selected"';
4584: } else {
4585: $selected = '';
4586: }
4587: }
4588: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4589: }
4590: $datatable .= '</select></td>';
4591: }
1.273 raeburn 4592: $datatable .= '</tr></table></fieldset>';
4593: my %courseconfig;
4594: if (ref($settings->{$item}) eq 'HASH') {
4595: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4596: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4597: }
4598: }
4599: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4600: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4601: my $checked;
4602: if ($courseconfig{$item}) {
4603: $checked = ' checked="checked"';
4604: }
4605: $datatable .= '<label>'.
4606: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4607: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4608: }
4609: $datatable .= '</span></fieldset>'.
1.267 raeburn 4610: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4611: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4612: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4613: my %custom = %{$settings->{$item}->{'custom'}};
4614: if (keys(%custom) > 0) {
4615: foreach my $key (sort(keys(%custom))) {
4616: $datatable .= '<tr><td><span class="LC_nobreak">'.
4617: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4618: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4619: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4620: ' value="'.$custom{$key}.'" /></td></tr>';
4621: }
4622: }
4623: }
4624: $datatable .= '<tr><td><span class="LC_nobreak">'.
4625: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4626: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4627: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4628: $datatable .= '</table></fieldset></td></tr>'."\n";
4629: $itemcount ++;
4630: }
4631: }
4632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4633: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4634: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4635: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4636: '<select name="ltitools_add_pos"'.$chgstr.'>';
4637: for (my $k=0; $k<$maxnum+1; $k++) {
4638: my $vpos = $k+1;
4639: my $selstr;
4640: if ($k == $maxnum) {
4641: $selstr = ' selected="selected" ';
4642: }
4643: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4644: }
4645: $datatable .= '</select> '."\n".
1.334 raeburn 4646: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4647: '<td colspan="2">'.
4648: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4649: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4650: (' 'x2).
4651: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4652: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4653: (' 'x2).
4654: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4655: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4656: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4657: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4658: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4659: '<br />'.
1.323 raeburn 4660: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4661: (' 'x2).
4662: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4663: (' 'x2).
1.322 raeburn 4664: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4665: (' 'x2).
1.267 raeburn 4666: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4667: '<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".
4668: '</fieldset>'.
4669: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4670: '<span class="LC_nobreak">'.&mt('Display target:');
4671: my %defaultdisp;
4672: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4673: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4674: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4675: $lt{$disp}.'</label>'.(' 'x2);
4676: }
4677: $datatable .= (' 'x4);
4678: foreach my $dimen ('width','height') {
4679: $datatable .= '<label>'.$lt{$dimen}.' '.
4680: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4681: (' 'x2);
4682: }
1.334 raeburn 4683: $datatable .= '</span><br />'.
1.296 raeburn 4684: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4685: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4686: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4687: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4688: '</div><div style=""></div><br />';
1.319 raeburn 4689: my %units = (
4690: 'passback' => 'days',
4691: 'roster' => 'seconds',
4692: );
4693: my %defaulttimes = (
4694: 'passback' => '7',
1.322 raeburn 4695: 'roster' => '300',
1.319 raeburn 4696: );
1.267 raeburn 4697: foreach my $extra ('passback','roster') {
1.319 raeburn 4698: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4699: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4700: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4701: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4702: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4703: &mt('Yes').'</label></span></div>'.
4704: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4705: '<span class="LC_nobreak">'.
4706: &mt("at least [_1] $units{$extra} after launch",
4707: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4708: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4709: }
1.319 raeburn 4710: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4711: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4712: if ($switchserver) {
4713: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4714: } else {
4715: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4716: }
4717: $datatable .= '</span></fieldset>'.
4718: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4719: '<span class="LC_nobreak">';
4720: foreach my $field (@fields) {
1.324 raeburn 4721: my ($id,$onclick,$spacer);
4722: if ($field eq 'user') {
4723: $id = ' id="ltitools_user_field_add"';
4724: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4725: } else {
4726: $spacer = (' ' x2);
4727: }
1.267 raeburn 4728: $datatable .= '<label>'.
1.324 raeburn 4729: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4730: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4731: }
1.324 raeburn 4732: $datatable .= '</span>'.
4733: '<div style="display:none;" id="ltitools_user_div_add">'.
4734: '<span class="LC_nobreak"> : '.
4735: '<select name="ltitools_userincdom_add">'.
4736: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4737: '<option value="0">'.&mt('username').'</option>'.
4738: '<option value="1">'.&mt('username:domain').'</option>'.
4739: '</select></span></div></fieldset>';
4740: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4741: foreach my $role (@courseroles) {
4742: my ($checked,$checkednone);
1.306 raeburn 4743: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4744: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4745: '<select name="ltitools_add_roles_'.$role.'">'.
4746: '<option value="" selected="selected">'.&mt('Select').'</option>';
4747: foreach my $ltirole (@ltiroles) {
4748: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4749: }
4750: $datatable .= '</select></td>';
4751: }
4752: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4753: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4754: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4755: $datatable .= '<label>'.
4756: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4757: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4758: }
4759: $datatable .= '</span></fieldset>'.
1.267 raeburn 4760: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4761: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4762: '<tr><td><span class="LC_nobreak">'.
4763: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4764: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4765: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4766: '</table></fieldset>'."\n".
1.267 raeburn 4767: '</td>'."\n".
4768: '</tr>'."\n";
4769: $itemcount ++;
4770: return $datatable;
4771: }
4772:
4773: sub ltitools_names {
4774: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4775: 'title' => 'Title',
4776: 'version' => 'Version',
4777: 'msgtype' => 'Message Type',
1.323 raeburn 4778: 'sigmethod' => 'Signature Method',
1.296 raeburn 4779: 'url' => 'URL',
4780: 'key' => 'Key',
1.322 raeburn 4781: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4782: 'secret' => 'Secret',
4783: 'icon' => 'Icon',
1.324 raeburn 4784: 'user' => 'User',
1.296 raeburn 4785: 'fullname' => 'Full Name',
4786: 'firstname' => 'First Name',
4787: 'lastname' => 'Last Name',
4788: 'email' => 'E-mail',
4789: 'roles' => 'Role',
1.298 raeburn 4790: 'window' => 'Window',
4791: 'tab' => 'Tab',
1.296 raeburn 4792: 'iframe' => 'iFrame',
4793: 'height' => 'Height',
4794: 'width' => 'Width',
4795: 'linktext' => 'Default Link Text',
4796: 'explanation' => 'Default Explanation',
4797: 'passback' => 'Tool can return grades:',
4798: 'roster' => 'Tool can retrieve roster:',
4799: 'crstarget' => 'Display target',
4800: 'crslabel' => 'Course label',
4801: 'crstitle' => 'Course title',
4802: 'crslinktext' => 'Link Text',
4803: 'crsexplanation' => 'Explanation',
1.318 raeburn 4804: 'crsappend' => 'Provider URL',
1.267 raeburn 4805: );
4806: return %lt;
4807: }
4808:
1.320 raeburn 4809: sub print_lti {
4810: my ($dom,$settings,$rowtotal) = @_;
4811: my $itemcount = 1;
4812: my $maxnum = 0;
4813: my $css_class;
4814: my %ordered;
4815: if (ref($settings) eq 'HASH') {
4816: foreach my $item (keys(%{$settings})) {
4817: if (ref($settings->{$item}) eq 'HASH') {
4818: my $num = $settings->{$item}{'order'};
4819: $ordered{$num} = $item;
4820: }
4821: }
4822: }
4823: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4824: my $datatable;
1.320 raeburn 4825: my %lt = <i_names();
4826: if (keys(%ordered)) {
4827: my @items = sort { $a <=> $b } keys(%ordered);
4828: for (my $i=0; $i<@items; $i++) {
4829: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4830: my $item = $ordered{$items[$i]};
1.345 raeburn 4831: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4832: if (ref($settings->{$item}) eq 'HASH') {
4833: $key = $settings->{$item}->{'key'};
4834: $secret = $settings->{$item}->{'secret'};
4835: $lifetime = $settings->{$item}->{'lifetime'};
4836: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4837: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4838: $current = $settings->{$item};
4839: }
1.345 raeburn 4840: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4841: my %checkedrequser = (
4842: yes => ' checked="checked"',
4843: no => '',
4844: );
4845: if (!$requser) {
4846: $checkedrequser{'no'} = $checkedrequser{'yes'};
4847: $checkedrequser{'yes'} = '';
1.352 raeburn 4848: }
1.320 raeburn 4849: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4850: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4851: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4852: for (my $k=0; $k<=$maxnum; $k++) {
4853: my $vpos = $k+1;
4854: my $selstr;
4855: if ($k == $i) {
4856: $selstr = ' selected="selected" ';
4857: }
4858: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4859: }
4860: $datatable .= '</select>'.(' 'x2).
4861: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4862: &mt('Delete?').'</label></span></td>'.
4863: '<td colspan="2">'.
4864: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4865: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4866: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4867: (' 'x2).
4868: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4869: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4870: (' 'x2).
4871: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4872: 'value="'.$lifetime.'" size="3" /></span>'.
4873: (' 'x2).
4874: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4875: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4876: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4877: '<br /><br />'.
4878: '<span class="LC_nobreak">'.$lt{'key'}.
4879: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4880: (' 'x2).
4881: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4882: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4883: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4884: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4885: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4886: $itemcount ++;
4887: }
4888: }
4889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4890: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4891: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4892: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4893: '<select name="lti_pos_add"'.$chgstr.'>';
4894: for (my $k=0; $k<$maxnum+1; $k++) {
4895: my $vpos = $k+1;
4896: my $selstr;
4897: if ($k == $maxnum) {
4898: $selstr = ' selected="selected" ';
4899: }
4900: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4901: }
4902: $datatable .= '</select> '."\n".
1.334 raeburn 4903: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4904: '<td colspan="2">'.
4905: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4906: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4907: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4908: (' 'x2).
4909: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4910: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4911: (' 'x2).
1.345 raeburn 4912: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4913: (' 'x2).
4914: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4915: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4916: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4917: '<br /><br />'.
4918: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4919: (' 'x2).
4920: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4921: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
1.325 raeburn 4922: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4923: '</td>'."\n".
4924: '</tr>'."\n";
4925: $$rowtotal ++;
4926: return $datatable;;
4927: }
4928:
4929: sub lti_names {
4930: my %lt = &Apache::lonlocal::texthash(
4931: 'version' => 'LTI Version',
4932: 'url' => 'URL',
4933: 'key' => 'Key',
1.322 raeburn 4934: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4935: 'consumer' => 'Consumer',
1.320 raeburn 4936: 'secret' => 'Secret',
1.345 raeburn 4937: 'requser' => "User's identity sent",
1.320 raeburn 4938: 'email' => 'Email address',
4939: 'sourcedid' => 'User ID',
4940: 'other' => 'Other',
4941: 'passback' => 'Can return grades to Consumer:',
4942: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4943: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4944: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4945: );
4946: return %lt;
4947: }
4948:
4949: sub lti_options {
1.325 raeburn 4950: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4951: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4952: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4953: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4954: $checked{'makecrs'}{'N'} = ' checked="checked"';
4955: $checked{'mapcrstype'} = {};
4956: $checked{'makeuser'} = {};
4957: $checked{'selfenroll'} = {};
4958: $checked{'crssec'} = {};
4959: $checked{'crssecsrc'} = {};
1.325 raeburn 4960: $checked{'lcauth'} = {};
1.326 raeburn 4961: $checked{'menuitem'} = {};
1.325 raeburn 4962: if ($num eq 'add') {
4963: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4964: }
1.320 raeburn 4965: my $userfieldsty = 'none';
4966: my $crsfieldsty = 'none';
4967: my $crssecfieldsty = 'none';
4968: my $secsrcfieldsty = 'none';
1.337 raeburn 4969: my $passbacksty = 'none';
1.345 raeburn 4970: my $optionsty = 'block';
1.325 raeburn 4971: my $lcauthparm;
4972: my $lcauthparmstyle = 'display:none';
4973: my $lcauthparmtext;
1.326 raeburn 4974: my $menusty;
1.325 raeburn 4975: my $numinrow = 4;
1.326 raeburn 4976: my %menutitles = <imenu_titles();
1.320 raeburn 4977:
4978: if (ref($current) eq 'HASH') {
1.345 raeburn 4979: if (!$current->{'requser'}) {
4980: $optionsty = 'none';
4981: }
1.320 raeburn 4982: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4983: $checked{'mapuser'}{'sourcedid'} = '';
4984: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4985: $checked{'mapuser'}{'email'} = ' checked="checked"';
4986: } else {
4987: $checked{'mapuser'}{'other'} = ' checked="checked"';
4988: $userfield = $current->{'mapuser'};
4989: $userfieldsty = 'inline-block';
4990: }
4991: }
4992: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
4993: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
4994: if ($current->{'mapcrs'} eq 'context_id') {
4995: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
4996: } else {
4997: $checked{'mapcrs'}{'other'} = ' checked="checked"';
4998: $cidfield = $current->{'mapcrs'};
4999: $crsfieldsty = 'inline-block';
5000: }
5001: }
5002: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5003: foreach my $type (@{$current->{'mapcrstype'}}) {
5004: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5005: }
5006: }
1.345 raeburn 5007: if ($current->{'makecrs'}) {
1.320 raeburn 5008: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5009: }
1.320 raeburn 5010: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5011: foreach my $role (@{$current->{'makeuser'}}) {
5012: $checked{'makeuser'}{$role} = ' checked="checked"';
5013: }
5014: }
1.325 raeburn 5015: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5016: $checked{'lcauth'}{$1} = ' checked="checked"';
5017: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5018: $lcauthparm = $current->{'lcauthparm'};
5019: $lcauthparmstyle = 'display:table-row';
5020: if ($current->{'lcauth'} eq 'localauth') {
5021: $lcauthparmtext = &mt('Local auth argument');
5022: } else {
5023: $lcauthparmtext = &mt('Kerberos domain');
5024: }
5025: }
5026: }
1.320 raeburn 5027: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5028: foreach my $role (@{$current->{'selfenroll'}}) {
5029: $checked{'selfenroll'}{$role} = ' checked="checked"';
5030: }
5031: }
5032: if (ref($current->{'maproles'}) eq 'HASH') {
5033: %rolemaps = %{$current->{'maproles'}};
5034: }
5035: if ($current->{'section'} ne '') {
5036: $checked{'crssec'}{'Y'} = ' checked="checked"';
5037: $crssecfieldsty = 'inline-block';
5038: if ($current->{'section'} eq 'course_section_sourcedid') {
5039: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5040: } else {
5041: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5042: $crssecsrc = $current->{'section'};
5043: $secsrcfieldsty = 'inline-block';
5044: }
5045: } else {
5046: $checked{'crssec'}{'N'} = ' checked="checked"';
5047: }
1.326 raeburn 5048: if ($current->{'topmenu'}) {
5049: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5050: } else {
5051: $checked{'topmenu'}{'N'} = ' checked="checked"';
5052: }
5053: if ($current->{'inlinemenu'}) {
5054: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5055: } else {
5056: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5057: }
5058: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5059: $menusty = 'inline-block';
5060: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5061: foreach my $item (@{$current->{'lcmenu'}}) {
5062: if (exists($menutitles{$item})) {
5063: $checked{'menuitem'}{$item} = ' checked="checked"';
5064: }
5065: }
5066: }
5067: } else {
5068: $menusty = 'none';
5069: }
1.320 raeburn 5070: } else {
5071: $checked{'makecrs'}{'N'} = ' checked="checked"';
5072: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 5073: $checked{'topmenu'}{'N'} = ' checked="checked"';
5074: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5075: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5076: $menusty = 'inline-block';
1.320 raeburn 5077: }
1.325 raeburn 5078: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5079: my %coursetypetitles = &Apache::lonlocal::texthash (
5080: official => 'Official',
5081: unofficial => 'Unofficial',
5082: community => 'Community',
5083: textbook => 'Textbook',
5084: placement => 'Placement Test',
1.325 raeburn 5085: lti => 'LTI Provider',
1.320 raeburn 5086: );
1.325 raeburn 5087: my @authtypes = ('internal','krb4','krb5','localauth');
5088: my %shortauth = (
5089: internal => 'int',
5090: krb4 => 'krb4',
5091: krb5 => 'krb5',
5092: localauth => 'loc'
5093: );
5094: my %authnames = &authtype_names();
1.320 raeburn 5095: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5096: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5097: my @courseroles = ('cc','in','ta','ep','st');
5098: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5099: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5100: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5101: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5102: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5103: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5104: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5105: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5106: foreach my $option ('sourcedid','email','other') {
5107: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5108: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5109: ($option eq 'other' ? '' : (' 'x2) );
5110: }
5111: $output .= '</span></div>'.
5112: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5113: '<input type="text" name="lti_customuser_'.$num.'" '.
5114: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5115: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5116: foreach my $ltirole (@lticourseroles) {
5117: my ($selected,$selectnone);
5118: if ($rolemaps{$ltirole} eq '') {
5119: $selectnone = ' selected="selected"';
5120: }
5121: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5122: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5123: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5124: foreach my $role (@courseroles) {
5125: unless ($selectnone) {
5126: if ($rolemaps{$ltirole} eq $role) {
5127: $selected = ' selected="selected"';
5128: } else {
5129: $selected = '';
5130: }
5131: }
5132: $output .= '<option value="'.$role.'"'.$selected.'>'.
5133: &Apache::lonnet::plaintext($role,'Course').
5134: '</option>';
5135: }
5136: $output .= '</select></td>';
5137: }
5138: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5139: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5140: foreach my $ltirole (@ltiroles) {
5141: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5142: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5143: }
5144: $output .= '</fieldset>'.
1.345 raeburn 5145: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5146: '<table>'.
5147: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5148: '</table>'.
5149: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5150: '<td class="LC_left_item">';
5151: foreach my $auth ('lti',@authtypes) {
5152: my $authtext;
5153: if ($auth eq 'lti') {
5154: $authtext = &mt('None');
5155: } else {
5156: $authtext = $authnames{$shortauth{$auth}};
5157: }
5158: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5159: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5160: $authtext.'</label></span> ';
5161: }
5162: $output .= '</td></tr>'.
5163: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5164: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5165: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5166: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5167: '</table></fieldset>'.
1.345 raeburn 5168: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5169: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5170: &mt('Unique course identifier').': ';
5171: foreach my $option ('course_offering_sourcedid','context_id','other') {
5172: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5173: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5174: ($option eq 'other' ? '' : (' 'x2) );
5175: }
1.334 raeburn 5176: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5177: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5178: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5179: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5180: foreach my $type (@coursetypes) {
5181: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5182: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5183: (' 'x2);
5184: }
5185: $output .= '</span></fieldset>'.
1.345 raeburn 5186: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5187: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5188: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5189: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5190: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5191: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5192: '</fieldset>'.
1.345 raeburn 5193: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5194: foreach my $lticrsrole (@lticourseroles) {
5195: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5196: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5197: }
5198: $output .= '</fieldset>'.
1.345 raeburn 5199: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5200: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5201: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5202: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5203: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5204: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5205: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5206: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5207: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5208: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5209: &mt('Standard field').'</label>'.(' 'x2).
5210: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5211: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5212: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5213: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5214: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5215: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5216: foreach my $extra ('roster','passback') {
1.320 raeburn 5217: my $checkedon = '';
5218: my $checkedoff = ' checked="checked"';
1.337 raeburn 5219: if ($extra eq 'passback') {
5220: $pb1p1chk = ' checked="checked"';
5221: $pb1p0chk = '';
5222: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5223: } else {
5224: $onclickpb = '';
5225: }
1.320 raeburn 5226: if (ref($current) eq 'HASH') {
5227: if (($current->{$extra})) {
5228: $checkedon = $checkedoff;
5229: $checkedoff = '';
1.337 raeburn 5230: if ($extra eq 'passback') {
5231: $passbacksty = 'inline-block';
5232: }
5233: if ($current->{'passbackformat'} eq '1.0') {
5234: $pb1p0chk = ' checked="checked"';
5235: $pb1p1chk = '';
5236: }
1.320 raeburn 5237: }
5238: }
5239: $output .= $lt{$extra}.' '.
1.337 raeburn 5240: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5241: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5242: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5243: &mt('Yes').'</label><br />';
5244: }
1.337 raeburn 5245: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5246: '<span class="LC_nobreak">'.&mt('Grade format').
5247: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5248: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5249: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5250: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345 raeburn 5251: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5252: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5253: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5254: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5255: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5256: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5257: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5258: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5259: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5260: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5261: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5262: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5263: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5264: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5265: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5266: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5267: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5268: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5269: (' 'x2);
5270: }
1.334 raeburn 5271: $output .= '</span></div></fieldset>';
1.320 raeburn 5272: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5273: #
5274: # $output .= '</fieldset>'.
5275: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5276: return $output;
5277: }
5278:
1.326 raeburn 5279: sub ltimenu_titles {
5280: return &Apache::lonlocal::texthash(
5281: fullname => 'Full name',
5282: coursetitle => 'Course title',
5283: role => 'Role',
5284: logout => 'Logout',
5285: grades => 'Grades',
5286: );
5287: }
5288:
1.121 raeburn 5289: sub print_coursedefaults {
1.139 raeburn 5290: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5291: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5292: my $itemcount = 1;
1.192 raeburn 5293: my %choices = &Apache::lonlocal::texthash (
5294: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5295: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5296: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5297: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5298: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5299: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5300: texengine => 'Default method to display mathematics',
1.257 raeburn 5301: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5302: canclone => "People who may clone a course (besides course's owner and coordinators)",
5303: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5304: );
1.198 raeburn 5305: my %staticdefaults = (
5306: anonsurvey_threshold => 10,
5307: uploadquota => 500,
1.257 raeburn 5308: postsubmit => 60,
1.276 raeburn 5309: mysqltables => 172800,
1.198 raeburn 5310: );
1.139 raeburn 5311: if ($position eq 'top') {
1.257 raeburn 5312: %defaultchecked = (
5313: 'canuse_pdfforms' => 'off',
5314: 'uselcmath' => 'on',
5315: 'usejsme' => 'on',
1.289 raeburn 5316: 'canclone' => 'none',
1.257 raeburn 5317: );
5318: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 5319: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5320: if (ref($settings) eq 'HASH') {
5321: if ($settings->{'texengine'}) {
5322: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5323: $deftex = $settings->{'texengine'};
5324: }
5325: }
5326: }
5327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5328: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5329: '<span class="LC_nobreak">'.$choices{'texengine'}.
5330: '</span></td><td class="LC_right_item">'.
5331: '<select name="texengine">'."\n";
5332: my %texoptions = (
5333: MathJax => 'MathJax',
5334: mimetex => &mt('Convert to Images'),
5335: tth => &mt('TeX to HTML'),
5336: );
5337: foreach my $renderer ('MathJax','mimetex','tth') {
5338: my $selected = '';
5339: if ($renderer eq $deftex) {
5340: $selected = ' selected="selected"';
5341: }
5342: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5343: }
5344: $mathdisp .= '</select></td></tr>'."\n";
5345: $itemcount ++;
1.139 raeburn 5346: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5347: \%choices,$itemcount);
1.314 raeburn 5348: $datatable = $mathdisp.$datatable;
1.264 raeburn 5349: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5350: $datatable .=
1.306 raeburn 5351: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5352: '<span class="LC_nobreak">'.$choices{'canclone'}.
5353: '</span></td><td class="LC_left_item">';
5354: my $currcanclone = 'none';
5355: my $onclick;
5356: my @cloneoptions = ('none','domain');
5357: my %clonetitles = (
5358: none => 'No additional course requesters',
5359: domain => "Any course requester in course's domain",
5360: instcode => 'Course requests for official courses ...',
5361: );
5362: my (%codedefaults,@code_order,@posscodes);
5363: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5364: \@code_order) eq 'ok') {
5365: if (@code_order > 0) {
5366: push(@cloneoptions,'instcode');
5367: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5368: }
5369: }
5370: if (ref($settings) eq 'HASH') {
5371: if ($settings->{'canclone'}) {
5372: if (ref($settings->{'canclone'}) eq 'HASH') {
5373: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5374: if (@code_order > 0) {
5375: $currcanclone = 'instcode';
5376: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5377: }
5378: }
5379: } elsif ($settings->{'canclone'} eq 'domain') {
5380: $currcanclone = $settings->{'canclone'};
5381: }
5382: }
1.289 raeburn 5383: }
1.264 raeburn 5384: foreach my $option (@cloneoptions) {
5385: my ($checked,$additional);
5386: if ($currcanclone eq $option) {
5387: $checked = ' checked="checked"';
5388: }
5389: if ($option eq 'instcode') {
5390: if (@code_order) {
5391: my $show = 'none';
5392: if ($checked) {
5393: $show = 'block';
5394: }
1.317 raeburn 5395: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5396: &mt('Institutional codes for new and cloned course have identical:').
5397: '<br />';
5398: foreach my $item (@code_order) {
5399: my $codechk;
5400: if ($checked) {
5401: if (grep(/^\Q$item\E$/,@posscodes)) {
5402: $codechk = ' checked="checked"';
5403: }
5404: }
5405: $additional .= '<label>'.
5406: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5407: $item.'</label>';
5408: }
5409: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5410: }
5411: }
5412: $datatable .=
5413: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5414: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5415: '</label> '.$additional.'</span><br />';
5416: }
5417: $datatable .= '</td>'.
5418: '</tr>';
5419: $itemcount ++;
1.139 raeburn 5420: } else {
5421: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5422: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5423: my $currusecredits = 0;
1.257 raeburn 5424: my $postsubmitclient = 1;
1.271 raeburn 5425: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5426: if (ref($settings) eq 'HASH') {
5427: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5428: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5429: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5430: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5431: }
5432: }
1.192 raeburn 5433: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5434: foreach my $type (@types) {
5435: next if ($type eq 'community');
5436: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5437: if ($defcredits{$type} ne '') {
5438: $currusecredits = 1;
5439: }
5440: }
5441: }
5442: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5443: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5444: $postsubmitclient = 0;
5445: foreach my $type (@types) {
5446: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5447: }
5448: } else {
5449: foreach my $type (@types) {
5450: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5451: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5452: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5453: } else {
5454: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5455: }
5456: } else {
5457: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5458: }
5459: }
5460: }
5461: } else {
5462: foreach my $type (@types) {
5463: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5464: }
5465: }
1.276 raeburn 5466: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5467: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5468: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5469: }
5470: } else {
5471: foreach my $type (@types) {
5472: $currmysql{$type} = $staticdefaults{'mysqltables'};
5473: }
5474: }
1.258 raeburn 5475: } else {
5476: foreach my $type (@types) {
5477: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5478: }
1.139 raeburn 5479: }
5480: if (!$currdefresponder) {
1.198 raeburn 5481: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5482: } elsif ($currdefresponder < 1) {
5483: $currdefresponder = 1;
5484: }
1.198 raeburn 5485: foreach my $type (@types) {
5486: if ($curruploadquota{$type} eq '') {
5487: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5488: }
5489: }
1.139 raeburn 5490: $datatable .=
1.192 raeburn 5491: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5492: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5493: '</span></td>'.
5494: '<td class="LC_right_item"><span class="LC_nobreak">'.
5495: '<input type="text" name="anonsurvey_threshold"'.
5496: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5497: '</td></tr>'."\n";
5498: $itemcount ++;
5499: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5500: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5501: $choices{'uploadquota'}.
5502: '</span></td>'.
1.306 raeburn 5503: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5504: '<table><tr>';
1.198 raeburn 5505: foreach my $type (@types) {
1.306 raeburn 5506: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5507: '<input type="text" name="uploadquota_'.$type.'"'.
5508: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5509: }
5510: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5511: $itemcount ++;
1.236 raeburn 5512: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5513: my $display = 'none';
1.192 raeburn 5514: if ($currusecredits) {
5515: $display = 'block';
5516: }
5517: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5518: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5519: foreach my $type (@types) {
5520: next if ($type eq 'community');
1.306 raeburn 5521: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5522: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5523: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5524: }
5525: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5526: %defaultchecked = ('coursecredits' => 'off');
5527: @toggles = ('coursecredits');
5528: my $current = {
5529: 'coursecredits' => $currusecredits,
5530: };
5531: (my $table,$itemcount) =
5532: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5533: \%choices,$itemcount,$onclick,$additional,'left');
5534: $datatable .= $table;
5535: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5536: my $display = 'none';
5537: if ($postsubmitclient) {
5538: $display = 'block';
5539: }
5540: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5541: &mt('Number of seconds submit is disabled').'<br />'.
5542: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5543: '<table><tr>';
1.257 raeburn 5544: foreach my $type (@types) {
1.306 raeburn 5545: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5546: '<input type="text" name="'.$type.'_timeout" value="'.
5547: $deftimeout{$type}.'" size="5" /></td>';
5548: }
5549: $additional .= '</tr></table></div>'."\n";
5550: %defaultchecked = ('postsubmit' => 'on');
5551: @toggles = ('postsubmit');
1.280 raeburn 5552: $current = {
5553: 'postsubmit' => $postsubmitclient,
5554: };
1.257 raeburn 5555: ($table,$itemcount) =
5556: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5557: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5558: $datatable .= $table;
1.276 raeburn 5559: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5560: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5561: $choices{'mysqltables'}.
5562: '</span></td>'.
1.306 raeburn 5563: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5564: '<table><tr>';
5565: foreach my $type (@types) {
1.306 raeburn 5566: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5567: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5568: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5569: }
5570: $datatable .= '</tr></table></td></tr>'."\n";
5571: $itemcount ++;
5572:
1.139 raeburn 5573: }
1.192 raeburn 5574: $$rowtotal += $itemcount;
1.121 raeburn 5575: return $datatable;
1.118 jms 5576: }
5577:
1.231 raeburn 5578: sub print_selfenrollment {
5579: my ($position,$dom,$settings,$rowtotal) = @_;
5580: my ($css_class,$datatable);
5581: my $itemcount = 1;
1.271 raeburn 5582: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5583: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5584: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5585: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5586: my @rows;
5587: my $key;
5588: if ($position eq 'top') {
5589: $key = 'admin';
5590: if (ref($rowsref) eq 'ARRAY') {
5591: @rows = @{$rowsref};
5592: }
5593: } elsif ($position eq 'middle') {
5594: $key = 'default';
5595: @rows = ('types','registered','approval','limit');
5596: }
5597: foreach my $row (@rows) {
5598: if (defined($titlesref->{$row})) {
5599: $itemcount ++;
5600: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5601: $datatable .= '<tr'.$css_class.'>'.
5602: '<td>'.$titlesref->{$row}.'</td>'.
5603: '<td class="LC_left_item">'.
5604: '<table><tr>';
5605: my (%current,%currentcap);
5606: if (ref($settings) eq 'HASH') {
5607: if (ref($settings->{$key}) eq 'HASH') {
5608: foreach my $type (@types) {
5609: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5610: $current{$type} = $settings->{$key}->{$type}->{$row};
5611: }
5612: if (($row eq 'limit') && ($key eq 'default')) {
5613: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5614: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5615: }
5616: }
5617: }
5618: }
5619: }
5620: my %roles = (
5621: '0' => &Apache::lonnet::plaintext('dc'),
5622: );
5623:
5624: foreach my $type (@types) {
5625: unless (($row eq 'registered') && ($key eq 'default')) {
5626: $datatable .= '<th>'.&mt($type).'</th>';
5627: }
5628: }
5629: unless (($row eq 'registered') && ($key eq 'default')) {
5630: $datatable .= '</tr><tr>';
5631: }
5632: foreach my $type (@types) {
5633: if ($type eq 'community') {
5634: $roles{'1'} = &mt('Community personnel');
5635: } else {
5636: $roles{'1'} = &mt('Course personnel');
5637: }
5638: $datatable .= '<td style="vertical-align: top">';
5639: if ($position eq 'top') {
5640: my %checked;
5641: if ($current{$type} eq '0') {
5642: $checked{'0'} = ' checked="checked"';
5643: } else {
5644: $checked{'1'} = ' checked="checked"';
5645: }
5646: foreach my $role ('1','0') {
5647: $datatable .= '<span class="LC_nobreak"><label>'.
5648: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5649: 'value="'.$role.'"'.$checked{$role}.' />'.
5650: $roles{$role}.'</label></span> ';
5651: }
5652: } else {
5653: if ($row eq 'types') {
5654: my %checked;
5655: if ($current{$type} =~ /^(all|dom)$/) {
5656: $checked{$1} = ' checked="checked"';
5657: } else {
5658: $checked{''} = ' checked="checked"';
5659: }
5660: foreach my $val ('','dom','all') {
5661: $datatable .= '<span class="LC_nobreak"><label>'.
5662: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5663: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5664: }
5665: } elsif ($row eq 'registered') {
5666: my %checked;
5667: if ($current{$type} eq '1') {
5668: $checked{'1'} = ' checked="checked"';
5669: } else {
5670: $checked{'0'} = ' checked="checked"';
5671: }
5672: foreach my $val ('0','1') {
5673: $datatable .= '<span class="LC_nobreak"><label>'.
5674: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5675: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5676: }
5677: } elsif ($row eq 'approval') {
5678: my %checked;
5679: if ($current{$type} =~ /^([12])$/) {
5680: $checked{$1} = ' checked="checked"';
5681: } else {
5682: $checked{'0'} = ' checked="checked"';
5683: }
5684: for my $val (0..2) {
5685: $datatable .= '<span class="LC_nobreak"><label>'.
5686: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5687: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5688: }
5689: } elsif ($row eq 'limit') {
5690: my %checked;
5691: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5692: $checked{$1} = ' checked="checked"';
5693: } else {
5694: $checked{'none'} = ' checked="checked"';
5695: }
5696: my $cap;
5697: if ($currentcap{$type} =~ /^\d+$/) {
5698: $cap = $currentcap{$type};
5699: }
5700: foreach my $val ('none','allstudents','selfenrolled') {
5701: $datatable .= '<span class="LC_nobreak"><label>'.
5702: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5703: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5704: }
5705: $datatable .= '<br />'.
5706: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5707: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5708: '</span>';
5709: }
5710: }
5711: $datatable .= '</td>';
5712: }
5713: $datatable .= '</tr>';
5714: }
5715: $datatable .= '</table></td></tr>';
5716: }
5717: } elsif ($position eq 'bottom') {
1.235 raeburn 5718: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5719: }
5720: $$rowtotal += $itemcount;
5721: return $datatable;
5722: }
5723:
5724: sub print_validation_rows {
5725: my ($caller,$dom,$settings,$rowtotal) = @_;
5726: my ($itemsref,$namesref,$fieldsref);
5727: if ($caller eq 'selfenroll') {
5728: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5729: } elsif ($caller eq 'requestcourses') {
5730: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5731: }
5732: my %currvalidation;
5733: if (ref($settings) eq 'HASH') {
5734: if (ref($settings->{'validation'}) eq 'HASH') {
5735: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5736: }
1.235 raeburn 5737: }
5738: my $datatable;
5739: my $itemcount = 0;
5740: foreach my $item (@{$itemsref}) {
5741: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5742: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5743: $namesref->{$item}.
5744: '</span></td>'.
5745: '<td class="LC_left_item">';
5746: if (($item eq 'url') || ($item eq 'button')) {
5747: $datatable .= '<span class="LC_nobreak">'.
5748: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5749: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5750: } elsif ($item eq 'fields') {
5751: my @currfields;
5752: if (ref($currvalidation{$item}) eq 'ARRAY') {
5753: @currfields = @{$currvalidation{$item}};
5754: }
5755: foreach my $field (@{$fieldsref}) {
5756: my $check = '';
5757: if (grep(/^\Q$field\E$/,@currfields)) {
5758: $check = ' checked="checked"';
5759: }
5760: $datatable .= '<span class="LC_nobreak"><label>'.
5761: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5762: ' value="'.$field.'"'.$check.' />'.$field.
5763: '</label></span> ';
5764: }
5765: } elsif ($item eq 'markup') {
1.334 raeburn 5766: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5767: $currvalidation{$item}.
1.231 raeburn 5768: '</textarea>';
1.235 raeburn 5769: }
5770: $datatable .= '</td></tr>'."\n";
5771: if (ref($rowtotal)) {
1.231 raeburn 5772: $itemcount ++;
5773: }
5774: }
1.235 raeburn 5775: if ($caller eq 'requestcourses') {
5776: my %currhash;
1.248 raeburn 5777: if (ref($settings) eq 'HASH') {
5778: if (ref($settings->{'validation'}) eq 'HASH') {
5779: if ($settings->{'validation'}{'dc'} ne '') {
5780: $currhash{$settings->{'validation'}{'dc'}} = 1;
5781: }
1.235 raeburn 5782: }
5783: }
5784: my $numinrow = 2;
5785: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5786: 'validationdc',%currhash);
1.247 raeburn 5787: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5788: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5789: if ($numdc > 1) {
1.247 raeburn 5790: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5791: } else {
1.247 raeburn 5792: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5793: }
1.247 raeburn 5794: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5795: $itemcount ++;
5796: }
5797: if (ref($rowtotal)) {
5798: $$rowtotal += $itemcount;
5799: }
1.231 raeburn 5800: return $datatable;
5801: }
5802:
1.354 raeburn 5803: sub print_passwords {
5804: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5805: my ($datatable,$css_class);
5806: my $itemcount = 0;
5807: my %titles = &Apache::lonlocal::texthash (
5808: captcha => '"Forgot Password" CAPTCHA validation',
5809: link => 'Reset link expiration (hours)',
5810: case => 'Case-sensitive usernames/e-mail',
5811: prelink => 'Information required (form 1)',
5812: postlink => 'Information required (form 2)',
5813: emailsrc => 'LON-CAPA e-mail address type(s)',
5814: customtext => 'Domain specific text (HTML)',
5815: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5816: intauth_check => 'Check bcrypt cost if authenticated',
5817: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5818: permanent => 'Permanent e-mail address',
5819: critical => 'Critical notification address',
5820: notify => 'Notification address',
5821: min => 'Minimum password length',
5822: max => 'Maximum password length',
5823: chars => 'Required characters',
5824: expire => 'Password expiration (days)',
5825: );
5826: if ($position eq 'top') {
5827: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5828: my $shownlinklife = 2;
5829: my $prelink = 'both';
5830: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5831: if (ref($settings) eq 'HASH') {
5832: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5833: $shownlinklife = $settings->{resetlink};
5834: }
5835: if (ref($settings->{resetcase}) eq 'ARRAY') {
5836: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5837: }
5838: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5839: $prelink = $settings->{resetprelink};
5840: }
5841: if (ref($settings->{resetpostlink}) eq 'HASH') {
5842: %postlink = %{$settings->{resetpostlink}};
5843: }
5844: if (ref($settings->{resetemail}) eq 'ARRAY') {
5845: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5846: }
5847: if ($settings->{resetremove}) {
5848: $nostdtext = 1;
5849: }
5850: if ($settings->{resetcustom}) {
5851: $customurl = $settings->{resetcustom};
5852: }
5853: } else {
5854: if (ref($types) eq 'ARRAY') {
5855: foreach my $item (@{$types}) {
5856: $casesens{$item} = 1;
5857: $postlink{$item} = ['username','email'];
5858: }
5859: }
5860: $casesens{'default'} = 1;
5861: $postlink{'default'} = ['username','email'];
5862: $prelink = 'both';
5863: %emailsrc = (
5864: permanent => 1,
5865: critical => 1,
5866: notify => 1,
5867: );
5868: }
5869: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5870: $itemcount ++;
5871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5872: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5873: '<td class="LC_left_item">'.
5874: '<input type="textbox" value="'.$shownlinklife.'" '.
5875: 'name="passwords_link" size="3" /></td></tr>';
5876: $itemcount ++;
5877: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5878: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5879: '<td class="LC_left_item">';
5880: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5881: foreach my $item (@{$types}) {
5882: my $checkedcase;
5883: if ($casesens{$item}) {
5884: $checkedcase = ' checked="checked"';
5885: }
5886: $datatable .= '<span class="LC_nobreak"><label>'.
5887: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5888: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
5889: '<span> ';
5890: }
5891: }
5892: my $checkedcase;
5893: if ($casesens{'default'}) {
5894: $checkedcase = ' checked="checked"';
5895: }
5896: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5897: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5898: $othertitle.'</label></span></td>';
5899: $itemcount ++;
5900: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5901: my %checkedpre = (
5902: both => ' checked="checked"',
5903: either => '',
5904: );
5905: if ($prelink eq 'either') {
5906: $checkedpre{either} = ' checked="checked"';
5907: $checkedpre{both} = '';
5908: }
5909: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5910: '<td class="LC_left_item"><span class="LC_nobreak">'.
5911: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5912: &mt('Both username and e-mail address').'</label></span> '.
5913: '<span class="LC_nobreak"><label>'.
5914: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
5915: &mt('Either username or e-mail address').'</label></span></td></tr>';
5916: $itemcount ++;
5917: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5918: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
5919: '<td class="LC_left_item">';
5920: my %postlinked;
5921: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5922: foreach my $item (@{$types}) {
5923: undef(%postlinked);
5924: $datatable .= '<fieldset style="display: inline-block;">'.
5925: '<legend>'.$usertypes->{$item}.'</legend>';
5926: if (ref($postlink{$item}) eq 'ARRAY') {
5927: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
5928: }
5929: foreach my $field ('email','username') {
5930: my $checked;
5931: if ($postlinked{$field}) {
5932: $checked = ' checked="checked"';
5933: }
5934: $datatable .= '<span class="LC_nobreak"><label>'.
5935: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
5936: $field.'"'.$checked.' />'.$field.'</label>'.
5937: '<span> ';
5938: }
5939: $datatable .= '</fieldset>';
5940: }
5941: }
5942: if (ref($postlink{'default'}) eq 'ARRAY') {
5943: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
5944: }
5945: $datatable .= '<fieldset style="display: inline-block;">'.
5946: '<legend>'.$othertitle.'</legend>';
5947: foreach my $field ('email','username') {
5948: my $checked;
5949: if ($postlinked{$field}) {
5950: $checked = ' checked="checked"';
5951: }
5952: $datatable .= '<span class="LC_nobreak"><label>'.
5953: '<input type="checkbox" name="passwords_postlink_default" value="'.
5954: $field.'"'.$checked.' />'.$field.'</label>'.
5955: '<span> ';
5956: }
5957: $datatable .= '</fieldset></td></tr>';
5958: $itemcount ++;
5959: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5960: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
5961: '<td class="LC_left_item">';
5962: foreach my $type ('permanent','critical','notify') {
5963: my $checkedemail;
5964: if ($emailsrc{$type}) {
5965: $checkedemail = ' checked="checked"';
5966: }
5967: $datatable .= '<span class="LC_nobreak"><label>'.
5968: '<input type="checkbox" name="passwords_emailsrc" value="'.
5969: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
5970: '<span> ';
5971: }
5972: $datatable .= '</td></tr>';
5973: $itemcount ++;
5974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5975: my $switchserver = &check_switchserver($dom,$confname);
5976: my ($showstd,$noshowstd);
5977: if ($nostdtext) {
5978: $noshowstd = ' checked="checked"';
5979: } else {
5980: $showstd = ' checked="checked"';
5981: }
5982: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
5983: '<td class="LC_left_item"><span class="LC_nobreak">'.
5984: &mt('Retain standard text:').
5985: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
5986: &mt('Yes').'</label>'.' '.
5987: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
5988: &mt('No').'</label></span><br />'.
5989: '<span class="LC_fontsize_small">'.
5990: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
5991: &mt('Include custom text:');
5992: if ($customurl) {
5993: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
5994: undef,undef,undef,undef,'background-color:#ffffff');
5995: $datatable .= '<span class="LC_nobreak"> '.$link.
5996: '<label><input type="checkbox" name="passwords_custom_del"'.
5997: ' value="1" />'.&mt('Delete?').'</label></span>'.
5998: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
5999: }
6000: if ($switchserver) {
6001: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6002: } else {
6003: $datatable .='<span class="LC_nobreak"> '.
6004: '<input type="file" name="passwords_customfile" /></span>';
6005: }
6006: $datatable .= '</td></tr>';
6007: } elsif ($position eq 'middle') {
6008: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6009: my @items = ('intauth_cost','intauth_check','intauth_switch');
6010: my %defaults;
6011: if (ref($domconf{'defaults'}) eq 'HASH') {
6012: %defaults = %{$domconf{'defaults'}};
6013: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6014: $defaults{'intauth_cost'} = 10;
6015: }
6016: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6017: $defaults{'intauth_check'} = 0;
6018: }
6019: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6020: $defaults{'intauth_switch'} = 0;
6021: }
6022: } else {
6023: %defaults = (
6024: 'intauth_cost' => 10,
6025: 'intauth_check' => 0,
6026: 'intauth_switch' => 0,
6027: );
6028: }
6029: foreach my $item (@items) {
6030: if ($itemcount%2) {
6031: $css_class = '';
6032: } else {
6033: $css_class = ' class="LC_odd_row" ';
6034: }
6035: $datatable .= '<tr'.$css_class.'>'.
6036: '<td><span class="LC_nobreak">'.$titles{$item}.
6037: '</span></td><td class="LC_left_item" colspan="3">';
6038: if ($item eq 'intauth_switch') {
6039: my @options = (0,1,2);
6040: my %optiondesc = &Apache::lonlocal::texthash (
6041: 0 => 'No',
6042: 1 => 'Yes',
6043: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6044: );
6045: $datatable .= '<table width="100%">';
6046: foreach my $option (@options) {
6047: my $checked = ' ';
6048: if ($defaults{$item} eq $option) {
6049: $checked = ' checked="checked"';
6050: }
6051: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6052: '<label><input type="radio" name="'.$item.
6053: '" value="'.$option.'"'.$checked.' />'.
6054: $optiondesc{$option}.'</label></span></td></tr>';
6055: }
6056: $datatable .= '</table>';
6057: } elsif ($item eq 'intauth_check') {
6058: my @options = (0,1,2);
6059: my %optiondesc = &Apache::lonlocal::texthash (
6060: 0 => 'No',
6061: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6062: 2 => 'Yes, disallow login if stored cost is less than domain default',
6063: );
6064: $datatable .= '<table width="100%">';
6065: foreach my $option (@options) {
6066: my $checked = ' ';
6067: my $onclick;
6068: if ($defaults{$item} eq $option) {
6069: $checked = ' checked="checked"';
6070: }
6071: if ($option == 2) {
6072: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6073: }
6074: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6075: '<label><input type="radio" name="'.$item.
6076: '" value="'.$option.'"'.$checked.$onclick.' />'.
6077: $optiondesc{$option}.'</label></span></td></tr>';
6078: }
6079: $datatable .= '</table>';
6080: } else {
6081: $datatable .= '<input type="text" name="'.$item.'" value="'.
6082: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6083: }
6084: $datatable .= '</td></tr>';
6085: $itemcount ++;
6086: }
6087: } elsif ($position eq 'lower') {
6088: my ($min,$max,%chars,$expire);
6089: if (ref($settings) eq 'HASH') {
6090: if ($settings->{min}) {
6091: $min = $settings->{min};
6092: }
6093: if ($settings->{max}) {
6094: $max = $settings->{max};
6095: }
6096: if (ref($settings->{chars}) eq 'ARRAY') {
6097: map { $chars{$_} = 1; } (@{$settings->{chars}});
6098: }
6099: if ($settings->{expire}) {
6100: $expire = $settings->{expire};
6101: }
6102: } else {
6103: $min = '7';
6104: }
6105: my %rulenames = &Apache::lonlocal::texthash(
6106: uc => 'At least one upper case letter',
6107: lc => 'At least one lower case letter',
6108: num => 'At least one number',
6109: spec => 'At least one non-alphanumeric',
6110: );
6111: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6112: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6113: '<td class="LC_left_item"><span class="LC_nobreak">'.
6114: '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
6115: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
6116: '</span></td></tr>';
6117: $itemcount ++;
6118: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6119: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6120: '<td class="LC_left_item"><span class="LC_nobreak">'.
6121: '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
6122: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6123: '</span></td></tr>';
6124: $itemcount ++;
6125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6126: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6127: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6128: '</span></td>';
6129: my $numinrow = 2;
6130: my @possrules = ('uc','lc','num','spec');
6131: $datatable .= '<td class="LC_left_item"><table>';
6132: for (my $i=0; $i<@possrules; $i++) {
6133: my ($rem,$checked);
6134: if ($chars{$possrules[$i]}) {
6135: $checked = ' checked="checked"';
6136: }
6137: $rem = $i%($numinrow);
6138: if ($rem == 0) {
6139: if ($i > 0) {
6140: $datatable .= '</tr>';
6141: }
6142: $datatable .= '<tr>';
6143: }
6144: $datatable .= '<td><span class="LC_nobreak"><label>'.
6145: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6146: $rulenames{$possrules[$i]}.'</label></span></td>';
6147: }
6148: my $rem = @possrules%($numinrow);
6149: my $colsleft = $numinrow - $rem;
6150: if ($colsleft > 1 ) {
6151: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6152: ' </td>';
6153: } elsif ($colsleft == 1) {
6154: $datatable .= '<td class="LC_left_item"> </td>';
6155: }
6156: $datatable .='</table></td></tr>';
6157: $itemcount ++;
6158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6159: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
6160: '<td class="LC_left_item"><span class="LC_nobreak">'.
6161: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" />'.
6162: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
6163: '</span></td></tr>';
6164: } else {
6165: my $checkedon;
6166: my $checkedoff = ' checked="checked"';
6167: if (ref($settings) eq 'HASH') {
6168: if ($settings->{crsownerchg}) {
6169: $checkedon = $checkedoff;
6170: $checkedoff = '';
6171: }
6172: }
6173: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6174: $datatable .= '<tr '.$css_class.'>'.
6175: '<td>'.
6176: &mt('Requirements').'<ul>'.
6177: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6178: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6179: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6180: '</ul>'.
6181: '</td>'.
6182: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
6183: '<label><input type="radio" name="passwords_crsowner" value="1"'.$checkedon.' />'.&mt('Yes').'</label></span> '.
6184: '<span class="LC_nobreak"><label><input type="radio" name="passwords_crsowner" value="0"'.$checkedoff.' />'.
6185: &mt('No').'</label></span>'.
6186: '</td></tr>';
6187:
6188: }
6189: return $datatable;
6190: }
6191:
1.137 raeburn 6192: sub print_usersessions {
6193: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 6194: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 6195: my (%by_ip,%by_location,@intdoms,@instdoms);
6196: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 6197:
6198: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6199: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6200: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6201: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6202: if ($position eq 'top') {
1.152 raeburn 6203: if (keys(%serverhomes) > 1) {
1.145 raeburn 6204: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 6205: my $curroffloadnow;
6206: if (ref($settings) eq 'HASH') {
6207: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6208: $curroffloadnow = $settings->{'offloadnow'};
6209: }
6210: }
6211: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 6212: } else {
1.140 raeburn 6213: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 6214: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
6215: '</td></tr>';
1.140 raeburn 6216: }
1.137 raeburn 6217: } else {
1.279 raeburn 6218: my %titles = &usersession_titles();
6219: my ($prefix,@types);
6220: if ($position eq 'bottom') {
6221: $prefix = 'remote';
6222: @types = ('version','excludedomain','includedomain');
1.145 raeburn 6223: } else {
1.279 raeburn 6224: $prefix = 'hosted';
6225: @types = ('excludedomain','includedomain');
6226: }
6227: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6228: }
6229: $$rowtotal += $itemcount;
6230: return $datatable;
6231: }
6232:
6233: sub rules_by_location {
6234: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
6235: my ($datatable,$itemcount,$css_class);
6236: if (keys(%{$by_location}) == 0) {
6237: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6238: $datatable = '<tr'.$css_class.'><td colspan="2">'.
6239: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
6240: '</td></tr>';
6241: $itemcount = 1;
6242: } else {
6243: $itemcount = 0;
6244: my $numinrow = 5;
6245: my (%current,%checkedon,%checkedoff);
6246: my @locations = sort(keys(%{$by_location}));
6247: foreach my $type (@{$types}) {
6248: $checkedon{$type} = '';
6249: $checkedoff{$type} = ' checked="checked"';
6250: }
6251: if (ref($settings) eq 'HASH') {
6252: if (ref($settings->{$prefix}) eq 'HASH') {
6253: foreach my $key (keys(%{$settings->{$prefix}})) {
6254: $current{$key} = $settings->{$prefix}{$key};
6255: if ($key eq 'version') {
6256: if ($current{$key} ne '') {
1.145 raeburn 6257: $checkedon{$key} = ' checked="checked"';
6258: $checkedoff{$key} = '';
6259: }
1.279 raeburn 6260: } elsif (ref($current{$key}) eq 'ARRAY') {
6261: $checkedon{$key} = ' checked="checked"';
6262: $checkedoff{$key} = '';
1.137 raeburn 6263: }
6264: }
6265: }
1.279 raeburn 6266: }
6267: foreach my $type (@{$types}) {
6268: next if ($type ne 'version' && !@locations);
6269: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6270: $datatable .= '<tr'.$css_class.'>
6271: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
6272: <span class="LC_nobreak">
6273: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6274: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6275: if ($type eq 'version') {
6276: my @lcversions = &Apache::lonnet::all_loncaparevs();
6277: my $selector = '<select name="'.$prefix.'_version">';
6278: foreach my $version (@lcversions) {
6279: my $selected = '';
6280: if ($current{'version'} eq $version) {
6281: $selected = ' selected="selected"';
1.145 raeburn 6282: }
1.279 raeburn 6283: $selector .= ' <option value="'.$version.'"'.
6284: $selected.'>'.$version.'</option>';
6285: }
6286: $selector .= '</select> ';
6287: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6288: } else {
6289: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6290: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6291: ' />'.(' 'x2).
6292: '<input type="button" value="'.&mt('uncheck all').'" '.
6293: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6294: "\n".
6295: '</div><div><table>';
6296: my $rem;
6297: for (my $i=0; $i<@locations; $i++) {
6298: my ($showloc,$value,$checkedtype);
6299: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
6300: my $ip = $by_location->{$locations[$i]}->[0];
6301: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6302: $value = join(':',@{$by_ip->{$ip}});
6303: $showloc = join(', ',@{$by_ip->{$ip}});
6304: if (ref($current{$type}) eq 'ARRAY') {
6305: foreach my $loc (@{$by_ip->{$ip}}) {
6306: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6307: $checkedtype = ' checked="checked"';
6308: last;
1.145 raeburn 6309: }
1.138 raeburn 6310: }
6311: }
6312: }
1.137 raeburn 6313: }
1.279 raeburn 6314: $rem = $i%($numinrow);
6315: if ($rem == 0) {
6316: if ($i > 0) {
6317: $datatable .= '</tr>';
6318: }
6319: $datatable .= '<tr>';
6320: }
6321: $datatable .= '<td class="LC_left_item">'.
6322: '<span class="LC_nobreak"><label>'.
6323: '<input type="checkbox" name="'.$prefix.'_'.$type.
6324: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6325: '</label></span></td>';
6326: }
6327: $rem = @locations%($numinrow);
6328: my $colsleft = $numinrow - $rem;
6329: if ($colsleft > 1 ) {
6330: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6331: ' </td>';
6332: } elsif ($colsleft == 1) {
6333: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6334: }
1.279 raeburn 6335: $datatable .= '</tr></table>';
1.137 raeburn 6336: }
1.279 raeburn 6337: $datatable .= '</td></tr>';
6338: $itemcount ++;
1.137 raeburn 6339: }
6340: }
1.279 raeburn 6341: return ($datatable,$itemcount);
1.137 raeburn 6342: }
6343:
1.275 raeburn 6344: sub print_ssl {
6345: my ($position,$dom,$settings,$rowtotal) = @_;
6346: my ($css_class,$datatable);
6347: my $itemcount = 1;
6348: if ($position eq 'top') {
1.281 raeburn 6349: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6350: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6351: my $same_institution;
6352: if ($intdom ne '') {
6353: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
6354: if (ref($internet_names) eq 'ARRAY') {
6355: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
6356: $same_institution = 1;
6357: }
6358: }
6359: }
1.275 raeburn 6360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 6361: $datatable = '<tr'.$css_class.'><td colspan="2">';
6362: if ($same_institution) {
6363: my %domservers = &Apache::lonnet::get_servers($dom);
6364: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
6365: } else {
6366: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
6367: }
6368: $datatable .= '</td></tr>';
1.275 raeburn 6369: $itemcount ++;
6370: } else {
6371: my %titles = &ssl_titles();
6372: my (%by_ip,%by_location,@intdoms,@instdoms);
6373: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6374: my @alldoms = &Apache::lonnet::all_domains();
6375: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6376: my @domservers = &Apache::lonnet::get_servers($dom);
6377: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6378: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 6379: if (($position eq 'connto') || ($position eq 'connfrom')) {
6380: my $legacy;
6381: unless (ref($settings) eq 'HASH') {
6382: my $name;
6383: if ($position eq 'connto') {
6384: $name = 'loncAllowInsecure';
6385: } else {
6386: $name = 'londAllowInsecure';
6387: }
6388: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
6389: my @ids=&Apache::lonnet::current_machine_ids();
6390: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
6391: my %what = (
6392: $name => 1,
6393: );
6394: my ($result,$returnhash) =
6395: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
6396: if ($result eq 'ok') {
6397: if (ref($returnhash) eq 'HASH') {
6398: $legacy = $returnhash->{$name};
6399: }
6400: }
6401: } else {
6402: $legacy = $Apache::lonnet::perlvar{$name};
6403: }
6404: }
1.275 raeburn 6405: foreach my $type ('dom','intdom','other') {
6406: my %checked;
6407: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6408: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
6409: '<td class="LC_right_item">';
6410: my $skip;
6411: if ($type eq 'dom') {
6412: unless (keys(%servers) > 1) {
6413: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
6414: $skip = 1;
6415: }
6416: }
6417: if ($type eq 'intdom') {
6418: unless (@instdoms > 1) {
6419: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6420: $skip = 1;
6421: }
6422: } elsif ($type eq 'other') {
6423: if (keys(%by_location) == 0) {
6424: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6425: $skip = 1;
6426: }
6427: }
6428: unless ($skip) {
6429: $checked{'yes'} = ' checked="checked"';
6430: if (ref($settings) eq 'HASH') {
1.293 raeburn 6431: if (ref($settings->{$position}) eq 'HASH') {
6432: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6433: $checked{$1} = $checked{'yes'};
6434: delete($checked{'yes'});
6435: }
6436: }
1.293 raeburn 6437: } else {
6438: if ($legacy == 0) {
6439: $checked{'req'} = $checked{'yes'};
6440: delete($checked{'yes'});
6441: }
1.275 raeburn 6442: }
6443: foreach my $option ('no','yes','req') {
6444: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6445: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6446: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6447: '</label></span>'.(' 'x2);
6448: }
6449: }
6450: $datatable .= '</td></tr>';
6451: $itemcount ++;
6452: }
6453: } else {
6454: my $prefix = 'replication';
6455: my @types = ('certreq','nocertreq');
1.279 raeburn 6456: if (keys(%by_location) == 0) {
6457: $datatable .= '<tr'.$css_class.'><td>'.
6458: &mt('Nothing to set here, as there are no other institutions').
6459: '</td></tr>';
6460: $itemcount ++;
1.275 raeburn 6461: } else {
1.279 raeburn 6462: ($datatable,$itemcount) =
6463: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6464: }
6465: }
6466: }
6467: $$rowtotal += $itemcount;
6468: return $datatable;
6469: }
6470:
6471: sub ssl_titles {
6472: return &Apache::lonlocal::texthash (
6473: dom => 'LON-CAPA servers/VMs from same domain',
6474: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6475: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6476: connto => 'Connections to other servers',
6477: connfrom => 'Connections from other servers',
1.275 raeburn 6478: replication => 'Replicating content to other institutions',
6479: certreq => 'Client certificate required, but specific domains exempt',
6480: nocertreq => 'No client certificate required, except for specific domains',
6481: no => 'SSL not used',
6482: yes => 'SSL Optional (used if available)',
6483: req => 'SSL Required',
6484: );
1.279 raeburn 6485: }
6486:
6487: sub print_trust {
6488: my ($prefix,$dom,$settings,$rowtotal) = @_;
6489: my ($css_class,$datatable,%checked,%choices);
6490: my (%by_ip,%by_location,@intdoms,@instdoms);
6491: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6492: my $itemcount = 1;
6493: my %titles = &trust_titles();
6494: my @types = ('exc','inc');
6495: if ($prefix eq 'top') {
6496: $prefix = 'content';
6497: } elsif ($prefix eq 'bottom') {
6498: $prefix = 'msg';
6499: }
6500: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6501: $$rowtotal += $itemcount;
6502: return $datatable;
6503: }
6504:
6505: sub trust_titles {
6506: return &Apache::lonlocal::texthash(
6507: content => "Access to this domain's content by others",
6508: shared => "Access to other domain's content by this domain",
6509: enroll => "Enrollment in this domain's courses by others",
6510: othcoau => "Co-author roles in this domain for others",
6511: coaurem => "Co-author roles for this domain's users elsewhere",
6512: domroles => "Domain roles in this domain assignable to others",
6513: catalog => "Course Catalog for this domain displayed elsewhere",
6514: reqcrs => "Requests for creation of courses in this domain by others",
6515: msg => "Users in other domains can send messages to this domain",
6516: exc => "Allow all, but exclude specific domains",
6517: inc => "Deny all, but include specific domains",
6518: );
1.275 raeburn 6519: }
6520:
1.138 raeburn 6521: sub build_location_hashes {
1.275 raeburn 6522: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6523: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6524: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6525: my %iphost = &Apache::lonnet::get_iphost();
6526: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6527: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6528: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6529: foreach my $id (@{$iphost{$primary_ip}}) {
6530: my $intdom = &Apache::lonnet::internet_dom($id);
6531: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6532: push(@{$intdoms},$intdom);
6533: }
6534: }
6535: }
6536: foreach my $ip (keys(%iphost)) {
6537: if (ref($iphost{$ip}) eq 'ARRAY') {
6538: foreach my $id (@{$iphost{$ip}}) {
6539: my $location = &Apache::lonnet::internet_dom($id);
6540: if ($location) {
1.275 raeburn 6541: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6542: my $dom = &Apache::lonnet::host_domain($id);
6543: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6544: push(@{$instdoms},$dom);
6545: }
6546: next;
6547: }
1.138 raeburn 6548: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6549: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6550: push(@{$by_ip->{$ip}},$location);
6551: }
6552: } else {
6553: $by_ip->{$ip} = [$location];
6554: }
6555: }
6556: }
6557: }
6558: }
6559: foreach my $ip (sort(keys(%{$by_ip}))) {
6560: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6561: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6562: my $first = $by_ip->{$ip}->[0];
6563: if (ref($by_location->{$first}) eq 'ARRAY') {
6564: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6565: push(@{$by_location->{$first}},$ip);
6566: }
6567: } else {
6568: $by_location->{$first} = [$ip];
6569: }
6570: }
6571: }
6572: return;
6573: }
6574:
1.145 raeburn 6575: sub current_offloads_to {
6576: my ($dom,$settings,$servers) = @_;
6577: my (%spareid,%otherdomconfigs);
1.152 raeburn 6578: if (ref($servers) eq 'HASH') {
1.145 raeburn 6579: foreach my $lonhost (sort(keys(%{$servers}))) {
6580: my $gotspares;
1.152 raeburn 6581: if (ref($settings) eq 'HASH') {
6582: if (ref($settings->{'spares'}) eq 'HASH') {
6583: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6584: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6585: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6586: $gotspares = 1;
6587: }
1.145 raeburn 6588: }
6589: }
6590: unless ($gotspares) {
6591: my $gotspares;
6592: my $serverhomeID =
6593: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6594: my $serverhomedom =
6595: &Apache::lonnet::host_domain($serverhomeID);
6596: if ($serverhomedom ne $dom) {
6597: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6598: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6599: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6600: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6601: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6602: $gotspares = 1;
6603: }
6604: }
6605: } else {
6606: $otherdomconfigs{$serverhomedom} =
6607: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6608: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6609: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6610: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6611: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6612: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6613: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6614: $gotspares = 1;
6615: }
6616: }
6617: }
6618: }
6619: }
6620: }
6621: }
6622: unless ($gotspares) {
6623: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6624: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6625: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6626: } else {
6627: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6628: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6629: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6630: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6631: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6632: } else {
1.150 raeburn 6633: my %what = (
6634: spareid => 1,
6635: );
6636: my ($result,$returnhash) =
6637: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6638: if ($result eq 'ok') {
6639: if (ref($returnhash) eq 'HASH') {
6640: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6641: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6642: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6643: }
6644: }
1.145 raeburn 6645: }
6646: }
6647: }
6648: }
6649: }
6650: }
6651: return %spareid;
6652: }
6653:
6654: sub spares_row {
1.261 raeburn 6655: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6656: my $css_class;
6657: my $numinrow = 4;
6658: my $itemcount = 1;
6659: my $datatable;
1.152 raeburn 6660: my %typetitles = &sparestype_titles();
6661: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6662: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6663: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6664: my ($othercontrol,$serverdom);
6665: if ($serverhome ne $server) {
6666: $serverdom = &Apache::lonnet::host_domain($serverhome);
6667: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6668: } else {
6669: $serverdom = &Apache::lonnet::host_domain($server);
6670: if ($serverdom ne $dom) {
6671: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6672: }
6673: }
6674: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6675: my $checkednow;
6676: if (ref($curroffloadnow) eq 'HASH') {
6677: if ($curroffloadnow->{$server}) {
6678: $checkednow = ' checked="checked"';
6679: }
6680: }
1.145 raeburn 6681: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6682: $datatable .= '<tr'.$css_class.'>
6683: <td rowspan="2">
1.183 bisitz 6684: <span class="LC_nobreak">'.
6685: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6686: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6687: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6688: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6689: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6690: "\n";
1.145 raeburn 6691: my (%current,%canselect);
1.152 raeburn 6692: my @choices =
6693: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6694: foreach my $type ('primary','default') {
6695: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6696: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6697: my @spares = @{$spareid->{$server}{$type}};
6698: if (@spares > 0) {
1.152 raeburn 6699: if ($othercontrol) {
6700: $current{$type} = join(', ',@spares);
6701: } else {
6702: $current{$type} .= '<table>';
6703: my $numspares = scalar(@spares);
6704: for (my $i=0; $i<@spares; $i++) {
6705: my $rem = $i%($numinrow);
6706: if ($rem == 0) {
6707: if ($i > 0) {
6708: $current{$type} .= '</tr>';
6709: }
6710: $current{$type} .= '<tr>';
1.145 raeburn 6711: }
1.152 raeburn 6712: $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'".');" /> '.
6713: $spareid->{$server}{$type}[$i].
6714: '</label></td>'."\n";
6715: }
6716: my $rem = @spares%($numinrow);
6717: my $colsleft = $numinrow - $rem;
6718: if ($colsleft > 1 ) {
6719: $current{$type} .= '<td colspan="'.$colsleft.
6720: '" class="LC_left_item">'.
6721: ' </td>';
6722: } elsif ($colsleft == 1) {
6723: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6724: }
1.152 raeburn 6725: $current{$type} .= '</tr></table>';
1.150 raeburn 6726: }
1.145 raeburn 6727: }
6728: }
6729: if ($current{$type} eq '') {
6730: $current{$type} = &mt('None specified');
6731: }
1.152 raeburn 6732: if ($othercontrol) {
6733: if ($type eq 'primary') {
6734: $canselect{$type} = $othercontrol;
6735: }
6736: } else {
6737: $canselect{$type} =
6738: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6739: '<select name="newspare_'.$type.'_'.$server.'" '.
6740: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6741: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6742: if (@choices > 0) {
6743: foreach my $lonhost (@choices) {
6744: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6745: }
6746: }
6747: $canselect{$type} .= '</select>'."\n";
6748: }
6749: } else {
6750: $current{$type} = &mt('Could not be determined');
6751: if ($type eq 'primary') {
6752: $canselect{$type} = $othercontrol;
6753: }
1.145 raeburn 6754: }
1.152 raeburn 6755: if ($type eq 'default') {
6756: $datatable .= '<tr'.$css_class.'>';
6757: }
6758: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6759: '<td>'.$current{$type}.'</td>'."\n".
6760: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6761: }
6762: $itemcount ++;
6763: }
6764: }
6765: $$rowtotal += $itemcount;
6766: return $datatable;
6767: }
6768:
1.152 raeburn 6769: sub possible_newspares {
6770: my ($server,$currspares,$serverhomes,$altids) = @_;
6771: my $serverhostname = &Apache::lonnet::hostname($server);
6772: my %excluded;
6773: if ($serverhostname ne '') {
6774: %excluded = (
6775: $serverhostname => 1,
6776: );
6777: }
6778: if (ref($currspares) eq 'HASH') {
6779: foreach my $type (keys(%{$currspares})) {
6780: if (ref($currspares->{$type}) eq 'ARRAY') {
6781: if (@{$currspares->{$type}} > 0) {
6782: foreach my $curr (@{$currspares->{$type}}) {
6783: my $hostname = &Apache::lonnet::hostname($curr);
6784: $excluded{$hostname} = 1;
6785: }
6786: }
6787: }
6788: }
6789: }
6790: my @choices;
6791: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6792: if (keys(%{$serverhomes}) > 1) {
6793: foreach my $name (sort(keys(%{$serverhomes}))) {
6794: unless ($excluded{$name}) {
6795: if (exists($altids->{$serverhomes->{$name}})) {
6796: push(@choices,$altids->{$serverhomes->{$name}});
6797: } else {
6798: push(@choices,$serverhomes->{$name});
1.145 raeburn 6799: }
6800: }
6801: }
6802: }
6803: }
1.152 raeburn 6804: return sort(@choices);
1.145 raeburn 6805: }
6806:
1.150 raeburn 6807: sub print_loadbalancing {
6808: my ($dom,$settings,$rowtotal) = @_;
6809: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6810: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6811: my $numinrow = 1;
6812: my $datatable;
6813: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 6814: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 6815: if (ref($settings) eq 'HASH') {
6816: %existing = %{$settings};
6817: }
6818: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
6819: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 6820: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 6821: } else {
6822: return;
6823: }
6824: my ($othertitle,$usertypes,$types) =
6825: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 6826: my $rownum = 8;
1.150 raeburn 6827: if (ref($types) eq 'ARRAY') {
6828: $rownum += scalar(@{$types});
6829: }
1.171 raeburn 6830: my @css_class = ('LC_odd_row','LC_even_row');
6831: my $balnum = 0;
6832: my $islast;
6833: my (@toshow,$disabledtext);
6834: if (keys(%currbalancer) > 0) {
6835: @toshow = sort(keys(%currbalancer));
6836: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
6837: push(@toshow,'');
6838: }
6839: } else {
6840: @toshow = ('');
6841: $disabledtext = &mt('No existing load balancer');
6842: }
6843: foreach my $lonhost (@toshow) {
6844: if ($balnum == scalar(@toshow)-1) {
6845: $islast = 1;
6846: } else {
6847: $islast = 0;
6848: }
6849: my $cssidx = $balnum%2;
6850: my $targets_div_style = 'display: none';
6851: my $disabled_div_style = 'display: block';
6852: my $homedom_div_style = 'display: none';
6853: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 6854: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6855: '<p>';
6856: if ($lonhost eq '') {
1.210 raeburn 6857: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 6858: if (keys(%currbalancer) > 0) {
6859: $datatable .= &mt('Add balancer:');
6860: } else {
6861: $datatable .= &mt('Enable balancer:');
6862: }
6863: $datatable .= ' '.
6864: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
6865: ' id="loadbalancing_lonhost_'.$balnum.'"'.
6866: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
6867: '<option value="" selected="selected">'.&mt('None').
6868: '</option>'."\n";
6869: foreach my $server (sort(keys(%servers))) {
6870: next if ($currbalancer{$server});
6871: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
6872: }
1.210 raeburn 6873: $datatable .=
1.171 raeburn 6874: '</select>'."\n".
6875: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
6876: } else {
6877: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
6878: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
6879: &mt('Stop balancing').'</label>'.
6880: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
6881: $targets_div_style = 'display: block';
6882: $disabled_div_style = 'display: none';
6883: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
6884: $homedom_div_style = 'display: block';
6885: }
6886: }
1.306 raeburn 6887: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 6888: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
6889: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
6890: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
6891: my ($numspares,@spares) = &count_servers($lonhost,%servers);
6892: my @sparestypes = ('primary','default');
6893: my %typetitles = &sparestype_titles();
1.284 raeburn 6894: my %hostherechecked = (
6895: no => ' checked="checked"',
6896: );
1.342 raeburn 6897: my %balcookiechecked = (
6898: no => ' checked="checked"',
6899: );
1.171 raeburn 6900: foreach my $sparetype (@sparestypes) {
6901: my $targettable;
6902: for (my $i=0; $i<$numspares; $i++) {
6903: my $checked;
6904: if (ref($currtargets{$lonhost}) eq 'HASH') {
6905: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6906: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6907: $checked = ' checked="checked"';
6908: }
6909: }
6910: }
6911: my ($chkboxval,$disabled);
6912: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
6913: $chkboxval = $spares[$i];
6914: }
6915: if (exists($currbalancer{$spares[$i]})) {
6916: $disabled = ' disabled="disabled"';
6917: }
1.210 raeburn 6918: $targettable .=
1.253 raeburn 6919: '<td><span class="LC_nobreak"><label>'.
6920: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 6921: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 6922: '</span></label></span></td>';
1.171 raeburn 6923: my $rem = $i%($numinrow);
6924: if ($rem == 0) {
6925: if (($i > 0) && ($i < $numspares-1)) {
6926: $targettable .= '</tr>';
6927: }
6928: if ($i < $numspares-1) {
6929: $targettable .= '<tr>';
1.150 raeburn 6930: }
6931: }
6932: }
1.171 raeburn 6933: if ($targettable ne '') {
6934: my $rem = $numspares%($numinrow);
6935: my $colsleft = $numinrow - $rem;
6936: if ($colsleft > 1 ) {
6937: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6938: ' </td>';
6939: } elsif ($colsleft == 1) {
6940: $targettable .= '<td class="LC_left_item"> </td>';
6941: }
6942: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
6943: '<table><tr>'.$targettable.'</tr></table><br />';
6944: }
1.284 raeburn 6945: $hostherechecked{$sparetype} = '';
6946: if (ref($currtargets{$lonhost}) eq 'HASH') {
6947: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
6948: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
6949: $hostherechecked{$sparetype} = ' checked="checked"';
6950: $hostherechecked{'no'} = '';
6951: }
6952: }
6953: }
6954: }
1.342 raeburn 6955: if ($currcookies{$lonhost}) {
6956: %balcookiechecked = (
6957: yes => ' checked="checked"',
6958: );
6959: }
1.284 raeburn 6960: $datatable .= &mt('Hosting on balancer itself').'<br />'.
6961: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
6962: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
6963: foreach my $sparetype (@sparestypes) {
6964: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
6965: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
6966: '</i></label><br />';
1.171 raeburn 6967: }
1.342 raeburn 6968: $datatable .= &mt('Use balancer cookie').'<br />'.
6969: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
6970: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
6971: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
6972: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
6973: '</div></td></tr>'.
1.171 raeburn 6974: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
6975: $othertitle,$usertypes,$types,\%servers,
6976: \%currbalancer,$lonhost,
6977: $targets_div_style,$homedom_div_style,
6978: $css_class[$cssidx],$balnum,$islast);
6979: $$rowtotal += $rownum;
6980: $balnum ++;
6981: }
6982: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
6983: return $datatable;
6984: }
6985:
6986: sub get_loadbalancers_config {
1.342 raeburn 6987: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 6988: return unless ((ref($servers) eq 'HASH') &&
6989: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 6990: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
6991: (ref($currcookies) eq 'HASH'));
1.171 raeburn 6992: if (keys(%{$existing}) > 0) {
6993: my $oldlonhost;
6994: foreach my $key (sort(keys(%{$existing}))) {
6995: if ($key eq 'lonhost') {
6996: $oldlonhost = $existing->{'lonhost'};
6997: $currbalancer->{$oldlonhost} = 1;
6998: } elsif ($key eq 'targets') {
6999: if ($oldlonhost) {
7000: $currtargets->{$oldlonhost} = $existing->{'targets'};
7001: }
7002: } elsif ($key eq 'rules') {
7003: if ($oldlonhost) {
7004: $currrules->{$oldlonhost} = $existing->{'rules'};
7005: }
7006: } elsif (ref($existing->{$key}) eq 'HASH') {
7007: $currbalancer->{$key} = 1;
7008: $currtargets->{$key} = $existing->{$key}{'targets'};
7009: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 7010: if ($existing->{$key}{'cookie'}) {
7011: $currcookies->{$key} = 1;
7012: }
1.150 raeburn 7013: }
7014: }
1.171 raeburn 7015: } else {
7016: my ($balancerref,$targetsref) =
7017: &Apache::lonnet::get_lonbalancer_config($servers);
7018: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7019: foreach my $server (sort(keys(%{$balancerref}))) {
7020: $currbalancer->{$server} = 1;
7021: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7022: }
7023: }
7024: }
1.171 raeburn 7025: return;
1.150 raeburn 7026: }
7027:
7028: sub loadbalancing_rules {
7029: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 7030: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7031: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7032: my $output;
1.171 raeburn 7033: my $num = 0;
1.210 raeburn 7034: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7035: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7036: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7037: foreach my $type (@{$alltypes}) {
1.171 raeburn 7038: $num ++;
1.150 raeburn 7039: my $current;
7040: if (ref($currrules) eq 'HASH') {
7041: $current = $currrules->{$type};
7042: }
1.253 raeburn 7043: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 7044: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7045: $current = '';
7046: }
7047: }
7048: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 7049: $servers,$currbalancer,$lonhost,$dom,
7050: $targets_div_style,$homedom_div_style,
7051: $css_class,$balnum,$num,$islast);
1.150 raeburn 7052: }
7053: }
7054: return $output;
7055: }
7056:
7057: sub loadbalancing_titles {
7058: my ($dom,$intdom,$usertypes,$types) = @_;
7059: my %othertypes = (
7060: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7061: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7062: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7063: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 7064: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7065: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7066: );
1.209 raeburn 7067: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 7068: my @available;
1.150 raeburn 7069: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7070: @available = @{$types};
1.150 raeburn 7071: }
1.302 raeburn 7072: unless (grep(/^default$/,@available)) {
7073: push(@available,'default');
7074: }
7075: unshift(@alltypes,@available);
1.150 raeburn 7076: my %titles;
7077: foreach my $type (@alltypes) {
7078: if ($type =~ /^_LC_/) {
7079: $titles{$type} = $othertypes{$type};
7080: } elsif ($type eq 'default') {
7081: $titles{$type} = &mt('All users from [_1]',$dom);
7082: if (ref($types) eq 'ARRAY') {
7083: if (@{$types} > 0) {
7084: $titles{$type} = &mt('Other users from [_1]',$dom);
7085: }
7086: }
7087: } elsif (ref($usertypes) eq 'HASH') {
7088: $titles{$type} = $usertypes->{$type};
7089: }
7090: }
7091: return (\@alltypes,\%othertypes,\%titles);
7092: }
7093:
7094: sub loadbalance_rule_row {
1.171 raeburn 7095: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7096: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 7097: my @rulenames;
1.150 raeburn 7098: my %ruletitles = &offloadtype_text();
1.209 raeburn 7099: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 7100: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7101: } else {
1.209 raeburn 7102: @rulenames = ('default','homeserver');
7103: if ($type eq '_LC_external') {
7104: push(@rulenames,'externalbalancer');
7105: } else {
7106: push(@rulenames,'specific');
7107: }
7108: push(@rulenames,'none');
1.150 raeburn 7109: }
7110: my $style = $targets_div_style;
1.253 raeburn 7111: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7112: $style = $homedom_div_style;
7113: }
1.171 raeburn 7114: my $space;
7115: if ($islast && $num == 1) {
1.317 raeburn 7116: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 7117: }
1.210 raeburn 7118: my $output =
1.306 raeburn 7119: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 7120: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7121: '<td valaign="top">'.$space.
7122: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7123: for (my $i=0; $i<@rulenames; $i++) {
7124: my $rule = $rulenames[$i];
7125: my ($checked,$extra);
7126: if ($rulenames[$i] eq 'default') {
7127: $rule = '';
7128: }
7129: if ($rulenames[$i] eq 'specific') {
7130: if (ref($servers) eq 'HASH') {
7131: my $default;
7132: if (($current ne '') && (exists($servers->{$current}))) {
7133: $checked = ' checked="checked"';
7134: }
7135: unless ($checked) {
7136: $default = ' selected="selected"';
7137: }
1.210 raeburn 7138: $extra =
1.171 raeburn 7139: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7140: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7141: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7142: '<option value=""'.$default.'></option>'."\n";
7143: foreach my $server (sort(keys(%{$servers}))) {
7144: if (ref($currbalancer) eq 'HASH') {
7145: next if (exists($currbalancer->{$server}));
7146: }
1.150 raeburn 7147: my $selected;
1.171 raeburn 7148: if ($server eq $current) {
1.150 raeburn 7149: $selected = ' selected="selected"';
7150: }
1.171 raeburn 7151: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7152: }
7153: $extra .= '</select>';
7154: }
7155: } elsif ($rule eq $current) {
7156: $checked = ' checked="checked"';
7157: }
7158: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 7159: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7160: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7161: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 7162: ')"'.$checked.' /> ';
7163: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7164: $output .= $ruletitles{'particular'};
7165: } else {
7166: $output .= $ruletitles{$rulenames[$i]};
7167: }
7168: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7169: }
7170: $output .= '</div></td></tr>'."\n";
7171: return $output;
7172: }
7173:
7174: sub offloadtype_text {
7175: my %ruletitles = &Apache::lonlocal::texthash (
7176: 'default' => 'Offloads to default destinations',
7177: 'homeserver' => "Offloads to user's home server",
7178: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7179: 'specific' => 'Offloads to specific server',
1.161 raeburn 7180: 'none' => 'No offload',
1.209 raeburn 7181: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7182: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 7183: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7184: );
7185: return %ruletitles;
7186: }
7187:
7188: sub sparestype_titles {
7189: my %typestitles = &Apache::lonlocal::texthash (
7190: 'primary' => 'primary',
7191: 'default' => 'default',
7192: );
7193: return %typestitles;
7194: }
7195:
1.28 raeburn 7196: sub contact_titles {
7197: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 7198: 'supportemail' => 'Support E-mail address',
7199: 'adminemail' => 'Default Server Admin E-mail address',
7200: 'errormail' => 'Error reports to be e-mailed to',
7201: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 7202: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7203: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 7204: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7205: 'requestsmail' => 'E-mail from course requests requiring approval',
7206: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 7207: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 7208: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 7209: 'errorthreshold' => 'Error/warning threshold for status e-mail',
7210: 'errorsysmail' => 'Error threshold for e-mail to core group',
7211: 'errorweights' => 'Weights used to compute error count',
7212: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7213: );
7214: my %short_titles = &Apache::lonlocal::texthash (
7215: adminemail => 'Admin E-mail address',
7216: supportemail => 'Support E-mail',
7217: );
7218: return (\%titles,\%short_titles);
7219: }
7220:
1.286 raeburn 7221: sub helpform_fields {
7222: my %titles = &Apache::lonlocal::texthash (
7223: 'username' => 'Name',
7224: 'user' => 'Username/domain',
7225: 'phone' => 'Phone',
7226: 'cc' => 'Cc e-mail',
7227: 'course' => 'Course Details',
7228: 'section' => 'Sections',
1.289 raeburn 7229: 'screenshot' => 'File upload',
1.286 raeburn 7230: );
7231: my @fields = ('username','phone','user','course','section','cc','screenshot');
7232: my %possoptions = (
7233: username => ['yes','no','req'],
1.289 raeburn 7234: phone => ['yes','no','req'],
1.286 raeburn 7235: user => ['yes','no'],
1.289 raeburn 7236: cc => ['yes','no'],
1.286 raeburn 7237: course => ['yes','no'],
7238: section => ['yes','no'],
7239: screenshot => ['yes','no'],
7240: );
7241: my %fieldoptions = &Apache::lonlocal::texthash (
7242: 'yes' => 'Optional',
7243: 'req' => 'Required',
7244: 'no' => "Not shown",
7245: );
7246: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7247: }
7248:
1.72 raeburn 7249: sub tool_titles {
7250: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 7251: aboutme => 'Personal web page',
1.86 raeburn 7252: blog => 'Blog',
1.162 raeburn 7253: webdav => 'WebDAV',
1.86 raeburn 7254: portfolio => 'Portfolio',
1.88 bisitz 7255: official => 'Official courses (with institutional codes)',
7256: unofficial => 'Unofficial courses',
1.98 raeburn 7257: community => 'Communities',
1.216 raeburn 7258: textbook => 'Textbook courses',
1.271 raeburn 7259: placement => 'Placement tests',
1.86 raeburn 7260: );
1.72 raeburn 7261: return %titles;
7262: }
7263:
1.101 raeburn 7264: sub courserequest_titles {
7265: my %titles = &Apache::lonlocal::texthash (
7266: official => 'Official',
7267: unofficial => 'Unofficial',
7268: community => 'Communities',
1.216 raeburn 7269: textbook => 'Textbook',
1.271 raeburn 7270: placement => 'Placement tests',
1.325 raeburn 7271: lti => 'LTI Provider',
1.101 raeburn 7272: norequest => 'Not allowed',
1.325 raeburn 7273: approval => 'Approval by DC',
1.101 raeburn 7274: validate => 'With validation',
7275: autolimit => 'Numerical limit',
1.103 raeburn 7276: unlimited => '(blank for unlimited)',
1.101 raeburn 7277: );
7278: return %titles;
7279: }
7280:
1.163 raeburn 7281: sub authorrequest_titles {
7282: my %titles = &Apache::lonlocal::texthash (
7283: norequest => 'Not allowed',
7284: approval => 'Approval by Dom. Coord.',
7285: automatic => 'Automatic approval',
7286: );
7287: return %titles;
1.210 raeburn 7288: }
1.163 raeburn 7289:
1.101 raeburn 7290: sub courserequest_conditions {
7291: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7292: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 7293: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7294: );
7295: return %conditions;
7296: }
7297:
7298:
1.27 raeburn 7299: sub print_usercreation {
1.30 raeburn 7300: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7301: my $numinrow = 4;
1.28 raeburn 7302: my $datatable;
7303: if ($position eq 'top') {
1.30 raeburn 7304: $$rowtotal ++;
1.34 raeburn 7305: my $rowcount = 0;
1.32 raeburn 7306: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7307: if (ref($rules) eq 'HASH') {
7308: if (keys(%{$rules}) > 0) {
1.32 raeburn 7309: $datatable .= &user_formats_row('username',$settings,$rules,
7310: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7311: $$rowtotal ++;
1.32 raeburn 7312: $rowcount ++;
7313: }
7314: }
7315: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7316: if (ref($idrules) eq 'HASH') {
7317: if (keys(%{$idrules}) > 0) {
7318: $datatable .= &user_formats_row('id',$settings,$idrules,
7319: $idruleorder,$numinrow,$rowcount);
7320: $$rowtotal ++;
7321: $rowcount ++;
1.28 raeburn 7322: }
7323: }
1.39 raeburn 7324: if ($rowcount == 0) {
7325: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7326: $$rowtotal ++;
7327: $rowcount ++;
7328: }
1.34 raeburn 7329: } elsif ($position eq 'middle') {
1.224 raeburn 7330: my @creators = ('author','course','requestcrs');
1.37 raeburn 7331: my ($rules,$ruleorder) =
7332: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7333: my %lt = &usercreation_types();
7334: my %checked;
7335: if (ref($settings) eq 'HASH') {
7336: if (ref($settings->{'cancreate'}) eq 'HASH') {
7337: foreach my $item (@creators) {
7338: $checked{$item} = $settings->{'cancreate'}{$item};
7339: }
7340: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7341: foreach my $item (@creators) {
7342: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7343: $checked{$item} = 'none';
7344: }
7345: }
7346: }
7347: }
7348: my $rownum = 0;
7349: foreach my $item (@creators) {
7350: $rownum ++;
1.224 raeburn 7351: if ($checked{$item} eq '') {
7352: $checked{$item} = 'any';
1.34 raeburn 7353: }
7354: my $css_class;
7355: if ($rownum%2) {
7356: $css_class = '';
7357: } else {
7358: $css_class = ' class="LC_odd_row" ';
7359: }
7360: $datatable .= '<tr'.$css_class.'>'.
7361: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 7362: '</span></td><td style="text-align: right">';
1.224 raeburn 7363: my @options = ('any');
7364: if (ref($rules) eq 'HASH') {
7365: if (keys(%{$rules}) > 0) {
7366: push(@options,('official','unofficial'));
1.37 raeburn 7367: }
7368: }
1.224 raeburn 7369: push(@options,'none');
1.37 raeburn 7370: foreach my $option (@options) {
1.50 raeburn 7371: my $type = 'radio';
1.34 raeburn 7372: my $check = ' ';
1.224 raeburn 7373: if ($checked{$item} eq $option) {
7374: $check = ' checked="checked" ';
1.34 raeburn 7375: }
7376: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7377: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7378: $item.'" value="'.$option.'"'.$check.'/> '.
7379: $lt{$option}.'</label> </span>';
7380: }
7381: $datatable .= '</td></tr>';
7382: }
1.28 raeburn 7383: } else {
7384: my @contexts = ('author','course','domain');
1.325 raeburn 7385: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 7386: my %checked;
7387: if (ref($settings) eq 'HASH') {
7388: if (ref($settings->{'authtypes'}) eq 'HASH') {
7389: foreach my $item (@contexts) {
7390: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7391: foreach my $auth (@authtypes) {
7392: if ($settings->{'authtypes'}{$item}{$auth}) {
7393: $checked{$item}{$auth} = ' checked="checked" ';
7394: }
7395: }
7396: }
7397: }
1.27 raeburn 7398: }
1.35 raeburn 7399: } else {
7400: foreach my $item (@contexts) {
1.36 raeburn 7401: foreach my $auth (@authtypes) {
1.35 raeburn 7402: $checked{$item}{$auth} = ' checked="checked" ';
7403: }
7404: }
1.27 raeburn 7405: }
1.28 raeburn 7406: my %title = &context_names();
7407: my %authname = &authtype_names();
7408: my $rownum = 0;
7409: my $css_class;
7410: foreach my $item (@contexts) {
7411: if ($rownum%2) {
7412: $css_class = '';
7413: } else {
7414: $css_class = ' class="LC_odd_row" ';
7415: }
1.30 raeburn 7416: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7417: '<td>'.$title{$item}.
7418: '</td><td class="LC_left_item">'.
7419: '<span class="LC_nobreak">';
7420: foreach my $auth (@authtypes) {
7421: $datatable .= '<label>'.
7422: '<input type="checkbox" name="'.$item.'_auth" '.
7423: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7424: $authname{$auth}.'</label> ';
7425: }
7426: $datatable .= '</span></td></tr>';
7427: $rownum ++;
1.27 raeburn 7428: }
1.30 raeburn 7429: $$rowtotal += $rownum;
1.27 raeburn 7430: }
7431: return $datatable;
7432: }
7433:
1.224 raeburn 7434: sub print_selfcreation {
7435: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7436: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7437: $emaildomain,$datatable);
1.224 raeburn 7438: if (ref($settings) eq 'HASH') {
7439: if (ref($settings->{'cancreate'}) eq 'HASH') {
7440: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7441: if (ref($createsettings) eq 'HASH') {
7442: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7443: @selfcreate = @{$createsettings->{'selfcreate'}};
7444: } elsif ($createsettings->{'selfcreate'} ne '') {
7445: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7446: @selfcreate = ('email','login','sso');
7447: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7448: @selfcreate = ($createsettings->{'selfcreate'});
7449: }
7450: }
7451: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7452: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7453: }
1.305 raeburn 7454: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7455: $emailoptions = $createsettings->{'emailoptions'};
7456: }
1.303 raeburn 7457: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7458: $emailverified = $createsettings->{'emailverified'};
7459: }
7460: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7461: $emaildomain = $createsettings->{'emaildomain'};
7462: }
1.224 raeburn 7463: }
7464: }
7465: }
7466: my %radiohash;
7467: my $numinrow = 4;
7468: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7469: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7470: if ($position eq 'top') {
7471: my %choices = &Apache::lonlocal::texthash (
7472: cancreate_login => 'Institutional Login',
7473: cancreate_sso => 'Institutional Single Sign On',
7474: );
7475: my @toggles = sort(keys(%choices));
7476: my %defaultchecked = (
7477: 'cancreate_login' => 'off',
7478: 'cancreate_sso' => 'off',
7479: );
1.228 raeburn 7480: my ($onclick,$itemcount);
1.224 raeburn 7481: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7482: \%choices,$itemcount,$onclick);
1.228 raeburn 7483: $$rowtotal += $itemcount;
7484:
1.224 raeburn 7485: if (ref($usertypes) eq 'HASH') {
7486: if (keys(%{$usertypes}) > 0) {
7487: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7488: $dom,$numinrow,$othertitle,
1.305 raeburn 7489: 'statustocreate',$rowtotal);
1.224 raeburn 7490: $$rowtotal ++;
7491: }
7492: }
1.240 raeburn 7493: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7494: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7495: $fieldtitles{'inststatus'} = &mt('Institutional status');
7496: my $rem;
7497: my $numperrow = 2;
7498: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7499: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7500: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7501: '<td class="LC_left_item">'."\n".
1.334 raeburn 7502: '<table>'."\n";
1.240 raeburn 7503: for (my $i=0; $i<@fields; $i++) {
7504: $rem = $i%($numperrow);
7505: if ($rem == 0) {
7506: if ($i > 0) {
7507: $datatable .= '</tr>';
7508: }
7509: $datatable .= '<tr>';
7510: }
7511: my $currval;
1.248 raeburn 7512: if (ref($createsettings) eq 'HASH') {
7513: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7514: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7515: }
1.240 raeburn 7516: }
7517: $datatable .= '<td class="LC_left_item">'.
7518: '<span class="LC_nobreak">'.
7519: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7520: 'value="'.$currval.'" size="10" /> '.
7521: $fieldtitles{$fields[$i]}.'</span></td>';
7522: }
7523: my $colsleft = $numperrow - $rem;
7524: if ($colsleft > 1 ) {
7525: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7526: ' </td>';
7527: } elsif ($colsleft == 1) {
7528: $datatable .= '<td class="LC_left_item"> </td>';
7529: }
7530: $datatable .= '</tr></table></td></tr>';
7531: $$rowtotal ++;
1.224 raeburn 7532: } elsif ($position eq 'middle') {
7533: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7534: my @posstypes;
1.224 raeburn 7535: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7536: @posstypes = @{$types};
7537: }
7538: unless (grep(/^default$/,@posstypes)) {
7539: push(@posstypes,'default');
7540: }
7541: my %usertypeshash;
7542: if (ref($usertypes) eq 'HASH') {
7543: %usertypeshash = %{$usertypes};
7544: }
7545: $usertypeshash{'default'} = $othertitle;
7546: foreach my $status (@posstypes) {
7547: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7548: $numinrow,$$rowtotal,\%usertypeshash);
7549: $$rowtotal ++;
1.224 raeburn 7550: }
7551: } else {
1.236 raeburn 7552: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7553: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7554: );
7555: my @toggles = sort(keys(%choices));
7556: my %defaultchecked = (
7557: 'cancreate_email' => 'off',
7558: );
1.305 raeburn 7559: my $customclass = 'LC_selfcreate_email';
7560: my $classprefix = 'LC_canmodify_emailusername_';
7561: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7562: my $display = 'none';
1.305 raeburn 7563: my $rowstyle = 'display:none';
1.236 raeburn 7564: if (grep(/^\Qemail\E$/,@selfcreate)) {
7565: $display = 'block';
1.305 raeburn 7566: $rowstyle = 'display:table-row';
1.236 raeburn 7567: }
1.305 raeburn 7568: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7569: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7570: \%choices,$$rowtotal,$onclick);
7571: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7572: $rowstyle);
7573: $$rowtotal ++;
7574: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7575: $rowstyle);
7576: $$rowtotal ++;
7577: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7579: my ($emailrules,$emailruleorder) =
7580: &Apache::lonnet::inst_userrules($dom,'email');
7581: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7582: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7583: if (ref($types) eq 'ARRAY') {
7584: @posstypes = @{$types};
7585: }
7586: if (@posstypes) {
7587: unless (grep(/^default$/,@posstypes)) {
7588: push(@posstypes,'default');
1.302 raeburn 7589: }
7590: if (ref($usertypes) eq 'HASH') {
7591: %usertypeshash = %{$usertypes};
7592: }
1.305 raeburn 7593: my $currassign;
7594: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7595: $currassign = {
7596: selfassign => $domdefaults{'inststatusguest'},
7597: };
7598: @ordered = @{$domdefaults{'inststatusguest'}};
7599: } else {
7600: $currassign = { selfassign => [] };
7601: }
7602: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7603: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7604: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7605: $numinrow,$othertitle,'selfassign',
7606: $rowtotal,$onclicktypes,$customclass,
7607: $rowstyle);
7608: $$rowtotal ++;
1.302 raeburn 7609: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7610: foreach my $status (@posstypes) {
7611: my $css_class;
7612: if ($$rowtotal%2) {
7613: $css_class = 'LC_odd_row ';
7614: }
7615: $css_class .= $customclass;
7616: my $rowid = $optionsprefix.$status;
7617: my $hidden = 1;
7618: my $currstyle = 'display:none';
7619: if (grep(/^\Q$status\E$/,@ordered)) {
7620: $currstyle = $rowstyle;
7621: $hidden = 0;
7622: }
7623: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7624: $emailrules,$emailruleorder,$settings,$status,$rowid,
7625: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7626: unless ($hidden) {
7627: $$rowtotal ++;
7628: }
1.224 raeburn 7629: }
1.302 raeburn 7630: } else {
1.305 raeburn 7631: my $css_class;
7632: if ($$rowtotal%2) {
7633: $css_class = 'LC_odd_row ';
7634: }
7635: $css_class .= $customclass;
1.302 raeburn 7636: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7637: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7638: $emailrules,$emailruleorder,$settings,'default','',
7639: $othertitle,$css_class,$rowstyle,$intdom);
7640: $$rowtotal ++;
1.224 raeburn 7641: }
7642: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7643: $numinrow = 1;
1.305 raeburn 7644: if (@posstypes) {
7645: foreach my $status (@posstypes) {
7646: my $rowid = $classprefix.$status;
7647: my $datarowstyle = 'display:none';
7648: if (grep(/^\Q$status\E$/,@ordered)) {
7649: $datarowstyle = $rowstyle;
7650: }
7651: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7652: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7653: $infotitles,$rowid,$customclass,$datarowstyle);
7654: unless ($datarowstyle eq 'display:none') {
7655: $$rowtotal ++;
7656: }
1.224 raeburn 7657: }
1.305 raeburn 7658: } else {
7659: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7660: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7661: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7662: }
7663: }
7664: return $datatable;
7665: }
7666:
1.305 raeburn 7667: sub selfcreate_javascript {
7668: return <<"ENDSCRIPT";
7669:
7670: <script type="text/javascript">
7671: // <![CDATA[
7672:
7673: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7674: var x = document.getElementsByClassName(target);
7675: var insttypes = 0;
7676: var insttypeRegExp = new RegExp(prefix);
7677: if ((x.length != undefined) && (x.length > 0)) {
7678: if (form.elements[radio].length != undefined) {
7679: for (var i=0; i<form.elements[radio].length; i++) {
7680: if (form.elements[radio][i].checked) {
7681: if (form.elements[radio][i].value == 1) {
7682: for (var j=0; j<x.length; j++) {
7683: if (x[j].id == 'undefined') {
7684: x[j].style.display = 'table-row';
7685: } else if (insttypeRegExp.test(x[j].id)) {
7686: insttypes ++;
7687: } else {
7688: x[j].style.display = 'table-row';
7689: }
7690: }
7691: } else {
7692: for (var j=0; j<x.length; j++) {
7693: x[j].style.display = 'none';
7694: }
1.236 raeburn 7695: }
1.305 raeburn 7696: break;
7697: }
7698: }
7699: if (insttypes > 0) {
7700: toggleDataRow(form,checkbox,target,altprefix);
7701: toggleDataRow(form,checkbox,target,prefix,1);
7702: }
7703: }
7704: }
7705: return;
7706: }
7707:
7708: function toggleDataRow(form,checkbox,target,prefix,docount) {
7709: if (form.elements[checkbox].length != undefined) {
7710: var count = 0;
7711: if (docount) {
7712: for (var i=0; i<form.elements[checkbox].length; i++) {
7713: if (form.elements[checkbox][i].checked) {
7714: count ++;
1.236 raeburn 7715: }
1.305 raeburn 7716: }
7717: }
7718: for (var i=0; i<form.elements[checkbox].length; i++) {
7719: var type = form.elements[checkbox][i].value;
7720: if (document.getElementById(prefix+type)) {
7721: if (form.elements[checkbox][i].checked) {
7722: document.getElementById(prefix+type).style.display = 'table-row';
7723: if (count % 2 == 1) {
7724: document.getElementById(prefix+type).className = target+' LC_odd_row';
7725: } else {
7726: document.getElementById(prefix+type).className = target;
1.236 raeburn 7727: }
1.305 raeburn 7728: count ++;
1.236 raeburn 7729: } else {
1.305 raeburn 7730: document.getElementById(prefix+type).style.display = 'none';
7731: }
7732: }
7733: }
7734: }
7735: return;
7736: }
7737:
7738: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7739: var caller = radio+'_'+status;
7740: if (form.elements[caller].length != undefined) {
7741: for (var i=0; i<form.elements[caller].length; i++) {
7742: if (form.elements[caller][i].checked) {
7743: if (document.getElementById(altprefix+'_inst_'+status)) {
7744: var curr = form.elements[caller][i].value;
7745: if (prefix) {
7746: document.getElementById(prefix+'_'+status).style.display = 'none';
7747: }
7748: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7749: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7750: if (curr == 'custom') {
7751: if (prefix) {
7752: document.getElementById(prefix+'_'+status).style.display = 'inline';
7753: }
7754: } else if (curr == 'inst') {
7755: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7756: } else if (curr == 'noninst') {
7757: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7758: }
1.305 raeburn 7759: break;
1.236 raeburn 7760: }
7761: }
7762: }
7763: }
7764: }
7765:
1.305 raeburn 7766: // ]]>
7767: </script>
7768:
7769: ENDSCRIPT
7770: }
7771:
7772: sub noninst_users {
7773: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7774: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7775: my $class = 'LC_left_item';
7776: if ($css_class) {
7777: $css_class = ' class="'.$css_class.'"';
7778: }
7779: if ($rowid) {
7780: $rowid = ' id="'.$rowid.'"';
7781: }
7782: if ($rowstyle) {
7783: $rowstyle = ' style="'.$rowstyle.'"';
7784: }
7785: my ($output,$description);
7786: if ($type eq 'default') {
7787: $description = &mt('Requests for: [_1]',$typetitle);
7788: } else {
7789: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7790: }
7791: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7792: "<td>$description</td>\n".
7793: '<td class="'.$class.'" colspan="2">'.
7794: '<table><tr>';
7795: my %headers = &Apache::lonlocal::texthash(
7796: approve => 'Processing',
7797: email => 'E-mail',
7798: username => 'Username',
7799: );
7800: foreach my $item ('approve','email','username') {
7801: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7802: }
1.305 raeburn 7803: $output .= '</tr><tr>';
7804: foreach my $item ('approve','email','username') {
1.306 raeburn 7805: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7806: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7807: if ($item eq 'approve') {
7808: %choices = &Apache::lonlocal::texthash (
7809: automatic => 'Automatically approved',
7810: approval => 'Queued for approval',
7811: );
7812: @options = ('automatic','approval');
7813: $hashref = $processing;
7814: $defoption = 'automatic';
7815: $name = 'cancreate_emailprocess_'.$type;
7816: } elsif ($item eq 'email') {
7817: %choices = &Apache::lonlocal::texthash (
7818: any => 'Any e-mail',
7819: inst => 'Institutional only',
7820: noninst => 'Non-institutional only',
7821: custom => 'Custom restrictions',
7822: );
7823: @options = ('any','inst','noninst');
7824: my $showcustom;
7825: if (ref($emailrules) eq 'HASH') {
7826: if (keys(%{$emailrules}) > 0) {
7827: push(@options,'custom');
7828: $showcustom = 'cancreate_emailrule';
7829: if (ref($settings) eq 'HASH') {
7830: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
7831: foreach my $rule (@{$settings->{'email_rule'}}) {
7832: if (exists($emailrules->{$rule})) {
7833: $hascustom ++;
7834: }
7835: }
7836: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
7837: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
7838: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
7839: if (exists($emailrules->{$rule})) {
7840: $hascustom ++;
7841: }
7842: }
7843: }
7844: }
7845: }
7846: }
7847: }
7848: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
7849: "'cancreate_emaildomain','$type'".');"';
7850: $hashref = $emailoptions;
7851: $defoption = 'any';
7852: $name = 'cancreate_emailoptions_'.$type;
7853: } elsif ($item eq 'username') {
7854: %choices = &Apache::lonlocal::texthash (
7855: all => 'Same as e-mail',
7856: first => 'Omit @domain',
7857: free => 'Free to choose',
7858: );
7859: @options = ('all','first','free');
7860: $hashref = $emailverified;
7861: $defoption = 'all';
7862: $name = 'cancreate_usernameoptions_'.$type;
7863: }
7864: foreach my $option (@options) {
7865: my $checked;
7866: if (ref($hashref) eq 'HASH') {
7867: if ($type eq '') {
7868: if (!exists($hashref->{'default'})) {
7869: if ($option eq $defoption) {
7870: $checked = ' checked="checked"';
7871: }
7872: } else {
7873: if ($hashref->{'default'} eq $option) {
7874: $checked = ' checked="checked"';
7875: }
1.303 raeburn 7876: }
7877: } else {
1.305 raeburn 7878: if (!exists($hashref->{$type})) {
7879: if ($option eq $defoption) {
7880: $checked = ' checked="checked"';
7881: }
7882: } else {
7883: if ($hashref->{$type} eq $option) {
7884: $checked = ' checked="checked"';
7885: }
1.303 raeburn 7886: }
7887: }
1.305 raeburn 7888: } elsif (($item eq 'email') && ($hascustom)) {
7889: if ($option eq 'custom') {
7890: $checked = ' checked="checked"';
7891: }
7892: } elsif ($option eq $defoption) {
7893: $checked = ' checked="checked"';
7894: }
7895: $output .= '<span class="LC_nobreak"><label>'.
7896: '<input type="radio" name="'.$name.'"'.
7897: $checked.' value="'.$option.'"'.$onclick.' />'.
7898: $choices{$option}.'</label></span><br />';
7899: if ($item eq 'email') {
7900: if ($option eq 'custom') {
7901: my $id = 'cancreate_emailrule_'.$type;
7902: my $display = 'none';
7903: if ($checked) {
7904: $display = 'inline';
1.303 raeburn 7905: }
1.305 raeburn 7906: my $numinrow = 2;
7907: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
7908: '<legend>'.&mt('Disallow').'</legend><table>'.
7909: &user_formats_row('email',$settings,$emailrules,
7910: $emailruleorder,$numinrow,'',$type);
7911: '</table></fieldset>';
7912: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
7913: my %text = &Apache::lonlocal::texthash (
7914: inst => 'must end:',
7915: noninst => 'cannot end:',
7916: );
7917: my $value;
7918: if (ref($emaildomain) eq 'HASH') {
7919: if (ref($emaildomain->{$type}) eq 'HASH') {
7920: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 7921: }
7922: }
1.305 raeburn 7923: if ($value eq '') {
7924: $value = '@'.$intdom;
7925: }
7926: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
7927: my $display = 'none';
7928: if ($checked) {
7929: $display = 'inline';
7930: }
7931: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
7932: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
7933: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
7934: '</div>';
1.303 raeburn 7935: }
7936: }
7937: }
1.305 raeburn 7938: $output .= '</td>'."\n";
1.303 raeburn 7939: }
1.305 raeburn 7940: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 7941: return $output;
7942: }
7943:
1.165 raeburn 7944: sub captcha_choice {
1.305 raeburn 7945: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 7946: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
7947: $vertext,$currver);
1.165 raeburn 7948: my %lt = &captcha_phrases();
7949: $keyentry = 'hidden';
1.354 raeburn 7950: my $colspan=2;
1.165 raeburn 7951: if ($context eq 'cancreate') {
1.224 raeburn 7952: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 7953: } elsif ($context eq 'login') {
7954: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 7955: } elsif ($context eq 'passwords') {
7956: $rowname = &mt('"Forgot Password" CAPTCHA validation');
7957: $colspan=1;
1.165 raeburn 7958: }
7959: if (ref($settings) eq 'HASH') {
7960: if ($settings->{'captcha'}) {
7961: $checked{$settings->{'captcha'}} = ' checked="checked"';
7962: } else {
7963: $checked{'original'} = ' checked="checked"';
7964: }
7965: if ($settings->{'captcha'} eq 'recaptcha') {
7966: $pubtext = $lt{'pub'};
7967: $privtext = $lt{'priv'};
7968: $keyentry = 'text';
1.269 raeburn 7969: $vertext = $lt{'ver'};
7970: $currver = $settings->{'recaptchaversion'};
7971: if ($currver ne '2') {
7972: $currver = 1;
7973: }
1.165 raeburn 7974: }
7975: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
7976: $currpub = $settings->{'recaptchakeys'}{'public'};
7977: $currpriv = $settings->{'recaptchakeys'}{'private'};
7978: }
7979: } else {
7980: $checked{'original'} = ' checked="checked"';
7981: }
1.305 raeburn 7982: my $css_class;
7983: if ($itemcount%2) {
7984: $css_class = 'LC_odd_row';
7985: }
7986: if ($customcss) {
7987: $css_class .= " $customcss";
7988: }
7989: $css_class =~ s/^\s+//;
7990: if ($css_class) {
7991: $css_class = ' class="'.$css_class.'"';
7992: }
7993: if ($rowstyle) {
7994: $css_class .= ' style="'.$rowstyle.'"';
7995: }
1.169 raeburn 7996: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 7997: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 7998: '<table><tr><td>'."\n";
7999: foreach my $option ('original','recaptcha','notused') {
8000: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8001: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8002: $lt{$option}.'</label></span>';
8003: unless ($option eq 'notused') {
8004: $output .= (' 'x2)."\n";
8005: }
8006: }
8007: #
8008: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8009: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 8010: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 8011: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 8012: #
1.165 raeburn 8013: $output .= '</td></tr>'."\n".
1.305 raeburn 8014: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 8015: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8016: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8017: $currpub.'" size="40" /></span><br />'."\n".
8018: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8019: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 8020: $currpriv.'" size="40" /></span><br />'.
8021: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8022: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8023: $currver.'" size="3" /></span><br />'.
8024: '</td></tr></table>'."\n".
1.165 raeburn 8025: '</td></tr>';
8026: return $output;
8027: }
8028:
1.32 raeburn 8029: sub user_formats_row {
1.305 raeburn 8030: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8031: my $output;
8032: my %text = (
8033: 'username' => 'new usernames',
8034: 'id' => 'IDs',
8035: );
1.305 raeburn 8036: unless ($type eq 'email') {
8037: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8038: $output = '<tr '.$css_class.'>'.
8039: '<td><span class="LC_nobreak">'.
8040: &mt("Format rules to check for $text{$type}: ").
8041: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8042: }
1.27 raeburn 8043: my $rem;
8044: if (ref($ruleorder) eq 'ARRAY') {
8045: for (my $i=0; $i<@{$ruleorder}; $i++) {
8046: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8047: my $rem = $i%($numinrow);
8048: if ($rem == 0) {
8049: if ($i > 0) {
8050: $output .= '</tr>';
8051: }
8052: $output .= '<tr>';
8053: }
8054: my $check = ' ';
1.39 raeburn 8055: if (ref($settings) eq 'HASH') {
8056: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8057: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8058: $check = ' checked="checked" ';
8059: }
1.305 raeburn 8060: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8061: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8062: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8063: $check = ' checked="checked" ';
8064: }
8065: }
1.27 raeburn 8066: }
8067: }
1.305 raeburn 8068: my $name = $type.'_rule';
8069: if ($type eq 'email') {
8070: $name .= '_'.$status;
8071: }
1.27 raeburn 8072: $output .= '<td class="LC_left_item">'.
8073: '<span class="LC_nobreak"><label>'.
1.311 raeburn 8074: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8075: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8076: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8077: }
8078: }
8079: $rem = @{$ruleorder}%($numinrow);
8080: }
1.305 raeburn 8081: my $colsleft;
8082: if ($rem) {
8083: $colsleft = $numinrow - $rem;
8084: }
1.27 raeburn 8085: if ($colsleft > 1 ) {
8086: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8087: ' </td>';
8088: } elsif ($colsleft == 1) {
8089: $output .= '<td class="LC_left_item"> </td>';
8090: }
1.305 raeburn 8091: $output .= '</tr></table>';
8092: unless ($type eq 'email') {
8093: $output .= '</td></tr>';
8094: }
1.27 raeburn 8095: return $output;
8096: }
8097:
1.34 raeburn 8098: sub usercreation_types {
8099: my %lt = &Apache::lonlocal::texthash (
8100: author => 'When adding a co-author',
8101: course => 'When adding a user to a course',
1.100 raeburn 8102: requestcrs => 'When requesting a course',
1.34 raeburn 8103: any => 'Any',
8104: official => 'Institutional only ',
8105: unofficial => 'Non-institutional only',
8106: none => 'None',
8107: );
8108: return %lt;
1.48 raeburn 8109: }
1.34 raeburn 8110:
1.224 raeburn 8111: sub selfcreation_types {
8112: my %lt = &Apache::lonlocal::texthash (
8113: selfcreate => 'User creates own account',
8114: any => 'Any',
8115: official => 'Institutional only ',
8116: unofficial => 'Non-institutional only',
8117: email => 'E-mail address',
8118: login => 'Institutional Login',
8119: sso => 'SSO',
8120: );
8121: }
8122:
1.28 raeburn 8123: sub authtype_names {
8124: my %lt = &Apache::lonlocal::texthash(
8125: int => 'Internal',
8126: krb4 => 'Kerberos 4',
8127: krb5 => 'Kerberos 5',
8128: loc => 'Local',
1.325 raeburn 8129: lti => 'LTI',
1.28 raeburn 8130: );
8131: return %lt;
8132: }
8133:
8134: sub context_names {
8135: my %context_title = &Apache::lonlocal::texthash(
8136: author => 'Creating users when an Author',
8137: course => 'Creating users when in a course',
8138: domain => 'Creating users when a Domain Coordinator',
8139: );
8140: return %context_title;
8141: }
8142:
1.33 raeburn 8143: sub print_usermodification {
8144: my ($position,$dom,$settings,$rowtotal) = @_;
8145: my $numinrow = 4;
8146: my ($context,$datatable,$rowcount);
8147: if ($position eq 'top') {
8148: $rowcount = 0;
8149: $context = 'author';
8150: foreach my $role ('ca','aa') {
8151: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8152: $numinrow,$rowcount);
8153: $$rowtotal ++;
8154: $rowcount ++;
8155: }
1.230 raeburn 8156: } elsif ($position eq 'bottom') {
1.33 raeburn 8157: $context = 'course';
8158: $rowcount = 0;
8159: foreach my $role ('st','ep','ta','in','cr') {
8160: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8161: $numinrow,$rowcount);
8162: $$rowtotal ++;
8163: $rowcount ++;
8164: }
8165: }
8166: return $datatable;
8167: }
8168:
1.43 raeburn 8169: sub print_defaults {
1.236 raeburn 8170: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8171: my $rownum = 0;
1.294 raeburn 8172: my ($datatable,$css_class,$titles);
8173: unless ($position eq 'bottom') {
8174: $titles = &defaults_titles($dom);
8175: }
1.236 raeburn 8176: if ($position eq 'top') {
8177: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8178: 'datelocale_def','portal_def');
8179: my %defaults;
8180: if (ref($settings) eq 'HASH') {
8181: %defaults = %{$settings};
1.43 raeburn 8182: } else {
1.236 raeburn 8183: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8184: foreach my $item (@items) {
8185: $defaults{$item} = $domdefaults{$item};
8186: }
1.43 raeburn 8187: }
1.236 raeburn 8188: foreach my $item (@items) {
8189: if ($rownum%2) {
8190: $css_class = '';
8191: } else {
8192: $css_class = ' class="LC_odd_row" ';
8193: }
8194: $datatable .= '<tr'.$css_class.'>'.
8195: '<td><span class="LC_nobreak">'.$titles->{$item}.
8196: '</span></td><td class="LC_right_item" colspan="3">';
8197: if ($item eq 'auth_def') {
1.325 raeburn 8198: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 8199: my %shortauth = (
8200: internal => 'int',
8201: krb4 => 'krb4',
8202: krb5 => 'krb5',
1.325 raeburn 8203: localauth => 'loc',
8204: lti => 'lti',
1.236 raeburn 8205: );
8206: my %authnames = &authtype_names();
8207: foreach my $auth (@authtypes) {
8208: my $checked = ' ';
8209: if ($defaults{$item} eq $auth) {
8210: $checked = ' checked="checked" ';
8211: }
8212: $datatable .= '<label><input type="radio" name="'.$item.
8213: '" value="'.$auth.'"'.$checked.'/>'.
8214: $authnames{$shortauth{$auth}}.'</label> ';
8215: }
8216: } elsif ($item eq 'timezone_def') {
8217: my $includeempty = 1;
8218: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8219: } elsif ($item eq 'datelocale_def') {
8220: my $includeempty = 1;
8221: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8222: } elsif ($item eq 'lang_def') {
1.263 raeburn 8223: my $includeempty = 1;
8224: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 8225: } else {
8226: my $size;
8227: if ($item eq 'portal_def') {
8228: $size = ' size="25"';
8229: }
8230: $datatable .= '<input type="text" name="'.$item.'" value="'.
8231: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 8232: }
1.236 raeburn 8233: $datatable .= '</td></tr>';
8234: $rownum ++;
8235: }
1.354 raeburn 8236: } else {
1.294 raeburn 8237: my %defaults;
8238: if (ref($settings) eq 'HASH') {
1.354 raeburn 8239: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8240: my $maxnum = @{$settings->{'inststatusorder'}};
8241: for (my $i=0; $i<$maxnum; $i++) {
8242: $css_class = $rownum%2?' class="LC_odd_row"':'';
8243: my $item = $settings->{'inststatusorder'}->[$i];
8244: my $title = $settings->{'inststatustypes'}->{$item};
8245: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8246: $datatable .= '<tr'.$css_class.'>'.
8247: '<td><span class="LC_nobreak">'.
8248: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8249: for (my $k=0; $k<=$maxnum; $k++) {
8250: my $vpos = $k+1;
8251: my $selstr;
8252: if ($k == $i) {
8253: $selstr = ' selected="selected" ';
8254: }
8255: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8256: }
8257: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8258: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8259: &mt('delete').'</span></td>'.
8260: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
8261: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8262: '</span></td></tr>';
8263: }
8264: $css_class = $rownum%2?' class="LC_odd_row"':'';
8265: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8266: $datatable .= '<tr '.$css_class.'>'.
8267: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8268: for (my $k=0; $k<=$maxnum; $k++) {
8269: my $vpos = $k+1;
8270: my $selstr;
8271: if ($k == $maxnum) {
8272: $selstr = ' selected="selected" ';
8273: }
8274: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8275: }
8276: $datatable .= '</select> '.&mt('Internal ID:').
8277: '<input type="text" size="10" name="addinststatus" value="" />'.
8278: ' '.&mt('(new)').
8279: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
8280: &mt('Name displayed:').
8281: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8282: '</tr>'."\n";
8283: $rownum ++;
1.294 raeburn 8284: }
1.354 raeburn 8285: }
8286: }
8287: $$rowtotal += $rownum;
1.43 raeburn 8288: return $datatable;
8289: }
8290:
1.168 raeburn 8291: sub get_languages_hash {
8292: my %langchoices;
8293: foreach my $id (&Apache::loncommon::languageids()) {
8294: my $code = &Apache::loncommon::supportedlanguagecode($id);
8295: if ($code ne '') {
8296: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8297: }
8298: }
8299: return %langchoices;
8300: }
8301:
1.43 raeburn 8302: sub defaults_titles {
1.141 raeburn 8303: my ($dom) = @_;
1.43 raeburn 8304: my %titles = &Apache::lonlocal::texthash (
8305: 'auth_def' => 'Default authentication type',
8306: 'auth_arg_def' => 'Default authentication argument',
8307: 'lang_def' => 'Default language',
1.54 raeburn 8308: 'timezone_def' => 'Default timezone',
1.68 raeburn 8309: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8310: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 8311: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8312: 'intauth_check' => 'Check bcrypt cost if authenticated',
8313: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8314: );
1.141 raeburn 8315: if ($dom) {
8316: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8317: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8318: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8319: $protocol = 'http' if ($protocol ne 'https');
8320: if ($uint_dom) {
8321: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8322: $uint_dom);
8323: }
8324: }
1.43 raeburn 8325: return (\%titles);
8326: }
8327:
1.346 raeburn 8328: sub print_scantron {
8329: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8330: if ($position eq 'top') {
8331: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8332: } else {
8333: return &print_scantronconfig($dom,$settings,\$rowtotal);
8334: }
8335: }
8336:
8337: sub scantron_javascript {
8338: return <<"ENDSCRIPT";
8339:
8340: <script type="text/javascript">
8341: // <![CDATA[
8342:
8343: function toggleScantron(form) {
1.347 raeburn 8344: var csvfieldset = new Array();
1.346 raeburn 8345: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8346: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8347: }
8348: if (document.getElementById('scantroncsv_options')) {
8349: csvfieldset.push(document.getElementById('scantroncsv_options'));
8350: }
8351: if (csvfieldset.length) {
1.346 raeburn 8352: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8353: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8354: if (scantroncsv.checked) {
1.347 raeburn 8355: for (var i=0; i<csvfieldset.length; i++) {
8356: csvfieldset[i].style.display = 'block';
8357: }
1.346 raeburn 8358: } else {
1.347 raeburn 8359: for (var i=0; i<csvfieldset.length; i++) {
8360: csvfieldset[i].style.display = 'none';
8361: }
1.346 raeburn 8362: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8363: if (csvselects.length) {
8364: for (var j=0; j<csvselects.length; j++) {
8365: csvselects[j].selectedIndex = 0;
8366: }
8367: }
8368: }
8369: }
8370: }
8371: return;
8372: }
8373: // ]]>
8374: </script>
8375:
8376: ENDSCRIPT
8377:
8378: }
8379:
1.46 raeburn 8380: sub print_scantronformat {
8381: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8382: my $itemcount = 1;
1.60 raeburn 8383: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8384: %confhash);
1.46 raeburn 8385: my $switchserver = &check_switchserver($dom,$confname);
8386: my %lt = &Apache::lonlocal::texthash (
1.95 www 8387: default => 'Default bubblesheet format file error',
8388: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8389: );
8390: my %scantronfiles = (
8391: default => 'default.tab',
8392: custom => 'custom.tab',
8393: );
8394: foreach my $key (keys(%scantronfiles)) {
8395: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8396: .$scantronfiles{$key};
8397: }
8398: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8399: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8400: if (!$switchserver) {
8401: my $servadm = $r->dir_config('lonAdmEMail');
8402: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8403: if ($configuserok eq 'ok') {
8404: if ($author_ok eq 'ok') {
8405: my %legacyfile = (
1.346 raeburn 8406: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8407: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8408: );
8409: my %md5chk;
8410: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8411: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8412: chomp($md5chk{$type});
1.46 raeburn 8413: }
8414: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8415: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8416: ($scantronurls{$type},my $error) =
1.46 raeburn 8417: &legacy_scantronformat($r,$dom,$confname,
8418: $type,$legacyfile{$type},
8419: $scantronurls{$type},
8420: $scantronfiles{$type});
1.60 raeburn 8421: if ($error ne '') {
8422: $error{$type} = $error;
8423: }
8424: }
8425: if (keys(%error) == 0) {
8426: $is_custom = 1;
1.346 raeburn 8427: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8428: $scantronurls{'custom'};
1.346 raeburn 8429: my $putresult =
1.60 raeburn 8430: &Apache::lonnet::put_dom('configuration',
8431: \%confhash,$dom);
8432: if ($putresult ne 'ok') {
1.346 raeburn 8433: $error{'custom'} =
1.60 raeburn 8434: '<span class="LC_error">'.
8435: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8436: }
1.46 raeburn 8437: }
8438: } else {
1.60 raeburn 8439: ($scantronurls{'default'},my $error) =
1.46 raeburn 8440: &legacy_scantronformat($r,$dom,$confname,
8441: 'default',$legacyfile{'default'},
8442: $scantronurls{'default'},
8443: $scantronfiles{'default'});
1.60 raeburn 8444: if ($error eq '') {
8445: $confhash{'scantron'}{'scantronformat'} = '';
8446: my $putresult =
8447: &Apache::lonnet::put_dom('configuration',
8448: \%confhash,$dom);
8449: if ($putresult ne 'ok') {
8450: $error{'default'} =
8451: '<span class="LC_error">'.
8452: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8453: }
8454: } else {
8455: $error{'default'} = $error;
8456: }
1.46 raeburn 8457: }
8458: }
8459: }
8460: } else {
1.95 www 8461: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8462: }
8463: }
8464: if (ref($settings) eq 'HASH') {
8465: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8466: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8467: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8468: $scantronurl = '';
8469: } else {
8470: $scantronurl = $settings->{'scantronformat'};
8471: }
8472: $is_custom = 1;
8473: } else {
8474: $scantronurl = $scantronurls{'default'};
8475: }
8476: } else {
1.60 raeburn 8477: if ($is_custom) {
8478: $scantronurl = $scantronurls{'custom'};
8479: } else {
8480: $scantronurl = $scantronurls{'default'};
8481: }
1.46 raeburn 8482: }
8483: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8484: $datatable .= '<tr'.$css_class.'>';
8485: if (!$is_custom) {
1.65 raeburn 8486: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8487: '<span class="LC_nobreak">';
1.46 raeburn 8488: if ($scantronurl) {
1.199 raeburn 8489: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8490: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8491: } else {
8492: $datatable = &mt('File unavailable for display');
8493: }
1.65 raeburn 8494: $datatable .= '</span></td>';
1.60 raeburn 8495: if (keys(%error) == 0) {
1.306 raeburn 8496: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8497: if (!$switchserver) {
8498: $datatable .= &mt('Upload:').'<br />';
8499: }
8500: } else {
8501: my $errorstr;
8502: foreach my $key (sort(keys(%error))) {
8503: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8504: }
8505: $datatable .= '<td>'.$errorstr;
8506: }
1.46 raeburn 8507: } else {
8508: if (keys(%error) > 0) {
8509: my $errorstr;
8510: foreach my $key (sort(keys(%error))) {
8511: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8512: }
1.60 raeburn 8513: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8514: } elsif ($scantronurl) {
1.199 raeburn 8515: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8516: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8517: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8518: $link.
8519: '<label><input type="checkbox" name="scantronformat_del"'.
8520: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8521: '<td><span class="LC_nobreak"> '.
8522: &mt('Replace:').'</span><br />';
1.46 raeburn 8523: }
8524: }
8525: if (keys(%error) == 0) {
8526: if ($switchserver) {
8527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8528: } else {
1.65 raeburn 8529: $datatable .='<span class="LC_nobreak"> '.
8530: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8531: }
8532: }
8533: $datatable .= '</td></tr>';
8534: $$rowtotal ++;
8535: return $datatable;
8536: }
8537:
8538: sub legacy_scantronformat {
8539: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8540: my ($url,$error);
8541: my @statinfo = &Apache::lonnet::stat_file($newurl);
8542: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8543: (my $result,$url) =
8544: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8545: '','',$newfile);
8546: if ($result ne 'ok') {
1.130 raeburn 8547: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8548: }
8549: }
8550: return ($url,$error);
8551: }
1.43 raeburn 8552:
1.346 raeburn 8553: sub print_scantronconfig {
8554: my ($dom,$settings,$rowtotal) = @_;
8555: my $itemcount = 2;
8556: my $is_checked = ' checked="checked"';
1.347 raeburn 8557: my %optionson = (
8558: hdr => ' checked="checked"',
8559: pad => ' checked="checked"',
8560: rem => ' checked="checked"',
8561: );
8562: my %optionsoff = (
8563: hdr => '',
8564: pad => '',
8565: rem => '',
8566: );
1.346 raeburn 8567: my $currcsvsty = 'none';
1.347 raeburn 8568: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8569: my @fields = &scantroncsv_fields();
8570: my %titles = &scantronconfig_titles();
8571: if (ref($settings) eq 'HASH') {
8572: if (ref($settings->{config}) eq 'HASH') {
8573: if ($settings->{config}->{dat}) {
8574: $checked{'dat'} = $is_checked;
8575: }
8576: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8577: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8578: %csvfields = %{$settings->{config}->{csv}->{fields}};
8579: if (keys(%csvfields) > 0) {
8580: $checked{'csv'} = $is_checked;
8581: $currcsvsty = 'block';
8582: }
8583: }
8584: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8585: %csvoptions = %{$settings->{config}->{csv}->{options}};
8586: foreach my $option (keys(%optionson)) {
8587: unless ($csvoptions{$option}) {
8588: $optionsoff{$option} = $optionson{$option};
8589: $optionson{$option} = '';
8590: }
8591: }
1.346 raeburn 8592: }
8593: }
8594: } else {
8595: $checked{'dat'} = $is_checked;
8596: }
8597: } else {
8598: $checked{'dat'} = $is_checked;
8599: }
8600: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8601: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8602: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8603: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8604: foreach my $item ('dat','csv') {
8605: my $id;
8606: if ($item eq 'csv') {
8607: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8608: }
1.346 raeburn 8609: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8610: $titles{$item}.'</label>'.(' 'x3);
8611: if ($item eq 'csv') {
8612: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8613: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8614: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8615: foreach my $col (@fields) {
8616: my $selnone;
8617: if ($csvfields{$col} eq '') {
8618: $selnone = ' selected="selected"';
8619: }
8620: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8621: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8622: '<option value=""'.$selnone.'></option>';
8623: for (my $i=0; $i<20; $i++) {
8624: my $shown = $i+1;
8625: my $sel;
8626: unless ($selnone) {
8627: if (exists($csvfields{$col})) {
8628: if ($csvfields{$col} == $i) {
8629: $sel = ' selected="selected"';
8630: }
8631: }
8632: }
8633: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8634: }
8635: $datatable .= '</select></td></tr>';
8636: }
1.347 raeburn 8637: $datatable .= '</table></fieldset>'.
8638: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8639: '<legend>'.&mt('CSV Options').'</legend>';
8640: foreach my $option ('hdr','pad','rem') {
8641: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8642: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8643: &mt('Yes').'</label>'.(' 'x2)."\n".
8644: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8645: }
8646: $datatable .= '</fieldset>';
1.346 raeburn 8647: $itemcount ++;
8648: }
8649: }
8650: $datatable .= '</td></tr>';
8651: $$rowtotal ++;
8652: return $datatable;
8653: }
8654:
8655: sub scantronconfig_titles {
8656: return &Apache::lonlocal::texthash(
8657: dat => 'Standard format (.dat)',
8658: csv => 'Comma separated values (.csv)',
1.347 raeburn 8659: hdr => 'Remove first line in file (contains column titles)',
8660: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8661: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8662: CODE => 'CODE',
8663: ID => 'Student ID',
8664: PaperID => 'Paper ID',
8665: FirstName => 'First Name',
8666: LastName => 'Last Name',
8667: FirstQuestion => 'First Question Response',
8668: Section => 'Section',
8669: );
8670: }
8671:
8672: sub scantroncsv_fields {
8673: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8674: }
8675:
1.49 raeburn 8676: sub print_coursecategories {
1.57 raeburn 8677: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8678: my $datatable;
8679: if ($position eq 'top') {
1.238 raeburn 8680: my (%checked);
8681: my @catitems = ('unauth','auth');
8682: my @cattypes = ('std','domonly','codesrch','none');
8683: $checked{'unauth'} = 'std';
8684: $checked{'auth'} = 'std';
8685: if (ref($settings) eq 'HASH') {
8686: foreach my $type (@cattypes) {
8687: if ($type eq $settings->{'unauth'}) {
8688: $checked{'unauth'} = $type;
8689: }
8690: if ($type eq $settings->{'auth'}) {
8691: $checked{'auth'} = $type;
8692: }
8693: }
8694: }
8695: my %lt = &Apache::lonlocal::texthash (
8696: unauth => 'Catalog type for unauthenticated users',
8697: auth => 'Catalog type for authenticated users',
8698: none => 'No catalog',
8699: std => 'Standard catalog',
8700: domonly => 'Domain-only catalog',
8701: codesrch => "Code search form",
8702: );
8703: my $itemcount = 0;
8704: foreach my $item (@catitems) {
8705: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8706: $datatable .= '<tr '.$css_class.'>'.
8707: '<td>'.$lt{$item}.'</td>'.
8708: '<td class="LC_right_item"><span class="LC_nobreak">';
8709: foreach my $type (@cattypes) {
8710: my $ischecked;
8711: if ($checked{$item} eq $type) {
8712: $ischecked=' checked="checked"';
8713: }
8714: $datatable .= '<label>'.
8715: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8716: ' />'.$lt{$type}.'</label> ';
8717: }
1.327 raeburn 8718: $datatable .= '</span></td></tr>';
1.238 raeburn 8719: $itemcount ++;
8720: }
8721: $$rowtotal += $itemcount;
8722: } elsif ($position eq 'middle') {
1.57 raeburn 8723: my $toggle_cats_crs = ' ';
8724: my $toggle_cats_dom = ' checked="checked" ';
8725: my $can_cat_crs = ' ';
8726: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8727: my $toggle_catscomm_comm = ' ';
8728: my $toggle_catscomm_dom = ' checked="checked" ';
8729: my $can_catcomm_comm = ' ';
8730: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8731: my $toggle_catsplace_place = ' ';
8732: my $toggle_catsplace_dom = ' checked="checked" ';
8733: my $can_catplace_place = ' ';
8734: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8735:
1.57 raeburn 8736: if (ref($settings) eq 'HASH') {
8737: if ($settings->{'togglecats'} eq 'crs') {
8738: $toggle_cats_crs = $toggle_cats_dom;
8739: $toggle_cats_dom = ' ';
8740: }
8741: if ($settings->{'categorize'} eq 'crs') {
8742: $can_cat_crs = $can_cat_dom;
8743: $can_cat_dom = ' ';
8744: }
1.120 raeburn 8745: if ($settings->{'togglecatscomm'} eq 'comm') {
8746: $toggle_catscomm_comm = $toggle_catscomm_dom;
8747: $toggle_catscomm_dom = ' ';
8748: }
8749: if ($settings->{'categorizecomm'} eq 'comm') {
8750: $can_catcomm_comm = $can_catcomm_dom;
8751: $can_catcomm_dom = ' ';
8752: }
1.272 raeburn 8753: if ($settings->{'togglecatsplace'} eq 'place') {
8754: $toggle_catsplace_place = $toggle_catsplace_dom;
8755: $toggle_catsplace_dom = ' ';
8756: }
8757: if ($settings->{'categorizeplace'} eq 'place') {
8758: $can_catplace_place = $can_catplace_dom;
8759: $can_catplace_dom = ' ';
8760: }
1.57 raeburn 8761: }
8762: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8763: togglecats => 'Show/Hide a course in catalog',
8764: togglecatscomm => 'Show/Hide a community in catalog',
8765: togglecatsplace => 'Show/Hide a placement test in catalog',
8766: categorize => 'Assign a category to a course',
8767: categorizecomm => 'Assign a category to a community',
8768: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8769: );
8770: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8771: dom => 'Set in Domain',
8772: crs => 'Set in Course',
8773: comm => 'Set in Community',
8774: place => 'Set in Placement Test',
1.57 raeburn 8775: );
8776: $datatable = '<tr class="LC_odd_row">'.
8777: '<td>'.$title{'togglecats'}.'</td>'.
8778: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8779: '<input type="radio" name="togglecats"'.
8780: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8781: '<label><input type="radio" name="togglecats"'.
8782: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8783: '</tr><tr>'.
8784: '<td>'.$title{'categorize'}.'</td>'.
8785: '<td class="LC_right_item"><span class="LC_nobreak">'.
8786: '<label><input type="radio" name="categorize"'.
8787: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8788: '<label><input type="radio" name="categorize"'.
8789: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8790: '</tr><tr class="LC_odd_row">'.
8791: '<td>'.$title{'togglecatscomm'}.'</td>'.
8792: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8793: '<input type="radio" name="togglecatscomm"'.
8794: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8795: '<label><input type="radio" name="togglecatscomm"'.
8796: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8797: '</tr><tr>'.
8798: '<td>'.$title{'categorizecomm'}.'</td>'.
8799: '<td class="LC_right_item"><span class="LC_nobreak">'.
8800: '<label><input type="radio" name="categorizecomm"'.
8801: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8802: '<label><input type="radio" name="categorizecomm"'.
8803: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8804: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8805: '<td>'.$title{'togglecatsplace'}.'</td>'.
8806: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8807: '<input type="radio" name="togglecatsplace"'.
8808: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8809: '<label><input type="radio" name="togglecatscomm"'.
8810: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8811: '</tr><tr>'.
8812: '<td>'.$title{'categorizeplace'}.'</td>'.
8813: '<td class="LC_right_item"><span class="LC_nobreak">'.
8814: '<label><input type="radio" name="categorizeplace"'.
8815: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8816: '<label><input type="radio" name="categorizeplace"'.
8817: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 8818: '</tr>';
1.272 raeburn 8819: $$rowtotal += 6;
1.57 raeburn 8820: } else {
8821: my $css_class;
8822: my $itemcount = 1;
8823: my $cathash;
8824: if (ref($settings) eq 'HASH') {
8825: $cathash = $settings->{'cats'};
8826: }
8827: if (ref($cathash) eq 'HASH') {
8828: my (@cats,@trails,%allitems,%idx,@jsarray);
8829: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
8830: \%allitems,\%idx,\@jsarray);
8831: my $maxdepth = scalar(@cats);
8832: my $colattrib = '';
8833: if ($maxdepth > 2) {
8834: $colattrib = ' colspan="2" ';
8835: }
8836: my @path;
8837: if (@cats > 0) {
8838: if (ref($cats[0]) eq 'ARRAY') {
8839: my $numtop = @{$cats[0]};
8840: my $maxnum = $numtop;
1.120 raeburn 8841: my %default_names = (
8842: instcode => &mt('Official courses'),
8843: communities => &mt('Communities'),
1.272 raeburn 8844: placement => &mt('Placement Tests'),
1.120 raeburn 8845: );
8846:
8847: if ((!grep(/^instcode$/,@{$cats[0]})) ||
8848: ($cathash->{'instcode::0'} eq '') ||
8849: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 8850: ($cathash->{'communities::0'} eq '') ||
8851: (!grep(/^placement$/,@{$cats[0]})) ||
8852: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 8853: $maxnum ++;
8854: }
8855: my $lastidx;
8856: for (my $i=0; $i<$numtop; $i++) {
8857: my $parent = $cats[0][$i];
8858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8859: my $item = &escape($parent).'::0';
8860: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
8861: $lastidx = $idx{$item};
8862: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
8863: .'<select name="'.$item.'"'.$chgstr.'>';
8864: for (my $k=0; $k<=$maxnum; $k++) {
8865: my $vpos = $k+1;
8866: my $selstr;
8867: if ($k == $i) {
8868: $selstr = ' selected="selected" ';
8869: }
8870: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8871: }
1.214 raeburn 8872: $datatable .= '</select></span></td><td>';
1.272 raeburn 8873: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 8874: $datatable .= '<span class="LC_nobreak">'
8875: .$default_names{$parent}.'</span>';
8876: if ($parent eq 'instcode') {
8877: $datatable .= '<br /><span class="LC_nobreak">('
8878: .&mt('with institutional codes')
8879: .')</span></td><td'.$colattrib.'>';
8880: } else {
8881: $datatable .= '<table><tr><td>';
8882: }
8883: $datatable .= '<span class="LC_nobreak">'
8884: .'<label><input type="radio" name="'
8885: .$parent.'" value="1" checked="checked" />'
8886: .&mt('Display').'</label>';
8887: if ($parent eq 'instcode') {
8888: $datatable .= ' ';
8889: } else {
8890: $datatable .= '</span></td></tr><tr><td>'
8891: .'<span class="LC_nobreak">';
8892: }
8893: $datatable .= '<label><input type="radio" name="'
8894: .$parent.'" value="0" />'
8895: .&mt('Do not display').'</label></span>';
1.272 raeburn 8896: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 8897: $datatable .= '</td></tr></table>';
8898: }
8899: $datatable .= '</td>';
1.57 raeburn 8900: } else {
8901: $datatable .= $parent
1.214 raeburn 8902: .' <span class="LC_nobreak"><label>'
8903: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 8904: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
8905: }
8906: my $depth = 1;
8907: push(@path,$parent);
8908: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
8909: pop(@path);
8910: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
8911: $itemcount ++;
8912: }
1.48 raeburn 8913: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 8914: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
8915: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 8916: for (my $k=0; $k<=$maxnum; $k++) {
8917: my $vpos = $k+1;
8918: my $selstr;
1.57 raeburn 8919: if ($k == $numtop) {
1.48 raeburn 8920: $selstr = ' selected="selected" ';
8921: }
8922: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8923: }
1.59 bisitz 8924: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 8925: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
8926: .'</tr>'."\n";
1.48 raeburn 8927: $itemcount ++;
1.272 raeburn 8928: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 8929: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
8930: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8931: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
8932: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
8933: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
8934: for (my $k=0; $k<=$maxnum; $k++) {
8935: my $vpos = $k+1;
8936: my $selstr;
8937: if ($k == $maxnum) {
8938: $selstr = ' selected="selected" ';
8939: }
8940: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 8941: }
1.120 raeburn 8942: $datatable .= '</select></span></td>'.
8943: '<td><span class="LC_nobreak">'.
8944: $default_names{$default}.'</span>';
8945: if ($default eq 'instcode') {
8946: $datatable .= '<br /><span class="LC_nobreak">('
8947: .&mt('with institutional codes').')</span>';
8948: }
8949: $datatable .= '</td>'
8950: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
8951: .&mt('Display').'</label> '
8952: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
8953: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 8954: }
8955: }
8956: }
1.57 raeburn 8957: } else {
8958: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 8959: }
8960: } else {
1.327 raeburn 8961: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 8962: .&initialize_categories($itemcount);
1.48 raeburn 8963: }
1.57 raeburn 8964: $$rowtotal += $itemcount;
1.48 raeburn 8965: }
8966: return $datatable;
8967: }
8968:
1.69 raeburn 8969: sub print_serverstatuses {
8970: my ($dom,$settings,$rowtotal) = @_;
8971: my $datatable;
8972: my @pages = &serverstatus_pages();
8973: my (%namedaccess,%machineaccess);
8974: foreach my $type (@pages) {
8975: $namedaccess{$type} = '';
8976: $machineaccess{$type}= '';
8977: }
8978: if (ref($settings) eq 'HASH') {
8979: foreach my $type (@pages) {
8980: if (exists($settings->{$type})) {
8981: if (ref($settings->{$type}) eq 'HASH') {
8982: foreach my $key (keys(%{$settings->{$type}})) {
8983: if ($key eq 'namedusers') {
8984: $namedaccess{$type} = $settings->{$type}->{$key};
8985: } elsif ($key eq 'machines') {
8986: $machineaccess{$type} = $settings->{$type}->{$key};
8987: }
8988: }
8989: }
8990: }
8991: }
8992: }
1.81 raeburn 8993: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 8994: my $rownum = 0;
8995: my $css_class;
8996: foreach my $type (@pages) {
8997: $rownum ++;
8998: $css_class = $rownum%2?' class="LC_odd_row"':'';
8999: $datatable .= '<tr'.$css_class.'>'.
9000: '<td><span class="LC_nobreak">'.
9001: $titles->{$type}.'</span></td>'.
9002: '<td class="LC_left_item">'.
9003: '<input type="text" name="'.$type.'_namedusers" '.
9004: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9005: '<td class="LC_right_item">'.
9006: '<span class="LC_nobreak">'.
9007: '<input type="text" name="'.$type.'_machines" '.
9008: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 9009: '</span></td></tr>'."\n";
1.69 raeburn 9010: }
9011: $$rowtotal += $rownum;
9012: return $datatable;
9013: }
9014:
9015: sub serverstatus_pages {
9016: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 9017: 'checksums','clusterstatus','certstatus','metadata_keywords',
9018: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
9019: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9020: }
9021:
1.236 raeburn 9022: sub defaults_javascript {
9023: my ($settings) = @_;
1.354 raeburn 9024: return unless (ref($settings) eq 'HASH');
1.236 raeburn 9025: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9026: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9027: if ($maxnum eq '') {
9028: $maxnum = 0;
9029: }
9030: $maxnum ++;
1.249 raeburn 9031: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 9032: return <<"ENDSCRIPT";
9033: <script type="text/javascript">
9034: // <![CDATA[
9035: function reorderTypes(form,caller) {
9036: var changedVal;
9037: $jstext
9038: var newpos = 'addinststatus_pos';
9039: var current = new Array;
9040: var maxh = $maxnum;
9041: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9042: var oldVal;
9043: if (caller == newpos) {
9044: changedVal = newitemVal;
9045: } else {
9046: var curritem = 'inststatus_pos_'+caller;
9047: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9048: current[newitemVal] = newpos;
9049: }
9050: for (var i=0; i<inststatuses.length; i++) {
9051: if (inststatuses[i] != caller) {
9052: var elementName = 'inststatus_pos_'+inststatuses[i];
9053: if (form.elements[elementName]) {
9054: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9055: current[currVal] = elementName;
9056: }
9057: }
9058: }
9059: for (var j=0; j<maxh; j++) {
9060: if (current[j] == undefined) {
9061: oldVal = j;
9062: }
9063: }
9064: if (oldVal < changedVal) {
9065: for (var k=oldVal+1; k<=changedVal ; k++) {
9066: var elementName = current[k];
9067: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9068: }
9069: } else {
9070: for (var k=changedVal; k<oldVal; k++) {
9071: var elementName = current[k];
9072: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9073: }
9074: }
9075: return;
9076: }
9077:
9078: // ]]>
9079: </script>
9080:
9081: ENDSCRIPT
9082: }
1.354 raeburn 9083: return;
9084: }
9085:
9086: sub passwords_javascript {
9087: my $intauthcheck = &mt('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.');
9088: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
9089: &js_escape(\$intauthcheck);
9090: &js_escape(\$intauthcost);
9091: my $intauthjs = <<"ENDSCRIPT";
9092:
9093: function warnIntAuth(field) {
9094: if (field.name == 'intauth_check') {
9095: if (field.value == '2') {
9096: alert('$intauthcheck');
9097: }
9098: }
9099: if (field.name == 'intauth_cost') {
9100: field.value.replace(/\s/g,'');
9101: if (field.value != '') {
9102: var regexdigit=/^\\d+\$/;
9103: if (!regexdigit.test(field.value)) {
9104: alert('$intauthcost');
9105: }
9106: }
9107: }
9108: return;
9109: }
9110:
9111: ENDSCRIPT
9112: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 9113: }
9114:
1.49 raeburn 9115: sub coursecategories_javascript {
9116: my ($settings) = @_;
1.57 raeburn 9117: my ($output,$jstext,$cathash);
1.49 raeburn 9118: if (ref($settings) eq 'HASH') {
1.57 raeburn 9119: $cathash = $settings->{'cats'};
9120: }
9121: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9122: my (@cats,@jsarray,%idx);
1.57 raeburn 9123: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9124: if (@jsarray > 0) {
9125: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9126: for (my $i=0; $i<@jsarray; $i++) {
9127: if (ref($jsarray[$i]) eq 'ARRAY') {
9128: my $catstr = join('","',@{$jsarray[$i]});
9129: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9130: }
9131: }
9132: }
9133: } else {
9134: $jstext = ' var categories = Array(1);'."\n".
9135: ' categories[0] = Array("instcode_pos");'."\n";
9136: }
1.237 bisitz 9137: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9138: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 9139: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 9140: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9141: &js_escape(\$instcode_reserved);
9142: &js_escape(\$communities_reserved);
1.272 raeburn 9143: &js_escape(\$placement_reserved);
1.265 damieng 9144: &js_escape(\$choose_again);
1.49 raeburn 9145: $output = <<"ENDSCRIPT";
9146: <script type="text/javascript">
1.109 raeburn 9147: // <![CDATA[
1.49 raeburn 9148: function reorderCats(form,parent,item,idx) {
9149: var changedVal;
9150: $jstext
9151: var newpos = 'addcategory_pos';
9152: if (parent == '') {
9153: var has_instcode = 0;
9154: var maxtop = categories[idx].length;
9155: for (var j=0; j<maxtop; j++) {
9156: if (categories[idx][j] == 'instcode::0') {
9157: has_instcode == 1;
9158: }
9159: }
9160: if (has_instcode == 0) {
9161: categories[idx][maxtop] = 'instcode_pos';
9162: }
9163: } else {
9164: newpos += '_'+parent;
9165: }
9166: var maxh = 1 + categories[idx].length;
9167: var current = new Array;
9168: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9169: if (item == newpos) {
9170: changedVal = newitemVal;
9171: } else {
9172: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9173: current[newitemVal] = newpos;
9174: }
9175: for (var i=0; i<categories[idx].length; i++) {
9176: var elementName = categories[idx][i];
9177: if (elementName != item) {
9178: if (form.elements[elementName]) {
9179: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9180: current[currVal] = elementName;
9181: }
9182: }
9183: }
9184: var oldVal;
9185: for (var j=0; j<maxh; j++) {
9186: if (current[j] == undefined) {
9187: oldVal = j;
9188: }
9189: }
9190: if (oldVal < changedVal) {
9191: for (var k=oldVal+1; k<=changedVal ; k++) {
9192: var elementName = current[k];
9193: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9194: }
9195: } else {
9196: for (var k=changedVal; k<oldVal; k++) {
9197: var elementName = current[k];
9198: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9199: }
9200: }
9201: return;
9202: }
1.120 raeburn 9203:
9204: function categoryCheck(form) {
9205: if (form.elements['addcategory_name'].value == 'instcode') {
9206: alert('$instcode_reserved\\n$choose_again');
9207: return false;
9208: }
9209: if (form.elements['addcategory_name'].value == 'communities') {
9210: alert('$communities_reserved\\n$choose_again');
9211: return false;
9212: }
1.272 raeburn 9213: if (form.elements['addcategory_name'].value == 'placement') {
9214: alert('$placement_reserved\\n$choose_again');
9215: return false;
9216: }
1.120 raeburn 9217: return true;
9218: }
9219:
1.109 raeburn 9220: // ]]>
1.49 raeburn 9221: </script>
9222:
9223: ENDSCRIPT
9224: return $output;
9225: }
9226:
1.48 raeburn 9227: sub initialize_categories {
9228: my ($itemcount) = @_;
1.120 raeburn 9229: my ($datatable,$css_class,$chgstr);
9230: my %default_names = (
9231: instcode => 'Official courses (with institutional codes)',
9232: communities => 'Communities',
1.272 raeburn 9233: placement => 'Placement Tests',
1.120 raeburn 9234: );
1.328 raeburn 9235: my %selnum = (
9236: instcode => '0',
9237: communities => '1',
9238: placement => '2',
9239: );
9240: my %selected;
1.272 raeburn 9241: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9242: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 9243: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 9244: map { $selected{$selnum{$_}} = '' } keys(%selnum);
9245: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 9246: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 9247: .'<select name="'.$default.'_pos"'.$chgstr.'>'
9248: .'<option value="0"'.$selected{'0'}.'>1</option>'
9249: .'<option value="1"'.$selected{'1'}.'>2</option>'
9250: .'<option value="2"'.$selected{'2'}.'>3</option>'
9251: .'<option value="3">4</option></select> '
1.120 raeburn 9252: .$default_names{$default}
9253: .'</span></td><td><span class="LC_nobreak">'
9254: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9255: .&mt('Display').'</label> <label>'
9256: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9257: .'</label></span></td></tr>';
1.120 raeburn 9258: $itemcount ++;
9259: }
1.48 raeburn 9260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9261: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9262: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9263: .'<select name="addcategory_pos"'.$chgstr.'>'
9264: .'<option value="0">1</option>'
9265: .'<option value="1">2</option>'
1.328 raeburn 9266: .'<option value="2">3</option>'
9267: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 9268: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9269: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9270: .'</td></tr>';
1.48 raeburn 9271: return $datatable;
9272: }
9273:
9274: sub build_category_rows {
1.49 raeburn 9275: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9276: my ($text,$name,$item,$chgstr);
1.48 raeburn 9277: if (ref($cats) eq 'ARRAY') {
9278: my $maxdepth = scalar(@{$cats});
9279: if (ref($cats->[$depth]) eq 'HASH') {
9280: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9281: my $numchildren = @{$cats->[$depth]{$parent}};
9282: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 9283: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9284: my ($idxnum,$parent_name,$parent_item);
9285: my $higher = $depth - 1;
9286: if ($higher == 0) {
9287: $parent_name = &escape($parent).'::'.$higher;
9288: } else {
9289: if (ref($path) eq 'ARRAY') {
9290: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9291: }
9292: }
9293: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9294: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9295: if ($j < $numchildren) {
1.48 raeburn 9296: $name = $cats->[$depth]{$parent}[$j];
9297: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9298: $idxnum = $idx->{$item};
9299: } else {
9300: $name = $parent_name;
9301: $item = $parent_item;
1.48 raeburn 9302: }
1.49 raeburn 9303: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9304: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9305: for (my $i=0; $i<=$numchildren; $i++) {
9306: my $vpos = $i+1;
9307: my $selstr;
9308: if ($j == $i) {
9309: $selstr = ' selected="selected" ';
9310: }
9311: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9312: }
9313: $text .= '</select> ';
9314: if ($j < $numchildren) {
9315: my $deeper = $depth+1;
9316: $text .= $name.' '
9317: .'<label><input type="checkbox" name="deletecategory" value="'
9318: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9319: if(ref($path) eq 'ARRAY') {
9320: push(@{$path},$name);
1.49 raeburn 9321: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9322: pop(@{$path});
9323: }
9324: } else {
1.330 raeburn 9325: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9326: if ($j == $numchildren) {
9327: $text .= $name;
9328: } else {
9329: $text .= $item;
9330: }
9331: $text .= '" value="" />';
9332: }
9333: $text .= '</td></tr>';
9334: }
9335: $text .= '</table></td>';
9336: } else {
9337: my $higher = $depth-1;
9338: if ($higher == 0) {
9339: $name = &escape($parent).'::'.$higher;
9340: } else {
9341: if (ref($path) eq 'ARRAY') {
9342: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9343: }
9344: }
9345: my $colspan;
9346: if ($parent ne 'instcode') {
9347: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9348: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9349: }
9350: }
9351: }
9352: }
9353: return $text;
9354: }
9355:
1.33 raeburn 9356: sub modifiable_userdata_row {
1.305 raeburn 9357: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9358: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 9359: my ($role,$rolename,$statustype);
9360: $role = $item;
1.224 raeburn 9361: if ($context eq 'cancreate') {
1.305 raeburn 9362: if ($item =~ /^(emailusername)_(.+)$/) {
9363: $role = $1;
9364: $statustype = $2;
1.228 raeburn 9365: if (ref($usertypes) eq 'HASH') {
9366: if ($usertypes->{$statustype}) {
9367: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9368: } else {
9369: $rolename = &mt('Data provided by user');
9370: }
9371: }
1.224 raeburn 9372: }
9373: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9374: if (ref($usertypes) eq 'HASH') {
9375: $rolename = $usertypes->{$role};
9376: } else {
9377: $rolename = $role;
9378: }
1.325 raeburn 9379: } elsif ($context eq 'lti') {
9380: $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 9381: } else {
1.63 raeburn 9382: if ($role eq 'cr') {
9383: $rolename = &mt('Custom role');
9384: } else {
9385: $rolename = &Apache::lonnet::plaintext($role);
9386: }
1.33 raeburn 9387: }
1.224 raeburn 9388: my (@fields,%fieldtitles);
9389: if (ref($fieldsref) eq 'ARRAY') {
9390: @fields = @{$fieldsref};
9391: } else {
9392: @fields = ('lastname','firstname','middlename','generation',
9393: 'permanentemail','id');
9394: }
9395: if ((ref($titlesref) eq 'HASH')) {
9396: %fieldtitles = %{$titlesref};
9397: } else {
9398: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9399: }
1.33 raeburn 9400: my $output;
1.305 raeburn 9401: my $css_class;
9402: if ($rowcount%2) {
9403: $css_class = 'LC_odd_row';
9404: }
9405: if ($customcss) {
9406: $css_class .= " $customcss";
9407: }
9408: $css_class =~ s/^\s+//;
9409: if ($css_class) {
9410: $css_class = ' class="'.$css_class.'"';
9411: }
9412: if ($rowstyle) {
9413: $css_class .= ' style="'.$rowstyle.'"';
9414: }
9415: if ($rowid) {
9416: $rowid = ' id="'.$rowid.'"';
9417: }
9418: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9419: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9420: '<td class="LC_left_item" colspan="2"><table>';
9421: my $rem;
9422: my %checks;
1.325 raeburn 9423: my %current;
1.33 raeburn 9424: if (ref($settings) eq 'HASH') {
1.325 raeburn 9425: my $hashref;
9426: if ($context eq 'lti') {
9427: if (ref($settings) eq 'HASH') {
9428: $hashref = $settings->{'instdata'};
9429: }
9430: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9431: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9432: $hashref = $settings->{'lti_instdata'};
9433: }
9434: if ($role eq 'emailusername') {
9435: if ($statustype) {
9436: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9437: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9438: }
1.325 raeburn 9439: }
9440: }
9441: }
9442: if (ref($hashref) eq 'HASH') {
9443: foreach my $field (@fields) {
9444: if ($hashref->{$field}) {
9445: if ($role eq 'emailusername') {
9446: $checks{$field} = $hashref->{$field};
9447: } else {
9448: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9449: }
9450: }
9451: }
9452: }
9453: }
1.305 raeburn 9454:
9455: my $total = scalar(@fields);
9456: for (my $i=0; $i<$total; $i++) {
9457: $rem = $i%($numinrow);
1.33 raeburn 9458: if ($rem == 0) {
9459: if ($i > 0) {
9460: $output .= '</tr>';
9461: }
9462: $output .= '<tr>';
9463: }
9464: my $check = ' ';
1.228 raeburn 9465: unless ($role eq 'emailusername') {
9466: if (exists($checks{$fields[$i]})) {
1.354 raeburn 9467: $check = $checks{$fields[$i]};
1.325 raeburn 9468: } elsif ($context ne 'lti') {
1.228 raeburn 9469: if ($role eq 'st') {
9470: if (ref($settings) ne 'HASH') {
9471: $check = ' checked="checked" ';
9472: }
1.33 raeburn 9473: }
9474: }
9475: }
9476: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9477: '<span class="LC_nobreak">';
1.325 raeburn 9478: my $prefix = 'canmodify';
1.228 raeburn 9479: if ($role eq 'emailusername') {
9480: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9481: $checks{$fields[$i]} = 'omit';
9482: }
9483: foreach my $option ('required','optional','omit') {
9484: my $checked='';
9485: if ($checks{$fields[$i]} eq $option) {
9486: $checked='checked="checked" ';
9487: }
9488: $output .= '<label>'.
1.325 raeburn 9489: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9490: &mt($option).'</label>'.(' ' x2);
9491: }
9492: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9493: } else {
1.325 raeburn 9494: if ($context eq 'lti') {
9495: $prefix = 'lti';
9496: }
1.228 raeburn 9497: $output .= '<label>'.
1.325 raeburn 9498: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9499: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9500: '</label>';
9501: }
9502: $output .= '</span></td>';
1.33 raeburn 9503: }
1.305 raeburn 9504: $rem = $total%$numinrow;
9505: my $colsleft;
9506: if ($rem) {
9507: $colsleft = $numinrow - $rem;
9508: }
9509: if ($colsleft > 1) {
1.33 raeburn 9510: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9511: ' </td>';
9512: } elsif ($colsleft == 1) {
9513: $output .= '<td class="LC_left_item"> </td>';
9514: }
9515: $output .= '</tr></table></td></tr>';
9516: return $output;
9517: }
1.28 raeburn 9518:
1.93 raeburn 9519: sub insttypes_row {
1.305 raeburn 9520: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9521: $customcss,$rowstyle) = @_;
1.93 raeburn 9522: my %lt = &Apache::lonlocal::texthash (
9523: cansearch => 'Users allowed to search',
9524: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9525: lockablenames => 'User preference to lock name',
1.305 raeburn 9526: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9527: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9528: );
9529: my $showdom;
9530: if ($context eq 'cansearch') {
9531: $showdom = ' ('.$dom.')';
9532: }
1.165 raeburn 9533: my $class = 'LC_left_item';
9534: if ($context eq 'statustocreate') {
9535: $class = 'LC_right_item';
9536: }
1.305 raeburn 9537: my $css_class;
9538: if ($$rowtotal%2) {
9539: $css_class = 'LC_odd_row';
9540: }
9541: if ($customcss) {
9542: $css_class .= ' '.$customcss;
9543: }
9544: $css_class =~ s/^\s+//;
9545: if ($css_class) {
9546: $css_class = ' class="'.$css_class.'"';
9547: }
9548: if ($rowstyle) {
9549: $css_class .= ' style="'.$rowstyle.'"';
9550: }
9551: if ($onclick) {
9552: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9553: }
9554: my $output = '<tr'.$css_class.'>'.
9555: '<td>'.$lt{$context}.$showdom.
9556: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9557: my $rem;
9558: if (ref($types) eq 'ARRAY') {
9559: for (my $i=0; $i<@{$types}; $i++) {
9560: if (defined($usertypes->{$types->[$i]})) {
9561: my $rem = $i%($numinrow);
9562: if ($rem == 0) {
9563: if ($i > 0) {
9564: $output .= '</tr>';
9565: }
9566: $output .= '<tr>';
1.23 raeburn 9567: }
1.26 raeburn 9568: my $check = ' ';
1.99 raeburn 9569: if (ref($settings) eq 'HASH') {
9570: if (ref($settings->{$context}) eq 'ARRAY') {
9571: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9572: $check = ' checked="checked" ';
9573: }
1.315 raeburn 9574: } elsif (ref($settings->{$context}) eq 'HASH') {
9575: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9576: $check = ' checked="checked" ';
9577: }
1.99 raeburn 9578: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9579: $check = ' checked="checked" ';
9580: }
1.23 raeburn 9581: }
1.26 raeburn 9582: $output .= '<td class="LC_left_item">'.
9583: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9584: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9585: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9586: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9587: }
9588: }
1.26 raeburn 9589: $rem = @{$types}%($numinrow);
1.23 raeburn 9590: }
9591: my $colsleft = $numinrow - $rem;
1.315 raeburn 9592: if ($context eq 'overrides') {
9593: if ($colsleft > 1) {
9594: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9595: } else {
9596: $output .= '<td class="LC_left_item">';
9597: }
9598: $output .= ' ';
1.23 raeburn 9599: } else {
1.334 raeburn 9600: if ($rem == 0) {
1.315 raeburn 9601: $output .= '<tr>';
9602: }
9603: if ($colsleft > 1) {
9604: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9605: } else {
9606: $output .= '<td class="LC_left_item">';
9607: }
9608: my $defcheck = ' ';
9609: if (ref($settings) eq 'HASH') {
9610: if (ref($settings->{$context}) eq 'ARRAY') {
9611: if (grep(/^default$/,@{$settings->{$context}})) {
9612: $defcheck = ' checked="checked" ';
9613: }
9614: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9615: $defcheck = ' checked="checked" ';
9616: }
1.26 raeburn 9617: }
1.315 raeburn 9618: $output .= '<span class="LC_nobreak"><label>'.
9619: '<input type="checkbox" name="'.$context.'" '.
9620: 'value="default"'.$defcheck.$onclick.' />'.
9621: $othertitle.'</label></span>';
1.23 raeburn 9622: }
1.315 raeburn 9623: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9624: return $output;
1.23 raeburn 9625: }
9626:
9627: sub sorted_searchtitles {
9628: my %searchtitles = &Apache::lonlocal::texthash(
9629: 'uname' => 'username',
9630: 'lastname' => 'last name',
9631: 'lastfirst' => 'last name, first name',
9632: );
9633: my @titleorder = ('uname','lastname','lastfirst');
9634: return (\%searchtitles,\@titleorder);
9635: }
9636:
1.25 raeburn 9637: sub sorted_searchtypes {
9638: my %srchtypes_desc = (
9639: exact => 'is exact match',
9640: contains => 'contains ..',
9641: begins => 'begins with ..',
9642: );
9643: my @srchtypeorder = ('exact','begins','contains');
9644: return (\%srchtypes_desc,\@srchtypeorder);
9645: }
9646:
1.3 raeburn 9647: sub usertype_update_row {
9648: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9649: my $datatable;
9650: my $numinrow = 4;
9651: foreach my $type (@{$types}) {
9652: if (defined($usertypes->{$type})) {
9653: $$rownums ++;
9654: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9655: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9656: '</td><td class="LC_left_item"><table>';
9657: for (my $i=0; $i<@{$fields}; $i++) {
9658: my $rem = $i%($numinrow);
9659: if ($rem == 0) {
9660: if ($i > 0) {
9661: $datatable .= '</tr>';
9662: }
9663: $datatable .= '<tr>';
9664: }
9665: my $check = ' ';
1.39 raeburn 9666: if (ref($settings) eq 'HASH') {
9667: if (ref($settings->{'fields'}) eq 'HASH') {
9668: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9669: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9670: $check = ' checked="checked" ';
9671: }
1.3 raeburn 9672: }
9673: }
9674: }
9675:
9676: if ($i == @{$fields}-1) {
9677: my $colsleft = $numinrow - $rem;
9678: if ($colsleft > 1) {
9679: $datatable .= '<td colspan="'.$colsleft.'">';
9680: } else {
9681: $datatable .= '<td>';
9682: }
9683: } else {
9684: $datatable .= '<td>';
9685: }
1.8 raeburn 9686: $datatable .= '<span class="LC_nobreak"><label>'.
9687: '<input type="checkbox" name="updateable_'.$type.
9688: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9689: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9690: }
9691: $datatable .= '</tr></table></td></tr>';
9692: }
9693: }
9694: return $datatable;
1.1 raeburn 9695: }
9696:
9697: sub modify_login {
1.205 raeburn 9698: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9699: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9700: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9701: %title = ( coursecatalog => 'Display course catalog',
9702: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9703: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9704: newuser => 'Link for visitors to create a user account',
9705: loginheader => 'Log-in box header');
9706: @offon = ('off','on');
1.112 raeburn 9707: if (ref($domconfig{login}) eq 'HASH') {
9708: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9709: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9710: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9711: }
9712: }
9713: }
1.9 raeburn 9714: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9715: \%domconfig,\%loginhash);
1.188 raeburn 9716: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9717: foreach my $item (@toggles) {
9718: $loginhash{login}{$item} = $env{'form.'.$item};
9719: }
1.41 raeburn 9720: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9721: if (ref($colchanges{'login'}) eq 'HASH') {
9722: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9723: \%loginhash);
9724: }
1.110 raeburn 9725:
1.149 raeburn 9726: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9727: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9728: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9729: if (keys(%servers) > 1) {
9730: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9731: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9732: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9733: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9734: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9735: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9736: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9737: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9738: $changes{'loginvia'}{$lonhost} = 1;
9739: } else {
9740: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9741: $changes{'loginvia'}{$lonhost} = 1;
9742: }
9743: } else {
9744: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9745: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9746: $changes{'loginvia'}{$lonhost} = 1;
9747: }
9748: }
9749: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9750: foreach my $item (@loginvia_attribs) {
9751: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9752: }
9753: } else {
9754: foreach my $item (@loginvia_attribs) {
9755: my $new = $env{'form.'.$lonhost.'_'.$item};
9756: if (($item eq 'serverpath') && ($new eq 'custom')) {
9757: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9758: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9759: $new = '/';
9760: }
9761: }
9762: if (($item eq 'custompath') &&
9763: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9764: $new = '';
9765: }
9766: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9767: $changes{'loginvia'}{$lonhost} = 1;
9768: }
9769: if ($item eq 'exempt') {
1.256 raeburn 9770: $new = &check_exempt_addresses($new);
1.128 raeburn 9771: }
9772: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9773: }
9774: }
1.112 raeburn 9775: } else {
1.128 raeburn 9776: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9777: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9778: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9779: foreach my $item (@loginvia_attribs) {
9780: my $new = $env{'form.'.$lonhost.'_'.$item};
9781: if (($item eq 'serverpath') && ($new eq 'custom')) {
9782: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9783: $new = '/';
9784: }
9785: }
9786: if (($item eq 'custompath') &&
9787: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9788: $new = '';
9789: }
9790: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9791: }
1.110 raeburn 9792: }
9793: }
9794: }
9795: }
1.119 raeburn 9796:
1.168 raeburn 9797: my $servadm = $r->dir_config('lonAdmEMail');
9798: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
9799: if (ref($domconfig{'login'}) eq 'HASH') {
9800: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
9801: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
9802: if ($lang eq 'nolang') {
9803: push(@currlangs,$lang);
9804: } elsif (defined($langchoices{$lang})) {
9805: push(@currlangs,$lang);
9806: } else {
9807: next;
9808: }
9809: }
9810: }
9811: }
9812: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
9813: if (@currlangs > 0) {
9814: foreach my $lang (@currlangs) {
9815: if (grep(/^\Q$lang\E$/,@delurls)) {
9816: $changes{'helpurl'}{$lang} = 1;
9817: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
9818: $changes{'helpurl'}{$lang} = 1;
9819: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
9820: push(@newlangs,$lang);
9821: } else {
9822: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9823: }
9824: }
9825: }
9826: unless (grep(/^nolang$/,@currlangs)) {
9827: if ($env{'form.loginhelpurl_nolang.filename'}) {
9828: $changes{'helpurl'}{'nolang'} = 1;
9829: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
9830: push(@newlangs,'nolang');
9831: }
9832: }
9833: if ($env{'form.loginhelpurl_add_lang'}) {
9834: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
9835: ($env{'form.loginhelpurl_add_file.filename'})) {
9836: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
9837: $addedfile = $env{'form.loginhelpurl_add_lang'};
9838: }
9839: }
9840: if ((@newlangs > 0) || ($addedfile)) {
9841: my $error;
9842: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9843: if ($configuserok eq 'ok') {
9844: if ($switchserver) {
9845: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
9846: } elsif ($author_ok eq 'ok') {
9847: my @allnew = @newlangs;
9848: if ($addedfile ne '') {
9849: push(@allnew,$addedfile);
9850: }
9851: foreach my $lang (@allnew) {
9852: my $formelem = 'loginhelpurl_'.$lang;
9853: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
9854: $formelem = 'loginhelpurl_add_file';
9855: }
9856: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9857: "help/$lang",'','',$newfile{$lang});
9858: if ($result eq 'ok') {
9859: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
9860: $changes{'helpurl'}{$lang} = 1;
9861: } else {
9862: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
9863: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 9864: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 9865: (!grep(/^\Q$lang\E$/,@delurls))) {
9866: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
9867: }
9868: }
9869: }
9870: } else {
9871: $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);
9872: }
9873: } else {
9874: $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);
9875: }
9876: if ($error) {
9877: &Apache::lonnet::logthis($error);
9878: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9879: }
9880: }
1.256 raeburn 9881:
9882: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
9883: if (ref($domconfig{'login'}) eq 'HASH') {
9884: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
9885: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
9886: if ($domservers{$lonhost}) {
9887: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
9888: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 9889: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 9890: }
9891: }
9892: }
9893: }
9894: }
9895: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
9896: foreach my $lonhost (sort(keys(%domservers))) {
9897: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
9898: $changes{'headtag'}{$lonhost} = 1;
9899: } else {
9900: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
9901: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
9902: }
9903: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
9904: push(@newhosts,$lonhost);
9905: } elsif ($currheadtagurls{$lonhost}) {
9906: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
9907: if ($currexempt{$lonhost}) {
1.289 raeburn 9908: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 9909: $changes{'headtag'}{$lonhost} = 1;
9910: }
9911: } elsif ($possexempt{$lonhost}) {
9912: $changes{'headtag'}{$lonhost} = 1;
9913: }
9914: if ($possexempt{$lonhost}) {
9915: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9916: }
9917: }
9918: }
9919: }
9920: if (@newhosts) {
9921: my $error;
9922: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9923: if ($configuserok eq 'ok') {
9924: if ($switchserver) {
9925: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
9926: } elsif ($author_ok eq 'ok') {
9927: foreach my $lonhost (@newhosts) {
9928: my $formelem = 'loginheadtag_'.$lonhost;
9929: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
9930: "login/headtag/$lonhost",'','',
9931: $env{'form.loginheadtag_'.$lonhost.'.filename'});
9932: if ($result eq 'ok') {
9933: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
9934: $changes{'headtag'}{$lonhost} = 1;
9935: if ($possexempt{$lonhost}) {
9936: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
9937: }
9938: } else {
9939: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
9940: $newheadtagurls{$lonhost},$result);
9941: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
9942: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
9943: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
9944: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
9945: }
9946: }
9947: }
9948: } else {
9949: $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);
9950: }
9951: } else {
9952: $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);
9953: }
9954: if ($error) {
9955: &Apache::lonnet::logthis($error);
9956: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9957: }
9958: }
1.169 raeburn 9959: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 9960:
9961: my $defaulthelpfile = '/adm/loginproblems.html';
9962: my $defaulttext = &mt('Default in use');
9963:
1.1 raeburn 9964: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
9965: $dom);
9966: if ($putresult eq 'ok') {
1.188 raeburn 9967: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9968: my %defaultchecked = (
9969: 'coursecatalog' => 'on',
1.188 raeburn 9970: 'helpdesk' => 'on',
1.42 raeburn 9971: 'adminmail' => 'off',
1.43 raeburn 9972: 'newuser' => 'off',
1.42 raeburn 9973: );
1.55 raeburn 9974: if (ref($domconfig{'login'}) eq 'HASH') {
9975: foreach my $item (@toggles) {
9976: if ($defaultchecked{$item} eq 'on') {
9977: if (($domconfig{'login'}{$item} eq '0') &&
9978: ($env{'form.'.$item} eq '1')) {
9979: $changes{$item} = 1;
9980: } elsif (($domconfig{'login'}{$item} eq '' ||
9981: $domconfig{'login'}{$item} eq '1') &&
9982: ($env{'form.'.$item} eq '0')) {
9983: $changes{$item} = 1;
9984: }
9985: } elsif ($defaultchecked{$item} eq 'off') {
9986: if (($domconfig{'login'}{$item} eq '1') &&
9987: ($env{'form.'.$item} eq '0')) {
9988: $changes{$item} = 1;
9989: } elsif (($domconfig{'login'}{$item} eq '' ||
9990: $domconfig{'login'}{$item} eq '0') &&
9991: ($env{'form.'.$item} eq '1')) {
9992: $changes{$item} = 1;
9993: }
1.42 raeburn 9994: }
9995: }
1.41 raeburn 9996: }
1.6 raeburn 9997: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 9998: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 9999: if (ref($lastactref) eq 'HASH') {
10000: $lastactref->{'domainconfig'} = 1;
10001: }
1.1 raeburn 10002: $resulttext = &mt('Changes made:').'<ul>';
10003: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10004: if ($item eq 'loginvia') {
1.112 raeburn 10005: if (ref($changes{$item}) eq 'HASH') {
10006: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10007: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10008: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10009: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10010: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10011: $protocol = 'http' if ($protocol ne 'https');
10012: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10013:
10014: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10015: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10016: } else {
10017: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10018: }
10019: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10020: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10021: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10022: }
10023: $resulttext .= '</li>';
10024: } else {
10025: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10026: }
1.112 raeburn 10027: } else {
1.128 raeburn 10028: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10029: }
10030: }
1.128 raeburn 10031: $resulttext .= '</ul></li>';
1.112 raeburn 10032: }
1.168 raeburn 10033: } elsif ($item eq 'helpurl') {
10034: if (ref($changes{$item}) eq 'HASH') {
10035: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10036: if (grep(/^\Q$lang\E$/,@delurls)) {
10037: my ($chg,$link);
10038: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10039: if ($lang eq 'nolang') {
10040: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10041: } else {
10042: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10043: }
10044: $resulttext .= '<li>'.$chg.'</li>';
10045: } else {
10046: my $chg;
10047: if ($lang eq 'nolang') {
10048: $chg = &mt('custom log-in help file for no preferred language');
10049: } else {
10050: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10051: }
10052: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10053: $loginhash{'login'}{'helpurl'}{$lang}.
10054: '?inhibitmenu=yes',$chg,600,500).
10055: '</li>';
10056: }
10057: }
10058: }
1.256 raeburn 10059: } elsif ($item eq 'headtag') {
10060: if (ref($changes{$item}) eq 'HASH') {
10061: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10062: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10063: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10064: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10065: $resulttext .= '<li><a href="'.
10066: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10067: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10068: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10069: if ($possexempt{$lonhost}) {
10070: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10071: } else {
10072: $resulttext .= &mt('included for any client IP');
10073: }
10074: $resulttext .= '</li>';
10075: }
10076: }
10077: }
1.169 raeburn 10078: } elsif ($item eq 'captcha') {
10079: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 10080: my $chgtxt;
1.169 raeburn 10081: if ($loginhash{'login'}{$item} eq 'notused') {
10082: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10083: } else {
10084: my %captchas = &captcha_phrases();
10085: if ($captchas{$loginhash{'login'}{$item}}) {
10086: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10087: } else {
10088: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10089: }
10090: }
10091: $resulttext .= '<li>'.$chgtxt.'</li>';
10092: }
10093: } elsif ($item eq 'recaptchakeys') {
10094: if (ref($loginhash{'login'}) eq 'HASH') {
10095: my ($privkey,$pubkey);
10096: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10097: $pubkey = $loginhash{'login'}{$item}{'public'};
10098: $privkey = $loginhash{'login'}{$item}{'private'};
10099: }
10100: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10101: if (!$pubkey) {
10102: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10103: } else {
10104: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10105: }
10106: if (!$privkey) {
10107: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10108: } else {
1.251 raeburn 10109: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 10110: }
10111: $chgtxt .= '</ul>';
10112: $resulttext .= '<li>'.$chgtxt.'</li>';
10113: }
1.269 raeburn 10114: } elsif ($item eq 'recaptchaversion') {
10115: if (ref($loginhash{'login'}) eq 'HASH') {
10116: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 10117: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 10118: '</li>';
10119: }
10120: }
1.41 raeburn 10121: } else {
10122: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10123: }
1.1 raeburn 10124: }
1.6 raeburn 10125: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10126: } else {
10127: $resulttext = &mt('No changes made to log-in page settings');
10128: }
10129: } else {
1.11 albertel 10130: $resulttext = '<span class="LC_error">'.
10131: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10132: }
1.6 raeburn 10133: if ($errors) {
1.9 raeburn 10134: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10135: $errors.'</ul>';
10136: }
10137: return $resulttext;
10138: }
10139:
1.256 raeburn 10140: sub check_exempt_addresses {
10141: my ($iplist) = @_;
10142: $iplist =~ s/^\s+//;
10143: $iplist =~ s/\s+$//;
10144: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10145: my (@okips,$new);
10146: foreach my $ip (@poss_ips) {
10147: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10148: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10149: push(@okips,$ip);
10150: }
10151: }
10152: }
10153: if (@okips > 0) {
10154: $new = join(',',@okips);
10155: } else {
10156: $new = '';
10157: }
10158: return $new;
10159: }
10160:
1.6 raeburn 10161: sub color_font_choices {
10162: my %choices =
10163: &Apache::lonlocal::texthash (
10164: img => "Header",
10165: bgs => "Background colors",
10166: links => "Link colors",
1.55 raeburn 10167: images => "Images",
1.6 raeburn 10168: font => "Font color",
1.201 raeburn 10169: fontmenu => "Font menu",
1.76 raeburn 10170: pgbg => "Page",
1.6 raeburn 10171: tabbg => "Header",
10172: sidebg => "Border",
10173: link => "Link",
10174: alink => "Active link",
10175: vlink => "Visited link",
10176: );
10177: return %choices;
10178: }
10179:
10180: sub modify_rolecolors {
1.205 raeburn 10181: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10182: my ($resulttext,%rolehash);
10183: $rolehash{'rolecolors'} = {};
1.55 raeburn 10184: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10185: if ($domconfig{'rolecolors'} eq '') {
10186: $domconfig{'rolecolors'} = {};
10187: }
10188: }
1.9 raeburn 10189: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10190: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10191: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10192: $dom);
10193: if ($putresult eq 'ok') {
10194: if (keys(%changes) > 0) {
1.41 raeburn 10195: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10196: if (ref($lastactref) eq 'HASH') {
10197: $lastactref->{'domainconfig'} = 1;
10198: }
1.6 raeburn 10199: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10200: $rolehash{'rolecolors'});
10201: } else {
10202: $resulttext = &mt('No changes made to default color schemes');
10203: }
10204: } else {
1.11 albertel 10205: $resulttext = '<span class="LC_error">'.
10206: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10207: }
10208: if ($errors) {
10209: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10210: $errors.'</ul>';
10211: }
10212: return $resulttext;
10213: }
10214:
10215: sub modify_colors {
1.9 raeburn 10216: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10217: my (%changes,%choices);
1.51 raeburn 10218: my @bgs;
1.6 raeburn 10219: my @links = ('link','alink','vlink');
1.41 raeburn 10220: my @logintext;
1.6 raeburn 10221: my @images;
10222: my $servadm = $r->dir_config('lonAdmEMail');
10223: my $errors;
1.200 raeburn 10224: my %defaults;
1.6 raeburn 10225: foreach my $role (@{$roles}) {
10226: if ($role eq 'login') {
1.12 raeburn 10227: %choices = &login_choices();
1.41 raeburn 10228: @logintext = ('textcol','bgcol');
1.12 raeburn 10229: } else {
10230: %choices = &color_font_choices();
10231: }
10232: if ($role eq 'login') {
1.41 raeburn 10233: @images = ('img','logo','domlogo','login');
1.51 raeburn 10234: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10235: } else {
10236: @images = ('img');
1.200 raeburn 10237: @bgs = ('pgbg','tabbg','sidebg');
10238: }
10239: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10240: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10241: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10242: }
10243: if ($role eq 'login') {
10244: foreach my $item (@logintext) {
1.234 raeburn 10245: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10246: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10247: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10248: }
10249: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 10250: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10251: }
10252: }
10253: } else {
1.234 raeburn 10254: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10255: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10256: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10257: }
10258: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 10259: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10260: }
1.6 raeburn 10261: }
1.200 raeburn 10262: foreach my $item (@bgs) {
1.234 raeburn 10263: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10264: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10265: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10266: }
10267: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 10268: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10269: }
10270: }
10271: foreach my $item (@links) {
1.234 raeburn 10272: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10273: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10274: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10275: }
10276: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 10277: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10278: }
1.6 raeburn 10279: }
1.46 raeburn 10280: my ($configuserok,$author_ok,$switchserver) =
10281: &config_check($dom,$confname,$servadm);
1.9 raeburn 10282: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10283: if (ref($domconfig->{$role}) ne 'HASH') {
10284: $domconfig->{$role} = {};
10285: }
1.8 raeburn 10286: foreach my $img (@images) {
1.70 raeburn 10287: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10288: if (defined($env{'form.login_showlogo_'.$img})) {
10289: $confhash->{$role}{'showlogo'}{$img} = 1;
10290: } else {
10291: $confhash->{$role}{'showlogo'}{$img} = 0;
10292: }
10293: }
1.18 albertel 10294: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10295: && !defined($domconfig->{$role}{$img})
10296: && !$env{'form.'.$role.'_del_'.$img}
10297: && $env{'form.'.$role.'_import_'.$img}) {
10298: # import the old configured image from the .tab setting
10299: # if they haven't provided a new one
10300: $domconfig->{$role}{$img} =
10301: $env{'form.'.$role.'_import_'.$img};
10302: }
1.6 raeburn 10303: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10304: my $error;
1.6 raeburn 10305: if ($configuserok eq 'ok') {
1.9 raeburn 10306: if ($switchserver) {
1.12 raeburn 10307: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10308: } else {
10309: if ($author_ok eq 'ok') {
10310: my ($result,$logourl) =
10311: &publishlogo($r,'upload',$role.'_'.$img,
10312: $dom,$confname,$img,$width,$height);
10313: if ($result eq 'ok') {
10314: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10315: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10316: } else {
1.12 raeburn 10317: $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 10318: }
10319: } else {
1.46 raeburn 10320: $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 10321: }
10322: }
10323: } else {
1.46 raeburn 10324: $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 10325: }
10326: if ($error) {
1.8 raeburn 10327: &Apache::lonnet::logthis($error);
1.11 albertel 10328: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10329: }
10330: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10331: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10332: my $error;
10333: if ($configuserok eq 'ok') {
10334: # is confname an author?
10335: if ($switchserver eq '') {
10336: if ($author_ok eq 'ok') {
10337: my ($result,$logourl) =
10338: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10339: $dom,$confname,$img,$width,$height);
10340: if ($result eq 'ok') {
10341: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10342: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10343: }
10344: }
10345: }
10346: }
1.6 raeburn 10347: }
10348: }
10349: }
10350: if (ref($domconfig) eq 'HASH') {
10351: if (ref($domconfig->{$role}) eq 'HASH') {
10352: foreach my $img (@images) {
10353: if ($domconfig->{$role}{$img} ne '') {
10354: if ($env{'form.'.$role.'_del_'.$img}) {
10355: $confhash->{$role}{$img} = '';
1.12 raeburn 10356: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10357: } else {
1.9 raeburn 10358: if ($confhash->{$role}{$img} eq '') {
10359: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10360: }
1.6 raeburn 10361: }
10362: } else {
10363: if ($env{'form.'.$role.'_del_'.$img}) {
10364: $confhash->{$role}{$img} = '';
1.12 raeburn 10365: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10366: }
10367: }
1.70 raeburn 10368: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10369: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10370: if ($confhash->{$role}{'showlogo'}{$img} ne
10371: $domconfig->{$role}{'showlogo'}{$img}) {
10372: $changes{$role}{'showlogo'}{$img} = 1;
10373: }
10374: } else {
10375: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10376: $changes{$role}{'showlogo'}{$img} = 1;
10377: }
10378: }
10379: }
10380: }
1.6 raeburn 10381: if ($domconfig->{$role}{'font'} ne '') {
10382: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10383: $changes{$role}{'font'} = 1;
10384: }
10385: } else {
10386: if ($confhash->{$role}{'font'}) {
10387: $changes{$role}{'font'} = 1;
10388: }
10389: }
1.107 raeburn 10390: if ($role ne 'login') {
10391: if ($domconfig->{$role}{'fontmenu'} ne '') {
10392: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10393: $changes{$role}{'fontmenu'} = 1;
10394: }
10395: } else {
10396: if ($confhash->{$role}{'fontmenu'}) {
10397: $changes{$role}{'fontmenu'} = 1;
10398: }
1.97 tempelho 10399: }
10400: }
1.6 raeburn 10401: foreach my $item (@bgs) {
10402: if ($domconfig->{$role}{$item} ne '') {
10403: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10404: $changes{$role}{'bgs'}{$item} = 1;
10405: }
10406: } else {
10407: if ($confhash->{$role}{$item}) {
10408: $changes{$role}{'bgs'}{$item} = 1;
10409: }
10410: }
10411: }
10412: foreach my $item (@links) {
10413: if ($domconfig->{$role}{$item} ne '') {
10414: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10415: $changes{$role}{'links'}{$item} = 1;
10416: }
10417: } else {
10418: if ($confhash->{$role}{$item}) {
10419: $changes{$role}{'links'}{$item} = 1;
10420: }
10421: }
10422: }
1.41 raeburn 10423: foreach my $item (@logintext) {
10424: if ($domconfig->{$role}{$item} ne '') {
10425: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10426: $changes{$role}{'logintext'}{$item} = 1;
10427: }
10428: } else {
10429: if ($confhash->{$role}{$item}) {
10430: $changes{$role}{'logintext'}{$item} = 1;
10431: }
10432: }
10433: }
1.6 raeburn 10434: } else {
10435: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10436: \@logintext,$confhash,\%changes);
1.6 raeburn 10437: }
10438: } else {
10439: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10440: \@logintext,$confhash,\%changes);
1.6 raeburn 10441: }
10442: }
10443: return ($errors,%changes);
10444: }
10445:
1.46 raeburn 10446: sub config_check {
10447: my ($dom,$confname,$servadm) = @_;
10448: my ($configuserok,$author_ok,$switchserver,%currroles);
10449: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10450: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10451: $confname,$servadm);
10452: if ($configuserok eq 'ok') {
10453: $switchserver = &check_switchserver($dom,$confname);
10454: if ($switchserver eq '') {
10455: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10456: }
10457: }
10458: return ($configuserok,$author_ok,$switchserver);
10459: }
10460:
1.6 raeburn 10461: sub default_change_checker {
1.41 raeburn 10462: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10463: foreach my $item (@{$links}) {
10464: if ($confhash->{$role}{$item}) {
10465: $changes->{$role}{'links'}{$item} = 1;
10466: }
10467: }
10468: foreach my $item (@{$bgs}) {
10469: if ($confhash->{$role}{$item}) {
10470: $changes->{$role}{'bgs'}{$item} = 1;
10471: }
10472: }
1.41 raeburn 10473: foreach my $item (@{$logintext}) {
10474: if ($confhash->{$role}{$item}) {
10475: $changes->{$role}{'logintext'}{$item} = 1;
10476: }
10477: }
1.6 raeburn 10478: foreach my $img (@{$images}) {
10479: if ($env{'form.'.$role.'_del_'.$img}) {
10480: $confhash->{$role}{$img} = '';
1.12 raeburn 10481: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10482: }
1.70 raeburn 10483: if ($role eq 'login') {
10484: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10485: $changes->{$role}{'showlogo'}{$img} = 1;
10486: }
10487: }
1.6 raeburn 10488: }
10489: if ($confhash->{$role}{'font'}) {
10490: $changes->{$role}{'font'} = 1;
10491: }
1.48 raeburn 10492: }
1.6 raeburn 10493:
10494: sub display_colorchgs {
10495: my ($dom,$changes,$roles,$confhash) = @_;
10496: my (%choices,$resulttext);
10497: if (!grep(/^login$/,@{$roles})) {
10498: $resulttext = &mt('Changes made:').'<br />';
10499: }
10500: foreach my $role (@{$roles}) {
10501: if ($role eq 'login') {
10502: %choices = &login_choices();
10503: } else {
10504: %choices = &color_font_choices();
10505: }
10506: if (ref($changes->{$role}) eq 'HASH') {
10507: if ($role ne 'login') {
10508: $resulttext .= '<h4>'.&mt($role).'</h4>';
10509: }
10510: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10511: if ($role ne 'login') {
10512: $resulttext .= '<ul>';
10513: }
10514: if (ref($changes->{$role}{$key}) eq 'HASH') {
10515: if ($role ne 'login') {
10516: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10517: }
10518: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10519: if (($role eq 'login') && ($key eq 'showlogo')) {
10520: if ($confhash->{$role}{$key}{$item}) {
10521: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10522: } else {
10523: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10524: }
10525: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10526: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10527: } else {
1.12 raeburn 10528: my $newitem = $confhash->{$role}{$item};
10529: if ($key eq 'images') {
1.306 raeburn 10530: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10531: }
10532: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10533: }
10534: }
10535: if ($role ne 'login') {
10536: $resulttext .= '</ul></li>';
10537: }
10538: } else {
10539: if ($confhash->{$role}{$key} eq '') {
10540: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10541: } else {
10542: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10543: }
10544: }
10545: if ($role ne 'login') {
10546: $resulttext .= '</ul>';
10547: }
10548: }
10549: }
10550: }
1.3 raeburn 10551: return $resulttext;
1.1 raeburn 10552: }
10553:
1.9 raeburn 10554: sub thumb_dimensions {
10555: return ('200','50');
10556: }
10557:
1.16 raeburn 10558: sub check_dimensions {
10559: my ($inputfile) = @_;
10560: my ($fullwidth,$fullheight);
10561: if ($inputfile =~ m|^[/\w.\-]+$|) {
10562: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10563: my $imageinfo = <PIPE>;
10564: if (!close(PIPE)) {
10565: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10566: }
10567: chomp($imageinfo);
10568: my ($fullsize) =
1.21 raeburn 10569: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10570: if ($fullsize) {
10571: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10572: }
10573: }
10574: }
10575: return ($fullwidth,$fullheight);
10576: }
10577:
1.9 raeburn 10578: sub check_configuser {
10579: my ($uhome,$dom,$confname,$servadm) = @_;
10580: my ($configuserok,%currroles);
10581: if ($uhome eq 'no_host') {
10582: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
10583: my $configpass = &LONCAPA::Enrollment::create_password();
10584: $configuserok =
10585: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10586: $configpass,'','','','','',undef,$servadm);
10587: } else {
10588: $configuserok = 'ok';
10589: %currroles =
10590: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10591: }
10592: return ($configuserok,%currroles);
10593: }
10594:
10595: sub check_authorstatus {
10596: my ($dom,$confname,%currroles) = @_;
10597: my $author_ok;
1.40 raeburn 10598: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10599: my $start = time;
10600: my $end = 0;
10601: $author_ok =
10602: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10603: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10604: } else {
10605: $author_ok = 'ok';
10606: }
10607: return $author_ok;
10608: }
10609:
10610: sub publishlogo {
1.46 raeburn 10611: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10612: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10613: if ($action eq 'upload') {
10614: $fname=$env{'form.'.$formname.'.filename'};
10615: chop($env{'form.'.$formname});
10616: } else {
10617: ($fname) = ($formname =~ /([^\/]+)$/);
10618: }
1.46 raeburn 10619: if ($savefileas ne '') {
10620: $fname = $savefileas;
10621: }
1.9 raeburn 10622: $fname=&Apache::lonnet::clean_filename($fname);
10623: # See if there is anything left
10624: unless ($fname) { return ('error: no uploaded file'); }
10625: $fname="$subdir/$fname";
1.210 raeburn 10626: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10627: my $filepath="$docroot/priv";
10628: my $relpath = "$dom/$confname";
1.9 raeburn 10629: my ($fnamepath,$file,$fetchthumb);
10630: $file=$fname;
10631: if ($fname=~m|/|) {
10632: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10633: }
1.164 raeburn 10634: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10635: my $count;
1.164 raeburn 10636: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10637: $filepath.="/$parts[$count]";
10638: if ((-e $filepath)!=1) {
10639: mkdir($filepath,02770);
10640: }
10641: }
10642: # Check for bad extension and disallow upload
10643: if ($file=~/\.(\w+)$/ &&
10644: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10645: $output =
1.207 bisitz 10646: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10647: } elsif ($file=~/\.(\w+)$/ &&
10648: !defined(&Apache::loncommon::fileembstyle($1))) {
10649: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10650: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10651: $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 10652: } elsif (-d "$filepath/$file") {
1.195 bisitz 10653: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10654: } else {
10655: my $source = $filepath.'/'.$file;
10656: my $logfile;
1.316 raeburn 10657: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10658: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10659: }
10660: print $logfile
10661: "\n================= Publish ".localtime()." ================\n".
10662: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10663: # Save the file
1.316 raeburn 10664: if (!open(FH,">",$source)) {
1.9 raeburn 10665: &Apache::lonnet::logthis('Failed to create '.$source);
10666: return (&mt('Failed to create file'));
10667: }
10668: if ($action eq 'upload') {
10669: if (!print FH ($env{'form.'.$formname})) {
10670: &Apache::lonnet::logthis('Failed to write to '.$source);
10671: return (&mt('Failed to write file'));
10672: }
10673: } else {
10674: my $original = &Apache::lonnet::filelocation('',$formname);
10675: if(!copy($original,$source)) {
10676: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10677: return (&mt('Failed to write file'));
10678: }
10679: }
10680: close(FH);
10681: chmod(0660, $source); # Permissions to rw-rw---.
10682:
10683: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10684: my $copyfile=$targetdir.'/'.$file;
10685:
10686: my @parts=split(/\//,$targetdir);
10687: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10688: for (my $count=5;$count<=$#parts;$count++) {
10689: $path.="/$parts[$count]";
10690: if (!-e $path) {
10691: print $logfile "\nCreating directory ".$path;
10692: mkdir($path,02770);
10693: }
10694: }
10695: my $versionresult;
10696: if (-e $copyfile) {
10697: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10698: } else {
10699: $versionresult = 'ok';
10700: }
10701: if ($versionresult eq 'ok') {
10702: if (copy($source,$copyfile)) {
10703: print $logfile "\nCopied original source to ".$copyfile."\n";
10704: $output = 'ok';
10705: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10706: push(@{$modified_urls},[$copyfile,$source]);
10707: my $metaoutput =
10708: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10709: unless ($registered_cleanup) {
10710: my $handlers = $r->get_handlers('PerlCleanupHandler');
10711: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10712: $registered_cleanup=1;
10713: }
1.9 raeburn 10714: } else {
10715: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10716: $output = &mt('Failed to copy file to RES space').", $!";
10717: }
10718: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10719: my $inputfile = $filepath.'/'.$file;
10720: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10721: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10722: if ($fullwidth ne '' && $fullheight ne '') {
10723: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10724: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10725: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10726: system({$args[0]} @args);
1.16 raeburn 10727: chmod(0660, $filepath.'/tn-'.$file);
10728: if (-e $outfile) {
10729: my $copyfile=$targetdir.'/tn-'.$file;
10730: if (copy($outfile,$copyfile)) {
10731: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10732: my $thumb_metaoutput =
10733: &write_metadata($dom,$confname,$formname,
10734: $targetdir,'tn-'.$file,$logfile);
10735: push(@{$modified_urls},[$copyfile,$outfile]);
10736: unless ($registered_cleanup) {
10737: my $handlers = $r->get_handlers('PerlCleanupHandler');
10738: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10739: $registered_cleanup=1;
10740: }
1.267 raeburn 10741: $madethumb = 1;
1.16 raeburn 10742: } else {
10743: print $logfile "\nUnable to write ".$copyfile.
10744: ':'.$!."\n";
10745: }
10746: }
1.9 raeburn 10747: }
10748: }
10749: }
10750: } else {
10751: $output = $versionresult;
10752: }
10753: }
1.267 raeburn 10754: return ($output,$logourl,$madethumb);
1.9 raeburn 10755: }
10756:
10757: sub logo_versioning {
10758: my ($targetdir,$file,$logfile) = @_;
10759: my $target = $targetdir.'/'.$file;
10760: my ($maxversion,$fn,$extn,$output);
10761: $maxversion = 0;
10762: if ($file =~ /^(.+)\.(\w+)$/) {
10763: $fn=$1;
10764: $extn=$2;
10765: }
10766: opendir(DIR,$targetdir);
10767: while (my $filename=readdir(DIR)) {
10768: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10769: $maxversion=($1>$maxversion)?$1:$maxversion;
10770: }
10771: }
10772: $maxversion++;
10773: print $logfile "\nCreating old version ".$maxversion."\n";
10774: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10775: if (copy($target,$copyfile)) {
10776: print $logfile "Copied old target to ".$copyfile."\n";
10777: $copyfile=$copyfile.'.meta';
10778: if (copy($target.'.meta',$copyfile)) {
10779: print $logfile "Copied old target metadata to ".$copyfile."\n";
10780: $output = 'ok';
10781: } else {
10782: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
10783: $output = &mt('Failed to copy old meta').", $!, ";
10784: }
10785: } else {
10786: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
10787: $output = &mt('Failed to copy old target').", $!, ";
10788: }
10789: return $output;
10790: }
10791:
10792: sub write_metadata {
10793: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
10794: my (%metadatafields,%metadatakeys,$output);
10795: $metadatafields{'title'}=$formname;
10796: $metadatafields{'creationdate'}=time;
10797: $metadatafields{'lastrevisiondate'}=time;
10798: $metadatafields{'copyright'}='public';
10799: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
10800: $env{'user.domain'};
10801: $metadatafields{'authorspace'}=$confname.':'.$dom;
10802: $metadatafields{'domain'}=$dom;
10803: {
10804: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
10805: my $mfh;
1.316 raeburn 10806: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 10807: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 10808: unless ($_=~/\./) {
10809: my $unikey=$_;
10810: $unikey=~/^([A-Za-z]+)/;
10811: my $tag=$1;
10812: $tag=~tr/A-Z/a-z/;
10813: print $mfh "\n\<$tag";
10814: foreach (split(/\,/,$metadatakeys{$unikey})) {
10815: my $value=$metadatafields{$unikey.'.'.$_};
10816: $value=~s/\"/\'\'/g;
10817: print $mfh ' '.$_.'="'.$value.'"';
10818: }
10819: print $mfh '>'.
10820: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
10821: .'</'.$tag.'>';
10822: }
10823: }
10824: $output = 'ok';
10825: print $logfile "\nWrote metadata";
10826: close($mfh);
10827: } else {
10828: print $logfile "\nFailed to open metadata file";
1.9 raeburn 10829: $output = &mt('Could not write metadata');
10830: }
10831: }
1.155 raeburn 10832: return $output;
10833: }
10834:
10835: sub notifysubscribed {
10836: foreach my $targetsource (@{$modified_urls}){
10837: next unless (ref($targetsource) eq 'ARRAY');
10838: my ($target,$source)=@{$targetsource};
10839: if ($source ne '') {
1.316 raeburn 10840: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 10841: print $logfh "\nCleanup phase: Notifications\n";
10842: my @subscribed=&subscribed_hosts($target);
10843: foreach my $subhost (@subscribed) {
10844: print $logfh "\nNotifying host ".$subhost.':';
10845: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
10846: print $logfh $reply;
10847: }
10848: my @subscribedmeta=&subscribed_hosts("$target.meta");
10849: foreach my $subhost (@subscribedmeta) {
10850: print $logfh "\nNotifying host for metadata only ".$subhost.':';
10851: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
10852: $subhost);
10853: print $logfh $reply;
10854: }
10855: print $logfh "\n============ Done ============\n";
1.160 raeburn 10856: close($logfh);
1.155 raeburn 10857: }
10858: }
10859: }
10860: return OK;
10861: }
10862:
10863: sub subscribed_hosts {
10864: my ($target) = @_;
10865: my @subscribed;
1.316 raeburn 10866: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 10867: while (my $subline=<$fh>) {
10868: if ($subline =~ /^($match_lonid):/) {
10869: my $host = $1;
10870: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
10871: unless (grep(/^\Q$host\E$/,@subscribed)) {
10872: push(@subscribed,$host);
10873: }
10874: }
10875: }
10876: }
10877: }
10878: return @subscribed;
1.9 raeburn 10879: }
10880:
10881: sub check_switchserver {
10882: my ($dom,$confname) = @_;
10883: my ($allowed,$switchserver);
10884: my $home = &Apache::lonnet::homeserver($confname,$dom);
10885: if ($home eq 'no_host') {
10886: $home = &Apache::lonnet::domain($dom,'primary');
10887: }
10888: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 10889: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
10890: if (!$allowed) {
1.180 raeburn 10891: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 10892: }
10893: return $switchserver;
10894: }
10895:
1.1 raeburn 10896: sub modify_quotas {
1.216 raeburn 10897: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 10898: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 10899: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 10900: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
10901: $validationfieldsref);
1.86 raeburn 10902: if ($action eq 'quotas') {
10903: $context = 'tools';
1.163 raeburn 10904: } else {
1.86 raeburn 10905: $context = $action;
10906: }
10907: if ($context eq 'requestcourses') {
1.325 raeburn 10908: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 10909: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 10910: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
10911: %titles = &courserequest_titles();
10912: $toolregexp = join('|',@usertools);
10913: %conditions = &courserequest_conditions();
1.216 raeburn 10914: $confname = $dom.'-domainconfig';
10915: my $servadm = $r->dir_config('lonAdmEMail');
10916: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 10917: ($validationitemsref,$validationnamesref,$validationfieldsref) =
10918: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 10919: } elsif ($context eq 'requestauthor') {
10920: @usertools = ('author');
10921: %titles = &authorrequest_titles();
1.86 raeburn 10922: } else {
1.162 raeburn 10923: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 10924: %titles = &tool_titles();
1.86 raeburn 10925: }
1.212 raeburn 10926: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 10927: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10928: foreach my $key (keys(%env)) {
1.101 raeburn 10929: if ($context eq 'requestcourses') {
10930: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
10931: my $item = $1;
10932: my $type = $2;
10933: if ($type =~ /^limit_(.+)/) {
10934: $limithash{$item}{$1} = $env{$key};
10935: } else {
10936: $confhash{$item}{$type} = $env{$key};
10937: }
10938: }
1.163 raeburn 10939: } elsif ($context eq 'requestauthor') {
10940: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
10941: $confhash{$1} = $env{$key};
10942: }
1.101 raeburn 10943: } else {
1.86 raeburn 10944: if ($key =~ /^form\.quota_(.+)$/) {
10945: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 10946: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
10947: $confhash{'authorquota'}{$1} = $env{$key};
10948: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 10949: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
10950: }
1.72 raeburn 10951: }
10952: }
1.163 raeburn 10953: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 10954: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 10955: @approvalnotify = sort(@approvalnotify);
10956: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 10957: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 10958: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
10959: foreach my $type (@hasuniquecode) {
10960: if (grep(/^\Q$type\E$/,@crstypes)) {
10961: $confhash{'uniquecode'}{$type} = 1;
10962: }
1.216 raeburn 10963: }
1.242 raeburn 10964: my (%newbook,%allpos);
1.216 raeburn 10965: if ($context eq 'requestcourses') {
1.242 raeburn 10966: foreach my $type ('textbooks','templates') {
10967: @{$allpos{$type}} = ();
10968: my $invalid;
10969: if ($type eq 'textbooks') {
10970: $invalid = &mt('Invalid LON-CAPA course for textbook');
10971: } else {
10972: $invalid = &mt('Invalid LON-CAPA course for template');
10973: }
10974: if ($env{'form.'.$type.'_addbook'}) {
10975: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
10976: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
10977: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
10978: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
10979: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
10980: } else {
10981: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
10982: my $position = $env{'form.'.$type.'_addbook_pos'};
10983: $position =~ s/\D+//g;
10984: if ($position ne '') {
10985: $allpos{$type}[$position] = $newbook{$type};
10986: }
1.216 raeburn 10987: }
1.242 raeburn 10988: } else {
10989: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 10990: }
10991: }
1.242 raeburn 10992: }
1.216 raeburn 10993: }
1.102 raeburn 10994: if (ref($domconfig{$action}) eq 'HASH') {
10995: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
10996: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
10997: $changes{'notify'}{'approval'} = 1;
10998: }
10999: } else {
1.144 raeburn 11000: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11001: $changes{'notify'}{'approval'} = 1;
11002: }
11003: }
1.218 raeburn 11004: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11005: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11006: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11007: unless ($confhash{'uniquecode'}{$crstype}) {
11008: $changes{'uniquecode'} = 1;
11009: }
11010: }
11011: unless ($changes{'uniquecode'}) {
11012: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11013: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11014: $changes{'uniquecode'} = 1;
11015: }
11016: }
11017: }
11018: } else {
11019: $changes{'uniquecode'} = 1;
11020: }
11021: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11022: $changes{'uniquecode'} = 1;
1.216 raeburn 11023: }
11024: if ($context eq 'requestcourses') {
1.242 raeburn 11025: foreach my $type ('textbooks','templates') {
11026: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11027: my %deletions;
11028: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11029: if (@todelete) {
11030: map { $deletions{$_} = 1; } @todelete;
11031: }
11032: my %imgdeletions;
11033: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11034: if (@todeleteimages) {
11035: map { $imgdeletions{$_} = 1; } @todeleteimages;
11036: }
11037: my $maxnum = $env{'form.'.$type.'_maxnum'};
11038: for (my $i=0; $i<=$maxnum; $i++) {
11039: my $itemid = $env{'form.'.$type.'_id_'.$i};
11040: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11041: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11042: if ($deletions{$key}) {
11043: if ($domconfig{$action}{$type}{$key}{'image'}) {
11044: #FIXME need to obsolete item in RES space
11045: }
11046: next;
11047: } else {
11048: my $newpos = $env{'form.'.$itemid};
11049: $newpos =~ s/\D+//g;
1.243 raeburn 11050: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 11051: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 11052: ($type eq 'templates'));
1.242 raeburn 11053: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11054: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11055: $changes{$type}{$key} = 1;
11056: }
11057: }
11058: $allpos{$type}[$newpos] = $key;
11059: }
11060: if ($imgdeletions{$key}) {
11061: $changes{$type}{$key} = 1;
1.216 raeburn 11062: #FIXME need to obsolete item in RES space
1.242 raeburn 11063: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11064: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 11065: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11066: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11067: } else {
11068: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11069: $cdom,$cnum,$type,$configuserok,
11070: $switchserver,$author_ok);
11071: if ($imgurl) {
11072: $confhash{$type}{$key}{'image'} = $imgurl;
11073: $changes{$type}{$key} = 1;
11074: }
11075: if ($error) {
11076: &Apache::lonnet::logthis($error);
11077: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11078: }
11079: }
1.242 raeburn 11080: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11081: $confhash{$type}{$key}{'image'} =
11082: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 11083: }
11084: }
11085: }
11086: }
11087: }
11088: }
1.102 raeburn 11089: } else {
1.144 raeburn 11090: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11091: $changes{'notify'}{'approval'} = 1;
11092: }
1.218 raeburn 11093: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 11094: $changes{'uniquecode'} = 1;
11095: }
11096: }
11097: if ($context eq 'requestcourses') {
1.242 raeburn 11098: foreach my $type ('textbooks','templates') {
11099: if ($newbook{$type}) {
11100: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 11101: foreach my $item ('subject','title','publisher','author') {
11102: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11103: ($type eq 'template'));
1.242 raeburn 11104: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11105: if ($env{'form.'.$type.'_addbook_'.$item}) {
11106: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11107: }
11108: }
11109: if ($type eq 'textbooks') {
11110: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11111: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 11112: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11113: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11114: } else {
11115: my ($imageurl,$error) =
11116: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11117: $configuserok,$switchserver,$author_ok);
11118: if ($imageurl) {
11119: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11120: }
11121: if ($error) {
11122: &Apache::lonnet::logthis($error);
11123: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11124: }
1.242 raeburn 11125: }
11126: }
1.216 raeburn 11127: }
11128: }
1.242 raeburn 11129: if (@{$allpos{$type}} > 0) {
11130: my $idx = 0;
11131: foreach my $item (@{$allpos{$type}}) {
11132: if ($item ne '') {
11133: $confhash{$type}{$item}{'order'} = $idx;
11134: if (ref($domconfig{$action}) eq 'HASH') {
11135: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11136: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11137: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11138: $changes{$type}{$item} = 1;
11139: }
1.216 raeburn 11140: }
11141: }
11142: }
1.242 raeburn 11143: $idx ++;
1.216 raeburn 11144: }
11145: }
11146: }
11147: }
1.235 raeburn 11148: if (ref($validationitemsref) eq 'ARRAY') {
11149: foreach my $item (@{$validationitemsref}) {
11150: if ($item eq 'fields') {
11151: my @changed;
11152: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11153: if (@{$confhash{'validation'}{$item}} > 0) {
11154: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11155: }
1.266 raeburn 11156: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11157: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11158: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11159: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11160: $domconfig{'requestcourses'}{'validation'}{$item});
11161: } else {
11162: @changed = @{$confhash{'validation'}{$item}};
11163: }
1.235 raeburn 11164: } else {
11165: @changed = @{$confhash{'validation'}{$item}};
11166: }
11167: } else {
11168: @changed = @{$confhash{'validation'}{$item}};
11169: }
11170: if (@changed) {
11171: if ($confhash{'validation'}{$item}) {
11172: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11173: } else {
11174: $changes{'validation'}{$item} = &mt('None');
11175: }
11176: }
11177: } else {
11178: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11179: if ($item eq 'markup') {
11180: if ($env{'form.requestcourses_validation_'.$item}) {
11181: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11182: }
11183: }
1.266 raeburn 11184: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11185: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11186: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11187: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11188: }
11189: } else {
11190: if ($confhash{'validation'}{$item} ne '') {
11191: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11192: }
1.235 raeburn 11193: }
11194: } else {
11195: if ($confhash{'validation'}{$item} ne '') {
11196: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11197: }
11198: }
11199: }
11200: }
11201: }
11202: if ($env{'form.validationdc'}) {
11203: my $newval = $env{'form.validationdc'};
1.285 raeburn 11204: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 11205: if (exists($domcoords{$newval})) {
11206: $confhash{'validation'}{'dc'} = $newval;
11207: }
11208: }
11209: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 11210: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11211: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11212: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11213: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11214: if ($confhash{'validation'}{'dc'} eq '') {
11215: $changes{'validation'}{'dc'} = &mt('None');
11216: } else {
11217: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11218: }
1.235 raeburn 11219: }
1.266 raeburn 11220: } elsif ($confhash{'validation'}{'dc'} ne '') {
11221: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 11222: }
11223: } elsif ($confhash{'validation'}{'dc'} ne '') {
11224: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11225: }
11226: } elsif ($confhash{'validation'}{'dc'} ne '') {
11227: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 11228: }
1.266 raeburn 11229: } else {
11230: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11231: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11232: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11233: $changes{'validation'}{'dc'} = &mt('None');
11234: }
11235: }
1.235 raeburn 11236: }
11237: }
1.102 raeburn 11238: }
11239: } else {
1.86 raeburn 11240: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 11241: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11242: }
1.72 raeburn 11243: foreach my $item (@usertools) {
11244: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11245: my $unset;
1.101 raeburn 11246: if ($context eq 'requestcourses') {
1.104 raeburn 11247: $unset = '0';
11248: if ($type eq '_LC_adv') {
11249: $unset = '';
11250: }
1.101 raeburn 11251: if ($confhash{$item}{$type} eq 'autolimit') {
11252: $confhash{$item}{$type} .= '=';
11253: unless ($limithash{$item}{$type} =~ /\D/) {
11254: $confhash{$item}{$type} .= $limithash{$item}{$type};
11255: }
11256: }
1.163 raeburn 11257: } elsif ($context eq 'requestauthor') {
11258: $unset = '0';
11259: if ($type eq '_LC_adv') {
11260: $unset = '';
11261: }
1.72 raeburn 11262: } else {
1.101 raeburn 11263: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11264: $confhash{$item}{$type} = 1;
11265: } else {
11266: $confhash{$item}{$type} = 0;
11267: }
1.72 raeburn 11268: }
1.86 raeburn 11269: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 11270: if ($action eq 'requestauthor') {
11271: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11272: $changes{$type} = 1;
11273: }
11274: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11275: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11276: $changes{$item}{$type} = 1;
11277: }
11278: } else {
11279: if ($context eq 'requestcourses') {
1.104 raeburn 11280: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11281: $changes{$item}{$type} = 1;
11282: }
11283: } else {
11284: if (!$confhash{$item}{$type}) {
11285: $changes{$item}{$type} = 1;
11286: }
11287: }
11288: }
11289: } else {
11290: if ($context eq 'requestcourses') {
1.104 raeburn 11291: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11292: $changes{$item}{$type} = 1;
11293: }
1.163 raeburn 11294: } elsif ($context eq 'requestauthor') {
11295: if ($confhash{$type} ne $unset) {
11296: $changes{$type} = 1;
11297: }
1.72 raeburn 11298: } else {
11299: if (!$confhash{$item}{$type}) {
11300: $changes{$item}{$type} = 1;
11301: }
11302: }
11303: }
1.1 raeburn 11304: }
11305: }
1.163 raeburn 11306: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11307: if (ref($domconfig{'quotas'}) eq 'HASH') {
11308: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11309: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11310: if (exists($confhash{'defaultquota'}{$key})) {
11311: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11312: $changes{'defaultquota'}{$key} = 1;
11313: }
11314: } else {
11315: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11316: }
11317: }
1.86 raeburn 11318: } else {
11319: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11320: if (exists($confhash{'defaultquota'}{$key})) {
11321: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11322: $changes{'defaultquota'}{$key} = 1;
11323: }
11324: } else {
11325: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11326: }
1.1 raeburn 11327: }
11328: }
1.197 raeburn 11329: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11330: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11331: if (exists($confhash{'authorquota'}{$key})) {
11332: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11333: $changes{'authorquota'}{$key} = 1;
11334: }
11335: } else {
11336: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11337: }
11338: }
11339: }
1.1 raeburn 11340: }
1.86 raeburn 11341: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11342: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11343: if (ref($domconfig{'quotas'}) eq 'HASH') {
11344: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11345: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11346: $changes{'defaultquota'}{$key} = 1;
11347: }
11348: } else {
11349: if (!exists($domconfig{'quotas'}{$key})) {
11350: $changes{'defaultquota'}{$key} = 1;
11351: }
1.72 raeburn 11352: }
11353: } else {
1.86 raeburn 11354: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11355: }
1.1 raeburn 11356: }
11357: }
1.197 raeburn 11358: if (ref($confhash{'authorquota'}) eq 'HASH') {
11359: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11360: if (ref($domconfig{'quotas'}) eq 'HASH') {
11361: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11362: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11363: $changes{'authorquota'}{$key} = 1;
11364: }
11365: } else {
11366: $changes{'authorquota'}{$key} = 1;
11367: }
11368: } else {
11369: $changes{'authorquota'}{$key} = 1;
11370: }
11371: }
11372: }
1.1 raeburn 11373: }
1.72 raeburn 11374:
1.163 raeburn 11375: if ($context eq 'requestauthor') {
11376: $domdefaults{'requestauthor'} = \%confhash;
11377: } else {
11378: foreach my $key (keys(%confhash)) {
1.242 raeburn 11379: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11380: $domdefaults{$key} = $confhash{$key};
11381: }
1.163 raeburn 11382: }
1.72 raeburn 11383: }
1.163 raeburn 11384:
1.1 raeburn 11385: my %quotahash = (
1.86 raeburn 11386: $action => { %confhash }
1.1 raeburn 11387: );
11388: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11389: $dom);
11390: if ($putresult eq 'ok') {
11391: if (keys(%changes) > 0) {
1.72 raeburn 11392: my $cachetime = 24*60*60;
11393: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11394: if (ref($lastactref) eq 'HASH') {
11395: $lastactref->{'domdefaults'} = 1;
11396: }
1.1 raeburn 11397: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11398: unless (($context eq 'requestcourses') ||
1.163 raeburn 11399: ($context eq 'requestauthor')) {
1.86 raeburn 11400: if (ref($changes{'defaultquota'}) eq 'HASH') {
11401: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11402: foreach my $type (@{$types},'default') {
11403: if (defined($changes{'defaultquota'}{$type})) {
11404: my $typetitle = $usertypes->{$type};
11405: if ($type eq 'default') {
11406: $typetitle = $othertitle;
11407: }
1.213 raeburn 11408: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11409: }
11410: }
1.86 raeburn 11411: $resulttext .= '</ul></li>';
1.72 raeburn 11412: }
1.197 raeburn 11413: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11414: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11415: foreach my $type (@{$types},'default') {
11416: if (defined($changes{'authorquota'}{$type})) {
11417: my $typetitle = $usertypes->{$type};
11418: if ($type eq 'default') {
11419: $typetitle = $othertitle;
11420: }
1.213 raeburn 11421: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11422: }
11423: }
11424: $resulttext .= '</ul></li>';
11425: }
1.72 raeburn 11426: }
1.80 raeburn 11427: my %newenv;
1.72 raeburn 11428: foreach my $item (@usertools) {
1.163 raeburn 11429: my (%haschgs,%inconf);
11430: if ($context eq 'requestauthor') {
11431: %haschgs = %changes;
1.210 raeburn 11432: %inconf = %confhash;
1.163 raeburn 11433: } else {
11434: if (ref($changes{$item}) eq 'HASH') {
11435: %haschgs = %{$changes{$item}};
11436: }
11437: if (ref($confhash{$item}) eq 'HASH') {
11438: %inconf = %{$confhash{$item}};
11439: }
11440: }
11441: if (keys(%haschgs) > 0) {
1.80 raeburn 11442: my $newacc =
11443: &Apache::lonnet::usertools_access($env{'user.name'},
11444: $env{'user.domain'},
1.86 raeburn 11445: $item,'reload',$context);
1.210 raeburn 11446: if (($context eq 'requestcourses') ||
1.163 raeburn 11447: ($context eq 'requestauthor')) {
1.108 raeburn 11448: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11449: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11450: }
11451: } else {
11452: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11453: $newenv{'environment.availabletools.'.$item} = $newacc;
11454: }
1.80 raeburn 11455: }
1.163 raeburn 11456: unless ($context eq 'requestauthor') {
11457: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11458: }
1.72 raeburn 11459: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11460: if ($haschgs{$type}) {
1.72 raeburn 11461: my $typetitle = $usertypes->{$type};
11462: if ($type eq 'default') {
11463: $typetitle = $othertitle;
11464: } elsif ($type eq '_LC_adv') {
11465: $typetitle = 'LON-CAPA Advanced Users';
11466: }
1.163 raeburn 11467: if ($inconf{$type}) {
1.101 raeburn 11468: if ($context eq 'requestcourses') {
11469: my $cond;
1.163 raeburn 11470: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11471: if ($1 eq '') {
11472: $cond = &mt('(Automatic processing of any request).');
11473: } else {
11474: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11475: }
11476: } else {
1.163 raeburn 11477: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11478: }
11479: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11480: } elsif ($context eq 'requestauthor') {
11481: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11482: $titles{$inconf{$type}},$typetitle);
11483:
1.101 raeburn 11484: } else {
11485: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11486: }
1.72 raeburn 11487: } else {
1.104 raeburn 11488: if ($type eq '_LC_adv') {
1.163 raeburn 11489: if ($inconf{$type} eq '0') {
1.104 raeburn 11490: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11491: } else {
11492: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11493: }
11494: } else {
11495: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11496: }
1.72 raeburn 11497: }
11498: }
1.26 raeburn 11499: }
1.163 raeburn 11500: unless ($context eq 'requestauthor') {
11501: $resulttext .= '</ul></li>';
11502: }
1.26 raeburn 11503: }
1.1 raeburn 11504: }
1.163 raeburn 11505: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11506: if (ref($changes{'notify'}) eq 'HASH') {
11507: if ($changes{'notify'}{'approval'}) {
11508: if (ref($confhash{'notify'}) eq 'HASH') {
11509: if ($confhash{'notify'}{'approval'}) {
11510: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11511: } else {
1.163 raeburn 11512: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11513: }
11514: }
11515: }
11516: }
11517: }
1.216 raeburn 11518: if ($action eq 'requestcourses') {
11519: my @offon = ('off','on');
11520: if ($changes{'uniquecode'}) {
1.218 raeburn 11521: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11522: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11523: $resulttext .= '<li>'.
11524: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11525: '</li>';
11526: } else {
11527: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11528: '</li>';
11529: }
1.216 raeburn 11530: }
1.242 raeburn 11531: foreach my $type ('textbooks','templates') {
11532: if (ref($changes{$type}) eq 'HASH') {
11533: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11534: foreach my $key (sort(keys(%{$changes{$type}}))) {
11535: my %coursehash = &Apache::lonnet::coursedescription($key);
11536: my $coursetitle = $coursehash{'description'};
11537: my $position = $confhash{$type}{$key}{'order'} + 1;
11538: $resulttext .= '<li>';
1.243 raeburn 11539: foreach my $item ('subject','title','publisher','author') {
11540: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11541: ($type eq 'templates'));
1.242 raeburn 11542: my $name = $item.':';
11543: $name =~ s/^(\w)/\U$1/;
11544: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11545: }
11546: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11547: if ($type eq 'textbooks') {
11548: if ($confhash{$type}{$key}{'image'}) {
11549: $resulttext .= ' '.&mt('Image: [_1]',
11550: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11551: ' alt="Textbook cover" />').'<br />';
11552: }
11553: }
11554: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11555: }
1.242 raeburn 11556: $resulttext .= '</ul></li>';
1.216 raeburn 11557: }
11558: }
1.235 raeburn 11559: if (ref($changes{'validation'}) eq 'HASH') {
11560: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11561: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11562: foreach my $item (@{$validationitemsref}) {
11563: if (exists($changes{'validation'}{$item})) {
11564: if ($item eq 'markup') {
11565: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11566: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11567: } else {
11568: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11569: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11570: }
11571: }
11572: }
11573: if (exists($changes{'validation'}{'dc'})) {
11574: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11575: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11576: }
11577: }
11578: }
1.216 raeburn 11579: }
1.1 raeburn 11580: $resulttext .= '</ul>';
1.80 raeburn 11581: if (keys(%newenv)) {
11582: &Apache::lonnet::appenv(\%newenv);
11583: }
1.1 raeburn 11584: } else {
1.86 raeburn 11585: if ($context eq 'requestcourses') {
11586: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11587: } elsif ($context eq 'requestauthor') {
11588: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11589: } else {
1.90 weissno 11590: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11591: }
1.1 raeburn 11592: }
11593: } else {
1.11 albertel 11594: $resulttext = '<span class="LC_error">'.
11595: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11596: }
1.216 raeburn 11597: if ($errors) {
11598: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11599: '<ul>'.$errors.'</ul></p>';
11600: }
1.3 raeburn 11601: return $resulttext;
1.1 raeburn 11602: }
11603:
1.216 raeburn 11604: sub process_textbook_image {
1.242 raeburn 11605: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11606: my $filename = $env{'form.'.$caller.'.filename'};
11607: my ($error,$url);
11608: my ($width,$height) = (50,50);
11609: if ($configuserok eq 'ok') {
11610: if ($switchserver) {
11611: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11612: $switchserver);
11613: } elsif ($author_ok eq 'ok') {
11614: my ($result,$imageurl) =
11615: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11616: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11617: if ($result eq 'ok') {
11618: $url = $imageurl;
11619: } else {
11620: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11621: }
11622: } else {
11623: $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);
11624: }
11625: } else {
11626: $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);
11627: }
11628: return ($url,$error);
11629: }
11630:
1.267 raeburn 11631: sub modify_ltitools {
11632: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11633: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11634: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11635: my $confname = $dom.'-domainconfig';
11636: my $servadm = $r->dir_config('lonAdmEMail');
11637: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11638: my (%posslti,%possfield);
11639: my @courseroles = ('cc','in','ta','ep','st');
11640: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11641: map { $posslti{$_} = 1; } @ltiroles;
11642: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11643: map { $possfield{$_} = 1; } @allfields;
11644: my %lt = <itools_names();
11645: if ($env{'form.ltitools_add'}) {
11646: my $title = $env{'form.ltitools_add_title'};
11647: $title =~ s/(`)/'/g;
11648: ($newid,my $error) = &get_ltitools_id($dom,$title);
11649: if ($newid) {
11650: my $position = $env{'form.ltitools_add_pos'};
11651: $position =~ s/\D+//g;
11652: if ($position ne '') {
11653: $allpos[$position] = $newid;
11654: }
11655: $changes{$newid} = 1;
1.322 raeburn 11656: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11657: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11658: if ($item eq 'lifetime') {
11659: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11660: }
1.267 raeburn 11661: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11662: if (($item eq 'key') || ($item eq 'secret')) {
11663: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11664: } else {
11665: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11666: }
1.267 raeburn 11667: }
11668: }
11669: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11670: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11671: }
11672: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11673: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11674: }
1.323 raeburn 11675: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11676: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11677: } else {
11678: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11679: }
1.296 raeburn 11680: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11681: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11682: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11683: if (($item eq 'width') || ($item eq 'height')) {
11684: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11685: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11686: }
11687: } else {
11688: if ($env{'form.ltitools_add_'.$item} ne '') {
11689: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11690: }
1.267 raeburn 11691: }
11692: }
11693: if ($env{'form.ltitools_add_target'} eq 'window') {
11694: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11695: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11696: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11697: } else {
11698: $confhash{$newid}{'display'}{'target'} = 'iframe';
11699: }
11700: foreach my $item ('passback','roster') {
1.319 raeburn 11701: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11702: $confhash{$newid}{$item} = 1;
1.319 raeburn 11703: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11704: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11705: $lifetime =~ s/^\s+|\s+$//g;
11706: if ($lifetime =~ /^\d+\.?\d*$/) {
11707: $confhash{$newid}{$item.'valid'} = $lifetime;
11708: }
11709: }
1.267 raeburn 11710: }
11711: }
11712: if ($env{'form.ltitools_add_image.filename'} ne '') {
11713: my ($imageurl,$error) =
1.307 raeburn 11714: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11715: $configuserok,$switchserver,$author_ok);
11716: if ($imageurl) {
11717: $confhash{$newid}{'image'} = $imageurl;
11718: }
11719: if ($error) {
11720: &Apache::lonnet::logthis($error);
11721: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11722: }
11723: }
11724: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11725: foreach my $field (@fields) {
11726: if ($possfield{$field}) {
11727: if ($field eq 'roles') {
11728: foreach my $role (@courseroles) {
11729: my $choice = $env{'form.ltitools_add_roles_'.$role};
11730: if (($choice ne '') && ($posslti{$choice})) {
11731: $confhash{$newid}{'roles'}{$role} = $choice;
11732: if ($role eq 'cc') {
11733: $confhash{$newid}{'roles'}{'co'} = $choice;
11734: }
11735: }
11736: }
11737: } else {
11738: $confhash{$newid}{'fields'}{$field} = 1;
11739: }
11740: }
11741: }
1.324 raeburn 11742: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11743: if ($confhash{$newid}{'fields'}{'user'}) {
11744: if ($env{'form.ltitools_userincdom_add'}) {
11745: $confhash{$newid}{'incdom'} = 1;
11746: }
11747: }
11748: }
1.273 raeburn 11749: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11750: foreach my $item (@courseconfig) {
11751: $confhash{$newid}{'crsconf'}{$item} = 1;
11752: }
1.267 raeburn 11753: if ($env{'form.ltitools_add_custom'}) {
11754: my $name = $env{'form.ltitools_add_custom_name'};
11755: my $value = $env{'form.ltitools_add_custom_value'};
11756: $value =~ s/(`)/'/g;
11757: $name =~ s/(`)/'/g;
11758: $confhash{$newid}{'custom'}{$name} = $value;
11759: }
11760: } else {
11761: my $error = &mt('Failed to acquire unique ID for new external tool');
11762: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11763: }
11764: }
11765: if (ref($domconfig{$action}) eq 'HASH') {
11766: my %deletions;
11767: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11768: if (@todelete) {
11769: map { $deletions{$_} = 1; } @todelete;
11770: }
11771: my %customadds;
11772: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11773: if (@newcustom) {
11774: map { $customadds{$_} = 1; } @newcustom;
11775: }
11776: my %imgdeletions;
11777: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11778: if (@todeleteimages) {
11779: map { $imgdeletions{$_} = 1; } @todeleteimages;
11780: }
11781: my $maxnum = $env{'form.ltitools_maxnum'};
11782: for (my $i=0; $i<=$maxnum; $i++) {
11783: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 11784: $itemid =~ s/\D+//g;
1.267 raeburn 11785: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
11786: if ($deletions{$itemid}) {
11787: if ($domconfig{$action}{$itemid}{'image'}) {
11788: #FIXME need to obsolete item in RES space
11789: }
11790: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
11791: next;
11792: } else {
11793: my $newpos = $env{'form.ltitools_'.$itemid};
11794: $newpos =~ s/\D+//g;
1.322 raeburn 11795: foreach my $item ('title','url','lifetime') {
1.267 raeburn 11796: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11797: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
11798: $changes{$itemid} = 1;
11799: }
11800: }
1.297 raeburn 11801: foreach my $item ('key','secret') {
11802: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11803: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
11804: $changes{$itemid} = 1;
11805: }
11806: }
1.267 raeburn 11807: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
11808: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
11809: }
11810: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
11811: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
11812: }
1.323 raeburn 11813: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
11814: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
11815: } else {
11816: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
11817: }
11818: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
11819: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
11820: $changes{$itemid} = 1;
11821: }
11822: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
11823: $changes{$itemid} = 1;
11824: }
1.267 raeburn 11825: foreach my $size ('width','height') {
11826: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
11827: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
11828: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
11829: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
11830: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11831: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
11832: $changes{$itemid} = 1;
11833: }
11834: } else {
11835: $changes{$itemid} = 1;
11836: }
1.296 raeburn 11837: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11838: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
11839: $changes{$itemid} = 1;
11840: }
11841: }
11842: }
11843: foreach my $item ('linktext','explanation') {
11844: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
11845: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
11846: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
11847: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
11848: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11849: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
11850: $changes{$itemid} = 1;
11851: }
11852: } else {
11853: $changes{$itemid} = 1;
11854: }
11855: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11856: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
11857: $changes{$itemid} = 1;
11858: }
1.267 raeburn 11859: }
11860: }
11861: if ($env{'form.ltitools_target_'.$i} eq 'window') {
11862: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 11863: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
11864: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 11865: } else {
11866: $confhash{$itemid}{'display'}{'target'} = 'iframe';
11867: }
11868: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
11869: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
11870: $changes{$itemid} = 1;
11871: }
11872: } else {
11873: $changes{$itemid} = 1;
11874: }
11875: foreach my $extra ('passback','roster') {
11876: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
11877: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 11878: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 11879: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 11880: $lifetime =~ s/^\s+|\s+$//g;
11881: if ($lifetime =~ /^\d+\.?\d*$/) {
11882: $confhash{$itemid}{$extra.'valid'} = $lifetime;
11883: }
11884: }
1.267 raeburn 11885: }
11886: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
11887: $changes{$itemid} = 1;
11888: }
1.319 raeburn 11889: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
11890: $changes{$itemid} = 1;
11891: }
1.267 raeburn 11892: }
1.273 raeburn 11893: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 11894: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 11895: if (grep(/^\Q$item\E$/,@courseconfig)) {
11896: $confhash{$itemid}{'crsconf'}{$item} = 1;
11897: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
11898: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
11899: $changes{$itemid} = 1;
11900: }
11901: } else {
11902: $changes{$itemid} = 1;
11903: }
11904: }
11905: }
1.267 raeburn 11906: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
11907: foreach my $field (@fields) {
11908: if ($possfield{$field}) {
11909: if ($field eq 'roles') {
11910: foreach my $role (@courseroles) {
11911: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
11912: if (($choice ne '') && ($posslti{$choice})) {
11913: $confhash{$itemid}{'roles'}{$role} = $choice;
11914: if ($role eq 'cc') {
11915: $confhash{$itemid}{'roles'}{'co'} = $choice;
11916: }
11917: }
11918: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
11919: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
11920: $changes{$itemid} = 1;
11921: }
11922: } elsif ($confhash{$itemid}{'roles'}{$role}) {
11923: $changes{$itemid} = 1;
11924: }
11925: }
11926: } else {
11927: $confhash{$itemid}{'fields'}{$field} = 1;
11928: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
11929: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
11930: $changes{$itemid} = 1;
11931: }
11932: } else {
11933: $changes{$itemid} = 1;
11934: }
11935: }
11936: }
11937: }
1.324 raeburn 11938: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
11939: if ($confhash{$itemid}{'fields'}{'user'}) {
11940: if ($env{'form.ltitools_userincdom_'.$i}) {
11941: $confhash{$itemid}{'incdom'} = 1;
11942: }
11943: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
11944: $changes{$itemid} = 1;
11945: }
11946: }
11947: }
1.267 raeburn 11948: $allpos[$newpos] = $itemid;
11949: }
11950: if ($imgdeletions{$itemid}) {
11951: $changes{$itemid} = 1;
11952: #FIXME need to obsolete item in RES space
11953: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
11954: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
11955: $itemid,$configuserok,$switchserver,
11956: $author_ok);
11957: if ($imgurl) {
11958: $confhash{$itemid}{'image'} = $imgurl;
11959: $changes{$itemid} = 1;
11960: }
11961: if ($error) {
11962: &Apache::lonnet::logthis($error);
11963: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11964: }
11965: } elsif ($domconfig{$action}{$itemid}{'image'}) {
11966: $confhash{$itemid}{'image'} =
11967: $domconfig{$action}{$itemid}{'image'};
11968: }
11969: if ($customadds{$i}) {
11970: my $name = $env{'form.ltitools_custom_name_'.$i};
11971: $name =~ s/(`)/'/g;
11972: $name =~ s/^\s+//;
11973: $name =~ s/\s+$//;
11974: my $value = $env{'form.ltitools_custom_value_'.$i};
11975: $value =~ s/(`)/'/g;
11976: $value =~ s/^\s+//;
11977: $value =~ s/\s+$//;
11978: if ($name ne '') {
11979: $confhash{$itemid}{'custom'}{$name} = $value;
11980: $changes{$itemid} = 1;
11981: }
11982: }
11983: my %customdels;
11984: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
11985: if (@customdeletions) {
11986: $changes{$itemid} = 1;
11987: }
11988: map { $customdels{$_} = 1; } @customdeletions;
11989: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
11990: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
11991: unless ($customdels{$key}) {
11992: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
11993: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
11994: }
11995: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
11996: $changes{$itemid} = 1;
11997: }
11998: }
11999: }
12000: }
12001: unless ($changes{$itemid}) {
12002: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12003: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12004: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12005: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12006: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12007: $changes{$itemid} = 1;
12008: last;
12009: }
12010: }
12011: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12012: $changes{$itemid} = 1;
12013: }
12014: }
12015: last if ($changes{$itemid});
12016: }
12017: }
12018: }
12019: }
12020: }
12021: if (@allpos > 0) {
12022: my $idx = 0;
12023: foreach my $itemid (@allpos) {
12024: if ($itemid ne '') {
12025: $confhash{$itemid}{'order'} = $idx;
12026: if (ref($domconfig{$action}) eq 'HASH') {
12027: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12028: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12029: $changes{$itemid} = 1;
12030: }
12031: }
12032: }
12033: $idx ++;
12034: }
12035: }
12036: }
12037: my %ltitoolshash = (
12038: $action => { %confhash }
12039: );
12040: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12041: $dom);
12042: if ($putresult eq 'ok') {
1.297 raeburn 12043: my %ltienchash = (
12044: $action => { %encconfig }
12045: );
12046: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 12047: if (keys(%changes) > 0) {
12048: my $cachetime = 24*60*60;
1.297 raeburn 12049: my %ltiall = %confhash;
12050: foreach my $id (keys(%ltiall)) {
12051: if (ref($encconfig{$id}) eq 'HASH') {
12052: foreach my $item ('key','secret') {
12053: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12054: }
12055: }
12056: }
12057: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 12058: if (ref($lastactref) eq 'HASH') {
12059: $lastactref->{'ltitools'} = 1;
12060: }
12061: $resulttext = &mt('Changes made:').'<ul>';
12062: my %bynum;
12063: foreach my $itemid (sort(keys(%changes))) {
12064: my $position = $confhash{$itemid}{'order'};
12065: $bynum{$position} = $itemid;
12066: }
12067: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12068: my $itemid = $bynum{$pos};
12069: if (ref($confhash{$itemid}) ne 'HASH') {
12070: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12071: } else {
12072: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12073: if ($confhash{$itemid}{'image'}) {
12074: $resulttext .= ' '.
12075: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12076: ' alt="'.&mt('Tool Provider icon').'" />';
12077: }
12078: $resulttext .= '</li><ul>';
12079: my $position = $pos + 1;
12080: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 12081: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 12082: if ($confhash{$itemid}{$item} ne '') {
12083: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12084: }
12085: }
1.297 raeburn 12086: if ($encconfig{$itemid}{'key'} ne '') {
12087: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12088: }
12089: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 12090: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 12091: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 12092: $resulttext .= ('*'x$num).'</li>';
12093: }
1.273 raeburn 12094: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 12095: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 12096: my $numconfig = 0;
12097: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12098: foreach my $item (@possconfig) {
12099: if ($confhash{$itemid}{'crsconf'}{$item}) {
12100: $numconfig ++;
1.296 raeburn 12101: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 12102: }
12103: }
12104: }
12105: if (!$numconfig) {
12106: $resulttext .= &mt('None');
12107: }
12108: $resulttext .= '</li>';
1.267 raeburn 12109: foreach my $item ('passback','roster') {
12110: $resulttext .= '<li>'.$lt{$item}.' ';
12111: if ($confhash{$itemid}{$item}) {
12112: $resulttext .= &mt('Yes');
1.319 raeburn 12113: if ($confhash{$itemid}{$item.'valid'}) {
12114: if ($item eq 'passback') {
12115: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
12116: $confhash{$itemid}{$item.'valid'});
12117: } else {
12118: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
12119: $confhash{$itemid}{$item.'valid'});
12120: }
12121: }
1.267 raeburn 12122: } else {
12123: $resulttext .= &mt('No');
12124: }
12125: $resulttext .= '</li>';
12126: }
12127: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12128: my $displaylist;
12129: if ($confhash{$itemid}{'display'}{'target'}) {
12130: $displaylist = &mt('Display target').': '.
12131: $confhash{$itemid}{'display'}{'target'}.',';
12132: }
12133: foreach my $size ('width','height') {
12134: if ($confhash{$itemid}{'display'}{$size}) {
12135: $displaylist .= (' 'x2).$lt{$size}.': '.
12136: $confhash{$itemid}{'display'}{$size}.',';
12137: }
12138: }
12139: if ($displaylist) {
12140: $displaylist =~ s/,$//;
12141: $resulttext .= '<li>'.$displaylist.'</li>';
12142: }
1.296 raeburn 12143: foreach my $item ('linktext','explanation') {
12144: if ($confhash{$itemid}{'display'}{$item}) {
12145: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12146: }
12147: }
12148: }
1.267 raeburn 12149: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12150: my $fieldlist;
12151: foreach my $field (@allfields) {
12152: if ($confhash{$itemid}{'fields'}{$field}) {
12153: $fieldlist .= (' 'x2).$lt{$field}.',';
12154: }
12155: }
12156: if ($fieldlist) {
12157: $fieldlist =~ s/,$//;
1.324 raeburn 12158: if ($confhash{$itemid}{'fields'}{'user'}) {
12159: if ($confhash{$itemid}{'incdom'}) {
12160: $fieldlist .= ' ('.&mt('username:domain').')';
12161: } else {
12162: $fieldlist .= ' ('.&mt('username').')';
12163: }
12164: }
1.267 raeburn 12165: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12166: }
12167: }
12168: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12169: my $rolemaps;
12170: foreach my $role (@courseroles) {
12171: if ($confhash{$itemid}{'roles'}{$role}) {
12172: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12173: $confhash{$itemid}{'roles'}{$role}.',';
12174: }
12175: }
12176: if ($rolemaps) {
12177: $rolemaps =~ s/,$//;
12178: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12179: }
12180: }
12181: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12182: my $customlist;
12183: if (keys(%{$confhash{$itemid}{'custom'}})) {
12184: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12185: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12186: }
12187: }
12188: if ($customlist) {
1.317 raeburn 12189: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 12190: }
12191: }
12192: $resulttext .= '</ul></li>';
12193: }
12194: }
12195: $resulttext .= '</ul>';
12196: } else {
12197: $resulttext = &mt('No changes made.');
12198: }
12199: } else {
12200: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12201: }
12202: if ($errors) {
12203: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12204: $errors.'</ul>';
12205: }
12206: return $resulttext;
12207: }
12208:
12209: sub process_ltitools_image {
12210: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12211: my $filename = $env{'form.'.$caller.'.filename'};
12212: my ($error,$url);
12213: my ($width,$height) = (21,21);
12214: if ($configuserok eq 'ok') {
12215: if ($switchserver) {
12216: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12217: $switchserver);
12218: } elsif ($author_ok eq 'ok') {
12219: my ($result,$imageurl,$madethumb) =
12220: &publishlogo($r,'upload',$caller,$dom,$confname,
12221: "ltitools/$itemid/icon",$width,$height);
12222: if ($result eq 'ok') {
12223: if ($madethumb) {
12224: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12225: my $imagethumb = "$path/tn-".$imagefile;
12226: $url = $imagethumb;
12227: } else {
12228: $url = $imageurl;
12229: }
12230: } else {
12231: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12232: }
12233: } else {
12234: $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);
12235: }
12236: } else {
12237: $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);
12238: }
12239: return ($url,$error);
12240: }
12241:
12242: sub get_ltitools_id {
12243: my ($cdom,$title) = @_;
12244: # get lock on ltitools db
12245: my $lockhash = {
12246: lock => $env{'user.name'}.
12247: ':'.$env{'user.domain'},
12248: };
12249: my $tries = 0;
12250: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12251: my ($id,$error);
12252:
12253: while (($gotlock ne 'ok') && ($tries<10)) {
12254: $tries ++;
12255: sleep (0.1);
12256: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12257: }
12258: if ($gotlock eq 'ok') {
12259: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12260: if ($currids{'lock'}) {
12261: delete($currids{'lock'});
12262: if (keys(%currids)) {
12263: my @curr = sort { $a <=> $b } keys(%currids);
12264: if ($curr[-1] =~ /^\d+$/) {
12265: $id = 1 + $curr[-1];
12266: }
12267: } else {
12268: $id = 1;
12269: }
12270: if ($id) {
12271: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12272: $error = 'nostore';
12273: }
12274: } else {
12275: $error = 'nonumber';
12276: }
12277: }
12278: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12279: } else {
12280: $error = 'nolock';
12281: }
12282: return ($id,$error);
12283: }
12284:
1.320 raeburn 12285: sub modify_lti {
12286: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12287: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12288: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12289: my (%posslti,%posslticrs,%posscrstype);
12290: my @courseroles = ('cc','in','ta','ep','st');
12291: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
12292: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
12293: my @coursetypes = ('official','unofficial','community','textbook','placement');
12294: my %coursetypetitles = &Apache::lonlocal::texthash (
12295: official => 'Official',
12296: unofficial => 'Unofficial',
12297: community => 'Community',
12298: textbook => 'Textbook',
12299: placement => 'Placement Test',
12300: );
1.325 raeburn 12301: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 12302: my %lt = <i_names();
12303: map { $posslti{$_} = 1; } @ltiroles;
12304: map { $posslticrs{$_} = 1; } @lticourseroles;
12305: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 12306:
1.326 raeburn 12307: my %menutitles = <imenu_titles();
12308:
1.320 raeburn 12309: my (@items,%deletions,%itemids);
12310: if ($env{'form.lti_add'}) {
12311: my $consumer = $env{'form.lti_consumer_add'};
12312: $consumer =~ s/(`)/'/g;
12313: ($newid,my $error) = &get_lti_id($dom,$consumer);
12314: if ($newid) {
12315: $itemids{'add'} = $newid;
12316: push(@items,'add');
12317: $changes{$newid} = 1;
12318: } else {
12319: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
12320: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12321: }
12322: }
12323: if (ref($domconfig{$action}) eq 'HASH') {
12324: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
12325: if (@todelete) {
12326: map { $deletions{$_} = 1; } @todelete;
12327: }
12328: my $maxnum = $env{'form.lti_maxnum'};
12329: for (my $i=0; $i<=$maxnum; $i++) {
12330: my $itemid = $env{'form.lti_id_'.$i};
12331: $itemid =~ s/\D+//g;
12332: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12333: if ($deletions{$itemid}) {
12334: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
12335: } else {
12336: push(@items,$i);
12337: $itemids{$i} = $itemid;
12338: }
12339: }
12340: }
12341: }
12342: foreach my $idx (@items) {
12343: my $itemid = $itemids{$idx};
12344: next unless ($itemid);
12345: my $position = $env{'form.lti_pos_'.$idx};
12346: $position =~ s/\D+//g;
12347: if ($position ne '') {
12348: $allpos[$position] = $itemid;
12349: }
1.345 raeburn 12350: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12351: my $formitem = 'form.lti_'.$item.'_'.$idx;
12352: $env{$formitem} =~ s/(`)/'/g;
12353: if ($item eq 'lifetime') {
12354: $env{$formitem} =~ s/[^\d.]//g;
12355: }
12356: if ($env{$formitem} ne '') {
12357: if (($item eq 'key') || ($item eq 'secret')) {
12358: $encconfig{$itemid}{$item} = $env{$formitem};
12359: } else {
12360: $confhash{$itemid}{$item} = $env{$formitem};
12361: unless (($idx eq 'add') || ($changes{$itemid})) {
12362: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12363: $changes{$itemid} = 1;
12364: }
12365: }
12366: }
12367: }
12368: }
12369: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12370: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12371: }
1.345 raeburn 12372: if ($confhash{$itemid}{'requser'}) {
12373: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12374: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12375: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12376: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12377: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12378: my $mapuser = $env{'form.lti_customuser_'.$idx};
12379: $mapuser =~ s/(`)/'/g;
12380: $mapuser =~ s/^\s+|\s+$//g;
12381: $confhash{$itemid}{'mapuser'} = $mapuser;
12382: }
12383: foreach my $ltirole (@lticourseroles) {
12384: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12385: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12386: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12387: }
12388: }
12389: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12390: my @makeuser;
12391: foreach my $ltirole (sort(@possmakeuser)) {
12392: if ($posslti{$ltirole}) {
12393: push(@makeuser,$ltirole);
12394: }
12395: }
12396: $confhash{$itemid}{'makeuser'} = \@makeuser;
12397: if (@makeuser) {
12398: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12399: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12400: $confhash{$itemid}{'lcauth'} = $lcauth;
12401: if ($lcauth ne 'internal') {
12402: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12403: $lcauthparm =~ s/^(\s+|\s+)$//g;
12404: $lcauthparm =~ s/`//g;
12405: if ($lcauthparm ne '') {
12406: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12407: }
12408: }
12409: } else {
12410: $confhash{$itemid}{'lcauth'} = 'lti';
12411: }
1.320 raeburn 12412: }
1.345 raeburn 12413: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12414: if (@possinstdata) {
12415: foreach my $field (@possinstdata) {
12416: if (exists($fieldtitles{$field})) {
12417: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12418: }
12419: }
12420: }
1.345 raeburn 12421: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12422: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12423: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12424: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12425: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12426: $mapcrs =~ s/(`)/'/g;
12427: $mapcrs =~ s/^\s+|\s+$//g;
12428: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12429: }
12430: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12431: my @crstypes;
12432: foreach my $type (sort(@posstypes)) {
12433: if ($posscrstype{$type}) {
12434: push(@crstypes,$type);
1.325 raeburn 12435: }
12436: }
1.345 raeburn 12437: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12438: if ($env{'form.lti_makecrs_'.$idx}) {
12439: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12440: }
1.345 raeburn 12441: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12442: my @selfenroll;
12443: foreach my $type (sort(@possenroll)) {
12444: if ($posslticrs{$type}) {
12445: push(@selfenroll,$type);
12446: }
1.320 raeburn 12447: }
1.345 raeburn 12448: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12449: if ($env{'form.lti_crssec_'.$idx}) {
12450: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12451: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12452: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12453: my $section = $env{'form.lti_customsection_'.$idx};
12454: $section =~ s/(`)/'/g;
12455: $section =~ s/^\s+|\s+$//g;
12456: if ($section ne '') {
12457: $confhash{$itemid}{'section'} = $section;
12458: }
1.320 raeburn 12459: }
12460: }
1.345 raeburn 12461: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12462: if ($env{'form.lti_'.$field.'_'.$idx}) {
12463: $confhash{$itemid}{$field} = 1;
12464: }
1.320 raeburn 12465: }
1.345 raeburn 12466: if ($env{'form.lti_passback_'.$idx}) {
12467: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12468: $confhash{$itemid}{'passbackformat'} = '1.0';
12469: } else {
12470: $confhash{$itemid}{'passbackformat'} = '1.1';
12471: }
1.337 raeburn 12472: }
1.345 raeburn 12473: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12474: $confhash{$itemid}{lcmenu} = [];
12475: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12476: foreach my $field (@possmenu) {
12477: if (exists($menutitles{$field})) {
12478: if ($field eq 'grades') {
12479: next unless ($env{'form.lti_inlinemenu_'.$idx});
12480: }
12481: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12482: }
12483: }
12484: }
1.345 raeburn 12485: unless (($idx eq 'add') || ($changes{$itemid})) {
12486: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12487: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12488: $changes{$itemid} = 1;
12489: }
12490: }
1.320 raeburn 12491: unless ($changes{$itemid}) {
1.345 raeburn 12492: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12493: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12494: $changes{$itemid} = 1;
12495: }
1.345 raeburn 12496: }
1.320 raeburn 12497: }
1.345 raeburn 12498: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12499: unless ($changes{$itemid}) {
12500: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12501: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12502: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12503: $confhash{$itemid}{$field});
12504: if (@diffs) {
12505: $changes{$itemid} = 1;
12506: }
12507: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12508: $changes{$itemid} = 1;
12509: }
12510: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12511: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12512: $changes{$itemid} = 1;
12513: }
12514: }
1.345 raeburn 12515: }
12516: }
12517: unless ($changes{$itemid}) {
12518: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12519: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12520: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12521: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12522: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12523: $changes{$itemid} = 1;
12524: last;
12525: }
12526: }
1.345 raeburn 12527: unless ($changes{$itemid}) {
12528: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12529: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12530: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12531: $changes{$itemid} = 1;
12532: last;
12533: }
12534: }
12535: }
12536: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12537: $changes{$itemid} = 1;
1.320 raeburn 12538: }
1.345 raeburn 12539: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12540: unless ($changes{$itemid}) {
12541: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12542: $changes{$itemid} = 1;
12543: }
1.320 raeburn 12544: }
12545: }
12546: }
12547: }
12548: }
12549: }
12550: if (@allpos > 0) {
12551: my $idx = 0;
12552: foreach my $itemid (@allpos) {
12553: if ($itemid ne '') {
12554: $confhash{$itemid}{'order'} = $idx;
12555: if (ref($domconfig{$action}) eq 'HASH') {
12556: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12557: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12558: $changes{$itemid} = 1;
12559: }
12560: }
12561: }
12562: $idx ++;
12563: }
12564: }
12565: }
12566: my %ltihash = (
12567: $action => { %confhash }
12568: );
12569: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12570: $dom);
12571: if ($putresult eq 'ok') {
12572: my %ltienchash = (
12573: $action => { %encconfig }
12574: );
12575: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12576: if (keys(%changes) > 0) {
12577: my $cachetime = 24*60*60;
12578: my %ltiall = %confhash;
12579: foreach my $id (keys(%ltiall)) {
12580: if (ref($encconfig{$id}) eq 'HASH') {
12581: foreach my $item ('key','secret') {
12582: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12583: }
12584: }
12585: }
12586: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12587: if (ref($lastactref) eq 'HASH') {
12588: $lastactref->{'lti'} = 1;
12589: }
12590: $resulttext = &mt('Changes made:').'<ul>';
12591: my %bynum;
12592: foreach my $itemid (sort(keys(%changes))) {
12593: my $position = $confhash{$itemid}{'order'};
12594: $bynum{$position} = $itemid;
12595: }
12596: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12597: my $itemid = $bynum{$pos};
12598: if (ref($confhash{$itemid}) ne 'HASH') {
12599: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12600: } else {
12601: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12602: my $position = $pos + 1;
12603: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12604: foreach my $item ('version','lifetime') {
12605: if ($confhash{$itemid}{$item} ne '') {
12606: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12607: }
12608: }
12609: if ($encconfig{$itemid}{'key'} ne '') {
12610: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12611: }
12612: if ($encconfig{$itemid}{'secret'} ne '') {
12613: $resulttext .= '<li>'.$lt{'secret'}.': ';
12614: my $num = length($encconfig{$itemid}{'secret'});
12615: $resulttext .= ('*'x$num).'</li>';
12616: }
1.345 raeburn 12617: if ($confhash{$itemid}{'requser'}) {
12618: if ($confhash{$itemid}{'mapuser'}) {
12619: my $shownmapuser;
12620: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12621: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12622: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12623: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12624: } else {
12625: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12626: }
1.345 raeburn 12627: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12628: }
1.345 raeburn 12629: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12630: my $rolemaps;
12631: foreach my $role (@ltiroles) {
12632: if ($confhash{$itemid}{'maproles'}{$role}) {
12633: $rolemaps .= (' 'x2).$role.'='.
12634: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12635: 'Course').',';
12636: }
12637: }
12638: if ($rolemaps) {
12639: $rolemaps =~ s/,$//;
12640: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12641: }
12642: }
12643: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12644: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12645: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12646: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12647: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12648: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12649: } else {
12650: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12651: $confhash{$itemid}{'lcauth'});
12652: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12653: $resulttext .= '; '.&mt('a randomly generated password will be created');
12654: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12655: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12656: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12657: }
12658: } else {
12659: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12660: }
12661: }
12662: $resulttext .= '</li>';
12663: } else {
12664: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12665: }
1.320 raeburn 12666: }
1.345 raeburn 12667: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12668: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12669: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12670: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12671: } else {
1.345 raeburn 12672: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12673: }
1.320 raeburn 12674: }
1.345 raeburn 12675: if ($confhash{$itemid}{'mapcrs'}) {
12676: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12677: }
12678: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12679: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12680: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12681: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12682: '</li>';
12683: } else {
12684: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12685: }
1.325 raeburn 12686: }
1.345 raeburn 12687: if ($confhash{$itemid}{'makecrs'}) {
12688: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12689: } else {
1.345 raeburn 12690: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12691: }
1.345 raeburn 12692: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12693: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12694: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12695: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12696: '</li>';
12697: } else {
12698: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12699: }
1.320 raeburn 12700: }
1.345 raeburn 12701: if ($confhash{$itemid}{'section'}) {
12702: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12703: $resulttext .= '<li>'.&mt('User section from standard field:').
12704: ' (course_section_sourcedid)'.'</li>';
12705: } else {
12706: $resulttext .= '<li>'.&mt('User section from:').' '.
12707: $confhash{$itemid}{'section'}.'</li>';
12708: }
1.320 raeburn 12709: } else {
1.345 raeburn 12710: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12711: }
1.345 raeburn 12712: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12713: $resulttext .= '<li>'.$lt{$item}.': ';
12714: if ($confhash{$itemid}{$item}) {
12715: $resulttext .= &mt('Yes');
12716: if ($item eq 'passback') {
12717: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12718: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12719: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12720: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12721: }
1.337 raeburn 12722: }
1.345 raeburn 12723: } else {
12724: $resulttext .= &mt('No');
1.337 raeburn 12725: }
1.345 raeburn 12726: $resulttext .= '</li>';
1.320 raeburn 12727: }
1.345 raeburn 12728: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12729: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12730: $resulttext .= '<li>'.&mt('Menu items:').' '.
12731: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12732: } else {
12733: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12734: }
1.326 raeburn 12735: }
12736: }
1.320 raeburn 12737: $resulttext .= '</ul></li>';
12738: }
12739: }
12740: $resulttext .= '</ul>';
12741: } else {
12742: $resulttext = &mt('No changes made.');
12743: }
12744: } else {
12745: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12746: }
12747: if ($errors) {
12748: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12749: $errors.'</ul>';
12750: }
12751: return $resulttext;
12752: }
12753:
12754: sub get_lti_id {
12755: my ($domain,$consumer) = @_;
12756: # get lock on lti db
12757: my $lockhash = {
12758: lock => $env{'user.name'}.
12759: ':'.$env{'user.domain'},
12760: };
12761: my $tries = 0;
12762: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12763: my ($id,$error);
12764:
12765: while (($gotlock ne 'ok') && ($tries<10)) {
12766: $tries ++;
12767: sleep (0.1);
12768: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12769: }
12770: if ($gotlock eq 'ok') {
12771: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12772: if ($currids{'lock'}) {
12773: delete($currids{'lock'});
12774: if (keys(%currids)) {
12775: my @curr = sort { $a <=> $b } keys(%currids);
12776: if ($curr[-1] =~ /^\d+$/) {
12777: $id = 1 + $curr[-1];
12778: }
12779: } else {
12780: $id = 1;
12781: }
12782: if ($id) {
12783: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
12784: $error = 'nostore';
12785: }
12786: } else {
12787: $error = 'nonumber';
12788: }
12789: }
12790: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
12791: } else {
12792: $error = 'nolock';
12793: }
12794: return ($id,$error);
12795: }
12796:
1.3 raeburn 12797: sub modify_autoenroll {
1.205 raeburn 12798: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 12799: my ($resulttext,%changes);
12800: my %currautoenroll;
12801: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
12802: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
12803: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
12804: }
12805: }
12806: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
12807: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 12808: sender => 'Sender for notification messages',
1.274 raeburn 12809: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
12810: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 12811: my @offon = ('off','on');
1.17 raeburn 12812: my $sender_uname = $env{'form.sender_uname'};
12813: my $sender_domain = $env{'form.sender_domain'};
12814: if ($sender_domain eq '') {
12815: $sender_uname = '';
12816: } elsif ($sender_uname eq '') {
12817: $sender_domain = '';
12818: }
1.129 raeburn 12819: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 12820: my $failsafe = $env{'form.autoenroll_failsafe'};
12821: $failsafe =~ s{^\s+|\s+$}{}g;
12822: if ($failsafe =~ /\D/) {
12823: undef($failsafe);
12824: }
1.1 raeburn 12825: my %autoenrollhash = (
1.129 raeburn 12826: autoenroll => { 'run' => $env{'form.autoenroll_run'},
12827: 'sender_uname' => $sender_uname,
12828: 'sender_domain' => $sender_domain,
12829: 'co-owners' => $coowners,
1.274 raeburn 12830: 'autofailsafe' => $failsafe,
1.1 raeburn 12831: }
12832: );
1.4 raeburn 12833: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
12834: $dom);
1.1 raeburn 12835: if ($putresult eq 'ok') {
12836: if (exists($currautoenroll{'run'})) {
12837: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
12838: $changes{'run'} = 1;
12839: }
12840: } elsif ($autorun) {
12841: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 12842: $changes{'run'} = 1;
1.1 raeburn 12843: }
12844: }
1.17 raeburn 12845: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 12846: $changes{'sender'} = 1;
12847: }
1.17 raeburn 12848: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 12849: $changes{'sender'} = 1;
12850: }
1.129 raeburn 12851: if ($currautoenroll{'co-owners'} ne '') {
12852: if ($currautoenroll{'co-owners'} ne $coowners) {
12853: $changes{'coowners'} = 1;
12854: }
12855: } elsif ($coowners) {
12856: $changes{'coowners'} = 1;
1.274 raeburn 12857: }
12858: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
12859: $changes{'autofailsafe'} = 1;
12860: }
1.1 raeburn 12861: if (keys(%changes) > 0) {
12862: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 12863: if ($changes{'run'}) {
1.1 raeburn 12864: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
12865: }
12866: if ($changes{'sender'}) {
1.17 raeburn 12867: if ($sender_uname eq '' || $sender_domain eq '') {
12868: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
12869: } else {
12870: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
12871: }
1.1 raeburn 12872: }
1.129 raeburn 12873: if ($changes{'coowners'}) {
12874: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
12875: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12876: if (ref($lastactref) eq 'HASH') {
12877: $lastactref->{'domainconfig'} = 1;
12878: }
1.129 raeburn 12879: }
1.274 raeburn 12880: if ($changes{'autofailsafe'}) {
12881: if ($failsafe ne '') {
1.299 raeburn 12882: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 12883: } else {
1.299 raeburn 12884: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 12885: }
12886: &Apache::lonnet::get_domain_defaults($dom,1);
12887: if (ref($lastactref) eq 'HASH') {
12888: $lastactref->{'domdefaults'} = 1;
12889: }
12890: }
1.1 raeburn 12891: $resulttext .= '</ul>';
12892: } else {
12893: $resulttext = &mt('No changes made to auto-enrollment settings');
12894: }
12895: } else {
1.11 albertel 12896: $resulttext = '<span class="LC_error">'.
12897: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12898: }
1.3 raeburn 12899: return $resulttext;
1.1 raeburn 12900: }
12901:
12902: sub modify_autoupdate {
1.3 raeburn 12903: my ($dom,%domconfig) = @_;
1.1 raeburn 12904: my ($resulttext,%currautoupdate,%fields,%changes);
12905: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
12906: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
12907: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
12908: }
12909: }
12910: my @offon = ('off','on');
12911: my %title = &Apache::lonlocal::texthash (
12912: run => 'Auto-update:',
12913: classlists => 'Updates to user information in classlists?'
12914: );
1.44 raeburn 12915: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12916: my %fieldtitles = &Apache::lonlocal::texthash (
12917: id => 'Student/Employee ID',
1.20 raeburn 12918: permanentemail => 'E-mail address',
1.1 raeburn 12919: lastname => 'Last Name',
12920: firstname => 'First Name',
12921: middlename => 'Middle Name',
1.132 raeburn 12922: generation => 'Generation',
1.1 raeburn 12923: );
1.142 raeburn 12924: $othertitle = &mt('All users');
1.1 raeburn 12925: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 12926: $othertitle = &mt('Other users');
1.1 raeburn 12927: }
12928: foreach my $key (keys(%env)) {
12929: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 12930: my ($usertype,$item) = ($1,$2);
12931: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
12932: if ($usertype eq 'default') {
12933: push(@{$fields{$1}},$2);
12934: } elsif (ref($types) eq 'ARRAY') {
12935: if (grep(/^\Q$usertype\E$/,@{$types})) {
12936: push(@{$fields{$1}},$2);
12937: }
12938: }
12939: }
1.1 raeburn 12940: }
12941: }
1.131 raeburn 12942: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
12943: @lockablenames = sort(@lockablenames);
12944: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
12945: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12946: if (@changed) {
12947: $changes{'lockablenames'} = 1;
12948: }
12949: } else {
12950: if (@lockablenames) {
12951: $changes{'lockablenames'} = 1;
12952: }
12953: }
1.1 raeburn 12954: my %updatehash = (
12955: autoupdate => { run => $env{'form.autoupdate_run'},
12956: classlists => $env{'form.classlists'},
12957: fields => {%fields},
1.131 raeburn 12958: lockablenames => \@lockablenames,
1.1 raeburn 12959: }
12960: );
12961: foreach my $key (keys(%currautoupdate)) {
12962: if (($key eq 'run') || ($key eq 'classlists')) {
12963: if (exists($updatehash{autoupdate}{$key})) {
12964: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
12965: $changes{$key} = 1;
12966: }
12967: }
12968: } elsif ($key eq 'fields') {
12969: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 12970: foreach my $item (@{$types},'default') {
1.1 raeburn 12971: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
12972: my $change = 0;
12973: foreach my $type (@{$currautoupdate{$key}{$item}}) {
12974: if (!exists($fields{$item})) {
12975: $change = 1;
1.132 raeburn 12976: last;
1.1 raeburn 12977: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 12978: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 12979: $change = 1;
1.132 raeburn 12980: last;
1.1 raeburn 12981: }
12982: }
12983: }
12984: if ($change) {
12985: push(@{$changes{$key}},$item);
12986: }
1.26 raeburn 12987: }
1.1 raeburn 12988: }
12989: }
1.131 raeburn 12990: } elsif ($key eq 'lockablenames') {
12991: if (ref($currautoupdate{$key}) eq 'ARRAY') {
12992: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
12993: if (@changed) {
12994: $changes{'lockablenames'} = 1;
12995: }
12996: } else {
12997: if (@lockablenames) {
12998: $changes{'lockablenames'} = 1;
12999: }
13000: }
13001: }
13002: }
13003: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13004: if (@lockablenames) {
13005: $changes{'lockablenames'} = 1;
1.1 raeburn 13006: }
13007: }
1.26 raeburn 13008: foreach my $item (@{$types},'default') {
13009: if (defined($fields{$item})) {
13010: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13011: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13012: my $change = 0;
13013: if (ref($fields{$item}) eq 'ARRAY') {
13014: foreach my $type (@{$fields{$item}}) {
13015: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13016: $change = 1;
13017: last;
13018: }
13019: }
13020: }
13021: if ($change) {
13022: push(@{$changes{'fields'}},$item);
13023: }
13024: } else {
1.26 raeburn 13025: push(@{$changes{'fields'}},$item);
13026: }
13027: } else {
13028: push(@{$changes{'fields'}},$item);
1.1 raeburn 13029: }
13030: }
13031: }
13032: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13033: $dom);
13034: if ($putresult eq 'ok') {
13035: if (keys(%changes) > 0) {
13036: $resulttext = &mt('Changes made:').'<ul>';
13037: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13038: if ($key eq 'lockablenames') {
13039: $resulttext .= '<li>';
13040: if (@lockablenames) {
13041: $usertypes->{'default'} = $othertitle;
13042: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13043: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13044: } else {
13045: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13046: }
13047: $resulttext .= '</li>';
13048: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13049: foreach my $item (@{$changes{$key}}) {
13050: my @newvalues;
13051: foreach my $type (@{$fields{$item}}) {
13052: push(@newvalues,$fieldtitles{$type});
13053: }
1.3 raeburn 13054: my $newvaluestr;
13055: if (@newvalues > 0) {
13056: $newvaluestr = join(', ',@newvalues);
13057: } else {
13058: $newvaluestr = &mt('none');
1.6 raeburn 13059: }
1.1 raeburn 13060: if ($item eq 'default') {
1.26 raeburn 13061: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13062: } else {
1.26 raeburn 13063: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13064: }
13065: }
13066: } else {
13067: my $newvalue;
13068: if ($key eq 'run') {
13069: $newvalue = $offon[$env{'form.autoupdate_run'}];
13070: } else {
13071: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13072: }
1.1 raeburn 13073: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13074: }
13075: }
13076: $resulttext .= '</ul>';
13077: } else {
1.3 raeburn 13078: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13079: }
13080: } else {
1.11 albertel 13081: $resulttext = '<span class="LC_error">'.
13082: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13083: }
1.3 raeburn 13084: return $resulttext;
1.1 raeburn 13085: }
13086:
1.125 raeburn 13087: sub modify_autocreate {
13088: my ($dom,%domconfig) = @_;
13089: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13090: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13091: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13092: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13093: }
13094: }
13095: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13096: req => 'Auto-creation of validated requests for official courses',
13097: xmldc => 'Identity of course creator of courses from XML files',
13098: );
13099: my @types = ('xml','req');
13100: foreach my $item (@types) {
13101: $newvals{$item} = $env{'form.autocreate_'.$item};
13102: $newvals{$item} =~ s/\D//g;
13103: $newvals{$item} = 0 if ($newvals{$item} eq '');
13104: }
13105: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 13106: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13107: unless (exists($domcoords{$newvals{'xmldc'}})) {
13108: $newvals{'xmldc'} = '';
13109: }
13110: %autocreatehash = (
13111: autocreate => { xml => $newvals{'xml'},
13112: req => $newvals{'req'},
13113: }
13114: );
13115: if ($newvals{'xmldc'} ne '') {
13116: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13117: }
13118: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13119: $dom);
13120: if ($putresult eq 'ok') {
13121: my @items = @types;
13122: if ($newvals{'xml'}) {
13123: push(@items,'xmldc');
13124: }
13125: foreach my $item (@items) {
13126: if (exists($currautocreate{$item})) {
13127: if ($currautocreate{$item} ne $newvals{$item}) {
13128: $changes{$item} = 1;
13129: }
13130: } elsif ($newvals{$item}) {
13131: $changes{$item} = 1;
13132: }
13133: }
13134: if (keys(%changes) > 0) {
13135: my @offon = ('off','on');
13136: $resulttext = &mt('Changes made:').'<ul>';
13137: foreach my $item (@types) {
13138: if ($changes{$item}) {
13139: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 13140: $resulttext .= '<li>'.
13141: &mt("$title{$item} set to [_1]$newtxt [_2]",
13142: '<b>','</b>').
13143: '</li>';
1.125 raeburn 13144: }
13145: }
13146: if ($changes{'xmldc'}) {
13147: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13148: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 13149: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13150: }
13151: $resulttext .= '</ul>';
13152: } else {
13153: $resulttext = &mt('No changes made to auto-creation settings');
13154: }
13155: } else {
13156: $resulttext = '<span class="LC_error">'.
13157: &mt('An error occurred: [_1]',$putresult).'</span>';
13158: }
13159: return $resulttext;
13160: }
13161:
1.23 raeburn 13162: sub modify_directorysrch {
1.295 raeburn 13163: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13164: my ($resulttext,%changes);
13165: my %currdirsrch;
13166: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13167: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13168: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13169: }
13170: }
1.277 raeburn 13171: my %title = ( available => 'Institutional directory search available',
13172: localonly => 'Other domains can search institution',
13173: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 13174: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13175: searchby => 'Search types',
13176: searchtypes => 'Search latitude');
13177: my @offon = ('off','on');
1.24 raeburn 13178: my @otherdoms = ('Yes','No');
1.23 raeburn 13179:
1.25 raeburn 13180: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13181: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13182: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13183:
1.44 raeburn 13184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13185: if (keys(%{$usertypes}) == 0) {
13186: @cansearch = ('default');
13187: } else {
13188: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13189: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13190: if (!grep(/^\Q$type\E$/,@cansearch)) {
13191: push(@{$changes{'cansearch'}},$type);
13192: }
1.23 raeburn 13193: }
1.26 raeburn 13194: foreach my $type (@cansearch) {
13195: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13196: push(@{$changes{'cansearch'}},$type);
13197: }
1.23 raeburn 13198: }
1.26 raeburn 13199: } else {
13200: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13201: }
13202: }
13203:
13204: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13205: foreach my $by (@{$currdirsrch{'searchby'}}) {
13206: if (!grep(/^\Q$by\E$/,@searchby)) {
13207: push(@{$changes{'searchby'}},$by);
13208: }
13209: }
13210: foreach my $by (@searchby) {
13211: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13212: push(@{$changes{'searchby'}},$by);
13213: }
13214: }
13215: } else {
13216: push(@{$changes{'searchby'}},@searchby);
13217: }
1.25 raeburn 13218:
13219: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13220: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13221: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13222: push(@{$changes{'searchtypes'}},$type);
13223: }
13224: }
13225: foreach my $type (@searchtypes) {
13226: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13227: push(@{$changes{'searchtypes'}},$type);
13228: }
13229: }
13230: } else {
13231: if (exists($currdirsrch{'searchtypes'})) {
13232: foreach my $type (@searchtypes) {
13233: if ($type ne $currdirsrch{'searchtypes'}) {
13234: push(@{$changes{'searchtypes'}},$type);
13235: }
13236: }
13237: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13238: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13239: }
13240: } else {
13241: push(@{$changes{'searchtypes'}},@searchtypes);
13242: }
13243: }
13244:
1.23 raeburn 13245: my %dirsrch_hash = (
13246: directorysrch => { available => $env{'form.dirsrch_available'},
13247: cansearch => \@cansearch,
1.277 raeburn 13248: localonly => $env{'form.dirsrch_instlocalonly'},
13249: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13250: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13251: searchby => \@searchby,
1.25 raeburn 13252: searchtypes => \@searchtypes,
1.23 raeburn 13253: }
13254: );
13255: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13256: $dom);
13257: if ($putresult eq 'ok') {
13258: if (exists($currdirsrch{'available'})) {
13259: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13260: $changes{'available'} = 1;
13261: }
13262: } else {
13263: if ($env{'form.dirsrch_available'} eq '1') {
13264: $changes{'available'} = 1;
13265: }
13266: }
1.277 raeburn 13267: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 13268: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13269: $changes{'lcavailable'} = 1;
13270: }
1.277 raeburn 13271: } else {
13272: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13273: $changes{'lcavailable'} = 1;
13274: }
13275: }
1.24 raeburn 13276: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 13277: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13278: $changes{'localonly'} = 1;
13279: }
1.24 raeburn 13280: } else {
1.277 raeburn 13281: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 13282: $changes{'localonly'} = 1;
13283: }
13284: }
1.277 raeburn 13285: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 13286: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13287: $changes{'lclocalonly'} = 1;
13288: }
1.277 raeburn 13289: } else {
13290: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13291: $changes{'lclocalonly'} = 1;
13292: }
13293: }
1.23 raeburn 13294: if (keys(%changes) > 0) {
13295: $resulttext = &mt('Changes made:').'<ul>';
13296: if ($changes{'available'}) {
13297: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13298: }
1.277 raeburn 13299: if ($changes{'lcavailable'}) {
13300: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13301: }
1.24 raeburn 13302: if ($changes{'localonly'}) {
1.277 raeburn 13303: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 13304: }
1.277 raeburn 13305: if ($changes{'lclocalonly'}) {
13306: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 13307: }
1.23 raeburn 13308: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13309: my $chgtext;
1.26 raeburn 13310: if (ref($usertypes) eq 'HASH') {
13311: if (keys(%{$usertypes}) > 0) {
13312: foreach my $type (@{$types}) {
13313: if (grep(/^\Q$type\E$/,@cansearch)) {
13314: $chgtext .= $usertypes->{$type}.'; ';
13315: }
13316: }
13317: if (grep(/^default$/,@cansearch)) {
13318: $chgtext .= $othertitle;
13319: } else {
13320: $chgtext =~ s/\; $//;
13321: }
1.210 raeburn 13322: $resulttext .=
1.178 raeburn 13323: '<li>'.
13324: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13325: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13326: '</li>';
1.23 raeburn 13327: }
13328: }
13329: }
13330: if (ref($changes{'searchby'}) eq 'ARRAY') {
13331: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13332: my $chgtext;
13333: foreach my $type (@{$titleorder}) {
13334: if (grep(/^\Q$type\E$/,@searchby)) {
13335: if (defined($searchtitles->{$type})) {
13336: $chgtext .= $searchtitles->{$type}.'; ';
13337: }
13338: }
13339: }
13340: $chgtext =~ s/\; $//;
13341: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13342: }
1.25 raeburn 13343: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13344: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13345: my $chgtext;
13346: foreach my $type (@{$srchtypeorder}) {
13347: if (grep(/^\Q$type\E$/,@searchtypes)) {
13348: if (defined($srchtypes_desc->{$type})) {
13349: $chgtext .= $srchtypes_desc->{$type}.'; ';
13350: }
13351: }
13352: }
13353: $chgtext =~ s/\; $//;
1.178 raeburn 13354: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13355: }
13356: $resulttext .= '</ul>';
1.295 raeburn 13357: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13358: if (ref($lastactref) eq 'HASH') {
13359: $lastactref->{'directorysrch'} = 1;
13360: }
1.23 raeburn 13361: } else {
1.277 raeburn 13362: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13363: }
13364: } else {
13365: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13366: &mt('An error occurred: [_1]',$putresult).'</span>';
13367: }
13368: return $resulttext;
13369: }
13370:
1.28 raeburn 13371: sub modify_contacts {
1.205 raeburn 13372: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13373: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13374: if (ref($domconfig{'contacts'}) eq 'HASH') {
13375: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13376: $currsetting{$key} = $domconfig{'contacts'}{$key};
13377: }
13378: }
1.286 raeburn 13379: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13380: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13381: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 13382: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 13383: my @toggles = ('reporterrors','reportupdates','reportstatus');
13384: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13385: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13386: foreach my $type (@mailings) {
13387: @{$newsetting{$type}} =
13388: &Apache::loncommon::get_env_multiple('form.'.$type);
13389: foreach my $item (@contacts) {
13390: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13391: $contacts_hash{contacts}{$type}{$item} = 1;
13392: } else {
13393: $contacts_hash{contacts}{$type}{$item} = 0;
13394: }
1.289 raeburn 13395: }
1.28 raeburn 13396: $others{$type} = $env{'form.'.$type.'_others'};
13397: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13398: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13399: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13400: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13401: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13402: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13403: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13404: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13405: }
1.134 raeburn 13406: }
1.28 raeburn 13407: }
13408: foreach my $item (@contacts) {
13409: $to{$item} = $env{'form.'.$item};
13410: $contacts_hash{'contacts'}{$item} = $to{$item};
13411: }
1.203 raeburn 13412: foreach my $item (@toggles) {
13413: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13414: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13415: }
13416: }
1.340 raeburn 13417: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13418: foreach my $item (@lonstatus) {
13419: if ($item eq 'excluded') {
13420: my (%serverhomes,@excluded);
13421: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13422: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13423: if (@possexcluded) {
13424: foreach my $id (sort(@possexcluded)) {
13425: if ($serverhomes{$id}) {
13426: push(@excluded,$id);
13427: }
13428: }
13429: }
13430: if (@excluded) {
13431: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13432: }
13433: } elsif ($item eq 'weights') {
13434: foreach my $type ('E','W','N') {
13435: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13436: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13437: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13438: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13439: $env{'form.error'.$item.'_'.$type};
13440: }
13441: }
13442: }
13443: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13444: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13445: if ($env{'form.error'.$item} =~ /^\d+$/) {
13446: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13447: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13448: }
13449: }
13450: }
13451: }
1.286 raeburn 13452: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13453: foreach my $field (@{$fields}) {
13454: if (ref($possoptions->{$field}) eq 'ARRAY') {
13455: my $value = $env{'form.helpform_'.$field};
13456: $value =~ s/^\s+|\s+$//g;
13457: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13458: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13459: if ($field eq 'screenshot') {
13460: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13461: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13462: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13463: }
13464: }
13465: }
13466: }
13467: }
13468: }
1.315 raeburn 13469: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13470: my (@statuses,%usertypeshash,@overrides);
13471: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13472: @statuses = @{$types};
13473: if (ref($usertypes) eq 'HASH') {
13474: %usertypeshash = %{$usertypes};
13475: }
13476: }
13477: if (@statuses) {
13478: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13479: foreach my $type (@possoverrides) {
13480: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13481: push(@overrides,$type);
13482: }
13483: }
13484: if (@overrides) {
13485: foreach my $type (@overrides) {
13486: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13487: foreach my $item (@contacts) {
13488: if (grep(/^\Q$item\E$/,@standard)) {
13489: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13490: $newsetting{'override_'.$type}{$item} = 1;
13491: } else {
13492: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13493: $newsetting{'override_'.$type}{$item} = 0;
13494: }
13495: }
13496: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13497: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13498: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13499: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13500: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13501: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13502: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13503: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13504: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13505: }
13506: }
13507: }
13508: }
1.28 raeburn 13509: if (keys(%currsetting) > 0) {
13510: foreach my $item (@contacts) {
13511: if ($to{$item} ne $currsetting{$item}) {
13512: $changes{$item} = 1;
13513: }
13514: }
13515: foreach my $type (@mailings) {
13516: foreach my $item (@contacts) {
13517: if (ref($currsetting{$type}) eq 'HASH') {
13518: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13519: push(@{$changes{$type}},$item);
13520: }
13521: } else {
13522: push(@{$changes{$type}},@{$newsetting{$type}});
13523: }
13524: }
13525: if ($others{$type} ne $currsetting{$type}{'others'}) {
13526: push(@{$changes{$type}},'others');
13527: }
1.289 raeburn 13528: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13529: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13530: push(@{$changes{$type}},'bcc');
13531: }
1.286 raeburn 13532: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13533: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13534: push(@{$changes{$type}},'include');
13535: }
13536: }
13537: }
13538: if (ref($fields) eq 'ARRAY') {
13539: if (ref($currsetting{'helpform'}) eq 'HASH') {
13540: foreach my $field (@{$fields}) {
13541: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13542: push(@{$changes{'helpform'}},$field);
13543: }
13544: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13545: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13546: push(@{$changes{'helpform'}},'maxsize');
13547: }
13548: }
13549: }
13550: } else {
13551: foreach my $field (@{$fields}) {
13552: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13553: push(@{$changes{'helpform'}},$field);
13554: }
13555: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13556: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13557: push(@{$changes{'helpform'}},'maxsize');
13558: }
13559: }
13560: }
1.134 raeburn 13561: }
1.28 raeburn 13562: }
1.315 raeburn 13563: if (@statuses) {
13564: if (ref($currsetting{'overrides'}) eq 'HASH') {
13565: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13566: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13567: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13568: foreach my $item (@contacts,'bcc','others','include') {
13569: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13570: push(@{$changes{'overrides'}},$key);
13571: last;
13572: }
13573: }
13574: } else {
13575: push(@{$changes{'overrides'}},$key);
13576: }
13577: }
13578: }
13579: foreach my $key (@overrides) {
13580: unless (exists($currsetting{'overrides'}{$key})) {
13581: push(@{$changes{'overrides'}},$key);
13582: }
13583: }
13584: } else {
13585: foreach my $key (@overrides) {
13586: push(@{$changes{'overrides'}},$key);
13587: }
13588: }
13589: }
1.340 raeburn 13590: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13591: foreach my $key ('excluded','weights','threshold','sysmail') {
13592: if ($key eq 'excluded') {
13593: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13594: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13595: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13596: (@{$currsetting{'lonstatus'}{$key}})) {
13597: my @diffs =
13598: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13599: $currsetting{'lonstatus'}{$key});
13600: if (@diffs) {
13601: push(@{$changes{'lonstatus'}},$key);
13602: }
13603: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13604: push(@{$changes{'lonstatus'}},$key);
13605: }
13606: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13607: (@{$currsetting{'lonstatus'}{$key}})) {
13608: push(@{$changes{'lonstatus'}},$key);
13609: }
13610: } elsif ($key eq 'weights') {
13611: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13612: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13613: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13614: foreach my $type ('E','W','N','U') {
1.340 raeburn 13615: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13616: $currsetting{'lonstatus'}{$key}{$type}) {
13617: push(@{$changes{'lonstatus'}},$key);
13618: last;
13619: }
13620: }
13621: } else {
1.341 raeburn 13622: foreach my $type ('E','W','N','U') {
1.340 raeburn 13623: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13624: push(@{$changes{'lonstatus'}},$key);
13625: last;
13626: }
13627: }
13628: }
13629: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13630: foreach my $type ('E','W','N','U') {
1.340 raeburn 13631: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13632: push(@{$changes{'lonstatus'}},$key);
13633: last;
13634: }
13635: }
13636: }
13637: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13638: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13639: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13640: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13641: push(@{$changes{'lonstatus'}},$key);
13642: }
13643: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13644: push(@{$changes{'lonstatus'}},$key);
13645: }
13646: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13647: push(@{$changes{'lonstatus'}},$key);
13648: }
13649: }
13650: }
13651: } else {
13652: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13653: foreach my $key ('excluded','weights','threshold','sysmail') {
13654: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13655: push(@{$changes{'lonstatus'}},$key);
13656: }
13657: }
13658: }
13659: }
1.28 raeburn 13660: } else {
13661: my %default;
13662: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13663: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13664: $default{'errormail'} = 'adminemail';
13665: $default{'packagesmail'} = 'adminemail';
13666: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13667: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13668: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13669: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13670: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 13671: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13672: foreach my $item (@contacts) {
13673: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13674: $changes{$item} = 1;
1.203 raeburn 13675: }
1.28 raeburn 13676: }
13677: foreach my $type (@mailings) {
13678: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13679: push(@{$changes{$type}},@{$newsetting{$type}});
13680: }
13681: if ($others{$type} ne '') {
13682: push(@{$changes{$type}},'others');
1.134 raeburn 13683: }
1.286 raeburn 13684: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13685: if ($bcc{$type} ne '') {
13686: push(@{$changes{$type}},'bcc');
13687: }
1.286 raeburn 13688: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13689: push(@{$changes{$type}},'include');
13690: }
1.134 raeburn 13691: }
1.28 raeburn 13692: }
1.286 raeburn 13693: if (ref($fields) eq 'ARRAY') {
13694: foreach my $field (@{$fields}) {
13695: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13696: push(@{$changes{'helpform'}},$field);
13697: }
13698: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13699: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13700: push(@{$changes{'helpform'}},'maxsize');
13701: }
13702: }
13703: }
1.289 raeburn 13704: }
1.340 raeburn 13705: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13706: foreach my $key ('excluded','weights','threshold','sysmail') {
13707: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13708: push(@{$changes{'lonstatus'}},$key);
13709: }
13710: }
13711: }
1.28 raeburn 13712: }
1.203 raeburn 13713: foreach my $item (@toggles) {
13714: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13715: $changes{$item} = 1;
13716: } elsif ((!$env{'form.'.$item}) &&
13717: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13718: $changes{$item} = 1;
13719: }
13720: }
1.28 raeburn 13721: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13722: $dom);
13723: if ($putresult eq 'ok') {
13724: if (keys(%changes) > 0) {
1.205 raeburn 13725: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13726: if (ref($lastactref) eq 'HASH') {
13727: $lastactref->{'domainconfig'} = 1;
13728: }
1.28 raeburn 13729: my ($titles,$short_titles) = &contact_titles();
13730: $resulttext = &mt('Changes made:').'<ul>';
13731: foreach my $item (@contacts) {
13732: if ($changes{$item}) {
13733: $resulttext .= '<li>'.$titles->{$item}.
13734: &mt(' set to: ').
13735: '<span class="LC_cusr_emph">'.
13736: $to{$item}.'</span></li>';
13737: }
13738: }
13739: foreach my $type (@mailings) {
13740: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13741: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13742: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13743: } else {
13744: $resulttext .= '<li>'.$titles->{$type}.': ';
13745: }
1.28 raeburn 13746: my @text;
13747: foreach my $item (@{$newsetting{$type}}) {
13748: push(@text,$short_titles->{$item});
13749: }
13750: if ($others{$type} ne '') {
13751: push(@text,$others{$type});
13752: }
1.286 raeburn 13753: if (@text) {
13754: $resulttext .= '<span class="LC_cusr_emph">'.
13755: join(', ',@text).'</span>';
13756: }
13757: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13758: if ($bcc{$type} ne '') {
1.286 raeburn 13759: my $bcctext;
13760: if (@text) {
1.289 raeburn 13761: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13762: } else {
13763: $bcctext = '(Bcc)';
13764: }
13765: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13766: } elsif (!@text) {
13767: $resulttext .= &mt('No one');
13768: }
1.289 raeburn 13769: if ($includestr{$type} ne '') {
1.286 raeburn 13770: if ($includeloc{$type} eq 'b') {
13771: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13772: } elsif ($includeloc{$type} eq 's') {
13773: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13774: }
1.134 raeburn 13775: }
1.286 raeburn 13776: } elsif (!@text) {
13777: $resulttext .= &mt('No recipients');
1.134 raeburn 13778: }
13779: $resulttext .= '</li>';
1.28 raeburn 13780: }
13781: }
1.315 raeburn 13782: if (ref($changes{'overrides'}) eq 'ARRAY') {
13783: my @deletions;
13784: foreach my $type (@{$changes{'overrides'}}) {
13785: if ($usertypeshash{$type}) {
13786: if (grep(/^\Q$type\E/,@overrides)) {
13787: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
13788: $usertypeshash{$type}).'<ul><li>';
13789: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
13790: my @text;
13791: foreach my $item (@contacts) {
13792: if ($newsetting{'override_'.$type}{$item}) {
13793: push(@text,$short_titles->{$item});
13794: }
13795: }
13796: if ($newsetting{'override_'.$type}{'others'} ne '') {
13797: push(@text,$newsetting{'override_'.$type}{'others'});
13798: }
13799:
13800: if (@text) {
13801: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
13802: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
13803: }
13804: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
13805: my $bcctext;
13806: if (@text) {
13807: $bcctext = ' '.&mt('with Bcc to');
13808: } else {
13809: $bcctext = '(Bcc)';
13810: }
13811: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
13812: } elsif (!@text) {
13813: $resulttext .= &mt('Helpdesk e-mail sent to no one');
13814: }
13815: $resulttext .= '</li>';
13816: if ($newsetting{'override_'.$type}{'include'} ne '') {
13817: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
13818: if ($loc eq 'b') {
13819: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
13820: } elsif ($loc eq 's') {
13821: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
13822: }
13823: }
13824: }
13825: $resulttext .= '</li></ul></li>';
13826: } else {
13827: push(@deletions,$usertypeshash{$type});
13828: }
13829: }
13830: }
13831: if (@deletions) {
13832: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
13833: join(', ',@deletions)).'</li>';
13834: }
13835: }
1.203 raeburn 13836: my @offon = ('off','on');
1.340 raeburn 13837: my $corelink = &core_link_msu();
1.203 raeburn 13838: if ($changes{'reporterrors'}) {
13839: $resulttext .= '<li>'.
13840: &mt('E-mail error reports to [_1] set to "'.
13841: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 13842: $corelink).
1.203 raeburn 13843: '</li>';
13844: }
13845: if ($changes{'reportupdates'}) {
13846: $resulttext .= '<li>'.
13847: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
13848: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 13849: $corelink).
1.203 raeburn 13850: '</li>';
13851: }
1.340 raeburn 13852: if ($changes{'reportstatus'}) {
13853: $resulttext .= '<li>'.
13854: &mt('E-mail status if errors above threshold to [_1] set to "'.
13855: $offon[$env{'form.reportstatus'}].'".',
13856: $corelink).
13857: '</li>';
13858: }
13859: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
13860: $resulttext .= '<li>'.
13861: &mt('Nightly status check e-mail settings').':<ul>';
13862: my (%defval,%use_def,%shown);
13863: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
13864: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
13865: $defval{'weights'} =
1.341 raeburn 13866: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 13867: $defval{'excluded'} = &mt('None');
13868: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
13869: foreach my $item ('threshold','sysmail','weights','excluded') {
13870: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
13871: if (($item eq 'threshold') || ($item eq 'sysmail')) {
13872: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
13873: } elsif ($item eq 'weights') {
13874: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 13875: foreach my $type ('E','W','N','U') {
1.340 raeburn 13876: $shown{$item} .= $lonstatus_names->{$type}.'=';
13877: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
13878: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
13879: } else {
13880: $shown{$item} .= $lonstatus_defs->{$type};
13881: }
13882: $shown{$item} .= ', ';
13883: }
13884: $shown{$item} =~ s/, $//;
13885: } else {
13886: $shown{$item} = $defval{$item};
13887: }
13888: } elsif ($item eq 'excluded') {
13889: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
13890: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
13891: } else {
13892: $shown{$item} = $defval{$item};
13893: }
13894: }
13895: } else {
13896: $shown{$item} = $defval{$item};
13897: }
13898: }
13899: } else {
13900: foreach my $item ('threshold','weights','excluded','sysmail') {
13901: $shown{$item} = $defval{$item};
13902: }
13903: }
13904: foreach my $item ('threshold','weights','excluded','sysmail') {
13905: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
13906: $shown{$item}).'</li>';
13907: }
13908: $resulttext .= '</ul></li>';
13909: }
1.286 raeburn 13910: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
13911: my (@optional,@required,@unused,$maxsizechg);
13912: foreach my $field (@{$changes{'helpform'}}) {
13913: if ($field eq 'maxsize') {
13914: $maxsizechg = 1;
13915: next;
13916: }
13917: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 13918: push(@optional,$field);
1.286 raeburn 13919: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
13920: push(@unused,$field);
13921: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 13922: push(@required,$field);
1.286 raeburn 13923: }
13924: }
13925: if (@optional) {
13926: $resulttext .= '<li>'.
13927: &mt('Help form fields changed to "Optional": [_1].',
13928: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
13929: '</li>';
13930: }
13931: if (@required) {
13932: $resulttext .= '<li>'.
13933: &mt('Help form fields changed to "Required": [_1].',
13934: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
13935: '</li>';
13936: }
13937: if (@unused) {
13938: $resulttext .= '<li>'.
13939: &mt('Help form fields changed to "Not shown": [_1].',
13940: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
13941: '</li>';
13942: }
13943: if ($maxsizechg) {
13944: $resulttext .= '<li>'.
13945: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
13946: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
13947: '</li>';
13948: }
13949: }
1.28 raeburn 13950: $resulttext .= '</ul>';
13951: } else {
1.288 raeburn 13952: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 13953: }
13954: } else {
13955: $resulttext = '<span class="LC_error">'.
13956: &mt('An error occurred: [_1].',$putresult).'</span>';
13957: }
13958: return $resulttext;
13959: }
13960:
1.354 raeburn 13961: sub modify_passwords {
13962: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 ! raeburn 13963: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
! 13964: $updatedefaults,$updateconf);
1.354 raeburn 13965: my $customfn = 'resetpw.html';
13966: if (ref($domconfig{'passwords'}) eq 'HASH') {
13967: %current = %{$domconfig{'passwords'}};
13968: }
13969: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13970: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13971: if (ref($types) eq 'ARRAY') {
13972: @oktypes = @{$types};
13973: }
13974: push(@oktypes,'default');
13975:
13976: my %titles = &Apache::lonlocal::texthash (
13977: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
13978: intauth_check => 'Check bcrypt cost if authenticated',
13979: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
13980: permanent => 'Permanent e-mail address',
13981: critical => 'Critical notification address',
13982: notify => 'Notification address',
13983: min => 'Minimum password length',
13984: max => 'Maximum password length',
13985: chars => 'Required characters',
13986: expire => 'Password expiration (days)',
13987: reset => 'Resetting Forgotten Password',
13988: intauth => 'Encryption of Stored Passwords (Internal Auth)',
13989: rules => 'Rules for LON-CAPA Passwords',
13990: crsownerchg => 'Course Owner Changing Student Passwords',
13991: username => 'Username',
13992: email => 'E-mail address',
13993: );
13994:
13995: #
13996: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
13997: #
13998: my (%curr_defaults,%save_defaults);
13999: if (ref($domconfig{'defaults'}) eq 'HASH') {
14000: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14001: if ($key =~ /^intauth_(cost|check|switch)$/) {
14002: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14003: } else {
14004: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14005: }
14006: }
14007: }
14008: my %staticdefaults = (
14009: 'resetlink' => 2,
14010: 'resetcase' => \@oktypes,
14011: 'resetprelink' => 'both',
14012: 'resetemail' => ['critical','notify','permanent'],
14013: 'intauth_cost' => 10,
14014: 'intauth_check' => 0,
14015: 'intauth_switch' => 0,
14016: 'min' => 7,
14017: );
14018: foreach my $type (@oktypes) {
14019: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14020: }
14021: my $linklife = $env{'form.passwords_link'};
14022: $linklife =~ s/^\s+|\s+$//g;
14023: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14024: $newvalues{'resetlink'} = $linklife;
14025: if ($current{'resetlink'}) {
14026: if ($current{'resetlink'} ne $linklife) {
14027: $changes{'reset'} = 1;
14028: }
14029: } elsif (!exists($domconfig{passwords})) {
14030: if ($staticdefaults{'resetlink'} ne $linklife) {
14031: $changes{'reset'} = 1;
14032: }
14033: }
14034: } elsif ($current{'resetlink'}) {
14035: $changes{'reset'} = 1;
14036: }
14037: my @casesens;
14038: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14039: foreach my $case (sort(@posscase)) {
14040: if (grep(/^\Q$case\E$/,@oktypes)) {
14041: push(@casesens,$case);
14042: }
14043: }
14044: $newvalues{'resetcase'} = \@casesens;
14045: if (ref($current{'resetcase'}) eq 'ARRAY') {
14046: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14047: if (@diffs > 0) {
14048: $changes{'reset'} = 1;
14049: }
14050: } elsif (!exists($domconfig{passwords})) {
14051: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14052: if (@diffs > 0) {
14053: $changes{'reset'} = 1;
14054: }
14055: }
14056: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14057: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14058: if (exists($current{'resetprelink'})) {
14059: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14060: $changes{'reset'} = 1;
14061: }
14062: } elsif (!exists($domconfig{passwords})) {
14063: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14064: $changes{'reset'} = 1;
14065: }
14066: }
14067: } elsif ($current{'resetprelink'}) {
14068: $changes{'reset'} = 1;
14069: }
14070: foreach my $type (@oktypes) {
14071: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14072: my @postlink;
14073: foreach my $item (sort(@possplink)) {
14074: if ($item =~ /^(email|username)$/) {
14075: push(@postlink,$item);
14076: }
14077: }
14078: $newvalues{'resetpostlink'}{$type} = \@postlink;
14079: unless ($changes{'reset'}) {
14080: if (ref($current{'resetpostlink'}) eq 'HASH') {
14081: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14082: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14083: if (@diffs > 0) {
14084: $changes{'reset'} = 1;
14085: }
14086: } else {
14087: $changes{'reset'} = 1;
14088: }
14089: } elsif (!exists($domconfig{passwords})) {
14090: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14091: if (@diffs > 0) {
14092: $changes{'reset'} = 1;
14093: }
14094: }
14095: }
14096: }
14097: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14098: my @resetemail;
14099: foreach my $item (sort(@possemailsrc)) {
14100: if ($item =~ /^(permanent|critical|notify)$/) {
14101: push(@resetemail,$item);
14102: }
14103: }
14104: $newvalues{'resetemail'} = \@resetemail;
14105: unless ($changes{'reset'}) {
14106: if (ref($current{'resetemail'}) eq 'ARRAY') {
14107: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14108: if (@diffs > 0) {
14109: $changes{'reset'} = 1;
14110: }
14111: } elsif (!exists($domconfig{passwords})) {
14112: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14113: if (@diffs > 0) {
14114: $changes{'reset'} = 1;
14115: }
14116: }
14117: }
14118: if ($env{'form.passwords_stdtext'} == 0) {
14119: $newvalues{'resetremove'} = 1;
14120: unless ($current{'resetremove'}) {
14121: $changes{'reset'} = 1;
14122: }
14123: } elsif ($current{'resetremove'}) {
14124: $changes{'reset'} = 1;
14125: }
14126: if ($env{'form.passwords_customfile.filename'} ne '') {
14127: my $servadm = $r->dir_config('lonAdmEMail');
14128: my ($configuserok,$author_ok,$switchserver) =
14129: &config_check($dom,$confname,$servadm);
14130: my $error;
14131: if ($configuserok eq 'ok') {
14132: if ($switchserver) {
14133: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14134: } else {
14135: if ($author_ok eq 'ok') {
14136: my ($result,$customurl) =
14137: &publishlogo($r,'upload','passwords_customfile',$dom,
14138: $confname,'customtext/resetpw','','',$customfn);
14139: if ($result eq 'ok') {
14140: $newvalues{'resetcustom'} = $customurl;
14141: $changes{'reset'} = 1;
14142: } else {
14143: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14144: }
14145: } else {
14146: $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);
14147: }
14148: }
14149: } else {
14150: $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);
14151: }
14152: if ($error) {
14153: &Apache::lonnet::logthis($error);
14154: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14155: }
14156: } elsif ($current{'resetcustom'}) {
14157: if ($env{'form.passwords_custom_del'}) {
14158: $changes{'reset'} = 1;
14159: } else {
14160: $newvalues{'resetcustom'} = $current{'resetcustom'};
14161: }
14162: }
14163: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14164: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14165: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14166: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14167: $changes{'intauth'} = 1;
14168: }
14169: } else {
14170: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14171: }
14172: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14173: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14174: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14175: $changes{'intauth'} = 1;
14176: }
14177: } else {
14178: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14179: }
14180: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14181: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14182: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14183: $changes{'intauth'} = 1;
14184: }
14185: } else {
14186: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14187: }
14188: foreach my $item ('cost','check','switch') {
14189: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14190: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14191: $updatedefaults = 1;
14192: }
14193: }
14194: foreach my $rule ('min','max','expire') {
14195: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
14196: if ($env{'form.passwords_'.$rule} =~ /^(|\d+(|\.\d*))$/) {
14197: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14198: if (exists($current{$rule})) {
14199: if ($newvalues{$rule} ne $current{$rule}) {
14200: $changes{'rules'} = 1;
14201: }
14202: } elsif ($rule eq 'min') {
14203: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14204: $changes{'rules'} = 1;
14205: }
14206: }
14207: } elsif (exists($current{$rule})) {
14208: $changes{'rules'} = 1;
14209: }
14210: }
14211: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14212: my @chars;
14213: foreach my $item (sort(@posschars)) {
14214: if ($item =~ /^(uc|lc|num|spec)$/) {
14215: push(@chars,$item);
14216: }
14217: }
14218: $newvalues{'chars'} = \@chars;
14219: unless ($changes{'rules'}) {
14220: if (ref($current{'chars'}) eq 'ARRAY') {
14221: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14222: if (@diffs > 0) {
14223: $changes{'rules'} = 1;
14224: }
14225: } else {
14226: if (@chars > 0) {
14227: $changes{'rules'} = 1;
14228: }
14229: }
14230: }
14231: if ($env{'form.passwords_crsowner'}) {
14232: $newvalues{'crsownerchg'} = 1;
14233: unless ($current{'crsownerchg'}) {
14234: $changes{'crsownerchg'} = 1;
14235: }
14236: } elsif ($current{'crsownerchg'}) {
14237: $changes{'crsownerchg'} = 1;
14238: }
14239:
14240: my %confighash = (
14241: defaults => \%save_defaults,
14242: passwords => \%newvalues,
14243: );
14244: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14245:
14246: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14247: if ($putresult eq 'ok') {
14248: if (keys(%changes) > 0) {
14249: $resulttext = &mt('Changes made: ').'<ul>';
14250: foreach my $key ('reset','intauth','rules','crsownerchg') {
14251: if ($changes{$key}) {
1.355 ! raeburn 14252: unless ($key eq 'intauth') {
! 14253: $updateconf = 1;
! 14254: }
1.354 raeburn 14255: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14256: if ($key eq 'reset') {
14257: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14258: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14259: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14260: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14261: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
14262: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
14263: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
14264: } else {
14265: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14266: }
14267: if ($confighash{'passwords'}{'resetlink'}) {
14268: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14269: } else {
14270: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14271: &mt('Will default to 2 hours').'</li>';
14272: }
14273: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14274: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14275: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14276: } else {
14277: my $casesens;
14278: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14279: if ($type eq 'default') {
14280: $casesens .= $othertitle.', ';
14281: } elsif ($usertypes->{$type} ne '') {
14282: $casesens .= $usertypes->{$type}.', ';
14283: }
14284: }
14285: $casesens =~ s/\Q, \E$//;
14286: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14287: }
14288: } else {
14289: $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>';
14290: }
14291: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14292: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14293: } else {
14294: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14295: }
14296: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14297: my $output;
14298: if (ref($types) eq 'ARRAY') {
14299: foreach my $type (@{$types}) {
14300: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14301: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14302: $output .= $usertypes->{$type}.' -- '.&mt('none');
14303: } else {
14304: $output .= $usertypes->{$type}.' -- '.
14305: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14306: }
14307: }
14308: }
14309: }
14310: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14311: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14312: $output .= $othertitle.' -- '.&mt('none');
14313: } else {
14314: $output .= $othertitle.' -- '.
14315: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14316: }
14317: }
14318: if ($output) {
14319: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14320: } else {
14321: $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>';
14322: }
14323: } else {
14324: $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>';
14325: }
14326: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14327: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14328: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14329: } else {
14330: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14331: }
14332: } else {
14333: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14334: }
14335: if ($confighash{'passwords'}{'resetremove'}) {
14336: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14337: } else {
14338: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14339: }
14340: if ($confighash{'passwords'}{'resetcustom'}) {
14341: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14342: $titles{custom},600,500);
14343: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
14344: } else {
14345: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14346: }
14347: } elsif ($key eq 'intauth') {
14348: foreach my $item ('cost','switch','check') {
14349: my $value = $save_defaults{$key.'_'.$item};
14350: if ($item eq 'switch') {
14351: my %optiondesc = &Apache::lonlocal::texthash (
14352: 0 => 'No',
14353: 1 => 'Yes',
14354: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14355: );
14356: if ($value =~ /^(0|1|2)$/) {
14357: $value = $optiondesc{$value};
14358: } else {
14359: $value = &mt('none -- defaults to No');
14360: }
14361: } elsif ($item eq 'check') {
14362: my %optiondesc = &Apache::lonlocal::texthash (
14363: 0 => 'No',
14364: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14365: 2 => 'Yes, disallow login if stored cost is less than domain default',
14366: );
14367: if ($value =~ /^(0|1|2)$/) {
14368: $value = $optiondesc{$value};
14369: } else {
14370: $value = &mt('none -- defaults to No');
14371: }
14372: }
14373: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14374: }
14375: } elsif ($key eq 'rules') {
14376: foreach my $rule ('min','max','expire') {
14377: if ($confighash{'passwords'}{$rule} eq '') {
14378: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14379: if ($rule eq 'min') {
14380: $resulttext .= ' '.&mt('Default of 7 will be used');
14381: }
14382: $resulttext .= '</li>';
14383: } else {
14384: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14385: }
14386: }
14387: } elsif ($key eq 'crsownerchg') {
14388: if ($confighash{'passwords'}{'crsownerchg'}) {
14389: $resulttext .= '<li>'.&mt('Course owner may change student passwords.').'</li>';
14390: } else {
14391: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.');
14392: }
14393: }
14394: $resulttext .= '</ul></li>';
14395: }
14396: }
14397: $resulttext .= '</ul>';
14398: } else {
14399: $resulttext = &mt('No changes made to password settings');
14400: }
1.355 ! raeburn 14401: my $cachetime = 24*60*60;
1.354 raeburn 14402: if ($updatedefaults) {
14403: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14404: if (ref($lastactref) eq 'HASH') {
14405: $lastactref->{'domdefaults'} = 1;
14406: }
14407: }
1.355 ! raeburn 14408: if ($updateconf) {
! 14409: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
! 14410: if (ref($lastactref) eq 'HASH') {
! 14411: $lastactref->{'passwdconf'} = 1;
! 14412: }
! 14413: }
1.354 raeburn 14414: } else {
14415: $resulttext = '<span class="LC_error">'.
14416: &mt('An error occurred: [_1]',$putresult).'</span>';
14417: }
14418: if ($errors) {
14419: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14420: $errors.'</ul></p>';
14421: }
14422: return $resulttext;
14423: }
14424:
1.28 raeburn 14425: sub modify_usercreation {
1.27 raeburn 14426: my ($dom,%domconfig) = @_;
1.224 raeburn 14427: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14428: my $warningmsg;
1.27 raeburn 14429: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14430: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 14431: if ($key eq 'cancreate') {
14432: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14433: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 14434: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
14435: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14436: } else {
1.224 raeburn 14437: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14438: }
14439: }
14440: }
14441: } elsif ($key eq 'email_rule') {
14442: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14443: } else {
14444: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14445: }
1.27 raeburn 14446: }
14447: }
14448: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 14449: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 14450: my @contexts = ('author','course','requestcrs');
1.34 raeburn 14451: foreach my $item(@contexts) {
1.224 raeburn 14452: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14453: }
1.34 raeburn 14454: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14455: foreach my $item (@contexts) {
1.224 raeburn 14456: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14457: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14458: }
1.27 raeburn 14459: }
1.34 raeburn 14460: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14461: foreach my $item (@contexts) {
1.43 raeburn 14462: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14463: if ($cancreate{$item} ne 'any') {
14464: push(@{$changes{'cancreate'}},$item);
14465: }
14466: } else {
14467: if ($cancreate{$item} ne 'none') {
14468: push(@{$changes{'cancreate'}},$item);
14469: }
1.27 raeburn 14470: }
14471: }
14472: } else {
1.43 raeburn 14473: foreach my $item (@contexts) {
1.34 raeburn 14474: push(@{$changes{'cancreate'}},$item);
14475: }
1.27 raeburn 14476: }
1.34 raeburn 14477:
1.27 raeburn 14478: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14479: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14480: if (!grep(/^\Q$type\E$/,@username_rule)) {
14481: push(@{$changes{'username_rule'}},$type);
14482: }
14483: }
14484: foreach my $type (@username_rule) {
14485: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14486: push(@{$changes{'username_rule'}},$type);
14487: }
14488: }
14489: } else {
14490: push(@{$changes{'username_rule'}},@username_rule);
14491: }
14492:
1.32 raeburn 14493: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14494: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14495: if (!grep(/^\Q$type\E$/,@id_rule)) {
14496: push(@{$changes{'id_rule'}},$type);
14497: }
14498: }
14499: foreach my $type (@id_rule) {
14500: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14501: push(@{$changes{'id_rule'}},$type);
14502: }
14503: }
14504: } else {
14505: push(@{$changes{'id_rule'}},@id_rule);
14506: }
14507:
1.43 raeburn 14508: my @authen_contexts = ('author','course','domain');
1.325 raeburn 14509: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 14510: my %authhash;
1.43 raeburn 14511: foreach my $item (@authen_contexts) {
1.28 raeburn 14512: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
14513: foreach my $auth (@authtypes) {
14514: if (grep(/^\Q$auth\E$/,@authallowed)) {
14515: $authhash{$item}{$auth} = 1;
14516: } else {
14517: $authhash{$item}{$auth} = 0;
14518: }
14519: }
14520: }
14521: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 14522: foreach my $item (@authen_contexts) {
1.28 raeburn 14523: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
14524: foreach my $auth (@authtypes) {
14525: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
14526: push(@{$changes{'authtypes'}},$item);
14527: last;
14528: }
14529: }
14530: }
14531: }
14532: } else {
1.43 raeburn 14533: foreach my $item (@authen_contexts) {
1.28 raeburn 14534: push(@{$changes{'authtypes'}},$item);
14535: }
14536: }
14537:
1.224 raeburn 14538: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
14539: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
14540: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
14541: $save_usercreate{'id_rule'} = \@id_rule;
14542: $save_usercreate{'username_rule'} = \@username_rule,
14543: $save_usercreate{'authtypes'} = \%authhash;
14544:
1.27 raeburn 14545: my %usercreation_hash = (
1.224 raeburn 14546: usercreation => \%save_usercreate,
14547: );
1.27 raeburn 14548:
14549: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
14550: $dom);
1.50 raeburn 14551:
1.224 raeburn 14552: if ($putresult eq 'ok') {
14553: if (keys(%changes) > 0) {
14554: $resulttext = &mt('Changes made:').'<ul>';
14555: if (ref($changes{'cancreate'}) eq 'ARRAY') {
14556: my %lt = &usercreation_types();
14557: foreach my $type (@{$changes{'cancreate'}}) {
14558: my $chgtext = $lt{$type}.', ';
14559: if ($cancreate{$type} eq 'none') {
14560: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
14561: } elsif ($cancreate{$type} eq 'any') {
14562: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
14563: } elsif ($cancreate{$type} eq 'official') {
14564: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
14565: } elsif ($cancreate{$type} eq 'unofficial') {
14566: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
14567: }
14568: $resulttext .= '<li>'.$chgtext.'</li>';
14569: }
14570: }
14571: if (ref($changes{'username_rule'}) eq 'ARRAY') {
14572: my ($rules,$ruleorder) =
14573: &Apache::lonnet::inst_userrules($dom,'username');
14574: my $chgtext = '<ul>';
14575: foreach my $type (@username_rule) {
14576: if (ref($rules->{$type}) eq 'HASH') {
14577: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
14578: }
14579: }
14580: $chgtext .= '</ul>';
14581: if (@username_rule > 0) {
14582: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14583: } else {
14584: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
14585: }
14586: }
14587: if (ref($changes{'id_rule'}) eq 'ARRAY') {
14588: my ($idrules,$idruleorder) =
14589: &Apache::lonnet::inst_userrules($dom,'id');
14590: my $chgtext = '<ul>';
14591: foreach my $type (@id_rule) {
14592: if (ref($idrules->{$type}) eq 'HASH') {
14593: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
14594: }
14595: }
14596: $chgtext .= '</ul>';
14597: if (@id_rule > 0) {
14598: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
14599: } else {
14600: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
14601: }
14602: }
14603: my %authname = &authtype_names();
14604: my %context_title = &context_names();
14605: if (ref($changes{'authtypes'}) eq 'ARRAY') {
14606: my $chgtext = '<ul>';
14607: foreach my $type (@{$changes{'authtypes'}}) {
14608: my @allowed;
14609: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
14610: foreach my $auth (@authtypes) {
14611: if ($authhash{$type}{$auth}) {
14612: push(@allowed,$authname{$auth});
14613: }
14614: }
14615: if (@allowed > 0) {
14616: $chgtext .= join(', ',@allowed).'</li>';
14617: } else {
14618: $chgtext .= &mt('none').'</li>';
14619: }
14620: }
14621: $chgtext .= '</ul>';
14622: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
14623: $resulttext .= '</li>';
14624: }
14625: $resulttext .= '</ul>';
14626: } else {
14627: $resulttext = &mt('No changes made to user creation settings');
14628: }
14629: } else {
14630: $resulttext = '<span class="LC_error">'.
14631: &mt('An error occurred: [_1]',$putresult).'</span>';
14632: }
14633: if ($warningmsg ne '') {
14634: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
14635: }
14636: return $resulttext;
14637: }
14638:
14639: sub modify_selfcreation {
1.305 raeburn 14640: my ($dom,$lastactref,%domconfig) = @_;
14641: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
14642: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
14643: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 14644: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
14645: if (ref($typesref) eq 'ARRAY') {
14646: @types = @{$typesref};
14647: }
14648: if (ref($usertypesref) eq 'HASH') {
14649: %usertypes = %{$usertypesref};
1.228 raeburn 14650: }
1.303 raeburn 14651: $usertypes{'default'} = $othertitle;
1.224 raeburn 14652: #
14653: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
14654: #
14655: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14656: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
14657: if ($key eq 'cancreate') {
14658: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14659: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
14660: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 14661: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
14662: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
14663: ($item eq 'emailusername') || ($item eq 'shibenv') ||
14664: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 14665: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 14666: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14667: } else {
14668: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14669: }
14670: }
14671: }
14672: } elsif ($key eq 'email_rule') {
14673: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14674: } else {
14675: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14676: }
14677: }
14678: }
14679: #
14680: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
14681: #
14682: if (ref($domconfig{'usermodification'}) eq 'HASH') {
14683: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
14684: if ($key eq 'selfcreate') {
14685: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
14686: } else {
14687: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
14688: }
14689: }
14690: }
1.305 raeburn 14691: #
14692: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
14693: #
14694: if (ref($domconfig{'inststatus'}) eq 'HASH') {
14695: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
14696: if ($key eq 'inststatusguest') {
14697: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
14698: } else {
14699: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
14700: }
14701: }
14702: }
1.224 raeburn 14703:
14704: my @contexts = ('selfcreate');
14705: @{$cancreate{'selfcreate'}} = ();
14706: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 14707: if (@types) {
14708: @{$cancreate{'statustocreate'}} = ();
14709: }
1.236 raeburn 14710: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 14711: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 14712: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 14713: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 14714: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 14715: my %selfcreatetypes = (
14716: sso => 'users authenticated by institutional single sign on',
14717: login => 'users authenticated by institutional log-in',
1.303 raeburn 14718: email => 'users verified by e-mail',
1.50 raeburn 14719: );
1.224 raeburn 14720: #
14721: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
14722: # is permitted.
14723: #
1.305 raeburn 14724: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 14725:
1.305 raeburn 14726: my (@statuses,%email_rule);
1.228 raeburn 14727: foreach my $item ('login','sso','email') {
1.224 raeburn 14728: if ($item eq 'email') {
1.236 raeburn 14729: if ($env{'form.cancreate_email'}) {
1.305 raeburn 14730: if (@types) {
14731: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
14732: foreach my $status (@poss_statuses) {
14733: if (grep(/^\Q$status\E$/,(@types,'default'))) {
14734: push(@statuses,$status);
14735: }
14736: }
14737: $save_inststatus{'inststatusguest'} = \@statuses;
14738: } else {
14739: push(@statuses,'default');
14740: }
14741: if (@statuses) {
14742: my %curr_rule;
14743: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
14744: foreach my $type (@statuses) {
14745: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 14746: }
1.305 raeburn 14747: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
14748: foreach my $type (@statuses) {
14749: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
14750: }
14751: }
14752: push(@{$cancreate{'selfcreate'}},'email');
14753: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
14754: my %curremaildom;
14755: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
14756: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
14757: }
14758: foreach my $type (@statuses) {
14759: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
14760: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
14761: }
14762: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
14763: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
14764: }
14765: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
14766: #
14767: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
14768: #
14769: my $chosen = $1;
14770: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
14771: my $emaildom;
14772: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
14773: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
14774: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
14775: if (ref($curremaildom{$type}) eq 'HASH') {
14776: if (exists($curremaildom{$type}{$chosen})) {
14777: if ($curremaildom{$type}{$chosen} ne $emaildom) {
14778: push(@{$changes{'cancreate'}},'emaildomain');
14779: }
14780: } elsif ($emaildom ne '') {
14781: push(@{$changes{'cancreate'}},'emaildomain');
14782: }
14783: } elsif ($emaildom ne '') {
14784: push(@{$changes{'cancreate'}},'emaildomain');
14785: }
14786: }
14787: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14788: } elsif ($chosen eq 'custom') {
14789: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
14790: $email_rule{$type} = [];
14791: if (ref($emailrules) eq 'HASH') {
14792: foreach my $rule (@possemail_rules) {
14793: if (exists($emailrules->{$rule})) {
14794: push(@{$email_rule{$type}},$rule);
14795: }
14796: }
14797: }
14798: if (@{$email_rule{$type}}) {
14799: $cancreate{'emailoptions'}{$type} = 'custom';
14800: if (ref($curr_rule{$type}) eq 'ARRAY') {
14801: if (@{$curr_rule{$type}} > 0) {
14802: foreach my $rule (@{$curr_rule{$type}}) {
14803: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
14804: push(@{$changes{'email_rule'}},$type);
14805: }
14806: }
14807: }
14808: foreach my $type (@{$email_rule{$type}}) {
14809: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
14810: push(@{$changes{'email_rule'}},$type);
14811: }
14812: }
14813: } else {
14814: push(@{$changes{'email_rule'}},$type);
14815: }
14816: }
14817: } else {
14818: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
14819: }
14820: }
14821: }
14822: if (@types) {
14823: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14824: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
14825: if (@changed) {
14826: push(@{$changes{'inststatus'}},'inststatusguest');
14827: }
14828: } else {
14829: push(@{$changes{'inststatus'}},'inststatusguest');
14830: }
14831: }
14832: } else {
14833: delete($env{'form.cancreate_email'});
14834: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14835: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14836: push(@{$changes{'inststatus'}},'inststatusguest');
14837: }
14838: }
14839: }
14840: } else {
14841: $save_inststatus{'inststatusguest'} = [];
14842: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
14843: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
14844: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 14845: }
14846: }
1.224 raeburn 14847: }
14848: } else {
14849: if ($env{'form.cancreate_'.$item}) {
14850: push(@{$cancreate{'selfcreate'}},$item);
14851: }
14852: }
14853: }
1.305 raeburn 14854: my (%userinfo,%savecaptcha);
1.224 raeburn 14855: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
14856: #
1.228 raeburn 14857: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
14858: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 14859: #
1.236 raeburn 14860:
1.244 raeburn 14861: if ($env{'form.cancreate_email'}) {
1.228 raeburn 14862: push(@contexts,'emailusername');
1.305 raeburn 14863: if (@statuses) {
14864: foreach my $type (@statuses) {
1.228 raeburn 14865: if (ref($infofields) eq 'ARRAY') {
14866: foreach my $field (@{$infofields}) {
14867: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
14868: $cancreate{'emailusername'}{$type}{$field} = $1;
14869: }
14870: }
1.224 raeburn 14871: }
14872: }
14873: }
14874: #
14875: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 14876: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 14877: #
14878:
14879: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
14880: @approvalnotify = sort(@approvalnotify);
14881: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
14882: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14883: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
14884: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
14885: push(@{$changes{'cancreate'}},'notify');
14886: }
14887: } else {
14888: if ($cancreate{'notify'}{'approval'}) {
14889: push(@{$changes{'cancreate'}},'notify');
14890: }
14891: }
14892: } elsif ($cancreate{'notify'}{'approval'}) {
14893: push(@{$changes{'cancreate'}},'notify');
14894: }
14895:
14896: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
14897: }
14898: #
1.236 raeburn 14899: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 14900: # institutional log-in.
14901: #
14902: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
14903: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
14904: ($domdefaults{'auth_def'} eq 'localauth'))) {
14905: $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.').' '.
14906: &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.');
14907: }
14908: }
14909: my @fields = ('lastname','firstname','middlename','generation',
14910: 'permanentemail','id');
1.240 raeburn 14911: my @shibfields = (@fields,'inststatus');
1.224 raeburn 14912: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
14913: #
14914: # Where usernames may created for institutional log-in and/or institutional single sign on:
14915: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
14916: # may self-create accounts
14917: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
14918: # which the user may supply, if institutional data is unavailable.
14919: #
14920: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 14921: if (@types) {
1.305 raeburn 14922: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
14923: push(@contexts,'statustocreate');
1.303 raeburn 14924: foreach my $type (@types) {
1.224 raeburn 14925: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
14926: foreach my $field (@fields) {
14927: if (grep(/^\Q$field\E$/,@modifiable)) {
14928: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
14929: } else {
14930: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
14931: }
14932: }
14933: }
14934: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 14935: foreach my $type (@types) {
1.224 raeburn 14936: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
14937: foreach my $field (@fields) {
14938: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
14939: $curr_usermodify{'selfcreate'}{$type}{$field}) {
14940: push(@{$changes{'selfcreate'}},$type);
14941: last;
14942: }
14943: }
14944: }
14945: }
14946: } else {
1.303 raeburn 14947: foreach my $type (@types) {
1.224 raeburn 14948: push(@{$changes{'selfcreate'}},$type);
14949: }
14950: }
14951: }
1.240 raeburn 14952: foreach my $field (@shibfields) {
14953: if ($env{'form.shibenv_'.$field} ne '') {
14954: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
14955: }
14956: }
14957: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14958: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
14959: foreach my $field (@shibfields) {
14960: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
14961: push(@{$changes{'cancreate'}},'shibenv');
14962: }
14963: }
14964: } else {
14965: foreach my $field (@shibfields) {
14966: if ($env{'form.shibenv_'.$field}) {
14967: push(@{$changes{'cancreate'}},'shibenv');
14968: last;
14969: }
14970: }
14971: }
14972: }
1.224 raeburn 14973: }
14974: foreach my $item (@contexts) {
14975: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
14976: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
14977: if (ref($cancreate{$item}) eq 'ARRAY') {
14978: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
14979: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14980: push(@{$changes{'cancreate'}},$item);
14981: }
14982: }
14983: }
14984: }
14985: if (ref($cancreate{$item}) eq 'ARRAY') {
14986: foreach my $type (@{$cancreate{$item}}) {
14987: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
14988: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
14989: push(@{$changes{'cancreate'}},$item);
14990: }
14991: }
14992: }
14993: }
14994: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
14995: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 14996: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
14997: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
14998: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
14999: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15000: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15001: push(@{$changes{'cancreate'}},$item);
15002: }
15003: }
15004: }
1.305 raeburn 15005: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15006: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15007: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15008: push(@{$changes{'cancreate'}},$item);
15009: }
1.224 raeburn 15010: }
15011: }
15012: }
1.305 raeburn 15013: foreach my $type (keys(%{$cancreate{$item}})) {
15014: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15015: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15016: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15017: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15018: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15019: push(@{$changes{'cancreate'}},$item);
15020: }
15021: }
15022: } else {
15023: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15024: push(@{$changes{'cancreate'}},$item);
15025: }
15026: }
15027: }
1.305 raeburn 15028: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15029: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15030: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15031: push(@{$changes{'cancreate'}},$item);
15032: }
1.224 raeburn 15033: }
15034: }
15035: }
15036: }
15037: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15038: if (ref($cancreate{$item}) eq 'ARRAY') {
15039: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15040: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15041: push(@{$changes{'cancreate'}},$item);
15042: }
15043: }
1.305 raeburn 15044: }
15045: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15046: if (ref($cancreate{$item}) eq 'HASH') {
15047: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15048: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 15049: }
15050: }
15051: } elsif ($item eq 'emailusername') {
1.228 raeburn 15052: if (ref($cancreate{$item}) eq 'HASH') {
15053: foreach my $type (keys(%{$cancreate{$item}})) {
15054: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15055: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15056: if ($cancreate{$item}{$type}{$field}) {
15057: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15058: push(@{$changes{'cancreate'}},$item);
15059: }
15060: last;
15061: }
15062: }
15063: }
15064: }
1.224 raeburn 15065: }
15066: }
15067: }
15068: #
15069: # Populate %save_usercreate hash with updates to self-creation configuration.
15070: #
15071: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15072: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 15073: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 15074: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15075: if (ref($cancreate{'notify'}) eq 'HASH') {
15076: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15077: }
1.236 raeburn 15078: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15079: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15080: }
1.303 raeburn 15081: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15082: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15083: }
1.305 raeburn 15084: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15085: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15086: }
1.303 raeburn 15087: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15088: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15089: }
1.224 raeburn 15090: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15091: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15092: }
1.240 raeburn 15093: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15094: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15095: }
1.224 raeburn 15096: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 15097: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 15098:
15099: my %userconfig_hash = (
15100: usercreation => \%save_usercreate,
15101: usermodification => \%save_usermodify,
1.305 raeburn 15102: inststatus => \%save_inststatus,
1.224 raeburn 15103: );
1.305 raeburn 15104:
1.224 raeburn 15105: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15106: $dom);
15107: #
1.305 raeburn 15108: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 15109: #
1.27 raeburn 15110: if ($putresult eq 'ok') {
15111: if (keys(%changes) > 0) {
15112: $resulttext = &mt('Changes made:').'<ul>';
15113: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 15114: my %lt = &selfcreation_types();
1.34 raeburn 15115: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 15116: my $chgtext = '';
1.45 raeburn 15117: if ($type eq 'selfcreate') {
1.50 raeburn 15118: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 15119: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15120: } else {
1.224 raeburn 15121: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15122: '<ul>';
1.50 raeburn 15123: foreach my $case (@{$cancreate{$type}}) {
15124: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15125: }
15126: $chgtext .= '</ul>';
1.100 raeburn 15127: if (ref($cancreate{$type}) eq 'ARRAY') {
15128: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15129: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15130: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 15131: $chgtext .= '<span class="LC_warning">'.
15132: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15133: '</span><br />';
15134: }
15135: }
15136: }
15137: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 15138: if (!@statuses) {
15139: $chgtext .= '<span class="LC_warning">'.
15140: &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.").
15141: '</span><br />';
1.303 raeburn 15142:
1.100 raeburn 15143: }
15144: }
15145: }
1.43 raeburn 15146: }
1.240 raeburn 15147: } elsif ($type eq 'shibenv') {
15148: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 15149: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 15150: } else {
15151: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15152: '<ul>';
15153: foreach my $field (@shibfields) {
15154: next if ($cancreate{$type}{$field} eq '');
15155: if ($field eq 'inststatus') {
15156: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15157: } else {
15158: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15159: }
15160: }
15161: $chgtext .= '</ul>';
1.303 raeburn 15162: }
1.93 raeburn 15163: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15164: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15165: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15166: if (@{$cancreate{'selfcreate'}} > 0) {
15167: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15168: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15169: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 15170: $chgtext .= '<br />'.
15171: '<span class="LC_warning">'.
15172: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15173: '</span>';
15174: }
1.303 raeburn 15175: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15176: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15177: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15178: } else {
15179: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15180: }
15181: $chgtext .= '<ul>';
15182: foreach my $case (@{$cancreate{$type}}) {
15183: if ($case eq 'default') {
15184: $chgtext .= '<li>'.$othertitle.'</li>';
15185: } else {
1.303 raeburn 15186: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15187: }
15188: }
1.100 raeburn 15189: $chgtext .= '</ul>';
15190: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 15191: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 15192: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15193: '</span>';
1.100 raeburn 15194: }
15195: }
15196: } else {
15197: if (@{$cancreate{$type}} == 0) {
15198: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15199: } else {
15200: $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 15201: }
15202: }
1.303 raeburn 15203: $chgtext .= '<br />';
1.93 raeburn 15204: }
1.236 raeburn 15205: } elsif ($type eq 'selfcreateprocessing') {
15206: my %choices = &Apache::lonlocal::texthash (
15207: automatic => 'Automatic approval',
15208: approval => 'Queued for approval',
15209: );
1.305 raeburn 15210: if (@types) {
15211: if (@statuses) {
1.303 raeburn 15212: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 15213: '<ul>';
1.305 raeburn 15214: foreach my $status (@statuses) {
15215: if ($status eq 'default') {
15216: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15217: } else {
1.305 raeburn 15218: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15219: }
15220: }
15221: $chgtext .= '</ul>';
15222: }
15223: } else {
15224: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15225: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15226: }
15227: } elsif ($type eq 'emailverified') {
15228: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 15229: all => 'Same as e-mail',
15230: first => 'Omit @domain',
15231: free => 'Free to choose',
1.303 raeburn 15232: );
1.305 raeburn 15233: if (@types) {
15234: if (@statuses) {
1.303 raeburn 15235: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15236: '<ul>';
1.305 raeburn 15237: foreach my $status (@statuses) {
1.303 raeburn 15238: if ($type eq 'default') {
1.305 raeburn 15239: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15240: } else {
1.305 raeburn 15241: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15242: }
15243: }
15244: $chgtext .= '</ul>';
15245: }
15246: } else {
1.305 raeburn 15247: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 15248: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 15249: }
1.305 raeburn 15250: } elsif ($type eq 'emailoptions') {
15251: my %options = &Apache::lonlocal::texthash (
15252: any => 'Any e-mail',
15253: inst => 'Institutional only',
15254: noninst => 'Non-institutional only',
15255: custom => 'Custom restrictions',
15256: );
15257: if (@types) {
15258: if (@statuses) {
15259: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15260: '<ul>';
15261: foreach my $status (@statuses) {
15262: if ($type eq 'default') {
15263: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15264: } else {
15265: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 15266: }
15267: }
1.305 raeburn 15268: $chgtext .= '</ul>';
15269: }
15270: } else {
15271: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15272: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15273: } else {
15274: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15275: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 15276: }
1.305 raeburn 15277: }
15278: } elsif ($type eq 'emaildomain') {
15279: my $output;
15280: if (@statuses) {
15281: foreach my $type (@statuses) {
15282: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15283: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15284: if ($type eq 'default') {
15285: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15286: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15287: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15288: } else {
15289: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15290: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15291: }
1.303 raeburn 15292: } else {
1.305 raeburn 15293: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15294: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15295: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15296: } else {
15297: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15298: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15299: }
1.303 raeburn 15300: }
1.305 raeburn 15301: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15302: if ($type eq 'default') {
15303: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15304: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15305: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15306: } else {
15307: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15308: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15309: }
1.303 raeburn 15310: } else {
1.305 raeburn 15311: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15312: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15313: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15314: } else {
15315: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15316: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15317: }
1.303 raeburn 15318: }
15319: }
15320: }
15321: }
1.305 raeburn 15322: }
15323: if ($output ne '') {
15324: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15325: '<ul>'.$output.'</ul>';
1.236 raeburn 15326: }
1.165 raeburn 15327: } elsif ($type eq 'captcha') {
1.224 raeburn 15328: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 15329: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15330: } else {
15331: my %captchas = &captcha_phrases();
1.224 raeburn 15332: if ($captchas{$savecaptcha{$type}}) {
15333: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 15334: } else {
1.210 raeburn 15335: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 15336: }
15337: }
15338: } elsif ($type eq 'recaptchakeys') {
15339: my ($privkey,$pubkey);
1.224 raeburn 15340: if (ref($savecaptcha{$type}) eq 'HASH') {
15341: $pubkey = $savecaptcha{$type}{'public'};
15342: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 15343: }
15344: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15345: if (!$pubkey) {
15346: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15347: } else {
15348: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15349: }
15350: if (!$privkey) {
15351: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15352: } else {
15353: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15354: }
15355: $chgtext .= '</ul>';
1.269 raeburn 15356: } elsif ($type eq 'recaptchaversion') {
15357: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 15358: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 15359: }
1.224 raeburn 15360: } elsif ($type eq 'emailusername') {
15361: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 15362: if (@statuses) {
15363: foreach my $type (@statuses) {
1.228 raeburn 15364: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15365: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 15366: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 15367: '<ul>';
15368: foreach my $field (@{$infofields}) {
15369: if ($cancreate{'emailusername'}{$type}{$field}) {
15370: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15371: }
15372: }
1.245 raeburn 15373: $chgtext .= '</ul>';
15374: } else {
1.303 raeburn 15375: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 15376: }
15377: } else {
1.303 raeburn 15378: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 15379: }
15380: }
15381: }
15382: }
15383: } elsif ($type eq 'notify') {
1.303 raeburn 15384: my $numapprove = 0;
1.224 raeburn 15385: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15386: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15387: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 15388: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15389: $numapprove ++;
1.224 raeburn 15390: }
15391: }
1.43 raeburn 15392: }
1.303 raeburn 15393: unless ($numapprove) {
15394: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15395: }
1.34 raeburn 15396: }
1.224 raeburn 15397: if ($chgtext) {
15398: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15399: }
15400: }
15401: }
1.305 raeburn 15402: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15403: my ($emailrules,$emailruleorder) =
15404: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 15405: foreach my $type (@{$changes{'email_rule'}}) {
15406: if (ref($email_rule{$type}) eq 'ARRAY') {
15407: my $chgtext = '<ul>';
15408: foreach my $rule (@{$email_rule{$type}}) {
15409: if (ref($emailrules->{$rule}) eq 'HASH') {
15410: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15411: }
15412: }
15413: $chgtext .= '</ul>';
1.310 raeburn 15414: my $typename;
1.305 raeburn 15415: if (@types) {
15416: if ($type eq 'default') {
15417: $typename = $othertitle;
15418: } else {
15419: $typename = $usertypes{$type};
15420: }
15421: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15422: }
15423: if (@{$email_rule{$type}} > 0) {
15424: $resulttext .= '<li>'.
15425: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15426: $usertypes{$type}).
15427: $chgtext.
15428: '</li>';
15429: } else {
15430: $resulttext .= '<li>'.
1.310 raeburn 15431: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305 raeburn 15432: '</li>'.
1.310 raeburn 15433: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 15434: }
1.43 raeburn 15435: }
15436: }
1.305 raeburn 15437: }
15438: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15439: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15440: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15441: my $chgtext = '<ul>';
15442: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15443: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15444: }
15445: $chgtext .= '</ul>';
15446: $resulttext .= '<li>'.
15447: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15448: $chgtext.
15449: '</li>';
15450: } else {
15451: $resulttext .= '<li>'.
15452: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15453: '</li>';
15454: }
1.43 raeburn 15455: }
15456: }
1.224 raeburn 15457: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15458: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15459: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15460: foreach my $type (@{$changes{'selfcreate'}}) {
15461: my $typename = $type;
1.303 raeburn 15462: if (keys(%usertypes) > 0) {
15463: if ($usertypes{$type} ne '') {
15464: $typename = $usertypes{$type};
1.224 raeburn 15465: }
15466: }
15467: my @modifiable;
15468: $resulttext .= '<li>'.
15469: &mt('Self-creation of account by users with status: [_1]',
15470: '<span class="LC_cusr_emph">'.$typename.'</span>').
15471: ' - '.&mt('modifiable fields (if institutional data blank): ');
15472: foreach my $field (@fields) {
15473: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15474: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 15475: }
15476: }
1.224 raeburn 15477: if (@modifiable > 0) {
15478: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15479: } else {
1.224 raeburn 15480: $resulttext .= &mt('none');
1.43 raeburn 15481: }
1.224 raeburn 15482: $resulttext .= '</li>';
1.28 raeburn 15483: }
1.224 raeburn 15484: $resulttext .= '</ul></li>';
1.28 raeburn 15485: }
1.27 raeburn 15486: $resulttext .= '</ul>';
1.305 raeburn 15487: my $cachetime = 24*60*60;
15488: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15489: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15490: if (ref($lastactref) eq 'HASH') {
15491: $lastactref->{'domdefaults'} = 1;
15492: }
1.27 raeburn 15493: } else {
1.224 raeburn 15494: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15495: }
15496: } else {
15497: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15498: &mt('An error occurred: [_1]',$putresult).'</span>';
15499: }
1.43 raeburn 15500: if ($warningmsg ne '') {
15501: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15502: }
1.23 raeburn 15503: return $resulttext;
15504: }
15505:
1.165 raeburn 15506: sub process_captcha {
15507: my ($container,$changes,$newsettings,$current) = @_;
15508: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
15509: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
15510: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
15511: $newsettings->{'captcha'} = 'original';
15512: }
15513: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 15514: if ($container eq 'cancreate') {
1.169 raeburn 15515: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15516: push(@{$changes->{'cancreate'}},'captcha');
15517: } elsif (!defined($changes->{'cancreate'})) {
15518: $changes->{'cancreate'} = ['captcha'];
15519: }
15520: } else {
15521: $changes->{'captcha'} = 1;
1.165 raeburn 15522: }
15523: }
1.269 raeburn 15524: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 15525: if ($newsettings->{'captcha'} eq 'recaptcha') {
15526: $newpub = $env{'form.'.$container.'_recaptchapub'};
15527: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 15528: $newpub =~ s/[^\w\-]//g;
15529: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 15530: $newsettings->{'recaptchakeys'} = {
15531: public => $newpub,
15532: private => $newpriv,
15533: };
1.269 raeburn 15534: $newversion = $env{'form.'.$container.'_recaptchaversion'};
15535: $newversion =~ s/\D//g;
15536: if ($newversion ne '2') {
15537: $newversion = 1;
15538: }
15539: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 15540: }
15541: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
15542: $currpub = $current->{'recaptchakeys'}{'public'};
15543: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 15544: unless ($newsettings->{'captcha'} eq 'recaptcha') {
15545: $newsettings->{'recaptchakeys'} = {
15546: public => '',
15547: private => '',
15548: }
15549: }
1.165 raeburn 15550: }
1.269 raeburn 15551: if ($current->{'captcha'} eq 'recaptcha') {
15552: $currversion = $current->{'recaptchaversion'};
15553: if ($currversion ne '2') {
15554: $currversion = 1;
15555: }
15556: }
15557: if ($currversion ne $newversion) {
15558: if ($container eq 'cancreate') {
15559: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15560: push(@{$changes->{'cancreate'}},'recaptchaversion');
15561: } elsif (!defined($changes->{'cancreate'})) {
15562: $changes->{'cancreate'} = ['recaptchaversion'];
15563: }
15564: } else {
15565: $changes->{'recaptchaversion'} = 1;
15566: }
15567: }
1.165 raeburn 15568: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 15569: if ($container eq 'cancreate') {
15570: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
15571: push(@{$changes->{'cancreate'}},'recaptchakeys');
15572: } elsif (!defined($changes->{'cancreate'})) {
15573: $changes->{'cancreate'} = ['recaptchakeys'];
15574: }
15575: } else {
1.210 raeburn 15576: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 15577: }
15578: }
15579: return;
15580: }
15581:
1.33 raeburn 15582: sub modify_usermodification {
15583: my ($dom,%domconfig) = @_;
1.224 raeburn 15584: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 15585: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15586: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 15587: if ($key eq 'selfcreate') {
15588: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
15589: } else {
15590: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
15591: }
1.33 raeburn 15592: }
15593: }
1.224 raeburn 15594: my @contexts = ('author','course');
1.33 raeburn 15595: my %context_title = (
15596: author => 'In author context',
15597: course => 'In course context',
15598: );
15599: my @fields = ('lastname','firstname','middlename','generation',
15600: 'permanentemail','id');
15601: my %roles = (
15602: author => ['ca','aa'],
15603: course => ['st','ep','ta','in','cr'],
15604: );
15605: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15606: foreach my $context (@contexts) {
15607: foreach my $role (@{$roles{$context}}) {
15608: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
15609: foreach my $item (@fields) {
15610: if (grep(/^\Q$item\E$/,@modifiable)) {
15611: $modifyhash{$context}{$role}{$item} = 1;
15612: } else {
15613: $modifyhash{$context}{$role}{$item} = 0;
15614: }
15615: }
15616: }
15617: if (ref($curr_usermodification{$context}) eq 'HASH') {
15618: foreach my $role (@{$roles{$context}}) {
15619: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
15620: foreach my $field (@fields) {
15621: if ($modifyhash{$context}{$role}{$field} ne
15622: $curr_usermodification{$context}{$role}{$field}) {
15623: push(@{$changes{$context}},$role);
15624: last;
15625: }
15626: }
15627: }
15628: }
15629: } else {
15630: foreach my $context (@contexts) {
15631: foreach my $role (@{$roles{$context}}) {
15632: push(@{$changes{$context}},$role);
15633: }
15634: }
15635: }
15636: }
15637: my %usermodification_hash = (
15638: usermodification => \%modifyhash,
15639: );
15640: my $putresult = &Apache::lonnet::put_dom('configuration',
15641: \%usermodification_hash,$dom);
15642: if ($putresult eq 'ok') {
15643: if (keys(%changes) > 0) {
15644: $resulttext = &mt('Changes made: ').'<ul>';
15645: foreach my $context (@contexts) {
15646: if (ref($changes{$context}) eq 'ARRAY') {
15647: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
15648: if (ref($changes{$context}) eq 'ARRAY') {
15649: foreach my $role (@{$changes{$context}}) {
15650: my $rolename;
1.224 raeburn 15651: if ($role eq 'cr') {
15652: $rolename = &mt('Custom');
1.33 raeburn 15653: } else {
1.224 raeburn 15654: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 15655: }
15656: my @modifiable;
1.224 raeburn 15657: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 15658: foreach my $field (@fields) {
15659: if ($modifyhash{$context}{$role}{$field}) {
15660: push(@modifiable,$fieldtitles{$field});
15661: }
15662: }
15663: if (@modifiable > 0) {
15664: $resulttext .= join(', ',@modifiable);
15665: } else {
15666: $resulttext .= &mt('none');
15667: }
15668: $resulttext .= '</li>';
15669: }
15670: $resulttext .= '</ul></li>';
15671: }
15672: }
15673: }
15674: $resulttext .= '</ul>';
15675: } else {
15676: $resulttext = &mt('No changes made to user modification settings');
15677: }
15678: } else {
15679: $resulttext = '<span class="LC_error">'.
15680: &mt('An error occurred: [_1]',$putresult).'</span>';
15681: }
15682: return $resulttext;
15683: }
15684:
1.43 raeburn 15685: sub modify_defaults {
1.212 raeburn 15686: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 15687: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 15688: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 15689: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 15690: 'portal_def');
1.325 raeburn 15691: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 15692: foreach my $item (@items) {
15693: $newvalues{$item} = $env{'form.'.$item};
15694: if ($item eq 'auth_def') {
15695: if ($newvalues{$item} ne '') {
15696: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
15697: push(@errors,$item);
15698: }
15699: }
15700: } elsif ($item eq 'lang_def') {
15701: if ($newvalues{$item} ne '') {
15702: if ($newvalues{$item} =~ /^(\w+)/) {
15703: my $langcode = $1;
1.103 raeburn 15704: if ($langcode ne 'x_chef') {
15705: if (code2language($langcode) eq '') {
15706: push(@errors,$item);
15707: }
1.43 raeburn 15708: }
15709: } else {
15710: push(@errors,$item);
15711: }
15712: }
1.54 raeburn 15713: } elsif ($item eq 'timezone_def') {
15714: if ($newvalues{$item} ne '') {
1.62 raeburn 15715: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 15716: push(@errors,$item);
15717: }
15718: }
1.68 raeburn 15719: } elsif ($item eq 'datelocale_def') {
15720: if ($newvalues{$item} ne '') {
15721: my @datelocale_ids = DateTime::Locale->ids();
15722: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
15723: push(@errors,$item);
15724: }
15725: }
1.141 raeburn 15726: } elsif ($item eq 'portal_def') {
15727: if ($newvalues{$item} ne '') {
15728: 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])\/?$/) {
15729: push(@errors,$item);
15730: }
15731: }
1.43 raeburn 15732: }
15733: if (grep(/^\Q$item\E$/,@errors)) {
15734: $newvalues{$item} = $domdefaults{$item};
15735: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
15736: $changes{$item} = 1;
15737: }
1.72 raeburn 15738: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 15739: }
1.354 raeburn 15740: my %staticdefaults = (
15741: 'intauth_cost' => 10,
15742: 'intauth_check' => 0,
15743: 'intauth_switch' => 0,
15744: );
15745: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
15746: if (exists($domdefaults{$item})) {
15747: $newvalues{$item} = $domdefaults{$item};
15748: } else {
15749: $newvalues{$item} = $staticdefaults{$item};
15750: }
15751: }
1.43 raeburn 15752: my %defaults_hash = (
1.72 raeburn 15753: defaults => \%newvalues,
15754: );
1.43 raeburn 15755: my $title = &defaults_titles();
1.236 raeburn 15756:
15757: my $currinststatus;
15758: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15759: $currinststatus = $domconfig{'inststatus'};
15760: } else {
15761: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15762: $currinststatus = {
15763: inststatustypes => $usertypes,
15764: inststatusorder => $types,
15765: inststatusguest => [],
15766: };
15767: }
15768: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
15769: my @allpos;
15770: my %alltypes;
1.305 raeburn 15771: my @inststatusguest;
15772: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
15773: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
15774: unless (grep(/^\Q$type\E$/,@todelete)) {
15775: push(@inststatusguest,$type);
15776: }
15777: }
15778: }
15779: my ($currtitles,$currorder);
1.236 raeburn 15780: if (ref($currinststatus) eq 'HASH') {
15781: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
15782: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
15783: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
15784: if ($currinststatus->{inststatustypes}->{$type} ne '') {
15785: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
15786: }
15787: }
15788: unless (grep(/^\Q$type\E$/,@todelete)) {
15789: my $position = $env{'form.inststatus_pos_'.$type};
15790: $position =~ s/\D+//g;
15791: $allpos[$position] = $type;
15792: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
15793: $alltypes{$type} =~ s/`//g;
15794: }
15795: }
15796: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
15797: $currtitles =~ s/,$//;
15798: }
15799: }
15800: if ($env{'form.addinststatus'}) {
15801: my $newtype = $env{'form.addinststatus'};
15802: $newtype =~ s/\W//g;
15803: unless (exists($alltypes{$newtype})) {
15804: $alltypes{$newtype} = $env{'form.addinststatus_title'};
15805: $alltypes{$newtype} =~ s/`//g;
15806: my $position = $env{'form.addinststatus_pos'};
15807: $position =~ s/\D+//g;
15808: if ($position ne '') {
15809: $allpos[$position] = $newtype;
15810: }
15811: }
15812: }
1.305 raeburn 15813: my @orderedstatus;
1.236 raeburn 15814: foreach my $type (@allpos) {
15815: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
15816: push(@orderedstatus,$type);
15817: }
15818: }
15819: foreach my $type (keys(%alltypes)) {
15820: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
15821: delete($alltypes{$type});
15822: }
15823: }
15824: $defaults_hash{'inststatus'} = {
15825: inststatustypes => \%alltypes,
15826: inststatusorder => \@orderedstatus,
1.305 raeburn 15827: inststatusguest => \@inststatusguest,
1.236 raeburn 15828: };
15829: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
15830: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
15831: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
15832: }
15833: }
15834: if ($currorder ne join(',',@orderedstatus)) {
15835: $changes{'inststatus'}{'inststatusorder'} = 1;
15836: }
15837: my $newtitles;
15838: foreach my $item (@orderedstatus) {
15839: $newtitles .= $alltypes{$item}.',';
15840: }
15841: $newtitles =~ s/,$//;
15842: if ($currtitles ne $newtitles) {
15843: $changes{'inststatus'}{'inststatustypes'} = 1;
15844: }
1.43 raeburn 15845: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
15846: $dom);
15847: if ($putresult eq 'ok') {
15848: if (keys(%changes) > 0) {
15849: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 15850: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 15851: 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";
15852: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 15853: if ($item eq 'inststatus') {
15854: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 15855: if (@orderedstatus) {
1.236 raeburn 15856: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
15857: foreach my $type (@orderedstatus) {
15858: $resulttext .= $alltypes{$type}.', ';
15859: }
15860: $resulttext =~ s/, $//;
15861: $resulttext .= '</li>';
1.305 raeburn 15862: } else {
15863: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 15864: }
15865: }
15866: } else {
15867: my $value = $env{'form.'.$item};
15868: if ($value eq '') {
15869: $value = &mt('none');
15870: } elsif ($item eq 'auth_def') {
15871: my %authnames = &authtype_names();
15872: my %shortauth = (
15873: internal => 'int',
15874: krb4 => 'krb4',
15875: krb5 => 'krb5',
15876: localauth => 'loc',
1.325 raeburn 15877: lti => 'lti',
1.236 raeburn 15878: );
15879: $value = $authnames{$shortauth{$value}};
15880: }
15881: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
15882: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 15883: }
15884: }
15885: $resulttext .= '</ul>';
15886: $mailmsgtext .= "\n";
15887: my $cachetime = 24*60*60;
1.72 raeburn 15888: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 15889: if (ref($lastactref) eq 'HASH') {
15890: $lastactref->{'domdefaults'} = 1;
15891: }
1.68 raeburn 15892: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 15893: my $notify = 1;
15894: if (ref($domconfig{'contacts'}) eq 'HASH') {
15895: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
15896: $notify = 0;
15897: }
15898: }
15899: if ($notify) {
15900: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
15901: "LON-CAPA Domain Settings Change - $dom",
15902: $mailmsgtext);
15903: }
1.54 raeburn 15904: }
1.43 raeburn 15905: } else {
1.54 raeburn 15906: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 15907: }
15908: } else {
15909: $resulttext = '<span class="LC_error">'.
15910: &mt('An error occurred: [_1]',$putresult).'</span>';
15911: }
15912: if (@errors > 0) {
15913: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
15914: foreach my $item (@errors) {
15915: $resulttext .= ' "'.$title->{$item}.'",';
15916: }
15917: $resulttext =~ s/,$//;
15918: }
15919: return $resulttext;
15920: }
15921:
1.46 raeburn 15922: sub modify_scantron {
1.205 raeburn 15923: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 15924: my ($resulttext,%confhash,%changes,$errors);
15925: my $custom = 'custom.tab';
15926: my $default = 'default.tab';
15927: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 15928: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 15929: &config_check($dom,$confname,$servadm);
15930: if ($env{'form.scantronformat.filename'} ne '') {
15931: my $error;
15932: if ($configuserok eq 'ok') {
15933: if ($switchserver) {
1.130 raeburn 15934: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 15935: } else {
15936: if ($author_ok eq 'ok') {
15937: my ($result,$scantronurl) =
15938: &publishlogo($r,'upload','scantronformat',$dom,
15939: $confname,'scantron','','',$custom);
15940: if ($result eq 'ok') {
15941: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 15942: $changes{'scantronformat'} = 1;
1.46 raeburn 15943: } else {
15944: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
15945: }
15946: } else {
15947: $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);
15948: }
15949: }
15950: } else {
15951: $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);
15952: }
15953: if ($error) {
15954: &Apache::lonnet::logthis($error);
15955: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15956: }
15957: }
1.48 raeburn 15958: if (ref($domconfig{'scantron'}) eq 'HASH') {
15959: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
15960: if ($env{'form.scantronformat_del'}) {
15961: $confhash{'scantron'}{'scantronformat'} = '';
15962: $changes{'scantronformat'} = 1;
1.347 raeburn 15963: } else {
15964: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 15965: }
15966: }
15967: }
1.347 raeburn 15968: my @options = ('hdr','pad','rem');
1.346 raeburn 15969: my @fields = &scantroncsv_fields();
15970: my %titles = &scantronconfig_titles();
1.347 raeburn 15971: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 15972: my ($newdat,$currdat,%newcol,%currcol);
15973: if (grep(/^dat$/,@formats)) {
15974: $confhash{'scantron'}{config}{dat} = 1;
15975: $newdat = 1;
15976: } else {
15977: $newdat = 0;
15978: }
15979: if (grep(/^csv$/,@formats)) {
15980: my %bynum;
15981: foreach my $field (@fields) {
15982: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
15983: my $posscol = $1;
15984: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 15985: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 15986: $bynum{$posscol} = $field;
15987: $newcol{$field} = $posscol;
15988: }
15989: }
15990: }
1.347 raeburn 15991: if (keys(%newcol)) {
15992: foreach my $option (@options) {
15993: if ($env{'form.scantroncsv_'.$option}) {
15994: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
15995: }
15996: }
15997: }
1.346 raeburn 15998: }
15999: $currdat = 1;
16000: if (ref($domconfig{'scantron'}) eq 'HASH') {
16001: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 16002: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 16003: $currdat = 0;
16004: }
16005: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16006: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16007: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16008: }
1.346 raeburn 16009: }
16010: }
16011: }
16012: if ($currdat != $newdat) {
16013: $changes{'config'} = 1;
16014: } else {
16015: foreach my $field (@fields) {
16016: if ($currcol{$field} ne '') {
16017: if ($currcol{$field} ne $newcol{$field}) {
16018: $changes{'config'} = 1;
16019: last;
1.347 raeburn 16020: }
1.346 raeburn 16021: } elsif ($newcol{$field} ne '') {
16022: $changes{'config'} = 1;
16023: last;
16024: }
16025: }
16026: }
1.46 raeburn 16027: if (keys(%confhash) > 0) {
16028: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16029: $dom);
16030: if ($putresult eq 'ok') {
16031: if (keys(%changes) > 0) {
1.48 raeburn 16032: if (ref($confhash{'scantron'}) eq 'HASH') {
16033: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 16034: if ($changes{'scantronformat'}) {
16035: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16036: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16037: } else {
16038: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16039: }
16040: }
1.347 raeburn 16041: if ($changes{'config'}) {
1.346 raeburn 16042: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16043: if ($confhash{'scantron'}{'config'}{'dat'}) {
16044: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16045: }
16046: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16047: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16048: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16049: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16050: foreach my $field (@fields) {
16051: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16052: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16053: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16054: }
16055: }
16056: $resulttext .= '</ul></li>';
16057: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16058: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16059: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16060: foreach my $option (@options) {
16061: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16062: $resulttext .= '<li>'.$titles{$option}.'</li>';
16063: }
16064: }
16065: $resulttext .= '</ul></li>';
16066: }
1.346 raeburn 16067: }
16068: }
16069: }
16070: }
16071: } else {
16072: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16073: }
1.46 raeburn 16074: }
1.48 raeburn 16075: $resulttext .= '</ul>';
16076: } else {
1.130 raeburn 16077: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16078: }
16079: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16080: if (ref($lastactref) eq 'HASH') {
16081: $lastactref->{'domainconfig'} = 1;
16082: }
1.46 raeburn 16083: } else {
1.346 raeburn 16084: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16085: }
16086: } else {
16087: $resulttext = '<span class="LC_error">'.
16088: &mt('An error occurred: [_1]',$putresult).'</span>';
16089: }
16090: } else {
1.130 raeburn 16091: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 16092: }
16093: if ($errors) {
1.353 raeburn 16094: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16095: $errors.'</ul></p>';
1.46 raeburn 16096: }
16097: return $resulttext;
16098: }
16099:
1.48 raeburn 16100: sub modify_coursecategories {
1.239 raeburn 16101: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16102: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16103: $cathash);
1.48 raeburn 16104: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 16105: my @catitems = ('unauth','auth');
16106: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16107: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16108: $cathash = $domconfig{'coursecategories'}{'cats'};
16109: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16110: $changes{'togglecats'} = 1;
16111: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16112: }
16113: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16114: $changes{'categorize'} = 1;
16115: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16116: }
1.120 raeburn 16117: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16118: $changes{'togglecatscomm'} = 1;
16119: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16120: }
16121: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16122: $changes{'categorizecomm'} = 1;
16123: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 16124:
16125: }
16126: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
16127: $changes{'togglecatsplace'} = 1;
16128: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
16129: }
16130: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
16131: $changes{'categorizeplace'} = 1;
16132: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 16133: }
1.238 raeburn 16134: foreach my $item (@catitems) {
16135: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16136: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16137: $changes{$item} = 1;
16138: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16139: }
16140: }
16141: }
1.57 raeburn 16142: } else {
16143: $changes{'togglecats'} = 1;
16144: $changes{'categorize'} = 1;
1.124 raeburn 16145: $changes{'togglecatscomm'} = 1;
16146: $changes{'categorizecomm'} = 1;
1.272 raeburn 16147: $changes{'togglecatsplace'} = 1;
16148: $changes{'categorizeplace'} = 1;
1.87 raeburn 16149: $domconfig{'coursecategories'} = {
16150: togglecats => $env{'form.togglecats'},
16151: categorize => $env{'form.categorize'},
1.124 raeburn 16152: togglecatscomm => $env{'form.togglecatscomm'},
16153: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 16154: togglecatsplace => $env{'form.togglecatsplace'},
16155: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 16156: };
1.238 raeburn 16157: foreach my $item (@catitems) {
16158: if ($env{'form.coursecat_'.$item} ne 'std') {
16159: $changes{$item} = 1;
16160: }
16161: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16162: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16163: }
16164: }
1.57 raeburn 16165: }
16166: if (ref($cathash) eq 'HASH') {
16167: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16168: push (@deletecategory,'instcode::0');
16169: }
1.120 raeburn 16170: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16171: push(@deletecategory,'communities::0');
16172: }
1.272 raeburn 16173: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
16174: push(@deletecategory,'placement::0');
16175: }
1.48 raeburn 16176: }
1.57 raeburn 16177: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16178: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16179: if (@deletecategory > 0) {
16180: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16181: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16182: foreach my $item (@deletecategory) {
1.57 raeburn 16183: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16184: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16185: $deletions{$item} = 1;
1.57 raeburn 16186: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16187: }
16188: }
16189: }
1.57 raeburn 16190: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16191: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16192: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16193: $reorderings{$item} = 1;
1.57 raeburn 16194: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16195: }
16196: if ($env{'form.addcategory_name_'.$item} ne '') {
16197: my $newcat = $env{'form.addcategory_name_'.$item};
16198: my $newdepth = $depth+1;
16199: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16200: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16201: $adds{$newitem} = 1;
16202: }
16203: if ($env{'form.subcat_'.$item} ne '') {
16204: my $newcat = $env{'form.subcat_'.$item};
16205: my $newdepth = $depth+1;
16206: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16207: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16208: $adds{$newitem} = 1;
16209: }
16210: }
16211: }
16212: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16213: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16214: my $newitem = 'instcode::0';
1.57 raeburn 16215: if ($cathash->{$newitem} eq '') {
16216: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16217: $adds{$newitem} = 1;
16218: }
16219: } else {
16220: my $newitem = 'instcode::0';
1.57 raeburn 16221: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16222: $adds{$newitem} = 1;
16223: }
16224: }
1.120 raeburn 16225: if ($env{'form.communities'} eq '1') {
16226: if (ref($cathash) eq 'HASH') {
16227: my $newitem = 'communities::0';
16228: if ($cathash->{$newitem} eq '') {
16229: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16230: $adds{$newitem} = 1;
16231: }
16232: } else {
16233: my $newitem = 'communities::0';
16234: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16235: $adds{$newitem} = 1;
16236: }
16237: }
1.272 raeburn 16238: if ($env{'form.placement'} eq '1') {
16239: if (ref($cathash) eq 'HASH') {
16240: my $newitem = 'placement::0';
16241: if ($cathash->{$newitem} eq '') {
16242: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16243: $adds{$newitem} = 1;
16244: }
16245: } else {
16246: my $newitem = 'placement::0';
16247: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16248: $adds{$newitem} = 1;
16249: }
16250: }
1.48 raeburn 16251: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16252: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 16253: ($env{'form.addcategory_name'} ne 'communities') &&
16254: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 16255: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16256: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16257: $adds{$newitem} = 1;
16258: }
1.48 raeburn 16259: }
1.57 raeburn 16260: my $putresult;
1.48 raeburn 16261: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16262: if (keys(%deletions) > 0) {
16263: foreach my $key (keys(%deletions)) {
16264: if ($predelallitems{$key} ne '') {
16265: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16266: }
16267: }
16268: }
16269: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16270: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16271: if (ref($chkcats[0]) eq 'ARRAY') {
16272: my $depth = 0;
16273: my $chg = 0;
16274: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16275: my $name = $chkcats[0][$i];
16276: my $item;
16277: if ($name eq '') {
16278: $chg ++;
16279: } else {
16280: $item = &escape($name).'::0';
16281: if ($chg) {
1.57 raeburn 16282: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16283: }
16284: $depth ++;
1.57 raeburn 16285: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16286: $depth --;
16287: }
16288: }
16289: }
1.57 raeburn 16290: }
16291: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16292: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16293: if ($putresult eq 'ok') {
1.57 raeburn 16294: my %title = (
1.120 raeburn 16295: togglecats => 'Show/Hide a course in catalog',
16296: categorize => 'Assign a category to a course',
16297: togglecatscomm => 'Show/Hide a community in catalog',
16298: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16299: );
16300: my %level = (
1.120 raeburn 16301: dom => 'set in Domain ("Modify Course/Community")',
16302: crs => 'set in Course ("Course Configuration")',
16303: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 16304: none => 'No catalog',
16305: std => 'Standard catalog',
16306: domonly => 'Domain-only catalog',
16307: codesrch => 'Code search form',
1.57 raeburn 16308: );
1.48 raeburn 16309: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16310: if ($changes{'togglecats'}) {
16311: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16312: }
16313: if ($changes{'categorize'}) {
16314: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16315: }
1.120 raeburn 16316: if ($changes{'togglecatscomm'}) {
16317: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16318: }
16319: if ($changes{'categorizecomm'}) {
16320: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16321: }
1.238 raeburn 16322: if ($changes{'unauth'}) {
16323: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16324: }
16325: if ($changes{'auth'}) {
16326: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16327: }
1.57 raeburn 16328: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16329: my $cathash;
16330: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16331: $cathash = $domconfig{'coursecategories'}{'cats'};
16332: } else {
16333: $cathash = {};
16334: }
16335: my (@cats,@trails,%allitems);
16336: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16337: if (keys(%deletions) > 0) {
16338: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16339: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16340: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16341: }
16342: $resulttext .= '</ul></li>';
16343: }
16344: if (keys(%reorderings) > 0) {
16345: my %sort_by_trail;
16346: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16347: foreach my $key (keys(%reorderings)) {
16348: if ($allitems{$key} ne '') {
16349: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16350: }
1.48 raeburn 16351: }
1.57 raeburn 16352: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16353: $resulttext .= '<li>'.$trails[$trail].'</li>';
16354: }
16355: $resulttext .= '</ul></li>';
1.48 raeburn 16356: }
1.57 raeburn 16357: if (keys(%adds) > 0) {
16358: my %sort_by_trail;
16359: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16360: foreach my $key (keys(%adds)) {
16361: if ($allitems{$key} ne '') {
16362: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16363: }
16364: }
16365: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16366: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16367: }
1.57 raeburn 16368: $resulttext .= '</ul></li>';
1.48 raeburn 16369: }
16370: }
16371: $resulttext .= '</ul>';
1.239 raeburn 16372: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 16373: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16374: if ($changes{'auth'}) {
16375: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16376: }
16377: if ($changes{'unauth'}) {
16378: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16379: }
16380: my $cachetime = 24*60*60;
16381: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 16382: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 16383: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 16384: }
16385: }
1.48 raeburn 16386: } else {
16387: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16388: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16389: }
16390: } else {
1.120 raeburn 16391: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16392: }
16393: return $resulttext;
16394: }
16395:
1.69 raeburn 16396: sub modify_serverstatuses {
16397: my ($dom,%domconfig) = @_;
16398: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16399: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16400: %currserverstatus = %{$domconfig{'serverstatuses'}};
16401: }
16402: my @pages = &serverstatus_pages();
16403: foreach my $type (@pages) {
16404: $newserverstatus{$type}{'namedusers'} = '';
16405: $newserverstatus{$type}{'machines'} = '';
16406: if (defined($env{'form.'.$type.'_namedusers'})) {
16407: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16408: my @okusers;
16409: foreach my $user (@users) {
16410: my ($uname,$udom) = split(/:/,$user);
16411: if (($udom =~ /^$match_domain$/) &&
16412: (&Apache::lonnet::domain($udom)) &&
16413: ($uname =~ /^$match_username$/)) {
16414: if (!grep(/^\Q$user\E/,@okusers)) {
16415: push(@okusers,$user);
16416: }
16417: }
16418: }
16419: if (@okusers > 0) {
16420: @okusers = sort(@okusers);
16421: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16422: }
16423: }
16424: if (defined($env{'form.'.$type.'_machines'})) {
16425: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16426: my @okmachines;
16427: foreach my $ip (@machines) {
16428: my @parts = split(/\./,$ip);
16429: next if (@parts < 4);
16430: my $badip = 0;
16431: for (my $i=0; $i<4; $i++) {
16432: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16433: $badip = 1;
16434: last;
16435: }
16436: }
16437: if (!$badip) {
16438: push(@okmachines,$ip);
16439: }
16440: }
16441: @okmachines = sort(@okmachines);
16442: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16443: }
16444: }
16445: my %serverstatushash = (
16446: serverstatuses => \%newserverstatus,
16447: );
16448: foreach my $type (@pages) {
1.83 raeburn 16449: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16450: my (@current,@new);
1.83 raeburn 16451: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16452: if ($currserverstatus{$type}{$setting} ne '') {
16453: @current = split(/,/,$currserverstatus{$type}{$setting});
16454: }
16455: }
16456: if ($newserverstatus{$type}{$setting} ne '') {
16457: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16458: }
16459: if (@current > 0) {
16460: if (@new > 0) {
16461: foreach my $item (@current) {
16462: if (!grep(/^\Q$item\E$/,@new)) {
16463: $changes{$type}{$setting} = 1;
1.82 raeburn 16464: last;
16465: }
16466: }
1.84 raeburn 16467: foreach my $item (@new) {
16468: if (!grep(/^\Q$item\E$/,@current)) {
16469: $changes{$type}{$setting} = 1;
16470: last;
1.82 raeburn 16471: }
16472: }
16473: } else {
1.83 raeburn 16474: $changes{$type}{$setting} = 1;
1.69 raeburn 16475: }
1.83 raeburn 16476: } elsif (@new > 0) {
16477: $changes{$type}{$setting} = 1;
1.69 raeburn 16478: }
16479: }
16480: }
16481: if (keys(%changes) > 0) {
1.81 raeburn 16482: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16483: my $putresult = &Apache::lonnet::put_dom('configuration',
16484: \%serverstatushash,$dom);
16485: if ($putresult eq 'ok') {
16486: $resulttext .= &mt('Changes made:').'<ul>';
16487: foreach my $type (@pages) {
1.84 raeburn 16488: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16489: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16490: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16491: if ($newserverstatus{$type}{'namedusers'} eq '') {
16492: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16493: } else {
16494: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16495: }
1.84 raeburn 16496: }
16497: if ($changes{$type}{'machines'}) {
1.69 raeburn 16498: if ($newserverstatus{$type}{'machines'} eq '') {
16499: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16500: } else {
16501: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16502: }
16503:
16504: }
16505: $resulttext .= '</ul></li>';
16506: }
16507: }
16508: $resulttext .= '</ul>';
16509: } else {
16510: $resulttext = '<span class="LC_error">'.
16511: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
16512:
16513: }
16514: } else {
16515: $resulttext = &mt('No changes made to access to server status pages');
16516: }
16517: return $resulttext;
16518: }
16519:
1.118 jms 16520: sub modify_helpsettings {
1.285 raeburn 16521: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 16522: my ($resulttext,$errors,%changes,%helphash);
16523: my %defaultchecked = ('submitbugs' => 'on');
16524: my @offon = ('off','on');
1.118 jms 16525: my @toggles = ('submitbugs');
1.285 raeburn 16526: my %current = ('submitbugs' => '',
16527: 'adhoc' => {},
16528: );
1.118 jms 16529: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 16530: %current = %{$domconfig{'helpsettings'}};
16531: }
1.285 raeburn 16532: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 16533: foreach my $item (@toggles) {
16534: if ($defaultchecked{$item} eq 'on') {
16535: if ($current{$item} eq '') {
16536: if ($env{'form.'.$item} eq '0') {
16537: $changes{$item} = 1;
16538: }
16539: } elsif ($current{$item} ne $env{'form.'.$item}) {
16540: $changes{$item} = 1;
16541: }
16542: } elsif ($defaultchecked{$item} eq 'off') {
16543: if ($current{$item} eq '') {
16544: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 16545: $changes{$item} = 1;
16546: }
1.282 raeburn 16547: } elsif ($current{$item} ne $env{'form.'.$item}) {
16548: $changes{$item} = 1;
16549: }
16550: }
16551: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
16552: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
16553: }
16554: }
1.285 raeburn 16555: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 16556: my $confname = $dom.'-domainconfig';
16557: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 16558: my (@allpos,%newsettings,%changedprivs,$newrole);
16559: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 16560: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 16561: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 16562: my %lt = &Apache::lonlocal::texthash(
16563: s => 'system',
16564: d => 'domain',
16565: order => 'Display order',
16566: access => 'Role usage',
1.291 raeburn 16567: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 16568: dh => 'All with domain helpdesk role',
16569: da => 'All with domain helpdesk assistant role',
1.285 raeburn 16570: none => 'None',
16571: status => 'Determined based on institutional status',
16572: inc => 'Include all, but exclude specific personnel',
16573: exc => 'Exclude all, but include specific personnel',
16574: );
16575: for (my $num=0; $num<=$maxnum; $num++) {
16576: my ($prefix,$identifier,$rolename,%curr);
16577: if ($num == $maxnum) {
16578: next unless ($env{'form.newcusthelp'} == $maxnum);
16579: $identifier = 'custhelp'.$num;
16580: $prefix = 'helproles_'.$num;
16581: $rolename = $env{'form.custhelpname'.$num};
16582: $rolename=~s/[^A-Za-z0-9]//gs;
16583: next if ($rolename eq '');
16584: next if (exists($existing{'rolesdef_'.$rolename}));
16585: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16586: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16587: $newprivs{'c'},$confname,$dom);
16588: if ($result ne 'ok') {
16589: $errors .= '<li><span class="LC_error">'.
16590: &mt('An error occurred storing the new custom role: [_1]',
16591: $result).'</span></li>';
16592: next;
16593: } else {
16594: $changedprivs{$rolename} = \%newprivs;
16595: $newrole = $rolename;
16596: }
16597: } else {
16598: $prefix = 'helproles_'.$num;
16599: $rolename = $env{'form.'.$prefix};
16600: next if ($rolename eq '');
16601: next unless (exists($existing{'rolesdef_'.$rolename}));
16602: $identifier = 'custhelp'.$num;
16603: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
16604: my %currprivs;
1.289 raeburn 16605: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 16606: split(/\_/,$existing{'rolesdef_'.$rolename});
16607: foreach my $level ('c','d','s') {
16608: if ($newprivs{$level} ne $currprivs{$level}) {
16609: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
16610: $newprivs{'c'},$confname,$dom);
16611: if ($result ne 'ok') {
16612: $errors .= '<li><span class="LC_error">'.
16613: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
16614: $rolename,$result).'</span></li>';
16615: } else {
16616: $changedprivs{$rolename} = \%newprivs;
16617: }
16618: last;
16619: }
16620: }
16621: if (ref($current{'adhoc'}) eq 'HASH') {
16622: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16623: %curr = %{$current{'adhoc'}{$rolename}};
16624: }
16625: }
16626: }
16627: my $newpos = $env{'form.'.$prefix.'_pos'};
16628: $newpos =~ s/\D+//g;
16629: $allpos[$newpos] = $rolename;
16630: my $newdesc = $env{'form.'.$prefix.'_desc'};
16631: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
16632: if ($curr{'desc'}) {
16633: if ($curr{'desc'} ne $newdesc) {
16634: $changes{'customrole'}{$rolename}{'desc'} = 1;
16635: $newsettings{$rolename}{'desc'} = $newdesc;
16636: }
16637: } elsif ($newdesc ne '') {
16638: $changes{'customrole'}{$rolename}{'desc'} = 1;
16639: $newsettings{$rolename}{'desc'} = $newdesc;
16640: }
16641: my $access = $env{'form.'.$prefix.'_access'};
16642: if (grep(/^\Q$access\E$/,@accesstypes)) {
16643: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
16644: if ($access eq 'status') {
16645: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
16646: if (scalar(@statuses) == 0) {
1.289 raeburn 16647: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 16648: } else {
16649: my (@shownstatus,$numtypes);
16650: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16651: if (ref($types) eq 'ARRAY') {
16652: $numtypes = scalar(@{$types});
16653: foreach my $type (sort(@statuses)) {
16654: if ($type eq 'default') {
16655: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16656: } elsif (grep(/^\Q$type\E$/,@{$types})) {
16657: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
16658: push(@shownstatus,$usertypes->{$type});
16659: }
16660: }
16661: }
16662: if (grep(/^default$/,@statuses)) {
16663: push(@shownstatus,$othertitle);
16664: }
16665: if (scalar(@shownstatus) == 1+$numtypes) {
16666: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
16667: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
16668: } else {
16669: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
16670: if (ref($curr{'status'}) eq 'ARRAY') {
16671: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16672: if (@diffs) {
16673: $changes{'customrole'}{$rolename}{$access} = 1;
16674: }
16675: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16676: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 16677: }
1.166 raeburn 16678: }
16679: }
1.285 raeburn 16680: } elsif (($access eq 'inc') || ($access eq 'exc')) {
16681: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
16682: my @newspecstaff;
16683: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
16684: foreach my $person (sort(@personnel)) {
16685: if ($domhelpdesk{$person}) {
16686: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
16687: }
16688: }
16689: if (ref($curr{$access}) eq 'ARRAY') {
16690: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
16691: if (@diffs) {
16692: $changes{'customrole'}{$rolename}{$access} = 1;
16693: }
16694: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16695: $changes{'customrole'}{$rolename}{$access} = 1;
16696: }
16697: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
16698: my ($uname,$udom) = split(/:/,$person);
16699: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
16700: }
16701: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 16702: }
1.285 raeburn 16703: } else {
16704: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
16705: }
16706: unless ($curr{'access'} eq $access) {
16707: $changes{'customrole'}{$rolename}{'access'} = 1;
16708: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 16709: }
16710: }
1.285 raeburn 16711: if (@allpos > 0) {
16712: my $idx = 0;
16713: foreach my $rolename (@allpos) {
16714: if ($rolename ne '') {
16715: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
16716: if (ref($current{'adhoc'}) eq 'HASH') {
16717: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
16718: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
16719: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 16720: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 16721: }
16722: }
1.282 raeburn 16723: }
1.285 raeburn 16724: $idx ++;
1.166 raeburn 16725: }
16726: }
1.118 jms 16727: }
1.123 jms 16728: my $putresult;
16729: if (keys(%changes) > 0) {
1.166 raeburn 16730: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 16731: if ($putresult eq 'ok') {
1.285 raeburn 16732: if (ref($helphash{'helpsettings'}) eq 'HASH') {
16733: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
16734: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
16735: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
16736: }
16737: }
16738: my $cachetime = 24*60*60;
16739: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16740: if (ref($lastactref) eq 'HASH') {
16741: $lastactref->{'domdefaults'} = 1;
16742: }
16743: } else {
16744: $errors .= '<li><span class="LC_error">'.
16745: &mt('An error occurred storing the settings: [_1]',
16746: $putresult).'</span></li>';
16747: }
16748: }
16749: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
16750: $resulttext = &mt('Changes made:').'<ul>';
16751: my (%shownprivs,@levelorder);
16752: @levelorder = ('c','d','s');
16753: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 16754: foreach my $item (sort(keys(%changes))) {
16755: if ($item eq 'submitbugs') {
16756: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
16757: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
16758: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 16759: } elsif ($item eq 'customrole') {
16760: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 16761: my @keyorder = ('order','desc','access','status','exc','inc');
16762: my %keytext = &Apache::lonlocal::texthash(
16763: order => 'Order',
16764: desc => 'Role description',
16765: access => 'Role usage',
1.300 droeschl 16766: status => 'Allowed institutional types',
1.285 raeburn 16767: exc => 'Allowed personnel',
16768: inc => 'Disallowed personnel',
16769: );
1.282 raeburn 16770: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 16771: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
16772: if ($role eq $newrole) {
16773: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
16774: $role).'<ul>';
16775: } else {
16776: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16777: $role).'<ul>';
16778: }
16779: foreach my $key (@keyorder) {
16780: if ($changes{'customrole'}{$role}{$key}) {
16781: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
16782: $keytext{$key},$newsettings{$role}{$key}).
16783: '</li>';
16784: }
16785: }
16786: if (ref($changedprivs{$role}) eq 'HASH') {
16787: $shownprivs{$role} = 1;
16788: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
16789: foreach my $level (@levelorder) {
16790: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16791: next if ($item eq '');
16792: my ($priv) = split(/\&/,$item,2);
16793: if (&Apache::lonnet::plaintext($priv)) {
16794: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16795: unless ($level eq 'c') {
16796: $resulttext .= ' ('.$lt{$level}.')';
16797: }
16798: $resulttext .= '</li>';
16799: }
16800: }
16801: }
16802: $resulttext .= '</ul>';
16803: }
16804: $resulttext .= '</ul></li>';
16805: }
16806: }
16807: }
16808: }
16809: }
16810: }
16811: if (keys(%changedprivs)) {
16812: foreach my $role (sort(keys(%changedprivs))) {
16813: unless ($shownprivs{$role}) {
16814: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
16815: $role).'<ul>'.
16816: '<li>'.&mt('Privileges set to :').'<ul>';
16817: foreach my $level (@levelorder) {
16818: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
16819: next if ($item eq '');
16820: my ($priv) = split(/\&/,$item,2);
16821: if (&Apache::lonnet::plaintext($priv)) {
16822: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
16823: unless ($level eq 'c') {
16824: $resulttext .= ' ('.$lt{$level}.')';
16825: }
16826: $resulttext .= '</li>';
16827: }
1.282 raeburn 16828: }
16829: }
1.285 raeburn 16830: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 16831: }
16832: }
16833: }
1.285 raeburn 16834: $resulttext .= '</ul>';
16835: } else {
16836: $resulttext = &mt('No changes made to help settings');
1.118 jms 16837: }
16838: if ($errors) {
1.168 raeburn 16839: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 16840: $errors.'</ul>';
1.118 jms 16841: }
16842: return $resulttext;
16843: }
16844:
1.121 raeburn 16845: sub modify_coursedefaults {
1.212 raeburn 16846: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 16847: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 16848: my %defaultchecked = (
16849: 'canuse_pdfforms' => 'off',
16850: 'uselcmath' => 'on',
16851: 'usejsme' => 'on'
16852: );
16853: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 16854: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 16855: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
16856: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
16857: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 16858: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 16859: my %staticdefaults = (
16860: anonsurvey_threshold => 10,
16861: uploadquota => 500,
1.257 raeburn 16862: postsubmit => 60,
1.276 raeburn 16863: mysqltables => 172800,
1.198 raeburn 16864: );
1.314 raeburn 16865: my %texoptions = (
16866: MathJax => 'MathJax',
16867: mimetex => &mt('Convert to Images'),
16868: tth => &mt('TeX to HTML'),
16869: );
1.121 raeburn 16870: $defaultshash{'coursedefaults'} = {};
16871:
16872: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
16873: if ($domconfig{'coursedefaults'} eq '') {
16874: $domconfig{'coursedefaults'} = {};
16875: }
16876: }
16877:
16878: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
16879: foreach my $item (@toggles) {
16880: if ($defaultchecked{$item} eq 'on') {
16881: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16882: ($env{'form.'.$item} eq '0')) {
16883: $changes{$item} = 1;
1.192 raeburn 16884: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 16885: $changes{$item} = 1;
16886: }
16887: } elsif ($defaultchecked{$item} eq 'off') {
16888: if (($domconfig{'coursedefaults'}{$item} eq '') &&
16889: ($env{'form.'.$item} eq '1')) {
16890: $changes{$item} = 1;
16891: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
16892: $changes{$item} = 1;
16893: }
16894: }
16895: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
16896: }
1.198 raeburn 16897: foreach my $item (@numbers) {
16898: my ($currdef,$newdef);
1.208 raeburn 16899: $newdef = $env{'form.'.$item};
1.198 raeburn 16900: if ($item eq 'anonsurvey_threshold') {
16901: $currdef = $domconfig{'coursedefaults'}{$item};
16902: $newdef =~ s/\D//g;
16903: if ($newdef eq '' || $newdef < 1) {
16904: $newdef = 1;
16905: }
16906: $defaultshash{'coursedefaults'}{$item} = $newdef;
16907: } else {
1.276 raeburn 16908: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
16909: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
16910: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 16911: }
16912: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 16913: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 16914: }
16915: if ($currdef ne $newdef) {
16916: if ($item eq 'anonsurvey_threshold') {
16917: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
16918: $changes{$item} = 1;
16919: }
1.276 raeburn 16920: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 16921: my $setting = $1;
1.276 raeburn 16922: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
16923: $changes{$setting} = 1;
1.198 raeburn 16924: }
16925: }
1.139 raeburn 16926: }
16927: }
1.314 raeburn 16928: my $texengine;
16929: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
16930: $texengine = $env{'form.texengine'};
1.349 raeburn 16931: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
16932: if ($currdef eq '') {
16933: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 16934: $changes{'texengine'} = 1;
16935: }
1.349 raeburn 16936: } elsif ($currdef ne $texengine) {
1.314 raeburn 16937: $changes{'texengine'} = 1;
16938: }
16939: }
16940: if ($texengine ne '') {
16941: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
16942: }
1.264 raeburn 16943: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
16944: my @currclonecode;
16945: if (ref($currclone) eq 'HASH') {
16946: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
16947: @currclonecode = @{$currclone->{'instcode'}};
16948: }
16949: }
16950: my $newclone;
1.289 raeburn 16951: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 16952: $newclone = $env{'form.canclone'};
16953: }
16954: if ($newclone eq 'instcode') {
16955: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
16956: my (%codedefaults,@code_order,@clonecode);
16957: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
16958: \@code_order);
16959: foreach my $item (@code_order) {
16960: if (grep(/^\Q$item\E$/,@newcodes)) {
16961: push(@clonecode,$item);
16962: }
16963: }
16964: if (@clonecode) {
16965: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
16966: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
16967: if (@diffs) {
16968: $changes{'canclone'} = 1;
16969: }
16970: } else {
16971: $newclone eq '';
16972: }
16973: } elsif ($newclone ne '') {
1.289 raeburn 16974: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
16975: }
1.264 raeburn 16976: if ($newclone ne $currclone) {
16977: $changes{'canclone'} = 1;
16978: }
1.257 raeburn 16979: my %credits;
16980: foreach my $type (@types) {
16981: unless ($type eq 'community') {
16982: $credits{$type} = $env{'form.'.$type.'_credits'};
16983: $credits{$type} =~ s/[^\d.]+//g;
16984: }
16985: }
16986: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
16987: ($env{'form.coursecredits'} eq '1')) {
16988: $changes{'coursecredits'} = 1;
16989: foreach my $type (keys(%credits)) {
16990: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
16991: }
16992: } else {
1.289 raeburn 16993: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 16994: foreach my $type (@types) {
16995: unless ($type eq 'community') {
1.289 raeburn 16996: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 16997: $changes{'coursecredits'} = 1;
16998: }
16999: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17000: }
17001: }
17002: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17003: foreach my $type (@types) {
17004: unless ($type eq 'community') {
17005: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17006: $changes{'coursecredits'} = 1;
17007: last;
17008: }
17009: }
17010: }
17011: }
17012: }
17013: if ($env{'form.postsubmit'} eq '1') {
17014: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17015: my %currtimeout;
17016: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17017: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17018: $changes{'postsubmit'} = 1;
17019: }
17020: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17021: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17022: }
17023: } else {
17024: $changes{'postsubmit'} = 1;
17025: }
17026: foreach my $type (@types) {
17027: my $timeout = $env{'form.'.$type.'_timeout'};
17028: $timeout =~ s/\D//g;
17029: if ($timeout == $staticdefaults{'postsubmit'}) {
17030: $timeout = '';
17031: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17032: $timeout = '0';
17033: }
17034: unless ($timeout eq '') {
17035: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17036: }
17037: if (exists($currtimeout{$type})) {
17038: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 17039: $changes{'postsubmit'} = 1;
1.257 raeburn 17040: }
17041: } elsif ($timeout ne '') {
17042: $changes{'postsubmit'} = 1;
17043: }
17044: }
17045: } else {
17046: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17047: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17048: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17049: $changes{'postsubmit'} = 1;
17050: }
17051: } else {
17052: $changes{'postsubmit'} = 1;
17053: }
1.192 raeburn 17054: }
1.121 raeburn 17055: }
17056: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17057: $dom);
17058: if ($putresult eq 'ok') {
17059: if (keys(%changes) > 0) {
1.213 raeburn 17060: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 17061: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 17062: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 17063: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
17064: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 17065: if ($changes{$item}) {
17066: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17067: }
1.289 raeburn 17068: }
1.192 raeburn 17069: if ($changes{'coursecredits'}) {
17070: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 17071: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17072: $domdefaults{$type.'credits'} =
17073: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17074: }
17075: }
17076: }
17077: if ($changes{'postsubmit'}) {
17078: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17079: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17080: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17081: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17082: $domdefaults{$type.'postsubtimeout'} =
17083: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17084: }
17085: }
1.192 raeburn 17086: }
17087: }
1.198 raeburn 17088: if ($changes{'uploadquota'}) {
17089: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17090: foreach my $type (@types) {
17091: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17092: }
17093: }
17094: }
1.264 raeburn 17095: if ($changes{'canclone'}) {
17096: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17097: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17098: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17099: if (@clonecodes) {
17100: $domdefaults{'canclone'} = join('+',@clonecodes);
17101: }
17102: }
17103: } else {
17104: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17105: }
17106: }
1.121 raeburn 17107: my $cachetime = 24*60*60;
17108: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17109: if (ref($lastactref) eq 'HASH') {
17110: $lastactref->{'domdefaults'} = 1;
17111: }
1.121 raeburn 17112: }
17113: $resulttext = &mt('Changes made:').'<ul>';
17114: foreach my $item (sort(keys(%changes))) {
17115: if ($item eq 'canuse_pdfforms') {
17116: if ($env{'form.'.$item} eq '1') {
17117: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
17118: } else {
17119: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
17120: }
1.257 raeburn 17121: } elsif ($item eq 'uselcmath') {
17122: if ($env{'form.'.$item} eq '1') {
17123: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17124: } else {
17125: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17126: }
17127: } elsif ($item eq 'usejsme') {
17128: if ($env{'form.'.$item} eq '1') {
17129: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17130: } else {
1.289 raeburn 17131: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 17132: }
1.314 raeburn 17133: } elsif ($item eq 'texengine') {
17134: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17135: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17136: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17137: }
1.139 raeburn 17138: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 17139: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 17140: } elsif ($item eq 'uploadquota') {
17141: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17142: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17143: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17144: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 17145: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 17146: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 17147: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17148: '</ul>'.
17149: '</li>';
17150: } else {
17151: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17152: }
1.276 raeburn 17153: } elsif ($item eq 'mysqltables') {
17154: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17155: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17156: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17157: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17158: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17159: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
17160: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17161: '</ul>'.
17162: '</li>';
17163: } else {
17164: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17165: }
1.257 raeburn 17166: } elsif ($item eq 'postsubmit') {
17167: if ($domdefaults{'postsubmit'} eq 'off') {
17168: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17169: } else {
17170: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 17171: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 17172: $resulttext .= &mt('durations:').'<ul>';
17173: foreach my $type (@types) {
17174: $resulttext .= '<li>';
17175: my $timeout;
17176: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17177: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17178: }
17179: my $display;
17180: if ($timeout eq '0') {
17181: $display = &mt('unlimited');
17182: } elsif ($timeout eq '') {
17183: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17184: } else {
17185: $display = &mt('[quant,_1,second]',$timeout);
17186: }
17187: if ($type eq 'community') {
17188: $resulttext .= &mt('Communities');
17189: } elsif ($type eq 'official') {
17190: $resulttext .= &mt('Official courses');
17191: } elsif ($type eq 'unofficial') {
17192: $resulttext .= &mt('Unofficial courses');
17193: } elsif ($type eq 'textbook') {
17194: $resulttext .= &mt('Textbook courses');
1.271 raeburn 17195: } elsif ($type eq 'placement') {
17196: $resulttext .= &mt('Placement tests');
1.257 raeburn 17197: }
17198: $resulttext .= ' -- '.$display.'</li>';
17199: }
17200: $resulttext .= '</ul>';
17201: }
1.289 raeburn 17202: $resulttext .= '</li>';
1.257 raeburn 17203: }
1.192 raeburn 17204: } elsif ($item eq 'coursecredits') {
17205: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17206: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 17207: ($domdefaults{'unofficialcredits'} eq '') &&
17208: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 17209: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17210: } else {
17211: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17212: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17213: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 17214: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 17215: '</ul>'.
17216: '</li>';
17217: }
17218: } else {
17219: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17220: }
1.264 raeburn 17221: } elsif ($item eq 'canclone') {
17222: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17223: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17224: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17225: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17226: }
17227: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17228: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17229: } else {
1.289 raeburn 17230: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 17231: }
1.140 raeburn 17232: }
1.121 raeburn 17233: }
17234: $resulttext .= '</ul>';
17235: } else {
17236: $resulttext = &mt('No changes made to course defaults');
17237: }
17238: } else {
17239: $resulttext = '<span class="LC_error">'.
17240: &mt('An error occurred: [_1]',$putresult).'</span>';
17241: }
17242: return $resulttext;
17243: }
17244:
1.231 raeburn 17245: sub modify_selfenrollment {
17246: my ($dom,$lastactref,%domconfig) = @_;
17247: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 17248: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 17249: my %titles = &tool_titles();
1.232 raeburn 17250: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17251: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 17252: $ordered{'default'} = ['types','registered','approval','limit'];
17253:
17254: my (%roles,%shown,%toplevel);
17255: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17256:
17257: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17258: if ($domconfig{'selfenrollment'} eq '') {
17259: $domconfig{'selfenrollment'} = {};
17260: }
17261: }
17262: %toplevel = (
17263: admin => 'Configuration Rights',
17264: default => 'Default settings',
17265: validation => 'Validation of self-enrollment requests',
17266: );
1.233 raeburn 17267: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 17268:
17269: if (ref($ordered{'admin'}) eq 'ARRAY') {
17270: foreach my $item (@{$ordered{'admin'}}) {
17271: foreach my $type (@types) {
17272: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17273: $selfenrollhash{'admin'}{$type}{$item} = 1;
17274: } else {
17275: $selfenrollhash{'admin'}{$type}{$item} = 0;
17276: }
17277: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17278: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17279: if ($selfenrollhash{'admin'}{$type}{$item} ne
17280: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17281: push(@{$changes{'admin'}{$type}},$item);
17282: }
17283: } else {
17284: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17285: push(@{$changes{'admin'}{$type}},$item);
17286: }
17287: }
17288: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17289: push(@{$changes{'admin'}{$type}},$item);
17290: }
17291: }
17292: }
17293: }
17294:
17295: foreach my $item (@{$ordered{'default'}}) {
17296: foreach my $type (@types) {
17297: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17298: if ($item eq 'types') {
17299: unless (($value eq 'all') || ($value eq 'dom')) {
17300: $value = '';
17301: }
17302: } elsif ($item eq 'registered') {
17303: unless ($value eq '1') {
17304: $value = 0;
17305: }
17306: } elsif ($item eq 'approval') {
17307: unless ($value =~ /^[012]$/) {
17308: $value = 0;
17309: }
17310: } else {
17311: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17312: $value = 'none';
17313: }
17314: }
17315: $selfenrollhash{'default'}{$type}{$item} = $value;
17316: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17317: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17318: if ($selfenrollhash{'default'}{$type}{$item} ne
17319: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17320: push(@{$changes{'default'}{$type}},$item);
17321: }
17322: } else {
17323: push(@{$changes{'default'}{$type}},$item);
17324: }
17325: } else {
17326: push(@{$changes{'default'}{$type}},$item);
17327: }
17328: if ($item eq 'limit') {
17329: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17330: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17331: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17332: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17333: }
17334: } else {
17335: $selfenrollhash{'default'}{$type}{'cap'} = '';
17336: }
17337: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17338: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17339: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17340: push(@{$changes{'default'}{$type}},'cap');
17341: }
17342: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17343: push(@{$changes{'default'}{$type}},'cap');
17344: }
17345: }
17346: }
17347: }
17348:
17349: foreach my $item (@{$itemsref}) {
17350: if ($item eq 'fields') {
17351: my @changed;
17352: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17353: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17354: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17355: }
17356: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17357: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17358: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17359: $domconfig{'selfenrollment'}{'validation'}{$item});
17360: } else {
17361: @changed = @{$selfenrollhash{'validation'}{$item}};
17362: }
17363: } else {
17364: @changed = @{$selfenrollhash{'validation'}{$item}};
17365: }
17366: if (@changed) {
17367: if ($selfenrollhash{'validation'}{$item}) {
17368: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17369: } else {
17370: $changes{'validation'}{$item} = &mt('None');
17371: }
17372: }
17373: } else {
17374: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17375: if ($item eq 'markup') {
17376: if ($env{'form.selfenroll_validation_'.$item}) {
17377: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17378: }
17379: }
17380: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17381: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17382: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17383: }
17384: }
17385: }
17386: }
17387:
17388: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17389: $dom);
17390: if ($putresult eq 'ok') {
17391: if (keys(%changes) > 0) {
17392: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17393: $resulttext = &mt('Changes made:').'<ul>';
17394: foreach my $key ('admin','default','validation') {
17395: if (ref($changes{$key}) eq 'HASH') {
17396: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17397: if ($key eq 'validation') {
17398: foreach my $item (@{$itemsref}) {
17399: if (exists($changes{$key}{$item})) {
17400: if ($item eq 'markup') {
17401: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17402: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17403: } else {
17404: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17405: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17406: }
17407: }
17408: }
17409: } else {
17410: foreach my $type (@types) {
17411: if ($type eq 'community') {
17412: $roles{'1'} = &mt('Community personnel');
17413: } else {
17414: $roles{'1'} = &mt('Course personnel');
17415: }
17416: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 17417: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17418: if ($key eq 'admin') {
17419: my @mgrdc = ();
17420: if (ref($ordered{$key}) eq 'ARRAY') {
17421: foreach my $item (@{$ordered{'admin'}}) {
17422: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17423: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17424: push(@mgrdc,$item);
17425: }
17426: }
17427: }
17428: if (@mgrdc) {
17429: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17430: } else {
17431: delete($domdefaults{$type.'selfenrolladmdc'});
17432: }
17433: }
17434: } else {
17435: if (ref($ordered{$key}) eq 'ARRAY') {
17436: foreach my $item (@{$ordered{$key}}) {
17437: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17438: $domdefaults{$type.'selfenroll'.$item} =
17439: $selfenrollhash{$key}{$type}{$item};
17440: }
17441: }
17442: }
17443: }
17444: }
1.231 raeburn 17445: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17446: foreach my $item (@{$ordered{$key}}) {
17447: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17448: $resulttext .= '<li>';
17449: if ($key eq 'admin') {
17450: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17451: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17452: } else {
17453: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17454: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17455: }
17456: $resulttext .= '</li>';
17457: }
17458: }
17459: $resulttext .= '</ul></li>';
17460: }
17461: }
17462: $resulttext .= '</ul></li>';
17463: }
17464: }
1.305 raeburn 17465: }
17466: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17467: my $cachetime = 24*60*60;
17468: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17469: if (ref($lastactref) eq 'HASH') {
17470: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 17471: }
1.231 raeburn 17472: }
17473: $resulttext .= '</ul>';
17474: } else {
17475: $resulttext = &mt('No changes made to self-enrollment settings');
17476: }
17477: } else {
17478: $resulttext = '<span class="LC_error">'.
17479: &mt('An error occurred: [_1]',$putresult).'</span>';
17480: }
17481: return $resulttext;
17482: }
17483:
1.137 raeburn 17484: sub modify_usersessions {
1.212 raeburn 17485: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17486: my @hostingtypes = ('version','excludedomain','includedomain');
17487: my @offloadtypes = ('primary','default');
17488: my %types = (
17489: remote => \@hostingtypes,
17490: hosted => \@hostingtypes,
17491: spares => \@offloadtypes,
17492: );
17493: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17494: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 17495: my (%by_ip,%by_location,@intdoms,@instdoms);
17496: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 17497: my @locations = sort(keys(%by_location));
1.137 raeburn 17498: my (%defaultshash,%changes);
17499: foreach my $prefix (@prefixes) {
17500: $defaultshash{'usersessions'}{$prefix} = {};
17501: }
1.212 raeburn 17502: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17503: my $resulttext;
1.138 raeburn 17504: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17505: foreach my $prefix (@prefixes) {
1.145 raeburn 17506: next if ($prefix eq 'spares');
17507: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 17508: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17509: if ($type eq 'version') {
17510: my $value = $env{'form.'.$prefix.'_'.$type};
17511: my $okvalue;
17512: if ($value ne '') {
17513: if (grep(/^\Q$value\E$/,@lcversions)) {
17514: $okvalue = $value;
17515: }
17516: }
17517: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17518: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17519: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
17520: if ($inuse == 0) {
17521: $changes{$prefix}{$type} = 1;
17522: } else {
17523: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
17524: $changes{$prefix}{$type} = 1;
17525: }
17526: if ($okvalue ne '') {
17527: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17528: }
17529: }
17530: } else {
17531: if (($inuse == 1) && ($okvalue ne '')) {
17532: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17533: $changes{$prefix}{$type} = 1;
17534: }
17535: }
17536: } else {
17537: if (($inuse == 1) && ($okvalue ne '')) {
17538: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17539: $changes{$prefix}{$type} = 1;
17540: }
17541: }
17542: } else {
17543: if (($inuse == 1) && ($okvalue ne '')) {
17544: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
17545: $changes{$prefix}{$type} = 1;
17546: }
17547: }
17548: } else {
17549: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17550: my @okvals;
17551: foreach my $val (@vals) {
1.138 raeburn 17552: if ($val =~ /:/) {
17553: my @items = split(/:/,$val);
17554: foreach my $item (@items) {
17555: if (ref($by_location{$item}) eq 'ARRAY') {
17556: push(@okvals,$item);
17557: }
17558: }
17559: } else {
17560: if (ref($by_location{$val}) eq 'ARRAY') {
17561: push(@okvals,$val);
17562: }
1.137 raeburn 17563: }
17564: }
17565: @okvals = sort(@okvals);
17566: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17567: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
17568: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17569: if ($inuse == 0) {
17570: $changes{$prefix}{$type} = 1;
17571: } else {
17572: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17573: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
17574: if (@changed > 0) {
17575: $changes{$prefix}{$type} = 1;
17576: }
17577: }
17578: } else {
17579: if ($inuse == 1) {
17580: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17581: $changes{$prefix}{$type} = 1;
17582: }
17583: }
17584: } else {
17585: if ($inuse == 1) {
17586: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17587: $changes{$prefix}{$type} = 1;
17588: }
17589: }
17590: } else {
17591: if ($inuse == 1) {
17592: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
17593: $changes{$prefix}{$type} = 1;
17594: }
17595: }
17596: }
17597: }
17598: }
1.145 raeburn 17599:
17600: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 17601: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 17602: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
17603: my $savespares;
17604:
17605: foreach my $lonhost (sort(keys(%servers))) {
17606: my $serverhomeID =
17607: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 17608: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 17609: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
17610: my %spareschg;
17611: foreach my $type (@{$types{'spares'}}) {
17612: my @okspares;
17613: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
17614: foreach my $server (@checked) {
1.152 raeburn 17615: if (&Apache::lonnet::hostname($server) ne '') {
17616: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
17617: unless (grep(/^\Q$server\E$/,@okspares)) {
17618: push(@okspares,$server);
17619: }
1.145 raeburn 17620: }
17621: }
17622: }
17623: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
17624: my $newspare;
1.152 raeburn 17625: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
17626: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 17627: $newspare = $new;
17628: }
17629: }
1.152 raeburn 17630: my @spares;
17631: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
17632: @spares = sort(@okspares,$newspare);
17633: } else {
17634: @spares = sort(@okspares);
17635: }
17636: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 17637: if (ref($spareid{$lonhost}) eq 'HASH') {
17638: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 17639: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 17640: if (@diffs > 0) {
17641: $spareschg{$type} = 1;
17642: }
17643: }
17644: }
17645: }
17646: if (keys(%spareschg) > 0) {
17647: $changes{'spares'}{$lonhost} = \%spareschg;
17648: }
17649: }
1.261 raeburn 17650: $defaultshash{'usersessions'}{'offloadnow'} = {};
17651: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
17652: my @okoffload;
17653: if (@offloadnow) {
17654: foreach my $server (@offloadnow) {
17655: if (&Apache::lonnet::hostname($server) ne '') {
17656: unless (grep(/^\Q$server\E$/,@okoffload)) {
17657: push(@okoffload,$server);
17658: }
17659: }
17660: }
17661: if (@okoffload) {
17662: foreach my $lonhost (@okoffload) {
17663: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
17664: }
17665: }
17666: }
1.145 raeburn 17667: if (ref($domconfig{'usersessions'}) eq 'HASH') {
17668: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
17669: if (ref($changes{'spares'}) eq 'HASH') {
17670: if (keys(%{$changes{'spares'}}) > 0) {
17671: $savespares = 1;
17672: }
17673: }
17674: } else {
17675: $savespares = 1;
17676: }
1.261 raeburn 17677: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
17678: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
17679: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
17680: $changes{'offloadnow'} = 1;
17681: last;
17682: }
17683: }
17684: unless ($changes{'offloadnow'}) {
1.289 raeburn 17685: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 17686: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
17687: $changes{'offloadnow'} = 1;
17688: last;
17689: }
17690: }
17691: }
17692: } elsif (@okoffload) {
17693: $changes{'offloadnow'} = 1;
17694: }
17695: } elsif (@okoffload) {
17696: $changes{'offloadnow'} = 1;
1.145 raeburn 17697: }
1.147 raeburn 17698: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
17699: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 17700: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17701: $dom);
17702: if ($putresult eq 'ok') {
17703: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17704: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
17705: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
17706: }
17707: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
17708: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
17709: }
1.261 raeburn 17710: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17711: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
17712: }
1.137 raeburn 17713: }
17714: my $cachetime = 24*60*60;
17715: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 17716: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 17717: if (ref($lastactref) eq 'HASH') {
17718: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 17719: $lastactref->{'usersessions'} = 1;
1.212 raeburn 17720: }
1.147 raeburn 17721: if (keys(%changes) > 0) {
17722: my %lt = &usersession_titles();
17723: $resulttext = &mt('Changes made:').'<ul>';
17724: foreach my $prefix (@prefixes) {
17725: if (ref($changes{$prefix}) eq 'HASH') {
17726: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
17727: if ($prefix eq 'spares') {
17728: if (ref($changes{$prefix}) eq 'HASH') {
17729: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
17730: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 17731: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 17732: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
17733: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 17734: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
17735: foreach my $type (@{$types{$prefix}}) {
17736: if ($changes{$prefix}{$lonhost}{$type}) {
17737: my $offloadto = &mt('None');
17738: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
17739: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
17740: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
17741: }
1.145 raeburn 17742: }
1.147 raeburn 17743: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 17744: }
1.137 raeburn 17745: }
17746: }
1.147 raeburn 17747: $resulttext .= '</li>';
1.137 raeburn 17748: }
17749: }
1.147 raeburn 17750: } else {
17751: foreach my $type (@{$types{$prefix}}) {
17752: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17753: my ($newvalue,$notinuse);
1.147 raeburn 17754: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
17755: if (ref($defaultshash{'usersessions'}{$prefix})) {
17756: if ($type eq 'version') {
17757: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 17758: } else {
17759: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
17760: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
17761: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
17762: }
17763: } else {
17764: $notinuse = 1;
1.147 raeburn 17765: }
1.145 raeburn 17766: }
17767: }
17768: }
1.147 raeburn 17769: if ($newvalue eq '') {
17770: if ($type eq 'version') {
17771: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 17772: } elsif ($notinuse) {
17773: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 17774: } else {
17775: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
17776: }
1.145 raeburn 17777: } else {
1.147 raeburn 17778: if ($type eq 'version') {
1.344 raeburn 17779: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 17780: }
17781: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 17782: }
1.137 raeburn 17783: }
17784: }
17785: }
1.147 raeburn 17786: $resulttext .= '</ul>';
1.137 raeburn 17787: }
17788: }
1.261 raeburn 17789: if ($changes{'offloadnow'}) {
17790: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
17791: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
17792: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
17793: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
17794: $resulttext .= '<li>'.$lonhost.'</li>';
17795: }
17796: $resulttext .= '</ul>';
17797: } else {
17798: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
17799: }
17800: } else {
17801: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
17802: }
17803: }
1.147 raeburn 17804: $resulttext .= '</ul>';
17805: } else {
17806: $resulttext = $nochgmsg;
1.137 raeburn 17807: }
17808: } else {
17809: $resulttext = '<span class="LC_error">'.
17810: &mt('An error occurred: [_1]',$putresult).'</span>';
17811: }
17812: } else {
1.147 raeburn 17813: $resulttext = $nochgmsg;
1.137 raeburn 17814: }
17815: return $resulttext;
17816: }
17817:
1.275 raeburn 17818: sub modify_ssl {
17819: my ($dom,$lastactref,%domconfig) = @_;
17820: my (%by_ip,%by_location,@intdoms,@instdoms);
17821: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17822: my @locations = sort(keys(%by_location));
17823: my %servers = &Apache::lonnet::internet_dom_servers($dom);
17824: my (%defaultshash,%changes);
17825: my $action = 'ssl';
1.293 raeburn 17826: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 17827: foreach my $prefix (@prefixes) {
17828: $defaultshash{$action}{$prefix} = {};
17829: }
17830: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17831: my $resulttext;
17832: my %iphost = &Apache::lonnet::get_iphost();
17833: my @reptypes = ('certreq','nocertreq');
17834: my @connecttypes = ('dom','intdom','other');
17835: my %types = (
1.293 raeburn 17836: connto => \@connecttypes,
17837: connfrom => \@connecttypes,
17838: replication => \@reptypes,
1.275 raeburn 17839: );
17840: foreach my $prefix (sort(keys(%types))) {
17841: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 17842: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17843: my $value = 'yes';
17844: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
17845: $value = $env{'form.'.$prefix.'_'.$type};
17846: }
1.335 raeburn 17847: if (ref($domconfig{$action}) eq 'HASH') {
17848: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17849: if ($domconfig{$action}{$prefix}{$type} ne '') {
17850: if ($value ne $domconfig{$action}{$prefix}{$type}) {
17851: $changes{$prefix}{$type} = 1;
17852: }
17853: $defaultshash{$action}{$prefix}{$type} = $value;
17854: } else {
17855: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 17856: $changes{$prefix}{$type} = 1;
17857: }
17858: } else {
17859: $defaultshash{$action}{$prefix}{$type} = $value;
17860: $changes{$prefix}{$type} = 1;
17861: }
17862: } else {
17863: $defaultshash{$action}{$prefix}{$type} = $value;
17864: $changes{$prefix}{$type} = 1;
17865: }
17866: if (($type eq 'dom') && (keys(%servers) == 1)) {
17867: delete($changes{$prefix}{$type});
17868: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
17869: delete($changes{$prefix}{$type});
17870: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
17871: delete($changes{$prefix}{$type});
17872: }
17873: } elsif ($prefix eq 'replication') {
17874: if (@locations > 0) {
17875: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
17876: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
17877: my @okvals;
17878: foreach my $val (@vals) {
17879: if ($val =~ /:/) {
17880: my @items = split(/:/,$val);
17881: foreach my $item (@items) {
17882: if (ref($by_location{$item}) eq 'ARRAY') {
17883: push(@okvals,$item);
17884: }
17885: }
17886: } else {
17887: if (ref($by_location{$val}) eq 'ARRAY') {
17888: push(@okvals,$val);
17889: }
17890: }
17891: }
17892: @okvals = sort(@okvals);
17893: if (ref($domconfig{$action}) eq 'HASH') {
17894: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
17895: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
17896: if ($inuse == 0) {
17897: $changes{$prefix}{$type} = 1;
17898: } else {
17899: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17900: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
17901: if (@changed > 0) {
17902: $changes{$prefix}{$type} = 1;
17903: }
17904: }
17905: } else {
17906: if ($inuse == 1) {
17907: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17908: $changes{$prefix}{$type} = 1;
17909: }
17910: }
17911: } else {
17912: if ($inuse == 1) {
17913: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17914: $changes{$prefix}{$type} = 1;
17915: }
17916: }
17917: } else {
17918: if ($inuse == 1) {
17919: $defaultshash{$action}{$prefix}{$type} = \@okvals;
17920: $changes{$prefix}{$type} = 1;
17921: }
17922: }
17923: }
17924: }
17925: }
17926: }
1.336 raeburn 17927: if (keys(%changes)) {
17928: foreach my $prefix (keys(%changes)) {
17929: if (ref($changes{$prefix}) eq 'HASH') {
17930: if (scalar(keys(%{$changes{$prefix}})) == 0) {
17931: delete($changes{$prefix});
17932: }
17933: } else {
17934: delete($changes{$prefix});
17935: }
17936: }
17937: }
1.275 raeburn 17938: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
17939: if (keys(%changes) > 0) {
17940: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17941: $dom);
17942: if ($putresult eq 'ok') {
17943: if (ref($defaultshash{$action}) eq 'HASH') {
17944: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
17945: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
17946: }
1.293 raeburn 17947: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 17948: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 17949: }
17950: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 17951: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 17952: }
17953: }
17954: my $cachetime = 24*60*60;
17955: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17956: if (ref($lastactref) eq 'HASH') {
17957: $lastactref->{'domdefaults'} = 1;
17958: }
17959: if (keys(%changes) > 0) {
17960: my %titles = &ssl_titles();
17961: $resulttext = &mt('Changes made:').'<ul>';
17962: foreach my $prefix (@prefixes) {
17963: if (ref($changes{$prefix}) eq 'HASH') {
17964: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
17965: foreach my $type (@{$types{$prefix}}) {
17966: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 17967: my ($newvalue,$notinuse);
1.275 raeburn 17968: if (ref($defaultshash{$action}) eq 'HASH') {
17969: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 17970: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 17971: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 17972: } else {
17973: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
17974: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
17975: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
17976: }
17977: } else {
17978: $notinuse = 1;
1.275 raeburn 17979: }
17980: }
17981: }
1.344 raeburn 17982: if ($notinuse) {
17983: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
17984: } elsif ($newvalue eq '') {
1.275 raeburn 17985: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
17986: } else {
17987: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
17988: }
17989: }
17990: }
17991: }
17992: $resulttext .= '</ul>';
17993: }
17994: }
17995: } else {
17996: $resulttext = $nochgmsg;
17997: }
17998: } else {
17999: $resulttext = '<span class="LC_error">'.
18000: &mt('An error occurred: [_1]',$putresult).'</span>';
18001: }
18002: } else {
18003: $resulttext = $nochgmsg;
18004: }
18005: return $resulttext;
18006: }
18007:
1.279 raeburn 18008: sub modify_trust {
18009: my ($dom,$lastactref,%domconfig) = @_;
18010: my (%by_ip,%by_location,@intdoms,@instdoms);
18011: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18012: my @locations = sort(keys(%by_location));
18013: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
18014: my @types = ('exc','inc');
18015: my (%defaultshash,%changes);
18016: foreach my $prefix (@prefixes) {
18017: $defaultshash{'trust'}{$prefix} = {};
18018: }
18019: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18020: my $resulttext;
18021: foreach my $prefix (@prefixes) {
18022: foreach my $type (@types) {
18023: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18024: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18025: my @okvals;
18026: foreach my $val (@vals) {
18027: if ($val =~ /:/) {
18028: my @items = split(/:/,$val);
18029: foreach my $item (@items) {
18030: if (ref($by_location{$item}) eq 'ARRAY') {
18031: push(@okvals,$item);
18032: }
18033: }
18034: } else {
18035: if (ref($by_location{$val}) eq 'ARRAY') {
18036: push(@okvals,$val);
18037: }
18038: }
18039: }
18040: @okvals = sort(@okvals);
18041: if (ref($domconfig{'trust'}) eq 'HASH') {
18042: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
18043: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18044: if ($inuse == 0) {
18045: $changes{$prefix}{$type} = 1;
18046: } else {
18047: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18048: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
18049: if (@changed > 0) {
18050: $changes{$prefix}{$type} = 1;
18051: }
18052: }
18053: } else {
18054: if ($inuse == 1) {
18055: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18056: $changes{$prefix}{$type} = 1;
18057: }
18058: }
18059: } else {
18060: if ($inuse == 1) {
18061: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18062: $changes{$prefix}{$type} = 1;
18063: }
18064: }
18065: } else {
18066: if ($inuse == 1) {
18067: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18068: $changes{$prefix}{$type} = 1;
18069: }
18070: }
18071: }
18072: }
18073: my $nochgmsg = &mt('No changes made to trust settings.');
18074: if (keys(%changes) > 0) {
18075: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18076: $dom);
18077: if ($putresult eq 'ok') {
18078: if (ref($defaultshash{'trust'}) eq 'HASH') {
18079: foreach my $prefix (@prefixes) {
18080: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
18081: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
18082: }
18083: }
18084: }
18085: my $cachetime = 24*60*60;
18086: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18087: if (ref($lastactref) eq 'HASH') {
18088: $lastactref->{'domdefaults'} = 1;
18089: }
18090: if (keys(%changes) > 0) {
18091: my %lt = &trust_titles();
18092: $resulttext = &mt('Changes made:').'<ul>';
18093: foreach my $prefix (@prefixes) {
18094: if (ref($changes{$prefix}) eq 'HASH') {
18095: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18096: foreach my $type (@types) {
18097: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18098: my ($newvalue,$notinuse);
1.279 raeburn 18099: if (ref($defaultshash{'trust'}) eq 'HASH') {
18100: if (ref($defaultshash{'trust'}{$prefix})) {
18101: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18102: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
18103: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
18104: }
1.344 raeburn 18105: } else {
18106: $notinuse = 1;
1.279 raeburn 18107: }
18108: }
18109: }
1.344 raeburn 18110: if ($notinuse) {
18111: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
18112: } elsif ($newvalue eq '') {
1.279 raeburn 18113: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18114: } else {
18115: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18116: }
18117: }
18118: }
18119: $resulttext .= '</ul>';
18120: }
18121: }
18122: $resulttext .= '</ul>';
18123: } else {
18124: $resulttext = $nochgmsg;
18125: }
18126: } else {
18127: $resulttext = '<span class="LC_error">'.
18128: &mt('An error occurred: [_1]',$putresult).'</span>';
18129: }
18130: } else {
18131: $resulttext = $nochgmsg;
18132: }
18133: return $resulttext;
18134: }
18135:
1.150 raeburn 18136: sub modify_loadbalancing {
18137: my ($dom,%domconfig) = @_;
18138: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18139: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18140: my ($othertitle,$usertypes,$types) =
18141: &Apache::loncommon::sorted_inst_types($dom);
18142: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 18143: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18144: my @sparestypes = ('primary','default');
18145: my %typetitles = &sparestype_titles();
18146: my $resulttext;
1.342 raeburn 18147: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18148: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18149: %existing = %{$domconfig{'loadbalancing'}};
18150: }
18151: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 18152: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 18153: my ($saveloadbalancing,%defaultshash,%changes);
18154: my ($alltypes,$othertypes,$titles) =
18155: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18156: my %ruletitles = &offloadtype_text();
18157: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18158: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18159: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18160: if ($balancer eq '') {
18161: next;
18162: }
1.210 raeburn 18163: if (!exists($servers{$balancer})) {
1.171 raeburn 18164: if (exists($currbalancer{$balancer})) {
18165: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18166: }
1.171 raeburn 18167: next;
18168: }
18169: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18170: push(@{$changes{'delete'}},$balancer);
18171: next;
18172: }
18173: if (!exists($currbalancer{$balancer})) {
18174: push(@{$changes{'add'}},$balancer);
18175: }
18176: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18177: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18178: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18179: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18180: $saveloadbalancing = 1;
18181: }
18182: foreach my $sparetype (@sparestypes) {
18183: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18184: my @offloadto;
18185: foreach my $target (@targets) {
18186: if (($servers{$target}) && ($target ne $balancer)) {
18187: if ($sparetype eq 'default') {
18188: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18189: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18190: }
18191: }
1.171 raeburn 18192: unless(grep(/^\Q$target\E$/,@offloadto)) {
18193: push(@offloadto,$target);
18194: }
1.150 raeburn 18195: }
18196: }
1.284 raeburn 18197: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18198: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18199: push(@offloadto,$balancer);
18200: }
18201: }
18202: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18203: }
1.342 raeburn 18204: if ($env{'form.loadbalancing_cookie_'.$i}) {
18205: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18206: if (exists($currbalancer{$balancer})) {
18207: unless ($currcookies{$balancer}) {
18208: $changes{'curr'}{$balancer}{'cookie'} = 1;
18209: }
18210: }
18211: } elsif (exists($currbalancer{$balancer})) {
18212: if ($currcookies{$balancer}) {
18213: $changes{'curr'}{$balancer}{'cookie'} = 1;
18214: }
18215: }
1.171 raeburn 18216: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18217: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18218: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18219: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18220: if (@targetdiffs > 0) {
1.171 raeburn 18221: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18222: }
1.171 raeburn 18223: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18224: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18225: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18226: }
18227: }
18228: }
18229: } else {
1.171 raeburn 18230: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 18231: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18232: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18233: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18234: $changes{'curr'}{$balancer}{'targets'} = 1;
18235: }
1.150 raeburn 18236: }
18237: }
1.210 raeburn 18238: }
1.150 raeburn 18239: }
18240: my $ishomedom;
1.171 raeburn 18241: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18242: $ishomedom = 1;
1.150 raeburn 18243: }
18244: if (ref($alltypes) eq 'ARRAY') {
18245: foreach my $type (@{$alltypes}) {
18246: my $rule;
1.210 raeburn 18247: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18248: (!$ishomedom)) {
1.171 raeburn 18249: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18250: }
18251: if ($rule eq 'specific') {
1.255 raeburn 18252: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 18253: if (exists($servers{$specifiedhost})) {
1.255 raeburn 18254: $rule = $specifiedhost;
18255: }
1.150 raeburn 18256: }
1.171 raeburn 18257: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18258: if (ref($currrules{$balancer}) eq 'HASH') {
18259: if ($rule ne $currrules{$balancer}{$type}) {
18260: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18261: }
18262: } elsif ($rule ne '') {
1.171 raeburn 18263: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18264: }
18265: }
18266: }
1.171 raeburn 18267: }
18268: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18269: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18270: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18271: $defaultshash{'loadbalancing'} = {};
18272: }
18273: my $putresult = &Apache::lonnet::put_dom('configuration',
18274: \%defaultshash,$dom);
18275: if ($putresult eq 'ok') {
18276: if (keys(%changes) > 0) {
1.252 raeburn 18277: my %toupdate;
1.171 raeburn 18278: if (ref($changes{'delete'}) eq 'ARRAY') {
18279: foreach my $balancer (sort(@{$changes{'delete'}})) {
18280: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 18281: $toupdate{$balancer} = 1;
1.150 raeburn 18282: }
1.171 raeburn 18283: }
18284: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 18285: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 18286: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 18287: $toupdate{$balancer} = 1;
1.171 raeburn 18288: }
18289: }
18290: if (ref($changes{'curr'}) eq 'HASH') {
18291: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 18292: $toupdate{$balancer} = 1;
1.171 raeburn 18293: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18294: if ($changes{'curr'}{$balancer}{'targets'}) {
18295: my %offloadstr;
18296: foreach my $sparetype (@sparestypes) {
18297: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18298: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18299: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18300: }
18301: }
1.150 raeburn 18302: }
1.171 raeburn 18303: if (keys(%offloadstr) == 0) {
18304: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18305: } else {
1.171 raeburn 18306: my $showoffload;
18307: foreach my $sparetype (@sparestypes) {
18308: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18309: if (defined($offloadstr{$sparetype})) {
18310: $showoffload .= $offloadstr{$sparetype};
18311: } else {
18312: $showoffload .= &mt('None');
18313: }
18314: $showoffload .= (' 'x3);
18315: }
18316: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18317: }
18318: }
18319: }
1.171 raeburn 18320: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18321: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18322: foreach my $type (@{$alltypes}) {
18323: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18324: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18325: my $balancetext;
18326: if ($rule eq '') {
18327: $balancetext = $ruletitles{'default'};
1.209 raeburn 18328: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 18329: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 18330: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 18331: foreach my $sparetype (@sparestypes) {
18332: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18333: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18334: }
18335: }
1.253 raeburn 18336: foreach my $item (@{$alltypes}) {
18337: next if ($item =~ /^_LC_ipchange/);
18338: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18339: if ($hasrule eq 'homeserver') {
18340: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18341: } else {
18342: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18343: if ($servers{$hasrule}) {
18344: $toupdate{$hasrule} = 1;
18345: }
18346: }
18347: }
18348: }
1.254 raeburn 18349: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18350: $balancetext = $ruletitles{$rule};
18351: } else {
18352: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18353: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18354: if ($receiver) {
18355: $toupdate{$receiver};
18356: }
18357: }
18358: } else {
18359: $balancetext = $ruletitles{$rule};
1.252 raeburn 18360: }
1.171 raeburn 18361: } else {
18362: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18363: }
1.210 raeburn 18364: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18365: }
18366: }
18367: }
18368: }
1.342 raeburn 18369: if ($changes{'curr'}{$balancer}{'cookie'}) {
18370: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18371: $balancer).'</li>';
18372: }
1.252 raeburn 18373: if (keys(%toupdate)) {
18374: my %thismachine;
18375: my $updatedhere;
18376: my $cachetime = 60*60*24;
18377: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18378: foreach my $lonhost (keys(%toupdate)) {
18379: if ($thismachine{$lonhost}) {
18380: unless ($updatedhere) {
18381: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18382: $defaultshash{'loadbalancing'},
18383: $cachetime);
18384: $updatedhere = 1;
18385: }
18386: } else {
18387: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18388: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18389: }
18390: }
18391: }
1.150 raeburn 18392: }
1.171 raeburn 18393: }
18394: if ($resulttext ne '') {
18395: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18396: } else {
18397: $resulttext = $nochgmsg;
18398: }
18399: } else {
1.171 raeburn 18400: $resulttext = $nochgmsg;
1.150 raeburn 18401: }
18402: } else {
1.171 raeburn 18403: $resulttext = '<span class="LC_error">'.
18404: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18405: }
18406: } else {
1.171 raeburn 18407: $resulttext = $nochgmsg;
1.150 raeburn 18408: }
18409: return $resulttext;
18410: }
18411:
1.48 raeburn 18412: sub recurse_check {
18413: my ($chkcats,$categories,$depth,$name) = @_;
18414: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18415: my $chg = 0;
18416: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18417: my $category = $chkcats->[$depth]{$name}[$j];
18418: my $item;
18419: if ($category eq '') {
18420: $chg ++;
18421: } else {
18422: my $deeper = $depth + 1;
18423: $item = &escape($category).':'.&escape($name).':'.$depth;
18424: if ($chg) {
18425: $categories->{$item} -= $chg;
18426: }
18427: &recurse_check($chkcats,$categories,$deeper,$category);
18428: $deeper --;
18429: }
18430: }
18431: }
18432: return;
18433: }
18434:
18435: sub recurse_cat_deletes {
18436: my ($item,$coursecategories,$deletions) = @_;
18437: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18438: my $subdepth = $depth + 1;
18439: if (ref($coursecategories) eq 'HASH') {
18440: foreach my $subitem (keys(%{$coursecategories})) {
18441: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18442: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18443: delete($coursecategories->{$subitem});
18444: $deletions->{$subitem} = 1;
18445: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 18446: }
1.48 raeburn 18447: }
18448: }
18449: return;
18450: }
18451:
1.125 raeburn 18452: sub active_dc_picker {
1.191 raeburn 18453: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 18454: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 18455: my @domcoord = keys(%domcoords);
18456: if (keys(%currhash)) {
18457: foreach my $dc (keys(%currhash)) {
18458: unless (exists($domcoords{$dc})) {
18459: push(@domcoord,$dc);
18460: }
18461: }
18462: }
18463: @domcoord = sort(@domcoord);
1.210 raeburn 18464: my $numdcs = scalar(@domcoord);
1.191 raeburn 18465: my $rows = 0;
18466: my $table;
1.125 raeburn 18467: if ($numdcs > 1) {
1.191 raeburn 18468: $table = '<table>';
18469: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18470: my $rem = $i%($numinrow);
18471: if ($rem == 0) {
18472: if ($i > 0) {
1.191 raeburn 18473: $table .= '</tr>';
1.125 raeburn 18474: }
1.191 raeburn 18475: $table .= '<tr>';
18476: $rows ++;
1.125 raeburn 18477: }
1.191 raeburn 18478: my $check = '';
18479: if ($inputtype eq 'radio') {
18480: if (keys(%currhash) == 0) {
18481: if (!$i) {
18482: $check = ' checked="checked"';
18483: }
18484: } elsif (exists($currhash{$domcoord[$i]})) {
18485: $check = ' checked="checked"';
18486: }
18487: } else {
18488: if (exists($currhash{$domcoord[$i]})) {
18489: $check = ' checked="checked"';
1.125 raeburn 18490: }
18491: }
1.191 raeburn 18492: if ($i == @domcoord - 1) {
1.125 raeburn 18493: my $colsleft = $numinrow - $rem;
18494: if ($colsleft > 1) {
1.191 raeburn 18495: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18496: } else {
1.191 raeburn 18497: $table .= '<td class="LC_left_item">';
1.125 raeburn 18498: }
18499: } else {
1.191 raeburn 18500: $table .= '<td class="LC_left_item">';
18501: }
18502: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18503: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18504: $table .= '<span class="LC_nobreak"><label>'.
18505: '<input type="'.$inputtype.'" name="'.$name.'"'.
18506: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
18507: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 18508: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 18509: }
1.219 raeburn 18510: $table .= '</label></span></td>';
1.191 raeburn 18511: }
18512: $table .= '</tr></table>';
18513: } elsif ($numdcs == 1) {
1.219 raeburn 18514: my ($dcname,$dcdom) = split(':',$domcoord[0]);
18515: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 18516: if ($inputtype eq 'radio') {
1.247 raeburn 18517: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 18518: if ($user ne $dcname.':'.$dcdom) {
18519: $table .= ' ('.$dcname.':'.$dcdom.')';
18520: }
1.191 raeburn 18521: } else {
18522: my $check;
18523: if (exists($currhash{$domcoord[0]})) {
18524: $check = ' checked="checked"';
1.125 raeburn 18525: }
1.247 raeburn 18526: $table = '<span class="LC_nobreak"><label>'.
18527: '<input type="checkbox" name="'.$name.'" '.
18528: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 18529: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 18530: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 18531: }
1.220 raeburn 18532: $table .= '</label></span>';
1.191 raeburn 18533: $rows ++;
1.125 raeburn 18534: }
18535: }
1.191 raeburn 18536: return ($numdcs,$table,$rows);
1.125 raeburn 18537: }
18538:
1.137 raeburn 18539: sub usersession_titles {
18540: return &Apache::lonlocal::texthash(
18541: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
18542: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 18543: spares => 'Servers offloaded to, when busy',
1.137 raeburn 18544: version => 'LON-CAPA version requirement',
1.138 raeburn 18545: excludedomain => 'Allow all, but exclude specific domains',
18546: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 18547: primary => 'Primary (checked first)',
1.154 raeburn 18548: default => 'Default',
1.137 raeburn 18549: );
18550: }
18551:
1.152 raeburn 18552: sub id_for_thisdom {
18553: my (%servers) = @_;
18554: my %altids;
18555: foreach my $server (keys(%servers)) {
18556: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18557: if ($serverhome ne $server) {
18558: $altids{$serverhome} = $server;
18559: }
18560: }
18561: return %altids;
18562: }
18563:
1.150 raeburn 18564: sub count_servers {
18565: my ($currbalancer,%servers) = @_;
18566: my (@spares,$numspares);
18567: foreach my $lonhost (sort(keys(%servers))) {
18568: next if ($currbalancer eq $lonhost);
18569: push(@spares,$lonhost);
18570: }
18571: if ($currbalancer) {
18572: $numspares = scalar(@spares);
18573: } else {
18574: $numspares = scalar(@spares) - 1;
18575: }
18576: return ($numspares,@spares);
18577: }
18578:
18579: sub lonbalance_targets_js {
1.171 raeburn 18580: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 18581: my $select = &mt('Select');
18582: my ($alltargets,$allishome,$allinsttypes,@alltypes);
18583: if (ref($servers) eq 'HASH') {
18584: $alltargets = join("','",sort(keys(%{$servers})));
18585: my @homedoms;
18586: foreach my $server (sort(keys(%{$servers}))) {
18587: if (&Apache::lonnet::host_domain($server) eq $dom) {
18588: push(@homedoms,'1');
18589: } else {
18590: push(@homedoms,'0');
18591: }
18592: }
18593: $allishome = join("','",@homedoms);
18594: }
18595: if (ref($types) eq 'ARRAY') {
18596: if (@{$types} > 0) {
18597: @alltypes = @{$types};
18598: }
18599: }
18600: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
18601: $allinsttypes = join("','",@alltypes);
1.342 raeburn 18602: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18603: if (ref($settings) eq 'HASH') {
18604: %existing = %{$settings};
18605: }
18606: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 18607: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 18608: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 18609: return <<"END";
18610:
18611: <script type="text/javascript">
18612: // <![CDATA[
18613:
1.171 raeburn 18614: currBalancers = new Array('$balancers');
18615:
18616: function toggleTargets(balnum) {
18617: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18618: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
18619: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
18620: var prevbalancer = prevhostitem.value;
18621: var baltotal = document.getElementById('loadbalancing_total').value;
18622: prevhostitem.value = balancer;
18623: if (prevbalancer != '') {
18624: var prevIdx = currBalancers.indexOf(prevbalancer);
18625: if (prevIdx != -1) {
18626: currBalancers.splice(prevIdx,1);
18627: }
18628: }
1.150 raeburn 18629: if (balancer == '') {
1.171 raeburn 18630: hideSpares(balnum);
1.150 raeburn 18631: } else {
1.171 raeburn 18632: var currIdx = currBalancers.indexOf(balancer);
18633: if (currIdx == -1) {
18634: currBalancers.push(balancer);
18635: }
1.150 raeburn 18636: var homedoms = new Array('$allishome');
1.171 raeburn 18637: var ishomedom = homedoms[lonhostitem.selectedIndex];
18638: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 18639: }
1.171 raeburn 18640: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 18641: return;
18642: }
18643:
1.171 raeburn 18644: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 18645: var alltargets = new Array('$alltargets');
18646: var insttypes = new Array('$allinsttypes');
1.151 raeburn 18647: var offloadtypes = new Array('primary','default');
18648:
1.171 raeburn 18649: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
18650: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 18651:
1.151 raeburn 18652: for (var i=0; i<offloadtypes.length; i++) {
18653: var count = 0;
18654: for (var j=0; j<alltargets.length; j++) {
18655: if (alltargets[j] != balancer) {
1.171 raeburn 18656: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
18657: item.value = alltargets[j];
18658: item.style.textAlign='left';
18659: item.style.textFace='normal';
18660: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
18661: if (currBalancers.indexOf(alltargets[j]) == -1) {
18662: item.disabled = '';
18663: } else {
18664: item.disabled = 'disabled';
18665: item.checked = false;
18666: }
1.151 raeburn 18667: count ++;
18668: }
1.150 raeburn 18669: }
18670: }
1.151 raeburn 18671: for (var k=0; k<insttypes.length; k++) {
18672: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 18673: if (ishomedom == 1) {
1.171 raeburn 18674: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18675: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18676: } else {
1.171 raeburn 18677: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18678: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 18679: }
18680: } else {
1.171 raeburn 18681: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
18682: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 18683: }
1.151 raeburn 18684: if ((insttypes[k] != '_LC_external') &&
18685: ((insttypes[k] != '_LC_internetdom') ||
18686: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 18687: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
18688: item.options.length = 0;
18689: item.options[0] = new Option("","",true,true);
1.210 raeburn 18690: var idx = 0;
1.151 raeburn 18691: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 18692: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
18693: idx ++;
18694: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 18695: }
18696: }
18697: }
18698: }
18699: return;
18700: }
18701:
1.171 raeburn 18702: function hideSpares(balnum) {
1.150 raeburn 18703: var alltargets = new Array('$alltargets');
18704: var insttypes = new Array('$allinsttypes');
18705: var offloadtypes = new Array('primary','default');
18706:
1.171 raeburn 18707: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
18708: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 18709:
18710: var total = alltargets.length - 1;
18711: for (var i=0; i<offloadtypes; i++) {
18712: for (var j=0; j<total; j++) {
1.171 raeburn 18713: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
18714: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
18715: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 18716: }
1.150 raeburn 18717: }
18718: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 18719: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
18720: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 18721: if (insttypes[k] != '_LC_external') {
1.171 raeburn 18722: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
18723: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 18724: }
18725: }
18726: return;
18727: }
18728:
1.171 raeburn 18729: function checkOffloads(item,balnum,type) {
1.150 raeburn 18730: var alltargets = new Array('$alltargets');
18731: var offloadtypes = new Array('primary','default');
18732: if (item.checked) {
18733: var total = alltargets.length - 1;
18734: var other;
18735: if (type == offloadtypes[0]) {
1.151 raeburn 18736: other = offloadtypes[1];
1.150 raeburn 18737: } else {
1.151 raeburn 18738: other = offloadtypes[0];
1.150 raeburn 18739: }
18740: for (var i=0; i<total; i++) {
1.171 raeburn 18741: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 18742: if (server == item.value) {
1.171 raeburn 18743: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
18744: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 18745: }
18746: }
18747: }
18748: }
18749: return;
18750: }
18751:
1.171 raeburn 18752: function singleServerToggle(balnum,type) {
18753: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 18754: if (offloadtoSelIdx == 0) {
1.171 raeburn 18755: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
18756: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18757:
18758: } else {
1.171 raeburn 18759: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
18760: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 18761: }
18762: return;
18763: }
18764:
1.171 raeburn 18765: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 18766: if (type == '_LC_external') {
1.171 raeburn 18767: return;
1.150 raeburn 18768: }
1.171 raeburn 18769: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 18770: for (var i=0; i<typesRules.length; i++) {
18771: if (formname.elements[typesRules[i]].checked) {
18772: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 18773: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
18774: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 18775: } else {
1.171 raeburn 18776: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
18777: }
18778: }
18779: }
18780: return;
18781: }
18782:
18783: function balancerDeleteChange(balnum) {
18784: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
18785: var baltotal = document.getElementById('loadbalancing_total').value;
18786: var addtarget;
18787: var removetarget;
18788: var action = 'delete';
18789: if (document.getElementById('loadbalancing_delete_'+balnum)) {
18790: var lonhost = hostitem.value;
18791: var currIdx = currBalancers.indexOf(lonhost);
18792: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
18793: if (currIdx != -1) {
18794: currBalancers.splice(currIdx,1);
18795: }
18796: addtarget = lonhost;
18797: } else {
18798: if (currIdx == -1) {
18799: currBalancers.push(lonhost);
18800: }
18801: removetarget = lonhost;
18802: action = 'undelete';
18803: }
18804: balancerChange(balnum,baltotal,action,addtarget,removetarget);
18805: }
18806: return;
18807: }
18808:
18809: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
18810: if (baltotal > 1) {
18811: var offloadtypes = new Array('primary','default');
18812: var alltargets = new Array('$alltargets');
18813: var insttypes = new Array('$allinsttypes');
18814: for (var i=0; i<baltotal; i++) {
18815: if (i != balnum) {
18816: for (var j=0; j<offloadtypes.length; j++) {
18817: var total = alltargets.length - 1;
18818: for (var k=0; k<total; k++) {
18819: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
18820: var server = serveritem.value;
18821: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18822: if (server == addtarget) {
18823: serveritem.disabled = '';
18824: }
18825: }
18826: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18827: if (server == removetarget) {
18828: serveritem.disabled = 'disabled';
18829: serveritem.checked = false;
18830: }
18831: }
18832: }
18833: }
18834: for (var j=0; j<insttypes.length; j++) {
18835: if (insttypes[j] != '_LC_external') {
18836: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
18837: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
18838: var currSel = singleserver.selectedIndex;
18839: var currVal = singleserver.options[currSel].value;
18840: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
18841: var numoptions = singleserver.options.length;
18842: var needsnew = 1;
18843: for (var k=0; k<numoptions; k++) {
18844: if (singleserver.options[k] == addtarget) {
18845: needsnew = 0;
18846: break;
18847: }
18848: }
18849: if (needsnew == 1) {
18850: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
18851: }
18852: }
18853: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
18854: singleserver.options.length = 0;
18855: if ((currVal) && (currVal != removetarget)) {
18856: singleserver.options[0] = new Option("","",false,false);
18857: } else {
18858: singleserver.options[0] = new Option("","",true,true);
18859: }
18860: var idx = 0;
18861: for (var m=0; m<alltargets.length; m++) {
18862: if (currBalancers.indexOf(alltargets[m]) == -1) {
18863: idx ++;
18864: if (currVal == alltargets[m]) {
18865: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
18866: } else {
18867: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
18868: }
18869: }
18870: }
18871: }
18872: }
18873: }
18874: }
1.150 raeburn 18875: }
18876: }
18877: }
18878: return;
18879: }
18880:
1.152 raeburn 18881: // ]]>
18882: </script>
18883:
18884: END
18885: }
18886:
18887: sub new_spares_js {
18888: my @sparestypes = ('primary','default');
18889: my $types = join("','",@sparestypes);
18890: my $select = &mt('Select');
18891: return <<"END";
18892:
18893: <script type="text/javascript">
18894: // <![CDATA[
18895:
18896: function updateNewSpares(formname,lonhost) {
18897: var types = new Array('$types');
18898: var include = new Array();
18899: var exclude = new Array();
18900: for (var i=0; i<types.length; i++) {
18901: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
18902: for (var j=0; j<spareboxes.length; j++) {
18903: if (formname.elements[spareboxes[j]].checked) {
18904: exclude.push(formname.elements[spareboxes[j]].value);
18905: } else {
18906: include.push(formname.elements[spareboxes[j]].value);
18907: }
18908: }
18909: }
18910: for (var i=0; i<types.length; i++) {
18911: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
18912: var selIdx = newSpare.selectedIndex;
18913: var currnew = newSpare.options[selIdx].value;
18914: var okSpares = new Array();
18915: for (var j=0; j<newSpare.options.length; j++) {
18916: var possible = newSpare.options[j].value;
18917: if (possible != '') {
18918: if (exclude.indexOf(possible) == -1) {
18919: okSpares.push(possible);
18920: } else {
18921: if (currnew == possible) {
18922: selIdx = 0;
18923: }
18924: }
18925: }
18926: }
18927: for (var k=0; k<include.length; k++) {
18928: if (okSpares.indexOf(include[k]) == -1) {
18929: okSpares.push(include[k]);
18930: }
18931: }
18932: okSpares.sort();
18933: newSpare.options.length = 0;
18934: if (selIdx == 0) {
18935: newSpare.options[0] = new Option("$select","",true,true);
18936: } else {
18937: newSpare.options[0] = new Option("$select","",false,false);
18938: }
18939: for (var m=0; m<okSpares.length; m++) {
18940: var idx = m+1;
18941: var selThis = 0;
18942: if (selIdx != 0) {
18943: if (okSpares[m] == currnew) {
18944: selThis = 1;
18945: }
18946: }
18947: if (selThis == 1) {
18948: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
18949: } else {
18950: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
18951: }
18952: }
18953: }
18954: return;
18955: }
18956:
18957: function checkNewSpares(lonhost,type) {
18958: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
18959: var chosen = newSpare.options[newSpare.selectedIndex].value;
18960: if (chosen != '') {
18961: var othertype;
18962: var othernewSpare;
18963: if (type == 'primary') {
18964: othernewSpare = document.getElementById('newspare_default_'+lonhost);
18965: }
18966: if (type == 'default') {
18967: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
18968: }
18969: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
18970: othernewSpare.selectedIndex = 0;
18971: }
18972: }
18973: return;
18974: }
18975:
18976: // ]]>
18977: </script>
18978:
18979: END
18980:
18981: }
18982:
18983: sub common_domprefs_js {
18984: return <<"END";
18985:
18986: <script type="text/javascript">
18987: // <![CDATA[
18988:
1.150 raeburn 18989: function getIndicesByName(formname,item) {
1.152 raeburn 18990: var group = new Array();
1.150 raeburn 18991: for (var i=0;i<formname.elements.length;i++) {
18992: if (formname.elements[i].name == item) {
1.152 raeburn 18993: group.push(formname.elements[i].id);
1.150 raeburn 18994: }
18995: }
1.152 raeburn 18996: return group;
1.150 raeburn 18997: }
18998:
18999: // ]]>
19000: </script>
19001:
19002: END
1.152 raeburn 19003:
1.150 raeburn 19004: }
19005:
1.165 raeburn 19006: sub recaptcha_js {
19007: my %lt = &captcha_phrases();
19008: return <<"END";
19009:
19010: <script type="text/javascript">
19011: // <![CDATA[
19012:
19013: function updateCaptcha(caller,context) {
19014: var privitem;
19015: var pubitem;
19016: var privtext;
19017: var pubtext;
1.269 raeburn 19018: var versionitem;
19019: var versiontext;
1.165 raeburn 19020: if (document.getElementById(context+'_recaptchapub')) {
19021: pubitem = document.getElementById(context+'_recaptchapub');
19022: } else {
19023: return;
19024: }
19025: if (document.getElementById(context+'_recaptchapriv')) {
19026: privitem = document.getElementById(context+'_recaptchapriv');
19027: } else {
19028: return;
19029: }
19030: if (document.getElementById(context+'_recaptchapubtxt')) {
19031: pubtext = document.getElementById(context+'_recaptchapubtxt');
19032: } else {
19033: return;
19034: }
19035: if (document.getElementById(context+'_recaptchaprivtxt')) {
19036: privtext = document.getElementById(context+'_recaptchaprivtxt');
19037: } else {
19038: return;
19039: }
1.269 raeburn 19040: if (document.getElementById(context+'_recaptchaversion')) {
19041: versionitem = document.getElementById(context+'_recaptchaversion');
19042: } else {
19043: return;
19044: }
19045: if (document.getElementById(context+'_recaptchavertxt')) {
19046: versiontext = document.getElementById(context+'_recaptchavertxt');
19047: } else {
19048: return;
19049: }
1.165 raeburn 19050: if (caller.checked) {
19051: if (caller.value == 'recaptcha') {
19052: pubitem.type = 'text';
19053: privitem.type = 'text';
19054: pubitem.size = '40';
19055: privitem.size = '40';
19056: pubtext.innerHTML = "$lt{'pub'}";
19057: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 19058: versionitem.type = 'text';
19059: versionitem.size = '3';
1.289 raeburn 19060: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 19061: } else {
19062: pubitem.type = 'hidden';
19063: privitem.type = 'hidden';
1.269 raeburn 19064: versionitem.type = 'hidden';
1.165 raeburn 19065: pubtext.innerHTML = '';
19066: privtext.innerHTML = '';
1.269 raeburn 19067: versiontext.innerHTML = '';
1.165 raeburn 19068: }
19069: }
19070: return;
19071: }
19072:
19073: // ]]>
19074: </script>
19075:
19076: END
19077:
19078: }
19079:
1.236 raeburn 19080: sub toggle_display_js {
1.192 raeburn 19081: return <<"END";
19082:
19083: <script type="text/javascript">
19084: // <![CDATA[
19085:
1.236 raeburn 19086: function toggleDisplay(domForm,caller) {
19087: if (document.getElementById(caller)) {
19088: var divitem = document.getElementById(caller);
19089: var optionsElement = domForm.coursecredits;
1.264 raeburn 19090: var checkval = 1;
19091: var dispval = 'block';
1.303 raeburn 19092: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 19093: if (caller == 'emailoptions') {
19094: optionsElement = domForm.cancreate_email;
19095: }
1.257 raeburn 19096: if (caller == 'studentsubmission') {
19097: optionsElement = domForm.postsubmit;
19098: }
1.264 raeburn 19099: if (caller == 'cloneinstcode') {
19100: optionsElement = domForm.canclone;
19101: checkval = 'instcode';
19102: }
1.303 raeburn 19103: if (selfcreateRegExp.test(caller)) {
19104: optionsElement = domForm.elements[caller];
19105: checkval = 'other';
19106: dispval = 'inline'
19107: }
1.236 raeburn 19108: if (optionsElement.length) {
1.192 raeburn 19109: var currval;
1.236 raeburn 19110: for (var i=0; i<optionsElement.length; i++) {
19111: if (optionsElement[i].checked) {
19112: currval = optionsElement[i].value;
1.192 raeburn 19113: }
19114: }
1.264 raeburn 19115: if (currval == checkval) {
19116: divitem.style.display = dispval;
1.192 raeburn 19117: } else {
1.236 raeburn 19118: divitem.style.display = 'none';
1.192 raeburn 19119: }
19120: }
19121: }
19122: return;
19123: }
19124:
19125: // ]]>
19126: </script>
19127:
19128: END
19129:
19130: }
19131:
1.165 raeburn 19132: sub captcha_phrases {
19133: return &Apache::lonlocal::texthash (
19134: priv => 'Private key',
19135: pub => 'Public key',
19136: original => 'original (CAPTCHA)',
19137: recaptcha => 'successor (ReCAPTCHA)',
19138: notused => 'unused',
1.289 raeburn 19139: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 19140: );
19141: }
19142:
1.205 raeburn 19143: sub devalidate_remote_domconfs {
1.212 raeburn 19144: my ($dom,$cachekeys) = @_;
19145: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 19146: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19147: my %thismachine;
19148: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 ! raeburn 19149: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
! 19150: 'directorysrch','passwdconf');
1.260 raeburn 19151: if (keys(%servers)) {
1.205 raeburn 19152: foreach my $server (keys(%servers)) {
19153: next if ($thismachine{$server});
1.212 raeburn 19154: my @cached;
19155: foreach my $name (@posscached) {
19156: if ($cachekeys->{$name}) {
19157: push(@cached,&escape($name).':'.&escape($dom));
19158: }
19159: }
19160: if (@cached) {
19161: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19162: }
1.205 raeburn 19163: }
19164: }
19165: return;
19166: }
19167:
1.3 raeburn 19168: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>