Annotation of loncom/interface/domainprefs.pm, revision 1.362
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.362 ! raeburn 4: # $Id: domainprefs.pm,v 1.361 2019/05/14 13:39:24 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.357 raeburn 222: 'ltitools','ssl','trust','lti','privacy','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.357 raeburn 250: 'autoupdate','autocreate','directorysrch','contacts','privacy',
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' =>
1.357 raeburn 500: {text => 'Availability of User Information',
1.120 raeburn 501: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 502: header => [{col1 => 'Role assigned in different domain',
503: col2 => 'Approval options'},
504: {col1 => 'Role assigned in different domain to user of type',
505: col2 => 'User information available in that domain'},
506: {col1 => "Role assigned in user's domain",
507: col2 => 'Information viewable by privileged user'},
508: {col1 => "Role assigned in user's domain",
509: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 510: print => \&print_privacy,
511: modify => \&modify_privacy,
1.120 raeburn 512: },
1.141 raeburn 513: 'usersessions' =>
1.145 raeburn 514: {text => 'User session hosting/offloading',
1.137 raeburn 515: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 516: header => [{col1 => 'Domain server',
517: col2 => 'Servers to offload sessions to when busy'},
518: {col1 => 'Hosting of users from other domains',
1.137 raeburn 519: col2 => 'Rules'},
520: {col1 => "Hosting domain's own users elsewhere",
521: col2 => 'Rules'}],
1.230 raeburn 522: print => \&print_usersessions,
523: modify => \&modify_usersessions,
1.137 raeburn 524: },
1.279 raeburn 525: 'loadbalancing' =>
1.185 raeburn 526: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 527: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 528: header => [{col1 => 'Balancers',
1.150 raeburn 529: col2 => 'Default destinations',
1.183 bisitz 530: col3 => 'User affiliation',
1.150 raeburn 531: col4 => 'Overrides'},
532: ],
1.230 raeburn 533: print => \&print_loadbalancing,
534: modify => \&modify_loadbalancing,
1.150 raeburn 535: },
1.279 raeburn 536: 'ltitools' =>
1.267 raeburn 537: {text => 'External Tools (LTI)',
1.296 raeburn 538: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 539: header => [{col1 => 'Setting',
540: col2 => 'Value',}],
541: print => \&print_ltitools,
542: modify => \&modify_ltitools,
543: },
1.279 raeburn 544: 'ssl' =>
1.275 raeburn 545: {text => 'LON-CAPA Network (SSL)',
546: help => 'Domain_Configuration_Network_SSL',
547: header => [{col1 => 'Server',
548: col2 => 'Certificate Status'},
549: {col1 => 'Connections to other servers',
550: col2 => 'Rules'},
1.293 raeburn 551: {col1 => 'Connections from other servers',
552: col2 => 'Rules'},
1.275 raeburn 553: {col1 => "Replicating domain's published content",
554: col2 => 'Rules'}],
555: print => \&print_ssl,
556: modify => \&modify_ssl,
557: },
1.279 raeburn 558: 'trust' =>
559: {text => 'Trust Settings',
560: help => 'Domain_Configuration_Trust',
561: header => [{col1 => "Access to this domain's content by others",
562: col2 => 'Rules'},
563: {col1 => "Access to other domain's content by this domain",
564: col2 => 'Rules'},
565: {col1 => "Enrollment in this domain's courses by others",
566: col2 => 'Rules',},
567: {col1 => "Co-author roles in this domain for others",
568: col2 => 'Rules',},
569: {col1 => "Co-author roles for this domain's users elsewhere",
570: col2 => 'Rules',},
571: {col1 => "Domain roles in this domain assignable to others",
572: col2 => 'Rules'},
573: {col1 => "Course catalog for this domain displayed elsewhere",
574: col2 => 'Rules'},
575: {col1 => "Requests for creation of courses in this domain by others",
576: col2 => 'Rules'},
577: {col1 => "Users in other domains can send messages to this domain",
578: col2 => 'Rules'},],
579: print => \&print_trust,
580: modify => \&modify_trust,
581: },
1.320 raeburn 582: 'lti' =>
583: {text => 'LTI Provider',
584: help => 'Domain_Configuration_LTI_Provider',
585: header => [{col1 => 'Setting',
586: col2 => 'Value',}],
587: print => \&print_lti,
588: modify => \&modify_lti,
589: },
1.3 raeburn 590: );
1.110 raeburn 591: if (keys(%servers) > 1) {
592: $prefs{'login'} = { text => 'Log-in page options',
593: help => 'Domain_Configuration_Login_Page',
594: header => [{col1 => 'Log-in Service',
595: col2 => 'Server Setting',},
596: {col1 => 'Log-in Page Items',
1.168 raeburn 597: col2 => ''},
598: {col1 => 'Log-in Help',
1.256 raeburn 599: col2 => 'Value'},
600: {col1 => 'Custom HTML in document head',
1.168 raeburn 601: col2 => 'Value'}],
1.230 raeburn 602: print => \&print_login,
603: modify => \&modify_login,
1.110 raeburn 604: };
605: }
1.174 foxr 606:
1.6 raeburn 607: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 608: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 609: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 610: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 611: text=>"Settings to display/modify"});
1.9 raeburn 612: my $confname = $dom.'-domainconfig';
1.174 foxr 613:
1.3 raeburn 614: if ($phase eq 'process') {
1.212 raeburn 615: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
616: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 617: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 618: $r->rflush();
1.212 raeburn 619: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 620: }
1.30 raeburn 621: } elsif ($phase eq 'display') {
1.192 raeburn 622: my $js = &recaptcha_js().
1.236 raeburn 623: &toggle_display_js();
1.171 raeburn 624: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 625: my ($othertitle,$usertypes,$types) =
626: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 627: $js .= &lonbalance_targets_js($dom,$types,\%servers,
628: $domconfig{'loadbalancing'}).
1.170 raeburn 629: &new_spares_js().
630: &common_domprefs_js().
631: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 632: }
1.216 raeburn 633: if (grep(/^requestcourses$/,@actions)) {
634: my $javascript_validations;
635: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
636: $js .= <<END;
637: <script type="text/javascript">
638: $javascript_validations
639: </script>
640: $coursebrowserjs
641: END
642: }
1.305 raeburn 643: if (grep(/^selfcreation$/,@actions)) {
644: $js .= &selfcreate_javascript();
645: }
1.286 raeburn 646: if (grep(/^contacts$/,@actions)) {
647: $js .= &contacts_javascript();
648: }
1.346 raeburn 649: if (grep(/^scantron$/,@actions)) {
650: $js .= &scantron_javascript();
651: }
1.150 raeburn 652: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 653: } else {
1.180 raeburn 654: # check if domconfig user exists for the domain.
655: my $servadm = $r->dir_config('lonAdmEMail');
656: my ($configuserok,$author_ok,$switchserver) =
657: &config_check($dom,$confname,$servadm);
658: unless ($configuserok eq 'ok') {
1.181 raeburn 659: &Apache::lonconfigsettings::print_header($r,$phase,$context);
660: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 661: $confname).
1.181 raeburn 662: '<br />'
663: );
1.180 raeburn 664: if ($switchserver) {
1.181 raeburn 665: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
666: '<br />'.
667: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
668: '<br />'.
669: &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).
670: '<br />'.
671: &mt('To do that now, use the following link: [_1]',$switchserver)
672: );
673: } else {
674: $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.').
675: '<br />'.
676: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
677: );
1.180 raeburn 678: }
679: $r->print(&Apache::loncommon::end_page());
680: return OK;
681: }
1.21 raeburn 682: if (keys(%domconfig) == 0) {
683: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 684: my @ids=&Apache::lonnet::current_machine_ids();
685: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 686: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 687: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 688: my $custom_img_count = 0;
689: foreach my $img (@loginimages) {
690: if ($designhash{$dom.'.login.'.$img} ne '') {
691: $custom_img_count ++;
692: }
693: }
694: foreach my $role (@roles) {
695: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
696: $custom_img_count ++;
697: }
698: }
699: if ($custom_img_count > 0) {
1.94 raeburn 700: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 701: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 702: $r->print(
703: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
704: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
705: &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 />'.
706: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
707: if ($switch_server) {
1.30 raeburn 708: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 709: }
1.91 raeburn 710: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 711: return OK;
712: }
713: }
714: }
1.91 raeburn 715: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 716: }
717: return OK;
718: }
719:
720: sub process_changes {
1.205 raeburn 721: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 722: my %domconfig;
723: if (ref($values) eq 'HASH') {
724: %domconfig = %{$values};
725: }
1.3 raeburn 726: my $output;
727: if ($action eq 'login') {
1.205 raeburn 728: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 729: } elsif ($action eq 'rolecolors') {
1.9 raeburn 730: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 731: $lastactref,%domconfig);
1.3 raeburn 732: } elsif ($action eq 'quotas') {
1.216 raeburn 733: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 734: } elsif ($action eq 'autoenroll') {
1.205 raeburn 735: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 736: } elsif ($action eq 'autoupdate') {
737: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 738: } elsif ($action eq 'autocreate') {
739: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 740: } elsif ($action eq 'directorysrch') {
1.295 raeburn 741: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 742: } elsif ($action eq 'usercreation') {
1.28 raeburn 743: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 744: } elsif ($action eq 'selfcreation') {
1.305 raeburn 745: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 746: } elsif ($action eq 'usermodification') {
747: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 748: } elsif ($action eq 'contacts') {
1.205 raeburn 749: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 750: } elsif ($action eq 'defaults') {
1.212 raeburn 751: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 752: } elsif ($action eq 'scantron') {
1.205 raeburn 753: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 754: } elsif ($action eq 'coursecategories') {
1.239 raeburn 755: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 756: } elsif ($action eq 'serverstatuses') {
757: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 758: } elsif ($action eq 'requestcourses') {
1.216 raeburn 759: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 760: } elsif ($action eq 'requestauthor') {
1.216 raeburn 761: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 762: } elsif ($action eq 'helpsettings') {
1.285 raeburn 763: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 764: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 765: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 766: } elsif ($action eq 'selfenrollment') {
767: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 768: } elsif ($action eq 'usersessions') {
1.212 raeburn 769: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 770: } elsif ($action eq 'loadbalancing') {
771: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 772: } elsif ($action eq 'ltitools') {
773: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 774: } elsif ($action eq 'ssl') {
775: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 776: } elsif ($action eq 'trust') {
777: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 778: } elsif ($action eq 'lti') {
779: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 780: } elsif ($action eq 'privacy') {
781: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 782: } elsif ($action eq 'passwords') {
783: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3 raeburn 784: }
785: return $output;
786: }
787:
788: sub print_config_box {
1.9 raeburn 789: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 790: my $rowtotal = 0;
1.49 raeburn 791: my $output;
792: if ($action eq 'coursecategories') {
793: $output = &coursecategories_javascript($settings);
1.236 raeburn 794: } elsif ($action eq 'defaults') {
795: $output = &defaults_javascript($settings);
1.354 raeburn 796: } elsif ($action eq 'passwords') {
797: $output = &passwords_javascript();
1.282 raeburn 798: } elsif ($action eq 'helpsettings') {
799: my (%privs,%levelscurrent);
800: my %full=();
801: my %levels=(
802: course => {},
803: domain => {},
804: system => {},
805: );
806: my $context = 'domain';
807: my $crstype = 'Course';
808: my $formname = 'display';
809: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
810: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
811: $output =
812: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
813: \@templateroles);
1.334 raeburn 814: } elsif ($action eq 'ltitools') {
815: $output .= <itools_javascript($settings);
816: } elsif ($action eq 'lti') {
817: $output .= <i_javascript($settings);
1.91 raeburn 818: }
1.236 raeburn 819: $output .=
1.30 raeburn 820: '<table class="LC_nested_outer">
1.3 raeburn 821: <tr>
1.306 raeburn 822: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 823: &mt($item->{text}).' '.
824: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
825: '</tr>';
1.30 raeburn 826: $rowtotal ++;
1.110 raeburn 827: my $numheaders = 1;
828: if (ref($item->{'header'}) eq 'ARRAY') {
829: $numheaders = scalar(@{$item->{'header'}});
830: }
831: if ($numheaders > 1) {
1.64 raeburn 832: my $colspan = '';
1.145 raeburn 833: my $rightcolspan = '';
1.238 raeburn 834: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 835: ($action eq 'directorysrch') ||
1.256 raeburn 836: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 837: $colspan = ' colspan="2"';
838: }
1.145 raeburn 839: if ($action eq 'usersessions') {
840: $rightcolspan = ' colspan="3"';
841: }
1.30 raeburn 842: $output .= '
1.3 raeburn 843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
1.59 bisitz 847: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 848: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 849: </tr>';
1.69 raeburn 850: $rowtotal ++;
1.230 raeburn 851: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 852: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 853: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 854: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.357 raeburn 855: ($action eq 'contacts') || ($action eq 'privacy')) {
1.230 raeburn 856: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 857: } elsif ($action eq 'passwords') {
858: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 859: } elsif ($action eq 'coursecategories') {
1.230 raeburn 860: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 861: } elsif ($action eq 'scantron') {
862: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 863: } elsif ($action eq 'login') {
1.256 raeburn 864: if ($numheaders == 4) {
1.168 raeburn 865: $colspan = ' colspan="2"';
866: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
867: } else {
868: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
869: }
1.230 raeburn 870: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 871: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 872: } elsif ($action eq 'rolecolors') {
1.30 raeburn 873: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 874: }
1.30 raeburn 875: $output .= '
1.6 raeburn 876: </table>
877: </td>
878: </tr>
879: <tr>
880: <td>
881: <table class="LC_nested">
882: <tr class="LC_info_row">
1.230 raeburn 883: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 884: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 885: </tr>';
886: $rowtotal ++;
1.230 raeburn 887: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
888: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 889: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.357 raeburn 890: ($action eq 'trust') || ($action eq 'contacts') ||
891: ($action eq 'privacy') || ($action eq 'passwords')) {
1.238 raeburn 892: if ($action eq 'coursecategories') {
893: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
894: $colspan = ' colspan="2"';
1.279 raeburn 895: } elsif ($action eq 'trust') {
896: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 897: } elsif ($action eq 'passwords') {
898: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 899: } else {
900: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
901: }
1.279 raeburn 902: if ($action eq 'trust') {
903: $output .= '
904: </table>
905: </td>
906: </tr>';
907: my @trusthdrs = qw(2 3 4 5 6 7);
908: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
909: for (my $i=0; $i<@trusthdrs; $i++) {
910: $output .= '
911: <tr>
912: <td>
913: <table class="LC_nested">
914: <tr class="LC_info_row">
915: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
916: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
917: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
918: </table>
919: </td>
920: </tr>';
921: }
922: $output .= '
923: <tr>
924: <td>
925: <table class="LC_nested">
926: <tr class="LC_info_row">
927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
928: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
929: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
930: } else {
931: $output .= '
1.63 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
939: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 940: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 941: </tr>'."\n";
1.279 raeburn 942: if ($action eq 'coursecategories') {
943: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357 raeburn 944: } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354 raeburn 945: if ($action eq 'passwords') {
946: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
947: } else {
948: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
949: }
950: $output .= '
1.340 raeburn 951: </tr>
952: </table>
953: </td>
954: </tr>
955: <tr>
956: <td>
957: <table class="LC_nested">
958: <tr class="LC_info_row">
959: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 960: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
961: if ($action eq 'passwords') {
962: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
963: } else {
964: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
965: }
966: $output .= '
1.340 raeburn 967: </table>
968: </td>
969: </tr>
970: <tr>';
1.279 raeburn 971: } else {
972: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
973: }
1.238 raeburn 974: }
1.63 raeburn 975: $rowtotal ++;
1.236 raeburn 976: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 977: ($action eq 'defaults') || ($action eq 'directorysrch') ||
978: ($action eq 'helpsettings')) {
1.230 raeburn 979: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 980: } elsif ($action eq 'scantron') {
981: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 982: } elsif ($action eq 'ssl') {
983: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
984: </table>
985: </td>
986: </tr>
987: <tr>
988: <td>
989: <table class="LC_nested">
990: <tr class="LC_info_row">
991: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
992: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
993: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
994: </table>
995: </td>
996: </tr>
997: <tr>
998: <td>
999: <table class="LC_nested">
1000: <tr class="LC_info_row">
1001: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1002: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1003: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1004: } elsif ($action eq 'login') {
1.256 raeburn 1005: if ($numheaders == 4) {
1.168 raeburn 1006: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1007: </table>
1008: </td>
1009: </tr>
1010: <tr>
1011: <td>
1012: <table class="LC_nested">
1013: <tr class="LC_info_row">
1014: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1015: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1016: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1017: $rowtotal ++;
1018: } else {
1019: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1020: }
1.256 raeburn 1021: $output .= '
1022: </table>
1023: </td>
1024: </tr>
1025: <tr>
1026: <td>
1027: <table class="LC_nested">
1028: <tr class="LC_info_row">';
1029: if ($numheaders == 4) {
1030: $output .= '
1031: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1032: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1033: </tr>';
1034: } else {
1035: $output .= '
1036: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1037: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1038: </tr>';
1039: }
1040: $rowtotal ++;
1041: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1042: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1043: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1044: $rowtotal ++;
1045: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1055: &textbookcourses_javascript($settings).
1056: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1057: </table>
1058: </td>
1059: </tr>
1060: <tr>
1061: <td>
1062: <table class="LC_nested">
1063: <tr class="LC_info_row">
1064: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1065: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1066: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1067: </table>
1068: </td>
1069: </tr>
1070: <tr>
1071: <td>
1072: <table class="LC_nested">
1073: <tr class="LC_info_row">
1.306 raeburn 1074: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1075: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1076: </tr>'.
1077: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1078: } elsif ($action eq 'requestauthor') {
1079: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1080: $rowtotal ++;
1.122 jms 1081: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1082: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1083: </table>
1084: </td>
1085: </tr>
1086: <tr>
1087: <td>
1088: <table class="LC_nested">
1089: <tr class="LC_info_row">
1.306 raeburn 1090: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1091: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1092: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1093: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1094: </tr>'.
1.30 raeburn 1095: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1096: </table>
1097: </td>
1098: </tr>
1099: <tr>
1100: <td>
1101: <table class="LC_nested">
1102: <tr class="LC_info_row">
1.59 bisitz 1103: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1104: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1105: </tr>'.
1.30 raeburn 1106: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1107: $rowtotal += 2;
1.6 raeburn 1108: }
1.3 raeburn 1109: } else {
1.30 raeburn 1110: $output .= '
1.3 raeburn 1111: <tr>
1112: <td>
1113: <table class="LC_nested">
1.30 raeburn 1114: <tr class="LC_info_row">';
1.277 raeburn 1115: if ($action eq 'login') {
1.30 raeburn 1116: $output .= '
1.59 bisitz 1117: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1118: } elsif ($action eq 'serverstatuses') {
1119: $output .= '
1.306 raeburn 1120: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1121: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1122:
1.6 raeburn 1123: } else {
1.30 raeburn 1124: $output .= '
1.306 raeburn 1125: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1126: }
1.72 raeburn 1127: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1128: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1129: &mt($item->{'header'}->[0]->{'col2'});
1130: if ($action eq 'serverstatuses') {
1131: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1132: }
1.69 raeburn 1133: } else {
1.306 raeburn 1134: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1135: &mt($item->{'header'}->[0]->{'col2'});
1136: }
1137: $output .= '</td>';
1138: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1139: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1140: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1141: &mt($item->{'header'}->[0]->{'col3'});
1142: } else {
1.306 raeburn 1143: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1144: &mt($item->{'header'}->[0]->{'col3'});
1145: }
1.69 raeburn 1146: if ($action eq 'serverstatuses') {
1147: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1148: }
1149: $output .= '</td>';
1.6 raeburn 1150: }
1.150 raeburn 1151: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1152: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1153: &mt($item->{'header'}->[0]->{'col4'});
1154: }
1.69 raeburn 1155: $output .= '</tr>';
1.48 raeburn 1156: $rowtotal ++;
1.168 raeburn 1157: if ($action eq 'quotas') {
1.86 raeburn 1158: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1159: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1160: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.320 raeburn 1161: ($action eq 'ltitools') || ($action eq 'lti')) {
1.230 raeburn 1162: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1163: }
1.3 raeburn 1164: }
1.30 raeburn 1165: $output .= '
1.3 raeburn 1166: </table>
1167: </td>
1168: </tr>
1.30 raeburn 1169: </table><br />';
1170: return ($output,$rowtotal);
1.1 raeburn 1171: }
1172:
1.3 raeburn 1173: sub print_login {
1.168 raeburn 1174: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1175: my ($css_class,$datatable);
1.6 raeburn 1176: my %choices = &login_choices();
1.110 raeburn 1177:
1.168 raeburn 1178: if ($caller eq 'service') {
1.149 raeburn 1179: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1180: my $choice = $choices{'disallowlogin'};
1181: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1182: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1183: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1184: '<th>'.$choices{'server'}.'</th>'.
1185: '<th>'.$choices{'serverpath'}.'</th>'.
1186: '<th>'.$choices{'custompath'}.'</th>'.
1187: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1188: my %disallowed;
1189: if (ref($settings) eq 'HASH') {
1190: if (ref($settings->{'loginvia'}) eq 'HASH') {
1191: %disallowed = %{$settings->{'loginvia'}};
1192: }
1193: }
1194: foreach my $lonhost (sort(keys(%servers))) {
1195: my $direct = 'selected="selected"';
1.128 raeburn 1196: if (ref($disallowed{$lonhost}) eq 'HASH') {
1197: if ($disallowed{$lonhost}{'server'} ne '') {
1198: $direct = '';
1199: }
1.110 raeburn 1200: }
1.115 raeburn 1201: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1202: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1203: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1204: '</option>';
1.184 raeburn 1205: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1206: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1207: my $selected = '';
1.128 raeburn 1208: if (ref($disallowed{$lonhost}) eq 'HASH') {
1209: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1210: $selected = 'selected="selected"';
1211: }
1.110 raeburn 1212: }
1213: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1214: $servers{$hostid}.'</option>';
1215: }
1.128 raeburn 1216: $datatable .= '</select></td>'.
1217: '<td><select name="'.$lonhost.'_serverpath">';
1218: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1219: my $pathname = $path;
1220: if ($path eq 'custom') {
1221: $pathname = &mt('Custom Path').' ->';
1222: }
1223: my $selected = '';
1224: if (ref($disallowed{$lonhost}) eq 'HASH') {
1225: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1226: $selected = 'selected="selected"';
1227: }
1228: } elsif ($path eq '') {
1229: $selected = 'selected="selected"';
1230: }
1231: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1232: }
1233: $datatable .= '</select></td>';
1234: my ($custom,$exempt);
1235: if (ref($disallowed{$lonhost}) eq 'HASH') {
1236: $custom = $disallowed{$lonhost}{'custompath'};
1237: $exempt = $disallowed{$lonhost}{'exempt'};
1238: }
1239: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1240: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1241: '</tr>';
1.110 raeburn 1242: }
1243: $datatable .= '</table></td></tr>';
1244: return $datatable;
1.168 raeburn 1245: } elsif ($caller eq 'page') {
1246: my %defaultchecked = (
1247: 'coursecatalog' => 'on',
1.188 raeburn 1248: 'helpdesk' => 'on',
1.168 raeburn 1249: 'adminmail' => 'off',
1250: 'newuser' => 'off',
1251: );
1.188 raeburn 1252: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1253: my (%checkedon,%checkedoff);
1.42 raeburn 1254: foreach my $item (@toggles) {
1.168 raeburn 1255: if ($defaultchecked{$item} eq 'on') {
1256: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1257: $checkedoff{$item} = ' ';
1.168 raeburn 1258: } elsif ($defaultchecked{$item} eq 'off') {
1259: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1260: $checkedon{$item} = ' ';
1261: }
1.1 raeburn 1262: }
1.168 raeburn 1263: my @images = ('img','logo','domlogo','login');
1264: my @logintext = ('textcol','bgcol');
1265: my @bgs = ('pgbg','mainbg','sidebg');
1266: my @links = ('link','alink','vlink');
1267: my %designhash = &Apache::loncommon::get_domainconf($dom);
1268: my %defaultdesign = %Apache::loncommon::defaultdesign;
1269: my (%is_custom,%designs);
1270: my %defaults = (
1271: font => $defaultdesign{'login.font'},
1272: );
1.6 raeburn 1273: foreach my $item (@images) {
1.168 raeburn 1274: $defaults{$item} = $defaultdesign{'login.'.$item};
1275: $defaults{'showlogo'}{$item} = 1;
1276: }
1277: foreach my $item (@bgs) {
1278: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1279: }
1.41 raeburn 1280: foreach my $item (@logintext) {
1.168 raeburn 1281: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1282: }
1.168 raeburn 1283: foreach my $item (@links) {
1284: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1285: }
1.168 raeburn 1286: if (ref($settings) eq 'HASH') {
1287: foreach my $item (@toggles) {
1288: if ($settings->{$item} eq '1') {
1289: $checkedon{$item} = ' checked="checked" ';
1290: $checkedoff{$item} = ' ';
1291: } elsif ($settings->{$item} eq '0') {
1292: $checkedoff{$item} = ' checked="checked" ';
1293: $checkedon{$item} = ' ';
1294: }
1295: }
1296: foreach my $item (@images) {
1297: if (defined($settings->{$item})) {
1298: $designs{$item} = $settings->{$item};
1299: $is_custom{$item} = 1;
1300: }
1301: if (defined($settings->{'showlogo'}{$item})) {
1302: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1303: }
1304: }
1305: foreach my $item (@logintext) {
1306: if ($settings->{$item} ne '') {
1307: $designs{'logintext'}{$item} = $settings->{$item};
1308: $is_custom{$item} = 1;
1309: }
1310: }
1311: if ($settings->{'font'} ne '') {
1312: $designs{'font'} = $settings->{'font'};
1313: $is_custom{'font'} = 1;
1314: }
1315: foreach my $item (@bgs) {
1316: if ($settings->{$item} ne '') {
1317: $designs{'bgs'}{$item} = $settings->{$item};
1318: $is_custom{$item} = 1;
1319: }
1320: }
1321: foreach my $item (@links) {
1322: if ($settings->{$item} ne '') {
1323: $designs{'links'}{$item} = $settings->{$item};
1324: $is_custom{$item} = 1;
1325: }
1326: }
1327: } else {
1328: if ($designhash{$dom.'.login.font'} ne '') {
1329: $designs{'font'} = $designhash{$dom.'.login.font'};
1330: $is_custom{'font'} = 1;
1331: }
1332: foreach my $item (@images) {
1333: if ($designhash{$dom.'.login.'.$item} ne '') {
1334: $designs{$item} = $designhash{$dom.'.login.'.$item};
1335: $is_custom{$item} = 1;
1336: }
1337: }
1338: foreach my $item (@bgs) {
1339: if ($designhash{$dom.'.login.'.$item} ne '') {
1340: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1341: $is_custom{$item} = 1;
1342: }
1.6 raeburn 1343: }
1.168 raeburn 1344: foreach my $item (@links) {
1345: if ($designhash{$dom.'.login.'.$item} ne '') {
1346: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1347: $is_custom{$item} = 1;
1348: }
1.6 raeburn 1349: }
1350: }
1.168 raeburn 1351: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1352: logo => 'Institution Logo',
1353: domlogo => 'Domain Logo',
1354: login => 'Login box');
1355: my $itemcount = 1;
1356: foreach my $item (@toggles) {
1357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1358: $datatable .=
1359: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1360: '</td><td>'.
1361: '<span class="LC_nobreak"><label><input type="radio" name="'.
1362: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1363: '</label> <label><input type="radio" name="'.$item.'"'.
1364: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1365: '</tr>';
1366: $itemcount ++;
1.6 raeburn 1367: }
1.168 raeburn 1368: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1369: $datatable .= '</tr></table></td></tr>';
1370: } elsif ($caller eq 'help') {
1371: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1372: my $switchserver = &check_switchserver($dom,$confname);
1373: my $itemcount = 1;
1374: $defaulturl = '/adm/loginproblems.html';
1375: $defaulttype = 'default';
1376: %lt = &Apache::lonlocal::texthash (
1377: del => 'Delete?',
1378: rep => 'Replace:',
1379: upl => 'Upload:',
1380: default => 'Default',
1381: custom => 'Custom',
1382: );
1383: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1384: my @currlangs;
1385: if (ref($settings) eq 'HASH') {
1386: if (ref($settings->{'helpurl'}) eq 'HASH') {
1387: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1388: next if ($settings->{'helpurl'}{$key} eq '');
1389: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1390: $type{$key} = 'custom';
1391: unless ($key eq 'nolang') {
1392: push(@currlangs,$key);
1393: }
1394: }
1395: } elsif ($settings->{'helpurl'} ne '') {
1396: $type{'nolang'} = 'custom';
1397: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1398: }
1399: }
1.168 raeburn 1400: foreach my $lang ('nolang',sort(@currlangs)) {
1401: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1402: $datatable .= '<tr'.$css_class.'>';
1403: if ($url{$lang} eq '') {
1404: $url{$lang} = $defaulturl;
1405: }
1406: if ($type{$lang} eq '') {
1407: $type{$lang} = $defaulttype;
1408: }
1409: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1410: if ($lang eq 'nolang') {
1411: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1412: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1413: } else {
1414: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1415: $langchoices{$lang},
1416: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1417: }
1418: $datatable .= '</span></td>'."\n".
1419: '<td class="LC_left_item">';
1420: if ($type{$lang} eq 'custom') {
1421: $datatable .= '<span class="LC_nobreak"><label>'.
1422: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1423: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1424: } else {
1425: $datatable .= $lt{'upl'};
1426: }
1427: $datatable .='<br />';
1428: if ($switchserver) {
1429: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1430: } else {
1431: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1432: }
1.168 raeburn 1433: $datatable .= '</td></tr>';
1434: $itemcount ++;
1.6 raeburn 1435: }
1.168 raeburn 1436: my @addlangs;
1437: foreach my $lang (sort(keys(%langchoices))) {
1438: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1439: push(@addlangs,$lang);
1440: }
1441: if (@addlangs > 0) {
1442: my %toadd;
1443: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1444: $toadd{''} = &mt('Select');
1445: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1446: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1447: &mt('Add log-in help page for a specific language:').' '.
1448: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1449: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1450: if ($switchserver) {
1451: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1452: } else {
1453: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1454: }
1.168 raeburn 1455: $datatable .= '</td></tr>';
1.169 raeburn 1456: $itemcount ++;
1.6 raeburn 1457: }
1.169 raeburn 1458: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1459: } elsif ($caller eq 'headtag') {
1460: my %domservers = &Apache::lonnet::get_servers($dom);
1461: my $choice = $choices{'headtag'};
1462: $css_class = ' class="LC_odd_row"';
1463: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1464: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1465: '<th>'.$choices{'current'}.'</th>'.
1466: '<th>'.$choices{'action'}.'</th>'.
1467: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1468: my (%currurls,%currexempt);
1469: if (ref($settings) eq 'HASH') {
1470: if (ref($settings->{'headtag'}) eq 'HASH') {
1471: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1472: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1473: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1474: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1475: }
1476: }
1477: }
1478: }
1479: my %lt = &Apache::lonlocal::texthash(
1480: del => 'Delete?',
1481: rep => 'Replace:',
1482: upl => 'Upload:',
1483: curr => 'View contents',
1484: none => 'None',
1485: );
1486: my $switchserver = &check_switchserver($dom,$confname);
1487: foreach my $lonhost (sort(keys(%domservers))) {
1488: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1489: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1490: if ($currurls{$lonhost}) {
1491: $datatable .= '<td class="LC_right_item"><a href="'.
1492: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1493: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1494: '">'.$lt{'curr'}.'</a></td>'.
1495: '<td><span class="LC_nobreak"><label>'.
1496: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1497: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1498: } else {
1499: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1500: }
1501: $datatable .='<br />';
1502: if ($switchserver) {
1503: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1504: } else {
1505: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1506: }
1.330 raeburn 1507: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1508: }
1509: $datatable .= '</table></td></tr>';
1.1 raeburn 1510: }
1.6 raeburn 1511: return $datatable;
1512: }
1513:
1514: sub login_choices {
1515: my %choices =
1516: &Apache::lonlocal::texthash (
1.116 bisitz 1517: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1518: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1519: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1520: disallowlogin => "Login page requests redirected",
1521: hostid => "Server",
1.128 raeburn 1522: server => "Redirect to:",
1523: serverpath => "Path",
1524: custompath => "Custom",
1525: exempt => "Exempt IP(s)",
1.110 raeburn 1526: directlogin => "No redirect",
1527: newuser => "Link to create a user account",
1528: img => "Header",
1529: logo => "Main Logo",
1530: domlogo => "Domain Logo",
1531: login => "Log-in Header",
1532: textcol => "Text color",
1533: bgcol => "Box color",
1534: bgs => "Background colors",
1535: links => "Link colors",
1536: font => "Font color",
1537: pgbg => "Header",
1538: mainbg => "Page",
1539: sidebg => "Login box",
1540: link => "Link",
1541: alink => "Active link",
1542: vlink => "Visited link",
1.256 raeburn 1543: headtag => "Custom markup",
1544: action => "Action",
1545: current => "Current",
1.6 raeburn 1546: );
1547: return %choices;
1548: }
1549:
1550: sub print_rolecolors {
1.30 raeburn 1551: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1552: my %choices = &color_font_choices();
1553: my @bgs = ('pgbg','tabbg','sidebg');
1554: my @links = ('link','alink','vlink');
1555: my @images = ('img');
1556: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1557: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1558: my %defaultdesign = %Apache::loncommon::defaultdesign;
1559: my (%is_custom,%designs);
1.200 raeburn 1560: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1561: if (ref($settings) eq 'HASH') {
1562: if (ref($settings->{$role}) eq 'HASH') {
1563: if ($settings->{$role}->{'img'} ne '') {
1564: $designs{'img'} = $settings->{$role}->{'img'};
1565: $is_custom{'img'} = 1;
1566: }
1567: if ($settings->{$role}->{'font'} ne '') {
1568: $designs{'font'} = $settings->{$role}->{'font'};
1569: $is_custom{'font'} = 1;
1570: }
1.97 tempelho 1571: if ($settings->{$role}->{'fontmenu'} ne '') {
1572: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1573: $is_custom{'fontmenu'} = 1;
1574: }
1.6 raeburn 1575: foreach my $item (@bgs) {
1576: if ($settings->{$role}->{$item} ne '') {
1577: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1578: $is_custom{$item} = 1;
1579: }
1580: }
1581: foreach my $item (@links) {
1582: if ($settings->{$role}->{$item} ne '') {
1583: $designs{'links'}{$item} = $settings->{$role}->{$item};
1584: $is_custom{$item} = 1;
1585: }
1586: }
1587: }
1588: } else {
1589: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1590: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1591: $is_custom{'img'} = 1;
1592: }
1.97 tempelho 1593: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1594: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1595: $is_custom{'fontmenu'} = 1;
1596: }
1.6 raeburn 1597: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1598: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1599: $is_custom{'font'} = 1;
1600: }
1601: foreach my $item (@bgs) {
1602: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1603: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1604: $is_custom{$item} = 1;
1605:
1606: }
1607: }
1608: foreach my $item (@links) {
1609: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1610: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1611: $is_custom{$item} = 1;
1612: }
1613: }
1614: }
1615: my $itemcount = 1;
1.30 raeburn 1616: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1617: $datatable .= '</tr></table></td></tr>';
1618: return $datatable;
1619: }
1620:
1.200 raeburn 1621: sub role_defaults {
1622: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1623: my %defaults;
1624: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1625: return %defaults;
1626: }
1627: my %defaultdesign = %Apache::loncommon::defaultdesign;
1628: if ($role eq 'login') {
1629: %defaults = (
1630: font => $defaultdesign{$role.'.font'},
1631: );
1632: if (ref($logintext) eq 'ARRAY') {
1633: foreach my $item (@{$logintext}) {
1634: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1635: }
1636: }
1637: foreach my $item (@{$images}) {
1638: $defaults{'showlogo'}{$item} = 1;
1639: }
1640: } else {
1641: %defaults = (
1642: img => $defaultdesign{$role.'.img'},
1643: font => $defaultdesign{$role.'.font'},
1644: fontmenu => $defaultdesign{$role.'.fontmenu'},
1645: );
1646: }
1647: foreach my $item (@{$bgs}) {
1648: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1649: }
1650: foreach my $item (@{$links}) {
1651: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1652: }
1653: foreach my $item (@{$images}) {
1654: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1655: }
1656: return %defaults;
1657: }
1658:
1.6 raeburn 1659: sub display_color_options {
1.9 raeburn 1660: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1661: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1662: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1663: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1664: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1665: '<td>'.$choices->{'font'}.'</td>';
1666: if (!$is_custom->{'font'}) {
1.329 raeburn 1667: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1668: } else {
1669: $datatable .= '<td> </td>';
1670: }
1.174 foxr 1671: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1672:
1.8 raeburn 1673: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1674: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1675: ' value="'.$current_color.'" /> '.
1.329 raeburn 1676: ' </span></td></tr>';
1.107 raeburn 1677: unless ($role eq 'login') {
1678: $datatable .= '<tr'.$css_class.'>'.
1679: '<td>'.$choices->{'fontmenu'}.'</td>';
1680: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 1681: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1682: } else {
1683: $datatable .= '<td> </td>';
1684: }
1.202 raeburn 1685: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1686: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1687: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1688: '<input class="colorchooser" type="text" size="10" name="'
1689: .$role.'_fontmenu"'.
1690: ' value="'.$current_color.'" /> '.
1.329 raeburn 1691: ' </span></td></tr>';
1.97 tempelho 1692: }
1.9 raeburn 1693: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1694: foreach my $img (@{$images}) {
1.18 albertel 1695: $itemcount ++;
1.6 raeburn 1696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1697: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1698: '<td>'.$choices->{$img};
1.41 raeburn 1699: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1700: if ($role eq 'login') {
1701: if ($img eq 'login') {
1702: $login_hdr_pick =
1.135 bisitz 1703: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1704: $logincolors =
1705: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1706: $designs,$defaults);
1.70 raeburn 1707: } elsif ($img ne 'domlogo') {
1708: $datatable.= &logo_display_options($img,$defaults,$designs);
1709: }
1710: }
1711: $datatable .= '</td>';
1.6 raeburn 1712: if ($designs->{$img} ne '') {
1713: $imgfile = $designs->{$img};
1.18 albertel 1714: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1715: } else {
1716: $imgfile = $defaults->{$img};
1717: }
1718: if ($imgfile) {
1.9 raeburn 1719: my ($showfile,$fullsize);
1720: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1721: my $urldir = $1;
1722: my $filename = $2;
1723: my @info = &Apache::lonnet::stat_file($designs->{$img});
1724: if (@info) {
1725: my $thumbfile = 'tn-'.$filename;
1726: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1727: if (@thumb) {
1728: $showfile = $urldir.'/'.$thumbfile;
1729: } else {
1730: $showfile = $imgfile;
1731: }
1732: } else {
1733: $showfile = '';
1734: }
1735: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1736: $showfile = $imgfile;
1.6 raeburn 1737: my $imgdir = $1;
1738: my $filename = $2;
1.159 raeburn 1739: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1740: $showfile = "/$imgdir/tn-".$filename;
1741: } else {
1.159 raeburn 1742: my $input = $londocroot.$imgfile;
1743: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1744: if (!-e $output) {
1.9 raeburn 1745: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1746: my ($fullwidth,$fullheight) = &check_dimensions($input);
1747: if ($fullwidth ne '' && $fullheight ne '') {
1748: if ($fullwidth > $width && $fullheight > $height) {
1749: my $size = $width.'x'.$height;
1.316 raeburn 1750: my @args = ('convert','-sample',$size,$input,$output);
1751: system({$args[0]} @args);
1.159 raeburn 1752: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1753: }
1754: }
1.6 raeburn 1755: }
1756: }
1.16 raeburn 1757: }
1.6 raeburn 1758: if ($showfile) {
1.40 raeburn 1759: if ($showfile =~ m{^/(adm|res)/}) {
1760: if ($showfile =~ m{^/res/}) {
1761: my $local_showfile =
1762: &Apache::lonnet::filelocation('',$showfile);
1763: &Apache::lonnet::repcopy($local_showfile);
1764: }
1765: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1766: }
1767: if ($imgfile) {
1768: if ($imgfile =~ m{^/(adm|res)/}) {
1769: if ($imgfile =~ m{^/res/}) {
1770: my $local_imgfile =
1771: &Apache::lonnet::filelocation('',$imgfile);
1772: &Apache::lonnet::repcopy($local_imgfile);
1773: }
1774: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1775: } else {
1776: $fullsize = $imgfile;
1777: }
1778: }
1.41 raeburn 1779: $datatable .= '<td>';
1780: if ($img eq 'login') {
1.135 bisitz 1781: $datatable .= $login_hdr_pick;
1782: }
1.41 raeburn 1783: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1784: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1785: } else {
1.201 raeburn 1786: $datatable .= '<td> </td><td class="LC_left_item">'.
1787: &mt('Upload:').'<br />';
1.6 raeburn 1788: }
1789: } else {
1.201 raeburn 1790: $datatable .= '<td> </td><td class="LC_left_item">'.
1791: &mt('Upload:').'<br />';
1.6 raeburn 1792: }
1.9 raeburn 1793: if ($switchserver) {
1794: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1795: } else {
1.135 bisitz 1796: if ($img ne 'login') { # suppress file selection for Log-in header
1797: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1798: }
1.9 raeburn 1799: }
1800: $datatable .= '</td></tr>';
1.6 raeburn 1801: }
1802: $itemcount ++;
1803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1804: $datatable .= '<tr'.$css_class.'>'.
1805: '<td>'.$choices->{'bgs'}.'</td>';
1806: my $bgs_def;
1807: foreach my $item (@{$bgs}) {
1808: if (!$is_custom->{$item}) {
1.329 raeburn 1809: $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 1810: }
1811: }
1812: if ($bgs_def) {
1.8 raeburn 1813: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1814: } else {
1815: $datatable .= '<td> </td>';
1816: }
1817: $datatable .= '<td class="LC_right_item">'.
1818: '<table border="0"><tr>';
1.174 foxr 1819:
1.6 raeburn 1820: foreach my $item (@{$bgs}) {
1.306 raeburn 1821: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1822: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1823: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1824: $datatable .= ' ';
1.6 raeburn 1825: }
1.174 foxr 1826: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1827: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1828: }
1829: $datatable .= '</tr></table></td></tr>';
1830: $itemcount ++;
1831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1832: $datatable .= '<tr'.$css_class.'>'.
1833: '<td>'.$choices->{'links'}.'</td>';
1834: my $links_def;
1835: foreach my $item (@{$links}) {
1836: if (!$is_custom->{$item}) {
1.329 raeburn 1837: $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 1838: }
1839: }
1840: if ($links_def) {
1.8 raeburn 1841: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1842: } else {
1843: $datatable .= '<td> </td>';
1844: }
1845: $datatable .= '<td class="LC_right_item">'.
1846: '<table border="0"><tr>';
1847: foreach my $item (@{$links}) {
1.234 raeburn 1848: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1849: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1850: if ($designs->{'links'}{$item}) {
1.174 foxr 1851: $datatable.=' ';
1.6 raeburn 1852: }
1.174 foxr 1853: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1854: '" /></td>';
1855: }
1.30 raeburn 1856: $$rowtotal += $itemcount;
1.3 raeburn 1857: return $datatable;
1858: }
1859:
1.70 raeburn 1860: sub logo_display_options {
1861: my ($img,$defaults,$designs) = @_;
1862: my $checkedon;
1863: if (ref($defaults) eq 'HASH') {
1864: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1865: if ($defaults->{'showlogo'}{$img}) {
1866: $checkedon = 'checked="checked" ';
1867: }
1868: }
1869: }
1870: if (ref($designs) eq 'HASH') {
1871: if (ref($designs->{'showlogo'}) eq 'HASH') {
1872: if (defined($designs->{'showlogo'}{$img})) {
1873: if ($designs->{'showlogo'}{$img} == 0) {
1874: $checkedon = '';
1875: } elsif ($designs->{'showlogo'}{$img} == 1) {
1876: $checkedon = 'checked="checked" ';
1877: }
1878: }
1879: }
1880: }
1881: return '<br /><label> <input type="checkbox" name="'.
1882: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1883: &mt('show').'</label>'."\n";
1884: }
1885:
1.41 raeburn 1886: sub login_header_options {
1.135 bisitz 1887: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1888: my $output = '';
1.41 raeburn 1889: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1890: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1891: if (!$is_custom->{'textcol'}) {
1892: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1893: ' ';
1894: }
1895: if (!$is_custom->{'bgcol'}) {
1896: $output .= $choices->{'bgcol'}.': '.
1897: '<span id="css_'.$role.'_font" style="background-color: '.
1898: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1899: }
1900: $output .= '<br />';
1901: }
1902: $output .='<br />';
1903: return $output;
1904: }
1905:
1906: sub login_text_colors {
1.201 raeburn 1907: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1908: my $color_menu = '<table border="0"><tr>';
1909: foreach my $item (@{$logintext}) {
1.306 raeburn 1910: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1911: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1912: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1913: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1914: }
1915: $color_menu .= '</tr></table><br />';
1916: return $color_menu;
1917: }
1918:
1919: sub image_changes {
1920: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1921: my $output;
1.135 bisitz 1922: if ($img eq 'login') {
1.331 raeburn 1923: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1924: } elsif (!$is_custom) {
1.70 raeburn 1925: if ($img ne 'domlogo') {
1.331 raeburn 1926: $output = &mt('Default image:').'<br />';
1.41 raeburn 1927: } else {
1.331 raeburn 1928: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1929: }
1930: }
1.331 raeburn 1931: if ($img ne 'login') {
1.135 bisitz 1932: if ($img_import) {
1933: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1934: }
1935: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1936: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1937: if ($is_custom) {
1938: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1939: '<input type="checkbox" name="'.
1940: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1941: '</label> '.&mt('Replace:').'</span><br />';
1942: } else {
1.306 raeburn 1943: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1944: }
1.41 raeburn 1945: }
1946: return $output;
1947: }
1948:
1.3 raeburn 1949: sub print_quotas {
1.86 raeburn 1950: my ($dom,$settings,$rowtotal,$action) = @_;
1951: my $context;
1952: if ($action eq 'quotas') {
1953: $context = 'tools';
1954: } else {
1955: $context = $action;
1956: }
1.197 raeburn 1957: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1958: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1959: my $typecount = 0;
1.101 raeburn 1960: my ($css_class,%titles);
1.86 raeburn 1961: if ($context eq 'requestcourses') {
1.325 raeburn 1962: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 1963: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1964: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1965: %titles = &courserequest_titles();
1.163 raeburn 1966: } elsif ($context eq 'requestauthor') {
1967: @usertools = ('author');
1968: @options = ('norequest','approval','automatic');
1.210 raeburn 1969: %titles = &authorrequest_titles();
1.86 raeburn 1970: } else {
1.162 raeburn 1971: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1972: %titles = &tool_titles();
1.86 raeburn 1973: }
1.26 raeburn 1974: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1975: foreach my $type (@{$types}) {
1.197 raeburn 1976: my ($currdefquota,$currauthorquota);
1.163 raeburn 1977: unless (($context eq 'requestcourses') ||
1978: ($context eq 'requestauthor')) {
1.86 raeburn 1979: if (ref($settings) eq 'HASH') {
1980: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1981: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1982: } else {
1983: $currdefquota = $settings->{$type};
1984: }
1.197 raeburn 1985: if (ref($settings->{authorquota}) eq 'HASH') {
1986: $currauthorquota = $settings->{authorquota}->{$type};
1987: }
1.78 raeburn 1988: }
1.72 raeburn 1989: }
1.3 raeburn 1990: if (defined($usertypes->{$type})) {
1991: $typecount ++;
1992: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1993: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1994: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1995: '<td class="LC_left_item">';
1.101 raeburn 1996: if ($context eq 'requestcourses') {
1997: $datatable .= '<table><tr>';
1998: }
1999: my %cell;
1.72 raeburn 2000: foreach my $item (@usertools) {
1.101 raeburn 2001: if ($context eq 'requestcourses') {
2002: my ($curroption,$currlimit);
2003: if (ref($settings) eq 'HASH') {
2004: if (ref($settings->{$item}) eq 'HASH') {
2005: $curroption = $settings->{$item}->{$type};
2006: if ($curroption =~ /^autolimit=(\d*)$/) {
2007: $currlimit = $1;
2008: }
2009: }
2010: }
2011: if (!$curroption) {
2012: $curroption = 'norequest';
2013: }
2014: $datatable .= '<th>'.$titles{$item}.'</th>';
2015: foreach my $option (@options) {
2016: my $val = $option;
2017: if ($option eq 'norequest') {
2018: $val = 0;
2019: }
2020: if ($option eq 'validate') {
2021: my $canvalidate = 0;
2022: if (ref($validations{$item}) eq 'HASH') {
2023: if ($validations{$item}{$type}) {
2024: $canvalidate = 1;
2025: }
2026: }
2027: next if (!$canvalidate);
2028: }
2029: my $checked = '';
2030: if ($option eq $curroption) {
2031: $checked = ' checked="checked"';
2032: } elsif ($option eq 'autolimit') {
2033: if ($curroption =~ /^autolimit/) {
2034: $checked = ' checked="checked"';
2035: }
2036: }
2037: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2038: '<input type="radio" name="crsreq_'.$item.
2039: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2040: $titles{$option}.'</label>';
1.101 raeburn 2041: if ($option eq 'autolimit') {
1.127 raeburn 2042: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2043: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2044: 'value="'.$currlimit.'" />';
1.101 raeburn 2045: }
1.127 raeburn 2046: $cell{$item} .= '</span> ';
1.103 raeburn 2047: if ($option eq 'autolimit') {
1.127 raeburn 2048: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2049: }
1.101 raeburn 2050: }
1.163 raeburn 2051: } elsif ($context eq 'requestauthor') {
2052: my $curroption;
2053: if (ref($settings) eq 'HASH') {
2054: $curroption = $settings->{$type};
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: foreach my $option (@options) {
2060: my $val = $option;
2061: if ($option eq 'norequest') {
2062: $val = 0;
2063: }
2064: my $checked = '';
2065: if ($option eq $curroption) {
2066: $checked = ' checked="checked"';
2067: }
2068: $datatable .= '<span class="LC_nobreak"><label>'.
2069: '<input type="radio" name="authorreq_'.$type.
2070: '" value="'.$val.'"'.$checked.' />'.
2071: $titles{$option}.'</label></span> ';
2072: }
1.101 raeburn 2073: } else {
2074: my $checked = 'checked="checked" ';
2075: if (ref($settings) eq 'HASH') {
2076: if (ref($settings->{$item}) eq 'HASH') {
2077: if ($settings->{$item}->{$type} == 0) {
2078: $checked = '';
2079: } elsif ($settings->{$item}->{$type} == 1) {
2080: $checked = 'checked="checked" ';
2081: }
1.78 raeburn 2082: }
1.72 raeburn 2083: }
1.101 raeburn 2084: $datatable .= '<span class="LC_nobreak"><label>'.
2085: '<input type="checkbox" name="'.$context.'_'.$item.
2086: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2087: '</label></span> ';
1.72 raeburn 2088: }
1.101 raeburn 2089: }
2090: if ($context eq 'requestcourses') {
2091: $datatable .= '</tr><tr>';
2092: foreach my $item (@usertools) {
1.106 raeburn 2093: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2094: }
2095: $datatable .= '</tr></table>';
1.72 raeburn 2096: }
1.86 raeburn 2097: $datatable .= '</td>';
1.163 raeburn 2098: unless (($context eq 'requestcourses') ||
2099: ($context eq 'requestauthor')) {
1.86 raeburn 2100: $datatable .=
1.197 raeburn 2101: '<td class="LC_right_item">'.
2102: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2103: '<input type="text" name="quota_'.$type.
1.72 raeburn 2104: '" value="'.$currdefquota.
1.197 raeburn 2105: '" size="5" /></span>'.(' ' x 2).
2106: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2107: '<input type="text" name="authorquota_'.$type.
2108: '" value="'.$currauthorquota.
2109: '" size="5" /></span></td>';
1.86 raeburn 2110: }
2111: $datatable .= '</tr>';
1.3 raeburn 2112: }
2113: }
2114: }
1.163 raeburn 2115: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2116: $defaultquota = '20';
1.197 raeburn 2117: $authorquota = '500';
1.86 raeburn 2118: if (ref($settings) eq 'HASH') {
2119: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2120: $defaultquota = $settings->{'defaultquota'}->{'default'};
2121: } elsif (defined($settings->{'default'})) {
2122: $defaultquota = $settings->{'default'};
2123: }
1.197 raeburn 2124: if (ref($settings->{'authorquota'}) eq 'HASH') {
2125: $authorquota = $settings->{'authorquota'}->{'default'};
2126: }
1.3 raeburn 2127: }
2128: }
2129: $typecount ++;
2130: $css_class = $typecount%2?' class="LC_odd_row"':'';
2131: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2132: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2133: '<td class="LC_left_item">';
1.101 raeburn 2134: if ($context eq 'requestcourses') {
2135: $datatable .= '<table><tr>';
2136: }
2137: my %defcell;
1.72 raeburn 2138: foreach my $item (@usertools) {
1.101 raeburn 2139: if ($context eq 'requestcourses') {
2140: my ($curroption,$currlimit);
2141: if (ref($settings) eq 'HASH') {
2142: if (ref($settings->{$item}) eq 'HASH') {
2143: $curroption = $settings->{$item}->{'default'};
2144: if ($curroption =~ /^autolimit=(\d*)$/) {
2145: $currlimit = $1;
2146: }
2147: }
2148: }
2149: if (!$curroption) {
2150: $curroption = 'norequest';
2151: }
2152: $datatable .= '<th>'.$titles{$item}.'</th>';
2153: foreach my $option (@options) {
2154: my $val = $option;
2155: if ($option eq 'norequest') {
2156: $val = 0;
2157: }
2158: if ($option eq 'validate') {
2159: my $canvalidate = 0;
2160: if (ref($validations{$item}) eq 'HASH') {
2161: if ($validations{$item}{'default'}) {
2162: $canvalidate = 1;
2163: }
2164: }
2165: next if (!$canvalidate);
2166: }
2167: my $checked = '';
2168: if ($option eq $curroption) {
2169: $checked = ' checked="checked"';
2170: } elsif ($option eq 'autolimit') {
2171: if ($curroption =~ /^autolimit/) {
2172: $checked = ' checked="checked"';
2173: }
2174: }
2175: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2176: '<input type="radio" name="crsreq_'.$item.
2177: '_default" value="'.$val.'"'.$checked.' />'.
2178: $titles{$option}.'</label>';
2179: if ($option eq 'autolimit') {
1.127 raeburn 2180: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2181: $item.'_limit_default" size="1" '.
2182: 'value="'.$currlimit.'" />';
2183: }
1.127 raeburn 2184: $defcell{$item} .= '</span> ';
1.104 raeburn 2185: if ($option eq 'autolimit') {
1.127 raeburn 2186: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2187: }
1.101 raeburn 2188: }
1.163 raeburn 2189: } elsif ($context eq 'requestauthor') {
2190: my $curroption;
2191: if (ref($settings) eq 'HASH') {
1.172 raeburn 2192: $curroption = $settings->{'default'};
1.163 raeburn 2193: }
2194: if (!$curroption) {
2195: $curroption = 'norequest';
2196: }
2197: foreach my $option (@options) {
2198: my $val = $option;
2199: if ($option eq 'norequest') {
2200: $val = 0;
2201: }
2202: my $checked = '';
2203: if ($option eq $curroption) {
2204: $checked = ' checked="checked"';
2205: }
2206: $datatable .= '<span class="LC_nobreak"><label>'.
2207: '<input type="radio" name="authorreq_default"'.
2208: ' value="'.$val.'"'.$checked.' />'.
2209: $titles{$option}.'</label></span> ';
2210: }
1.101 raeburn 2211: } else {
2212: my $checked = 'checked="checked" ';
2213: if (ref($settings) eq 'HASH') {
2214: if (ref($settings->{$item}) eq 'HASH') {
2215: if ($settings->{$item}->{'default'} == 0) {
2216: $checked = '';
2217: } elsif ($settings->{$item}->{'default'} == 1) {
2218: $checked = 'checked="checked" ';
2219: }
1.78 raeburn 2220: }
1.72 raeburn 2221: }
1.101 raeburn 2222: $datatable .= '<span class="LC_nobreak"><label>'.
2223: '<input type="checkbox" name="'.$context.'_'.$item.
2224: '" value="default" '.$checked.'/>'.$titles{$item}.
2225: '</label></span> ';
2226: }
2227: }
2228: if ($context eq 'requestcourses') {
2229: $datatable .= '</tr><tr>';
2230: foreach my $item (@usertools) {
1.106 raeburn 2231: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2232: }
1.101 raeburn 2233: $datatable .= '</tr></table>';
1.72 raeburn 2234: }
1.86 raeburn 2235: $datatable .= '</td>';
1.163 raeburn 2236: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2237: $datatable .= '<td class="LC_right_item">'.
2238: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2239: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2240: $defaultquota.'" size="5" /></span>'.(' ' x2).
2241: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2242: '<input type="text" name="authorquota" value="'.
2243: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2244: }
2245: $datatable .= '</tr>';
1.72 raeburn 2246: $typecount ++;
2247: $css_class = $typecount%2?' class="LC_odd_row"':'';
2248: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2249: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2250: if ($context eq 'requestcourses') {
1.109 raeburn 2251: $datatable .= &mt('(overrides affiliation, if set)').
2252: '</td>'.
2253: '<td class="LC_left_item">'.
2254: '<table><tr>';
1.101 raeburn 2255: } else {
1.109 raeburn 2256: $datatable .= &mt('(overrides affiliation, if checked)').
2257: '</td>'.
2258: '<td class="LC_left_item" colspan="2">'.
2259: '<br />';
1.101 raeburn 2260: }
2261: my %advcell;
1.72 raeburn 2262: foreach my $item (@usertools) {
1.101 raeburn 2263: if ($context eq 'requestcourses') {
2264: my ($curroption,$currlimit);
2265: if (ref($settings) eq 'HASH') {
2266: if (ref($settings->{$item}) eq 'HASH') {
2267: $curroption = $settings->{$item}->{'_LC_adv'};
2268: if ($curroption =~ /^autolimit=(\d*)$/) {
2269: $currlimit = $1;
2270: }
2271: }
2272: }
2273: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2274: my $checked = '';
2275: if ($curroption eq '') {
2276: $checked = ' checked="checked"';
2277: }
2278: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2279: '<input type="radio" name="crsreq_'.$item.
2280: '__LC_adv" value=""'.$checked.' />'.
2281: &mt('No override set').'</label></span> ';
1.101 raeburn 2282: foreach my $option (@options) {
2283: my $val = $option;
2284: if ($option eq 'norequest') {
2285: $val = 0;
2286: }
2287: if ($option eq 'validate') {
2288: my $canvalidate = 0;
2289: if (ref($validations{$item}) eq 'HASH') {
2290: if ($validations{$item}{'_LC_adv'}) {
2291: $canvalidate = 1;
2292: }
2293: }
2294: next if (!$canvalidate);
2295: }
2296: my $checked = '';
1.104 raeburn 2297: if ($val eq $curroption) {
1.101 raeburn 2298: $checked = ' checked="checked"';
2299: } elsif ($option eq 'autolimit') {
2300: if ($curroption =~ /^autolimit/) {
2301: $checked = ' checked="checked"';
2302: }
2303: }
2304: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2305: '<input type="radio" name="crsreq_'.$item.
2306: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2307: $titles{$option}.'</label>';
2308: if ($option eq 'autolimit') {
1.127 raeburn 2309: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2310: $item.'_limit__LC_adv" size="1" '.
2311: 'value="'.$currlimit.'" />';
2312: }
1.127 raeburn 2313: $advcell{$item} .= '</span> ';
1.104 raeburn 2314: if ($option eq 'autolimit') {
1.127 raeburn 2315: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2316: }
1.101 raeburn 2317: }
1.163 raeburn 2318: } elsif ($context eq 'requestauthor') {
2319: my $curroption;
2320: if (ref($settings) eq 'HASH') {
2321: $curroption = $settings->{'_LC_adv'};
2322: }
2323: my $checked = '';
2324: if ($curroption eq '') {
2325: $checked = ' checked="checked"';
2326: }
2327: $datatable .= '<span class="LC_nobreak"><label>'.
2328: '<input type="radio" name="authorreq__LC_adv"'.
2329: ' value=""'.$checked.' />'.
2330: &mt('No override set').'</label></span> ';
2331: foreach my $option (@options) {
2332: my $val = $option;
2333: if ($option eq 'norequest') {
2334: $val = 0;
2335: }
2336: my $checked = '';
2337: if ($val eq $curroption) {
2338: $checked = ' checked="checked"';
2339: }
2340: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2341: '<input type="radio" name="authorreq__LC_adv"'.
2342: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2343: $titles{$option}.'</label></span> ';
2344: }
1.101 raeburn 2345: } else {
2346: my $checked = 'checked="checked" ';
2347: if (ref($settings) eq 'HASH') {
2348: if (ref($settings->{$item}) eq 'HASH') {
2349: if ($settings->{$item}->{'_LC_adv'} == 0) {
2350: $checked = '';
2351: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2352: $checked = 'checked="checked" ';
2353: }
1.79 raeburn 2354: }
1.72 raeburn 2355: }
1.101 raeburn 2356: $datatable .= '<span class="LC_nobreak"><label>'.
2357: '<input type="checkbox" name="'.$context.'_'.$item.
2358: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2359: '</label></span> ';
2360: }
2361: }
2362: if ($context eq 'requestcourses') {
2363: $datatable .= '</tr><tr>';
2364: foreach my $item (@usertools) {
1.106 raeburn 2365: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2366: }
1.101 raeburn 2367: $datatable .= '</tr></table>';
1.72 raeburn 2368: }
1.98 raeburn 2369: $datatable .= '</td></tr>';
1.30 raeburn 2370: $$rowtotal += $typecount;
1.3 raeburn 2371: return $datatable;
2372: }
2373:
1.163 raeburn 2374: sub print_requestmail {
1.305 raeburn 2375: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2376: my ($now,$datatable,%currapp);
1.102 raeburn 2377: $now = time;
2378: if (ref($settings) eq 'HASH') {
2379: if (ref($settings->{'notify'}) eq 'HASH') {
2380: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2381: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2382: }
2383: }
2384: }
1.191 raeburn 2385: my $numinrow = 2;
1.224 raeburn 2386: my $css_class;
1.305 raeburn 2387: if ($$rowtotal%2) {
2388: $css_class = 'LC_odd_row';
2389: }
2390: if ($customcss) {
2391: $css_class .= " $customcss";
2392: }
2393: $css_class =~ s/^\s+//;
2394: if ($css_class) {
2395: $css_class = ' class="'.$css_class.'"';
2396: }
2397: if ($rowstyle) {
2398: $css_class .= ' style="'.$rowstyle.'"';
2399: }
1.163 raeburn 2400: my $text;
2401: if ($action eq 'requestcourses') {
2402: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2403: } elsif ($action eq 'requestauthor') {
2404: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2405: } else {
1.224 raeburn 2406: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2407: }
1.224 raeburn 2408: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2409: ' <td>'.$text.'</td>'.
1.102 raeburn 2410: ' <td class="LC_left_item">';
1.191 raeburn 2411: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2412: $action.'notifyapproval',%currapp);
1.191 raeburn 2413: if ($numdc > 0) {
2414: $datatable .= $table;
1.102 raeburn 2415: } else {
2416: $datatable .= &mt('There are no active Domain Coordinators');
2417: }
2418: $datatable .='</td></tr>';
2419: return $datatable;
2420: }
2421:
1.216 raeburn 2422: sub print_studentcode {
2423: my ($settings,$rowtotal) = @_;
2424: my $rownum = 0;
1.218 raeburn 2425: my ($output,%current);
1.325 raeburn 2426: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2427: if (ref($settings) eq 'HASH') {
2428: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2429: foreach my $type (@crstypes) {
2430: $current{$type} = $settings->{'uniquecode'}{$type};
2431: }
1.218 raeburn 2432: }
2433: }
2434: $output .= '<tr>'.
2435: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2436: '<td class="LC_left_item">';
2437: foreach my $type (@crstypes) {
2438: my $check = ' ';
2439: if ($current{$type}) {
2440: $check = ' checked="checked" ';
2441: }
2442: $output .= '<span class="LC_nobreak"><label>'.
2443: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2444: &mt($type).'</label></span>'.(' 'x2).' ';
2445: }
2446: $output .= '</td></tr>';
2447: $$rowtotal ++;
2448: return $output;
1.216 raeburn 2449: }
2450:
2451: sub print_textbookcourses {
1.242 raeburn 2452: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2453: my $rownum = 0;
2454: my $css_class;
2455: my $itemcount = 1;
2456: my $maxnum = 0;
2457: my $bookshash;
2458: if (ref($settings) eq 'HASH') {
1.242 raeburn 2459: $bookshash = $settings->{$type};
1.216 raeburn 2460: }
2461: my %ordered;
2462: if (ref($bookshash) eq 'HASH') {
2463: foreach my $item (keys(%{$bookshash})) {
2464: if (ref($bookshash->{$item}) eq 'HASH') {
2465: my $num = $bookshash->{$item}{'order'};
2466: $ordered{$num} = $item;
2467: }
2468: }
2469: }
2470: my $confname = $dom.'-domainconfig';
2471: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2472: my $maxnum = scalar(keys(%ordered));
2473: my $datatable;
1.216 raeburn 2474: if (keys(%ordered)) {
2475: my @items = sort { $a <=> $b } keys(%ordered);
2476: for (my $i=0; $i<@items; $i++) {
2477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2478: my $key = $ordered{$items[$i]};
2479: my %coursehash=&Apache::lonnet::coursedescription($key);
2480: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2481: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2482: if (ref($bookshash->{$key}) eq 'HASH') {
2483: $subject = $bookshash->{$key}->{'subject'};
2484: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2485: if ($type eq 'textbooks') {
1.243 raeburn 2486: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2487: $author = $bookshash->{$key}->{'author'};
2488: $image = $bookshash->{$key}->{'image'};
2489: if ($image ne '') {
2490: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2491: my $imagethumb = "$path/tn-".$imagefile;
2492: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2493: }
1.216 raeburn 2494: }
2495: }
1.242 raeburn 2496: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2497: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2498: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2499: for (my $k=0; $k<=$maxnum; $k++) {
2500: my $vpos = $k+1;
2501: my $selstr;
2502: if ($k == $i) {
2503: $selstr = ' selected="selected" ';
2504: }
2505: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2506: }
2507: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2508: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2509: &mt('Delete?').'</label></span></td>'.
2510: '<td colspan="2">'.
1.242 raeburn 2511: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2512: (' 'x2).
1.242 raeburn 2513: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2514: if ($type eq 'textbooks') {
2515: $datatable .= (' 'x2).
1.243 raeburn 2516: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2517: (' 'x2).
1.242 raeburn 2518: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2519: (' 'x2).
2520: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2521: if ($image) {
1.267 raeburn 2522: $datatable .= $imgsrc.
1.242 raeburn 2523: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2524: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2525: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2526: }
2527: if ($switchserver) {
2528: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2529: } else {
2530: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2531: }
1.216 raeburn 2532: }
1.242 raeburn 2533: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2534: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2535: $coursetitle.'</span></td></tr>'."\n";
2536: $itemcount ++;
2537: }
2538: }
2539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2540: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2541: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2542: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2543: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2544: for (my $k=0; $k<$maxnum+1; $k++) {
2545: my $vpos = $k+1;
2546: my $selstr;
2547: if ($k == $maxnum) {
2548: $selstr = ' selected="selected" ';
2549: }
2550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2551: }
2552: $datatable .= '</select> '."\n".
1.334 raeburn 2553: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 2554: '<td colspan="2">'.
1.242 raeburn 2555: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2556: (' 'x2).
1.242 raeburn 2557: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2558: (' 'x2);
2559: if ($type eq 'textbooks') {
1.243 raeburn 2560: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2561: (' 'x2).
2562: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2563: (' 'x2).
2564: '<span class="LC_nobreak">'.&mt('Image:').' ';
2565: if ($switchserver) {
2566: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2567: } else {
2568: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2569: }
1.334 raeburn 2570: $datatable .= '</span>'."\n";
1.216 raeburn 2571: }
1.334 raeburn 2572: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2573: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2574: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2575: &Apache::loncommon::selectcourse_link
1.334 raeburn 2576: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 2577: '</span></td>'."\n".
2578: '</tr>'."\n";
2579: $itemcount ++;
2580: return $datatable;
2581: }
2582:
1.217 raeburn 2583: sub textbookcourses_javascript {
1.242 raeburn 2584: my ($settings) = @_;
2585: return unless(ref($settings) eq 'HASH');
2586: my (%ordered,%total,%jstext);
2587: foreach my $type ('textbooks','templates') {
2588: $total{$type} = 0;
2589: if (ref($settings->{$type}) eq 'HASH') {
2590: foreach my $item (keys(%{$settings->{$type}})) {
2591: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2592: my $num = $settings->{$type}->{$item}{'order'};
2593: $ordered{$type}{$num} = $item;
2594: }
2595: }
2596: $total{$type} = scalar(keys(%{$settings->{$type}}));
2597: }
2598: my @jsarray = ();
2599: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2600: push(@jsarray,$ordered{$type}{$item});
2601: }
2602: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2603: }
2604: return <<"ENDSCRIPT";
2605: <script type="text/javascript">
2606: // <![CDATA[
1.242 raeburn 2607: function reorderBooks(form,item,caller) {
1.217 raeburn 2608: var changedVal;
1.242 raeburn 2609: $jstext{'textbooks'};
2610: $jstext{'templates'};
2611: var newpos;
2612: var maxh;
2613: if (caller == 'textbooks') {
2614: newpos = 'textbooks_addbook_pos';
2615: maxh = 1 + $total{'textbooks'};
2616: } else {
2617: newpos = 'templates_addbook_pos';
2618: maxh = 1 + $total{'templates'};
2619: }
1.217 raeburn 2620: var current = new Array;
2621: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2622: if (item == newpos) {
2623: changedVal = newitemVal;
2624: } else {
2625: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2626: current[newitemVal] = newpos;
2627: }
1.242 raeburn 2628: if (caller == 'textbooks') {
2629: for (var i=0; i<textbooks.length; i++) {
2630: var elementName = 'textbooks_'+textbooks[i];
2631: if (elementName != item) {
2632: if (form.elements[elementName]) {
2633: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2634: current[currVal] = elementName;
2635: }
2636: }
2637: }
2638: }
2639: if (caller == 'templates') {
2640: for (var i=0; i<templates.length; i++) {
2641: var elementName = 'templates_'+templates[i];
2642: if (elementName != item) {
2643: if (form.elements[elementName]) {
2644: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2645: current[currVal] = elementName;
2646: }
1.217 raeburn 2647: }
2648: }
2649: }
2650: var oldVal;
2651: for (var j=0; j<maxh; j++) {
2652: if (current[j] == undefined) {
2653: oldVal = j;
2654: }
2655: }
2656: if (oldVal < changedVal) {
2657: for (var k=oldVal+1; k<=changedVal ; k++) {
2658: var elementName = current[k];
2659: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2660: }
2661: } else {
2662: for (var k=changedVal; k<oldVal; k++) {
2663: var elementName = current[k];
2664: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2665: }
2666: }
2667: return;
2668: }
2669:
2670: // ]]>
2671: </script>
2672:
2673: ENDSCRIPT
2674: }
2675:
1.267 raeburn 2676: sub ltitools_javascript {
2677: my ($settings) = @_;
1.319 raeburn 2678: my $togglejs = <itools_toggle_js();
2679: unless (ref($settings) eq 'HASH') {
2680: return $togglejs;
2681: }
1.267 raeburn 2682: my (%ordered,$total,%jstext);
2683: $total = 0;
2684: foreach my $item (keys(%{$settings})) {
2685: if (ref($settings->{$item}) eq 'HASH') {
2686: my $num = $settings->{$item}{'order'};
2687: $ordered{$num} = $item;
2688: }
2689: }
2690: $total = scalar(keys(%{$settings}));
2691: my @jsarray = ();
2692: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2693: push(@jsarray,$ordered{$item});
2694: }
2695: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2696: return <<"ENDSCRIPT";
2697: <script type="text/javascript">
2698: // <![CDATA[
1.319 raeburn 2699: function reorderLTITools(form,item) {
1.267 raeburn 2700: var changedVal;
2701: $jstext
2702: var newpos = 'ltitools_add_pos';
2703: var maxh = 1 + $total;
2704: var current = new Array;
2705: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2706: if (item == newpos) {
2707: changedVal = newitemVal;
2708: } else {
2709: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2710: current[newitemVal] = newpos;
2711: }
2712: for (var i=0; i<ltitools.length; i++) {
2713: var elementName = 'ltitools_'+ltitools[i];
2714: if (elementName != item) {
2715: if (form.elements[elementName]) {
2716: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2717: current[currVal] = elementName;
2718: }
2719: }
2720: }
2721: var oldVal;
2722: for (var j=0; j<maxh; j++) {
2723: if (current[j] == undefined) {
2724: oldVal = j;
2725: }
2726: }
2727: if (oldVal < changedVal) {
2728: for (var k=oldVal+1; k<=changedVal ; k++) {
2729: var elementName = current[k];
2730: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2731: }
2732: } else {
2733: for (var k=changedVal; k<oldVal; k++) {
2734: var elementName = current[k];
2735: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2736: }
2737: }
2738: return;
2739: }
2740:
2741: // ]]>
2742: </script>
2743:
1.319 raeburn 2744: $togglejs
2745:
2746: ENDSCRIPT
2747: }
2748:
2749: sub ltitools_toggle_js {
2750: return <<"ENDSCRIPT";
2751: <script type="text/javascript">
2752: // <![CDATA[
2753:
2754: function toggleLTITools(form,setting,item) {
2755: var radioname = '';
2756: var divid = '';
2757: if ((setting == 'passback') || (setting == 'roster')) {
2758: radioname = 'ltitools_'+setting+'_'+item;
2759: divid = 'ltitools_'+setting+'time_'+item;
2760: var num = form.elements[radioname].length;
2761: if (num) {
2762: var setvis = '';
2763: for (var i=0; i<num; i++) {
2764: if (form.elements[radioname][i].checked) {
2765: if (form.elements[radioname][i].value == '1') {
2766: if (document.getElementById(divid)) {
2767: document.getElementById(divid).style.display = 'inline-block';
2768: }
2769: setvis = 1;
2770: }
2771: break;
2772: }
2773: }
2774: }
2775: if (!setvis) {
2776: if (document.getElementById(divid)) {
2777: document.getElementById(divid).style.display = 'none';
2778: }
2779: }
2780: }
1.324 raeburn 2781: if (setting == 'user') {
2782: divid = 'ltitools_'+setting+'_div_'+item;
2783: var checkid = 'ltitools_'+setting+'_field_'+item;
2784: if (document.getElementById(divid)) {
2785: if (document.getElementById(checkid)) {
2786: if (document.getElementById(checkid).checked) {
2787: document.getElementById(divid).style.display = 'inline-block';
2788: } else {
2789: document.getElementById(divid).style.display = 'none';
2790: }
2791: }
2792: }
2793: }
1.319 raeburn 2794: return;
2795: }
2796: // ]]>
2797: </script>
2798:
1.267 raeburn 2799: ENDSCRIPT
2800: }
2801:
1.320 raeburn 2802: sub lti_javascript {
2803: my ($settings) = @_;
2804: my $togglejs = <i_toggle_js();
2805: unless (ref($settings) eq 'HASH') {
2806: return $togglejs;
2807: }
2808: my (%ordered,$total,%jstext);
2809: $total = 0;
2810: foreach my $item (keys(%{$settings})) {
2811: if (ref($settings->{$item}) eq 'HASH') {
2812: my $num = $settings->{$item}{'order'};
2813: $ordered{$num} = $item;
2814: }
2815: }
2816: $total = scalar(keys(%{$settings}));
2817: my @jsarray = ();
2818: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2819: push(@jsarray,$ordered{$item});
2820: }
2821: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
2822: return <<"ENDSCRIPT";
2823: <script type="text/javascript">
2824: // <![CDATA[
2825: function reorderLTI(form,item) {
2826: var changedVal;
2827: $jstext
2828: var newpos = 'lti_pos_add';
2829: var maxh = 1 + $total;
2830: var current = new Array;
2831: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2832: if (item == newpos) {
2833: changedVal = newitemVal;
2834: } else {
2835: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2836: current[newitemVal] = newpos;
2837: }
2838: for (var i=0; i<lti.length; i++) {
2839: var elementName = 'lti_pos_'+lti[i];
2840: if (elementName != item) {
2841: if (form.elements[elementName]) {
2842: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2843: current[currVal] = elementName;
2844: }
2845: }
2846: }
2847: var oldVal;
2848: for (var j=0; j<maxh; j++) {
2849: if (current[j] == undefined) {
2850: oldVal = j;
2851: }
2852: }
2853: if (oldVal < changedVal) {
2854: for (var k=oldVal+1; k<=changedVal ; k++) {
2855: var elementName = current[k];
2856: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2857: }
2858: } else {
2859: for (var k=changedVal; k<oldVal; k++) {
2860: var elementName = current[k];
2861: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2862: }
2863: }
2864: return;
2865: }
2866: // ]]>
2867: </script>
2868:
2869: $togglejs
2870:
2871: ENDSCRIPT
2872: }
2873:
2874: sub lti_toggle_js {
1.325 raeburn 2875: my %lcauthparmtext = &Apache::lonlocal::texthash (
2876: localauth => 'Local auth argument',
2877: krb => 'Kerberos domain',
2878: );
1.320 raeburn 2879: return <<"ENDSCRIPT";
2880: <script type="text/javascript">
2881: // <![CDATA[
2882:
2883: function toggleLTI(form,setting,item) {
1.345 raeburn 2884: if (setting == 'requser') {
2885: var fieldsets = document.getElementsByClassName('ltioption_'+item);
2886: if (fieldsets.length) {
2887: var radioname = 'lti_'+setting+'_'+item;
2888: var num = form.elements[radioname].length;
2889: if (num) {
2890: var setvis = '';
2891: for (var i=0; i<num; i++) {
2892: if (form.elements[radioname][i].checked) {
2893: if (form.elements[radioname][i].value == '1') {
2894: setvis = 1;
2895: break;
2896: }
2897: }
2898: }
1.352 raeburn 2899: for (var j=0; j<fieldsets.length; j++) {
1.345 raeburn 2900: if (setvis) {
2901: fieldsets[j].style.display = 'block';
2902: } else {
2903: fieldsets[j].style.display = 'none';
2904: }
2905: }
2906: }
2907: }
2908: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320 raeburn 2909: var radioname = '';
2910: var divid = '';
2911: if (setting == 'user') {
2912: radioname = 'lti_mapuser_'+item;
2913: divid = 'lti_userfield_'+item;
1.343 raeburn 2914: } else if (setting == 'crs') {
1.320 raeburn 2915: radioname = 'lti_mapcrs_'+item;
2916: divid = 'lti_crsfield_'+item;
1.337 raeburn 2917: } else {
1.351 raeburn 2918: radioname = 'lti_passback_'+item;
1.337 raeburn 2919: divid = 'lti_passback_'+item;
1.320 raeburn 2920: }
2921: var num = form.elements[radioname].length;
2922: if (num) {
2923: var setvis = '';
2924: for (var i=0; i<num; i++) {
2925: if (form.elements[radioname][i].checked) {
1.337 raeburn 2926: if (setting == 'passback') {
2927: if (form.elements[radioname][i].value == '1') {
2928: if (document.getElementById(divid)) {
2929: document.getElementById(divid).style.display = 'inline-block';
2930: }
2931: setvis = 1;
2932: break;
2933: }
2934: } else {
2935: if (form.elements[radioname][i].value == 'other') {
2936: if (document.getElementById(divid)) {
2937: document.getElementById(divid).style.display = 'inline-block';
2938: }
2939: setvis = 1;
2940: break;
1.320 raeburn 2941: }
2942: }
2943: }
2944: }
2945: if (!setvis) {
2946: if (document.getElementById(divid)) {
2947: document.getElementById(divid).style.display = 'none';
2948: }
2949: }
2950: }
2951: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2952: var numsec = form.elements['lti_crssec_'+item].length;
2953: if (numsec) {
2954: var setvis = '';
2955: for (var i=0; i<numsec; i++) {
2956: if (form.elements['lti_crssec_'+item][i].checked) {
2957: if (form.elements['lti_crssec_'+item][i].value == '1') {
2958: if (document.getElementById('lti_crssecfield_'+item)) {
2959: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2960: setvis = 1;
2961: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2962: if (numsrcsec) {
2963: var setsrcvis = '';
2964: for (var j=0; j<numsrcsec; j++) {
2965: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2966: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2967: if (document.getElementById('lti_secsrcfield_'+item)) {
2968: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2969: setsrcvis = 1;
2970: }
2971: }
2972: }
2973: }
2974: if (!setsrcvis) {
2975: if (document.getElementById('lti_secsrcfield_'+item)) {
2976: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2977: }
2978: }
2979: }
2980: }
2981: }
2982: }
2983: }
2984: if (!setvis) {
2985: if (document.getElementById('lti_crssecfield_'+item)) {
2986: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2987: }
2988: if (document.getElementById('lti_secsrcfield_'+item)) {
2989: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2990: }
2991: }
2992: }
1.325 raeburn 2993: } else if (setting == 'lcauth') {
2994: var numauth = form.elements['lti_lcauth_'+item].length;
2995: if (numauth) {
2996: for (var i=0; i<numauth; i++) {
2997: if (form.elements['lti_lcauth_'+item][i].checked) {
2998: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
2999: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3000: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3001: } else {
3002: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3003: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3004: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3005: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3006: } else {
3007: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3008: }
3009: }
3010: }
3011: }
3012: }
3013: }
3014: }
1.326 raeburn 3015: } else if (setting == 'lcmenu') {
3016: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3017: var divid = 'lti_menufield_'+item;
3018: var setvis = '';
3019: for (var i=0; i<menus.length; i++) {
3020: var radioname = menus[i];
3021: var num = form.elements[radioname].length;
3022: if (num) {
3023: for (var j=0; j<num; j++) {
3024: if (form.elements[radioname][j].checked) {
3025: if (form.elements[radioname][j].value == '1') {
3026: if (document.getElementById(divid)) {
3027: document.getElementById(divid).style.display = 'inline-block';
3028: }
3029: setvis = 1;
3030: break;
3031: }
3032: }
3033: }
3034: }
3035: if (setvis == 1) {
3036: break;
3037: }
3038: }
3039: if (!setvis) {
3040: if (document.getElementById(divid)) {
3041: document.getElementById(divid).style.display = 'none';
3042: }
3043: }
1.320 raeburn 3044: }
3045: return;
3046: }
3047: // ]]>
3048: </script>
3049:
3050: ENDSCRIPT
3051: }
3052:
1.3 raeburn 3053: sub print_autoenroll {
1.30 raeburn 3054: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3055: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3056: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3057: if (ref($settings) eq 'HASH') {
3058: if (exists($settings->{'run'})) {
3059: if ($settings->{'run'} eq '0') {
3060: $runoff = ' checked="checked" ';
3061: $runon = ' ';
3062: } else {
3063: $runon = ' checked="checked" ';
3064: $runoff = ' ';
3065: }
3066: } else {
3067: if ($autorun) {
3068: $runon = ' checked="checked" ';
3069: $runoff = ' ';
3070: } else {
3071: $runoff = ' checked="checked" ';
3072: $runon = ' ';
3073: }
3074: }
1.129 raeburn 3075: if (exists($settings->{'co-owners'})) {
3076: if ($settings->{'co-owners'} eq '0') {
3077: $coownersoff = ' checked="checked" ';
3078: $coownerson = ' ';
3079: } else {
3080: $coownerson = ' checked="checked" ';
3081: $coownersoff = ' ';
3082: }
3083: } else {
3084: $coownersoff = ' checked="checked" ';
3085: $coownerson = ' ';
3086: }
1.3 raeburn 3087: if (exists($settings->{'sender_domain'})) {
3088: $defdom = $settings->{'sender_domain'};
3089: }
1.274 raeburn 3090: if (exists($settings->{'autofailsafe'})) {
3091: $failsafe = $settings->{'autofailsafe'};
3092: }
1.14 raeburn 3093: } else {
3094: if ($autorun) {
3095: $runon = ' checked="checked" ';
3096: $runoff = ' ';
3097: } else {
3098: $runoff = ' checked="checked" ';
3099: $runon = ' ';
3100: }
1.3 raeburn 3101: }
3102: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3103: my $notif_sender;
3104: if (ref($settings) eq 'HASH') {
3105: $notif_sender = $settings->{'sender_uname'};
3106: }
1.3 raeburn 3107: my $datatable='<tr class="LC_odd_row">'.
3108: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3109: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3110: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3111: $runon.' value="1" />'.&mt('Yes').'</label> '.
3112: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3113: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3114: '</tr><tr>'.
3115: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3116: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3117: &mt('username').': '.
3118: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3119: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3120: ': '.$domform.'</span></td></tr>'.
3121: '<tr class="LC_odd_row">'.
3122: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3123: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3124: '<input type="radio" name="autoassign_coowners"'.
3125: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3126: '<label><input type="radio" name="autoassign_coowners"'.
3127: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3128: '</tr><tr>'.
3129: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3130: '<td class="LC_right_item"><span class="LC_nobreak">'.
3131: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3132: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3133: $$rowtotal += 4;
1.3 raeburn 3134: return $datatable;
3135: }
3136:
3137: sub print_autoupdate {
1.30 raeburn 3138: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3139: my $datatable;
3140: if ($position eq 'top') {
3141: my $updateon = ' ';
3142: my $updateoff = ' checked="checked" ';
3143: my $classlistson = ' ';
3144: my $classlistsoff = ' checked="checked" ';
3145: if (ref($settings) eq 'HASH') {
3146: if ($settings->{'run'} eq '1') {
3147: $updateon = $updateoff;
3148: $updateoff = ' ';
3149: }
3150: if ($settings->{'classlists'} eq '1') {
3151: $classlistson = $classlistsoff;
3152: $classlistsoff = ' ';
3153: }
3154: }
3155: my %title = (
3156: run => 'Auto-update active?',
3157: classlists => 'Update information in classlists?',
3158: );
3159: $datatable = '<tr class="LC_odd_row">'.
3160: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3161: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3162: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3163: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3164: '<label><input type="radio" name="autoupdate_run"'.
3165: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3166: '</tr><tr>'.
3167: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3168: '<td class="LC_right_item"><span class="LC_nobreak">'.
3169: '<label><input type="radio" name="classlists"'.
3170: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3171: '<label><input type="radio" name="classlists"'.
3172: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3173: '</tr>';
1.30 raeburn 3174: $$rowtotal += 2;
1.131 raeburn 3175: } elsif ($position eq 'middle') {
3176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3177: my $numinrow = 3;
3178: my $locknamesettings;
3179: $datatable .= &insttypes_row($settings,$types,$usertypes,
3180: $dom,$numinrow,$othertitle,
1.305 raeburn 3181: 'lockablenames',$rowtotal);
1.131 raeburn 3182: $$rowtotal ++;
1.3 raeburn 3183: } else {
1.44 raeburn 3184: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3185: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3186: 'permanentemail','id');
1.33 raeburn 3187: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3188: my $numrows = 0;
1.26 raeburn 3189: if (ref($types) eq 'ARRAY') {
3190: if (@{$types} > 0) {
3191: $datatable =
3192: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3193: \@fields,$types,\$numrows);
1.30 raeburn 3194: $$rowtotal += @{$types};
1.26 raeburn 3195: }
1.3 raeburn 3196: }
3197: $datatable .=
3198: &usertype_update_row($settings,{'default' => $othertitle},
3199: \%fieldtitles,\@fields,['default'],
3200: \$numrows);
1.30 raeburn 3201: $$rowtotal ++;
1.3 raeburn 3202: }
3203: return $datatable;
3204: }
3205:
1.125 raeburn 3206: sub print_autocreate {
3207: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3208: my (%createon,%createoff,%currhash);
1.125 raeburn 3209: my @types = ('xml','req');
3210: if (ref($settings) eq 'HASH') {
3211: foreach my $item (@types) {
3212: $createoff{$item} = ' checked="checked" ';
3213: $createon{$item} = ' ';
3214: if (exists($settings->{$item})) {
3215: if ($settings->{$item}) {
3216: $createon{$item} = ' checked="checked" ';
3217: $createoff{$item} = ' ';
3218: }
3219: }
3220: }
1.210 raeburn 3221: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3222: $currhash{$settings->{'xmldc'}} = 1;
3223: }
1.125 raeburn 3224: } else {
3225: foreach my $item (@types) {
3226: $createoff{$item} = ' checked="checked" ';
3227: $createon{$item} = ' ';
3228: }
3229: }
3230: $$rowtotal += 2;
1.191 raeburn 3231: my $numinrow = 2;
1.125 raeburn 3232: my $datatable='<tr class="LC_odd_row">'.
3233: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3234: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3235: '<input type="radio" name="autocreate_xml"'.
3236: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3237: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3238: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3239: '</td></tr><tr>'.
3240: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3241: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3242: '<input type="radio" name="autocreate_req"'.
3243: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3244: '<label><input type="radio" name="autocreate_req"'.
3245: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3246: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3247: 'autocreate_xmldc',%currhash);
1.247 raeburn 3248: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3249: if ($numdc > 1) {
1.247 raeburn 3250: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3251: '</td><td class="LC_left_item">';
1.125 raeburn 3252: } else {
1.247 raeburn 3253: $datatable .= &mt('Course creation processed as:').
3254: '</td><td class="LC_right_item">';
1.125 raeburn 3255: }
1.247 raeburn 3256: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3257: $$rowtotal += $rows;
1.125 raeburn 3258: return $datatable;
3259: }
3260:
1.23 raeburn 3261: sub print_directorysrch {
1.277 raeburn 3262: my ($position,$dom,$settings,$rowtotal) = @_;
3263: my $datatable;
3264: if ($position eq 'top') {
3265: my $instsrchon = ' ';
3266: my $instsrchoff = ' checked="checked" ';
3267: my ($exacton,$containson,$beginson);
3268: my $instlocalon = ' ';
3269: my $instlocaloff = ' checked="checked" ';
3270: if (ref($settings) eq 'HASH') {
3271: if ($settings->{'available'} eq '1') {
3272: $instsrchon = $instsrchoff;
3273: $instsrchoff = ' ';
3274: }
3275: if ($settings->{'localonly'} eq '1') {
3276: $instlocalon = $instlocaloff;
3277: $instlocaloff = ' ';
3278: }
3279: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3280: foreach my $type (@{$settings->{'searchtypes'}}) {
3281: if ($type eq 'exact') {
3282: $exacton = ' checked="checked" ';
3283: } elsif ($type eq 'contains') {
3284: $containson = ' checked="checked" ';
3285: } elsif ($type eq 'begins') {
3286: $beginson = ' checked="checked" ';
3287: }
3288: }
3289: } else {
3290: if ($settings->{'searchtypes'} eq 'exact') {
3291: $exacton = ' checked="checked" ';
3292: } elsif ($settings->{'searchtypes'} eq 'contains') {
3293: $containson = ' checked="checked" ';
3294: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3295: $exacton = ' checked="checked" ';
3296: $containson = ' checked="checked" ';
3297: }
3298: }
1.277 raeburn 3299: }
3300: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3301: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3302:
3303: my $numinrow = 4;
3304: my $cansrchrow = 0;
3305: $datatable='<tr class="LC_odd_row">'.
3306: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3307: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3308: '<input type="radio" name="dirsrch_available"'.
3309: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3310: '<label><input type="radio" name="dirsrch_available"'.
3311: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3312: '</tr><tr>'.
3313: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3314: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3315: '<input type="radio" name="dirsrch_instlocalonly"'.
3316: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3317: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3318: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3319: '</tr>';
3320: $$rowtotal += 2;
3321: if (ref($usertypes) eq 'HASH') {
3322: if (keys(%{$usertypes}) > 0) {
3323: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3324: $numinrow,$othertitle,'cansearch',
3325: $rowtotal);
1.277 raeburn 3326: $cansrchrow = 1;
1.25 raeburn 3327: }
1.23 raeburn 3328: }
1.277 raeburn 3329: if ($cansrchrow) {
3330: $$rowtotal ++;
3331: $datatable .= '<tr>';
3332: } else {
3333: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3334: }
1.277 raeburn 3335: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3336: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3337: foreach my $title (@{$titleorder}) {
3338: if (defined($searchtitles->{$title})) {
3339: my $check = ' ';
3340: if (ref($settings) eq 'HASH') {
3341: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3342: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3343: $check = ' checked="checked" ';
3344: }
1.39 raeburn 3345: }
1.25 raeburn 3346: }
1.277 raeburn 3347: $datatable .= '<td class="LC_left_item">'.
3348: '<span class="LC_nobreak"><label>'.
3349: '<input type="checkbox" name="searchby" '.
3350: 'value="'.$title.'"'.$check.'/>'.
3351: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3352: }
3353: }
1.277 raeburn 3354: $datatable .= '</tr></table></td></tr>';
3355: $$rowtotal ++;
3356: if ($cansrchrow) {
3357: $datatable .= '<tr class="LC_odd_row">';
3358: } else {
3359: $datatable .= '<tr>';
3360: }
3361: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3362: '<td class="LC_left_item" colspan="2">'.
3363: '<span class="LC_nobreak"><label>'.
3364: '<input type="checkbox" name="searchtypes" '.
3365: $exacton.' value="exact" />'.&mt('Exact match').
3366: '</label> '.
3367: '<label><input type="checkbox" name="searchtypes" '.
3368: $beginson.' value="begins" />'.&mt('Begins with').
3369: '</label> '.
3370: '<label><input type="checkbox" name="searchtypes" '.
3371: $containson.' value="contains" />'.&mt('Contains').
3372: '</label></span></td></tr>';
3373: $$rowtotal ++;
1.26 raeburn 3374: } else {
1.277 raeburn 3375: my $domsrchon = ' checked="checked" ';
3376: my $domsrchoff = ' ';
3377: my $domlocalon = ' ';
3378: my $domlocaloff = ' checked="checked" ';
3379: if (ref($settings) eq 'HASH') {
3380: if ($settings->{'lclocalonly'} eq '1') {
3381: $domlocalon = $domlocaloff;
3382: $domlocaloff = ' ';
3383: }
3384: if ($settings->{'lcavailable'} eq '0') {
3385: $domsrchoff = $domsrchon;
3386: $domsrchon = ' ';
3387: }
3388: }
3389: $datatable='<tr class="LC_odd_row">'.
3390: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3392: '<input type="radio" name="dirsrch_domavailable"'.
3393: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3394: '<label><input type="radio" name="dirsrch_domavailable"'.
3395: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3396: '</tr><tr>'.
3397: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3398: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3399: '<input type="radio" name="dirsrch_domlocalonly"'.
3400: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3401: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3402: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3403: '</tr>';
3404: $$rowtotal += 2;
1.26 raeburn 3405: }
1.25 raeburn 3406: return $datatable;
3407: }
3408:
1.28 raeburn 3409: sub print_contacts {
1.286 raeburn 3410: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3411: my $datatable;
3412: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3413: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3414: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3415: if ($position eq 'top') {
3416: if (ref($settings) eq 'HASH') {
3417: foreach my $item (@contacts) {
3418: if (exists($settings->{$item})) {
3419: $to{$item} = $settings->{$item};
3420: }
3421: }
3422: }
3423: } elsif ($position eq 'middle') {
3424: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3425: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3426: foreach my $type (@mailings) {
3427: $otheremails{$type} = '';
3428: }
1.340 raeburn 3429: } elsif ($position eq 'lower') {
3430: if (ref($settings) eq 'HASH') {
3431: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3432: %lonstatus = %{$settings->{'lonstatus'}};
3433: }
3434: }
1.286 raeburn 3435: } else {
3436: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3437: foreach my $type (@mailings) {
3438: $otheremails{$type} = '';
3439: }
1.286 raeburn 3440: $bccemails{'helpdeskmail'} = '';
3441: $bccemails{'otherdomsmail'} = '';
3442: $includestr{'helpdeskmail'} = '';
3443: $includestr{'otherdomsmail'} = '';
3444: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3445: }
1.28 raeburn 3446: if (ref($settings) eq 'HASH') {
1.340 raeburn 3447: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3448: foreach my $type (@mailings) {
3449: if (exists($settings->{$type})) {
3450: if (ref($settings->{$type}) eq 'HASH') {
3451: foreach my $item (@contacts) {
3452: if ($settings->{$type}{$item}) {
3453: $checked{$type}{$item} = ' checked="checked" ';
3454: }
3455: }
3456: $otheremails{$type} = $settings->{$type}{'others'};
3457: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3458: $bccemails{$type} = $settings->{$type}{'bcc'};
3459: if ($settings->{$type}{'include'} ne '') {
3460: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3461: $includestr{$type} = &unescape($includestr{$type});
3462: }
3463: }
3464: }
3465: } elsif ($type eq 'lonstatusmail') {
3466: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3467: }
1.28 raeburn 3468: }
3469: }
1.286 raeburn 3470: if ($position eq 'bottom') {
3471: foreach my $type (@mailings) {
3472: $bccemails{$type} = $settings->{$type}{'bcc'};
3473: if ($settings->{$type}{'include'} ne '') {
3474: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3475: $includestr{$type} = &unescape($includestr{$type});
3476: }
3477: }
3478: if (ref($settings->{'helpform'}) eq 'HASH') {
3479: if (ref($fields) eq 'ARRAY') {
3480: foreach my $field (@{$fields}) {
3481: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3482: }
1.286 raeburn 3483: }
3484: if (exists($settings->{'helpform'}{'maxsize'})) {
3485: $maxsize = $settings->{'helpform'}{'maxsize'};
3486: } else {
1.289 raeburn 3487: $maxsize = '1.0';
1.286 raeburn 3488: }
3489: } else {
3490: if (ref($fields) eq 'ARRAY') {
3491: foreach my $field (@{$fields}) {
3492: $currfield{$field} = 'yes';
1.134 raeburn 3493: }
1.28 raeburn 3494: }
1.286 raeburn 3495: $maxsize = '1.0';
1.28 raeburn 3496: }
3497: }
3498: } else {
1.286 raeburn 3499: if ($position eq 'top') {
3500: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3501: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3502: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3503: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3504: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3505: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3506: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3507: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3508: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3509: } elsif ($position eq 'bottom') {
3510: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3511: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3512: if (ref($fields) eq 'ARRAY') {
3513: foreach my $field (@{$fields}) {
3514: $currfield{$field} = 'yes';
3515: }
3516: }
3517: $maxsize = '1.0';
3518: }
1.28 raeburn 3519: }
3520: my ($titles,$short_titles) = &contact_titles();
3521: my $rownum = 0;
3522: my $css_class;
1.286 raeburn 3523: if ($position eq 'top') {
3524: foreach my $item (@contacts) {
3525: $css_class = $rownum%2?' class="LC_odd_row"':'';
3526: $datatable .= '<tr'.$css_class.'>'.
3527: '<td><span class="LC_nobreak">'.$titles->{$item}.
3528: '</span></td><td class="LC_right_item">'.
3529: '<input type="text" name="'.$item.'" value="'.
3530: $to{$item}.'" /></td></tr>';
3531: $rownum ++;
3532: }
1.315 raeburn 3533: } elsif ($position eq 'bottom') {
3534: $css_class = $rownum%2?' class="LC_odd_row"':'';
3535: $datatable .= '<tr'.$css_class.'>'.
3536: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3537: &mt('(e-mail, subject, and description always shown)').
3538: '</td><td class="LC_left_item">';
3539: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3540: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3541: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3542: foreach my $field (@{$fields}) {
3543: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3544: if (($field eq 'screenshot') || ($field eq 'cc')) {
3545: $datatable .= ' '.&mt('(logged-in users)');
3546: }
3547: $datatable .='</td><td>';
3548: my $clickaction;
3549: if ($field eq 'screenshot') {
3550: $clickaction = ' onclick="screenshotSize(this);"';
3551: }
3552: if (ref($possoptions->{$field}) eq 'ARRAY') {
3553: foreach my $option (@{$possoptions->{$field}}) {
3554: my $checked;
3555: if ($currfield{$field} eq $option) {
3556: $checked = ' checked="checked"';
3557: }
3558: $datatable .= '<span class="LC_nobreak"><label>'.
3559: '<input type="radio" name="helpform_'.$field.'" '.
3560: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3561: '</label></span>'.(' 'x2);
3562: }
3563: }
3564: if ($field eq 'screenshot') {
3565: my $display;
3566: if ($currfield{$field} eq 'no') {
3567: $display = ' style="display:none"';
3568: }
1.334 raeburn 3569: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3570: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3571: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3572: }
3573: $datatable .= '</td></tr>';
3574: }
3575: $datatable .= '</table>';
3576: }
3577: $datatable .= '</td></tr>'."\n";
3578: $rownum ++;
3579: }
1.340 raeburn 3580: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3581: foreach my $type (@mailings) {
3582: $css_class = $rownum%2?' class="LC_odd_row"':'';
3583: $datatable .= '<tr'.$css_class.'>'.
3584: '<td><span class="LC_nobreak">'.
3585: $titles->{$type}.': </span></td>'.
3586: '<td class="LC_left_item">';
3587: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3588: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3589: }
3590: $datatable .= '<span class="LC_nobreak">';
3591: foreach my $item (@contacts) {
3592: $datatable .= '<label>'.
3593: '<input type="checkbox" name="'.$type.'"'.
3594: $checked{$type}{$item}.
3595: ' value="'.$item.'" />'.$short_titles->{$item}.
3596: '</label> ';
3597: }
3598: $datatable .= '</span><br />'.&mt('Others').': '.
3599: '<input type="text" name="'.$type.'_others" '.
3600: 'value="'.$otheremails{$type}.'" />';
3601: my %locchecked;
3602: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3603: foreach my $loc ('s','b') {
3604: if ($includeloc{$type} eq $loc) {
3605: $locchecked{$loc} = ' checked="checked"';
3606: last;
3607: }
3608: }
3609: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3610: '<input type="text" name="'.$type.'_bcc" '.
3611: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3612: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3613: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3614: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3615: '<span class="LC_nobreak">'.&mt('Location:').' '.
3616: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3617: (' 'x2).
3618: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3619: '</span></fieldset>';
3620: }
3621: $datatable .= '</td></tr>'."\n";
3622: $rownum ++;
3623: }
1.28 raeburn 3624: }
1.286 raeburn 3625: if ($position eq 'middle') {
3626: my %choices;
1.340 raeburn 3627: my $corelink = &core_link_msu();
3628: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3629: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3630: $corelink);
3631: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3632: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3633: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3634: 'reportupdates' => 'on',
3635: 'reportstatus' => 'on');
1.286 raeburn 3636: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3637: \%choices,$rownum);
3638: $datatable .= $reports;
1.340 raeburn 3639: } elsif ($position eq 'lower') {
3640: $css_class = $rownum%2?' class="LC_odd_row"':'';
3641: my ($threshold,$sysmail,%excluded,%weights);
3642: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3643: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3644: $threshold = $lonstatus{'threshold'};
3645: } else {
3646: $threshold = $defaults->{'threshold'};
3647: }
3648: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3649: $sysmail = $lonstatus{'sysmail'};
3650: } else {
3651: $sysmail = $defaults->{'sysmail'};
3652: }
3653: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3654: foreach my $type ('E','W','N','U') {
1.340 raeburn 3655: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3656: $weights{$type} = $lonstatus{'weights'}{$type};
3657: } else {
3658: $weights{$type} = $defaults->{$type};
3659: }
3660: }
3661: } else {
1.341 raeburn 3662: foreach my $type ('E','W','N','U') {
1.340 raeburn 3663: $weights{$type} = $defaults->{$type};
3664: }
3665: }
3666: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3667: if (@{$lonstatus{'excluded'}} > 0) {
3668: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3669: }
3670: }
3671: $datatable .= '<tr'.$css_class.'>'.
3672: '<td class="LC_left_item"><span class="LC_nobreak">'.
3673: $titles->{'errorthreshold'}.
3674: '</span></td><td class="LC_left_item">'.
3675: '<input type="text" name="errorthreshold" value="'.
3676: $threshold.'" size="5" /></td></tr>';
3677: $rownum ++;
3678: $css_class = $rownum%2?' class="LC_odd_row"':'';
3679: $datatable .= '<tr'.$css_class.'>'.
3680: '<td class="LC_left_item">'.
3681: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3682: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3683: foreach my $type ('E','W','N','U') {
1.340 raeburn 3684: $datatable .= '<td>'.$names->{$type}.'<br />'.
3685: '<input type="text" name="errorweights_'.$type.'" value="'.
3686: $weights{$type}.'" size="5" /></td>';
3687: }
3688: $datatable .= '</tr></table></tr>';
3689: $rownum ++;
3690: $css_class = $rownum%2?' class="LC_odd_row"':'';
3691: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3692: $titles->{'errorexcluded'}.'</td>'.
3693: '<td class="LC_left_item"><table>';
3694: my $numinrow = 4;
3695: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3696: for (my $i=0; $i<@ids; $i++) {
3697: my $rem = $i%($numinrow);
3698: if ($rem == 0) {
3699: if ($i > 0) {
3700: $datatable .= '</tr>';
3701: }
3702: $datatable .= '<tr>';
3703: }
3704: my $check;
3705: if ($excluded{$ids[$i]}) {
3706: $check = ' checked="checked" ';
3707: }
3708: $datatable .= '<td class="LC_left_item">'.
3709: '<span class="LC_nobreak"><label>'.
3710: '<input type="checkbox" name="errorexcluded" '.
3711: 'value="'.$ids[$i].'"'.$check.' />'.
3712: $ids[$i].'</label></span></td>';
3713: }
3714: my $colsleft = $numinrow - @ids%($numinrow);
3715: if ($colsleft > 1 ) {
3716: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3717: ' </td>';
3718: } elsif ($colsleft == 1) {
3719: $datatable .= '<td class="LC_left_item"> </td>';
3720: }
3721: $datatable .= '</tr></table></td></tr>';
3722: $rownum ++;
3723: $css_class = $rownum%2?' class="LC_odd_row"':'';
3724: $datatable .= '<tr'.$css_class.'>'.
3725: '<td class="LC_left_item"><span class="LC_nobreak">'.
3726: $titles->{'errorsysmail'}.
3727: '</span></td><td class="LC_left_item">'.
3728: '<input type="text" name="errorsysmail" value="'.
3729: $sysmail.'" size="5" /></td></tr>';
3730: $rownum ++;
1.286 raeburn 3731: } elsif ($position eq 'bottom') {
1.315 raeburn 3732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3733: my (@posstypes,%usertypeshash);
3734: if (ref($types) eq 'ARRAY') {
3735: @posstypes = @{$types};
3736: }
3737: if (@posstypes) {
3738: if (ref($usertypes) eq 'HASH') {
3739: %usertypeshash = %{$usertypes};
3740: }
3741: my @overridden;
3742: my $numinrow = 4;
3743: if (ref($settings) eq 'HASH') {
3744: if (ref($settings->{'overrides'}) eq 'HASH') {
3745: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3746: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3747: push(@overridden,$key);
3748: foreach my $item (@contacts) {
3749: if ($settings->{'overrides'}{$key}{$item}) {
3750: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3751: }
3752: }
3753: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3754: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3755: $includeloc{'override_'.$key} = '';
3756: $includestr{'override_'.$key} = '';
3757: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3758: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3759: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3760: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3761: }
1.286 raeburn 3762: }
3763: }
3764: }
1.315 raeburn 3765: }
3766: my $customclass = 'LC_helpdesk_override';
3767: my $optionsprefix = 'LC_options_helpdesk_';
3768:
3769: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3770:
3771: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3772: $numinrow,$othertitle,'overrides',
3773: \$rownum,$onclicktypes,$customclass);
3774: $rownum ++;
3775: $usertypeshash{'default'} = $othertitle;
3776: foreach my $status (@posstypes) {
3777: my $css_class;
3778: if ($rownum%2) {
3779: $css_class = 'LC_odd_row ';
3780: }
3781: $css_class .= $customclass;
3782: my $rowid = $optionsprefix.$status;
3783: my $hidden = 1;
3784: my $currstyle = 'display:none';
3785: if (grep(/^\Q$status\E$/,@overridden)) {
3786: $currstyle = 'display:table-row';
3787: $hidden = 0;
3788: }
3789: my $key = 'override_'.$status;
3790: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3791: $includeloc{$key},$includestr{$key},$status,$rowid,
3792: $usertypeshash{$status},$css_class,$currstyle,
3793: \@contacts,$short_titles);
3794: unless ($hidden) {
3795: $rownum ++;
1.286 raeburn 3796: }
3797: }
1.134 raeburn 3798: }
1.28 raeburn 3799: }
1.30 raeburn 3800: $$rowtotal += $rownum;
1.28 raeburn 3801: return $datatable;
3802: }
3803:
1.340 raeburn 3804: sub core_link_msu {
3805: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3806: &mt('LON-CAPA core group - MSU'),600,500);
3807: }
3808:
1.315 raeburn 3809: sub overridden_helpdesk {
3810: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3811: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3812: my $class = 'LC_left_item';
3813: if ($css_class) {
3814: $css_class = ' class="'.$css_class.'"';
3815: }
3816: if ($rowid) {
3817: $rowid = ' id="'.$rowid.'"';
3818: }
3819: if ($rowstyle) {
3820: $rowstyle = ' style="'.$rowstyle.'"';
3821: }
3822: my ($output,$description);
3823: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3824: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3825: "<td>$description</td>\n".
3826: '<td class="'.$class.'" colspan="2">'.
3827: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3828: '<span class="LC_nobreak">';
3829: if (ref($contacts) eq 'ARRAY') {
3830: foreach my $item (@{$contacts}) {
3831: my $check;
3832: if (ref($checked) eq 'HASH') {
3833: $check = $checked->{$item};
3834: }
3835: my $title;
3836: if (ref($short_titles) eq 'HASH') {
3837: $title = $short_titles->{$item};
3838: }
3839: $output .= '<label>'.
3840: '<input type="checkbox" name="override_'.$type.'"'.$check.
3841: ' value="'.$item.'" />'.$title.'</label> ';
3842: }
3843: }
3844: $output .= '</span><br />'.&mt('Others').': '.
3845: '<input type="text" name="override_'.$type.'_others" '.
3846: 'value="'.$otheremails.'" />';
3847: my %locchecked;
3848: foreach my $loc ('s','b') {
3849: if ($includeloc eq $loc) {
3850: $locchecked{$loc} = ' checked="checked"';
3851: last;
3852: }
3853: }
3854: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3855: '<input type="text" name="override_'.$type.'_bcc" '.
3856: 'value="'.$bccemails.'" /></fieldset>'.
3857: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3858: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3859: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3860: '<span class="LC_nobreak">'.&mt('Location:').' '.
3861: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3862: (' 'x2).
3863: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3864: '</span></fieldset>'.
3865: '</td></tr>'."\n";
3866: return $output;
3867: }
3868:
1.286 raeburn 3869: sub contacts_javascript {
3870: return <<"ENDSCRIPT";
3871:
3872: <script type="text/javascript">
3873: // <![CDATA[
3874:
3875: function screenshotSize(field) {
3876: if (document.getElementById('help_screenshotsize')) {
3877: if (field.value == 'no') {
1.289 raeburn 3878: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3879: } else {
3880: document.getElementById('help_screenshotsize').style.display="";
3881: }
3882: }
3883: return;
3884: }
3885:
1.315 raeburn 3886: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3887: if (form.elements[checkbox].length != undefined) {
3888: var count = 0;
3889: if (docount) {
3890: for (var i=0; i<form.elements[checkbox].length; i++) {
3891: if (form.elements[checkbox][i].checked) {
3892: count ++;
3893: }
3894: }
3895: }
3896: for (var i=0; i<form.elements[checkbox].length; i++) {
3897: var type = form.elements[checkbox][i].value;
3898: if (document.getElementById(prefix+type)) {
3899: if (form.elements[checkbox][i].checked) {
3900: document.getElementById(prefix+type).style.display = 'table-row';
3901: if (count % 2 == 1) {
3902: document.getElementById(prefix+type).className = target+' LC_odd_row';
3903: } else {
3904: document.getElementById(prefix+type).className = target;
3905: }
3906: count ++;
3907: } else {
3908: document.getElementById(prefix+type).style.display = 'none';
3909: }
3910: }
3911: }
3912: }
3913: return;
3914: }
3915:
3916:
1.286 raeburn 3917: // ]]>
3918: </script>
3919:
3920: ENDSCRIPT
3921: }
3922:
1.118 jms 3923: sub print_helpsettings {
1.282 raeburn 3924: my ($position,$dom,$settings,$rowtotal) = @_;
3925: my $confname = $dom.'-domainconfig';
1.285 raeburn 3926: my $formname = 'display';
1.168 raeburn 3927: my ($datatable,$itemcount);
1.282 raeburn 3928: if ($position eq 'top') {
3929: $itemcount = 1;
3930: my (%choices,%defaultchecked,@toggles);
3931: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3932: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3933: &mt('LON-CAPA bug tracker'),600,500));
3934: %defaultchecked = ('submitbugs' => 'on');
3935: @toggles = ('submitbugs');
3936: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3937: \%choices,$itemcount);
3938: $$rowtotal ++;
3939: } else {
3940: my $css_class;
3941: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3942: my (%customroles,%ordered,%current);
1.301 raeburn 3943: if (ref($settings) eq 'HASH') {
3944: if (ref($settings->{'adhoc'}) eq 'HASH') {
3945: %current = %{$settings->{'adhoc'}};
3946: }
1.285 raeburn 3947: }
3948: my $count = 0;
3949: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3950: if ($key=~/^rolesdef\_(\w+)$/) {
3951: my $rolename = $1;
1.285 raeburn 3952: my (%privs,$order);
1.282 raeburn 3953: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3954: $customroles{$rolename} = \%privs;
1.285 raeburn 3955: if (ref($current{$rolename}) eq 'HASH') {
3956: $order = $current{$rolename}{'order'};
3957: }
3958: if ($order eq '') {
3959: $order = $count;
3960: }
3961: $ordered{$order} = $rolename;
3962: $count++;
3963: }
3964: }
3965: my $maxnum = scalar(keys(%ordered));
3966: my @roles_by_num = ();
3967: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3968: push(@roles_by_num,$item);
3969: }
3970: my $context = 'domprefs';
3971: my $crstype = 'Course';
3972: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3973: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3974: my ($numstatustypes,@jsarray);
3975: if (ref($types) eq 'ARRAY') {
3976: if (@{$types} > 0) {
3977: $numstatustypes = scalar(@{$types});
3978: push(@accesstypes,'status');
3979: @jsarray = ('bystatus');
1.282 raeburn 3980: }
3981: }
1.290 raeburn 3982: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3983: if (keys(%domhelpdesk)) {
3984: push(@accesstypes,('inc','exc'));
3985: push(@jsarray,('notinc','notexc'));
3986: }
3987: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3988: my $context = 'domprefs';
3989: my $crstype = 'Course';
1.285 raeburn 3990: my $prefix = 'helproles_';
3991: my $add_class = 'LC_hidden';
3992: foreach my $num (@roles_by_num) {
3993: my $role = $ordered{$num};
3994: my ($desc,$access,@statuses);
3995: if (ref($current{$role}) eq 'HASH') {
3996: $desc = $current{$role}{'desc'};
3997: $access = $current{$role}{'access'};
3998: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3999: @statuses = @{$current{$role}{'insttypes'}};
4000: }
4001: }
4002: if ($desc eq '') {
4003: $desc = $role;
4004: }
4005: my $identifier = 'custhelp'.$num;
1.282 raeburn 4006: my %full=();
4007: my %levels= (
4008: course => {},
4009: domain => {},
4010: system => {},
4011: );
4012: my %levelscurrent=(
4013: course => {},
4014: domain => {},
4015: system => {},
4016: );
4017: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4018: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4019: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4020: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4021: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4022: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4023: for (my $k=0; $k<=$maxnum; $k++) {
4024: my $vpos = $k+1;
4025: my $selstr;
4026: if ($k == $num) {
4027: $selstr = ' selected="selected" ';
4028: }
4029: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4030: }
4031: $datatable .= '</select>'.(' 'x2).
4032: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4033: '</td>'.
4034: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4035: &mt('Name shown to users:').
4036: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4037: '</fieldset>'.
4038: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4039: $othertitle,$usertypes,$types,\%domhelpdesk).
4040: '<fieldset>'.
4041: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4042: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4043: \%levelscurrent,$identifier,
4044: 'LC_hidden',$prefix.$num.'_privs').
4045: '</fieldset></td>';
1.282 raeburn 4046: $itemcount ++;
4047: }
4048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4049: my $newcust = 'custhelp'.$count;
4050: my (%privs,%levelscurrent);
4051: my %full=();
4052: my %levels= (
4053: course => {},
4054: domain => {},
4055: system => {},
4056: );
4057: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4058: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4059: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4060: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4061: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4062: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4063: for (my $k=0; $k<$maxnum+1; $k++) {
4064: my $vpos = $k+1;
4065: my $selstr;
4066: if ($k == $maxnum) {
4067: $selstr = ' selected="selected" ';
4068: }
4069: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4070: }
4071: $datatable .= '</select> '."\n".
1.282 raeburn 4072: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4073: '</label></span></td>'.
1.285 raeburn 4074: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4075: '<span class="LC_nobreak">'.
4076: &mt('Internal name:').
4077: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4078: '</span>'.(' 'x4).
4079: '<span class="LC_nobreak">'.
4080: &mt('Name shown to users:').
4081: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4082: '</span></fieldset>'.
4083: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4084: $usertypes,$types,\%domhelpdesk).
4085: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4086: &Apache::lonuserutils::custom_role_header($context,$crstype,
4087: \@templateroles,$newcust).
4088: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4089: \%levelscurrent,$newcust).
1.334 raeburn 4090: '</fieldset>'.
4091: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4092: '</td></tr>';
1.282 raeburn 4093: $count ++;
4094: $$rowtotal += $count;
4095: }
1.166 raeburn 4096: return $datatable;
1.121 raeburn 4097: }
4098:
1.285 raeburn 4099: sub adhocbutton {
4100: my ($prefix,$num,$field,$visibility) = @_;
4101: my %lt = &Apache::lonlocal::texthash(
4102: show => 'Show details',
4103: hide => 'Hide details',
4104: );
4105: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4106: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4107: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4108: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4109: }
4110:
4111: sub helpsettings_javascript {
4112: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4113: return unless(ref($roles_by_num) eq 'ARRAY');
4114: my %html_js_lt = &Apache::lonlocal::texthash(
4115: show => 'Show details',
4116: hide => 'Hide details',
4117: );
4118: &html_escape(\%html_js_lt);
4119: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4120: return <<"ENDSCRIPT";
4121: <script type="text/javascript">
4122: // <![CDATA[
4123:
4124: function reorderHelpRoles(form,item) {
4125: var changedVal;
4126: $jstext
4127: var newpos = 'helproles_${total}_pos';
4128: var maxh = 1 + $total;
4129: var current = new Array();
4130: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4131: if (item == newpos) {
4132: changedVal = newitemVal;
4133: } else {
4134: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4135: current[newitemVal] = newpos;
4136: }
4137: for (var i=0; i<helproles.length; i++) {
4138: var elementName = 'helproles_'+helproles[i]+'_pos';
4139: if (elementName != item) {
4140: if (form.elements[elementName]) {
4141: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4142: current[currVal] = elementName;
4143: }
4144: }
4145: }
4146: var oldVal;
4147: for (var j=0; j<maxh; j++) {
4148: if (current[j] == undefined) {
4149: oldVal = j;
4150: }
4151: }
4152: if (oldVal < changedVal) {
4153: for (var k=oldVal+1; k<=changedVal ; k++) {
4154: var elementName = current[k];
4155: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4156: }
4157: } else {
4158: for (var k=changedVal; k<oldVal; k++) {
4159: var elementName = current[k];
4160: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4161: }
4162: }
4163: return;
4164: }
4165:
4166: function helpdeskAccess(num) {
4167: var curraccess = null;
4168: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4169: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4170: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4171: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4172: }
4173: }
4174: }
4175: var shown = Array();
4176: var hidden = Array();
4177: if (curraccess == 'none') {
4178: hidden = Array('$hiddenstr');
4179: } else {
4180: if (curraccess == 'status') {
4181: shown = Array('bystatus');
4182: hidden = Array('notinc','notexc');
4183: } else {
4184: if (curraccess == 'exc') {
4185: shown = Array('notexc');
4186: hidden = Array('notinc','bystatus');
4187: }
4188: if (curraccess == 'inc') {
4189: shown = Array('notinc');
4190: hidden = Array('notexc','bystatus');
4191: }
1.293 raeburn 4192: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4193: hidden = Array('notinc','notexc','bystatus');
4194: }
4195: }
4196: }
4197: if (hidden.length > 0) {
4198: for (var i=0; i<hidden.length; i++) {
4199: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4200: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4201: }
4202: }
4203: }
4204: if (shown.length > 0) {
4205: for (var i=0; i<shown.length; i++) {
4206: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4207: if (shown[i] == 'privs') {
4208: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4209: } else {
4210: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4211: }
4212: }
4213: }
4214: }
4215: return;
4216: }
4217:
4218: function toggleHelpdeskItem(num,field) {
4219: if (document.getElementById('helproles_'+num+'_'+field)) {
4220: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4221: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4222: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4223: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4224: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4225: }
4226: } else {
4227: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4228: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4229: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4230: }
4231: }
4232: }
4233: return;
4234: }
4235:
4236: // ]]>
4237: </script>
4238:
4239: ENDSCRIPT
4240: }
4241:
4242: sub helpdeskroles_access {
4243: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4244: $usertypes,$types,$domhelpdesk) = @_;
4245: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4246: my %lt = &Apache::lonlocal::texthash(
4247: 'rou' => 'Role usage',
4248: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4249: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4250: 'dh' => 'All with domain helpdesk role',
4251: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4252: 'none' => 'None',
4253: 'status' => 'Determined based on institutional status',
4254: 'inc' => 'Include all, but exclude specific personnel',
4255: 'exc' => 'Exclude all, but include specific personnel',
4256: );
4257: my %usecheck = (
4258: all => ' checked="checked"',
4259: );
4260: my %displaydiv = (
4261: status => 'none',
4262: inc => 'none',
4263: exc => 'none',
4264: priv => 'block',
4265: );
4266: my $output;
4267: if (ref($current) eq 'HASH') {
4268: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4269: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4270: $usecheck{$current->{access}} = $usecheck{'all'};
4271: delete($usecheck{'all'});
4272: if ($current->{access} =~ /^(status|inc|exc)$/) {
4273: my $access = $1;
4274: $displaydiv{$access} = 'inline';
4275: } elsif ($current->{access} eq 'none') {
4276: $displaydiv{'priv'} = 'none';
4277: }
4278: }
4279: }
4280: }
4281: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4282: '<p>'.$lt{'whi'}.'</p>';
4283: foreach my $access (@{$accesstypes}) {
4284: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4285: ' onclick="helpdeskAccess('."'$num'".');" />'.
4286: $lt{$access}.'</label>';
4287: if ($access eq 'status') {
4288: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4289: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4290: $othertitle,$usertypes,$types).
4291: '</div>';
4292: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4293: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4294: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4295: '</div>';
4296: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4297: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4298: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4299: '</div>';
4300: }
4301: $output .= '</p>';
4302: }
4303: $output .= '</fieldset>';
4304: return $output;
4305: }
4306:
1.121 raeburn 4307: sub radiobutton_prefs {
1.192 raeburn 4308: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4309: $additional,$align) = @_;
1.121 raeburn 4310: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4311: (ref($choices) eq 'HASH'));
4312:
1.170 raeburn 4313: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4314:
4315: foreach my $item (@{$toggles}) {
4316: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4317: $checkedon{$item} = ' checked="checked" ';
4318: $checkedoff{$item} = ' ';
1.121 raeburn 4319: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4320: $checkedoff{$item} = ' checked="checked" ';
4321: $checkedon{$item} = ' ';
4322: }
4323: }
4324: if (ref($settings) eq 'HASH') {
1.121 raeburn 4325: foreach my $item (@{$toggles}) {
1.118 jms 4326: if ($settings->{$item} eq '1') {
4327: $checkedon{$item} = ' checked="checked" ';
4328: $checkedoff{$item} = ' ';
4329: } elsif ($settings->{$item} eq '0') {
4330: $checkedoff{$item} = ' checked="checked" ';
4331: $checkedon{$item} = ' ';
4332: }
4333: }
1.121 raeburn 4334: }
1.192 raeburn 4335: if ($onclick) {
4336: $onclick = ' onclick="'.$onclick.'"';
4337: }
1.121 raeburn 4338: foreach my $item (@{$toggles}) {
1.118 jms 4339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4340: $datatable .=
1.306 raeburn 4341: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4342: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4343: '</span></td>';
4344: if ($align eq 'left') {
4345: $datatable .= '<td class="LC_left_item">';
4346: } else {
4347: $datatable .= '<td class="LC_right_item">';
4348: }
1.289 raeburn 4349: $datatable .=
1.257 raeburn 4350: '<span class="LC_nobreak">'.
1.118 jms 4351: '<label><input type="radio" name="'.
1.192 raeburn 4352: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4353: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4354: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4355: '</span>'.$additional.
4356: '</td>'.
1.118 jms 4357: '</tr>';
4358: $itemcount ++;
1.121 raeburn 4359: }
4360: return ($datatable,$itemcount);
4361: }
4362:
1.267 raeburn 4363: sub print_ltitools {
4364: my ($dom,$settings,$rowtotal) = @_;
4365: my $rownum = 0;
4366: my $css_class;
4367: my $itemcount = 1;
4368: my $maxnum = 0;
4369: my %ordered;
4370: if (ref($settings) eq 'HASH') {
4371: foreach my $item (keys(%{$settings})) {
4372: if (ref($settings->{$item}) eq 'HASH') {
4373: my $num = $settings->{$item}{'order'};
4374: $ordered{$num} = $item;
4375: }
4376: }
4377: }
4378: my $confname = $dom.'-domainconfig';
4379: my $switchserver = &check_switchserver($dom,$confname);
4380: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4381: my $datatable;
1.267 raeburn 4382: my %lt = <itools_names();
4383: my @courseroles = ('cc','in','ta','ep','st');
4384: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4385: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4386: if (keys(%ordered)) {
4387: my @items = sort { $a <=> $b } keys(%ordered);
4388: for (my $i=0; $i<@items; $i++) {
4389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4390: my $item = $ordered{$items[$i]};
1.323 raeburn 4391: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4392: if (ref($settings->{$item}) eq 'HASH') {
4393: $title = $settings->{$item}->{'title'};
4394: $url = $settings->{$item}->{'url'};
4395: $key = $settings->{$item}->{'key'};
4396: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4397: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4398: my $image = $settings->{$item}->{'image'};
4399: if ($image ne '') {
4400: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4401: }
1.323 raeburn 4402: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4403: $sigsel{'HMAC-256'} = ' selected="selected"';
4404: } else {
4405: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4406: }
1.267 raeburn 4407: }
1.319 raeburn 4408: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4409: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4410: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4411: for (my $k=0; $k<=$maxnum; $k++) {
4412: my $vpos = $k+1;
4413: my $selstr;
4414: if ($k == $i) {
4415: $selstr = ' selected="selected" ';
4416: }
4417: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4418: }
4419: $datatable .= '</select>'.(' 'x2).
4420: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4421: &mt('Delete?').'</label></span></td>'.
4422: '<td colspan="2">'.
4423: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4424: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4425: (' 'x2).
4426: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4427: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4428: (' 'x2).
4429: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4430: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4431: (' 'x2).
4432: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4433: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4434: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4435: '<br /><br />'.
1.323 raeburn 4436: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4437: ' value="'.$url.'" /></span>'.
4438: (' 'x2).
1.319 raeburn 4439: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4440: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4441: (' 'x2).
1.322 raeburn 4442: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4443: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4444: (' 'x2).
1.267 raeburn 4445: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4446: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4447: '<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>'.
4448: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4449: '</fieldset>'.
4450: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4451: '<span class="LC_nobreak">'.&mt('Display target:');
4452: my %currdisp;
4453: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4454: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4455: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4456: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4457: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4458: } else {
4459: $currdisp{'iframe'} = ' checked="checked"';
4460: }
4461: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4462: $currdisp{'width'} = $1;
4463: }
4464: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4465: $currdisp{'height'} = $1;
4466: }
1.296 raeburn 4467: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4468: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4469: } else {
4470: $currdisp{'iframe'} = ' checked="checked"';
4471: }
1.298 raeburn 4472: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4473: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4474: $lt{$disp}.'</label>'.(' 'x2);
4475: }
4476: $datatable .= (' 'x4);
4477: foreach my $dimen ('width','height') {
4478: $datatable .= '<label>'.$lt{$dimen}.' '.
4479: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4480: (' 'x2);
4481: }
1.334 raeburn 4482: $datatable .= '</span><br />'.
1.296 raeburn 4483: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4484: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4485: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4486: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4487: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4488: my %units = (
4489: 'passback' => 'days',
4490: 'roster' => 'seconds',
4491: );
1.267 raeburn 4492: foreach my $extra ('passback','roster') {
1.319 raeburn 4493: my $validsty = 'none';
4494: my $currvalid;
1.267 raeburn 4495: my $checkedon = '';
4496: my $checkedoff = ' checked="checked"';
4497: if ($settings->{$item}->{$extra}) {
4498: $checkedon = $checkedoff;
4499: $checkedoff = '';
1.319 raeburn 4500: $validsty = 'inline-block';
4501: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4502: $currvalid = $settings->{$item}->{$extra.'valid'};
4503: }
4504: }
4505: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4506: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4507: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4508: &mt('No').'</label>'.(' 'x2).
4509: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4510: &mt('Yes').'</label></span></div>'.
4511: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4512: '<span class="LC_nobreak">'.
4513: &mt("at least [_1] $units{$extra} after launch",
4514: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4515: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4516: }
1.319 raeburn 4517: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4518: if ($imgsrc) {
4519: $datatable .= $imgsrc.
4520: '<label><input type="checkbox" name="ltitools_image_del"'.
4521: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4522: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4523: } else {
4524: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4525: }
4526: if ($switchserver) {
4527: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4528: } else {
4529: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4530: }
4531: $datatable .= '</span></fieldset>';
1.324 raeburn 4532: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4533: if (ref($settings->{$item}) eq 'HASH') {
4534: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4535: %checkedfields = %{$settings->{$item}->{'fields'}};
4536: }
1.324 raeburn 4537: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4538: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4539: %rolemaps = %{$settings->{$item}->{'roles'}};
4540: $checkedfields{'roles'} = 1;
4541: }
4542: }
4543: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4544: '<span class="LC_nobreak">';
1.324 raeburn 4545: my $userfieldstyle = 'display:none;';
4546: my $seluserdom = '';
4547: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4548: foreach my $field (@fields) {
1.324 raeburn 4549: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4550: if ($checkedfields{$field}) {
4551: $checked = ' checked="checked"';
4552: }
1.324 raeburn 4553: if ($field eq 'user') {
4554: $id = ' id="ltitools_user_field_'.$i.'"';
4555: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4556: if ($checked) {
4557: $userfieldstyle = 'display:inline-block';
4558: if ($userincdom) {
4559: $seluserdom = $unseluserdom;
4560: $unseluserdom = '';
4561: }
4562: }
4563: } else {
4564: $spacer = (' ' x2);
4565: }
1.267 raeburn 4566: $datatable .= '<label>'.
1.324 raeburn 4567: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4568: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4569: }
1.324 raeburn 4570: $datatable .= '</span>';
4571: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4572: '<span class="LC_nobreak"> : '.
4573: '<select name="ltitools_userincdom_'.$i.'">'.
4574: '<option value="">'.&mt('Select').'</option>'.
4575: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4576: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4577: '</select></span></div>';
4578: $datatable .= '</fieldset>'.
1.267 raeburn 4579: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4580: foreach my $role (@courseroles) {
4581: my ($selected,$selectnone);
4582: if (!$rolemaps{$role}) {
4583: $selectnone = ' selected="selected"';
4584: }
1.306 raeburn 4585: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4586: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4587: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4588: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4589: foreach my $ltirole (@ltiroles) {
4590: unless ($selectnone) {
4591: if ($rolemaps{$role} eq $ltirole) {
4592: $selected = ' selected="selected"';
4593: } else {
4594: $selected = '';
4595: }
4596: }
4597: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4598: }
4599: $datatable .= '</select></td>';
4600: }
1.273 raeburn 4601: $datatable .= '</tr></table></fieldset>';
4602: my %courseconfig;
4603: if (ref($settings->{$item}) eq 'HASH') {
4604: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4605: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4606: }
4607: }
4608: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4609: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4610: my $checked;
4611: if ($courseconfig{$item}) {
4612: $checked = ' checked="checked"';
4613: }
4614: $datatable .= '<label>'.
4615: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4616: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4617: }
4618: $datatable .= '</span></fieldset>'.
1.267 raeburn 4619: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4620: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4621: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4622: my %custom = %{$settings->{$item}->{'custom'}};
4623: if (keys(%custom) > 0) {
4624: foreach my $key (sort(keys(%custom))) {
4625: $datatable .= '<tr><td><span class="LC_nobreak">'.
4626: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4627: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4628: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4629: ' value="'.$custom{$key}.'" /></td></tr>';
4630: }
4631: }
4632: }
4633: $datatable .= '<tr><td><span class="LC_nobreak">'.
4634: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4635: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4636: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4637: $datatable .= '</table></fieldset></td></tr>'."\n";
4638: $itemcount ++;
4639: }
4640: }
4641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4642: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4643: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4644: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4645: '<select name="ltitools_add_pos"'.$chgstr.'>';
4646: for (my $k=0; $k<$maxnum+1; $k++) {
4647: my $vpos = $k+1;
4648: my $selstr;
4649: if ($k == $maxnum) {
4650: $selstr = ' selected="selected" ';
4651: }
4652: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4653: }
4654: $datatable .= '</select> '."\n".
1.334 raeburn 4655: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4656: '<td colspan="2">'.
4657: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4658: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4659: (' 'x2).
4660: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4661: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4662: (' 'x2).
4663: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4664: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4665: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4666: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4667: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4668: '<br />'.
1.323 raeburn 4669: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4670: (' 'x2).
4671: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4672: (' 'x2).
1.322 raeburn 4673: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4674: (' 'x2).
1.267 raeburn 4675: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4676: '<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".
4677: '</fieldset>'.
4678: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4679: '<span class="LC_nobreak">'.&mt('Display target:');
4680: my %defaultdisp;
4681: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4682: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4683: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4684: $lt{$disp}.'</label>'.(' 'x2);
4685: }
4686: $datatable .= (' 'x4);
4687: foreach my $dimen ('width','height') {
4688: $datatable .= '<label>'.$lt{$dimen}.' '.
4689: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4690: (' 'x2);
4691: }
1.334 raeburn 4692: $datatable .= '</span><br />'.
1.296 raeburn 4693: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4694: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4695: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4696: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4697: '</div><div style=""></div><br />';
1.319 raeburn 4698: my %units = (
4699: 'passback' => 'days',
4700: 'roster' => 'seconds',
4701: );
4702: my %defaulttimes = (
4703: 'passback' => '7',
1.322 raeburn 4704: 'roster' => '300',
1.319 raeburn 4705: );
1.267 raeburn 4706: foreach my $extra ('passback','roster') {
1.319 raeburn 4707: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4708: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4709: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4710: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4711: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4712: &mt('Yes').'</label></span></div>'.
4713: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4714: '<span class="LC_nobreak">'.
4715: &mt("at least [_1] $units{$extra} after launch",
4716: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4717: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4718: }
1.319 raeburn 4719: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4720: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4721: if ($switchserver) {
4722: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4723: } else {
4724: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4725: }
4726: $datatable .= '</span></fieldset>'.
4727: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4728: '<span class="LC_nobreak">';
4729: foreach my $field (@fields) {
1.324 raeburn 4730: my ($id,$onclick,$spacer);
4731: if ($field eq 'user') {
4732: $id = ' id="ltitools_user_field_add"';
4733: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4734: } else {
4735: $spacer = (' ' x2);
4736: }
1.267 raeburn 4737: $datatable .= '<label>'.
1.324 raeburn 4738: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4739: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4740: }
1.324 raeburn 4741: $datatable .= '</span>'.
4742: '<div style="display:none;" id="ltitools_user_div_add">'.
4743: '<span class="LC_nobreak"> : '.
4744: '<select name="ltitools_userincdom_add">'.
4745: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4746: '<option value="0">'.&mt('username').'</option>'.
4747: '<option value="1">'.&mt('username:domain').'</option>'.
4748: '</select></span></div></fieldset>';
4749: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4750: foreach my $role (@courseroles) {
4751: my ($checked,$checkednone);
1.306 raeburn 4752: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4753: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4754: '<select name="ltitools_add_roles_'.$role.'">'.
4755: '<option value="" selected="selected">'.&mt('Select').'</option>';
4756: foreach my $ltirole (@ltiroles) {
4757: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4758: }
4759: $datatable .= '</select></td>';
4760: }
4761: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4762: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4763: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4764: $datatable .= '<label>'.
4765: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4766: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4767: }
4768: $datatable .= '</span></fieldset>'.
1.267 raeburn 4769: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4770: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4771: '<tr><td><span class="LC_nobreak">'.
4772: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4773: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4774: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4775: '</table></fieldset>'."\n".
1.267 raeburn 4776: '</td>'."\n".
4777: '</tr>'."\n";
4778: $itemcount ++;
4779: return $datatable;
4780: }
4781:
4782: sub ltitools_names {
4783: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4784: 'title' => 'Title',
4785: 'version' => 'Version',
4786: 'msgtype' => 'Message Type',
1.323 raeburn 4787: 'sigmethod' => 'Signature Method',
1.296 raeburn 4788: 'url' => 'URL',
4789: 'key' => 'Key',
1.322 raeburn 4790: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4791: 'secret' => 'Secret',
4792: 'icon' => 'Icon',
1.324 raeburn 4793: 'user' => 'User',
1.296 raeburn 4794: 'fullname' => 'Full Name',
4795: 'firstname' => 'First Name',
4796: 'lastname' => 'Last Name',
4797: 'email' => 'E-mail',
4798: 'roles' => 'Role',
1.298 raeburn 4799: 'window' => 'Window',
4800: 'tab' => 'Tab',
1.296 raeburn 4801: 'iframe' => 'iFrame',
4802: 'height' => 'Height',
4803: 'width' => 'Width',
4804: 'linktext' => 'Default Link Text',
4805: 'explanation' => 'Default Explanation',
4806: 'passback' => 'Tool can return grades:',
4807: 'roster' => 'Tool can retrieve roster:',
4808: 'crstarget' => 'Display target',
4809: 'crslabel' => 'Course label',
4810: 'crstitle' => 'Course title',
4811: 'crslinktext' => 'Link Text',
4812: 'crsexplanation' => 'Explanation',
1.318 raeburn 4813: 'crsappend' => 'Provider URL',
1.267 raeburn 4814: );
4815: return %lt;
4816: }
4817:
1.320 raeburn 4818: sub print_lti {
4819: my ($dom,$settings,$rowtotal) = @_;
4820: my $itemcount = 1;
4821: my $maxnum = 0;
4822: my $css_class;
4823: my %ordered;
4824: if (ref($settings) eq 'HASH') {
4825: foreach my $item (keys(%{$settings})) {
4826: if (ref($settings->{$item}) eq 'HASH') {
4827: my $num = $settings->{$item}{'order'};
4828: $ordered{$num} = $item;
4829: }
4830: }
4831: }
4832: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4833: my $datatable;
1.320 raeburn 4834: my %lt = <i_names();
4835: if (keys(%ordered)) {
4836: my @items = sort { $a <=> $b } keys(%ordered);
4837: for (my $i=0; $i<@items; $i++) {
4838: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4839: my $item = $ordered{$items[$i]};
1.345 raeburn 4840: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4841: if (ref($settings->{$item}) eq 'HASH') {
4842: $key = $settings->{$item}->{'key'};
4843: $secret = $settings->{$item}->{'secret'};
4844: $lifetime = $settings->{$item}->{'lifetime'};
4845: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4846: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4847: $current = $settings->{$item};
4848: }
1.345 raeburn 4849: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4850: my %checkedrequser = (
4851: yes => ' checked="checked"',
4852: no => '',
4853: );
4854: if (!$requser) {
4855: $checkedrequser{'no'} = $checkedrequser{'yes'};
4856: $checkedrequser{'yes'} = '';
1.352 raeburn 4857: }
1.320 raeburn 4858: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4859: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4860: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4861: for (my $k=0; $k<=$maxnum; $k++) {
4862: my $vpos = $k+1;
4863: my $selstr;
4864: if ($k == $i) {
4865: $selstr = ' selected="selected" ';
4866: }
4867: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4868: }
4869: $datatable .= '</select>'.(' 'x2).
4870: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4871: &mt('Delete?').'</label></span></td>'.
4872: '<td colspan="2">'.
4873: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4874: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4875: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4876: (' 'x2).
4877: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4878: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4879: (' 'x2).
4880: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4881: 'value="'.$lifetime.'" size="3" /></span>'.
4882: (' 'x2).
4883: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4884: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4885: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4886: '<br /><br />'.
4887: '<span class="LC_nobreak">'.$lt{'key'}.
4888: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4889: (' 'x2).
4890: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4891: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4892: '<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>'.
4893: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4894: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4895: $itemcount ++;
4896: }
4897: }
4898: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4899: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4900: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4901: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4902: '<select name="lti_pos_add"'.$chgstr.'>';
4903: for (my $k=0; $k<$maxnum+1; $k++) {
4904: my $vpos = $k+1;
4905: my $selstr;
4906: if ($k == $maxnum) {
4907: $selstr = ' selected="selected" ';
4908: }
4909: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4910: }
4911: $datatable .= '</select> '."\n".
1.334 raeburn 4912: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4913: '<td colspan="2">'.
4914: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4915: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4916: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4917: (' 'x2).
4918: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4919: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4920: (' 'x2).
1.345 raeburn 4921: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4922: (' 'x2).
4923: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4924: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4925: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4926: '<br /><br />'.
4927: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4928: (' 'x2).
4929: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4930: '<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 4931: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4932: '</td>'."\n".
4933: '</tr>'."\n";
4934: $$rowtotal ++;
4935: return $datatable;;
4936: }
4937:
4938: sub lti_names {
4939: my %lt = &Apache::lonlocal::texthash(
4940: 'version' => 'LTI Version',
4941: 'url' => 'URL',
4942: 'key' => 'Key',
1.322 raeburn 4943: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4944: 'consumer' => 'Consumer',
1.320 raeburn 4945: 'secret' => 'Secret',
1.345 raeburn 4946: 'requser' => "User's identity sent",
1.320 raeburn 4947: 'email' => 'Email address',
4948: 'sourcedid' => 'User ID',
4949: 'other' => 'Other',
4950: 'passback' => 'Can return grades to Consumer:',
4951: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4952: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4953: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4954: );
4955: return %lt;
4956: }
4957:
4958: sub lti_options {
1.325 raeburn 4959: my ($num,$current,$itemcount,%lt) = @_;
1.320 raeburn 4960: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
4961: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4962: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4963: $checked{'makecrs'}{'N'} = ' checked="checked"';
4964: $checked{'mapcrstype'} = {};
4965: $checked{'makeuser'} = {};
4966: $checked{'selfenroll'} = {};
4967: $checked{'crssec'} = {};
4968: $checked{'crssecsrc'} = {};
1.325 raeburn 4969: $checked{'lcauth'} = {};
1.326 raeburn 4970: $checked{'menuitem'} = {};
1.325 raeburn 4971: if ($num eq 'add') {
4972: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4973: }
1.320 raeburn 4974: my $userfieldsty = 'none';
4975: my $crsfieldsty = 'none';
4976: my $crssecfieldsty = 'none';
4977: my $secsrcfieldsty = 'none';
1.337 raeburn 4978: my $passbacksty = 'none';
1.345 raeburn 4979: my $optionsty = 'block';
1.325 raeburn 4980: my $lcauthparm;
4981: my $lcauthparmstyle = 'display:none';
4982: my $lcauthparmtext;
1.326 raeburn 4983: my $menusty;
1.325 raeburn 4984: my $numinrow = 4;
1.326 raeburn 4985: my %menutitles = <imenu_titles();
1.320 raeburn 4986:
4987: if (ref($current) eq 'HASH') {
1.345 raeburn 4988: if (!$current->{'requser'}) {
4989: $optionsty = 'none';
4990: }
1.320 raeburn 4991: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4992: $checked{'mapuser'}{'sourcedid'} = '';
4993: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4994: $checked{'mapuser'}{'email'} = ' checked="checked"';
4995: } else {
4996: $checked{'mapuser'}{'other'} = ' checked="checked"';
4997: $userfield = $current->{'mapuser'};
4998: $userfieldsty = 'inline-block';
4999: }
5000: }
5001: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5002: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5003: if ($current->{'mapcrs'} eq 'context_id') {
5004: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5005: } else {
5006: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5007: $cidfield = $current->{'mapcrs'};
5008: $crsfieldsty = 'inline-block';
5009: }
5010: }
5011: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5012: foreach my $type (@{$current->{'mapcrstype'}}) {
5013: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5014: }
5015: }
1.345 raeburn 5016: if ($current->{'makecrs'}) {
1.320 raeburn 5017: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5018: }
1.320 raeburn 5019: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5020: foreach my $role (@{$current->{'makeuser'}}) {
5021: $checked{'makeuser'}{$role} = ' checked="checked"';
5022: }
5023: }
1.325 raeburn 5024: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5025: $checked{'lcauth'}{$1} = ' checked="checked"';
5026: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5027: $lcauthparm = $current->{'lcauthparm'};
5028: $lcauthparmstyle = 'display:table-row';
5029: if ($current->{'lcauth'} eq 'localauth') {
5030: $lcauthparmtext = &mt('Local auth argument');
5031: } else {
5032: $lcauthparmtext = &mt('Kerberos domain');
5033: }
5034: }
5035: }
1.320 raeburn 5036: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5037: foreach my $role (@{$current->{'selfenroll'}}) {
5038: $checked{'selfenroll'}{$role} = ' checked="checked"';
5039: }
5040: }
5041: if (ref($current->{'maproles'}) eq 'HASH') {
5042: %rolemaps = %{$current->{'maproles'}};
5043: }
5044: if ($current->{'section'} ne '') {
5045: $checked{'crssec'}{'Y'} = ' checked="checked"';
5046: $crssecfieldsty = 'inline-block';
5047: if ($current->{'section'} eq 'course_section_sourcedid') {
5048: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5049: } else {
5050: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5051: $crssecsrc = $current->{'section'};
5052: $secsrcfieldsty = 'inline-block';
5053: }
5054: } else {
5055: $checked{'crssec'}{'N'} = ' checked="checked"';
5056: }
1.326 raeburn 5057: if ($current->{'topmenu'}) {
5058: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5059: } else {
5060: $checked{'topmenu'}{'N'} = ' checked="checked"';
5061: }
5062: if ($current->{'inlinemenu'}) {
5063: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5064: } else {
5065: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5066: }
5067: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5068: $menusty = 'inline-block';
5069: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5070: foreach my $item (@{$current->{'lcmenu'}}) {
5071: if (exists($menutitles{$item})) {
5072: $checked{'menuitem'}{$item} = ' checked="checked"';
5073: }
5074: }
5075: }
5076: } else {
5077: $menusty = 'none';
5078: }
1.320 raeburn 5079: } else {
5080: $checked{'makecrs'}{'N'} = ' checked="checked"';
5081: $checked{'crssec'}{'N'} = ' checked="checked"';
1.326 raeburn 5082: $checked{'topmenu'}{'N'} = ' checked="checked"';
5083: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5084: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5085: $menusty = 'inline-block';
1.320 raeburn 5086: }
1.325 raeburn 5087: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5088: my %coursetypetitles = &Apache::lonlocal::texthash (
5089: official => 'Official',
5090: unofficial => 'Unofficial',
5091: community => 'Community',
5092: textbook => 'Textbook',
5093: placement => 'Placement Test',
1.325 raeburn 5094: lti => 'LTI Provider',
1.320 raeburn 5095: );
1.325 raeburn 5096: my @authtypes = ('internal','krb4','krb5','localauth');
5097: my %shortauth = (
5098: internal => 'int',
5099: krb4 => 'krb4',
5100: krb5 => 'krb5',
5101: localauth => 'loc'
5102: );
5103: my %authnames = &authtype_names();
1.320 raeburn 5104: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5105: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5106: my @courseroles = ('cc','in','ta','ep','st');
5107: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5108: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5109: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5110: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5111: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5112: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5113: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5114: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5115: foreach my $option ('sourcedid','email','other') {
5116: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5117: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5118: ($option eq 'other' ? '' : (' 'x2) );
5119: }
5120: $output .= '</span></div>'.
5121: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5122: '<input type="text" name="lti_customuser_'.$num.'" '.
5123: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5124: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5125: foreach my $ltirole (@lticourseroles) {
5126: my ($selected,$selectnone);
5127: if ($rolemaps{$ltirole} eq '') {
5128: $selectnone = ' selected="selected"';
5129: }
5130: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5131: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5132: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5133: foreach my $role (@courseroles) {
5134: unless ($selectnone) {
5135: if ($rolemaps{$ltirole} eq $role) {
5136: $selected = ' selected="selected"';
5137: } else {
5138: $selected = '';
5139: }
5140: }
5141: $output .= '<option value="'.$role.'"'.$selected.'>'.
5142: &Apache::lonnet::plaintext($role,'Course').
5143: '</option>';
5144: }
5145: $output .= '</select></td>';
5146: }
5147: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5148: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5149: foreach my $ltirole (@ltiroles) {
5150: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5151: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5152: }
5153: $output .= '</fieldset>'.
1.345 raeburn 5154: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5155: '<table>'.
5156: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5157: '</table>'.
5158: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5159: '<td class="LC_left_item">';
5160: foreach my $auth ('lti',@authtypes) {
5161: my $authtext;
5162: if ($auth eq 'lti') {
5163: $authtext = &mt('None');
5164: } else {
5165: $authtext = $authnames{$shortauth{$auth}};
5166: }
5167: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5168: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5169: $authtext.'</label></span> ';
5170: }
5171: $output .= '</td></tr>'.
5172: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5173: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5174: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5175: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5176: '</table></fieldset>'.
1.345 raeburn 5177: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5178: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5179: &mt('Unique course identifier').': ';
5180: foreach my $option ('course_offering_sourcedid','context_id','other') {
5181: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5182: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5183: ($option eq 'other' ? '' : (' 'x2) );
5184: }
1.334 raeburn 5185: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5186: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5187: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5188: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5189: foreach my $type (@coursetypes) {
5190: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5191: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5192: (' 'x2);
5193: }
5194: $output .= '</span></fieldset>'.
1.345 raeburn 5195: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5196: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5197: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5198: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5199: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5200: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5201: '</fieldset>'.
1.345 raeburn 5202: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5203: foreach my $lticrsrole (@lticourseroles) {
5204: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5205: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5206: }
5207: $output .= '</fieldset>'.
1.345 raeburn 5208: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5209: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5210: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5211: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5212: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5213: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5214: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5215: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5216: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5217: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5218: &mt('Standard field').'</label>'.(' 'x2).
5219: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5220: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5221: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5222: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5223: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5224: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5225: foreach my $extra ('roster','passback') {
1.320 raeburn 5226: my $checkedon = '';
5227: my $checkedoff = ' checked="checked"';
1.337 raeburn 5228: if ($extra eq 'passback') {
5229: $pb1p1chk = ' checked="checked"';
5230: $pb1p0chk = '';
5231: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5232: } else {
5233: $onclickpb = '';
5234: }
1.320 raeburn 5235: if (ref($current) eq 'HASH') {
5236: if (($current->{$extra})) {
5237: $checkedon = $checkedoff;
5238: $checkedoff = '';
1.337 raeburn 5239: if ($extra eq 'passback') {
5240: $passbacksty = 'inline-block';
5241: }
5242: if ($current->{'passbackformat'} eq '1.0') {
5243: $pb1p0chk = ' checked="checked"';
5244: $pb1p1chk = '';
5245: }
1.320 raeburn 5246: }
5247: }
5248: $output .= $lt{$extra}.' '.
1.337 raeburn 5249: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5250: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5251: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5252: &mt('Yes').'</label><br />';
5253: }
1.337 raeburn 5254: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5255: '<span class="LC_nobreak">'.&mt('Grade format').
5256: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5257: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5258: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5259: &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345 raeburn 5260: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5261: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5262: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5263: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5264: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5265: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5266: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5267: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5268: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5269: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5270: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5271: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5272: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5273: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5274: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5275: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5276: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5277: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5278: (' 'x2);
5279: }
1.334 raeburn 5280: $output .= '</span></div></fieldset>';
1.320 raeburn 5281: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5282: #
5283: # $output .= '</fieldset>'.
5284: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5285: return $output;
5286: }
5287:
1.326 raeburn 5288: sub ltimenu_titles {
5289: return &Apache::lonlocal::texthash(
5290: fullname => 'Full name',
5291: coursetitle => 'Course title',
5292: role => 'Role',
5293: logout => 'Logout',
5294: grades => 'Grades',
5295: );
5296: }
5297:
1.121 raeburn 5298: sub print_coursedefaults {
1.139 raeburn 5299: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5300: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5301: my $itemcount = 1;
1.192 raeburn 5302: my %choices = &Apache::lonlocal::texthash (
5303: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5304: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5305: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5306: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5307: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5308: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5309: texengine => 'Default method to display mathematics',
1.257 raeburn 5310: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5311: canclone => "People who may clone a course (besides course's owner and coordinators)",
5312: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5313: );
1.198 raeburn 5314: my %staticdefaults = (
5315: anonsurvey_threshold => 10,
5316: uploadquota => 500,
1.257 raeburn 5317: postsubmit => 60,
1.276 raeburn 5318: mysqltables => 172800,
1.198 raeburn 5319: );
1.139 raeburn 5320: if ($position eq 'top') {
1.257 raeburn 5321: %defaultchecked = (
5322: 'canuse_pdfforms' => 'off',
5323: 'uselcmath' => 'on',
5324: 'usejsme' => 'on',
1.289 raeburn 5325: 'canclone' => 'none',
1.257 raeburn 5326: );
5327: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 5328: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5329: if (ref($settings) eq 'HASH') {
5330: if ($settings->{'texengine'}) {
5331: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5332: $deftex = $settings->{'texengine'};
5333: }
5334: }
5335: }
5336: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5337: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5338: '<span class="LC_nobreak">'.$choices{'texengine'}.
5339: '</span></td><td class="LC_right_item">'.
5340: '<select name="texengine">'."\n";
5341: my %texoptions = (
5342: MathJax => 'MathJax',
5343: mimetex => &mt('Convert to Images'),
5344: tth => &mt('TeX to HTML'),
5345: );
5346: foreach my $renderer ('MathJax','mimetex','tth') {
5347: my $selected = '';
5348: if ($renderer eq $deftex) {
5349: $selected = ' selected="selected"';
5350: }
5351: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5352: }
5353: $mathdisp .= '</select></td></tr>'."\n";
5354: $itemcount ++;
1.139 raeburn 5355: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5356: \%choices,$itemcount);
1.314 raeburn 5357: $datatable = $mathdisp.$datatable;
1.264 raeburn 5358: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5359: $datatable .=
1.306 raeburn 5360: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5361: '<span class="LC_nobreak">'.$choices{'canclone'}.
5362: '</span></td><td class="LC_left_item">';
5363: my $currcanclone = 'none';
5364: my $onclick;
5365: my @cloneoptions = ('none','domain');
5366: my %clonetitles = (
5367: none => 'No additional course requesters',
5368: domain => "Any course requester in course's domain",
5369: instcode => 'Course requests for official courses ...',
5370: );
5371: my (%codedefaults,@code_order,@posscodes);
5372: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5373: \@code_order) eq 'ok') {
5374: if (@code_order > 0) {
5375: push(@cloneoptions,'instcode');
5376: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5377: }
5378: }
5379: if (ref($settings) eq 'HASH') {
5380: if ($settings->{'canclone'}) {
5381: if (ref($settings->{'canclone'}) eq 'HASH') {
5382: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5383: if (@code_order > 0) {
5384: $currcanclone = 'instcode';
5385: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5386: }
5387: }
5388: } elsif ($settings->{'canclone'} eq 'domain') {
5389: $currcanclone = $settings->{'canclone'};
5390: }
5391: }
1.289 raeburn 5392: }
1.264 raeburn 5393: foreach my $option (@cloneoptions) {
5394: my ($checked,$additional);
5395: if ($currcanclone eq $option) {
5396: $checked = ' checked="checked"';
5397: }
5398: if ($option eq 'instcode') {
5399: if (@code_order) {
5400: my $show = 'none';
5401: if ($checked) {
5402: $show = 'block';
5403: }
1.317 raeburn 5404: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5405: &mt('Institutional codes for new and cloned course have identical:').
5406: '<br />';
5407: foreach my $item (@code_order) {
5408: my $codechk;
5409: if ($checked) {
5410: if (grep(/^\Q$item\E$/,@posscodes)) {
5411: $codechk = ' checked="checked"';
5412: }
5413: }
5414: $additional .= '<label>'.
5415: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5416: $item.'</label>';
5417: }
5418: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5419: }
5420: }
5421: $datatable .=
5422: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5423: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5424: '</label> '.$additional.'</span><br />';
5425: }
5426: $datatable .= '</td>'.
5427: '</tr>';
5428: $itemcount ++;
1.139 raeburn 5429: } else {
5430: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5431: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5432: my $currusecredits = 0;
1.257 raeburn 5433: my $postsubmitclient = 1;
1.271 raeburn 5434: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5435: if (ref($settings) eq 'HASH') {
5436: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5437: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5438: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5439: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5440: }
5441: }
1.192 raeburn 5442: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5443: foreach my $type (@types) {
5444: next if ($type eq 'community');
5445: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5446: if ($defcredits{$type} ne '') {
5447: $currusecredits = 1;
5448: }
5449: }
5450: }
5451: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5452: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5453: $postsubmitclient = 0;
5454: foreach my $type (@types) {
5455: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5456: }
5457: } else {
5458: foreach my $type (@types) {
5459: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5460: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5461: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5462: } else {
5463: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5464: }
5465: } else {
5466: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5467: }
5468: }
5469: }
5470: } else {
5471: foreach my $type (@types) {
5472: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5473: }
5474: }
1.276 raeburn 5475: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5476: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5477: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5478: }
5479: } else {
5480: foreach my $type (@types) {
5481: $currmysql{$type} = $staticdefaults{'mysqltables'};
5482: }
5483: }
1.258 raeburn 5484: } else {
5485: foreach my $type (@types) {
5486: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5487: }
1.139 raeburn 5488: }
5489: if (!$currdefresponder) {
1.198 raeburn 5490: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5491: } elsif ($currdefresponder < 1) {
5492: $currdefresponder = 1;
5493: }
1.198 raeburn 5494: foreach my $type (@types) {
5495: if ($curruploadquota{$type} eq '') {
5496: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5497: }
5498: }
1.139 raeburn 5499: $datatable .=
1.192 raeburn 5500: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5501: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5502: '</span></td>'.
5503: '<td class="LC_right_item"><span class="LC_nobreak">'.
5504: '<input type="text" name="anonsurvey_threshold"'.
5505: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5506: '</td></tr>'."\n";
5507: $itemcount ++;
5508: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5509: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5510: $choices{'uploadquota'}.
5511: '</span></td>'.
1.306 raeburn 5512: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5513: '<table><tr>';
1.198 raeburn 5514: foreach my $type (@types) {
1.306 raeburn 5515: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5516: '<input type="text" name="uploadquota_'.$type.'"'.
5517: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5518: }
5519: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5520: $itemcount ++;
1.236 raeburn 5521: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5522: my $display = 'none';
1.192 raeburn 5523: if ($currusecredits) {
5524: $display = 'block';
5525: }
5526: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5527: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5528: foreach my $type (@types) {
5529: next if ($type eq 'community');
1.306 raeburn 5530: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5531: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5532: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5533: }
5534: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5535: %defaultchecked = ('coursecredits' => 'off');
5536: @toggles = ('coursecredits');
5537: my $current = {
5538: 'coursecredits' => $currusecredits,
5539: };
5540: (my $table,$itemcount) =
5541: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5542: \%choices,$itemcount,$onclick,$additional,'left');
5543: $datatable .= $table;
5544: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5545: my $display = 'none';
5546: if ($postsubmitclient) {
5547: $display = 'block';
5548: }
5549: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5550: &mt('Number of seconds submit is disabled').'<br />'.
5551: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5552: '<table><tr>';
1.257 raeburn 5553: foreach my $type (@types) {
1.306 raeburn 5554: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5555: '<input type="text" name="'.$type.'_timeout" value="'.
5556: $deftimeout{$type}.'" size="5" /></td>';
5557: }
5558: $additional .= '</tr></table></div>'."\n";
5559: %defaultchecked = ('postsubmit' => 'on');
5560: @toggles = ('postsubmit');
1.280 raeburn 5561: $current = {
5562: 'postsubmit' => $postsubmitclient,
5563: };
1.257 raeburn 5564: ($table,$itemcount) =
5565: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5566: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5567: $datatable .= $table;
1.276 raeburn 5568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5569: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5570: $choices{'mysqltables'}.
5571: '</span></td>'.
1.306 raeburn 5572: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5573: '<table><tr>';
5574: foreach my $type (@types) {
1.306 raeburn 5575: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5576: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5577: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5578: }
5579: $datatable .= '</tr></table></td></tr>'."\n";
5580: $itemcount ++;
5581:
1.139 raeburn 5582: }
1.192 raeburn 5583: $$rowtotal += $itemcount;
1.121 raeburn 5584: return $datatable;
1.118 jms 5585: }
5586:
1.231 raeburn 5587: sub print_selfenrollment {
5588: my ($position,$dom,$settings,$rowtotal) = @_;
5589: my ($css_class,$datatable);
5590: my $itemcount = 1;
1.271 raeburn 5591: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5592: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5593: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5594: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5595: my @rows;
5596: my $key;
5597: if ($position eq 'top') {
5598: $key = 'admin';
5599: if (ref($rowsref) eq 'ARRAY') {
5600: @rows = @{$rowsref};
5601: }
5602: } elsif ($position eq 'middle') {
5603: $key = 'default';
5604: @rows = ('types','registered','approval','limit');
5605: }
5606: foreach my $row (@rows) {
5607: if (defined($titlesref->{$row})) {
5608: $itemcount ++;
5609: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5610: $datatable .= '<tr'.$css_class.'>'.
5611: '<td>'.$titlesref->{$row}.'</td>'.
5612: '<td class="LC_left_item">'.
5613: '<table><tr>';
5614: my (%current,%currentcap);
5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{$key}) eq 'HASH') {
5617: foreach my $type (@types) {
5618: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5619: $current{$type} = $settings->{$key}->{$type}->{$row};
5620: }
5621: if (($row eq 'limit') && ($key eq 'default')) {
5622: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5623: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5624: }
5625: }
5626: }
5627: }
5628: }
5629: my %roles = (
5630: '0' => &Apache::lonnet::plaintext('dc'),
5631: );
5632:
5633: foreach my $type (@types) {
5634: unless (($row eq 'registered') && ($key eq 'default')) {
5635: $datatable .= '<th>'.&mt($type).'</th>';
5636: }
5637: }
5638: unless (($row eq 'registered') && ($key eq 'default')) {
5639: $datatable .= '</tr><tr>';
5640: }
5641: foreach my $type (@types) {
5642: if ($type eq 'community') {
5643: $roles{'1'} = &mt('Community personnel');
5644: } else {
5645: $roles{'1'} = &mt('Course personnel');
5646: }
5647: $datatable .= '<td style="vertical-align: top">';
5648: if ($position eq 'top') {
5649: my %checked;
5650: if ($current{$type} eq '0') {
5651: $checked{'0'} = ' checked="checked"';
5652: } else {
5653: $checked{'1'} = ' checked="checked"';
5654: }
5655: foreach my $role ('1','0') {
5656: $datatable .= '<span class="LC_nobreak"><label>'.
5657: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5658: 'value="'.$role.'"'.$checked{$role}.' />'.
5659: $roles{$role}.'</label></span> ';
5660: }
5661: } else {
5662: if ($row eq 'types') {
5663: my %checked;
5664: if ($current{$type} =~ /^(all|dom)$/) {
5665: $checked{$1} = ' checked="checked"';
5666: } else {
5667: $checked{''} = ' checked="checked"';
5668: }
5669: foreach my $val ('','dom','all') {
5670: $datatable .= '<span class="LC_nobreak"><label>'.
5671: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5672: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5673: }
5674: } elsif ($row eq 'registered') {
5675: my %checked;
5676: if ($current{$type} eq '1') {
5677: $checked{'1'} = ' checked="checked"';
5678: } else {
5679: $checked{'0'} = ' checked="checked"';
5680: }
5681: foreach my $val ('0','1') {
5682: $datatable .= '<span class="LC_nobreak"><label>'.
5683: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5684: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5685: }
5686: } elsif ($row eq 'approval') {
5687: my %checked;
5688: if ($current{$type} =~ /^([12])$/) {
5689: $checked{$1} = ' checked="checked"';
5690: } else {
5691: $checked{'0'} = ' checked="checked"';
5692: }
5693: for my $val (0..2) {
5694: $datatable .= '<span class="LC_nobreak"><label>'.
5695: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5696: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5697: }
5698: } elsif ($row eq 'limit') {
5699: my %checked;
5700: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5701: $checked{$1} = ' checked="checked"';
5702: } else {
5703: $checked{'none'} = ' checked="checked"';
5704: }
5705: my $cap;
5706: if ($currentcap{$type} =~ /^\d+$/) {
5707: $cap = $currentcap{$type};
5708: }
5709: foreach my $val ('none','allstudents','selfenrolled') {
5710: $datatable .= '<span class="LC_nobreak"><label>'.
5711: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5712: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5713: }
5714: $datatable .= '<br />'.
5715: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5716: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5717: '</span>';
5718: }
5719: }
5720: $datatable .= '</td>';
5721: }
5722: $datatable .= '</tr>';
5723: }
5724: $datatable .= '</table></td></tr>';
5725: }
5726: } elsif ($position eq 'bottom') {
1.235 raeburn 5727: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5728: }
5729: $$rowtotal += $itemcount;
5730: return $datatable;
5731: }
5732:
5733: sub print_validation_rows {
5734: my ($caller,$dom,$settings,$rowtotal) = @_;
5735: my ($itemsref,$namesref,$fieldsref);
5736: if ($caller eq 'selfenroll') {
5737: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5738: } elsif ($caller eq 'requestcourses') {
5739: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5740: }
5741: my %currvalidation;
5742: if (ref($settings) eq 'HASH') {
5743: if (ref($settings->{'validation'}) eq 'HASH') {
5744: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5745: }
1.235 raeburn 5746: }
5747: my $datatable;
5748: my $itemcount = 0;
5749: foreach my $item (@{$itemsref}) {
5750: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5751: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5752: $namesref->{$item}.
5753: '</span></td>'.
5754: '<td class="LC_left_item">';
5755: if (($item eq 'url') || ($item eq 'button')) {
5756: $datatable .= '<span class="LC_nobreak">'.
5757: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5758: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5759: } elsif ($item eq 'fields') {
5760: my @currfields;
5761: if (ref($currvalidation{$item}) eq 'ARRAY') {
5762: @currfields = @{$currvalidation{$item}};
5763: }
5764: foreach my $field (@{$fieldsref}) {
5765: my $check = '';
5766: if (grep(/^\Q$field\E$/,@currfields)) {
5767: $check = ' checked="checked"';
5768: }
5769: $datatable .= '<span class="LC_nobreak"><label>'.
5770: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5771: ' value="'.$field.'"'.$check.' />'.$field.
5772: '</label></span> ';
5773: }
5774: } elsif ($item eq 'markup') {
1.334 raeburn 5775: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5776: $currvalidation{$item}.
1.231 raeburn 5777: '</textarea>';
1.235 raeburn 5778: }
5779: $datatable .= '</td></tr>'."\n";
5780: if (ref($rowtotal)) {
1.231 raeburn 5781: $itemcount ++;
5782: }
5783: }
1.235 raeburn 5784: if ($caller eq 'requestcourses') {
5785: my %currhash;
1.248 raeburn 5786: if (ref($settings) eq 'HASH') {
5787: if (ref($settings->{'validation'}) eq 'HASH') {
5788: if ($settings->{'validation'}{'dc'} ne '') {
5789: $currhash{$settings->{'validation'}{'dc'}} = 1;
5790: }
1.235 raeburn 5791: }
5792: }
5793: my $numinrow = 2;
5794: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5795: 'validationdc',%currhash);
1.247 raeburn 5796: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5797: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5798: if ($numdc > 1) {
1.247 raeburn 5799: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5800: } else {
1.247 raeburn 5801: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5802: }
1.247 raeburn 5803: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5804: $itemcount ++;
5805: }
5806: if (ref($rowtotal)) {
5807: $$rowtotal += $itemcount;
5808: }
1.231 raeburn 5809: return $datatable;
5810: }
5811:
1.357 raeburn 5812: sub print_privacy {
5813: my ($position,$dom,$settings,$rowtotal) = @_;
5814: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
5815: my $itemcount = 0;
5816: unless ($position eq 'top') {
5817: @items = ('domain','author','course','community');
5818: %names = &Apache::lonlocal::texthash (
5819: domain => 'Assigned domain role(s)',
5820: author => 'Assigned co-author role(s)',
5821: course => 'Assigned course role(s)',
5822: community => 'Assigned community role',
5823: );
5824: $numinrow = 4;
5825: ($othertitle,$usertypes,$types) =
5826: &Apache::loncommon::sorted_inst_types($dom);
5827: }
5828: if (($position eq 'top') || ($position eq 'middle')) {
5829: my (%by_ip,%by_location,@intdoms,@instdoms);
5830: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5831: if ($position eq 'top') {
5832: my %curr;
5833: my @options = ('none','user','domain','auto');
5834: my %titles = &Apache::lonlocal::texthash (
5835: none => 'Not allowed',
5836: user => 'User authorizes',
5837: domain => 'DC authorizes',
5838: auto => 'Unrestricted',
5839: instdom => 'Other domain shares institution/provider',
5840: extdom => 'Other domain has different institution/provider',
5841: );
5842: my %names = &Apache::lonlocal::texthash (
5843: domain => 'Domain role',
5844: author => 'Co-author role',
5845: course => 'Course role',
5846: community => 'Community role',
5847: );
5848: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5849: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5850: foreach my $domtype ('instdom','extdom') {
5851: my (%checked,$skip);
5852: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5853: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
5854: '<td class="LC_left_item">';
5855: if ($domtype eq 'instdom') {
5856: unless (@instdoms > 1) {
5857: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
5858: $skip = 1;
5859: }
5860: } elsif ($domtype eq 'extdom') {
5861: if (keys(%by_location) == 0) {
5862: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
5863: $skip = 1;
5864: }
5865: }
5866: unless ($skip) {
5867: foreach my $roletype ('domain','author','course','community') {
5868: $checked{'auto'} = ' checked="checked"';
5869: if (ref($settings) eq 'HASH') {
5870: if (ref($settings->{approval}) eq 'HASH') {
5871: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
5872: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
5873: $checked{$1} = ' checked="checked"';
5874: $checked{'auto'} = '';
5875: }
5876: }
5877: }
5878: }
5879: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
5880: foreach my $option (@options) {
5881: $datatable .= '<span class="LC_nobreak"><label>'.
5882: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
5883: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5884: '</label></span> ';
5885: }
5886: $datatable .= '</fieldset>';
5887: }
5888: }
5889: $datatable .= '</td></tr>';
5890: $itemcount ++;
5891: }
5892: } elsif ($position eq 'middle') {
5893: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
5894: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5895: foreach my $item (@{$types}) {
5896: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
5897: $numinrow,$itemcount,'','','','','',
5898: '',$usertypes->{$item});
5899: $itemcount ++;
5900: }
5901: }
5902: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
5903: $numinrow,$itemcount,'','','','','',
5904: '',$othertitle);
5905: $itemcount ++;
5906: } else {
1.360 raeburn 5907: my (@insttypes,%insttitles);
5908: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5909: @insttypes = @{$types};
5910: %insttitles = %{$usertypes};
5911: }
5912: foreach my $item (@insttypes,'default') {
5913: my $title;
5914: if ($item eq 'default') {
5915: $title = $othertitle;
5916: } else {
5917: $title = $insttitles{$item};
5918: }
5919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5920: $datatable .= '<tr'.$css_class.'>'.
5921: '<td class="LC_left_item">'.$title.'</td>'.
5922: '<td class="LC_left_item">'.
5923: &mt('Nothing to set here, as there are no other domains').
5924: '</td></tr>';
5925: $itemcount ++;
5926: }
1.357 raeburn 5927: }
5928: }
5929: } else {
5930: my $prefix;
5931: if ($position eq 'lower') {
5932: $prefix = 'priv';
5933: } else {
5934: $prefix = 'unpriv';
5935: }
5936: foreach my $item (@items) {
5937: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
5938: $numinrow,$itemcount,'','','','','',
5939: '',$names{$item});
5940: $itemcount ++;
5941: }
5942: }
5943: if (ref($rowtotal)) {
5944: $$rowtotal += $itemcount;
5945: }
5946: return $datatable;
5947: }
5948:
1.354 raeburn 5949: sub print_passwords {
5950: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5951: my ($datatable,$css_class);
5952: my $itemcount = 0;
5953: my %titles = &Apache::lonlocal::texthash (
5954: captcha => '"Forgot Password" CAPTCHA validation',
5955: link => 'Reset link expiration (hours)',
5956: case => 'Case-sensitive usernames/e-mail',
5957: prelink => 'Information required (form 1)',
5958: postlink => 'Information required (form 2)',
5959: emailsrc => 'LON-CAPA e-mail address type(s)',
5960: customtext => 'Domain specific text (HTML)',
5961: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5962: intauth_check => 'Check bcrypt cost if authenticated',
5963: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5964: permanent => 'Permanent e-mail address',
5965: critical => 'Critical notification address',
5966: notify => 'Notification address',
5967: min => 'Minimum password length',
5968: max => 'Maximum password length',
5969: chars => 'Required characters',
5970: expire => 'Password expiration (days)',
1.356 raeburn 5971: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 5972: );
5973: if ($position eq 'top') {
5974: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5975: my $shownlinklife = 2;
5976: my $prelink = 'both';
5977: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5978: if (ref($settings) eq 'HASH') {
5979: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5980: $shownlinklife = $settings->{resetlink};
5981: }
5982: if (ref($settings->{resetcase}) eq 'ARRAY') {
5983: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5984: }
5985: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5986: $prelink = $settings->{resetprelink};
5987: }
5988: if (ref($settings->{resetpostlink}) eq 'HASH') {
5989: %postlink = %{$settings->{resetpostlink}};
5990: }
5991: if (ref($settings->{resetemail}) eq 'ARRAY') {
5992: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5993: }
5994: if ($settings->{resetremove}) {
5995: $nostdtext = 1;
5996: }
5997: if ($settings->{resetcustom}) {
5998: $customurl = $settings->{resetcustom};
5999: }
6000: } else {
6001: if (ref($types) eq 'ARRAY') {
6002: foreach my $item (@{$types}) {
6003: $casesens{$item} = 1;
6004: $postlink{$item} = ['username','email'];
6005: }
6006: }
6007: $casesens{'default'} = 1;
6008: $postlink{'default'} = ['username','email'];
6009: $prelink = 'both';
6010: %emailsrc = (
6011: permanent => 1,
6012: critical => 1,
6013: notify => 1,
6014: );
6015: }
6016: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6017: $itemcount ++;
6018: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6019: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6020: '<td class="LC_left_item">'.
6021: '<input type="textbox" value="'.$shownlinklife.'" '.
6022: 'name="passwords_link" size="3" /></td></tr>';
6023: $itemcount ++;
6024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6025: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6026: '<td class="LC_left_item">';
6027: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6028: foreach my $item (@{$types}) {
6029: my $checkedcase;
6030: if ($casesens{$item}) {
6031: $checkedcase = ' checked="checked"';
6032: }
6033: $datatable .= '<span class="LC_nobreak"><label>'.
6034: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6035: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
6036: '<span> ';
6037: }
6038: }
6039: my $checkedcase;
6040: if ($casesens{'default'}) {
6041: $checkedcase = ' checked="checked"';
6042: }
6043: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6044: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6045: $othertitle.'</label></span></td>';
6046: $itemcount ++;
6047: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6048: my %checkedpre = (
6049: both => ' checked="checked"',
6050: either => '',
6051: );
6052: if ($prelink eq 'either') {
6053: $checkedpre{either} = ' checked="checked"';
6054: $checkedpre{both} = '';
6055: }
6056: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6057: '<td class="LC_left_item"><span class="LC_nobreak">'.
6058: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6059: &mt('Both username and e-mail address').'</label></span> '.
6060: '<span class="LC_nobreak"><label>'.
6061: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6062: &mt('Either username or e-mail address').'</label></span></td></tr>';
6063: $itemcount ++;
6064: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6065: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6066: '<td class="LC_left_item">';
6067: my %postlinked;
6068: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6069: foreach my $item (@{$types}) {
6070: undef(%postlinked);
6071: $datatable .= '<fieldset style="display: inline-block;">'.
6072: '<legend>'.$usertypes->{$item}.'</legend>';
6073: if (ref($postlink{$item}) eq 'ARRAY') {
6074: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6075: }
6076: foreach my $field ('email','username') {
6077: my $checked;
6078: if ($postlinked{$field}) {
6079: $checked = ' checked="checked"';
6080: }
6081: $datatable .= '<span class="LC_nobreak"><label>'.
6082: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6083: $field.'"'.$checked.' />'.$field.'</label>'.
6084: '<span> ';
6085: }
6086: $datatable .= '</fieldset>';
6087: }
6088: }
6089: if (ref($postlink{'default'}) eq 'ARRAY') {
6090: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6091: }
6092: $datatable .= '<fieldset style="display: inline-block;">'.
6093: '<legend>'.$othertitle.'</legend>';
6094: foreach my $field ('email','username') {
6095: my $checked;
6096: if ($postlinked{$field}) {
6097: $checked = ' checked="checked"';
6098: }
6099: $datatable .= '<span class="LC_nobreak"><label>'.
6100: '<input type="checkbox" name="passwords_postlink_default" value="'.
6101: $field.'"'.$checked.' />'.$field.'</label>'.
6102: '<span> ';
6103: }
6104: $datatable .= '</fieldset></td></tr>';
6105: $itemcount ++;
6106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6107: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6108: '<td class="LC_left_item">';
6109: foreach my $type ('permanent','critical','notify') {
6110: my $checkedemail;
6111: if ($emailsrc{$type}) {
6112: $checkedemail = ' checked="checked"';
6113: }
6114: $datatable .= '<span class="LC_nobreak"><label>'.
6115: '<input type="checkbox" name="passwords_emailsrc" value="'.
6116: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6117: '<span> ';
6118: }
6119: $datatable .= '</td></tr>';
6120: $itemcount ++;
6121: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6122: my $switchserver = &check_switchserver($dom,$confname);
6123: my ($showstd,$noshowstd);
6124: if ($nostdtext) {
6125: $noshowstd = ' checked="checked"';
6126: } else {
6127: $showstd = ' checked="checked"';
6128: }
6129: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6130: '<td class="LC_left_item"><span class="LC_nobreak">'.
6131: &mt('Retain standard text:').
6132: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6133: &mt('Yes').'</label>'.' '.
6134: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6135: &mt('No').'</label></span><br />'.
6136: '<span class="LC_fontsize_small">'.
6137: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6138: &mt('Include custom text:');
6139: if ($customurl) {
6140: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
6141: undef,undef,undef,undef,'background-color:#ffffff');
6142: $datatable .= '<span class="LC_nobreak"> '.$link.
6143: '<label><input type="checkbox" name="passwords_custom_del"'.
6144: ' value="1" />'.&mt('Delete?').'</label></span>'.
6145: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6146: }
6147: if ($switchserver) {
6148: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6149: } else {
6150: $datatable .='<span class="LC_nobreak"> '.
6151: '<input type="file" name="passwords_customfile" /></span>';
6152: }
6153: $datatable .= '</td></tr>';
6154: } elsif ($position eq 'middle') {
6155: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6156: my @items = ('intauth_cost','intauth_check','intauth_switch');
6157: my %defaults;
6158: if (ref($domconf{'defaults'}) eq 'HASH') {
6159: %defaults = %{$domconf{'defaults'}};
6160: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6161: $defaults{'intauth_cost'} = 10;
6162: }
6163: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6164: $defaults{'intauth_check'} = 0;
6165: }
6166: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6167: $defaults{'intauth_switch'} = 0;
6168: }
6169: } else {
6170: %defaults = (
6171: 'intauth_cost' => 10,
6172: 'intauth_check' => 0,
6173: 'intauth_switch' => 0,
6174: );
6175: }
6176: foreach my $item (@items) {
6177: if ($itemcount%2) {
6178: $css_class = '';
6179: } else {
6180: $css_class = ' class="LC_odd_row" ';
6181: }
6182: $datatable .= '<tr'.$css_class.'>'.
6183: '<td><span class="LC_nobreak">'.$titles{$item}.
6184: '</span></td><td class="LC_left_item" colspan="3">';
6185: if ($item eq 'intauth_switch') {
6186: my @options = (0,1,2);
6187: my %optiondesc = &Apache::lonlocal::texthash (
6188: 0 => 'No',
6189: 1 => 'Yes',
6190: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6191: );
6192: $datatable .= '<table width="100%">';
6193: foreach my $option (@options) {
6194: my $checked = ' ';
6195: if ($defaults{$item} eq $option) {
6196: $checked = ' checked="checked"';
6197: }
6198: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6199: '<label><input type="radio" name="'.$item.
6200: '" value="'.$option.'"'.$checked.' />'.
6201: $optiondesc{$option}.'</label></span></td></tr>';
6202: }
6203: $datatable .= '</table>';
6204: } elsif ($item eq 'intauth_check') {
6205: my @options = (0,1,2);
6206: my %optiondesc = &Apache::lonlocal::texthash (
6207: 0 => 'No',
6208: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6209: 2 => 'Yes, disallow login if stored cost is less than domain default',
6210: );
6211: $datatable .= '<table width="100%">';
6212: foreach my $option (@options) {
6213: my $checked = ' ';
6214: my $onclick;
6215: if ($defaults{$item} eq $option) {
6216: $checked = ' checked="checked"';
6217: }
6218: if ($option == 2) {
6219: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6220: }
6221: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6222: '<label><input type="radio" name="'.$item.
6223: '" value="'.$option.'"'.$checked.$onclick.' />'.
6224: $optiondesc{$option}.'</label></span></td></tr>';
6225: }
6226: $datatable .= '</table>';
6227: } else {
6228: $datatable .= '<input type="text" name="'.$item.'" value="'.
6229: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6230: }
6231: $datatable .= '</td></tr>';
6232: $itemcount ++;
6233: }
6234: } elsif ($position eq 'lower') {
1.356 raeburn 6235: my ($min,$max,%chars,$expire,$numsaved);
1.354 raeburn 6236: if (ref($settings) eq 'HASH') {
6237: if ($settings->{min}) {
6238: $min = $settings->{min};
6239: }
6240: if ($settings->{max}) {
6241: $max = $settings->{max};
6242: }
6243: if (ref($settings->{chars}) eq 'ARRAY') {
6244: map { $chars{$_} = 1; } (@{$settings->{chars}});
6245: }
6246: if ($settings->{expire}) {
6247: $expire = $settings->{expire};
6248: }
1.358 raeburn 6249: if ($settings->{numsaved}) {
6250: $numsaved = $settings->{numsaved};
1.356 raeburn 6251: }
1.354 raeburn 6252: } else {
6253: $min = '7';
6254: }
6255: my %rulenames = &Apache::lonlocal::texthash(
6256: uc => 'At least one upper case letter',
6257: lc => 'At least one lower case letter',
6258: num => 'At least one number',
6259: spec => 'At least one non-alphanumeric',
6260: );
6261: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6262: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6263: '<td class="LC_left_item"><span class="LC_nobreak">'.
6264: '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
6265: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
6266: '</span></td></tr>';
6267: $itemcount ++;
6268: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6269: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6270: '<td class="LC_left_item"><span class="LC_nobreak">'.
6271: '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
6272: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6273: '</span></td></tr>';
6274: $itemcount ++;
6275: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6276: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6277: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6278: '</span></td>';
6279: my $numinrow = 2;
6280: my @possrules = ('uc','lc','num','spec');
6281: $datatable .= '<td class="LC_left_item"><table>';
6282: for (my $i=0; $i<@possrules; $i++) {
6283: my ($rem,$checked);
6284: if ($chars{$possrules[$i]}) {
6285: $checked = ' checked="checked"';
6286: }
6287: $rem = $i%($numinrow);
6288: if ($rem == 0) {
6289: if ($i > 0) {
6290: $datatable .= '</tr>';
6291: }
6292: $datatable .= '<tr>';
6293: }
6294: $datatable .= '<td><span class="LC_nobreak"><label>'.
6295: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6296: $rulenames{$possrules[$i]}.'</label></span></td>';
6297: }
6298: my $rem = @possrules%($numinrow);
6299: my $colsleft = $numinrow - $rem;
6300: if ($colsleft > 1 ) {
6301: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6302: ' </td>';
6303: } elsif ($colsleft == 1) {
6304: $datatable .= '<td class="LC_left_item"> </td>';
6305: }
6306: $datatable .='</table></td></tr>';
6307: $itemcount ++;
6308: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6309: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
6310: '<td class="LC_left_item"><span class="LC_nobreak">'.
6311: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" />'.
6312: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
6313: '</span></td></tr>';
1.356 raeburn 6314: $itemcount ++;
6315: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6316: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6317: '<td class="LC_left_item"><span class="LC_nobreak">'.
6318: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
6319: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6320: '</span></td></tr>';
1.354 raeburn 6321: } else {
1.359 raeburn 6322: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6323: my %ownerchg = (
6324: by => {},
6325: for => {},
6326: );
6327: my %ownertitles = &Apache::lonlocal::texthash (
6328: by => 'Course owner status(es) allowed',
6329: for => 'Student status(es) allowed',
6330: );
1.354 raeburn 6331: if (ref($settings) eq 'HASH') {
1.359 raeburn 6332: if (ref($settings->{crsownerchg}) eq 'HASH') {
6333: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6334: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6335: }
6336: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6337: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6338: }
1.354 raeburn 6339: }
6340: }
6341: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6342: $datatable .= '<tr '.$css_class.'>'.
6343: '<td>'.
6344: &mt('Requirements').'<ul>'.
1.359 raeburn 6345: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 6346: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6347: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 6348: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 6349: '</ul>'.
6350: '</td>'.
1.359 raeburn 6351: '<td class="LC_left_item">';
6352: foreach my $item ('by','for') {
6353: $datatable .= '<fieldset style="display: inline-block;">'.
6354: '<legend>'.$ownertitles{$item}.'</legend>';
6355: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6356: foreach my $type (@{$types}) {
6357: my $checked;
6358: if ($ownerchg{$item}{$type}) {
6359: $checked = ' checked="checked"';
6360: }
6361: $datatable .= '<span class="LC_nobreak"><label>'.
6362: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6363: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
6364: '<span> ';
6365: }
6366: }
6367: my $checked;
6368: if ($ownerchg{$item}{'default'}) {
6369: $checked = ' checked="checked"';
6370: }
6371: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6372: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6373: $othertitle.'</label></span></fieldset>';
6374: }
6375: $datatable .= '</td></tr>';
1.354 raeburn 6376: }
6377: return $datatable;
6378: }
6379:
1.137 raeburn 6380: sub print_usersessions {
6381: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 6382: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 6383: my (%by_ip,%by_location,@intdoms,@instdoms);
6384: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 6385:
6386: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6387: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6388: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6389: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6390: if ($position eq 'top') {
1.152 raeburn 6391: if (keys(%serverhomes) > 1) {
1.145 raeburn 6392: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 6393: my $curroffloadnow;
6394: if (ref($settings) eq 'HASH') {
6395: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6396: $curroffloadnow = $settings->{'offloadnow'};
6397: }
6398: }
6399: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 6400: } else {
1.140 raeburn 6401: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 6402: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
6403: '</td></tr>';
1.140 raeburn 6404: }
1.137 raeburn 6405: } else {
1.279 raeburn 6406: my %titles = &usersession_titles();
6407: my ($prefix,@types);
6408: if ($position eq 'bottom') {
6409: $prefix = 'remote';
6410: @types = ('version','excludedomain','includedomain');
1.145 raeburn 6411: } else {
1.279 raeburn 6412: $prefix = 'hosted';
6413: @types = ('excludedomain','includedomain');
6414: }
6415: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6416: }
6417: $$rowtotal += $itemcount;
6418: return $datatable;
6419: }
6420:
6421: sub rules_by_location {
6422: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
6423: my ($datatable,$itemcount,$css_class);
6424: if (keys(%{$by_location}) == 0) {
6425: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6426: $datatable = '<tr'.$css_class.'><td colspan="2">'.
6427: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
6428: '</td></tr>';
6429: $itemcount = 1;
6430: } else {
6431: $itemcount = 0;
6432: my $numinrow = 5;
6433: my (%current,%checkedon,%checkedoff);
6434: my @locations = sort(keys(%{$by_location}));
6435: foreach my $type (@{$types}) {
6436: $checkedon{$type} = '';
6437: $checkedoff{$type} = ' checked="checked"';
6438: }
6439: if (ref($settings) eq 'HASH') {
6440: if (ref($settings->{$prefix}) eq 'HASH') {
6441: foreach my $key (keys(%{$settings->{$prefix}})) {
6442: $current{$key} = $settings->{$prefix}{$key};
6443: if ($key eq 'version') {
6444: if ($current{$key} ne '') {
1.145 raeburn 6445: $checkedon{$key} = ' checked="checked"';
6446: $checkedoff{$key} = '';
6447: }
1.279 raeburn 6448: } elsif (ref($current{$key}) eq 'ARRAY') {
6449: $checkedon{$key} = ' checked="checked"';
6450: $checkedoff{$key} = '';
1.137 raeburn 6451: }
6452: }
6453: }
1.279 raeburn 6454: }
6455: foreach my $type (@{$types}) {
6456: next if ($type ne 'version' && !@locations);
6457: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6458: $datatable .= '<tr'.$css_class.'>
6459: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
6460: <span class="LC_nobreak">
6461: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6462: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6463: if ($type eq 'version') {
6464: my @lcversions = &Apache::lonnet::all_loncaparevs();
6465: my $selector = '<select name="'.$prefix.'_version">';
6466: foreach my $version (@lcversions) {
6467: my $selected = '';
6468: if ($current{'version'} eq $version) {
6469: $selected = ' selected="selected"';
1.145 raeburn 6470: }
1.279 raeburn 6471: $selector .= ' <option value="'.$version.'"'.
6472: $selected.'>'.$version.'</option>';
6473: }
6474: $selector .= '</select> ';
6475: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6476: } else {
6477: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6478: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6479: ' />'.(' 'x2).
6480: '<input type="button" value="'.&mt('uncheck all').'" '.
6481: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6482: "\n".
6483: '</div><div><table>';
6484: my $rem;
6485: for (my $i=0; $i<@locations; $i++) {
6486: my ($showloc,$value,$checkedtype);
6487: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
6488: my $ip = $by_location->{$locations[$i]}->[0];
6489: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6490: $value = join(':',@{$by_ip->{$ip}});
6491: $showloc = join(', ',@{$by_ip->{$ip}});
6492: if (ref($current{$type}) eq 'ARRAY') {
6493: foreach my $loc (@{$by_ip->{$ip}}) {
6494: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6495: $checkedtype = ' checked="checked"';
6496: last;
1.145 raeburn 6497: }
1.138 raeburn 6498: }
6499: }
6500: }
1.137 raeburn 6501: }
1.279 raeburn 6502: $rem = $i%($numinrow);
6503: if ($rem == 0) {
6504: if ($i > 0) {
6505: $datatable .= '</tr>';
6506: }
6507: $datatable .= '<tr>';
6508: }
6509: $datatable .= '<td class="LC_left_item">'.
6510: '<span class="LC_nobreak"><label>'.
6511: '<input type="checkbox" name="'.$prefix.'_'.$type.
6512: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6513: '</label></span></td>';
6514: }
6515: $rem = @locations%($numinrow);
6516: my $colsleft = $numinrow - $rem;
6517: if ($colsleft > 1 ) {
6518: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6519: ' </td>';
6520: } elsif ($colsleft == 1) {
6521: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6522: }
1.279 raeburn 6523: $datatable .= '</tr></table>';
1.137 raeburn 6524: }
1.279 raeburn 6525: $datatable .= '</td></tr>';
6526: $itemcount ++;
1.137 raeburn 6527: }
6528: }
1.279 raeburn 6529: return ($datatable,$itemcount);
1.137 raeburn 6530: }
6531:
1.275 raeburn 6532: sub print_ssl {
6533: my ($position,$dom,$settings,$rowtotal) = @_;
6534: my ($css_class,$datatable);
6535: my $itemcount = 1;
6536: if ($position eq 'top') {
1.281 raeburn 6537: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6538: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6539: my $same_institution;
6540: if ($intdom ne '') {
6541: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
6542: if (ref($internet_names) eq 'ARRAY') {
6543: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
6544: $same_institution = 1;
6545: }
6546: }
6547: }
1.275 raeburn 6548: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 6549: $datatable = '<tr'.$css_class.'><td colspan="2">';
6550: if ($same_institution) {
6551: my %domservers = &Apache::lonnet::get_servers($dom);
6552: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
6553: } else {
6554: $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.");
6555: }
6556: $datatable .= '</td></tr>';
1.275 raeburn 6557: $itemcount ++;
6558: } else {
6559: my %titles = &ssl_titles();
6560: my (%by_ip,%by_location,@intdoms,@instdoms);
6561: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6562: my @alldoms = &Apache::lonnet::all_domains();
6563: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6564: my @domservers = &Apache::lonnet::get_servers($dom);
6565: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6566: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 6567: if (($position eq 'connto') || ($position eq 'connfrom')) {
6568: my $legacy;
6569: unless (ref($settings) eq 'HASH') {
6570: my $name;
6571: if ($position eq 'connto') {
6572: $name = 'loncAllowInsecure';
6573: } else {
6574: $name = 'londAllowInsecure';
6575: }
6576: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
6577: my @ids=&Apache::lonnet::current_machine_ids();
6578: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
6579: my %what = (
6580: $name => 1,
6581: );
6582: my ($result,$returnhash) =
6583: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
6584: if ($result eq 'ok') {
6585: if (ref($returnhash) eq 'HASH') {
6586: $legacy = $returnhash->{$name};
6587: }
6588: }
6589: } else {
6590: $legacy = $Apache::lonnet::perlvar{$name};
6591: }
6592: }
1.275 raeburn 6593: foreach my $type ('dom','intdom','other') {
6594: my %checked;
6595: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6596: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
6597: '<td class="LC_right_item">';
6598: my $skip;
6599: if ($type eq 'dom') {
6600: unless (keys(%servers) > 1) {
6601: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
6602: $skip = 1;
6603: }
6604: }
6605: if ($type eq 'intdom') {
6606: unless (@instdoms > 1) {
6607: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6608: $skip = 1;
6609: }
6610: } elsif ($type eq 'other') {
6611: if (keys(%by_location) == 0) {
6612: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6613: $skip = 1;
6614: }
6615: }
6616: unless ($skip) {
6617: $checked{'yes'} = ' checked="checked"';
6618: if (ref($settings) eq 'HASH') {
1.293 raeburn 6619: if (ref($settings->{$position}) eq 'HASH') {
6620: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6621: $checked{$1} = $checked{'yes'};
6622: delete($checked{'yes'});
6623: }
6624: }
1.293 raeburn 6625: } else {
6626: if ($legacy == 0) {
6627: $checked{'req'} = $checked{'yes'};
6628: delete($checked{'yes'});
6629: }
1.275 raeburn 6630: }
6631: foreach my $option ('no','yes','req') {
6632: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6633: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6634: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6635: '</label></span>'.(' 'x2);
6636: }
6637: }
6638: $datatable .= '</td></tr>';
6639: $itemcount ++;
6640: }
6641: } else {
6642: my $prefix = 'replication';
6643: my @types = ('certreq','nocertreq');
1.279 raeburn 6644: if (keys(%by_location) == 0) {
6645: $datatable .= '<tr'.$css_class.'><td>'.
6646: &mt('Nothing to set here, as there are no other institutions').
6647: '</td></tr>';
6648: $itemcount ++;
1.275 raeburn 6649: } else {
1.279 raeburn 6650: ($datatable,$itemcount) =
6651: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6652: }
6653: }
6654: }
6655: $$rowtotal += $itemcount;
6656: return $datatable;
6657: }
6658:
6659: sub ssl_titles {
6660: return &Apache::lonlocal::texthash (
6661: dom => 'LON-CAPA servers/VMs from same domain',
6662: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6663: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6664: connto => 'Connections to other servers',
6665: connfrom => 'Connections from other servers',
1.275 raeburn 6666: replication => 'Replicating content to other institutions',
6667: certreq => 'Client certificate required, but specific domains exempt',
6668: nocertreq => 'No client certificate required, except for specific domains',
6669: no => 'SSL not used',
6670: yes => 'SSL Optional (used if available)',
6671: req => 'SSL Required',
6672: );
1.279 raeburn 6673: }
6674:
6675: sub print_trust {
6676: my ($prefix,$dom,$settings,$rowtotal) = @_;
6677: my ($css_class,$datatable,%checked,%choices);
6678: my (%by_ip,%by_location,@intdoms,@instdoms);
6679: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6680: my $itemcount = 1;
6681: my %titles = &trust_titles();
6682: my @types = ('exc','inc');
6683: if ($prefix eq 'top') {
6684: $prefix = 'content';
6685: } elsif ($prefix eq 'bottom') {
6686: $prefix = 'msg';
6687: }
6688: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6689: $$rowtotal += $itemcount;
6690: return $datatable;
6691: }
6692:
6693: sub trust_titles {
6694: return &Apache::lonlocal::texthash(
6695: content => "Access to this domain's content by others",
6696: shared => "Access to other domain's content by this domain",
6697: enroll => "Enrollment in this domain's courses by others",
6698: othcoau => "Co-author roles in this domain for others",
6699: coaurem => "Co-author roles for this domain's users elsewhere",
6700: domroles => "Domain roles in this domain assignable to others",
6701: catalog => "Course Catalog for this domain displayed elsewhere",
6702: reqcrs => "Requests for creation of courses in this domain by others",
6703: msg => "Users in other domains can send messages to this domain",
6704: exc => "Allow all, but exclude specific domains",
6705: inc => "Deny all, but include specific domains",
6706: );
1.275 raeburn 6707: }
6708:
1.138 raeburn 6709: sub build_location_hashes {
1.275 raeburn 6710: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6711: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6712: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6713: my %iphost = &Apache::lonnet::get_iphost();
6714: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6715: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6716: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6717: foreach my $id (@{$iphost{$primary_ip}}) {
6718: my $intdom = &Apache::lonnet::internet_dom($id);
6719: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6720: push(@{$intdoms},$intdom);
6721: }
6722: }
6723: }
6724: foreach my $ip (keys(%iphost)) {
6725: if (ref($iphost{$ip}) eq 'ARRAY') {
6726: foreach my $id (@{$iphost{$ip}}) {
6727: my $location = &Apache::lonnet::internet_dom($id);
6728: if ($location) {
1.275 raeburn 6729: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6730: my $dom = &Apache::lonnet::host_domain($id);
6731: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6732: push(@{$instdoms},$dom);
6733: }
6734: next;
6735: }
1.138 raeburn 6736: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6737: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6738: push(@{$by_ip->{$ip}},$location);
6739: }
6740: } else {
6741: $by_ip->{$ip} = [$location];
6742: }
6743: }
6744: }
6745: }
6746: }
6747: foreach my $ip (sort(keys(%{$by_ip}))) {
6748: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6749: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6750: my $first = $by_ip->{$ip}->[0];
6751: if (ref($by_location->{$first}) eq 'ARRAY') {
6752: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6753: push(@{$by_location->{$first}},$ip);
6754: }
6755: } else {
6756: $by_location->{$first} = [$ip];
6757: }
6758: }
6759: }
6760: return;
6761: }
6762:
1.145 raeburn 6763: sub current_offloads_to {
6764: my ($dom,$settings,$servers) = @_;
6765: my (%spareid,%otherdomconfigs);
1.152 raeburn 6766: if (ref($servers) eq 'HASH') {
1.145 raeburn 6767: foreach my $lonhost (sort(keys(%{$servers}))) {
6768: my $gotspares;
1.152 raeburn 6769: if (ref($settings) eq 'HASH') {
6770: if (ref($settings->{'spares'}) eq 'HASH') {
6771: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6772: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6773: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6774: $gotspares = 1;
6775: }
1.145 raeburn 6776: }
6777: }
6778: unless ($gotspares) {
6779: my $gotspares;
6780: my $serverhomeID =
6781: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6782: my $serverhomedom =
6783: &Apache::lonnet::host_domain($serverhomeID);
6784: if ($serverhomedom ne $dom) {
6785: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6786: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6787: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6788: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6789: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6790: $gotspares = 1;
6791: }
6792: }
6793: } else {
6794: $otherdomconfigs{$serverhomedom} =
6795: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6796: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6797: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6798: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6799: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6800: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6801: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6802: $gotspares = 1;
6803: }
6804: }
6805: }
6806: }
6807: }
6808: }
6809: }
6810: unless ($gotspares) {
6811: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6812: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6813: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6814: } else {
6815: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6816: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6817: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6818: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6819: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6820: } else {
1.150 raeburn 6821: my %what = (
6822: spareid => 1,
6823: );
6824: my ($result,$returnhash) =
6825: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6826: if ($result eq 'ok') {
6827: if (ref($returnhash) eq 'HASH') {
6828: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6829: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6830: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6831: }
6832: }
1.145 raeburn 6833: }
6834: }
6835: }
6836: }
6837: }
6838: }
6839: return %spareid;
6840: }
6841:
6842: sub spares_row {
1.261 raeburn 6843: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6844: my $css_class;
6845: my $numinrow = 4;
6846: my $itemcount = 1;
6847: my $datatable;
1.152 raeburn 6848: my %typetitles = &sparestype_titles();
6849: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6850: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6851: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6852: my ($othercontrol,$serverdom);
6853: if ($serverhome ne $server) {
6854: $serverdom = &Apache::lonnet::host_domain($serverhome);
6855: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6856: } else {
6857: $serverdom = &Apache::lonnet::host_domain($server);
6858: if ($serverdom ne $dom) {
6859: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6860: }
6861: }
6862: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6863: my $checkednow;
6864: if (ref($curroffloadnow) eq 'HASH') {
6865: if ($curroffloadnow->{$server}) {
6866: $checkednow = ' checked="checked"';
6867: }
6868: }
1.145 raeburn 6869: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6870: $datatable .= '<tr'.$css_class.'>
6871: <td rowspan="2">
1.183 bisitz 6872: <span class="LC_nobreak">'.
6873: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6874: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6875: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6876: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6877: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6878: "\n";
1.145 raeburn 6879: my (%current,%canselect);
1.152 raeburn 6880: my @choices =
6881: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6882: foreach my $type ('primary','default') {
6883: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6884: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6885: my @spares = @{$spareid->{$server}{$type}};
6886: if (@spares > 0) {
1.152 raeburn 6887: if ($othercontrol) {
6888: $current{$type} = join(', ',@spares);
6889: } else {
6890: $current{$type} .= '<table>';
6891: my $numspares = scalar(@spares);
6892: for (my $i=0; $i<@spares; $i++) {
6893: my $rem = $i%($numinrow);
6894: if ($rem == 0) {
6895: if ($i > 0) {
6896: $current{$type} .= '</tr>';
6897: }
6898: $current{$type} .= '<tr>';
1.145 raeburn 6899: }
1.152 raeburn 6900: $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'".');" /> '.
6901: $spareid->{$server}{$type}[$i].
6902: '</label></td>'."\n";
6903: }
6904: my $rem = @spares%($numinrow);
6905: my $colsleft = $numinrow - $rem;
6906: if ($colsleft > 1 ) {
6907: $current{$type} .= '<td colspan="'.$colsleft.
6908: '" class="LC_left_item">'.
6909: ' </td>';
6910: } elsif ($colsleft == 1) {
6911: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6912: }
1.152 raeburn 6913: $current{$type} .= '</tr></table>';
1.150 raeburn 6914: }
1.145 raeburn 6915: }
6916: }
6917: if ($current{$type} eq '') {
6918: $current{$type} = &mt('None specified');
6919: }
1.152 raeburn 6920: if ($othercontrol) {
6921: if ($type eq 'primary') {
6922: $canselect{$type} = $othercontrol;
6923: }
6924: } else {
6925: $canselect{$type} =
6926: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6927: '<select name="newspare_'.$type.'_'.$server.'" '.
6928: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6929: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6930: if (@choices > 0) {
6931: foreach my $lonhost (@choices) {
6932: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6933: }
6934: }
6935: $canselect{$type} .= '</select>'."\n";
6936: }
6937: } else {
6938: $current{$type} = &mt('Could not be determined');
6939: if ($type eq 'primary') {
6940: $canselect{$type} = $othercontrol;
6941: }
1.145 raeburn 6942: }
1.152 raeburn 6943: if ($type eq 'default') {
6944: $datatable .= '<tr'.$css_class.'>';
6945: }
6946: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6947: '<td>'.$current{$type}.'</td>'."\n".
6948: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6949: }
6950: $itemcount ++;
6951: }
6952: }
6953: $$rowtotal += $itemcount;
6954: return $datatable;
6955: }
6956:
1.152 raeburn 6957: sub possible_newspares {
6958: my ($server,$currspares,$serverhomes,$altids) = @_;
6959: my $serverhostname = &Apache::lonnet::hostname($server);
6960: my %excluded;
6961: if ($serverhostname ne '') {
6962: %excluded = (
6963: $serverhostname => 1,
6964: );
6965: }
6966: if (ref($currspares) eq 'HASH') {
6967: foreach my $type (keys(%{$currspares})) {
6968: if (ref($currspares->{$type}) eq 'ARRAY') {
6969: if (@{$currspares->{$type}} > 0) {
6970: foreach my $curr (@{$currspares->{$type}}) {
6971: my $hostname = &Apache::lonnet::hostname($curr);
6972: $excluded{$hostname} = 1;
6973: }
6974: }
6975: }
6976: }
6977: }
6978: my @choices;
6979: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
6980: if (keys(%{$serverhomes}) > 1) {
6981: foreach my $name (sort(keys(%{$serverhomes}))) {
6982: unless ($excluded{$name}) {
6983: if (exists($altids->{$serverhomes->{$name}})) {
6984: push(@choices,$altids->{$serverhomes->{$name}});
6985: } else {
6986: push(@choices,$serverhomes->{$name});
1.145 raeburn 6987: }
6988: }
6989: }
6990: }
6991: }
1.152 raeburn 6992: return sort(@choices);
1.145 raeburn 6993: }
6994:
1.150 raeburn 6995: sub print_loadbalancing {
6996: my ($dom,$settings,$rowtotal) = @_;
6997: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6998: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6999: my $numinrow = 1;
7000: my $datatable;
7001: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 7002: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 7003: if (ref($settings) eq 'HASH') {
7004: %existing = %{$settings};
7005: }
7006: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7007: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 7008: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7009: } else {
7010: return;
7011: }
7012: my ($othertitle,$usertypes,$types) =
7013: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 7014: my $rownum = 8;
1.150 raeburn 7015: if (ref($types) eq 'ARRAY') {
7016: $rownum += scalar(@{$types});
7017: }
1.171 raeburn 7018: my @css_class = ('LC_odd_row','LC_even_row');
7019: my $balnum = 0;
7020: my $islast;
7021: my (@toshow,$disabledtext);
7022: if (keys(%currbalancer) > 0) {
7023: @toshow = sort(keys(%currbalancer));
7024: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7025: push(@toshow,'');
7026: }
7027: } else {
7028: @toshow = ('');
7029: $disabledtext = &mt('No existing load balancer');
7030: }
7031: foreach my $lonhost (@toshow) {
7032: if ($balnum == scalar(@toshow)-1) {
7033: $islast = 1;
7034: } else {
7035: $islast = 0;
7036: }
7037: my $cssidx = $balnum%2;
7038: my $targets_div_style = 'display: none';
7039: my $disabled_div_style = 'display: block';
7040: my $homedom_div_style = 'display: none';
7041: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7042: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7043: '<p>';
7044: if ($lonhost eq '') {
1.210 raeburn 7045: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 7046: if (keys(%currbalancer) > 0) {
7047: $datatable .= &mt('Add balancer:');
7048: } else {
7049: $datatable .= &mt('Enable balancer:');
7050: }
7051: $datatable .= ' '.
7052: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7053: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7054: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7055: '<option value="" selected="selected">'.&mt('None').
7056: '</option>'."\n";
7057: foreach my $server (sort(keys(%servers))) {
7058: next if ($currbalancer{$server});
7059: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7060: }
1.210 raeburn 7061: $datatable .=
1.171 raeburn 7062: '</select>'."\n".
7063: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7064: } else {
7065: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7066: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7067: &mt('Stop balancing').'</label>'.
7068: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7069: $targets_div_style = 'display: block';
7070: $disabled_div_style = 'display: none';
7071: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7072: $homedom_div_style = 'display: block';
7073: }
7074: }
1.306 raeburn 7075: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7076: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7077: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7078: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7079: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7080: my @sparestypes = ('primary','default');
7081: my %typetitles = &sparestype_titles();
1.284 raeburn 7082: my %hostherechecked = (
7083: no => ' checked="checked"',
7084: );
1.342 raeburn 7085: my %balcookiechecked = (
7086: no => ' checked="checked"',
7087: );
1.171 raeburn 7088: foreach my $sparetype (@sparestypes) {
7089: my $targettable;
7090: for (my $i=0; $i<$numspares; $i++) {
7091: my $checked;
7092: if (ref($currtargets{$lonhost}) eq 'HASH') {
7093: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7094: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7095: $checked = ' checked="checked"';
7096: }
7097: }
7098: }
7099: my ($chkboxval,$disabled);
7100: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7101: $chkboxval = $spares[$i];
7102: }
7103: if (exists($currbalancer{$spares[$i]})) {
7104: $disabled = ' disabled="disabled"';
7105: }
1.210 raeburn 7106: $targettable .=
1.253 raeburn 7107: '<td><span class="LC_nobreak"><label>'.
7108: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 7109: $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 7110: '</span></label></span></td>';
1.171 raeburn 7111: my $rem = $i%($numinrow);
7112: if ($rem == 0) {
7113: if (($i > 0) && ($i < $numspares-1)) {
7114: $targettable .= '</tr>';
7115: }
7116: if ($i < $numspares-1) {
7117: $targettable .= '<tr>';
1.150 raeburn 7118: }
7119: }
7120: }
1.171 raeburn 7121: if ($targettable ne '') {
7122: my $rem = $numspares%($numinrow);
7123: my $colsleft = $numinrow - $rem;
7124: if ($colsleft > 1 ) {
7125: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7126: ' </td>';
7127: } elsif ($colsleft == 1) {
7128: $targettable .= '<td class="LC_left_item"> </td>';
7129: }
7130: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7131: '<table><tr>'.$targettable.'</tr></table><br />';
7132: }
1.284 raeburn 7133: $hostherechecked{$sparetype} = '';
7134: if (ref($currtargets{$lonhost}) eq 'HASH') {
7135: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7136: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7137: $hostherechecked{$sparetype} = ' checked="checked"';
7138: $hostherechecked{'no'} = '';
7139: }
7140: }
7141: }
7142: }
1.342 raeburn 7143: if ($currcookies{$lonhost}) {
7144: %balcookiechecked = (
7145: yes => ' checked="checked"',
7146: );
7147: }
1.284 raeburn 7148: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7149: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7150: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7151: foreach my $sparetype (@sparestypes) {
7152: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7153: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7154: '</i></label><br />';
1.171 raeburn 7155: }
1.342 raeburn 7156: $datatable .= &mt('Use balancer cookie').'<br />'.
7157: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7158: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7159: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7160: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7161: '</div></td></tr>'.
1.171 raeburn 7162: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7163: $othertitle,$usertypes,$types,\%servers,
7164: \%currbalancer,$lonhost,
7165: $targets_div_style,$homedom_div_style,
7166: $css_class[$cssidx],$balnum,$islast);
7167: $$rowtotal += $rownum;
7168: $balnum ++;
7169: }
7170: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7171: return $datatable;
7172: }
7173:
7174: sub get_loadbalancers_config {
1.342 raeburn 7175: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 7176: return unless ((ref($servers) eq 'HASH') &&
7177: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 7178: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7179: (ref($currcookies) eq 'HASH'));
1.171 raeburn 7180: if (keys(%{$existing}) > 0) {
7181: my $oldlonhost;
7182: foreach my $key (sort(keys(%{$existing}))) {
7183: if ($key eq 'lonhost') {
7184: $oldlonhost = $existing->{'lonhost'};
7185: $currbalancer->{$oldlonhost} = 1;
7186: } elsif ($key eq 'targets') {
7187: if ($oldlonhost) {
7188: $currtargets->{$oldlonhost} = $existing->{'targets'};
7189: }
7190: } elsif ($key eq 'rules') {
7191: if ($oldlonhost) {
7192: $currrules->{$oldlonhost} = $existing->{'rules'};
7193: }
7194: } elsif (ref($existing->{$key}) eq 'HASH') {
7195: $currbalancer->{$key} = 1;
7196: $currtargets->{$key} = $existing->{$key}{'targets'};
7197: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 7198: if ($existing->{$key}{'cookie'}) {
7199: $currcookies->{$key} = 1;
7200: }
1.150 raeburn 7201: }
7202: }
1.171 raeburn 7203: } else {
7204: my ($balancerref,$targetsref) =
7205: &Apache::lonnet::get_lonbalancer_config($servers);
7206: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7207: foreach my $server (sort(keys(%{$balancerref}))) {
7208: $currbalancer->{$server} = 1;
7209: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7210: }
7211: }
7212: }
1.171 raeburn 7213: return;
1.150 raeburn 7214: }
7215:
7216: sub loadbalancing_rules {
7217: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 7218: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7219: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7220: my $output;
1.171 raeburn 7221: my $num = 0;
1.210 raeburn 7222: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7223: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7224: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7225: foreach my $type (@{$alltypes}) {
1.171 raeburn 7226: $num ++;
1.150 raeburn 7227: my $current;
7228: if (ref($currrules) eq 'HASH') {
7229: $current = $currrules->{$type};
7230: }
1.253 raeburn 7231: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 7232: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7233: $current = '';
7234: }
7235: }
7236: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 7237: $servers,$currbalancer,$lonhost,$dom,
7238: $targets_div_style,$homedom_div_style,
7239: $css_class,$balnum,$num,$islast);
1.150 raeburn 7240: }
7241: }
7242: return $output;
7243: }
7244:
7245: sub loadbalancing_titles {
7246: my ($dom,$intdom,$usertypes,$types) = @_;
7247: my %othertypes = (
7248: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7249: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7250: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7251: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 7252: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7253: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7254: );
1.209 raeburn 7255: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 7256: my @available;
1.150 raeburn 7257: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7258: @available = @{$types};
1.150 raeburn 7259: }
1.302 raeburn 7260: unless (grep(/^default$/,@available)) {
7261: push(@available,'default');
7262: }
7263: unshift(@alltypes,@available);
1.150 raeburn 7264: my %titles;
7265: foreach my $type (@alltypes) {
7266: if ($type =~ /^_LC_/) {
7267: $titles{$type} = $othertypes{$type};
7268: } elsif ($type eq 'default') {
7269: $titles{$type} = &mt('All users from [_1]',$dom);
7270: if (ref($types) eq 'ARRAY') {
7271: if (@{$types} > 0) {
7272: $titles{$type} = &mt('Other users from [_1]',$dom);
7273: }
7274: }
7275: } elsif (ref($usertypes) eq 'HASH') {
7276: $titles{$type} = $usertypes->{$type};
7277: }
7278: }
7279: return (\@alltypes,\%othertypes,\%titles);
7280: }
7281:
7282: sub loadbalance_rule_row {
1.171 raeburn 7283: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7284: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 7285: my @rulenames;
1.150 raeburn 7286: my %ruletitles = &offloadtype_text();
1.209 raeburn 7287: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 7288: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7289: } else {
1.209 raeburn 7290: @rulenames = ('default','homeserver');
7291: if ($type eq '_LC_external') {
7292: push(@rulenames,'externalbalancer');
7293: } else {
7294: push(@rulenames,'specific');
7295: }
7296: push(@rulenames,'none');
1.150 raeburn 7297: }
7298: my $style = $targets_div_style;
1.253 raeburn 7299: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7300: $style = $homedom_div_style;
7301: }
1.171 raeburn 7302: my $space;
7303: if ($islast && $num == 1) {
1.317 raeburn 7304: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 7305: }
1.210 raeburn 7306: my $output =
1.306 raeburn 7307: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 7308: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7309: '<td valaign="top">'.$space.
7310: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7311: for (my $i=0; $i<@rulenames; $i++) {
7312: my $rule = $rulenames[$i];
7313: my ($checked,$extra);
7314: if ($rulenames[$i] eq 'default') {
7315: $rule = '';
7316: }
7317: if ($rulenames[$i] eq 'specific') {
7318: if (ref($servers) eq 'HASH') {
7319: my $default;
7320: if (($current ne '') && (exists($servers->{$current}))) {
7321: $checked = ' checked="checked"';
7322: }
7323: unless ($checked) {
7324: $default = ' selected="selected"';
7325: }
1.210 raeburn 7326: $extra =
1.171 raeburn 7327: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7328: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7329: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7330: '<option value=""'.$default.'></option>'."\n";
7331: foreach my $server (sort(keys(%{$servers}))) {
7332: if (ref($currbalancer) eq 'HASH') {
7333: next if (exists($currbalancer->{$server}));
7334: }
1.150 raeburn 7335: my $selected;
1.171 raeburn 7336: if ($server eq $current) {
1.150 raeburn 7337: $selected = ' selected="selected"';
7338: }
1.171 raeburn 7339: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7340: }
7341: $extra .= '</select>';
7342: }
7343: } elsif ($rule eq $current) {
7344: $checked = ' checked="checked"';
7345: }
7346: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 7347: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7348: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7349: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 7350: ')"'.$checked.' /> ';
7351: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7352: $output .= $ruletitles{'particular'};
7353: } else {
7354: $output .= $ruletitles{$rulenames[$i]};
7355: }
7356: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7357: }
7358: $output .= '</div></td></tr>'."\n";
7359: return $output;
7360: }
7361:
7362: sub offloadtype_text {
7363: my %ruletitles = &Apache::lonlocal::texthash (
7364: 'default' => 'Offloads to default destinations',
7365: 'homeserver' => "Offloads to user's home server",
7366: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7367: 'specific' => 'Offloads to specific server',
1.161 raeburn 7368: 'none' => 'No offload',
1.209 raeburn 7369: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7370: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 7371: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7372: );
7373: return %ruletitles;
7374: }
7375:
7376: sub sparestype_titles {
7377: my %typestitles = &Apache::lonlocal::texthash (
7378: 'primary' => 'primary',
7379: 'default' => 'default',
7380: );
7381: return %typestitles;
7382: }
7383:
1.28 raeburn 7384: sub contact_titles {
7385: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 7386: 'supportemail' => 'Support E-mail address',
7387: 'adminemail' => 'Default Server Admin E-mail address',
7388: 'errormail' => 'Error reports to be e-mailed to',
7389: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 7390: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7391: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 7392: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7393: 'requestsmail' => 'E-mail from course requests requiring approval',
7394: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 7395: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 7396: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 7397: 'errorthreshold' => 'Error/warning threshold for status e-mail',
7398: 'errorsysmail' => 'Error threshold for e-mail to core group',
7399: 'errorweights' => 'Weights used to compute error count',
7400: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7401: );
7402: my %short_titles = &Apache::lonlocal::texthash (
7403: adminemail => 'Admin E-mail address',
7404: supportemail => 'Support E-mail',
7405: );
7406: return (\%titles,\%short_titles);
7407: }
7408:
1.286 raeburn 7409: sub helpform_fields {
7410: my %titles = &Apache::lonlocal::texthash (
7411: 'username' => 'Name',
7412: 'user' => 'Username/domain',
7413: 'phone' => 'Phone',
7414: 'cc' => 'Cc e-mail',
7415: 'course' => 'Course Details',
7416: 'section' => 'Sections',
1.289 raeburn 7417: 'screenshot' => 'File upload',
1.286 raeburn 7418: );
7419: my @fields = ('username','phone','user','course','section','cc','screenshot');
7420: my %possoptions = (
7421: username => ['yes','no','req'],
1.289 raeburn 7422: phone => ['yes','no','req'],
1.286 raeburn 7423: user => ['yes','no'],
1.289 raeburn 7424: cc => ['yes','no'],
1.286 raeburn 7425: course => ['yes','no'],
7426: section => ['yes','no'],
7427: screenshot => ['yes','no'],
7428: );
7429: my %fieldoptions = &Apache::lonlocal::texthash (
7430: 'yes' => 'Optional',
7431: 'req' => 'Required',
7432: 'no' => "Not shown",
7433: );
7434: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7435: }
7436:
1.72 raeburn 7437: sub tool_titles {
7438: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 7439: aboutme => 'Personal web page',
1.86 raeburn 7440: blog => 'Blog',
1.162 raeburn 7441: webdav => 'WebDAV',
1.86 raeburn 7442: portfolio => 'Portfolio',
1.88 bisitz 7443: official => 'Official courses (with institutional codes)',
7444: unofficial => 'Unofficial courses',
1.98 raeburn 7445: community => 'Communities',
1.216 raeburn 7446: textbook => 'Textbook courses',
1.271 raeburn 7447: placement => 'Placement tests',
1.86 raeburn 7448: );
1.72 raeburn 7449: return %titles;
7450: }
7451:
1.101 raeburn 7452: sub courserequest_titles {
7453: my %titles = &Apache::lonlocal::texthash (
7454: official => 'Official',
7455: unofficial => 'Unofficial',
7456: community => 'Communities',
1.216 raeburn 7457: textbook => 'Textbook',
1.271 raeburn 7458: placement => 'Placement tests',
1.325 raeburn 7459: lti => 'LTI Provider',
1.101 raeburn 7460: norequest => 'Not allowed',
1.325 raeburn 7461: approval => 'Approval by DC',
1.101 raeburn 7462: validate => 'With validation',
7463: autolimit => 'Numerical limit',
1.103 raeburn 7464: unlimited => '(blank for unlimited)',
1.101 raeburn 7465: );
7466: return %titles;
7467: }
7468:
1.163 raeburn 7469: sub authorrequest_titles {
7470: my %titles = &Apache::lonlocal::texthash (
7471: norequest => 'Not allowed',
7472: approval => 'Approval by Dom. Coord.',
7473: automatic => 'Automatic approval',
7474: );
7475: return %titles;
1.210 raeburn 7476: }
1.163 raeburn 7477:
1.101 raeburn 7478: sub courserequest_conditions {
7479: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7480: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 7481: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7482: );
7483: return %conditions;
7484: }
7485:
7486:
1.27 raeburn 7487: sub print_usercreation {
1.30 raeburn 7488: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7489: my $numinrow = 4;
1.28 raeburn 7490: my $datatable;
7491: if ($position eq 'top') {
1.30 raeburn 7492: $$rowtotal ++;
1.34 raeburn 7493: my $rowcount = 0;
1.32 raeburn 7494: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7495: if (ref($rules) eq 'HASH') {
7496: if (keys(%{$rules}) > 0) {
1.32 raeburn 7497: $datatable .= &user_formats_row('username',$settings,$rules,
7498: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7499: $$rowtotal ++;
1.32 raeburn 7500: $rowcount ++;
7501: }
7502: }
7503: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7504: if (ref($idrules) eq 'HASH') {
7505: if (keys(%{$idrules}) > 0) {
7506: $datatable .= &user_formats_row('id',$settings,$idrules,
7507: $idruleorder,$numinrow,$rowcount);
7508: $$rowtotal ++;
7509: $rowcount ++;
1.28 raeburn 7510: }
7511: }
1.39 raeburn 7512: if ($rowcount == 0) {
7513: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7514: $$rowtotal ++;
7515: $rowcount ++;
7516: }
1.34 raeburn 7517: } elsif ($position eq 'middle') {
1.224 raeburn 7518: my @creators = ('author','course','requestcrs');
1.37 raeburn 7519: my ($rules,$ruleorder) =
7520: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7521: my %lt = &usercreation_types();
7522: my %checked;
7523: if (ref($settings) eq 'HASH') {
7524: if (ref($settings->{'cancreate'}) eq 'HASH') {
7525: foreach my $item (@creators) {
7526: $checked{$item} = $settings->{'cancreate'}{$item};
7527: }
7528: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7529: foreach my $item (@creators) {
7530: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7531: $checked{$item} = 'none';
7532: }
7533: }
7534: }
7535: }
7536: my $rownum = 0;
7537: foreach my $item (@creators) {
7538: $rownum ++;
1.224 raeburn 7539: if ($checked{$item} eq '') {
7540: $checked{$item} = 'any';
1.34 raeburn 7541: }
7542: my $css_class;
7543: if ($rownum%2) {
7544: $css_class = '';
7545: } else {
7546: $css_class = ' class="LC_odd_row" ';
7547: }
7548: $datatable .= '<tr'.$css_class.'>'.
7549: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 7550: '</span></td><td style="text-align: right">';
1.224 raeburn 7551: my @options = ('any');
7552: if (ref($rules) eq 'HASH') {
7553: if (keys(%{$rules}) > 0) {
7554: push(@options,('official','unofficial'));
1.37 raeburn 7555: }
7556: }
1.224 raeburn 7557: push(@options,'none');
1.37 raeburn 7558: foreach my $option (@options) {
1.50 raeburn 7559: my $type = 'radio';
1.34 raeburn 7560: my $check = ' ';
1.224 raeburn 7561: if ($checked{$item} eq $option) {
7562: $check = ' checked="checked" ';
1.34 raeburn 7563: }
7564: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7565: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7566: $item.'" value="'.$option.'"'.$check.'/> '.
7567: $lt{$option}.'</label> </span>';
7568: }
7569: $datatable .= '</td></tr>';
7570: }
1.28 raeburn 7571: } else {
7572: my @contexts = ('author','course','domain');
1.325 raeburn 7573: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 7574: my %checked;
7575: if (ref($settings) eq 'HASH') {
7576: if (ref($settings->{'authtypes'}) eq 'HASH') {
7577: foreach my $item (@contexts) {
7578: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7579: foreach my $auth (@authtypes) {
7580: if ($settings->{'authtypes'}{$item}{$auth}) {
7581: $checked{$item}{$auth} = ' checked="checked" ';
7582: }
7583: }
7584: }
7585: }
1.27 raeburn 7586: }
1.35 raeburn 7587: } else {
7588: foreach my $item (@contexts) {
1.36 raeburn 7589: foreach my $auth (@authtypes) {
1.35 raeburn 7590: $checked{$item}{$auth} = ' checked="checked" ';
7591: }
7592: }
1.27 raeburn 7593: }
1.28 raeburn 7594: my %title = &context_names();
7595: my %authname = &authtype_names();
7596: my $rownum = 0;
7597: my $css_class;
7598: foreach my $item (@contexts) {
7599: if ($rownum%2) {
7600: $css_class = '';
7601: } else {
7602: $css_class = ' class="LC_odd_row" ';
7603: }
1.30 raeburn 7604: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7605: '<td>'.$title{$item}.
7606: '</td><td class="LC_left_item">'.
7607: '<span class="LC_nobreak">';
7608: foreach my $auth (@authtypes) {
7609: $datatable .= '<label>'.
7610: '<input type="checkbox" name="'.$item.'_auth" '.
7611: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7612: $authname{$auth}.'</label> ';
7613: }
7614: $datatable .= '</span></td></tr>';
7615: $rownum ++;
1.27 raeburn 7616: }
1.30 raeburn 7617: $$rowtotal += $rownum;
1.27 raeburn 7618: }
7619: return $datatable;
7620: }
7621:
1.224 raeburn 7622: sub print_selfcreation {
7623: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7624: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7625: $emaildomain,$datatable);
1.224 raeburn 7626: if (ref($settings) eq 'HASH') {
7627: if (ref($settings->{'cancreate'}) eq 'HASH') {
7628: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7629: if (ref($createsettings) eq 'HASH') {
7630: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7631: @selfcreate = @{$createsettings->{'selfcreate'}};
7632: } elsif ($createsettings->{'selfcreate'} ne '') {
7633: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7634: @selfcreate = ('email','login','sso');
7635: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7636: @selfcreate = ($createsettings->{'selfcreate'});
7637: }
7638: }
7639: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7640: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7641: }
1.305 raeburn 7642: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7643: $emailoptions = $createsettings->{'emailoptions'};
7644: }
1.303 raeburn 7645: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7646: $emailverified = $createsettings->{'emailverified'};
7647: }
7648: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7649: $emaildomain = $createsettings->{'emaildomain'};
7650: }
1.224 raeburn 7651: }
7652: }
7653: }
7654: my %radiohash;
7655: my $numinrow = 4;
7656: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7657: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7658: if ($position eq 'top') {
7659: my %choices = &Apache::lonlocal::texthash (
7660: cancreate_login => 'Institutional Login',
7661: cancreate_sso => 'Institutional Single Sign On',
7662: );
7663: my @toggles = sort(keys(%choices));
7664: my %defaultchecked = (
7665: 'cancreate_login' => 'off',
7666: 'cancreate_sso' => 'off',
7667: );
1.228 raeburn 7668: my ($onclick,$itemcount);
1.224 raeburn 7669: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7670: \%choices,$itemcount,$onclick);
1.228 raeburn 7671: $$rowtotal += $itemcount;
7672:
1.224 raeburn 7673: if (ref($usertypes) eq 'HASH') {
7674: if (keys(%{$usertypes}) > 0) {
7675: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7676: $dom,$numinrow,$othertitle,
1.305 raeburn 7677: 'statustocreate',$rowtotal);
1.224 raeburn 7678: $$rowtotal ++;
7679: }
7680: }
1.240 raeburn 7681: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7682: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7683: $fieldtitles{'inststatus'} = &mt('Institutional status');
7684: my $rem;
7685: my $numperrow = 2;
7686: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7687: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7688: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7689: '<td class="LC_left_item">'."\n".
1.334 raeburn 7690: '<table>'."\n";
1.240 raeburn 7691: for (my $i=0; $i<@fields; $i++) {
7692: $rem = $i%($numperrow);
7693: if ($rem == 0) {
7694: if ($i > 0) {
7695: $datatable .= '</tr>';
7696: }
7697: $datatable .= '<tr>';
7698: }
7699: my $currval;
1.248 raeburn 7700: if (ref($createsettings) eq 'HASH') {
7701: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7702: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7703: }
1.240 raeburn 7704: }
7705: $datatable .= '<td class="LC_left_item">'.
7706: '<span class="LC_nobreak">'.
7707: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7708: 'value="'.$currval.'" size="10" /> '.
7709: $fieldtitles{$fields[$i]}.'</span></td>';
7710: }
7711: my $colsleft = $numperrow - $rem;
7712: if ($colsleft > 1 ) {
7713: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7714: ' </td>';
7715: } elsif ($colsleft == 1) {
7716: $datatable .= '<td class="LC_left_item"> </td>';
7717: }
7718: $datatable .= '</tr></table></td></tr>';
7719: $$rowtotal ++;
1.224 raeburn 7720: } elsif ($position eq 'middle') {
7721: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7722: my @posstypes;
1.224 raeburn 7723: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7724: @posstypes = @{$types};
7725: }
7726: unless (grep(/^default$/,@posstypes)) {
7727: push(@posstypes,'default');
7728: }
7729: my %usertypeshash;
7730: if (ref($usertypes) eq 'HASH') {
7731: %usertypeshash = %{$usertypes};
7732: }
7733: $usertypeshash{'default'} = $othertitle;
7734: foreach my $status (@posstypes) {
7735: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7736: $numinrow,$$rowtotal,\%usertypeshash);
7737: $$rowtotal ++;
1.224 raeburn 7738: }
7739: } else {
1.236 raeburn 7740: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7741: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7742: );
7743: my @toggles = sort(keys(%choices));
7744: my %defaultchecked = (
7745: 'cancreate_email' => 'off',
7746: );
1.305 raeburn 7747: my $customclass = 'LC_selfcreate_email';
7748: my $classprefix = 'LC_canmodify_emailusername_';
7749: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7750: my $display = 'none';
1.305 raeburn 7751: my $rowstyle = 'display:none';
1.236 raeburn 7752: if (grep(/^\Qemail\E$/,@selfcreate)) {
7753: $display = 'block';
1.305 raeburn 7754: $rowstyle = 'display:table-row';
1.236 raeburn 7755: }
1.305 raeburn 7756: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7757: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7758: \%choices,$$rowtotal,$onclick);
7759: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7760: $rowstyle);
7761: $$rowtotal ++;
7762: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7763: $rowstyle);
7764: $$rowtotal ++;
7765: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7766: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7767: my ($emailrules,$emailruleorder) =
7768: &Apache::lonnet::inst_userrules($dom,'email');
7769: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7770: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7771: if (ref($types) eq 'ARRAY') {
7772: @posstypes = @{$types};
7773: }
7774: if (@posstypes) {
7775: unless (grep(/^default$/,@posstypes)) {
7776: push(@posstypes,'default');
1.302 raeburn 7777: }
7778: if (ref($usertypes) eq 'HASH') {
7779: %usertypeshash = %{$usertypes};
7780: }
1.305 raeburn 7781: my $currassign;
7782: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7783: $currassign = {
7784: selfassign => $domdefaults{'inststatusguest'},
7785: };
7786: @ordered = @{$domdefaults{'inststatusguest'}};
7787: } else {
7788: $currassign = { selfassign => [] };
7789: }
7790: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7791: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7792: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7793: $numinrow,$othertitle,'selfassign',
7794: $rowtotal,$onclicktypes,$customclass,
7795: $rowstyle);
7796: $$rowtotal ++;
1.302 raeburn 7797: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7798: foreach my $status (@posstypes) {
7799: my $css_class;
7800: if ($$rowtotal%2) {
7801: $css_class = 'LC_odd_row ';
7802: }
7803: $css_class .= $customclass;
7804: my $rowid = $optionsprefix.$status;
7805: my $hidden = 1;
7806: my $currstyle = 'display:none';
7807: if (grep(/^\Q$status\E$/,@ordered)) {
7808: $currstyle = $rowstyle;
7809: $hidden = 0;
7810: }
7811: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7812: $emailrules,$emailruleorder,$settings,$status,$rowid,
7813: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7814: unless ($hidden) {
7815: $$rowtotal ++;
7816: }
1.224 raeburn 7817: }
1.302 raeburn 7818: } else {
1.305 raeburn 7819: my $css_class;
7820: if ($$rowtotal%2) {
7821: $css_class = 'LC_odd_row ';
7822: }
7823: $css_class .= $customclass;
1.302 raeburn 7824: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7825: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7826: $emailrules,$emailruleorder,$settings,'default','',
7827: $othertitle,$css_class,$rowstyle,$intdom);
7828: $$rowtotal ++;
1.224 raeburn 7829: }
7830: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7831: $numinrow = 1;
1.305 raeburn 7832: if (@posstypes) {
7833: foreach my $status (@posstypes) {
7834: my $rowid = $classprefix.$status;
7835: my $datarowstyle = 'display:none';
7836: if (grep(/^\Q$status\E$/,@ordered)) {
7837: $datarowstyle = $rowstyle;
7838: }
7839: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7840: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7841: $infotitles,$rowid,$customclass,$datarowstyle);
7842: unless ($datarowstyle eq 'display:none') {
7843: $$rowtotal ++;
7844: }
1.224 raeburn 7845: }
1.305 raeburn 7846: } else {
7847: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7848: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7849: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7850: }
7851: }
7852: return $datatable;
7853: }
7854:
1.305 raeburn 7855: sub selfcreate_javascript {
7856: return <<"ENDSCRIPT";
7857:
7858: <script type="text/javascript">
7859: // <![CDATA[
7860:
7861: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7862: var x = document.getElementsByClassName(target);
7863: var insttypes = 0;
7864: var insttypeRegExp = new RegExp(prefix);
7865: if ((x.length != undefined) && (x.length > 0)) {
7866: if (form.elements[radio].length != undefined) {
7867: for (var i=0; i<form.elements[radio].length; i++) {
7868: if (form.elements[radio][i].checked) {
7869: if (form.elements[radio][i].value == 1) {
7870: for (var j=0; j<x.length; j++) {
7871: if (x[j].id == 'undefined') {
7872: x[j].style.display = 'table-row';
7873: } else if (insttypeRegExp.test(x[j].id)) {
7874: insttypes ++;
7875: } else {
7876: x[j].style.display = 'table-row';
7877: }
7878: }
7879: } else {
7880: for (var j=0; j<x.length; j++) {
7881: x[j].style.display = 'none';
7882: }
1.236 raeburn 7883: }
1.305 raeburn 7884: break;
7885: }
7886: }
7887: if (insttypes > 0) {
7888: toggleDataRow(form,checkbox,target,altprefix);
7889: toggleDataRow(form,checkbox,target,prefix,1);
7890: }
7891: }
7892: }
7893: return;
7894: }
7895:
7896: function toggleDataRow(form,checkbox,target,prefix,docount) {
7897: if (form.elements[checkbox].length != undefined) {
7898: var count = 0;
7899: if (docount) {
7900: for (var i=0; i<form.elements[checkbox].length; i++) {
7901: if (form.elements[checkbox][i].checked) {
7902: count ++;
1.236 raeburn 7903: }
1.305 raeburn 7904: }
7905: }
7906: for (var i=0; i<form.elements[checkbox].length; i++) {
7907: var type = form.elements[checkbox][i].value;
7908: if (document.getElementById(prefix+type)) {
7909: if (form.elements[checkbox][i].checked) {
7910: document.getElementById(prefix+type).style.display = 'table-row';
7911: if (count % 2 == 1) {
7912: document.getElementById(prefix+type).className = target+' LC_odd_row';
7913: } else {
7914: document.getElementById(prefix+type).className = target;
1.236 raeburn 7915: }
1.305 raeburn 7916: count ++;
1.236 raeburn 7917: } else {
1.305 raeburn 7918: document.getElementById(prefix+type).style.display = 'none';
7919: }
7920: }
7921: }
7922: }
7923: return;
7924: }
7925:
7926: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7927: var caller = radio+'_'+status;
7928: if (form.elements[caller].length != undefined) {
7929: for (var i=0; i<form.elements[caller].length; i++) {
7930: if (form.elements[caller][i].checked) {
7931: if (document.getElementById(altprefix+'_inst_'+status)) {
7932: var curr = form.elements[caller][i].value;
7933: if (prefix) {
7934: document.getElementById(prefix+'_'+status).style.display = 'none';
7935: }
7936: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7937: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7938: if (curr == 'custom') {
7939: if (prefix) {
7940: document.getElementById(prefix+'_'+status).style.display = 'inline';
7941: }
7942: } else if (curr == 'inst') {
7943: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7944: } else if (curr == 'noninst') {
7945: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7946: }
1.305 raeburn 7947: break;
1.236 raeburn 7948: }
7949: }
7950: }
7951: }
7952: }
7953:
1.305 raeburn 7954: // ]]>
7955: </script>
7956:
7957: ENDSCRIPT
7958: }
7959:
7960: sub noninst_users {
7961: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7962: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7963: my $class = 'LC_left_item';
7964: if ($css_class) {
7965: $css_class = ' class="'.$css_class.'"';
7966: }
7967: if ($rowid) {
7968: $rowid = ' id="'.$rowid.'"';
7969: }
7970: if ($rowstyle) {
7971: $rowstyle = ' style="'.$rowstyle.'"';
7972: }
7973: my ($output,$description);
7974: if ($type eq 'default') {
7975: $description = &mt('Requests for: [_1]',$typetitle);
7976: } else {
7977: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
7978: }
7979: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
7980: "<td>$description</td>\n".
7981: '<td class="'.$class.'" colspan="2">'.
7982: '<table><tr>';
7983: my %headers = &Apache::lonlocal::texthash(
7984: approve => 'Processing',
7985: email => 'E-mail',
7986: username => 'Username',
7987: );
7988: foreach my $item ('approve','email','username') {
7989: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 7990: }
1.305 raeburn 7991: $output .= '</tr><tr>';
7992: foreach my $item ('approve','email','username') {
1.306 raeburn 7993: $output .= '<td style="vertical-align: top">';
1.305 raeburn 7994: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
7995: if ($item eq 'approve') {
7996: %choices = &Apache::lonlocal::texthash (
7997: automatic => 'Automatically approved',
7998: approval => 'Queued for approval',
7999: );
8000: @options = ('automatic','approval');
8001: $hashref = $processing;
8002: $defoption = 'automatic';
8003: $name = 'cancreate_emailprocess_'.$type;
8004: } elsif ($item eq 'email') {
8005: %choices = &Apache::lonlocal::texthash (
8006: any => 'Any e-mail',
8007: inst => 'Institutional only',
8008: noninst => 'Non-institutional only',
8009: custom => 'Custom restrictions',
8010: );
8011: @options = ('any','inst','noninst');
8012: my $showcustom;
8013: if (ref($emailrules) eq 'HASH') {
8014: if (keys(%{$emailrules}) > 0) {
8015: push(@options,'custom');
8016: $showcustom = 'cancreate_emailrule';
8017: if (ref($settings) eq 'HASH') {
8018: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8019: foreach my $rule (@{$settings->{'email_rule'}}) {
8020: if (exists($emailrules->{$rule})) {
8021: $hascustom ++;
8022: }
8023: }
8024: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8025: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8026: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8027: if (exists($emailrules->{$rule})) {
8028: $hascustom ++;
8029: }
8030: }
8031: }
8032: }
8033: }
8034: }
8035: }
8036: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8037: "'cancreate_emaildomain','$type'".');"';
8038: $hashref = $emailoptions;
8039: $defoption = 'any';
8040: $name = 'cancreate_emailoptions_'.$type;
8041: } elsif ($item eq 'username') {
8042: %choices = &Apache::lonlocal::texthash (
8043: all => 'Same as e-mail',
8044: first => 'Omit @domain',
8045: free => 'Free to choose',
8046: );
8047: @options = ('all','first','free');
8048: $hashref = $emailverified;
8049: $defoption = 'all';
8050: $name = 'cancreate_usernameoptions_'.$type;
8051: }
8052: foreach my $option (@options) {
8053: my $checked;
8054: if (ref($hashref) eq 'HASH') {
8055: if ($type eq '') {
8056: if (!exists($hashref->{'default'})) {
8057: if ($option eq $defoption) {
8058: $checked = ' checked="checked"';
8059: }
8060: } else {
8061: if ($hashref->{'default'} eq $option) {
8062: $checked = ' checked="checked"';
8063: }
1.303 raeburn 8064: }
8065: } else {
1.305 raeburn 8066: if (!exists($hashref->{$type})) {
8067: if ($option eq $defoption) {
8068: $checked = ' checked="checked"';
8069: }
8070: } else {
8071: if ($hashref->{$type} eq $option) {
8072: $checked = ' checked="checked"';
8073: }
1.303 raeburn 8074: }
8075: }
1.305 raeburn 8076: } elsif (($item eq 'email') && ($hascustom)) {
8077: if ($option eq 'custom') {
8078: $checked = ' checked="checked"';
8079: }
8080: } elsif ($option eq $defoption) {
8081: $checked = ' checked="checked"';
8082: }
8083: $output .= '<span class="LC_nobreak"><label>'.
8084: '<input type="radio" name="'.$name.'"'.
8085: $checked.' value="'.$option.'"'.$onclick.' />'.
8086: $choices{$option}.'</label></span><br />';
8087: if ($item eq 'email') {
8088: if ($option eq 'custom') {
8089: my $id = 'cancreate_emailrule_'.$type;
8090: my $display = 'none';
8091: if ($checked) {
8092: $display = 'inline';
1.303 raeburn 8093: }
1.305 raeburn 8094: my $numinrow = 2;
8095: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8096: '<legend>'.&mt('Disallow').'</legend><table>'.
8097: &user_formats_row('email',$settings,$emailrules,
8098: $emailruleorder,$numinrow,'',$type);
8099: '</table></fieldset>';
8100: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8101: my %text = &Apache::lonlocal::texthash (
8102: inst => 'must end:',
8103: noninst => 'cannot end:',
8104: );
8105: my $value;
8106: if (ref($emaildomain) eq 'HASH') {
8107: if (ref($emaildomain->{$type}) eq 'HASH') {
8108: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 8109: }
8110: }
1.305 raeburn 8111: if ($value eq '') {
8112: $value = '@'.$intdom;
8113: }
8114: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8115: my $display = 'none';
8116: if ($checked) {
8117: $display = 'inline';
8118: }
8119: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8120: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8121: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8122: '</div>';
1.303 raeburn 8123: }
8124: }
8125: }
1.305 raeburn 8126: $output .= '</td>'."\n";
1.303 raeburn 8127: }
1.305 raeburn 8128: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 8129: return $output;
8130: }
8131:
1.165 raeburn 8132: sub captcha_choice {
1.305 raeburn 8133: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 8134: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8135: $vertext,$currver);
1.165 raeburn 8136: my %lt = &captcha_phrases();
8137: $keyentry = 'hidden';
1.354 raeburn 8138: my $colspan=2;
1.165 raeburn 8139: if ($context eq 'cancreate') {
1.224 raeburn 8140: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 8141: } elsif ($context eq 'login') {
8142: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 8143: } elsif ($context eq 'passwords') {
8144: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8145: $colspan=1;
1.165 raeburn 8146: }
8147: if (ref($settings) eq 'HASH') {
8148: if ($settings->{'captcha'}) {
8149: $checked{$settings->{'captcha'}} = ' checked="checked"';
8150: } else {
8151: $checked{'original'} = ' checked="checked"';
8152: }
8153: if ($settings->{'captcha'} eq 'recaptcha') {
8154: $pubtext = $lt{'pub'};
8155: $privtext = $lt{'priv'};
8156: $keyentry = 'text';
1.269 raeburn 8157: $vertext = $lt{'ver'};
8158: $currver = $settings->{'recaptchaversion'};
8159: if ($currver ne '2') {
8160: $currver = 1;
8161: }
1.165 raeburn 8162: }
8163: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8164: $currpub = $settings->{'recaptchakeys'}{'public'};
8165: $currpriv = $settings->{'recaptchakeys'}{'private'};
8166: }
8167: } else {
8168: $checked{'original'} = ' checked="checked"';
8169: }
1.305 raeburn 8170: my $css_class;
8171: if ($itemcount%2) {
8172: $css_class = 'LC_odd_row';
8173: }
8174: if ($customcss) {
8175: $css_class .= " $customcss";
8176: }
8177: $css_class =~ s/^\s+//;
8178: if ($css_class) {
8179: $css_class = ' class="'.$css_class.'"';
8180: }
8181: if ($rowstyle) {
8182: $css_class .= ' style="'.$rowstyle.'"';
8183: }
1.169 raeburn 8184: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 8185: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 8186: '<table><tr><td>'."\n";
8187: foreach my $option ('original','recaptcha','notused') {
8188: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8189: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8190: $lt{$option}.'</label></span>';
8191: unless ($option eq 'notused') {
8192: $output .= (' 'x2)."\n";
8193: }
8194: }
8195: #
8196: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8197: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 8198: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 8199: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 8200: #
1.165 raeburn 8201: $output .= '</td></tr>'."\n".
1.305 raeburn 8202: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 8203: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8204: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8205: $currpub.'" size="40" /></span><br />'."\n".
8206: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8207: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 8208: $currpriv.'" size="40" /></span><br />'.
8209: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8210: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8211: $currver.'" size="3" /></span><br />'.
8212: '</td></tr></table>'."\n".
1.165 raeburn 8213: '</td></tr>';
8214: return $output;
8215: }
8216:
1.32 raeburn 8217: sub user_formats_row {
1.305 raeburn 8218: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8219: my $output;
8220: my %text = (
8221: 'username' => 'new usernames',
8222: 'id' => 'IDs',
8223: );
1.305 raeburn 8224: unless ($type eq 'email') {
8225: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8226: $output = '<tr '.$css_class.'>'.
8227: '<td><span class="LC_nobreak">'.
8228: &mt("Format rules to check for $text{$type}: ").
8229: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8230: }
1.27 raeburn 8231: my $rem;
8232: if (ref($ruleorder) eq 'ARRAY') {
8233: for (my $i=0; $i<@{$ruleorder}; $i++) {
8234: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8235: my $rem = $i%($numinrow);
8236: if ($rem == 0) {
8237: if ($i > 0) {
8238: $output .= '</tr>';
8239: }
8240: $output .= '<tr>';
8241: }
8242: my $check = ' ';
1.39 raeburn 8243: if (ref($settings) eq 'HASH') {
8244: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8245: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8246: $check = ' checked="checked" ';
8247: }
1.305 raeburn 8248: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8249: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8250: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8251: $check = ' checked="checked" ';
8252: }
8253: }
1.27 raeburn 8254: }
8255: }
1.305 raeburn 8256: my $name = $type.'_rule';
8257: if ($type eq 'email') {
8258: $name .= '_'.$status;
8259: }
1.27 raeburn 8260: $output .= '<td class="LC_left_item">'.
8261: '<span class="LC_nobreak"><label>'.
1.311 raeburn 8262: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8263: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8264: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8265: }
8266: }
8267: $rem = @{$ruleorder}%($numinrow);
8268: }
1.305 raeburn 8269: my $colsleft;
8270: if ($rem) {
8271: $colsleft = $numinrow - $rem;
8272: }
1.27 raeburn 8273: if ($colsleft > 1 ) {
8274: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8275: ' </td>';
8276: } elsif ($colsleft == 1) {
8277: $output .= '<td class="LC_left_item"> </td>';
8278: }
1.305 raeburn 8279: $output .= '</tr></table>';
8280: unless ($type eq 'email') {
8281: $output .= '</td></tr>';
8282: }
1.27 raeburn 8283: return $output;
8284: }
8285:
1.34 raeburn 8286: sub usercreation_types {
8287: my %lt = &Apache::lonlocal::texthash (
8288: author => 'When adding a co-author',
8289: course => 'When adding a user to a course',
1.100 raeburn 8290: requestcrs => 'When requesting a course',
1.34 raeburn 8291: any => 'Any',
8292: official => 'Institutional only ',
8293: unofficial => 'Non-institutional only',
8294: none => 'None',
8295: );
8296: return %lt;
1.48 raeburn 8297: }
1.34 raeburn 8298:
1.224 raeburn 8299: sub selfcreation_types {
8300: my %lt = &Apache::lonlocal::texthash (
8301: selfcreate => 'User creates own account',
8302: any => 'Any',
8303: official => 'Institutional only ',
8304: unofficial => 'Non-institutional only',
8305: email => 'E-mail address',
8306: login => 'Institutional Login',
8307: sso => 'SSO',
8308: );
8309: }
8310:
1.28 raeburn 8311: sub authtype_names {
8312: my %lt = &Apache::lonlocal::texthash(
8313: int => 'Internal',
8314: krb4 => 'Kerberos 4',
8315: krb5 => 'Kerberos 5',
8316: loc => 'Local',
1.325 raeburn 8317: lti => 'LTI',
1.28 raeburn 8318: );
8319: return %lt;
8320: }
8321:
8322: sub context_names {
8323: my %context_title = &Apache::lonlocal::texthash(
8324: author => 'Creating users when an Author',
8325: course => 'Creating users when in a course',
8326: domain => 'Creating users when a Domain Coordinator',
8327: );
8328: return %context_title;
8329: }
8330:
1.33 raeburn 8331: sub print_usermodification {
8332: my ($position,$dom,$settings,$rowtotal) = @_;
8333: my $numinrow = 4;
8334: my ($context,$datatable,$rowcount);
8335: if ($position eq 'top') {
8336: $rowcount = 0;
8337: $context = 'author';
8338: foreach my $role ('ca','aa') {
8339: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8340: $numinrow,$rowcount);
8341: $$rowtotal ++;
8342: $rowcount ++;
8343: }
1.230 raeburn 8344: } elsif ($position eq 'bottom') {
1.33 raeburn 8345: $context = 'course';
8346: $rowcount = 0;
8347: foreach my $role ('st','ep','ta','in','cr') {
8348: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8349: $numinrow,$rowcount);
8350: $$rowtotal ++;
8351: $rowcount ++;
8352: }
8353: }
8354: return $datatable;
8355: }
8356:
1.43 raeburn 8357: sub print_defaults {
1.236 raeburn 8358: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8359: my $rownum = 0;
1.294 raeburn 8360: my ($datatable,$css_class,$titles);
8361: unless ($position eq 'bottom') {
8362: $titles = &defaults_titles($dom);
8363: }
1.236 raeburn 8364: if ($position eq 'top') {
8365: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8366: 'datelocale_def','portal_def');
8367: my %defaults;
8368: if (ref($settings) eq 'HASH') {
8369: %defaults = %{$settings};
1.43 raeburn 8370: } else {
1.236 raeburn 8371: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8372: foreach my $item (@items) {
8373: $defaults{$item} = $domdefaults{$item};
8374: }
1.43 raeburn 8375: }
1.236 raeburn 8376: foreach my $item (@items) {
8377: if ($rownum%2) {
8378: $css_class = '';
8379: } else {
8380: $css_class = ' class="LC_odd_row" ';
8381: }
8382: $datatable .= '<tr'.$css_class.'>'.
8383: '<td><span class="LC_nobreak">'.$titles->{$item}.
8384: '</span></td><td class="LC_right_item" colspan="3">';
8385: if ($item eq 'auth_def') {
1.325 raeburn 8386: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 8387: my %shortauth = (
8388: internal => 'int',
8389: krb4 => 'krb4',
8390: krb5 => 'krb5',
1.325 raeburn 8391: localauth => 'loc',
8392: lti => 'lti',
1.236 raeburn 8393: );
8394: my %authnames = &authtype_names();
8395: foreach my $auth (@authtypes) {
8396: my $checked = ' ';
8397: if ($defaults{$item} eq $auth) {
8398: $checked = ' checked="checked" ';
8399: }
8400: $datatable .= '<label><input type="radio" name="'.$item.
8401: '" value="'.$auth.'"'.$checked.'/>'.
8402: $authnames{$shortauth{$auth}}.'</label> ';
8403: }
8404: } elsif ($item eq 'timezone_def') {
8405: my $includeempty = 1;
8406: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8407: } elsif ($item eq 'datelocale_def') {
8408: my $includeempty = 1;
8409: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8410: } elsif ($item eq 'lang_def') {
1.263 raeburn 8411: my $includeempty = 1;
8412: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 8413: } else {
8414: my $size;
8415: if ($item eq 'portal_def') {
8416: $size = ' size="25"';
8417: }
8418: $datatable .= '<input type="text" name="'.$item.'" value="'.
8419: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 8420: }
1.236 raeburn 8421: $datatable .= '</td></tr>';
8422: $rownum ++;
8423: }
1.354 raeburn 8424: } else {
1.294 raeburn 8425: my %defaults;
8426: if (ref($settings) eq 'HASH') {
1.354 raeburn 8427: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8428: my $maxnum = @{$settings->{'inststatusorder'}};
8429: for (my $i=0; $i<$maxnum; $i++) {
8430: $css_class = $rownum%2?' class="LC_odd_row"':'';
8431: my $item = $settings->{'inststatusorder'}->[$i];
8432: my $title = $settings->{'inststatustypes'}->{$item};
8433: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8434: $datatable .= '<tr'.$css_class.'>'.
8435: '<td><span class="LC_nobreak">'.
8436: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8437: for (my $k=0; $k<=$maxnum; $k++) {
8438: my $vpos = $k+1;
8439: my $selstr;
8440: if ($k == $i) {
8441: $selstr = ' selected="selected" ';
8442: }
8443: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8444: }
8445: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8446: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8447: &mt('delete').'</span></td>'.
8448: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
8449: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8450: '</span></td></tr>';
8451: }
8452: $css_class = $rownum%2?' class="LC_odd_row"':'';
8453: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8454: $datatable .= '<tr '.$css_class.'>'.
8455: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8456: for (my $k=0; $k<=$maxnum; $k++) {
8457: my $vpos = $k+1;
8458: my $selstr;
8459: if ($k == $maxnum) {
8460: $selstr = ' selected="selected" ';
8461: }
8462: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8463: }
8464: $datatable .= '</select> '.&mt('Internal ID:').
8465: '<input type="text" size="10" name="addinststatus" value="" />'.
8466: ' '.&mt('(new)').
8467: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
8468: &mt('Name displayed:').
8469: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8470: '</tr>'."\n";
8471: $rownum ++;
1.294 raeburn 8472: }
1.354 raeburn 8473: }
8474: }
8475: $$rowtotal += $rownum;
1.43 raeburn 8476: return $datatable;
8477: }
8478:
1.168 raeburn 8479: sub get_languages_hash {
8480: my %langchoices;
8481: foreach my $id (&Apache::loncommon::languageids()) {
8482: my $code = &Apache::loncommon::supportedlanguagecode($id);
8483: if ($code ne '') {
8484: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8485: }
8486: }
8487: return %langchoices;
8488: }
8489:
1.43 raeburn 8490: sub defaults_titles {
1.141 raeburn 8491: my ($dom) = @_;
1.43 raeburn 8492: my %titles = &Apache::lonlocal::texthash (
8493: 'auth_def' => 'Default authentication type',
8494: 'auth_arg_def' => 'Default authentication argument',
8495: 'lang_def' => 'Default language',
1.54 raeburn 8496: 'timezone_def' => 'Default timezone',
1.68 raeburn 8497: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8498: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 8499: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8500: 'intauth_check' => 'Check bcrypt cost if authenticated',
8501: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8502: );
1.141 raeburn 8503: if ($dom) {
8504: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8505: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8506: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8507: $protocol = 'http' if ($protocol ne 'https');
8508: if ($uint_dom) {
8509: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8510: $uint_dom);
8511: }
8512: }
1.43 raeburn 8513: return (\%titles);
8514: }
8515:
1.346 raeburn 8516: sub print_scantron {
8517: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8518: if ($position eq 'top') {
8519: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8520: } else {
8521: return &print_scantronconfig($dom,$settings,\$rowtotal);
8522: }
8523: }
8524:
8525: sub scantron_javascript {
8526: return <<"ENDSCRIPT";
8527:
8528: <script type="text/javascript">
8529: // <![CDATA[
8530:
8531: function toggleScantron(form) {
1.347 raeburn 8532: var csvfieldset = new Array();
1.346 raeburn 8533: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8534: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8535: }
8536: if (document.getElementById('scantroncsv_options')) {
8537: csvfieldset.push(document.getElementById('scantroncsv_options'));
8538: }
8539: if (csvfieldset.length) {
1.346 raeburn 8540: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8541: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8542: if (scantroncsv.checked) {
1.347 raeburn 8543: for (var i=0; i<csvfieldset.length; i++) {
8544: csvfieldset[i].style.display = 'block';
8545: }
1.346 raeburn 8546: } else {
1.347 raeburn 8547: for (var i=0; i<csvfieldset.length; i++) {
8548: csvfieldset[i].style.display = 'none';
8549: }
1.346 raeburn 8550: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8551: if (csvselects.length) {
8552: for (var j=0; j<csvselects.length; j++) {
8553: csvselects[j].selectedIndex = 0;
8554: }
8555: }
8556: }
8557: }
8558: }
8559: return;
8560: }
8561: // ]]>
8562: </script>
8563:
8564: ENDSCRIPT
8565:
8566: }
8567:
1.46 raeburn 8568: sub print_scantronformat {
8569: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8570: my $itemcount = 1;
1.60 raeburn 8571: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8572: %confhash);
1.46 raeburn 8573: my $switchserver = &check_switchserver($dom,$confname);
8574: my %lt = &Apache::lonlocal::texthash (
1.95 www 8575: default => 'Default bubblesheet format file error',
8576: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8577: );
8578: my %scantronfiles = (
8579: default => 'default.tab',
8580: custom => 'custom.tab',
8581: );
8582: foreach my $key (keys(%scantronfiles)) {
8583: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8584: .$scantronfiles{$key};
8585: }
8586: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8587: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8588: if (!$switchserver) {
8589: my $servadm = $r->dir_config('lonAdmEMail');
8590: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8591: if ($configuserok eq 'ok') {
8592: if ($author_ok eq 'ok') {
8593: my %legacyfile = (
1.346 raeburn 8594: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8595: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8596: );
8597: my %md5chk;
8598: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8599: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8600: chomp($md5chk{$type});
1.46 raeburn 8601: }
8602: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8603: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8604: ($scantronurls{$type},my $error) =
1.46 raeburn 8605: &legacy_scantronformat($r,$dom,$confname,
8606: $type,$legacyfile{$type},
8607: $scantronurls{$type},
8608: $scantronfiles{$type});
1.60 raeburn 8609: if ($error ne '') {
8610: $error{$type} = $error;
8611: }
8612: }
8613: if (keys(%error) == 0) {
8614: $is_custom = 1;
1.346 raeburn 8615: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8616: $scantronurls{'custom'};
1.346 raeburn 8617: my $putresult =
1.60 raeburn 8618: &Apache::lonnet::put_dom('configuration',
8619: \%confhash,$dom);
8620: if ($putresult ne 'ok') {
1.346 raeburn 8621: $error{'custom'} =
1.60 raeburn 8622: '<span class="LC_error">'.
8623: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8624: }
1.46 raeburn 8625: }
8626: } else {
1.60 raeburn 8627: ($scantronurls{'default'},my $error) =
1.46 raeburn 8628: &legacy_scantronformat($r,$dom,$confname,
8629: 'default',$legacyfile{'default'},
8630: $scantronurls{'default'},
8631: $scantronfiles{'default'});
1.60 raeburn 8632: if ($error eq '') {
8633: $confhash{'scantron'}{'scantronformat'} = '';
8634: my $putresult =
8635: &Apache::lonnet::put_dom('configuration',
8636: \%confhash,$dom);
8637: if ($putresult ne 'ok') {
8638: $error{'default'} =
8639: '<span class="LC_error">'.
8640: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8641: }
8642: } else {
8643: $error{'default'} = $error;
8644: }
1.46 raeburn 8645: }
8646: }
8647: }
8648: } else {
1.95 www 8649: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8650: }
8651: }
8652: if (ref($settings) eq 'HASH') {
8653: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8654: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8655: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8656: $scantronurl = '';
8657: } else {
8658: $scantronurl = $settings->{'scantronformat'};
8659: }
8660: $is_custom = 1;
8661: } else {
8662: $scantronurl = $scantronurls{'default'};
8663: }
8664: } else {
1.60 raeburn 8665: if ($is_custom) {
8666: $scantronurl = $scantronurls{'custom'};
8667: } else {
8668: $scantronurl = $scantronurls{'default'};
8669: }
1.46 raeburn 8670: }
8671: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8672: $datatable .= '<tr'.$css_class.'>';
8673: if (!$is_custom) {
1.65 raeburn 8674: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8675: '<span class="LC_nobreak">';
1.46 raeburn 8676: if ($scantronurl) {
1.199 raeburn 8677: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8678: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8679: } else {
8680: $datatable = &mt('File unavailable for display');
8681: }
1.65 raeburn 8682: $datatable .= '</span></td>';
1.60 raeburn 8683: if (keys(%error) == 0) {
1.306 raeburn 8684: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8685: if (!$switchserver) {
8686: $datatable .= &mt('Upload:').'<br />';
8687: }
8688: } else {
8689: my $errorstr;
8690: foreach my $key (sort(keys(%error))) {
8691: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8692: }
8693: $datatable .= '<td>'.$errorstr;
8694: }
1.46 raeburn 8695: } else {
8696: if (keys(%error) > 0) {
8697: my $errorstr;
8698: foreach my $key (sort(keys(%error))) {
8699: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8700: }
1.60 raeburn 8701: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8702: } elsif ($scantronurl) {
1.199 raeburn 8703: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8704: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8705: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8706: $link.
8707: '<label><input type="checkbox" name="scantronformat_del"'.
8708: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8709: '<td><span class="LC_nobreak"> '.
8710: &mt('Replace:').'</span><br />';
1.46 raeburn 8711: }
8712: }
8713: if (keys(%error) == 0) {
8714: if ($switchserver) {
8715: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8716: } else {
1.65 raeburn 8717: $datatable .='<span class="LC_nobreak"> '.
8718: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8719: }
8720: }
8721: $datatable .= '</td></tr>';
8722: $$rowtotal ++;
8723: return $datatable;
8724: }
8725:
8726: sub legacy_scantronformat {
8727: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8728: my ($url,$error);
8729: my @statinfo = &Apache::lonnet::stat_file($newurl);
8730: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8731: (my $result,$url) =
8732: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8733: '','',$newfile);
8734: if ($result ne 'ok') {
1.130 raeburn 8735: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8736: }
8737: }
8738: return ($url,$error);
8739: }
1.43 raeburn 8740:
1.346 raeburn 8741: sub print_scantronconfig {
8742: my ($dom,$settings,$rowtotal) = @_;
8743: my $itemcount = 2;
8744: my $is_checked = ' checked="checked"';
1.347 raeburn 8745: my %optionson = (
8746: hdr => ' checked="checked"',
8747: pad => ' checked="checked"',
8748: rem => ' checked="checked"',
8749: );
8750: my %optionsoff = (
8751: hdr => '',
8752: pad => '',
8753: rem => '',
8754: );
1.346 raeburn 8755: my $currcsvsty = 'none';
1.347 raeburn 8756: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8757: my @fields = &scantroncsv_fields();
8758: my %titles = &scantronconfig_titles();
8759: if (ref($settings) eq 'HASH') {
8760: if (ref($settings->{config}) eq 'HASH') {
8761: if ($settings->{config}->{dat}) {
8762: $checked{'dat'} = $is_checked;
8763: }
8764: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8765: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8766: %csvfields = %{$settings->{config}->{csv}->{fields}};
8767: if (keys(%csvfields) > 0) {
8768: $checked{'csv'} = $is_checked;
8769: $currcsvsty = 'block';
8770: }
8771: }
8772: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8773: %csvoptions = %{$settings->{config}->{csv}->{options}};
8774: foreach my $option (keys(%optionson)) {
8775: unless ($csvoptions{$option}) {
8776: $optionsoff{$option} = $optionson{$option};
8777: $optionson{$option} = '';
8778: }
8779: }
1.346 raeburn 8780: }
8781: }
8782: } else {
8783: $checked{'dat'} = $is_checked;
8784: }
8785: } else {
8786: $checked{'dat'} = $is_checked;
8787: }
8788: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8789: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8790: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8791: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8792: foreach my $item ('dat','csv') {
8793: my $id;
8794: if ($item eq 'csv') {
8795: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8796: }
1.346 raeburn 8797: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8798: $titles{$item}.'</label>'.(' 'x3);
8799: if ($item eq 'csv') {
8800: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8801: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8802: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8803: foreach my $col (@fields) {
8804: my $selnone;
8805: if ($csvfields{$col} eq '') {
8806: $selnone = ' selected="selected"';
8807: }
8808: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8809: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8810: '<option value=""'.$selnone.'></option>';
8811: for (my $i=0; $i<20; $i++) {
8812: my $shown = $i+1;
8813: my $sel;
8814: unless ($selnone) {
8815: if (exists($csvfields{$col})) {
8816: if ($csvfields{$col} == $i) {
8817: $sel = ' selected="selected"';
8818: }
8819: }
8820: }
8821: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8822: }
8823: $datatable .= '</select></td></tr>';
8824: }
1.347 raeburn 8825: $datatable .= '</table></fieldset>'.
8826: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8827: '<legend>'.&mt('CSV Options').'</legend>';
8828: foreach my $option ('hdr','pad','rem') {
8829: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8830: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8831: &mt('Yes').'</label>'.(' 'x2)."\n".
8832: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8833: }
8834: $datatable .= '</fieldset>';
1.346 raeburn 8835: $itemcount ++;
8836: }
8837: }
8838: $datatable .= '</td></tr>';
8839: $$rowtotal ++;
8840: return $datatable;
8841: }
8842:
8843: sub scantronconfig_titles {
8844: return &Apache::lonlocal::texthash(
8845: dat => 'Standard format (.dat)',
8846: csv => 'Comma separated values (.csv)',
1.347 raeburn 8847: hdr => 'Remove first line in file (contains column titles)',
8848: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8849: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8850: CODE => 'CODE',
8851: ID => 'Student ID',
8852: PaperID => 'Paper ID',
8853: FirstName => 'First Name',
8854: LastName => 'Last Name',
8855: FirstQuestion => 'First Question Response',
8856: Section => 'Section',
8857: );
8858: }
8859:
8860: sub scantroncsv_fields {
8861: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8862: }
8863:
1.49 raeburn 8864: sub print_coursecategories {
1.57 raeburn 8865: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8866: my $datatable;
8867: if ($position eq 'top') {
1.238 raeburn 8868: my (%checked);
8869: my @catitems = ('unauth','auth');
8870: my @cattypes = ('std','domonly','codesrch','none');
8871: $checked{'unauth'} = 'std';
8872: $checked{'auth'} = 'std';
8873: if (ref($settings) eq 'HASH') {
8874: foreach my $type (@cattypes) {
8875: if ($type eq $settings->{'unauth'}) {
8876: $checked{'unauth'} = $type;
8877: }
8878: if ($type eq $settings->{'auth'}) {
8879: $checked{'auth'} = $type;
8880: }
8881: }
8882: }
8883: my %lt = &Apache::lonlocal::texthash (
8884: unauth => 'Catalog type for unauthenticated users',
8885: auth => 'Catalog type for authenticated users',
8886: none => 'No catalog',
8887: std => 'Standard catalog',
8888: domonly => 'Domain-only catalog',
8889: codesrch => "Code search form",
8890: );
8891: my $itemcount = 0;
8892: foreach my $item (@catitems) {
8893: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8894: $datatable .= '<tr '.$css_class.'>'.
8895: '<td>'.$lt{$item}.'</td>'.
8896: '<td class="LC_right_item"><span class="LC_nobreak">';
8897: foreach my $type (@cattypes) {
8898: my $ischecked;
8899: if ($checked{$item} eq $type) {
8900: $ischecked=' checked="checked"';
8901: }
8902: $datatable .= '<label>'.
8903: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8904: ' />'.$lt{$type}.'</label> ';
8905: }
1.327 raeburn 8906: $datatable .= '</span></td></tr>';
1.238 raeburn 8907: $itemcount ++;
8908: }
8909: $$rowtotal += $itemcount;
8910: } elsif ($position eq 'middle') {
1.57 raeburn 8911: my $toggle_cats_crs = ' ';
8912: my $toggle_cats_dom = ' checked="checked" ';
8913: my $can_cat_crs = ' ';
8914: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8915: my $toggle_catscomm_comm = ' ';
8916: my $toggle_catscomm_dom = ' checked="checked" ';
8917: my $can_catcomm_comm = ' ';
8918: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8919: my $toggle_catsplace_place = ' ';
8920: my $toggle_catsplace_dom = ' checked="checked" ';
8921: my $can_catplace_place = ' ';
8922: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8923:
1.57 raeburn 8924: if (ref($settings) eq 'HASH') {
8925: if ($settings->{'togglecats'} eq 'crs') {
8926: $toggle_cats_crs = $toggle_cats_dom;
8927: $toggle_cats_dom = ' ';
8928: }
8929: if ($settings->{'categorize'} eq 'crs') {
8930: $can_cat_crs = $can_cat_dom;
8931: $can_cat_dom = ' ';
8932: }
1.120 raeburn 8933: if ($settings->{'togglecatscomm'} eq 'comm') {
8934: $toggle_catscomm_comm = $toggle_catscomm_dom;
8935: $toggle_catscomm_dom = ' ';
8936: }
8937: if ($settings->{'categorizecomm'} eq 'comm') {
8938: $can_catcomm_comm = $can_catcomm_dom;
8939: $can_catcomm_dom = ' ';
8940: }
1.272 raeburn 8941: if ($settings->{'togglecatsplace'} eq 'place') {
8942: $toggle_catsplace_place = $toggle_catsplace_dom;
8943: $toggle_catsplace_dom = ' ';
8944: }
8945: if ($settings->{'categorizeplace'} eq 'place') {
8946: $can_catplace_place = $can_catplace_dom;
8947: $can_catplace_dom = ' ';
8948: }
1.57 raeburn 8949: }
8950: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8951: togglecats => 'Show/Hide a course in catalog',
8952: togglecatscomm => 'Show/Hide a community in catalog',
8953: togglecatsplace => 'Show/Hide a placement test in catalog',
8954: categorize => 'Assign a category to a course',
8955: categorizecomm => 'Assign a category to a community',
8956: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8957: );
8958: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8959: dom => 'Set in Domain',
8960: crs => 'Set in Course',
8961: comm => 'Set in Community',
8962: place => 'Set in Placement Test',
1.57 raeburn 8963: );
8964: $datatable = '<tr class="LC_odd_row">'.
8965: '<td>'.$title{'togglecats'}.'</td>'.
8966: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8967: '<input type="radio" name="togglecats"'.
8968: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8969: '<label><input type="radio" name="togglecats"'.
8970: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8971: '</tr><tr>'.
8972: '<td>'.$title{'categorize'}.'</td>'.
8973: '<td class="LC_right_item"><span class="LC_nobreak">'.
8974: '<label><input type="radio" name="categorize"'.
8975: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8976: '<label><input type="radio" name="categorize"'.
8977: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 8978: '</tr><tr class="LC_odd_row">'.
8979: '<td>'.$title{'togglecatscomm'}.'</td>'.
8980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8981: '<input type="radio" name="togglecatscomm"'.
8982: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8983: '<label><input type="radio" name="togglecatscomm"'.
8984: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
8985: '</tr><tr>'.
8986: '<td>'.$title{'categorizecomm'}.'</td>'.
8987: '<td class="LC_right_item"><span class="LC_nobreak">'.
8988: '<label><input type="radio" name="categorizecomm"'.
8989: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8990: '<label><input type="radio" name="categorizecomm"'.
8991: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 8992: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 8993: '<td>'.$title{'togglecatsplace'}.'</td>'.
8994: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8995: '<input type="radio" name="togglecatsplace"'.
8996: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8997: '<label><input type="radio" name="togglecatscomm"'.
8998: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
8999: '</tr><tr>'.
9000: '<td>'.$title{'categorizeplace'}.'</td>'.
9001: '<td class="LC_right_item"><span class="LC_nobreak">'.
9002: '<label><input type="radio" name="categorizeplace"'.
9003: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9004: '<label><input type="radio" name="categorizeplace"'.
9005: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 9006: '</tr>';
1.272 raeburn 9007: $$rowtotal += 6;
1.57 raeburn 9008: } else {
9009: my $css_class;
9010: my $itemcount = 1;
9011: my $cathash;
9012: if (ref($settings) eq 'HASH') {
9013: $cathash = $settings->{'cats'};
9014: }
9015: if (ref($cathash) eq 'HASH') {
9016: my (@cats,@trails,%allitems,%idx,@jsarray);
9017: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9018: \%allitems,\%idx,\@jsarray);
9019: my $maxdepth = scalar(@cats);
9020: my $colattrib = '';
9021: if ($maxdepth > 2) {
9022: $colattrib = ' colspan="2" ';
9023: }
9024: my @path;
9025: if (@cats > 0) {
9026: if (ref($cats[0]) eq 'ARRAY') {
9027: my $numtop = @{$cats[0]};
9028: my $maxnum = $numtop;
1.120 raeburn 9029: my %default_names = (
9030: instcode => &mt('Official courses'),
9031: communities => &mt('Communities'),
1.272 raeburn 9032: placement => &mt('Placement Tests'),
1.120 raeburn 9033: );
9034:
9035: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9036: ($cathash->{'instcode::0'} eq '') ||
9037: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9038: ($cathash->{'communities::0'} eq '') ||
9039: (!grep(/^placement$/,@{$cats[0]})) ||
9040: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9041: $maxnum ++;
9042: }
9043: my $lastidx;
9044: for (my $i=0; $i<$numtop; $i++) {
9045: my $parent = $cats[0][$i];
9046: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9047: my $item = &escape($parent).'::0';
9048: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9049: $lastidx = $idx{$item};
9050: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9051: .'<select name="'.$item.'"'.$chgstr.'>';
9052: for (my $k=0; $k<=$maxnum; $k++) {
9053: my $vpos = $k+1;
9054: my $selstr;
9055: if ($k == $i) {
9056: $selstr = ' selected="selected" ';
9057: }
9058: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9059: }
1.214 raeburn 9060: $datatable .= '</select></span></td><td>';
1.272 raeburn 9061: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 9062: $datatable .= '<span class="LC_nobreak">'
9063: .$default_names{$parent}.'</span>';
9064: if ($parent eq 'instcode') {
9065: $datatable .= '<br /><span class="LC_nobreak">('
9066: .&mt('with institutional codes')
9067: .')</span></td><td'.$colattrib.'>';
9068: } else {
9069: $datatable .= '<table><tr><td>';
9070: }
9071: $datatable .= '<span class="LC_nobreak">'
9072: .'<label><input type="radio" name="'
9073: .$parent.'" value="1" checked="checked" />'
9074: .&mt('Display').'</label>';
9075: if ($parent eq 'instcode') {
9076: $datatable .= ' ';
9077: } else {
9078: $datatable .= '</span></td></tr><tr><td>'
9079: .'<span class="LC_nobreak">';
9080: }
9081: $datatable .= '<label><input type="radio" name="'
9082: .$parent.'" value="0" />'
9083: .&mt('Do not display').'</label></span>';
1.272 raeburn 9084: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 9085: $datatable .= '</td></tr></table>';
9086: }
9087: $datatable .= '</td>';
1.57 raeburn 9088: } else {
9089: $datatable .= $parent
1.214 raeburn 9090: .' <span class="LC_nobreak"><label>'
9091: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9092: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9093: }
9094: my $depth = 1;
9095: push(@path,$parent);
9096: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9097: pop(@path);
9098: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9099: $itemcount ++;
9100: }
1.48 raeburn 9101: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9102: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9103: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9104: for (my $k=0; $k<=$maxnum; $k++) {
9105: my $vpos = $k+1;
9106: my $selstr;
1.57 raeburn 9107: if ($k == $numtop) {
1.48 raeburn 9108: $selstr = ' selected="selected" ';
9109: }
9110: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9111: }
1.59 bisitz 9112: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9113: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9114: .'</tr>'."\n";
1.48 raeburn 9115: $itemcount ++;
1.272 raeburn 9116: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9117: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9118: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9119: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9120: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9121: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9122: for (my $k=0; $k<=$maxnum; $k++) {
9123: my $vpos = $k+1;
9124: my $selstr;
9125: if ($k == $maxnum) {
9126: $selstr = ' selected="selected" ';
9127: }
9128: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9129: }
1.120 raeburn 9130: $datatable .= '</select></span></td>'.
9131: '<td><span class="LC_nobreak">'.
9132: $default_names{$default}.'</span>';
9133: if ($default eq 'instcode') {
9134: $datatable .= '<br /><span class="LC_nobreak">('
9135: .&mt('with institutional codes').')</span>';
9136: }
9137: $datatable .= '</td>'
9138: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9139: .&mt('Display').'</label> '
9140: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9141: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9142: }
9143: }
9144: }
1.57 raeburn 9145: } else {
9146: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9147: }
9148: } else {
1.327 raeburn 9149: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9150: .&initialize_categories($itemcount);
1.48 raeburn 9151: }
1.57 raeburn 9152: $$rowtotal += $itemcount;
1.48 raeburn 9153: }
9154: return $datatable;
9155: }
9156:
1.69 raeburn 9157: sub print_serverstatuses {
9158: my ($dom,$settings,$rowtotal) = @_;
9159: my $datatable;
9160: my @pages = &serverstatus_pages();
9161: my (%namedaccess,%machineaccess);
9162: foreach my $type (@pages) {
9163: $namedaccess{$type} = '';
9164: $machineaccess{$type}= '';
9165: }
9166: if (ref($settings) eq 'HASH') {
9167: foreach my $type (@pages) {
9168: if (exists($settings->{$type})) {
9169: if (ref($settings->{$type}) eq 'HASH') {
9170: foreach my $key (keys(%{$settings->{$type}})) {
9171: if ($key eq 'namedusers') {
9172: $namedaccess{$type} = $settings->{$type}->{$key};
9173: } elsif ($key eq 'machines') {
9174: $machineaccess{$type} = $settings->{$type}->{$key};
9175: }
9176: }
9177: }
9178: }
9179: }
9180: }
1.81 raeburn 9181: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9182: my $rownum = 0;
9183: my $css_class;
9184: foreach my $type (@pages) {
9185: $rownum ++;
9186: $css_class = $rownum%2?' class="LC_odd_row"':'';
9187: $datatable .= '<tr'.$css_class.'>'.
9188: '<td><span class="LC_nobreak">'.
9189: $titles->{$type}.'</span></td>'.
9190: '<td class="LC_left_item">'.
9191: '<input type="text" name="'.$type.'_namedusers" '.
9192: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9193: '<td class="LC_right_item">'.
9194: '<span class="LC_nobreak">'.
9195: '<input type="text" name="'.$type.'_machines" '.
9196: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 9197: '</span></td></tr>'."\n";
1.69 raeburn 9198: }
9199: $$rowtotal += $rownum;
9200: return $datatable;
9201: }
9202:
9203: sub serverstatus_pages {
9204: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 9205: 'checksums','clusterstatus','certstatus','metadata_keywords',
9206: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
9207: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9208: }
9209:
1.236 raeburn 9210: sub defaults_javascript {
9211: my ($settings) = @_;
1.354 raeburn 9212: return unless (ref($settings) eq 'HASH');
1.236 raeburn 9213: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9214: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9215: if ($maxnum eq '') {
9216: $maxnum = 0;
9217: }
9218: $maxnum ++;
1.249 raeburn 9219: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 9220: return <<"ENDSCRIPT";
9221: <script type="text/javascript">
9222: // <![CDATA[
9223: function reorderTypes(form,caller) {
9224: var changedVal;
9225: $jstext
9226: var newpos = 'addinststatus_pos';
9227: var current = new Array;
9228: var maxh = $maxnum;
9229: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9230: var oldVal;
9231: if (caller == newpos) {
9232: changedVal = newitemVal;
9233: } else {
9234: var curritem = 'inststatus_pos_'+caller;
9235: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9236: current[newitemVal] = newpos;
9237: }
9238: for (var i=0; i<inststatuses.length; i++) {
9239: if (inststatuses[i] != caller) {
9240: var elementName = 'inststatus_pos_'+inststatuses[i];
9241: if (form.elements[elementName]) {
9242: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9243: current[currVal] = elementName;
9244: }
9245: }
9246: }
9247: for (var j=0; j<maxh; j++) {
9248: if (current[j] == undefined) {
9249: oldVal = j;
9250: }
9251: }
9252: if (oldVal < changedVal) {
9253: for (var k=oldVal+1; k<=changedVal ; k++) {
9254: var elementName = current[k];
9255: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9256: }
9257: } else {
9258: for (var k=changedVal; k<oldVal; k++) {
9259: var elementName = current[k];
9260: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9261: }
9262: }
9263: return;
9264: }
9265:
9266: // ]]>
9267: </script>
9268:
9269: ENDSCRIPT
9270: }
1.354 raeburn 9271: return;
9272: }
9273:
9274: sub passwords_javascript {
9275: 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.');
9276: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
9277: &js_escape(\$intauthcheck);
9278: &js_escape(\$intauthcost);
9279: my $intauthjs = <<"ENDSCRIPT";
9280:
9281: function warnIntAuth(field) {
9282: if (field.name == 'intauth_check') {
9283: if (field.value == '2') {
9284: alert('$intauthcheck');
9285: }
9286: }
9287: if (field.name == 'intauth_cost') {
9288: field.value.replace(/\s/g,'');
9289: if (field.value != '') {
9290: var regexdigit=/^\\d+\$/;
9291: if (!regexdigit.test(field.value)) {
9292: alert('$intauthcost');
9293: }
9294: }
9295: }
9296: return;
9297: }
9298:
9299: ENDSCRIPT
9300: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 9301: }
9302:
1.49 raeburn 9303: sub coursecategories_javascript {
9304: my ($settings) = @_;
1.57 raeburn 9305: my ($output,$jstext,$cathash);
1.49 raeburn 9306: if (ref($settings) eq 'HASH') {
1.57 raeburn 9307: $cathash = $settings->{'cats'};
9308: }
9309: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9310: my (@cats,@jsarray,%idx);
1.57 raeburn 9311: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9312: if (@jsarray > 0) {
9313: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9314: for (my $i=0; $i<@jsarray; $i++) {
9315: if (ref($jsarray[$i]) eq 'ARRAY') {
9316: my $catstr = join('","',@{$jsarray[$i]});
9317: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9318: }
9319: }
9320: }
9321: } else {
9322: $jstext = ' var categories = Array(1);'."\n".
9323: ' categories[0] = Array("instcode_pos");'."\n";
9324: }
1.237 bisitz 9325: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9326: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 9327: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 9328: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9329: &js_escape(\$instcode_reserved);
9330: &js_escape(\$communities_reserved);
1.272 raeburn 9331: &js_escape(\$placement_reserved);
1.265 damieng 9332: &js_escape(\$choose_again);
1.49 raeburn 9333: $output = <<"ENDSCRIPT";
9334: <script type="text/javascript">
1.109 raeburn 9335: // <![CDATA[
1.49 raeburn 9336: function reorderCats(form,parent,item,idx) {
9337: var changedVal;
9338: $jstext
9339: var newpos = 'addcategory_pos';
9340: if (parent == '') {
9341: var has_instcode = 0;
9342: var maxtop = categories[idx].length;
9343: for (var j=0; j<maxtop; j++) {
9344: if (categories[idx][j] == 'instcode::0') {
9345: has_instcode == 1;
9346: }
9347: }
9348: if (has_instcode == 0) {
9349: categories[idx][maxtop] = 'instcode_pos';
9350: }
9351: } else {
9352: newpos += '_'+parent;
9353: }
9354: var maxh = 1 + categories[idx].length;
9355: var current = new Array;
9356: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9357: if (item == newpos) {
9358: changedVal = newitemVal;
9359: } else {
9360: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9361: current[newitemVal] = newpos;
9362: }
9363: for (var i=0; i<categories[idx].length; i++) {
9364: var elementName = categories[idx][i];
9365: if (elementName != item) {
9366: if (form.elements[elementName]) {
9367: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9368: current[currVal] = elementName;
9369: }
9370: }
9371: }
9372: var oldVal;
9373: for (var j=0; j<maxh; j++) {
9374: if (current[j] == undefined) {
9375: oldVal = j;
9376: }
9377: }
9378: if (oldVal < changedVal) {
9379: for (var k=oldVal+1; k<=changedVal ; k++) {
9380: var elementName = current[k];
9381: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9382: }
9383: } else {
9384: for (var k=changedVal; k<oldVal; k++) {
9385: var elementName = current[k];
9386: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9387: }
9388: }
9389: return;
9390: }
1.120 raeburn 9391:
9392: function categoryCheck(form) {
9393: if (form.elements['addcategory_name'].value == 'instcode') {
9394: alert('$instcode_reserved\\n$choose_again');
9395: return false;
9396: }
9397: if (form.elements['addcategory_name'].value == 'communities') {
9398: alert('$communities_reserved\\n$choose_again');
9399: return false;
9400: }
1.272 raeburn 9401: if (form.elements['addcategory_name'].value == 'placement') {
9402: alert('$placement_reserved\\n$choose_again');
9403: return false;
9404: }
1.120 raeburn 9405: return true;
9406: }
9407:
1.109 raeburn 9408: // ]]>
1.49 raeburn 9409: </script>
9410:
9411: ENDSCRIPT
9412: return $output;
9413: }
9414:
1.48 raeburn 9415: sub initialize_categories {
9416: my ($itemcount) = @_;
1.120 raeburn 9417: my ($datatable,$css_class,$chgstr);
9418: my %default_names = (
9419: instcode => 'Official courses (with institutional codes)',
9420: communities => 'Communities',
1.272 raeburn 9421: placement => 'Placement Tests',
1.120 raeburn 9422: );
1.328 raeburn 9423: my %selnum = (
9424: instcode => '0',
9425: communities => '1',
9426: placement => '2',
9427: );
9428: my %selected;
1.272 raeburn 9429: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 9431: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 9432: map { $selected{$selnum{$_}} = '' } keys(%selnum);
9433: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 9434: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 9435: .'<select name="'.$default.'_pos"'.$chgstr.'>'
9436: .'<option value="0"'.$selected{'0'}.'>1</option>'
9437: .'<option value="1"'.$selected{'1'}.'>2</option>'
9438: .'<option value="2"'.$selected{'2'}.'>3</option>'
9439: .'<option value="3">4</option></select> '
1.120 raeburn 9440: .$default_names{$default}
9441: .'</span></td><td><span class="LC_nobreak">'
9442: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9443: .&mt('Display').'</label> <label>'
9444: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9445: .'</label></span></td></tr>';
1.120 raeburn 9446: $itemcount ++;
9447: }
1.48 raeburn 9448: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9449: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9450: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9451: .'<select name="addcategory_pos"'.$chgstr.'>'
9452: .'<option value="0">1</option>'
9453: .'<option value="1">2</option>'
1.328 raeburn 9454: .'<option value="2">3</option>'
9455: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 9456: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9457: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9458: .'</td></tr>';
1.48 raeburn 9459: return $datatable;
9460: }
9461:
9462: sub build_category_rows {
1.49 raeburn 9463: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9464: my ($text,$name,$item,$chgstr);
1.48 raeburn 9465: if (ref($cats) eq 'ARRAY') {
9466: my $maxdepth = scalar(@{$cats});
9467: if (ref($cats->[$depth]) eq 'HASH') {
9468: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9469: my $numchildren = @{$cats->[$depth]{$parent}};
9470: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 9471: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9472: my ($idxnum,$parent_name,$parent_item);
9473: my $higher = $depth - 1;
9474: if ($higher == 0) {
9475: $parent_name = &escape($parent).'::'.$higher;
9476: } else {
9477: if (ref($path) eq 'ARRAY') {
9478: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9479: }
9480: }
9481: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9482: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9483: if ($j < $numchildren) {
1.48 raeburn 9484: $name = $cats->[$depth]{$parent}[$j];
9485: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9486: $idxnum = $idx->{$item};
9487: } else {
9488: $name = $parent_name;
9489: $item = $parent_item;
1.48 raeburn 9490: }
1.49 raeburn 9491: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9492: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9493: for (my $i=0; $i<=$numchildren; $i++) {
9494: my $vpos = $i+1;
9495: my $selstr;
9496: if ($j == $i) {
9497: $selstr = ' selected="selected" ';
9498: }
9499: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9500: }
9501: $text .= '</select> ';
9502: if ($j < $numchildren) {
9503: my $deeper = $depth+1;
9504: $text .= $name.' '
9505: .'<label><input type="checkbox" name="deletecategory" value="'
9506: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9507: if(ref($path) eq 'ARRAY') {
9508: push(@{$path},$name);
1.49 raeburn 9509: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9510: pop(@{$path});
9511: }
9512: } else {
1.330 raeburn 9513: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9514: if ($j == $numchildren) {
9515: $text .= $name;
9516: } else {
9517: $text .= $item;
9518: }
9519: $text .= '" value="" />';
9520: }
9521: $text .= '</td></tr>';
9522: }
9523: $text .= '</table></td>';
9524: } else {
9525: my $higher = $depth-1;
9526: if ($higher == 0) {
9527: $name = &escape($parent).'::'.$higher;
9528: } else {
9529: if (ref($path) eq 'ARRAY') {
9530: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9531: }
9532: }
9533: my $colspan;
9534: if ($parent ne 'instcode') {
9535: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9536: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9537: }
9538: }
9539: }
9540: }
9541: return $text;
9542: }
9543:
1.33 raeburn 9544: sub modifiable_userdata_row {
1.305 raeburn 9545: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 9546: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 9547: my ($role,$rolename,$statustype);
9548: $role = $item;
1.224 raeburn 9549: if ($context eq 'cancreate') {
1.305 raeburn 9550: if ($item =~ /^(emailusername)_(.+)$/) {
9551: $role = $1;
9552: $statustype = $2;
1.228 raeburn 9553: if (ref($usertypes) eq 'HASH') {
9554: if ($usertypes->{$statustype}) {
9555: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9556: } else {
9557: $rolename = &mt('Data provided by user');
9558: }
9559: }
1.224 raeburn 9560: }
9561: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9562: if (ref($usertypes) eq 'HASH') {
9563: $rolename = $usertypes->{$role};
9564: } else {
9565: $rolename = $role;
9566: }
1.325 raeburn 9567: } elsif ($context eq 'lti') {
9568: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 9569: } elsif ($context eq 'privacy') {
9570: $rolename = $itemdesc;
1.33 raeburn 9571: } else {
1.63 raeburn 9572: if ($role eq 'cr') {
9573: $rolename = &mt('Custom role');
9574: } else {
9575: $rolename = &Apache::lonnet::plaintext($role);
9576: }
1.33 raeburn 9577: }
1.224 raeburn 9578: my (@fields,%fieldtitles);
9579: if (ref($fieldsref) eq 'ARRAY') {
9580: @fields = @{$fieldsref};
9581: } else {
9582: @fields = ('lastname','firstname','middlename','generation',
9583: 'permanentemail','id');
9584: }
9585: if ((ref($titlesref) eq 'HASH')) {
9586: %fieldtitles = %{$titlesref};
9587: } else {
9588: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9589: }
1.33 raeburn 9590: my $output;
1.305 raeburn 9591: my $css_class;
9592: if ($rowcount%2) {
9593: $css_class = 'LC_odd_row';
9594: }
9595: if ($customcss) {
9596: $css_class .= " $customcss";
9597: }
9598: $css_class =~ s/^\s+//;
9599: if ($css_class) {
9600: $css_class = ' class="'.$css_class.'"';
9601: }
9602: if ($rowstyle) {
9603: $css_class .= ' style="'.$rowstyle.'"';
9604: }
9605: if ($rowid) {
9606: $rowid = ' id="'.$rowid.'"';
9607: }
9608: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9609: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9610: '<td class="LC_left_item" colspan="2"><table>';
9611: my $rem;
9612: my %checks;
1.325 raeburn 9613: my %current;
1.33 raeburn 9614: if (ref($settings) eq 'HASH') {
1.325 raeburn 9615: my $hashref;
9616: if ($context eq 'lti') {
9617: if (ref($settings) eq 'HASH') {
9618: $hashref = $settings->{'instdata'};
9619: }
1.357 raeburn 9620: } elsif ($context eq 'privacy') {
9621: my ($key,$inner) = split(/_/,$role);
9622: if (ref($settings) eq 'HASH') {
9623: if (ref($settings->{$key}) eq 'HASH') {
9624: $hashref = $settings->{$key}->{$inner};
9625: }
9626: }
1.325 raeburn 9627: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9628: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9629: $hashref = $settings->{'lti_instdata'};
9630: }
9631: if ($role eq 'emailusername') {
9632: if ($statustype) {
9633: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9634: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9635: }
1.325 raeburn 9636: }
9637: }
9638: }
9639: if (ref($hashref) eq 'HASH') {
9640: foreach my $field (@fields) {
9641: if ($hashref->{$field}) {
9642: if ($role eq 'emailusername') {
9643: $checks{$field} = $hashref->{$field};
9644: } else {
9645: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9646: }
9647: }
9648: }
9649: }
9650: }
1.305 raeburn 9651:
9652: my $total = scalar(@fields);
9653: for (my $i=0; $i<$total; $i++) {
9654: $rem = $i%($numinrow);
1.33 raeburn 9655: if ($rem == 0) {
9656: if ($i > 0) {
9657: $output .= '</tr>';
9658: }
9659: $output .= '<tr>';
9660: }
9661: my $check = ' ';
1.228 raeburn 9662: unless ($role eq 'emailusername') {
9663: if (exists($checks{$fields[$i]})) {
1.354 raeburn 9664: $check = $checks{$fields[$i]};
1.357 raeburn 9665: } elsif ($context eq 'privacy') {
9666: if ($role =~ /^priv_(domain|course)$/) {
9667: if (ref($settings) ne 'HASH') {
9668: $check = ' checked="checked" ';
9669: }
9670: } elsif ($role =~ /^priv_(author|community)$/) {
9671: if (ref($settings) ne 'HASH') {
9672: unless ($fields[$i] eq 'id') {
9673: $check = ' checked="checked" ';
9674: }
9675: }
9676: } elsif ($role =~ /^(unpriv|othdom)_/) {
9677: if (ref($settings) ne 'HASH') {
9678: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
9679: $check = ' checked="checked" ';
9680: }
9681: }
9682: }
1.325 raeburn 9683: } elsif ($context ne 'lti') {
1.228 raeburn 9684: if ($role eq 'st') {
9685: if (ref($settings) ne 'HASH') {
9686: $check = ' checked="checked" ';
9687: }
1.33 raeburn 9688: }
9689: }
9690: }
9691: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9692: '<span class="LC_nobreak">';
1.325 raeburn 9693: my $prefix = 'canmodify';
1.228 raeburn 9694: if ($role eq 'emailusername') {
9695: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9696: $checks{$fields[$i]} = 'omit';
9697: }
9698: foreach my $option ('required','optional','omit') {
9699: my $checked='';
9700: if ($checks{$fields[$i]} eq $option) {
9701: $checked='checked="checked" ';
9702: }
9703: $output .= '<label>'.
1.325 raeburn 9704: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9705: &mt($option).'</label>'.(' ' x2);
9706: }
9707: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9708: } else {
1.325 raeburn 9709: if ($context eq 'lti') {
9710: $prefix = 'lti';
1.357 raeburn 9711: } elsif ($context eq 'privacy') {
9712: $prefix = 'privacy';
1.325 raeburn 9713: }
1.228 raeburn 9714: $output .= '<label>'.
1.325 raeburn 9715: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9716: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9717: '</label>';
9718: }
9719: $output .= '</span></td>';
1.33 raeburn 9720: }
1.305 raeburn 9721: $rem = $total%$numinrow;
9722: my $colsleft;
9723: if ($rem) {
9724: $colsleft = $numinrow - $rem;
9725: }
9726: if ($colsleft > 1) {
1.33 raeburn 9727: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9728: ' </td>';
9729: } elsif ($colsleft == 1) {
9730: $output .= '<td class="LC_left_item"> </td>';
9731: }
9732: $output .= '</tr></table></td></tr>';
9733: return $output;
9734: }
1.28 raeburn 9735:
1.93 raeburn 9736: sub insttypes_row {
1.305 raeburn 9737: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9738: $customcss,$rowstyle) = @_;
1.93 raeburn 9739: my %lt = &Apache::lonlocal::texthash (
9740: cansearch => 'Users allowed to search',
9741: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9742: lockablenames => 'User preference to lock name',
1.305 raeburn 9743: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9744: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9745: );
9746: my $showdom;
9747: if ($context eq 'cansearch') {
9748: $showdom = ' ('.$dom.')';
9749: }
1.165 raeburn 9750: my $class = 'LC_left_item';
9751: if ($context eq 'statustocreate') {
9752: $class = 'LC_right_item';
9753: }
1.305 raeburn 9754: my $css_class;
9755: if ($$rowtotal%2) {
9756: $css_class = 'LC_odd_row';
9757: }
9758: if ($customcss) {
9759: $css_class .= ' '.$customcss;
9760: }
9761: $css_class =~ s/^\s+//;
9762: if ($css_class) {
9763: $css_class = ' class="'.$css_class.'"';
9764: }
9765: if ($rowstyle) {
9766: $css_class .= ' style="'.$rowstyle.'"';
9767: }
9768: if ($onclick) {
9769: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9770: }
9771: my $output = '<tr'.$css_class.'>'.
9772: '<td>'.$lt{$context}.$showdom.
9773: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9774: my $rem;
9775: if (ref($types) eq 'ARRAY') {
9776: for (my $i=0; $i<@{$types}; $i++) {
9777: if (defined($usertypes->{$types->[$i]})) {
9778: my $rem = $i%($numinrow);
9779: if ($rem == 0) {
9780: if ($i > 0) {
9781: $output .= '</tr>';
9782: }
9783: $output .= '<tr>';
1.23 raeburn 9784: }
1.26 raeburn 9785: my $check = ' ';
1.99 raeburn 9786: if (ref($settings) eq 'HASH') {
9787: if (ref($settings->{$context}) eq 'ARRAY') {
9788: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9789: $check = ' checked="checked" ';
9790: }
1.315 raeburn 9791: } elsif (ref($settings->{$context}) eq 'HASH') {
9792: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9793: $check = ' checked="checked" ';
9794: }
1.99 raeburn 9795: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9796: $check = ' checked="checked" ';
9797: }
1.23 raeburn 9798: }
1.26 raeburn 9799: $output .= '<td class="LC_left_item">'.
9800: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9801: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9802: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9803: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9804: }
9805: }
1.26 raeburn 9806: $rem = @{$types}%($numinrow);
1.23 raeburn 9807: }
9808: my $colsleft = $numinrow - $rem;
1.315 raeburn 9809: if ($context eq 'overrides') {
9810: if ($colsleft > 1) {
9811: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9812: } else {
9813: $output .= '<td class="LC_left_item">';
9814: }
9815: $output .= ' ';
1.23 raeburn 9816: } else {
1.334 raeburn 9817: if ($rem == 0) {
1.315 raeburn 9818: $output .= '<tr>';
9819: }
9820: if ($colsleft > 1) {
9821: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9822: } else {
9823: $output .= '<td class="LC_left_item">';
9824: }
9825: my $defcheck = ' ';
9826: if (ref($settings) eq 'HASH') {
9827: if (ref($settings->{$context}) eq 'ARRAY') {
9828: if (grep(/^default$/,@{$settings->{$context}})) {
9829: $defcheck = ' checked="checked" ';
9830: }
9831: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9832: $defcheck = ' checked="checked" ';
9833: }
1.26 raeburn 9834: }
1.315 raeburn 9835: $output .= '<span class="LC_nobreak"><label>'.
9836: '<input type="checkbox" name="'.$context.'" '.
9837: 'value="default"'.$defcheck.$onclick.' />'.
9838: $othertitle.'</label></span>';
1.23 raeburn 9839: }
1.315 raeburn 9840: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9841: return $output;
1.23 raeburn 9842: }
9843:
9844: sub sorted_searchtitles {
9845: my %searchtitles = &Apache::lonlocal::texthash(
9846: 'uname' => 'username',
9847: 'lastname' => 'last name',
9848: 'lastfirst' => 'last name, first name',
9849: );
9850: my @titleorder = ('uname','lastname','lastfirst');
9851: return (\%searchtitles,\@titleorder);
9852: }
9853:
1.25 raeburn 9854: sub sorted_searchtypes {
9855: my %srchtypes_desc = (
9856: exact => 'is exact match',
9857: contains => 'contains ..',
9858: begins => 'begins with ..',
9859: );
9860: my @srchtypeorder = ('exact','begins','contains');
9861: return (\%srchtypes_desc,\@srchtypeorder);
9862: }
9863:
1.3 raeburn 9864: sub usertype_update_row {
9865: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9866: my $datatable;
9867: my $numinrow = 4;
9868: foreach my $type (@{$types}) {
9869: if (defined($usertypes->{$type})) {
9870: $$rownums ++;
9871: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9872: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9873: '</td><td class="LC_left_item"><table>';
9874: for (my $i=0; $i<@{$fields}; $i++) {
9875: my $rem = $i%($numinrow);
9876: if ($rem == 0) {
9877: if ($i > 0) {
9878: $datatable .= '</tr>';
9879: }
9880: $datatable .= '<tr>';
9881: }
9882: my $check = ' ';
1.39 raeburn 9883: if (ref($settings) eq 'HASH') {
9884: if (ref($settings->{'fields'}) eq 'HASH') {
9885: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9886: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9887: $check = ' checked="checked" ';
9888: }
1.3 raeburn 9889: }
9890: }
9891: }
9892:
9893: if ($i == @{$fields}-1) {
9894: my $colsleft = $numinrow - $rem;
9895: if ($colsleft > 1) {
9896: $datatable .= '<td colspan="'.$colsleft.'">';
9897: } else {
9898: $datatable .= '<td>';
9899: }
9900: } else {
9901: $datatable .= '<td>';
9902: }
1.8 raeburn 9903: $datatable .= '<span class="LC_nobreak"><label>'.
9904: '<input type="checkbox" name="updateable_'.$type.
9905: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9906: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9907: }
9908: $datatable .= '</tr></table></td></tr>';
9909: }
9910: }
9911: return $datatable;
1.1 raeburn 9912: }
9913:
9914: sub modify_login {
1.205 raeburn 9915: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 9916: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
9917: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
9918: %title = ( coursecatalog => 'Display course catalog',
9919: adminmail => 'Display administrator E-mail address',
1.188 raeburn 9920: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 9921: newuser => 'Link for visitors to create a user account',
9922: loginheader => 'Log-in box header');
9923: @offon = ('off','on');
1.112 raeburn 9924: if (ref($domconfig{login}) eq 'HASH') {
9925: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
9926: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
9927: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
9928: }
9929: }
9930: }
1.9 raeburn 9931: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
9932: \%domconfig,\%loginhash);
1.188 raeburn 9933: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 9934: foreach my $item (@toggles) {
9935: $loginhash{login}{$item} = $env{'form.'.$item};
9936: }
1.41 raeburn 9937: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 9938: if (ref($colchanges{'login'}) eq 'HASH') {
9939: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
9940: \%loginhash);
9941: }
1.110 raeburn 9942:
1.149 raeburn 9943: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 9944: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 9945: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 9946: if (keys(%servers) > 1) {
9947: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 9948: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
9949: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
9950: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
9951: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
9952: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
9953: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9954: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9955: $changes{'loginvia'}{$lonhost} = 1;
9956: } else {
9957: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
9958: $changes{'loginvia'}{$lonhost} = 1;
9959: }
9960: } else {
9961: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9962: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
9963: $changes{'loginvia'}{$lonhost} = 1;
9964: }
9965: }
9966: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
9967: foreach my $item (@loginvia_attribs) {
9968: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
9969: }
9970: } else {
9971: foreach my $item (@loginvia_attribs) {
9972: my $new = $env{'form.'.$lonhost.'_'.$item};
9973: if (($item eq 'serverpath') && ($new eq 'custom')) {
9974: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
9975: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
9976: $new = '/';
9977: }
9978: }
9979: if (($item eq 'custompath') &&
9980: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
9981: $new = '';
9982: }
9983: if ($new ne $curr_loginvia{$lonhost}{$item}) {
9984: $changes{'loginvia'}{$lonhost} = 1;
9985: }
9986: if ($item eq 'exempt') {
1.256 raeburn 9987: $new = &check_exempt_addresses($new);
1.128 raeburn 9988: }
9989: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
9990: }
9991: }
1.112 raeburn 9992: } else {
1.128 raeburn 9993: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
9994: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 9995: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 9996: foreach my $item (@loginvia_attribs) {
9997: my $new = $env{'form.'.$lonhost.'_'.$item};
9998: if (($item eq 'serverpath') && ($new eq 'custom')) {
9999: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10000: $new = '/';
10001: }
10002: }
10003: if (($item eq 'custompath') &&
10004: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10005: $new = '';
10006: }
10007: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10008: }
1.110 raeburn 10009: }
10010: }
10011: }
10012: }
1.119 raeburn 10013:
1.168 raeburn 10014: my $servadm = $r->dir_config('lonAdmEMail');
10015: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10016: if (ref($domconfig{'login'}) eq 'HASH') {
10017: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10018: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10019: if ($lang eq 'nolang') {
10020: push(@currlangs,$lang);
10021: } elsif (defined($langchoices{$lang})) {
10022: push(@currlangs,$lang);
10023: } else {
10024: next;
10025: }
10026: }
10027: }
10028: }
10029: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10030: if (@currlangs > 0) {
10031: foreach my $lang (@currlangs) {
10032: if (grep(/^\Q$lang\E$/,@delurls)) {
10033: $changes{'helpurl'}{$lang} = 1;
10034: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10035: $changes{'helpurl'}{$lang} = 1;
10036: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10037: push(@newlangs,$lang);
10038: } else {
10039: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10040: }
10041: }
10042: }
10043: unless (grep(/^nolang$/,@currlangs)) {
10044: if ($env{'form.loginhelpurl_nolang.filename'}) {
10045: $changes{'helpurl'}{'nolang'} = 1;
10046: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10047: push(@newlangs,'nolang');
10048: }
10049: }
10050: if ($env{'form.loginhelpurl_add_lang'}) {
10051: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10052: ($env{'form.loginhelpurl_add_file.filename'})) {
10053: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10054: $addedfile = $env{'form.loginhelpurl_add_lang'};
10055: }
10056: }
10057: if ((@newlangs > 0) || ($addedfile)) {
10058: my $error;
10059: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10060: if ($configuserok eq 'ok') {
10061: if ($switchserver) {
10062: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10063: } elsif ($author_ok eq 'ok') {
10064: my @allnew = @newlangs;
10065: if ($addedfile ne '') {
10066: push(@allnew,$addedfile);
10067: }
10068: foreach my $lang (@allnew) {
10069: my $formelem = 'loginhelpurl_'.$lang;
10070: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10071: $formelem = 'loginhelpurl_add_file';
10072: }
10073: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10074: "help/$lang",'','',$newfile{$lang});
10075: if ($result eq 'ok') {
10076: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10077: $changes{'helpurl'}{$lang} = 1;
10078: } else {
10079: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10080: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 10081: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 10082: (!grep(/^\Q$lang\E$/,@delurls))) {
10083: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10084: }
10085: }
10086: }
10087: } else {
10088: $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);
10089: }
10090: } else {
10091: $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);
10092: }
10093: if ($error) {
10094: &Apache::lonnet::logthis($error);
10095: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10096: }
10097: }
1.256 raeburn 10098:
10099: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10100: if (ref($domconfig{'login'}) eq 'HASH') {
10101: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10102: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10103: if ($domservers{$lonhost}) {
10104: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10105: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 10106: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 10107: }
10108: }
10109: }
10110: }
10111: }
10112: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10113: foreach my $lonhost (sort(keys(%domservers))) {
10114: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10115: $changes{'headtag'}{$lonhost} = 1;
10116: } else {
10117: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10118: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10119: }
10120: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10121: push(@newhosts,$lonhost);
10122: } elsif ($currheadtagurls{$lonhost}) {
10123: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10124: if ($currexempt{$lonhost}) {
1.289 raeburn 10125: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 10126: $changes{'headtag'}{$lonhost} = 1;
10127: }
10128: } elsif ($possexempt{$lonhost}) {
10129: $changes{'headtag'}{$lonhost} = 1;
10130: }
10131: if ($possexempt{$lonhost}) {
10132: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10133: }
10134: }
10135: }
10136: }
10137: if (@newhosts) {
10138: my $error;
10139: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10140: if ($configuserok eq 'ok') {
10141: if ($switchserver) {
10142: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10143: } elsif ($author_ok eq 'ok') {
10144: foreach my $lonhost (@newhosts) {
10145: my $formelem = 'loginheadtag_'.$lonhost;
10146: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10147: "login/headtag/$lonhost",'','',
10148: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10149: if ($result eq 'ok') {
10150: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10151: $changes{'headtag'}{$lonhost} = 1;
10152: if ($possexempt{$lonhost}) {
10153: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10154: }
10155: } else {
10156: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10157: $newheadtagurls{$lonhost},$result);
10158: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10159: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10160: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10161: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10162: }
10163: }
10164: }
10165: } else {
10166: $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);
10167: }
10168: } else {
10169: $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);
10170: }
10171: if ($error) {
10172: &Apache::lonnet::logthis($error);
10173: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10174: }
10175: }
1.169 raeburn 10176: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 10177:
10178: my $defaulthelpfile = '/adm/loginproblems.html';
10179: my $defaulttext = &mt('Default in use');
10180:
1.1 raeburn 10181: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10182: $dom);
10183: if ($putresult eq 'ok') {
1.188 raeburn 10184: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10185: my %defaultchecked = (
10186: 'coursecatalog' => 'on',
1.188 raeburn 10187: 'helpdesk' => 'on',
1.42 raeburn 10188: 'adminmail' => 'off',
1.43 raeburn 10189: 'newuser' => 'off',
1.42 raeburn 10190: );
1.55 raeburn 10191: if (ref($domconfig{'login'}) eq 'HASH') {
10192: foreach my $item (@toggles) {
10193: if ($defaultchecked{$item} eq 'on') {
10194: if (($domconfig{'login'}{$item} eq '0') &&
10195: ($env{'form.'.$item} eq '1')) {
10196: $changes{$item} = 1;
10197: } elsif (($domconfig{'login'}{$item} eq '' ||
10198: $domconfig{'login'}{$item} eq '1') &&
10199: ($env{'form.'.$item} eq '0')) {
10200: $changes{$item} = 1;
10201: }
10202: } elsif ($defaultchecked{$item} eq 'off') {
10203: if (($domconfig{'login'}{$item} eq '1') &&
10204: ($env{'form.'.$item} eq '0')) {
10205: $changes{$item} = 1;
10206: } elsif (($domconfig{'login'}{$item} eq '' ||
10207: $domconfig{'login'}{$item} eq '0') &&
10208: ($env{'form.'.$item} eq '1')) {
10209: $changes{$item} = 1;
10210: }
1.42 raeburn 10211: }
10212: }
1.41 raeburn 10213: }
1.6 raeburn 10214: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10215: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10216: if (ref($lastactref) eq 'HASH') {
10217: $lastactref->{'domainconfig'} = 1;
10218: }
1.1 raeburn 10219: $resulttext = &mt('Changes made:').'<ul>';
10220: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10221: if ($item eq 'loginvia') {
1.112 raeburn 10222: if (ref($changes{$item}) eq 'HASH') {
10223: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10224: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10225: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10226: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10227: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10228: $protocol = 'http' if ($protocol ne 'https');
10229: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10230:
10231: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10232: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10233: } else {
10234: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10235: }
10236: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10237: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10238: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10239: }
10240: $resulttext .= '</li>';
10241: } else {
10242: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10243: }
1.112 raeburn 10244: } else {
1.128 raeburn 10245: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10246: }
10247: }
1.128 raeburn 10248: $resulttext .= '</ul></li>';
1.112 raeburn 10249: }
1.168 raeburn 10250: } elsif ($item eq 'helpurl') {
10251: if (ref($changes{$item}) eq 'HASH') {
10252: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10253: if (grep(/^\Q$lang\E$/,@delurls)) {
10254: my ($chg,$link);
10255: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10256: if ($lang eq 'nolang') {
10257: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10258: } else {
10259: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10260: }
10261: $resulttext .= '<li>'.$chg.'</li>';
10262: } else {
10263: my $chg;
10264: if ($lang eq 'nolang') {
10265: $chg = &mt('custom log-in help file for no preferred language');
10266: } else {
10267: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10268: }
10269: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10270: $loginhash{'login'}{'helpurl'}{$lang}.
10271: '?inhibitmenu=yes',$chg,600,500).
10272: '</li>';
10273: }
10274: }
10275: }
1.256 raeburn 10276: } elsif ($item eq 'headtag') {
10277: if (ref($changes{$item}) eq 'HASH') {
10278: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10279: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10280: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10281: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10282: $resulttext .= '<li><a href="'.
10283: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10284: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10285: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10286: if ($possexempt{$lonhost}) {
10287: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10288: } else {
10289: $resulttext .= &mt('included for any client IP');
10290: }
10291: $resulttext .= '</li>';
10292: }
10293: }
10294: }
1.169 raeburn 10295: } elsif ($item eq 'captcha') {
10296: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 10297: my $chgtxt;
1.169 raeburn 10298: if ($loginhash{'login'}{$item} eq 'notused') {
10299: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10300: } else {
10301: my %captchas = &captcha_phrases();
10302: if ($captchas{$loginhash{'login'}{$item}}) {
10303: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10304: } else {
10305: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10306: }
10307: }
10308: $resulttext .= '<li>'.$chgtxt.'</li>';
10309: }
10310: } elsif ($item eq 'recaptchakeys') {
10311: if (ref($loginhash{'login'}) eq 'HASH') {
10312: my ($privkey,$pubkey);
10313: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10314: $pubkey = $loginhash{'login'}{$item}{'public'};
10315: $privkey = $loginhash{'login'}{$item}{'private'};
10316: }
10317: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10318: if (!$pubkey) {
10319: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10320: } else {
10321: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10322: }
10323: if (!$privkey) {
10324: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10325: } else {
1.251 raeburn 10326: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 10327: }
10328: $chgtxt .= '</ul>';
10329: $resulttext .= '<li>'.$chgtxt.'</li>';
10330: }
1.269 raeburn 10331: } elsif ($item eq 'recaptchaversion') {
10332: if (ref($loginhash{'login'}) eq 'HASH') {
10333: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 10334: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 10335: '</li>';
10336: }
10337: }
1.41 raeburn 10338: } else {
10339: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10340: }
1.1 raeburn 10341: }
1.6 raeburn 10342: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10343: } else {
10344: $resulttext = &mt('No changes made to log-in page settings');
10345: }
10346: } else {
1.11 albertel 10347: $resulttext = '<span class="LC_error">'.
10348: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10349: }
1.6 raeburn 10350: if ($errors) {
1.9 raeburn 10351: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10352: $errors.'</ul>';
10353: }
10354: return $resulttext;
10355: }
10356:
1.256 raeburn 10357: sub check_exempt_addresses {
10358: my ($iplist) = @_;
10359: $iplist =~ s/^\s+//;
10360: $iplist =~ s/\s+$//;
10361: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10362: my (@okips,$new);
10363: foreach my $ip (@poss_ips) {
10364: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10365: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10366: push(@okips,$ip);
10367: }
10368: }
10369: }
10370: if (@okips > 0) {
10371: $new = join(',',@okips);
10372: } else {
10373: $new = '';
10374: }
10375: return $new;
10376: }
10377:
1.6 raeburn 10378: sub color_font_choices {
10379: my %choices =
10380: &Apache::lonlocal::texthash (
10381: img => "Header",
10382: bgs => "Background colors",
10383: links => "Link colors",
1.55 raeburn 10384: images => "Images",
1.6 raeburn 10385: font => "Font color",
1.201 raeburn 10386: fontmenu => "Font menu",
1.76 raeburn 10387: pgbg => "Page",
1.6 raeburn 10388: tabbg => "Header",
10389: sidebg => "Border",
10390: link => "Link",
10391: alink => "Active link",
10392: vlink => "Visited link",
10393: );
10394: return %choices;
10395: }
10396:
10397: sub modify_rolecolors {
1.205 raeburn 10398: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10399: my ($resulttext,%rolehash);
10400: $rolehash{'rolecolors'} = {};
1.55 raeburn 10401: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10402: if ($domconfig{'rolecolors'} eq '') {
10403: $domconfig{'rolecolors'} = {};
10404: }
10405: }
1.9 raeburn 10406: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10407: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10408: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10409: $dom);
10410: if ($putresult eq 'ok') {
10411: if (keys(%changes) > 0) {
1.41 raeburn 10412: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10413: if (ref($lastactref) eq 'HASH') {
10414: $lastactref->{'domainconfig'} = 1;
10415: }
1.6 raeburn 10416: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10417: $rolehash{'rolecolors'});
10418: } else {
10419: $resulttext = &mt('No changes made to default color schemes');
10420: }
10421: } else {
1.11 albertel 10422: $resulttext = '<span class="LC_error">'.
10423: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10424: }
10425: if ($errors) {
10426: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10427: $errors.'</ul>';
10428: }
10429: return $resulttext;
10430: }
10431:
10432: sub modify_colors {
1.9 raeburn 10433: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10434: my (%changes,%choices);
1.51 raeburn 10435: my @bgs;
1.6 raeburn 10436: my @links = ('link','alink','vlink');
1.41 raeburn 10437: my @logintext;
1.6 raeburn 10438: my @images;
10439: my $servadm = $r->dir_config('lonAdmEMail');
10440: my $errors;
1.200 raeburn 10441: my %defaults;
1.6 raeburn 10442: foreach my $role (@{$roles}) {
10443: if ($role eq 'login') {
1.12 raeburn 10444: %choices = &login_choices();
1.41 raeburn 10445: @logintext = ('textcol','bgcol');
1.12 raeburn 10446: } else {
10447: %choices = &color_font_choices();
10448: }
10449: if ($role eq 'login') {
1.41 raeburn 10450: @images = ('img','logo','domlogo','login');
1.51 raeburn 10451: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10452: } else {
10453: @images = ('img');
1.200 raeburn 10454: @bgs = ('pgbg','tabbg','sidebg');
10455: }
10456: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10457: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10458: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10459: }
10460: if ($role eq 'login') {
10461: foreach my $item (@logintext) {
1.234 raeburn 10462: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10463: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10464: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10465: }
10466: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 10467: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10468: }
10469: }
10470: } else {
1.234 raeburn 10471: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10472: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10473: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10474: }
10475: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 10476: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10477: }
1.6 raeburn 10478: }
1.200 raeburn 10479: foreach my $item (@bgs) {
1.234 raeburn 10480: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10481: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10482: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10483: }
10484: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 10485: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10486: }
10487: }
10488: foreach my $item (@links) {
1.234 raeburn 10489: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10490: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10491: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10492: }
10493: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 10494: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10495: }
1.6 raeburn 10496: }
1.46 raeburn 10497: my ($configuserok,$author_ok,$switchserver) =
10498: &config_check($dom,$confname,$servadm);
1.9 raeburn 10499: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10500: if (ref($domconfig->{$role}) ne 'HASH') {
10501: $domconfig->{$role} = {};
10502: }
1.8 raeburn 10503: foreach my $img (@images) {
1.70 raeburn 10504: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10505: if (defined($env{'form.login_showlogo_'.$img})) {
10506: $confhash->{$role}{'showlogo'}{$img} = 1;
10507: } else {
10508: $confhash->{$role}{'showlogo'}{$img} = 0;
10509: }
10510: }
1.18 albertel 10511: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10512: && !defined($domconfig->{$role}{$img})
10513: && !$env{'form.'.$role.'_del_'.$img}
10514: && $env{'form.'.$role.'_import_'.$img}) {
10515: # import the old configured image from the .tab setting
10516: # if they haven't provided a new one
10517: $domconfig->{$role}{$img} =
10518: $env{'form.'.$role.'_import_'.$img};
10519: }
1.6 raeburn 10520: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10521: my $error;
1.6 raeburn 10522: if ($configuserok eq 'ok') {
1.9 raeburn 10523: if ($switchserver) {
1.12 raeburn 10524: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10525: } else {
10526: if ($author_ok eq 'ok') {
10527: my ($result,$logourl) =
10528: &publishlogo($r,'upload',$role.'_'.$img,
10529: $dom,$confname,$img,$width,$height);
10530: if ($result eq 'ok') {
10531: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10532: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10533: } else {
1.12 raeburn 10534: $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 10535: }
10536: } else {
1.46 raeburn 10537: $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 10538: }
10539: }
10540: } else {
1.46 raeburn 10541: $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 10542: }
10543: if ($error) {
1.8 raeburn 10544: &Apache::lonnet::logthis($error);
1.11 albertel 10545: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10546: }
10547: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10548: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10549: my $error;
10550: if ($configuserok eq 'ok') {
10551: # is confname an author?
10552: if ($switchserver eq '') {
10553: if ($author_ok eq 'ok') {
10554: my ($result,$logourl) =
10555: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10556: $dom,$confname,$img,$width,$height);
10557: if ($result eq 'ok') {
10558: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10559: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10560: }
10561: }
10562: }
10563: }
1.6 raeburn 10564: }
10565: }
10566: }
10567: if (ref($domconfig) eq 'HASH') {
10568: if (ref($domconfig->{$role}) eq 'HASH') {
10569: foreach my $img (@images) {
10570: if ($domconfig->{$role}{$img} ne '') {
10571: if ($env{'form.'.$role.'_del_'.$img}) {
10572: $confhash->{$role}{$img} = '';
1.12 raeburn 10573: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10574: } else {
1.9 raeburn 10575: if ($confhash->{$role}{$img} eq '') {
10576: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10577: }
1.6 raeburn 10578: }
10579: } else {
10580: if ($env{'form.'.$role.'_del_'.$img}) {
10581: $confhash->{$role}{$img} = '';
1.12 raeburn 10582: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10583: }
10584: }
1.70 raeburn 10585: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10586: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10587: if ($confhash->{$role}{'showlogo'}{$img} ne
10588: $domconfig->{$role}{'showlogo'}{$img}) {
10589: $changes{$role}{'showlogo'}{$img} = 1;
10590: }
10591: } else {
10592: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10593: $changes{$role}{'showlogo'}{$img} = 1;
10594: }
10595: }
10596: }
10597: }
1.6 raeburn 10598: if ($domconfig->{$role}{'font'} ne '') {
10599: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10600: $changes{$role}{'font'} = 1;
10601: }
10602: } else {
10603: if ($confhash->{$role}{'font'}) {
10604: $changes{$role}{'font'} = 1;
10605: }
10606: }
1.107 raeburn 10607: if ($role ne 'login') {
10608: if ($domconfig->{$role}{'fontmenu'} ne '') {
10609: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10610: $changes{$role}{'fontmenu'} = 1;
10611: }
10612: } else {
10613: if ($confhash->{$role}{'fontmenu'}) {
10614: $changes{$role}{'fontmenu'} = 1;
10615: }
1.97 tempelho 10616: }
10617: }
1.6 raeburn 10618: foreach my $item (@bgs) {
10619: if ($domconfig->{$role}{$item} ne '') {
10620: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10621: $changes{$role}{'bgs'}{$item} = 1;
10622: }
10623: } else {
10624: if ($confhash->{$role}{$item}) {
10625: $changes{$role}{'bgs'}{$item} = 1;
10626: }
10627: }
10628: }
10629: foreach my $item (@links) {
10630: if ($domconfig->{$role}{$item} ne '') {
10631: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10632: $changes{$role}{'links'}{$item} = 1;
10633: }
10634: } else {
10635: if ($confhash->{$role}{$item}) {
10636: $changes{$role}{'links'}{$item} = 1;
10637: }
10638: }
10639: }
1.41 raeburn 10640: foreach my $item (@logintext) {
10641: if ($domconfig->{$role}{$item} ne '') {
10642: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10643: $changes{$role}{'logintext'}{$item} = 1;
10644: }
10645: } else {
10646: if ($confhash->{$role}{$item}) {
10647: $changes{$role}{'logintext'}{$item} = 1;
10648: }
10649: }
10650: }
1.6 raeburn 10651: } else {
10652: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10653: \@logintext,$confhash,\%changes);
1.6 raeburn 10654: }
10655: } else {
10656: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10657: \@logintext,$confhash,\%changes);
1.6 raeburn 10658: }
10659: }
10660: return ($errors,%changes);
10661: }
10662:
1.46 raeburn 10663: sub config_check {
10664: my ($dom,$confname,$servadm) = @_;
10665: my ($configuserok,$author_ok,$switchserver,%currroles);
10666: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10667: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10668: $confname,$servadm);
10669: if ($configuserok eq 'ok') {
10670: $switchserver = &check_switchserver($dom,$confname);
10671: if ($switchserver eq '') {
10672: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10673: }
10674: }
10675: return ($configuserok,$author_ok,$switchserver);
10676: }
10677:
1.6 raeburn 10678: sub default_change_checker {
1.41 raeburn 10679: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10680: foreach my $item (@{$links}) {
10681: if ($confhash->{$role}{$item}) {
10682: $changes->{$role}{'links'}{$item} = 1;
10683: }
10684: }
10685: foreach my $item (@{$bgs}) {
10686: if ($confhash->{$role}{$item}) {
10687: $changes->{$role}{'bgs'}{$item} = 1;
10688: }
10689: }
1.41 raeburn 10690: foreach my $item (@{$logintext}) {
10691: if ($confhash->{$role}{$item}) {
10692: $changes->{$role}{'logintext'}{$item} = 1;
10693: }
10694: }
1.6 raeburn 10695: foreach my $img (@{$images}) {
10696: if ($env{'form.'.$role.'_del_'.$img}) {
10697: $confhash->{$role}{$img} = '';
1.12 raeburn 10698: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10699: }
1.70 raeburn 10700: if ($role eq 'login') {
10701: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10702: $changes->{$role}{'showlogo'}{$img} = 1;
10703: }
10704: }
1.6 raeburn 10705: }
10706: if ($confhash->{$role}{'font'}) {
10707: $changes->{$role}{'font'} = 1;
10708: }
1.48 raeburn 10709: }
1.6 raeburn 10710:
10711: sub display_colorchgs {
10712: my ($dom,$changes,$roles,$confhash) = @_;
10713: my (%choices,$resulttext);
10714: if (!grep(/^login$/,@{$roles})) {
10715: $resulttext = &mt('Changes made:').'<br />';
10716: }
10717: foreach my $role (@{$roles}) {
10718: if ($role eq 'login') {
10719: %choices = &login_choices();
10720: } else {
10721: %choices = &color_font_choices();
10722: }
10723: if (ref($changes->{$role}) eq 'HASH') {
10724: if ($role ne 'login') {
10725: $resulttext .= '<h4>'.&mt($role).'</h4>';
10726: }
10727: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10728: if ($role ne 'login') {
10729: $resulttext .= '<ul>';
10730: }
10731: if (ref($changes->{$role}{$key}) eq 'HASH') {
10732: if ($role ne 'login') {
10733: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10734: }
10735: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10736: if (($role eq 'login') && ($key eq 'showlogo')) {
10737: if ($confhash->{$role}{$key}{$item}) {
10738: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10739: } else {
10740: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10741: }
10742: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10743: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10744: } else {
1.12 raeburn 10745: my $newitem = $confhash->{$role}{$item};
10746: if ($key eq 'images') {
1.306 raeburn 10747: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10748: }
10749: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10750: }
10751: }
10752: if ($role ne 'login') {
10753: $resulttext .= '</ul></li>';
10754: }
10755: } else {
10756: if ($confhash->{$role}{$key} eq '') {
10757: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10758: } else {
10759: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10760: }
10761: }
10762: if ($role ne 'login') {
10763: $resulttext .= '</ul>';
10764: }
10765: }
10766: }
10767: }
1.3 raeburn 10768: return $resulttext;
1.1 raeburn 10769: }
10770:
1.9 raeburn 10771: sub thumb_dimensions {
10772: return ('200','50');
10773: }
10774:
1.16 raeburn 10775: sub check_dimensions {
10776: my ($inputfile) = @_;
10777: my ($fullwidth,$fullheight);
10778: if ($inputfile =~ m|^[/\w.\-]+$|) {
10779: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10780: my $imageinfo = <PIPE>;
10781: if (!close(PIPE)) {
10782: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10783: }
10784: chomp($imageinfo);
10785: my ($fullsize) =
1.21 raeburn 10786: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10787: if ($fullsize) {
10788: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10789: }
10790: }
10791: }
10792: return ($fullwidth,$fullheight);
10793: }
10794:
1.9 raeburn 10795: sub check_configuser {
10796: my ($uhome,$dom,$confname,$servadm) = @_;
10797: my ($configuserok,%currroles);
10798: if ($uhome eq 'no_host') {
10799: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 10800: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10801: $configuserok =
10802: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10803: $configpass,'','','','','',undef,$servadm);
10804: } else {
10805: $configuserok = 'ok';
10806: %currroles =
10807: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10808: }
10809: return ($configuserok,%currroles);
10810: }
10811:
10812: sub check_authorstatus {
10813: my ($dom,$confname,%currroles) = @_;
10814: my $author_ok;
1.40 raeburn 10815: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10816: my $start = time;
10817: my $end = 0;
10818: $author_ok =
10819: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10820: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10821: } else {
10822: $author_ok = 'ok';
10823: }
10824: return $author_ok;
10825: }
10826:
10827: sub publishlogo {
1.46 raeburn 10828: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10829: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10830: if ($action eq 'upload') {
10831: $fname=$env{'form.'.$formname.'.filename'};
10832: chop($env{'form.'.$formname});
10833: } else {
10834: ($fname) = ($formname =~ /([^\/]+)$/);
10835: }
1.46 raeburn 10836: if ($savefileas ne '') {
10837: $fname = $savefileas;
10838: }
1.9 raeburn 10839: $fname=&Apache::lonnet::clean_filename($fname);
10840: # See if there is anything left
10841: unless ($fname) { return ('error: no uploaded file'); }
10842: $fname="$subdir/$fname";
1.210 raeburn 10843: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10844: my $filepath="$docroot/priv";
10845: my $relpath = "$dom/$confname";
1.9 raeburn 10846: my ($fnamepath,$file,$fetchthumb);
10847: $file=$fname;
10848: if ($fname=~m|/|) {
10849: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10850: }
1.164 raeburn 10851: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10852: my $count;
1.164 raeburn 10853: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10854: $filepath.="/$parts[$count]";
10855: if ((-e $filepath)!=1) {
10856: mkdir($filepath,02770);
10857: }
10858: }
10859: # Check for bad extension and disallow upload
10860: if ($file=~/\.(\w+)$/ &&
10861: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10862: $output =
1.207 bisitz 10863: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10864: } elsif ($file=~/\.(\w+)$/ &&
10865: !defined(&Apache::loncommon::fileembstyle($1))) {
10866: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10867: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10868: $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 10869: } elsif (-d "$filepath/$file") {
1.195 bisitz 10870: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10871: } else {
10872: my $source = $filepath.'/'.$file;
10873: my $logfile;
1.316 raeburn 10874: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10875: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10876: }
10877: print $logfile
10878: "\n================= Publish ".localtime()." ================\n".
10879: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10880: # Save the file
1.316 raeburn 10881: if (!open(FH,">",$source)) {
1.9 raeburn 10882: &Apache::lonnet::logthis('Failed to create '.$source);
10883: return (&mt('Failed to create file'));
10884: }
10885: if ($action eq 'upload') {
10886: if (!print FH ($env{'form.'.$formname})) {
10887: &Apache::lonnet::logthis('Failed to write to '.$source);
10888: return (&mt('Failed to write file'));
10889: }
10890: } else {
10891: my $original = &Apache::lonnet::filelocation('',$formname);
10892: if(!copy($original,$source)) {
10893: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10894: return (&mt('Failed to write file'));
10895: }
10896: }
10897: close(FH);
10898: chmod(0660, $source); # Permissions to rw-rw---.
10899:
10900: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10901: my $copyfile=$targetdir.'/'.$file;
10902:
10903: my @parts=split(/\//,$targetdir);
10904: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10905: for (my $count=5;$count<=$#parts;$count++) {
10906: $path.="/$parts[$count]";
10907: if (!-e $path) {
10908: print $logfile "\nCreating directory ".$path;
10909: mkdir($path,02770);
10910: }
10911: }
10912: my $versionresult;
10913: if (-e $copyfile) {
10914: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10915: } else {
10916: $versionresult = 'ok';
10917: }
10918: if ($versionresult eq 'ok') {
10919: if (copy($source,$copyfile)) {
10920: print $logfile "\nCopied original source to ".$copyfile."\n";
10921: $output = 'ok';
10922: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 10923: push(@{$modified_urls},[$copyfile,$source]);
10924: my $metaoutput =
10925: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
10926: unless ($registered_cleanup) {
10927: my $handlers = $r->get_handlers('PerlCleanupHandler');
10928: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10929: $registered_cleanup=1;
10930: }
1.9 raeburn 10931: } else {
10932: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
10933: $output = &mt('Failed to copy file to RES space').", $!";
10934: }
10935: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
10936: my $inputfile = $filepath.'/'.$file;
10937: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 10938: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
10939: if ($fullwidth ne '' && $fullheight ne '') {
10940: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
10941: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 10942: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
10943: system({$args[0]} @args);
1.16 raeburn 10944: chmod(0660, $filepath.'/tn-'.$file);
10945: if (-e $outfile) {
10946: my $copyfile=$targetdir.'/tn-'.$file;
10947: if (copy($outfile,$copyfile)) {
10948: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 10949: my $thumb_metaoutput =
10950: &write_metadata($dom,$confname,$formname,
10951: $targetdir,'tn-'.$file,$logfile);
10952: push(@{$modified_urls},[$copyfile,$outfile]);
10953: unless ($registered_cleanup) {
10954: my $handlers = $r->get_handlers('PerlCleanupHandler');
10955: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
10956: $registered_cleanup=1;
10957: }
1.267 raeburn 10958: $madethumb = 1;
1.16 raeburn 10959: } else {
10960: print $logfile "\nUnable to write ".$copyfile.
10961: ':'.$!."\n";
10962: }
10963: }
1.9 raeburn 10964: }
10965: }
10966: }
10967: } else {
10968: $output = $versionresult;
10969: }
10970: }
1.267 raeburn 10971: return ($output,$logourl,$madethumb);
1.9 raeburn 10972: }
10973:
10974: sub logo_versioning {
10975: my ($targetdir,$file,$logfile) = @_;
10976: my $target = $targetdir.'/'.$file;
10977: my ($maxversion,$fn,$extn,$output);
10978: $maxversion = 0;
10979: if ($file =~ /^(.+)\.(\w+)$/) {
10980: $fn=$1;
10981: $extn=$2;
10982: }
10983: opendir(DIR,$targetdir);
10984: while (my $filename=readdir(DIR)) {
10985: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
10986: $maxversion=($1>$maxversion)?$1:$maxversion;
10987: }
10988: }
10989: $maxversion++;
10990: print $logfile "\nCreating old version ".$maxversion."\n";
10991: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
10992: if (copy($target,$copyfile)) {
10993: print $logfile "Copied old target to ".$copyfile."\n";
10994: $copyfile=$copyfile.'.meta';
10995: if (copy($target.'.meta',$copyfile)) {
10996: print $logfile "Copied old target metadata to ".$copyfile."\n";
10997: $output = 'ok';
10998: } else {
10999: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11000: $output = &mt('Failed to copy old meta').", $!, ";
11001: }
11002: } else {
11003: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11004: $output = &mt('Failed to copy old target').", $!, ";
11005: }
11006: return $output;
11007: }
11008:
11009: sub write_metadata {
11010: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11011: my (%metadatafields,%metadatakeys,$output);
11012: $metadatafields{'title'}=$formname;
11013: $metadatafields{'creationdate'}=time;
11014: $metadatafields{'lastrevisiondate'}=time;
11015: $metadatafields{'copyright'}='public';
11016: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11017: $env{'user.domain'};
11018: $metadatafields{'authorspace'}=$confname.':'.$dom;
11019: $metadatafields{'domain'}=$dom;
11020: {
11021: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11022: my $mfh;
1.316 raeburn 11023: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 11024: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11025: unless ($_=~/\./) {
11026: my $unikey=$_;
11027: $unikey=~/^([A-Za-z]+)/;
11028: my $tag=$1;
11029: $tag=~tr/A-Z/a-z/;
11030: print $mfh "\n\<$tag";
11031: foreach (split(/\,/,$metadatakeys{$unikey})) {
11032: my $value=$metadatafields{$unikey.'.'.$_};
11033: $value=~s/\"/\'\'/g;
11034: print $mfh ' '.$_.'="'.$value.'"';
11035: }
11036: print $mfh '>'.
11037: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11038: .'</'.$tag.'>';
11039: }
11040: }
11041: $output = 'ok';
11042: print $logfile "\nWrote metadata";
11043: close($mfh);
11044: } else {
11045: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11046: $output = &mt('Could not write metadata');
11047: }
11048: }
1.155 raeburn 11049: return $output;
11050: }
11051:
11052: sub notifysubscribed {
11053: foreach my $targetsource (@{$modified_urls}){
11054: next unless (ref($targetsource) eq 'ARRAY');
11055: my ($target,$source)=@{$targetsource};
11056: if ($source ne '') {
1.316 raeburn 11057: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11058: print $logfh "\nCleanup phase: Notifications\n";
11059: my @subscribed=&subscribed_hosts($target);
11060: foreach my $subhost (@subscribed) {
11061: print $logfh "\nNotifying host ".$subhost.':';
11062: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11063: print $logfh $reply;
11064: }
11065: my @subscribedmeta=&subscribed_hosts("$target.meta");
11066: foreach my $subhost (@subscribedmeta) {
11067: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11068: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11069: $subhost);
11070: print $logfh $reply;
11071: }
11072: print $logfh "\n============ Done ============\n";
1.160 raeburn 11073: close($logfh);
1.155 raeburn 11074: }
11075: }
11076: }
11077: return OK;
11078: }
11079:
11080: sub subscribed_hosts {
11081: my ($target) = @_;
11082: my @subscribed;
1.316 raeburn 11083: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11084: while (my $subline=<$fh>) {
11085: if ($subline =~ /^($match_lonid):/) {
11086: my $host = $1;
11087: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11088: unless (grep(/^\Q$host\E$/,@subscribed)) {
11089: push(@subscribed,$host);
11090: }
11091: }
11092: }
11093: }
11094: }
11095: return @subscribed;
1.9 raeburn 11096: }
11097:
11098: sub check_switchserver {
11099: my ($dom,$confname) = @_;
11100: my ($allowed,$switchserver);
11101: my $home = &Apache::lonnet::homeserver($confname,$dom);
11102: if ($home eq 'no_host') {
11103: $home = &Apache::lonnet::domain($dom,'primary');
11104: }
11105: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11106: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11107: if (!$allowed) {
1.180 raeburn 11108: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11109: }
11110: return $switchserver;
11111: }
11112:
1.1 raeburn 11113: sub modify_quotas {
1.216 raeburn 11114: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11115: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 11116: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 11117: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11118: $validationfieldsref);
1.86 raeburn 11119: if ($action eq 'quotas') {
11120: $context = 'tools';
1.163 raeburn 11121: } else {
1.86 raeburn 11122: $context = $action;
11123: }
11124: if ($context eq 'requestcourses') {
1.325 raeburn 11125: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 11126: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11127: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11128: %titles = &courserequest_titles();
11129: $toolregexp = join('|',@usertools);
11130: %conditions = &courserequest_conditions();
1.216 raeburn 11131: $confname = $dom.'-domainconfig';
11132: my $servadm = $r->dir_config('lonAdmEMail');
11133: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 11134: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11135: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 11136: } elsif ($context eq 'requestauthor') {
11137: @usertools = ('author');
11138: %titles = &authorrequest_titles();
1.86 raeburn 11139: } else {
1.162 raeburn 11140: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11141: %titles = &tool_titles();
1.86 raeburn 11142: }
1.212 raeburn 11143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11144: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11145: foreach my $key (keys(%env)) {
1.101 raeburn 11146: if ($context eq 'requestcourses') {
11147: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11148: my $item = $1;
11149: my $type = $2;
11150: if ($type =~ /^limit_(.+)/) {
11151: $limithash{$item}{$1} = $env{$key};
11152: } else {
11153: $confhash{$item}{$type} = $env{$key};
11154: }
11155: }
1.163 raeburn 11156: } elsif ($context eq 'requestauthor') {
11157: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11158: $confhash{$1} = $env{$key};
11159: }
1.101 raeburn 11160: } else {
1.86 raeburn 11161: if ($key =~ /^form\.quota_(.+)$/) {
11162: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 11163: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11164: $confhash{'authorquota'}{$1} = $env{$key};
11165: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11166: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11167: }
1.72 raeburn 11168: }
11169: }
1.163 raeburn 11170: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 11171: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11172: @approvalnotify = sort(@approvalnotify);
11173: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 11174: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 11175: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11176: foreach my $type (@hasuniquecode) {
11177: if (grep(/^\Q$type\E$/,@crstypes)) {
11178: $confhash{'uniquecode'}{$type} = 1;
11179: }
1.216 raeburn 11180: }
1.242 raeburn 11181: my (%newbook,%allpos);
1.216 raeburn 11182: if ($context eq 'requestcourses') {
1.242 raeburn 11183: foreach my $type ('textbooks','templates') {
11184: @{$allpos{$type}} = ();
11185: my $invalid;
11186: if ($type eq 'textbooks') {
11187: $invalid = &mt('Invalid LON-CAPA course for textbook');
11188: } else {
11189: $invalid = &mt('Invalid LON-CAPA course for template');
11190: }
11191: if ($env{'form.'.$type.'_addbook'}) {
11192: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11193: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11194: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11195: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11196: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11197: } else {
11198: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11199: my $position = $env{'form.'.$type.'_addbook_pos'};
11200: $position =~ s/\D+//g;
11201: if ($position ne '') {
11202: $allpos{$type}[$position] = $newbook{$type};
11203: }
1.216 raeburn 11204: }
1.242 raeburn 11205: } else {
11206: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 11207: }
11208: }
1.242 raeburn 11209: }
1.216 raeburn 11210: }
1.102 raeburn 11211: if (ref($domconfig{$action}) eq 'HASH') {
11212: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11213: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11214: $changes{'notify'}{'approval'} = 1;
11215: }
11216: } else {
1.144 raeburn 11217: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11218: $changes{'notify'}{'approval'} = 1;
11219: }
11220: }
1.218 raeburn 11221: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11222: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11223: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11224: unless ($confhash{'uniquecode'}{$crstype}) {
11225: $changes{'uniquecode'} = 1;
11226: }
11227: }
11228: unless ($changes{'uniquecode'}) {
11229: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11230: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11231: $changes{'uniquecode'} = 1;
11232: }
11233: }
11234: }
11235: } else {
11236: $changes{'uniquecode'} = 1;
11237: }
11238: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11239: $changes{'uniquecode'} = 1;
1.216 raeburn 11240: }
11241: if ($context eq 'requestcourses') {
1.242 raeburn 11242: foreach my $type ('textbooks','templates') {
11243: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11244: my %deletions;
11245: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11246: if (@todelete) {
11247: map { $deletions{$_} = 1; } @todelete;
11248: }
11249: my %imgdeletions;
11250: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11251: if (@todeleteimages) {
11252: map { $imgdeletions{$_} = 1; } @todeleteimages;
11253: }
11254: my $maxnum = $env{'form.'.$type.'_maxnum'};
11255: for (my $i=0; $i<=$maxnum; $i++) {
11256: my $itemid = $env{'form.'.$type.'_id_'.$i};
11257: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11258: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11259: if ($deletions{$key}) {
11260: if ($domconfig{$action}{$type}{$key}{'image'}) {
11261: #FIXME need to obsolete item in RES space
11262: }
11263: next;
11264: } else {
11265: my $newpos = $env{'form.'.$itemid};
11266: $newpos =~ s/\D+//g;
1.243 raeburn 11267: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 11268: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 11269: ($type eq 'templates'));
1.242 raeburn 11270: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11271: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11272: $changes{$type}{$key} = 1;
11273: }
11274: }
11275: $allpos{$type}[$newpos] = $key;
11276: }
11277: if ($imgdeletions{$key}) {
11278: $changes{$type}{$key} = 1;
1.216 raeburn 11279: #FIXME need to obsolete item in RES space
1.242 raeburn 11280: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11281: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 11282: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11283: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11284: } else {
11285: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11286: $cdom,$cnum,$type,$configuserok,
11287: $switchserver,$author_ok);
11288: if ($imgurl) {
11289: $confhash{$type}{$key}{'image'} = $imgurl;
11290: $changes{$type}{$key} = 1;
11291: }
11292: if ($error) {
11293: &Apache::lonnet::logthis($error);
11294: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11295: }
11296: }
1.242 raeburn 11297: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11298: $confhash{$type}{$key}{'image'} =
11299: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 11300: }
11301: }
11302: }
11303: }
11304: }
11305: }
1.102 raeburn 11306: } else {
1.144 raeburn 11307: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11308: $changes{'notify'}{'approval'} = 1;
11309: }
1.218 raeburn 11310: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 11311: $changes{'uniquecode'} = 1;
11312: }
11313: }
11314: if ($context eq 'requestcourses') {
1.242 raeburn 11315: foreach my $type ('textbooks','templates') {
11316: if ($newbook{$type}) {
11317: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 11318: foreach my $item ('subject','title','publisher','author') {
11319: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11320: ($type eq 'template'));
1.242 raeburn 11321: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11322: if ($env{'form.'.$type.'_addbook_'.$item}) {
11323: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11324: }
11325: }
11326: if ($type eq 'textbooks') {
11327: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11328: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 11329: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11330: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11331: } else {
11332: my ($imageurl,$error) =
11333: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11334: $configuserok,$switchserver,$author_ok);
11335: if ($imageurl) {
11336: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11337: }
11338: if ($error) {
11339: &Apache::lonnet::logthis($error);
11340: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11341: }
1.242 raeburn 11342: }
11343: }
1.216 raeburn 11344: }
11345: }
1.242 raeburn 11346: if (@{$allpos{$type}} > 0) {
11347: my $idx = 0;
11348: foreach my $item (@{$allpos{$type}}) {
11349: if ($item ne '') {
11350: $confhash{$type}{$item}{'order'} = $idx;
11351: if (ref($domconfig{$action}) eq 'HASH') {
11352: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11353: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11354: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11355: $changes{$type}{$item} = 1;
11356: }
1.216 raeburn 11357: }
11358: }
11359: }
1.242 raeburn 11360: $idx ++;
1.216 raeburn 11361: }
11362: }
11363: }
11364: }
1.235 raeburn 11365: if (ref($validationitemsref) eq 'ARRAY') {
11366: foreach my $item (@{$validationitemsref}) {
11367: if ($item eq 'fields') {
11368: my @changed;
11369: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11370: if (@{$confhash{'validation'}{$item}} > 0) {
11371: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11372: }
1.266 raeburn 11373: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11374: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11375: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11376: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11377: $domconfig{'requestcourses'}{'validation'}{$item});
11378: } else {
11379: @changed = @{$confhash{'validation'}{$item}};
11380: }
1.235 raeburn 11381: } else {
11382: @changed = @{$confhash{'validation'}{$item}};
11383: }
11384: } else {
11385: @changed = @{$confhash{'validation'}{$item}};
11386: }
11387: if (@changed) {
11388: if ($confhash{'validation'}{$item}) {
11389: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11390: } else {
11391: $changes{'validation'}{$item} = &mt('None');
11392: }
11393: }
11394: } else {
11395: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11396: if ($item eq 'markup') {
11397: if ($env{'form.requestcourses_validation_'.$item}) {
11398: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11399: }
11400: }
1.266 raeburn 11401: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11402: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11403: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11404: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11405: }
11406: } else {
11407: if ($confhash{'validation'}{$item} ne '') {
11408: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11409: }
1.235 raeburn 11410: }
11411: } else {
11412: if ($confhash{'validation'}{$item} ne '') {
11413: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11414: }
11415: }
11416: }
11417: }
11418: }
11419: if ($env{'form.validationdc'}) {
11420: my $newval = $env{'form.validationdc'};
1.285 raeburn 11421: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 11422: if (exists($domcoords{$newval})) {
11423: $confhash{'validation'}{'dc'} = $newval;
11424: }
11425: }
11426: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 11427: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11428: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11429: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11430: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11431: if ($confhash{'validation'}{'dc'} eq '') {
11432: $changes{'validation'}{'dc'} = &mt('None');
11433: } else {
11434: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11435: }
1.235 raeburn 11436: }
1.266 raeburn 11437: } elsif ($confhash{'validation'}{'dc'} ne '') {
11438: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 11439: }
11440: } elsif ($confhash{'validation'}{'dc'} ne '') {
11441: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11442: }
11443: } elsif ($confhash{'validation'}{'dc'} ne '') {
11444: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 11445: }
1.266 raeburn 11446: } else {
11447: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11448: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11449: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11450: $changes{'validation'}{'dc'} = &mt('None');
11451: }
11452: }
1.235 raeburn 11453: }
11454: }
1.102 raeburn 11455: }
11456: } else {
1.86 raeburn 11457: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 11458: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11459: }
1.72 raeburn 11460: foreach my $item (@usertools) {
11461: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11462: my $unset;
1.101 raeburn 11463: if ($context eq 'requestcourses') {
1.104 raeburn 11464: $unset = '0';
11465: if ($type eq '_LC_adv') {
11466: $unset = '';
11467: }
1.101 raeburn 11468: if ($confhash{$item}{$type} eq 'autolimit') {
11469: $confhash{$item}{$type} .= '=';
11470: unless ($limithash{$item}{$type} =~ /\D/) {
11471: $confhash{$item}{$type} .= $limithash{$item}{$type};
11472: }
11473: }
1.163 raeburn 11474: } elsif ($context eq 'requestauthor') {
11475: $unset = '0';
11476: if ($type eq '_LC_adv') {
11477: $unset = '';
11478: }
1.72 raeburn 11479: } else {
1.101 raeburn 11480: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11481: $confhash{$item}{$type} = 1;
11482: } else {
11483: $confhash{$item}{$type} = 0;
11484: }
1.72 raeburn 11485: }
1.86 raeburn 11486: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 11487: if ($action eq 'requestauthor') {
11488: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11489: $changes{$type} = 1;
11490: }
11491: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11492: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11493: $changes{$item}{$type} = 1;
11494: }
11495: } else {
11496: if ($context eq 'requestcourses') {
1.104 raeburn 11497: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11498: $changes{$item}{$type} = 1;
11499: }
11500: } else {
11501: if (!$confhash{$item}{$type}) {
11502: $changes{$item}{$type} = 1;
11503: }
11504: }
11505: }
11506: } else {
11507: if ($context eq 'requestcourses') {
1.104 raeburn 11508: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11509: $changes{$item}{$type} = 1;
11510: }
1.163 raeburn 11511: } elsif ($context eq 'requestauthor') {
11512: if ($confhash{$type} ne $unset) {
11513: $changes{$type} = 1;
11514: }
1.72 raeburn 11515: } else {
11516: if (!$confhash{$item}{$type}) {
11517: $changes{$item}{$type} = 1;
11518: }
11519: }
11520: }
1.1 raeburn 11521: }
11522: }
1.163 raeburn 11523: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11524: if (ref($domconfig{'quotas'}) eq 'HASH') {
11525: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11526: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11527: if (exists($confhash{'defaultquota'}{$key})) {
11528: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11529: $changes{'defaultquota'}{$key} = 1;
11530: }
11531: } else {
11532: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11533: }
11534: }
1.86 raeburn 11535: } else {
11536: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11537: if (exists($confhash{'defaultquota'}{$key})) {
11538: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11539: $changes{'defaultquota'}{$key} = 1;
11540: }
11541: } else {
11542: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11543: }
1.1 raeburn 11544: }
11545: }
1.197 raeburn 11546: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11547: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11548: if (exists($confhash{'authorquota'}{$key})) {
11549: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11550: $changes{'authorquota'}{$key} = 1;
11551: }
11552: } else {
11553: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11554: }
11555: }
11556: }
1.1 raeburn 11557: }
1.86 raeburn 11558: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11559: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11560: if (ref($domconfig{'quotas'}) eq 'HASH') {
11561: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11562: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11563: $changes{'defaultquota'}{$key} = 1;
11564: }
11565: } else {
11566: if (!exists($domconfig{'quotas'}{$key})) {
11567: $changes{'defaultquota'}{$key} = 1;
11568: }
1.72 raeburn 11569: }
11570: } else {
1.86 raeburn 11571: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11572: }
1.1 raeburn 11573: }
11574: }
1.197 raeburn 11575: if (ref($confhash{'authorquota'}) eq 'HASH') {
11576: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11577: if (ref($domconfig{'quotas'}) eq 'HASH') {
11578: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11579: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11580: $changes{'authorquota'}{$key} = 1;
11581: }
11582: } else {
11583: $changes{'authorquota'}{$key} = 1;
11584: }
11585: } else {
11586: $changes{'authorquota'}{$key} = 1;
11587: }
11588: }
11589: }
1.1 raeburn 11590: }
1.72 raeburn 11591:
1.163 raeburn 11592: if ($context eq 'requestauthor') {
11593: $domdefaults{'requestauthor'} = \%confhash;
11594: } else {
11595: foreach my $key (keys(%confhash)) {
1.242 raeburn 11596: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11597: $domdefaults{$key} = $confhash{$key};
11598: }
1.163 raeburn 11599: }
1.72 raeburn 11600: }
1.163 raeburn 11601:
1.1 raeburn 11602: my %quotahash = (
1.86 raeburn 11603: $action => { %confhash }
1.1 raeburn 11604: );
11605: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11606: $dom);
11607: if ($putresult eq 'ok') {
11608: if (keys(%changes) > 0) {
1.72 raeburn 11609: my $cachetime = 24*60*60;
11610: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11611: if (ref($lastactref) eq 'HASH') {
11612: $lastactref->{'domdefaults'} = 1;
11613: }
1.1 raeburn 11614: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11615: unless (($context eq 'requestcourses') ||
1.163 raeburn 11616: ($context eq 'requestauthor')) {
1.86 raeburn 11617: if (ref($changes{'defaultquota'}) eq 'HASH') {
11618: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11619: foreach my $type (@{$types},'default') {
11620: if (defined($changes{'defaultquota'}{$type})) {
11621: my $typetitle = $usertypes->{$type};
11622: if ($type eq 'default') {
11623: $typetitle = $othertitle;
11624: }
1.213 raeburn 11625: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11626: }
11627: }
1.86 raeburn 11628: $resulttext .= '</ul></li>';
1.72 raeburn 11629: }
1.197 raeburn 11630: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11631: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11632: foreach my $type (@{$types},'default') {
11633: if (defined($changes{'authorquota'}{$type})) {
11634: my $typetitle = $usertypes->{$type};
11635: if ($type eq 'default') {
11636: $typetitle = $othertitle;
11637: }
1.213 raeburn 11638: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11639: }
11640: }
11641: $resulttext .= '</ul></li>';
11642: }
1.72 raeburn 11643: }
1.80 raeburn 11644: my %newenv;
1.72 raeburn 11645: foreach my $item (@usertools) {
1.163 raeburn 11646: my (%haschgs,%inconf);
11647: if ($context eq 'requestauthor') {
11648: %haschgs = %changes;
1.210 raeburn 11649: %inconf = %confhash;
1.163 raeburn 11650: } else {
11651: if (ref($changes{$item}) eq 'HASH') {
11652: %haschgs = %{$changes{$item}};
11653: }
11654: if (ref($confhash{$item}) eq 'HASH') {
11655: %inconf = %{$confhash{$item}};
11656: }
11657: }
11658: if (keys(%haschgs) > 0) {
1.80 raeburn 11659: my $newacc =
11660: &Apache::lonnet::usertools_access($env{'user.name'},
11661: $env{'user.domain'},
1.86 raeburn 11662: $item,'reload',$context);
1.210 raeburn 11663: if (($context eq 'requestcourses') ||
1.163 raeburn 11664: ($context eq 'requestauthor')) {
1.108 raeburn 11665: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11666: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11667: }
11668: } else {
11669: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11670: $newenv{'environment.availabletools.'.$item} = $newacc;
11671: }
1.80 raeburn 11672: }
1.163 raeburn 11673: unless ($context eq 'requestauthor') {
11674: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11675: }
1.72 raeburn 11676: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11677: if ($haschgs{$type}) {
1.72 raeburn 11678: my $typetitle = $usertypes->{$type};
11679: if ($type eq 'default') {
11680: $typetitle = $othertitle;
11681: } elsif ($type eq '_LC_adv') {
11682: $typetitle = 'LON-CAPA Advanced Users';
11683: }
1.163 raeburn 11684: if ($inconf{$type}) {
1.101 raeburn 11685: if ($context eq 'requestcourses') {
11686: my $cond;
1.163 raeburn 11687: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11688: if ($1 eq '') {
11689: $cond = &mt('(Automatic processing of any request).');
11690: } else {
11691: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11692: }
11693: } else {
1.163 raeburn 11694: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11695: }
11696: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11697: } elsif ($context eq 'requestauthor') {
11698: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11699: $titles{$inconf{$type}},$typetitle);
11700:
1.101 raeburn 11701: } else {
11702: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11703: }
1.72 raeburn 11704: } else {
1.104 raeburn 11705: if ($type eq '_LC_adv') {
1.163 raeburn 11706: if ($inconf{$type} eq '0') {
1.104 raeburn 11707: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11708: } else {
11709: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11710: }
11711: } else {
11712: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11713: }
1.72 raeburn 11714: }
11715: }
1.26 raeburn 11716: }
1.163 raeburn 11717: unless ($context eq 'requestauthor') {
11718: $resulttext .= '</ul></li>';
11719: }
1.26 raeburn 11720: }
1.1 raeburn 11721: }
1.163 raeburn 11722: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11723: if (ref($changes{'notify'}) eq 'HASH') {
11724: if ($changes{'notify'}{'approval'}) {
11725: if (ref($confhash{'notify'}) eq 'HASH') {
11726: if ($confhash{'notify'}{'approval'}) {
11727: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11728: } else {
1.163 raeburn 11729: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11730: }
11731: }
11732: }
11733: }
11734: }
1.216 raeburn 11735: if ($action eq 'requestcourses') {
11736: my @offon = ('off','on');
11737: if ($changes{'uniquecode'}) {
1.218 raeburn 11738: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11739: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11740: $resulttext .= '<li>'.
11741: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11742: '</li>';
11743: } else {
11744: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11745: '</li>';
11746: }
1.216 raeburn 11747: }
1.242 raeburn 11748: foreach my $type ('textbooks','templates') {
11749: if (ref($changes{$type}) eq 'HASH') {
11750: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11751: foreach my $key (sort(keys(%{$changes{$type}}))) {
11752: my %coursehash = &Apache::lonnet::coursedescription($key);
11753: my $coursetitle = $coursehash{'description'};
11754: my $position = $confhash{$type}{$key}{'order'} + 1;
11755: $resulttext .= '<li>';
1.243 raeburn 11756: foreach my $item ('subject','title','publisher','author') {
11757: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11758: ($type eq 'templates'));
1.242 raeburn 11759: my $name = $item.':';
11760: $name =~ s/^(\w)/\U$1/;
11761: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11762: }
11763: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11764: if ($type eq 'textbooks') {
11765: if ($confhash{$type}{$key}{'image'}) {
11766: $resulttext .= ' '.&mt('Image: [_1]',
11767: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11768: ' alt="Textbook cover" />').'<br />';
11769: }
11770: }
11771: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11772: }
1.242 raeburn 11773: $resulttext .= '</ul></li>';
1.216 raeburn 11774: }
11775: }
1.235 raeburn 11776: if (ref($changes{'validation'}) eq 'HASH') {
11777: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11778: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11779: foreach my $item (@{$validationitemsref}) {
11780: if (exists($changes{'validation'}{$item})) {
11781: if ($item eq 'markup') {
11782: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11783: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11784: } else {
11785: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11786: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11787: }
11788: }
11789: }
11790: if (exists($changes{'validation'}{'dc'})) {
11791: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11792: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11793: }
11794: }
11795: }
1.216 raeburn 11796: }
1.1 raeburn 11797: $resulttext .= '</ul>';
1.80 raeburn 11798: if (keys(%newenv)) {
11799: &Apache::lonnet::appenv(\%newenv);
11800: }
1.1 raeburn 11801: } else {
1.86 raeburn 11802: if ($context eq 'requestcourses') {
11803: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11804: } elsif ($context eq 'requestauthor') {
11805: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11806: } else {
1.90 weissno 11807: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11808: }
1.1 raeburn 11809: }
11810: } else {
1.11 albertel 11811: $resulttext = '<span class="LC_error">'.
11812: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11813: }
1.216 raeburn 11814: if ($errors) {
11815: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11816: '<ul>'.$errors.'</ul></p>';
11817: }
1.3 raeburn 11818: return $resulttext;
1.1 raeburn 11819: }
11820:
1.216 raeburn 11821: sub process_textbook_image {
1.242 raeburn 11822: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11823: my $filename = $env{'form.'.$caller.'.filename'};
11824: my ($error,$url);
11825: my ($width,$height) = (50,50);
11826: if ($configuserok eq 'ok') {
11827: if ($switchserver) {
11828: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11829: $switchserver);
11830: } elsif ($author_ok eq 'ok') {
11831: my ($result,$imageurl) =
11832: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11833: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11834: if ($result eq 'ok') {
11835: $url = $imageurl;
11836: } else {
11837: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11838: }
11839: } else {
11840: $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);
11841: }
11842: } else {
11843: $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);
11844: }
11845: return ($url,$error);
11846: }
11847:
1.267 raeburn 11848: sub modify_ltitools {
11849: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11850: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11851: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11852: my $confname = $dom.'-domainconfig';
11853: my $servadm = $r->dir_config('lonAdmEMail');
11854: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11855: my (%posslti,%possfield);
11856: my @courseroles = ('cc','in','ta','ep','st');
11857: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11858: map { $posslti{$_} = 1; } @ltiroles;
11859: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11860: map { $possfield{$_} = 1; } @allfields;
11861: my %lt = <itools_names();
11862: if ($env{'form.ltitools_add'}) {
11863: my $title = $env{'form.ltitools_add_title'};
11864: $title =~ s/(`)/'/g;
11865: ($newid,my $error) = &get_ltitools_id($dom,$title);
11866: if ($newid) {
11867: my $position = $env{'form.ltitools_add_pos'};
11868: $position =~ s/\D+//g;
11869: if ($position ne '') {
11870: $allpos[$position] = $newid;
11871: }
11872: $changes{$newid} = 1;
1.322 raeburn 11873: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11874: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11875: if ($item eq 'lifetime') {
11876: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11877: }
1.267 raeburn 11878: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11879: if (($item eq 'key') || ($item eq 'secret')) {
11880: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11881: } else {
11882: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11883: }
1.267 raeburn 11884: }
11885: }
11886: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11887: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11888: }
11889: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11890: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11891: }
1.323 raeburn 11892: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11893: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11894: } else {
11895: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11896: }
1.296 raeburn 11897: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11898: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11899: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11900: if (($item eq 'width') || ($item eq 'height')) {
11901: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11902: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11903: }
11904: } else {
11905: if ($env{'form.ltitools_add_'.$item} ne '') {
11906: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11907: }
1.267 raeburn 11908: }
11909: }
11910: if ($env{'form.ltitools_add_target'} eq 'window') {
11911: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11912: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11913: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11914: } else {
11915: $confhash{$newid}{'display'}{'target'} = 'iframe';
11916: }
11917: foreach my $item ('passback','roster') {
1.319 raeburn 11918: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 11919: $confhash{$newid}{$item} = 1;
1.319 raeburn 11920: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
11921: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
11922: $lifetime =~ s/^\s+|\s+$//g;
11923: if ($lifetime =~ /^\d+\.?\d*$/) {
11924: $confhash{$newid}{$item.'valid'} = $lifetime;
11925: }
11926: }
1.267 raeburn 11927: }
11928: }
11929: if ($env{'form.ltitools_add_image.filename'} ne '') {
11930: my ($imageurl,$error) =
1.307 raeburn 11931: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 11932: $configuserok,$switchserver,$author_ok);
11933: if ($imageurl) {
11934: $confhash{$newid}{'image'} = $imageurl;
11935: }
11936: if ($error) {
11937: &Apache::lonnet::logthis($error);
11938: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11939: }
11940: }
11941: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
11942: foreach my $field (@fields) {
11943: if ($possfield{$field}) {
11944: if ($field eq 'roles') {
11945: foreach my $role (@courseroles) {
11946: my $choice = $env{'form.ltitools_add_roles_'.$role};
11947: if (($choice ne '') && ($posslti{$choice})) {
11948: $confhash{$newid}{'roles'}{$role} = $choice;
11949: if ($role eq 'cc') {
11950: $confhash{$newid}{'roles'}{'co'} = $choice;
11951: }
11952: }
11953: }
11954: } else {
11955: $confhash{$newid}{'fields'}{$field} = 1;
11956: }
11957: }
11958: }
1.324 raeburn 11959: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
11960: if ($confhash{$newid}{'fields'}{'user'}) {
11961: if ($env{'form.ltitools_userincdom_add'}) {
11962: $confhash{$newid}{'incdom'} = 1;
11963: }
11964: }
11965: }
1.273 raeburn 11966: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
11967: foreach my $item (@courseconfig) {
11968: $confhash{$newid}{'crsconf'}{$item} = 1;
11969: }
1.267 raeburn 11970: if ($env{'form.ltitools_add_custom'}) {
11971: my $name = $env{'form.ltitools_add_custom_name'};
11972: my $value = $env{'form.ltitools_add_custom_value'};
11973: $value =~ s/(`)/'/g;
11974: $name =~ s/(`)/'/g;
11975: $confhash{$newid}{'custom'}{$name} = $value;
11976: }
11977: } else {
11978: my $error = &mt('Failed to acquire unique ID for new external tool');
11979: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11980: }
11981: }
11982: if (ref($domconfig{$action}) eq 'HASH') {
11983: my %deletions;
11984: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
11985: if (@todelete) {
11986: map { $deletions{$_} = 1; } @todelete;
11987: }
11988: my %customadds;
11989: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
11990: if (@newcustom) {
11991: map { $customadds{$_} = 1; } @newcustom;
11992: }
11993: my %imgdeletions;
11994: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
11995: if (@todeleteimages) {
11996: map { $imgdeletions{$_} = 1; } @todeleteimages;
11997: }
11998: my $maxnum = $env{'form.ltitools_maxnum'};
11999: for (my $i=0; $i<=$maxnum; $i++) {
12000: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 12001: $itemid =~ s/\D+//g;
1.267 raeburn 12002: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12003: if ($deletions{$itemid}) {
12004: if ($domconfig{$action}{$itemid}{'image'}) {
12005: #FIXME need to obsolete item in RES space
12006: }
12007: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12008: next;
12009: } else {
12010: my $newpos = $env{'form.ltitools_'.$itemid};
12011: $newpos =~ s/\D+//g;
1.322 raeburn 12012: foreach my $item ('title','url','lifetime') {
1.267 raeburn 12013: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12014: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12015: $changes{$itemid} = 1;
12016: }
12017: }
1.297 raeburn 12018: foreach my $item ('key','secret') {
12019: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12020: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12021: $changes{$itemid} = 1;
12022: }
12023: }
1.267 raeburn 12024: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12025: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12026: }
12027: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12028: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12029: }
1.323 raeburn 12030: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12031: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12032: } else {
12033: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12034: }
12035: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12036: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12037: $changes{$itemid} = 1;
12038: }
12039: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12040: $changes{$itemid} = 1;
12041: }
1.267 raeburn 12042: foreach my $size ('width','height') {
12043: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12044: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12045: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12046: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12047: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12048: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12049: $changes{$itemid} = 1;
12050: }
12051: } else {
12052: $changes{$itemid} = 1;
12053: }
1.296 raeburn 12054: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12055: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12056: $changes{$itemid} = 1;
12057: }
12058: }
12059: }
12060: foreach my $item ('linktext','explanation') {
12061: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12062: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12063: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12064: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12065: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12066: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12067: $changes{$itemid} = 1;
12068: }
12069: } else {
12070: $changes{$itemid} = 1;
12071: }
12072: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12073: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12074: $changes{$itemid} = 1;
12075: }
1.267 raeburn 12076: }
12077: }
12078: if ($env{'form.ltitools_target_'.$i} eq 'window') {
12079: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 12080: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12081: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 12082: } else {
12083: $confhash{$itemid}{'display'}{'target'} = 'iframe';
12084: }
12085: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12086: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12087: $changes{$itemid} = 1;
12088: }
12089: } else {
12090: $changes{$itemid} = 1;
12091: }
12092: foreach my $extra ('passback','roster') {
12093: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
12094: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 12095: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 12096: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 12097: $lifetime =~ s/^\s+|\s+$//g;
12098: if ($lifetime =~ /^\d+\.?\d*$/) {
12099: $confhash{$itemid}{$extra.'valid'} = $lifetime;
12100: }
12101: }
1.267 raeburn 12102: }
12103: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
12104: $changes{$itemid} = 1;
12105: }
1.319 raeburn 12106: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
12107: $changes{$itemid} = 1;
12108: }
1.267 raeburn 12109: }
1.273 raeburn 12110: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 12111: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 12112: if (grep(/^\Q$item\E$/,@courseconfig)) {
12113: $confhash{$itemid}{'crsconf'}{$item} = 1;
12114: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12115: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12116: $changes{$itemid} = 1;
12117: }
12118: } else {
12119: $changes{$itemid} = 1;
12120: }
12121: }
12122: }
1.267 raeburn 12123: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12124: foreach my $field (@fields) {
12125: if ($possfield{$field}) {
12126: if ($field eq 'roles') {
12127: foreach my $role (@courseroles) {
12128: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12129: if (($choice ne '') && ($posslti{$choice})) {
12130: $confhash{$itemid}{'roles'}{$role} = $choice;
12131: if ($role eq 'cc') {
12132: $confhash{$itemid}{'roles'}{'co'} = $choice;
12133: }
12134: }
12135: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12136: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12137: $changes{$itemid} = 1;
12138: }
12139: } elsif ($confhash{$itemid}{'roles'}{$role}) {
12140: $changes{$itemid} = 1;
12141: }
12142: }
12143: } else {
12144: $confhash{$itemid}{'fields'}{$field} = 1;
12145: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12146: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12147: $changes{$itemid} = 1;
12148: }
12149: } else {
12150: $changes{$itemid} = 1;
12151: }
12152: }
12153: }
12154: }
1.324 raeburn 12155: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12156: if ($confhash{$itemid}{'fields'}{'user'}) {
12157: if ($env{'form.ltitools_userincdom_'.$i}) {
12158: $confhash{$itemid}{'incdom'} = 1;
12159: }
12160: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12161: $changes{$itemid} = 1;
12162: }
12163: }
12164: }
1.267 raeburn 12165: $allpos[$newpos] = $itemid;
12166: }
12167: if ($imgdeletions{$itemid}) {
12168: $changes{$itemid} = 1;
12169: #FIXME need to obsolete item in RES space
12170: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12171: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12172: $itemid,$configuserok,$switchserver,
12173: $author_ok);
12174: if ($imgurl) {
12175: $confhash{$itemid}{'image'} = $imgurl;
12176: $changes{$itemid} = 1;
12177: }
12178: if ($error) {
12179: &Apache::lonnet::logthis($error);
12180: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12181: }
12182: } elsif ($domconfig{$action}{$itemid}{'image'}) {
12183: $confhash{$itemid}{'image'} =
12184: $domconfig{$action}{$itemid}{'image'};
12185: }
12186: if ($customadds{$i}) {
12187: my $name = $env{'form.ltitools_custom_name_'.$i};
12188: $name =~ s/(`)/'/g;
12189: $name =~ s/^\s+//;
12190: $name =~ s/\s+$//;
12191: my $value = $env{'form.ltitools_custom_value_'.$i};
12192: $value =~ s/(`)/'/g;
12193: $value =~ s/^\s+//;
12194: $value =~ s/\s+$//;
12195: if ($name ne '') {
12196: $confhash{$itemid}{'custom'}{$name} = $value;
12197: $changes{$itemid} = 1;
12198: }
12199: }
12200: my %customdels;
12201: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12202: if (@customdeletions) {
12203: $changes{$itemid} = 1;
12204: }
12205: map { $customdels{$_} = 1; } @customdeletions;
12206: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12207: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12208: unless ($customdels{$key}) {
12209: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12210: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12211: }
12212: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12213: $changes{$itemid} = 1;
12214: }
12215: }
12216: }
12217: }
12218: unless ($changes{$itemid}) {
12219: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12220: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12221: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12222: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12223: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12224: $changes{$itemid} = 1;
12225: last;
12226: }
12227: }
12228: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12229: $changes{$itemid} = 1;
12230: }
12231: }
12232: last if ($changes{$itemid});
12233: }
12234: }
12235: }
12236: }
12237: }
12238: if (@allpos > 0) {
12239: my $idx = 0;
12240: foreach my $itemid (@allpos) {
12241: if ($itemid ne '') {
12242: $confhash{$itemid}{'order'} = $idx;
12243: if (ref($domconfig{$action}) eq 'HASH') {
12244: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12245: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12246: $changes{$itemid} = 1;
12247: }
12248: }
12249: }
12250: $idx ++;
12251: }
12252: }
12253: }
12254: my %ltitoolshash = (
12255: $action => { %confhash }
12256: );
12257: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12258: $dom);
12259: if ($putresult eq 'ok') {
1.297 raeburn 12260: my %ltienchash = (
12261: $action => { %encconfig }
12262: );
12263: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 12264: if (keys(%changes) > 0) {
12265: my $cachetime = 24*60*60;
1.297 raeburn 12266: my %ltiall = %confhash;
12267: foreach my $id (keys(%ltiall)) {
12268: if (ref($encconfig{$id}) eq 'HASH') {
12269: foreach my $item ('key','secret') {
12270: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12271: }
12272: }
12273: }
12274: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 12275: if (ref($lastactref) eq 'HASH') {
12276: $lastactref->{'ltitools'} = 1;
12277: }
12278: $resulttext = &mt('Changes made:').'<ul>';
12279: my %bynum;
12280: foreach my $itemid (sort(keys(%changes))) {
12281: my $position = $confhash{$itemid}{'order'};
12282: $bynum{$position} = $itemid;
12283: }
12284: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12285: my $itemid = $bynum{$pos};
12286: if (ref($confhash{$itemid}) ne 'HASH') {
12287: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12288: } else {
12289: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12290: if ($confhash{$itemid}{'image'}) {
12291: $resulttext .= ' '.
12292: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12293: ' alt="'.&mt('Tool Provider icon').'" />';
12294: }
12295: $resulttext .= '</li><ul>';
12296: my $position = $pos + 1;
12297: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 12298: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 12299: if ($confhash{$itemid}{$item} ne '') {
12300: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12301: }
12302: }
1.297 raeburn 12303: if ($encconfig{$itemid}{'key'} ne '') {
12304: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12305: }
12306: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 12307: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 12308: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 12309: $resulttext .= ('*'x$num).'</li>';
12310: }
1.273 raeburn 12311: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 12312: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 12313: my $numconfig = 0;
12314: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12315: foreach my $item (@possconfig) {
12316: if ($confhash{$itemid}{'crsconf'}{$item}) {
12317: $numconfig ++;
1.296 raeburn 12318: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 12319: }
12320: }
12321: }
12322: if (!$numconfig) {
12323: $resulttext .= &mt('None');
12324: }
12325: $resulttext .= '</li>';
1.267 raeburn 12326: foreach my $item ('passback','roster') {
12327: $resulttext .= '<li>'.$lt{$item}.' ';
12328: if ($confhash{$itemid}{$item}) {
12329: $resulttext .= &mt('Yes');
1.319 raeburn 12330: if ($confhash{$itemid}{$item.'valid'}) {
12331: if ($item eq 'passback') {
12332: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
12333: $confhash{$itemid}{$item.'valid'});
12334: } else {
12335: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
12336: $confhash{$itemid}{$item.'valid'});
12337: }
12338: }
1.267 raeburn 12339: } else {
12340: $resulttext .= &mt('No');
12341: }
12342: $resulttext .= '</li>';
12343: }
12344: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12345: my $displaylist;
12346: if ($confhash{$itemid}{'display'}{'target'}) {
12347: $displaylist = &mt('Display target').': '.
12348: $confhash{$itemid}{'display'}{'target'}.',';
12349: }
12350: foreach my $size ('width','height') {
12351: if ($confhash{$itemid}{'display'}{$size}) {
12352: $displaylist .= (' 'x2).$lt{$size}.': '.
12353: $confhash{$itemid}{'display'}{$size}.',';
12354: }
12355: }
12356: if ($displaylist) {
12357: $displaylist =~ s/,$//;
12358: $resulttext .= '<li>'.$displaylist.'</li>';
12359: }
1.296 raeburn 12360: foreach my $item ('linktext','explanation') {
12361: if ($confhash{$itemid}{'display'}{$item}) {
12362: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12363: }
12364: }
12365: }
1.267 raeburn 12366: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12367: my $fieldlist;
12368: foreach my $field (@allfields) {
12369: if ($confhash{$itemid}{'fields'}{$field}) {
12370: $fieldlist .= (' 'x2).$lt{$field}.',';
12371: }
12372: }
12373: if ($fieldlist) {
12374: $fieldlist =~ s/,$//;
1.324 raeburn 12375: if ($confhash{$itemid}{'fields'}{'user'}) {
12376: if ($confhash{$itemid}{'incdom'}) {
12377: $fieldlist .= ' ('.&mt('username:domain').')';
12378: } else {
12379: $fieldlist .= ' ('.&mt('username').')';
12380: }
12381: }
1.267 raeburn 12382: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12383: }
12384: }
12385: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12386: my $rolemaps;
12387: foreach my $role (@courseroles) {
12388: if ($confhash{$itemid}{'roles'}{$role}) {
12389: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12390: $confhash{$itemid}{'roles'}{$role}.',';
12391: }
12392: }
12393: if ($rolemaps) {
12394: $rolemaps =~ s/,$//;
12395: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12396: }
12397: }
12398: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12399: my $customlist;
12400: if (keys(%{$confhash{$itemid}{'custom'}})) {
12401: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12402: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12403: }
12404: }
12405: if ($customlist) {
1.317 raeburn 12406: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 12407: }
12408: }
12409: $resulttext .= '</ul></li>';
12410: }
12411: }
12412: $resulttext .= '</ul>';
12413: } else {
12414: $resulttext = &mt('No changes made.');
12415: }
12416: } else {
12417: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12418: }
12419: if ($errors) {
12420: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12421: $errors.'</ul>';
12422: }
12423: return $resulttext;
12424: }
12425:
12426: sub process_ltitools_image {
12427: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12428: my $filename = $env{'form.'.$caller.'.filename'};
12429: my ($error,$url);
12430: my ($width,$height) = (21,21);
12431: if ($configuserok eq 'ok') {
12432: if ($switchserver) {
12433: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12434: $switchserver);
12435: } elsif ($author_ok eq 'ok') {
12436: my ($result,$imageurl,$madethumb) =
12437: &publishlogo($r,'upload',$caller,$dom,$confname,
12438: "ltitools/$itemid/icon",$width,$height);
12439: if ($result eq 'ok') {
12440: if ($madethumb) {
12441: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12442: my $imagethumb = "$path/tn-".$imagefile;
12443: $url = $imagethumb;
12444: } else {
12445: $url = $imageurl;
12446: }
12447: } else {
12448: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12449: }
12450: } else {
12451: $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);
12452: }
12453: } else {
12454: $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);
12455: }
12456: return ($url,$error);
12457: }
12458:
12459: sub get_ltitools_id {
12460: my ($cdom,$title) = @_;
12461: # get lock on ltitools db
12462: my $lockhash = {
12463: lock => $env{'user.name'}.
12464: ':'.$env{'user.domain'},
12465: };
12466: my $tries = 0;
12467: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12468: my ($id,$error);
12469:
12470: while (($gotlock ne 'ok') && ($tries<10)) {
12471: $tries ++;
12472: sleep (0.1);
12473: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12474: }
12475: if ($gotlock eq 'ok') {
12476: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12477: if ($currids{'lock'}) {
12478: delete($currids{'lock'});
12479: if (keys(%currids)) {
12480: my @curr = sort { $a <=> $b } keys(%currids);
12481: if ($curr[-1] =~ /^\d+$/) {
12482: $id = 1 + $curr[-1];
12483: }
12484: } else {
12485: $id = 1;
12486: }
12487: if ($id) {
12488: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12489: $error = 'nostore';
12490: }
12491: } else {
12492: $error = 'nonumber';
12493: }
12494: }
12495: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12496: } else {
12497: $error = 'nolock';
12498: }
12499: return ($id,$error);
12500: }
12501:
1.320 raeburn 12502: sub modify_lti {
12503: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12504: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12505: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12506: my (%posslti,%posslticrs,%posscrstype);
12507: my @courseroles = ('cc','in','ta','ep','st');
12508: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
12509: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
12510: my @coursetypes = ('official','unofficial','community','textbook','placement');
12511: my %coursetypetitles = &Apache::lonlocal::texthash (
12512: official => 'Official',
12513: unofficial => 'Unofficial',
12514: community => 'Community',
12515: textbook => 'Textbook',
12516: placement => 'Placement Test',
12517: );
1.325 raeburn 12518: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 12519: my %lt = <i_names();
12520: map { $posslti{$_} = 1; } @ltiroles;
12521: map { $posslticrs{$_} = 1; } @lticourseroles;
12522: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 12523:
1.326 raeburn 12524: my %menutitles = <imenu_titles();
12525:
1.320 raeburn 12526: my (@items,%deletions,%itemids);
12527: if ($env{'form.lti_add'}) {
12528: my $consumer = $env{'form.lti_consumer_add'};
12529: $consumer =~ s/(`)/'/g;
12530: ($newid,my $error) = &get_lti_id($dom,$consumer);
12531: if ($newid) {
12532: $itemids{'add'} = $newid;
12533: push(@items,'add');
12534: $changes{$newid} = 1;
12535: } else {
12536: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
12537: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12538: }
12539: }
12540: if (ref($domconfig{$action}) eq 'HASH') {
12541: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
12542: if (@todelete) {
12543: map { $deletions{$_} = 1; } @todelete;
12544: }
12545: my $maxnum = $env{'form.lti_maxnum'};
12546: for (my $i=0; $i<=$maxnum; $i++) {
12547: my $itemid = $env{'form.lti_id_'.$i};
12548: $itemid =~ s/\D+//g;
12549: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12550: if ($deletions{$itemid}) {
12551: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
12552: } else {
12553: push(@items,$i);
12554: $itemids{$i} = $itemid;
12555: }
12556: }
12557: }
12558: }
12559: foreach my $idx (@items) {
12560: my $itemid = $itemids{$idx};
12561: next unless ($itemid);
12562: my $position = $env{'form.lti_pos_'.$idx};
12563: $position =~ s/\D+//g;
12564: if ($position ne '') {
12565: $allpos[$position] = $itemid;
12566: }
1.345 raeburn 12567: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12568: my $formitem = 'form.lti_'.$item.'_'.$idx;
12569: $env{$formitem} =~ s/(`)/'/g;
12570: if ($item eq 'lifetime') {
12571: $env{$formitem} =~ s/[^\d.]//g;
12572: }
12573: if ($env{$formitem} ne '') {
12574: if (($item eq 'key') || ($item eq 'secret')) {
12575: $encconfig{$itemid}{$item} = $env{$formitem};
12576: } else {
12577: $confhash{$itemid}{$item} = $env{$formitem};
12578: unless (($idx eq 'add') || ($changes{$itemid})) {
12579: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12580: $changes{$itemid} = 1;
12581: }
12582: }
12583: }
12584: }
12585: }
12586: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12587: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12588: }
1.345 raeburn 12589: if ($confhash{$itemid}{'requser'}) {
12590: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12591: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12592: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12593: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12594: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12595: my $mapuser = $env{'form.lti_customuser_'.$idx};
12596: $mapuser =~ s/(`)/'/g;
12597: $mapuser =~ s/^\s+|\s+$//g;
12598: $confhash{$itemid}{'mapuser'} = $mapuser;
12599: }
12600: foreach my $ltirole (@lticourseroles) {
12601: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12602: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12603: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12604: }
12605: }
12606: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12607: my @makeuser;
12608: foreach my $ltirole (sort(@possmakeuser)) {
12609: if ($posslti{$ltirole}) {
12610: push(@makeuser,$ltirole);
12611: }
12612: }
12613: $confhash{$itemid}{'makeuser'} = \@makeuser;
12614: if (@makeuser) {
12615: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12616: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12617: $confhash{$itemid}{'lcauth'} = $lcauth;
12618: if ($lcauth ne 'internal') {
12619: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12620: $lcauthparm =~ s/^(\s+|\s+)$//g;
12621: $lcauthparm =~ s/`//g;
12622: if ($lcauthparm ne '') {
12623: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12624: }
12625: }
12626: } else {
12627: $confhash{$itemid}{'lcauth'} = 'lti';
12628: }
1.320 raeburn 12629: }
1.345 raeburn 12630: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12631: if (@possinstdata) {
12632: foreach my $field (@possinstdata) {
12633: if (exists($fieldtitles{$field})) {
12634: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12635: }
12636: }
12637: }
1.345 raeburn 12638: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12639: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12640: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12641: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12642: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12643: $mapcrs =~ s/(`)/'/g;
12644: $mapcrs =~ s/^\s+|\s+$//g;
12645: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12646: }
12647: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12648: my @crstypes;
12649: foreach my $type (sort(@posstypes)) {
12650: if ($posscrstype{$type}) {
12651: push(@crstypes,$type);
1.325 raeburn 12652: }
12653: }
1.345 raeburn 12654: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12655: if ($env{'form.lti_makecrs_'.$idx}) {
12656: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12657: }
1.345 raeburn 12658: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12659: my @selfenroll;
12660: foreach my $type (sort(@possenroll)) {
12661: if ($posslticrs{$type}) {
12662: push(@selfenroll,$type);
12663: }
1.320 raeburn 12664: }
1.345 raeburn 12665: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12666: if ($env{'form.lti_crssec_'.$idx}) {
12667: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12668: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12669: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12670: my $section = $env{'form.lti_customsection_'.$idx};
12671: $section =~ s/(`)/'/g;
12672: $section =~ s/^\s+|\s+$//g;
12673: if ($section ne '') {
12674: $confhash{$itemid}{'section'} = $section;
12675: }
1.320 raeburn 12676: }
12677: }
1.345 raeburn 12678: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12679: if ($env{'form.lti_'.$field.'_'.$idx}) {
12680: $confhash{$itemid}{$field} = 1;
12681: }
1.320 raeburn 12682: }
1.345 raeburn 12683: if ($env{'form.lti_passback_'.$idx}) {
12684: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12685: $confhash{$itemid}{'passbackformat'} = '1.0';
12686: } else {
12687: $confhash{$itemid}{'passbackformat'} = '1.1';
12688: }
1.337 raeburn 12689: }
1.345 raeburn 12690: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12691: $confhash{$itemid}{lcmenu} = [];
12692: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12693: foreach my $field (@possmenu) {
12694: if (exists($menutitles{$field})) {
12695: if ($field eq 'grades') {
12696: next unless ($env{'form.lti_inlinemenu_'.$idx});
12697: }
12698: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12699: }
12700: }
12701: }
1.345 raeburn 12702: unless (($idx eq 'add') || ($changes{$itemid})) {
12703: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
12704: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12705: $changes{$itemid} = 1;
12706: }
12707: }
1.320 raeburn 12708: unless ($changes{$itemid}) {
1.345 raeburn 12709: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12710: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12711: $changes{$itemid} = 1;
12712: }
1.345 raeburn 12713: }
1.320 raeburn 12714: }
1.345 raeburn 12715: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12716: unless ($changes{$itemid}) {
12717: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12718: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12719: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12720: $confhash{$itemid}{$field});
12721: if (@diffs) {
12722: $changes{$itemid} = 1;
12723: }
12724: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12725: $changes{$itemid} = 1;
12726: }
12727: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12728: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12729: $changes{$itemid} = 1;
12730: }
12731: }
1.345 raeburn 12732: }
12733: }
12734: unless ($changes{$itemid}) {
12735: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12736: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12737: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12738: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12739: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12740: $changes{$itemid} = 1;
12741: last;
12742: }
12743: }
1.345 raeburn 12744: unless ($changes{$itemid}) {
12745: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12746: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12747: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12748: $changes{$itemid} = 1;
12749: last;
12750: }
12751: }
12752: }
12753: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12754: $changes{$itemid} = 1;
1.320 raeburn 12755: }
1.345 raeburn 12756: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12757: unless ($changes{$itemid}) {
12758: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12759: $changes{$itemid} = 1;
12760: }
1.320 raeburn 12761: }
12762: }
12763: }
12764: }
12765: }
12766: }
12767: if (@allpos > 0) {
12768: my $idx = 0;
12769: foreach my $itemid (@allpos) {
12770: if ($itemid ne '') {
12771: $confhash{$itemid}{'order'} = $idx;
12772: if (ref($domconfig{$action}) eq 'HASH') {
12773: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12774: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12775: $changes{$itemid} = 1;
12776: }
12777: }
12778: }
12779: $idx ++;
12780: }
12781: }
12782: }
12783: my %ltihash = (
12784: $action => { %confhash }
12785: );
12786: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12787: $dom);
12788: if ($putresult eq 'ok') {
12789: my %ltienchash = (
12790: $action => { %encconfig }
12791: );
12792: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12793: if (keys(%changes) > 0) {
12794: my $cachetime = 24*60*60;
12795: my %ltiall = %confhash;
12796: foreach my $id (keys(%ltiall)) {
12797: if (ref($encconfig{$id}) eq 'HASH') {
12798: foreach my $item ('key','secret') {
12799: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12800: }
12801: }
12802: }
12803: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12804: if (ref($lastactref) eq 'HASH') {
12805: $lastactref->{'lti'} = 1;
12806: }
12807: $resulttext = &mt('Changes made:').'<ul>';
12808: my %bynum;
12809: foreach my $itemid (sort(keys(%changes))) {
12810: my $position = $confhash{$itemid}{'order'};
12811: $bynum{$position} = $itemid;
12812: }
12813: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12814: my $itemid = $bynum{$pos};
12815: if (ref($confhash{$itemid}) ne 'HASH') {
12816: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12817: } else {
12818: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12819: my $position = $pos + 1;
12820: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12821: foreach my $item ('version','lifetime') {
12822: if ($confhash{$itemid}{$item} ne '') {
12823: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12824: }
12825: }
12826: if ($encconfig{$itemid}{'key'} ne '') {
12827: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12828: }
12829: if ($encconfig{$itemid}{'secret'} ne '') {
12830: $resulttext .= '<li>'.$lt{'secret'}.': ';
12831: my $num = length($encconfig{$itemid}{'secret'});
12832: $resulttext .= ('*'x$num).'</li>';
12833: }
1.345 raeburn 12834: if ($confhash{$itemid}{'requser'}) {
12835: if ($confhash{$itemid}{'mapuser'}) {
12836: my $shownmapuser;
12837: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12838: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12839: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12840: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12841: } else {
12842: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12843: }
1.345 raeburn 12844: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12845: }
1.345 raeburn 12846: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12847: my $rolemaps;
12848: foreach my $role (@ltiroles) {
12849: if ($confhash{$itemid}{'maproles'}{$role}) {
12850: $rolemaps .= (' 'x2).$role.'='.
12851: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12852: 'Course').',';
12853: }
12854: }
12855: if ($rolemaps) {
12856: $rolemaps =~ s/,$//;
12857: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12858: }
12859: }
12860: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12861: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12862: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12863: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12864: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12865: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12866: } else {
12867: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12868: $confhash{$itemid}{'lcauth'});
12869: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12870: $resulttext .= '; '.&mt('a randomly generated password will be created');
12871: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12872: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12873: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12874: }
12875: } else {
12876: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12877: }
12878: }
12879: $resulttext .= '</li>';
12880: } else {
12881: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12882: }
1.320 raeburn 12883: }
1.345 raeburn 12884: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12885: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12886: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12887: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12888: } else {
1.345 raeburn 12889: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12890: }
1.320 raeburn 12891: }
1.345 raeburn 12892: if ($confhash{$itemid}{'mapcrs'}) {
12893: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12894: }
12895: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12896: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12897: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12898: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12899: '</li>';
12900: } else {
12901: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12902: }
1.325 raeburn 12903: }
1.345 raeburn 12904: if ($confhash{$itemid}{'makecrs'}) {
12905: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12906: } else {
1.345 raeburn 12907: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12908: }
1.345 raeburn 12909: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
12910: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
12911: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
12912: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
12913: '</li>';
12914: } else {
12915: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
12916: }
1.320 raeburn 12917: }
1.345 raeburn 12918: if ($confhash{$itemid}{'section'}) {
12919: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
12920: $resulttext .= '<li>'.&mt('User section from standard field:').
12921: ' (course_section_sourcedid)'.'</li>';
12922: } else {
12923: $resulttext .= '<li>'.&mt('User section from:').' '.
12924: $confhash{$itemid}{'section'}.'</li>';
12925: }
1.320 raeburn 12926: } else {
1.345 raeburn 12927: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 12928: }
1.345 raeburn 12929: foreach my $item ('passback','roster','topmenu','inlinemenu') {
12930: $resulttext .= '<li>'.$lt{$item}.': ';
12931: if ($confhash{$itemid}{$item}) {
12932: $resulttext .= &mt('Yes');
12933: if ($item eq 'passback') {
12934: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
12935: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
12936: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
12937: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
12938: }
1.337 raeburn 12939: }
1.345 raeburn 12940: } else {
12941: $resulttext .= &mt('No');
1.337 raeburn 12942: }
1.345 raeburn 12943: $resulttext .= '</li>';
1.320 raeburn 12944: }
1.345 raeburn 12945: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
12946: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
12947: $resulttext .= '<li>'.&mt('Menu items:').' '.
12948: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
12949: } else {
12950: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
12951: }
1.326 raeburn 12952: }
12953: }
1.320 raeburn 12954: $resulttext .= '</ul></li>';
12955: }
12956: }
12957: $resulttext .= '</ul>';
12958: } else {
12959: $resulttext = &mt('No changes made.');
12960: }
12961: } else {
12962: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12963: }
12964: if ($errors) {
12965: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12966: $errors.'</ul>';
12967: }
12968: return $resulttext;
12969: }
12970:
12971: sub get_lti_id {
12972: my ($domain,$consumer) = @_;
12973: # get lock on lti db
12974: my $lockhash = {
12975: lock => $env{'user.name'}.
12976: ':'.$env{'user.domain'},
12977: };
12978: my $tries = 0;
12979: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12980: my ($id,$error);
12981:
12982: while (($gotlock ne 'ok') && ($tries<10)) {
12983: $tries ++;
12984: sleep (0.1);
12985: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
12986: }
12987: if ($gotlock eq 'ok') {
12988: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
12989: if ($currids{'lock'}) {
12990: delete($currids{'lock'});
12991: if (keys(%currids)) {
12992: my @curr = sort { $a <=> $b } keys(%currids);
12993: if ($curr[-1] =~ /^\d+$/) {
12994: $id = 1 + $curr[-1];
12995: }
12996: } else {
12997: $id = 1;
12998: }
12999: if ($id) {
13000: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
13001: $error = 'nostore';
13002: }
13003: } else {
13004: $error = 'nonumber';
13005: }
13006: }
13007: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
13008: } else {
13009: $error = 'nolock';
13010: }
13011: return ($id,$error);
13012: }
13013:
1.3 raeburn 13014: sub modify_autoenroll {
1.205 raeburn 13015: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 13016: my ($resulttext,%changes);
13017: my %currautoenroll;
13018: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13019: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13020: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13021: }
13022: }
13023: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13024: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13025: sender => 'Sender for notification messages',
1.274 raeburn 13026: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
13027: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13028: my @offon = ('off','on');
1.17 raeburn 13029: my $sender_uname = $env{'form.sender_uname'};
13030: my $sender_domain = $env{'form.sender_domain'};
13031: if ($sender_domain eq '') {
13032: $sender_uname = '';
13033: } elsif ($sender_uname eq '') {
13034: $sender_domain = '';
13035: }
1.129 raeburn 13036: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 13037: my $failsafe = $env{'form.autoenroll_failsafe'};
13038: $failsafe =~ s{^\s+|\s+$}{}g;
13039: if ($failsafe =~ /\D/) {
13040: undef($failsafe);
13041: }
1.1 raeburn 13042: my %autoenrollhash = (
1.129 raeburn 13043: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13044: 'sender_uname' => $sender_uname,
13045: 'sender_domain' => $sender_domain,
13046: 'co-owners' => $coowners,
1.274 raeburn 13047: 'autofailsafe' => $failsafe,
1.1 raeburn 13048: }
13049: );
1.4 raeburn 13050: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13051: $dom);
1.1 raeburn 13052: if ($putresult eq 'ok') {
13053: if (exists($currautoenroll{'run'})) {
13054: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13055: $changes{'run'} = 1;
13056: }
13057: } elsif ($autorun) {
13058: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13059: $changes{'run'} = 1;
1.1 raeburn 13060: }
13061: }
1.17 raeburn 13062: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13063: $changes{'sender'} = 1;
13064: }
1.17 raeburn 13065: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13066: $changes{'sender'} = 1;
13067: }
1.129 raeburn 13068: if ($currautoenroll{'co-owners'} ne '') {
13069: if ($currautoenroll{'co-owners'} ne $coowners) {
13070: $changes{'coowners'} = 1;
13071: }
13072: } elsif ($coowners) {
13073: $changes{'coowners'} = 1;
1.274 raeburn 13074: }
13075: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
13076: $changes{'autofailsafe'} = 1;
13077: }
1.1 raeburn 13078: if (keys(%changes) > 0) {
13079: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13080: if ($changes{'run'}) {
1.1 raeburn 13081: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13082: }
13083: if ($changes{'sender'}) {
1.17 raeburn 13084: if ($sender_uname eq '' || $sender_domain eq '') {
13085: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13086: } else {
13087: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13088: }
1.1 raeburn 13089: }
1.129 raeburn 13090: if ($changes{'coowners'}) {
13091: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13092: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13093: if (ref($lastactref) eq 'HASH') {
13094: $lastactref->{'domainconfig'} = 1;
13095: }
1.129 raeburn 13096: }
1.274 raeburn 13097: if ($changes{'autofailsafe'}) {
13098: if ($failsafe ne '') {
1.299 raeburn 13099: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 13100: } else {
1.299 raeburn 13101: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 13102: }
13103: &Apache::lonnet::get_domain_defaults($dom,1);
13104: if (ref($lastactref) eq 'HASH') {
13105: $lastactref->{'domdefaults'} = 1;
13106: }
13107: }
1.1 raeburn 13108: $resulttext .= '</ul>';
13109: } else {
13110: $resulttext = &mt('No changes made to auto-enrollment settings');
13111: }
13112: } else {
1.11 albertel 13113: $resulttext = '<span class="LC_error">'.
13114: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13115: }
1.3 raeburn 13116: return $resulttext;
1.1 raeburn 13117: }
13118:
13119: sub modify_autoupdate {
1.3 raeburn 13120: my ($dom,%domconfig) = @_;
1.1 raeburn 13121: my ($resulttext,%currautoupdate,%fields,%changes);
13122: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13123: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13124: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13125: }
13126: }
13127: my @offon = ('off','on');
13128: my %title = &Apache::lonlocal::texthash (
13129: run => 'Auto-update:',
13130: classlists => 'Updates to user information in classlists?'
13131: );
1.44 raeburn 13132: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13133: my %fieldtitles = &Apache::lonlocal::texthash (
13134: id => 'Student/Employee ID',
1.20 raeburn 13135: permanentemail => 'E-mail address',
1.1 raeburn 13136: lastname => 'Last Name',
13137: firstname => 'First Name',
13138: middlename => 'Middle Name',
1.132 raeburn 13139: generation => 'Generation',
1.1 raeburn 13140: );
1.142 raeburn 13141: $othertitle = &mt('All users');
1.1 raeburn 13142: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13143: $othertitle = &mt('Other users');
1.1 raeburn 13144: }
13145: foreach my $key (keys(%env)) {
13146: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13147: my ($usertype,$item) = ($1,$2);
13148: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13149: if ($usertype eq 'default') {
13150: push(@{$fields{$1}},$2);
13151: } elsif (ref($types) eq 'ARRAY') {
13152: if (grep(/^\Q$usertype\E$/,@{$types})) {
13153: push(@{$fields{$1}},$2);
13154: }
13155: }
13156: }
1.1 raeburn 13157: }
13158: }
1.131 raeburn 13159: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13160: @lockablenames = sort(@lockablenames);
13161: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13162: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13163: if (@changed) {
13164: $changes{'lockablenames'} = 1;
13165: }
13166: } else {
13167: if (@lockablenames) {
13168: $changes{'lockablenames'} = 1;
13169: }
13170: }
1.1 raeburn 13171: my %updatehash = (
13172: autoupdate => { run => $env{'form.autoupdate_run'},
13173: classlists => $env{'form.classlists'},
13174: fields => {%fields},
1.131 raeburn 13175: lockablenames => \@lockablenames,
1.1 raeburn 13176: }
13177: );
13178: foreach my $key (keys(%currautoupdate)) {
13179: if (($key eq 'run') || ($key eq 'classlists')) {
13180: if (exists($updatehash{autoupdate}{$key})) {
13181: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13182: $changes{$key} = 1;
13183: }
13184: }
13185: } elsif ($key eq 'fields') {
13186: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13187: foreach my $item (@{$types},'default') {
1.1 raeburn 13188: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13189: my $change = 0;
13190: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13191: if (!exists($fields{$item})) {
13192: $change = 1;
1.132 raeburn 13193: last;
1.1 raeburn 13194: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13195: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13196: $change = 1;
1.132 raeburn 13197: last;
1.1 raeburn 13198: }
13199: }
13200: }
13201: if ($change) {
13202: push(@{$changes{$key}},$item);
13203: }
1.26 raeburn 13204: }
1.1 raeburn 13205: }
13206: }
1.131 raeburn 13207: } elsif ($key eq 'lockablenames') {
13208: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13209: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13210: if (@changed) {
13211: $changes{'lockablenames'} = 1;
13212: }
13213: } else {
13214: if (@lockablenames) {
13215: $changes{'lockablenames'} = 1;
13216: }
13217: }
13218: }
13219: }
13220: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13221: if (@lockablenames) {
13222: $changes{'lockablenames'} = 1;
1.1 raeburn 13223: }
13224: }
1.26 raeburn 13225: foreach my $item (@{$types},'default') {
13226: if (defined($fields{$item})) {
13227: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13228: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13229: my $change = 0;
13230: if (ref($fields{$item}) eq 'ARRAY') {
13231: foreach my $type (@{$fields{$item}}) {
13232: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13233: $change = 1;
13234: last;
13235: }
13236: }
13237: }
13238: if ($change) {
13239: push(@{$changes{'fields'}},$item);
13240: }
13241: } else {
1.26 raeburn 13242: push(@{$changes{'fields'}},$item);
13243: }
13244: } else {
13245: push(@{$changes{'fields'}},$item);
1.1 raeburn 13246: }
13247: }
13248: }
13249: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13250: $dom);
13251: if ($putresult eq 'ok') {
13252: if (keys(%changes) > 0) {
13253: $resulttext = &mt('Changes made:').'<ul>';
13254: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13255: if ($key eq 'lockablenames') {
13256: $resulttext .= '<li>';
13257: if (@lockablenames) {
13258: $usertypes->{'default'} = $othertitle;
13259: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13260: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13261: } else {
13262: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13263: }
13264: $resulttext .= '</li>';
13265: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13266: foreach my $item (@{$changes{$key}}) {
13267: my @newvalues;
13268: foreach my $type (@{$fields{$item}}) {
13269: push(@newvalues,$fieldtitles{$type});
13270: }
1.3 raeburn 13271: my $newvaluestr;
13272: if (@newvalues > 0) {
13273: $newvaluestr = join(', ',@newvalues);
13274: } else {
13275: $newvaluestr = &mt('none');
1.6 raeburn 13276: }
1.1 raeburn 13277: if ($item eq 'default') {
1.26 raeburn 13278: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13279: } else {
1.26 raeburn 13280: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13281: }
13282: }
13283: } else {
13284: my $newvalue;
13285: if ($key eq 'run') {
13286: $newvalue = $offon[$env{'form.autoupdate_run'}];
13287: } else {
13288: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13289: }
1.1 raeburn 13290: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13291: }
13292: }
13293: $resulttext .= '</ul>';
13294: } else {
1.3 raeburn 13295: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13296: }
13297: } else {
1.11 albertel 13298: $resulttext = '<span class="LC_error">'.
13299: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13300: }
1.3 raeburn 13301: return $resulttext;
1.1 raeburn 13302: }
13303:
1.125 raeburn 13304: sub modify_autocreate {
13305: my ($dom,%domconfig) = @_;
13306: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13307: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13308: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13309: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13310: }
13311: }
13312: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13313: req => 'Auto-creation of validated requests for official courses',
13314: xmldc => 'Identity of course creator of courses from XML files',
13315: );
13316: my @types = ('xml','req');
13317: foreach my $item (@types) {
13318: $newvals{$item} = $env{'form.autocreate_'.$item};
13319: $newvals{$item} =~ s/\D//g;
13320: $newvals{$item} = 0 if ($newvals{$item} eq '');
13321: }
13322: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 13323: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13324: unless (exists($domcoords{$newvals{'xmldc'}})) {
13325: $newvals{'xmldc'} = '';
13326: }
13327: %autocreatehash = (
13328: autocreate => { xml => $newvals{'xml'},
13329: req => $newvals{'req'},
13330: }
13331: );
13332: if ($newvals{'xmldc'} ne '') {
13333: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13334: }
13335: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13336: $dom);
13337: if ($putresult eq 'ok') {
13338: my @items = @types;
13339: if ($newvals{'xml'}) {
13340: push(@items,'xmldc');
13341: }
13342: foreach my $item (@items) {
13343: if (exists($currautocreate{$item})) {
13344: if ($currautocreate{$item} ne $newvals{$item}) {
13345: $changes{$item} = 1;
13346: }
13347: } elsif ($newvals{$item}) {
13348: $changes{$item} = 1;
13349: }
13350: }
13351: if (keys(%changes) > 0) {
13352: my @offon = ('off','on');
13353: $resulttext = &mt('Changes made:').'<ul>';
13354: foreach my $item (@types) {
13355: if ($changes{$item}) {
13356: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 13357: $resulttext .= '<li>'.
13358: &mt("$title{$item} set to [_1]$newtxt [_2]",
13359: '<b>','</b>').
13360: '</li>';
1.125 raeburn 13361: }
13362: }
13363: if ($changes{'xmldc'}) {
13364: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13365: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 13366: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13367: }
13368: $resulttext .= '</ul>';
13369: } else {
13370: $resulttext = &mt('No changes made to auto-creation settings');
13371: }
13372: } else {
13373: $resulttext = '<span class="LC_error">'.
13374: &mt('An error occurred: [_1]',$putresult).'</span>';
13375: }
13376: return $resulttext;
13377: }
13378:
1.23 raeburn 13379: sub modify_directorysrch {
1.295 raeburn 13380: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13381: my ($resulttext,%changes);
13382: my %currdirsrch;
13383: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13384: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13385: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13386: }
13387: }
1.277 raeburn 13388: my %title = ( available => 'Institutional directory search available',
13389: localonly => 'Other domains can search institution',
13390: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 13391: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13392: searchby => 'Search types',
13393: searchtypes => 'Search latitude');
13394: my @offon = ('off','on');
1.24 raeburn 13395: my @otherdoms = ('Yes','No');
1.23 raeburn 13396:
1.25 raeburn 13397: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13398: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13399: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13400:
1.44 raeburn 13401: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13402: if (keys(%{$usertypes}) == 0) {
13403: @cansearch = ('default');
13404: } else {
13405: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13406: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13407: if (!grep(/^\Q$type\E$/,@cansearch)) {
13408: push(@{$changes{'cansearch'}},$type);
13409: }
1.23 raeburn 13410: }
1.26 raeburn 13411: foreach my $type (@cansearch) {
13412: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13413: push(@{$changes{'cansearch'}},$type);
13414: }
1.23 raeburn 13415: }
1.26 raeburn 13416: } else {
13417: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13418: }
13419: }
13420:
13421: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13422: foreach my $by (@{$currdirsrch{'searchby'}}) {
13423: if (!grep(/^\Q$by\E$/,@searchby)) {
13424: push(@{$changes{'searchby'}},$by);
13425: }
13426: }
13427: foreach my $by (@searchby) {
13428: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13429: push(@{$changes{'searchby'}},$by);
13430: }
13431: }
13432: } else {
13433: push(@{$changes{'searchby'}},@searchby);
13434: }
1.25 raeburn 13435:
13436: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13437: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13438: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13439: push(@{$changes{'searchtypes'}},$type);
13440: }
13441: }
13442: foreach my $type (@searchtypes) {
13443: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13444: push(@{$changes{'searchtypes'}},$type);
13445: }
13446: }
13447: } else {
13448: if (exists($currdirsrch{'searchtypes'})) {
13449: foreach my $type (@searchtypes) {
13450: if ($type ne $currdirsrch{'searchtypes'}) {
13451: push(@{$changes{'searchtypes'}},$type);
13452: }
13453: }
13454: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13455: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13456: }
13457: } else {
13458: push(@{$changes{'searchtypes'}},@searchtypes);
13459: }
13460: }
13461:
1.23 raeburn 13462: my %dirsrch_hash = (
13463: directorysrch => { available => $env{'form.dirsrch_available'},
13464: cansearch => \@cansearch,
1.277 raeburn 13465: localonly => $env{'form.dirsrch_instlocalonly'},
13466: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13467: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13468: searchby => \@searchby,
1.25 raeburn 13469: searchtypes => \@searchtypes,
1.23 raeburn 13470: }
13471: );
13472: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13473: $dom);
13474: if ($putresult eq 'ok') {
13475: if (exists($currdirsrch{'available'})) {
13476: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13477: $changes{'available'} = 1;
13478: }
13479: } else {
13480: if ($env{'form.dirsrch_available'} eq '1') {
13481: $changes{'available'} = 1;
13482: }
13483: }
1.277 raeburn 13484: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 13485: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13486: $changes{'lcavailable'} = 1;
13487: }
1.277 raeburn 13488: } else {
13489: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13490: $changes{'lcavailable'} = 1;
13491: }
13492: }
1.24 raeburn 13493: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 13494: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13495: $changes{'localonly'} = 1;
13496: }
1.24 raeburn 13497: } else {
1.277 raeburn 13498: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 13499: $changes{'localonly'} = 1;
13500: }
13501: }
1.277 raeburn 13502: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 13503: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13504: $changes{'lclocalonly'} = 1;
13505: }
1.277 raeburn 13506: } else {
13507: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13508: $changes{'lclocalonly'} = 1;
13509: }
13510: }
1.23 raeburn 13511: if (keys(%changes) > 0) {
13512: $resulttext = &mt('Changes made:').'<ul>';
13513: if ($changes{'available'}) {
13514: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13515: }
1.277 raeburn 13516: if ($changes{'lcavailable'}) {
13517: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13518: }
1.24 raeburn 13519: if ($changes{'localonly'}) {
1.277 raeburn 13520: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 13521: }
1.277 raeburn 13522: if ($changes{'lclocalonly'}) {
13523: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 13524: }
1.23 raeburn 13525: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13526: my $chgtext;
1.26 raeburn 13527: if (ref($usertypes) eq 'HASH') {
13528: if (keys(%{$usertypes}) > 0) {
13529: foreach my $type (@{$types}) {
13530: if (grep(/^\Q$type\E$/,@cansearch)) {
13531: $chgtext .= $usertypes->{$type}.'; ';
13532: }
13533: }
13534: if (grep(/^default$/,@cansearch)) {
13535: $chgtext .= $othertitle;
13536: } else {
13537: $chgtext =~ s/\; $//;
13538: }
1.210 raeburn 13539: $resulttext .=
1.178 raeburn 13540: '<li>'.
13541: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13542: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13543: '</li>';
1.23 raeburn 13544: }
13545: }
13546: }
13547: if (ref($changes{'searchby'}) eq 'ARRAY') {
13548: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13549: my $chgtext;
13550: foreach my $type (@{$titleorder}) {
13551: if (grep(/^\Q$type\E$/,@searchby)) {
13552: if (defined($searchtitles->{$type})) {
13553: $chgtext .= $searchtitles->{$type}.'; ';
13554: }
13555: }
13556: }
13557: $chgtext =~ s/\; $//;
13558: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13559: }
1.25 raeburn 13560: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13561: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13562: my $chgtext;
13563: foreach my $type (@{$srchtypeorder}) {
13564: if (grep(/^\Q$type\E$/,@searchtypes)) {
13565: if (defined($srchtypes_desc->{$type})) {
13566: $chgtext .= $srchtypes_desc->{$type}.'; ';
13567: }
13568: }
13569: }
13570: $chgtext =~ s/\; $//;
1.178 raeburn 13571: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13572: }
13573: $resulttext .= '</ul>';
1.295 raeburn 13574: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13575: if (ref($lastactref) eq 'HASH') {
13576: $lastactref->{'directorysrch'} = 1;
13577: }
1.23 raeburn 13578: } else {
1.277 raeburn 13579: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13580: }
13581: } else {
13582: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13583: &mt('An error occurred: [_1]',$putresult).'</span>';
13584: }
13585: return $resulttext;
13586: }
13587:
1.28 raeburn 13588: sub modify_contacts {
1.205 raeburn 13589: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13590: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13591: if (ref($domconfig{'contacts'}) eq 'HASH') {
13592: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13593: $currsetting{$key} = $domconfig{'contacts'}{$key};
13594: }
13595: }
1.286 raeburn 13596: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13597: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13598: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 13599: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 13600: my @toggles = ('reporterrors','reportupdates','reportstatus');
13601: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13602: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13603: foreach my $type (@mailings) {
13604: @{$newsetting{$type}} =
13605: &Apache::loncommon::get_env_multiple('form.'.$type);
13606: foreach my $item (@contacts) {
13607: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13608: $contacts_hash{contacts}{$type}{$item} = 1;
13609: } else {
13610: $contacts_hash{contacts}{$type}{$item} = 0;
13611: }
1.289 raeburn 13612: }
1.28 raeburn 13613: $others{$type} = $env{'form.'.$type.'_others'};
13614: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13615: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13616: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13617: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13618: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13619: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13620: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13621: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13622: }
1.134 raeburn 13623: }
1.28 raeburn 13624: }
13625: foreach my $item (@contacts) {
13626: $to{$item} = $env{'form.'.$item};
13627: $contacts_hash{'contacts'}{$item} = $to{$item};
13628: }
1.203 raeburn 13629: foreach my $item (@toggles) {
13630: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13631: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13632: }
13633: }
1.340 raeburn 13634: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13635: foreach my $item (@lonstatus) {
13636: if ($item eq 'excluded') {
13637: my (%serverhomes,@excluded);
13638: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13639: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13640: if (@possexcluded) {
13641: foreach my $id (sort(@possexcluded)) {
13642: if ($serverhomes{$id}) {
13643: push(@excluded,$id);
13644: }
13645: }
13646: }
13647: if (@excluded) {
13648: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13649: }
13650: } elsif ($item eq 'weights') {
13651: foreach my $type ('E','W','N') {
13652: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13653: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13654: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13655: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13656: $env{'form.error'.$item.'_'.$type};
13657: }
13658: }
13659: }
13660: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13661: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13662: if ($env{'form.error'.$item} =~ /^\d+$/) {
13663: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13664: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13665: }
13666: }
13667: }
13668: }
1.286 raeburn 13669: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13670: foreach my $field (@{$fields}) {
13671: if (ref($possoptions->{$field}) eq 'ARRAY') {
13672: my $value = $env{'form.helpform_'.$field};
13673: $value =~ s/^\s+|\s+$//g;
13674: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13675: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13676: if ($field eq 'screenshot') {
13677: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13678: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13679: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13680: }
13681: }
13682: }
13683: }
13684: }
13685: }
1.315 raeburn 13686: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13687: my (@statuses,%usertypeshash,@overrides);
13688: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13689: @statuses = @{$types};
13690: if (ref($usertypes) eq 'HASH') {
13691: %usertypeshash = %{$usertypes};
13692: }
13693: }
13694: if (@statuses) {
13695: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13696: foreach my $type (@possoverrides) {
13697: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13698: push(@overrides,$type);
13699: }
13700: }
13701: if (@overrides) {
13702: foreach my $type (@overrides) {
13703: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13704: foreach my $item (@contacts) {
13705: if (grep(/^\Q$item\E$/,@standard)) {
13706: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13707: $newsetting{'override_'.$type}{$item} = 1;
13708: } else {
13709: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13710: $newsetting{'override_'.$type}{$item} = 0;
13711: }
13712: }
13713: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13714: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13715: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13716: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13717: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13718: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13719: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13720: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13721: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13722: }
13723: }
13724: }
13725: }
1.28 raeburn 13726: if (keys(%currsetting) > 0) {
13727: foreach my $item (@contacts) {
13728: if ($to{$item} ne $currsetting{$item}) {
13729: $changes{$item} = 1;
13730: }
13731: }
13732: foreach my $type (@mailings) {
13733: foreach my $item (@contacts) {
13734: if (ref($currsetting{$type}) eq 'HASH') {
13735: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13736: push(@{$changes{$type}},$item);
13737: }
13738: } else {
13739: push(@{$changes{$type}},@{$newsetting{$type}});
13740: }
13741: }
13742: if ($others{$type} ne $currsetting{$type}{'others'}) {
13743: push(@{$changes{$type}},'others');
13744: }
1.289 raeburn 13745: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13746: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13747: push(@{$changes{$type}},'bcc');
13748: }
1.286 raeburn 13749: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13750: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13751: push(@{$changes{$type}},'include');
13752: }
13753: }
13754: }
13755: if (ref($fields) eq 'ARRAY') {
13756: if (ref($currsetting{'helpform'}) eq 'HASH') {
13757: foreach my $field (@{$fields}) {
13758: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13759: push(@{$changes{'helpform'}},$field);
13760: }
13761: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13762: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13763: push(@{$changes{'helpform'}},'maxsize');
13764: }
13765: }
13766: }
13767: } else {
13768: foreach my $field (@{$fields}) {
13769: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13770: push(@{$changes{'helpform'}},$field);
13771: }
13772: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13773: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13774: push(@{$changes{'helpform'}},'maxsize');
13775: }
13776: }
13777: }
1.134 raeburn 13778: }
1.28 raeburn 13779: }
1.315 raeburn 13780: if (@statuses) {
13781: if (ref($currsetting{'overrides'}) eq 'HASH') {
13782: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13783: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13784: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13785: foreach my $item (@contacts,'bcc','others','include') {
13786: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13787: push(@{$changes{'overrides'}},$key);
13788: last;
13789: }
13790: }
13791: } else {
13792: push(@{$changes{'overrides'}},$key);
13793: }
13794: }
13795: }
13796: foreach my $key (@overrides) {
13797: unless (exists($currsetting{'overrides'}{$key})) {
13798: push(@{$changes{'overrides'}},$key);
13799: }
13800: }
13801: } else {
13802: foreach my $key (@overrides) {
13803: push(@{$changes{'overrides'}},$key);
13804: }
13805: }
13806: }
1.340 raeburn 13807: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13808: foreach my $key ('excluded','weights','threshold','sysmail') {
13809: if ($key eq 'excluded') {
13810: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13811: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13812: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13813: (@{$currsetting{'lonstatus'}{$key}})) {
13814: my @diffs =
13815: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13816: $currsetting{'lonstatus'}{$key});
13817: if (@diffs) {
13818: push(@{$changes{'lonstatus'}},$key);
13819: }
13820: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13821: push(@{$changes{'lonstatus'}},$key);
13822: }
13823: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13824: (@{$currsetting{'lonstatus'}{$key}})) {
13825: push(@{$changes{'lonstatus'}},$key);
13826: }
13827: } elsif ($key eq 'weights') {
13828: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13829: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13830: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13831: foreach my $type ('E','W','N','U') {
1.340 raeburn 13832: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13833: $currsetting{'lonstatus'}{$key}{$type}) {
13834: push(@{$changes{'lonstatus'}},$key);
13835: last;
13836: }
13837: }
13838: } else {
1.341 raeburn 13839: foreach my $type ('E','W','N','U') {
1.340 raeburn 13840: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13841: push(@{$changes{'lonstatus'}},$key);
13842: last;
13843: }
13844: }
13845: }
13846: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13847: foreach my $type ('E','W','N','U') {
1.340 raeburn 13848: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13849: push(@{$changes{'lonstatus'}},$key);
13850: last;
13851: }
13852: }
13853: }
13854: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13855: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13856: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13857: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13858: push(@{$changes{'lonstatus'}},$key);
13859: }
13860: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13861: push(@{$changes{'lonstatus'}},$key);
13862: }
13863: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13864: push(@{$changes{'lonstatus'}},$key);
13865: }
13866: }
13867: }
13868: } else {
13869: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13870: foreach my $key ('excluded','weights','threshold','sysmail') {
13871: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13872: push(@{$changes{'lonstatus'}},$key);
13873: }
13874: }
13875: }
13876: }
1.28 raeburn 13877: } else {
13878: my %default;
13879: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13880: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13881: $default{'errormail'} = 'adminemail';
13882: $default{'packagesmail'} = 'adminemail';
13883: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13884: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13885: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13886: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13887: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 13888: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13889: foreach my $item (@contacts) {
13890: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13891: $changes{$item} = 1;
1.203 raeburn 13892: }
1.28 raeburn 13893: }
13894: foreach my $type (@mailings) {
13895: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13896: push(@{$changes{$type}},@{$newsetting{$type}});
13897: }
13898: if ($others{$type} ne '') {
13899: push(@{$changes{$type}},'others');
1.134 raeburn 13900: }
1.286 raeburn 13901: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13902: if ($bcc{$type} ne '') {
13903: push(@{$changes{$type}},'bcc');
13904: }
1.286 raeburn 13905: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
13906: push(@{$changes{$type}},'include');
13907: }
1.134 raeburn 13908: }
1.28 raeburn 13909: }
1.286 raeburn 13910: if (ref($fields) eq 'ARRAY') {
13911: foreach my $field (@{$fields}) {
13912: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13913: push(@{$changes{'helpform'}},$field);
13914: }
13915: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13916: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13917: push(@{$changes{'helpform'}},'maxsize');
13918: }
13919: }
13920: }
1.289 raeburn 13921: }
1.340 raeburn 13922: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13923: foreach my $key ('excluded','weights','threshold','sysmail') {
13924: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13925: push(@{$changes{'lonstatus'}},$key);
13926: }
13927: }
13928: }
1.28 raeburn 13929: }
1.203 raeburn 13930: foreach my $item (@toggles) {
13931: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
13932: $changes{$item} = 1;
13933: } elsif ((!$env{'form.'.$item}) &&
13934: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
13935: $changes{$item} = 1;
13936: }
13937: }
1.28 raeburn 13938: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
13939: $dom);
13940: if ($putresult eq 'ok') {
13941: if (keys(%changes) > 0) {
1.205 raeburn 13942: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13943: if (ref($lastactref) eq 'HASH') {
13944: $lastactref->{'domainconfig'} = 1;
13945: }
1.28 raeburn 13946: my ($titles,$short_titles) = &contact_titles();
13947: $resulttext = &mt('Changes made:').'<ul>';
13948: foreach my $item (@contacts) {
13949: if ($changes{$item}) {
13950: $resulttext .= '<li>'.$titles->{$item}.
13951: &mt(' set to: ').
13952: '<span class="LC_cusr_emph">'.
13953: $to{$item}.'</span></li>';
13954: }
13955: }
13956: foreach my $type (@mailings) {
13957: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 13958: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 13959: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 13960: } else {
13961: $resulttext .= '<li>'.$titles->{$type}.': ';
13962: }
1.28 raeburn 13963: my @text;
13964: foreach my $item (@{$newsetting{$type}}) {
13965: push(@text,$short_titles->{$item});
13966: }
13967: if ($others{$type} ne '') {
13968: push(@text,$others{$type});
13969: }
1.286 raeburn 13970: if (@text) {
13971: $resulttext .= '<span class="LC_cusr_emph">'.
13972: join(', ',@text).'</span>';
13973: }
13974: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13975: if ($bcc{$type} ne '') {
1.286 raeburn 13976: my $bcctext;
13977: if (@text) {
1.289 raeburn 13978: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 13979: } else {
13980: $bcctext = '(Bcc)';
13981: }
13982: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
13983: } elsif (!@text) {
13984: $resulttext .= &mt('No one');
13985: }
1.289 raeburn 13986: if ($includestr{$type} ne '') {
1.286 raeburn 13987: if ($includeloc{$type} eq 'b') {
13988: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
13989: } elsif ($includeloc{$type} eq 's') {
13990: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
13991: }
1.134 raeburn 13992: }
1.286 raeburn 13993: } elsif (!@text) {
13994: $resulttext .= &mt('No recipients');
1.134 raeburn 13995: }
13996: $resulttext .= '</li>';
1.28 raeburn 13997: }
13998: }
1.315 raeburn 13999: if (ref($changes{'overrides'}) eq 'ARRAY') {
14000: my @deletions;
14001: foreach my $type (@{$changes{'overrides'}}) {
14002: if ($usertypeshash{$type}) {
14003: if (grep(/^\Q$type\E/,@overrides)) {
14004: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14005: $usertypeshash{$type}).'<ul><li>';
14006: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14007: my @text;
14008: foreach my $item (@contacts) {
14009: if ($newsetting{'override_'.$type}{$item}) {
14010: push(@text,$short_titles->{$item});
14011: }
14012: }
14013: if ($newsetting{'override_'.$type}{'others'} ne '') {
14014: push(@text,$newsetting{'override_'.$type}{'others'});
14015: }
14016:
14017: if (@text) {
14018: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14019: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14020: }
14021: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14022: my $bcctext;
14023: if (@text) {
14024: $bcctext = ' '.&mt('with Bcc to');
14025: } else {
14026: $bcctext = '(Bcc)';
14027: }
14028: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14029: } elsif (!@text) {
14030: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14031: }
14032: $resulttext .= '</li>';
14033: if ($newsetting{'override_'.$type}{'include'} ne '') {
14034: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14035: if ($loc eq 'b') {
14036: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14037: } elsif ($loc eq 's') {
14038: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14039: }
14040: }
14041: }
14042: $resulttext .= '</li></ul></li>';
14043: } else {
14044: push(@deletions,$usertypeshash{$type});
14045: }
14046: }
14047: }
14048: if (@deletions) {
14049: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14050: join(', ',@deletions)).'</li>';
14051: }
14052: }
1.203 raeburn 14053: my @offon = ('off','on');
1.340 raeburn 14054: my $corelink = &core_link_msu();
1.203 raeburn 14055: if ($changes{'reporterrors'}) {
14056: $resulttext .= '<li>'.
14057: &mt('E-mail error reports to [_1] set to "'.
14058: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 14059: $corelink).
1.203 raeburn 14060: '</li>';
14061: }
14062: if ($changes{'reportupdates'}) {
14063: $resulttext .= '<li>'.
14064: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14065: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 14066: $corelink).
1.203 raeburn 14067: '</li>';
14068: }
1.340 raeburn 14069: if ($changes{'reportstatus'}) {
14070: $resulttext .= '<li>'.
14071: &mt('E-mail status if errors above threshold to [_1] set to "'.
14072: $offon[$env{'form.reportstatus'}].'".',
14073: $corelink).
14074: '</li>';
14075: }
14076: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14077: $resulttext .= '<li>'.
14078: &mt('Nightly status check e-mail settings').':<ul>';
14079: my (%defval,%use_def,%shown);
14080: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14081: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14082: $defval{'weights'} =
1.341 raeburn 14083: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 14084: $defval{'excluded'} = &mt('None');
14085: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14086: foreach my $item ('threshold','sysmail','weights','excluded') {
14087: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14088: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14089: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14090: } elsif ($item eq 'weights') {
14091: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 14092: foreach my $type ('E','W','N','U') {
1.340 raeburn 14093: $shown{$item} .= $lonstatus_names->{$type}.'=';
14094: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14095: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14096: } else {
14097: $shown{$item} .= $lonstatus_defs->{$type};
14098: }
14099: $shown{$item} .= ', ';
14100: }
14101: $shown{$item} =~ s/, $//;
14102: } else {
14103: $shown{$item} = $defval{$item};
14104: }
14105: } elsif ($item eq 'excluded') {
14106: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14107: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14108: } else {
14109: $shown{$item} = $defval{$item};
14110: }
14111: }
14112: } else {
14113: $shown{$item} = $defval{$item};
14114: }
14115: }
14116: } else {
14117: foreach my $item ('threshold','weights','excluded','sysmail') {
14118: $shown{$item} = $defval{$item};
14119: }
14120: }
14121: foreach my $item ('threshold','weights','excluded','sysmail') {
14122: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14123: $shown{$item}).'</li>';
14124: }
14125: $resulttext .= '</ul></li>';
14126: }
1.286 raeburn 14127: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14128: my (@optional,@required,@unused,$maxsizechg);
14129: foreach my $field (@{$changes{'helpform'}}) {
14130: if ($field eq 'maxsize') {
14131: $maxsizechg = 1;
14132: next;
14133: }
14134: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 14135: push(@optional,$field);
1.286 raeburn 14136: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14137: push(@unused,$field);
14138: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 14139: push(@required,$field);
1.286 raeburn 14140: }
14141: }
14142: if (@optional) {
14143: $resulttext .= '<li>'.
14144: &mt('Help form fields changed to "Optional": [_1].',
14145: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14146: '</li>';
14147: }
14148: if (@required) {
14149: $resulttext .= '<li>'.
14150: &mt('Help form fields changed to "Required": [_1].',
14151: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14152: '</li>';
14153: }
14154: if (@unused) {
14155: $resulttext .= '<li>'.
14156: &mt('Help form fields changed to "Not shown": [_1].',
14157: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14158: '</li>';
14159: }
14160: if ($maxsizechg) {
14161: $resulttext .= '<li>'.
14162: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14163: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14164: '</li>';
14165: }
14166: }
1.28 raeburn 14167: $resulttext .= '</ul>';
14168: } else {
1.288 raeburn 14169: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14170: }
14171: } else {
14172: $resulttext = '<span class="LC_error">'.
14173: &mt('An error occurred: [_1].',$putresult).'</span>';
14174: }
14175: return $resulttext;
14176: }
14177:
1.357 raeburn 14178: sub modify_privacy {
14179: my ($dom,%domconfig) = @_;
14180: my ($resulttext,%current,%changes);
14181: if (ref($domconfig{'privacy'}) eq 'HASH') {
14182: %current = %{$domconfig{'privacy'}};
14183: }
14184: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
14185: my @items = ('domain','author','course','community');
14186: my %names = &Apache::lonlocal::texthash (
14187: domain => 'Assigned domain role(s)',
14188: author => 'Assigned co-author role(s)',
14189: course => 'Assigned course role(s)',
14190: community => 'Assigned community role',
14191: );
14192: my %roles = &Apache::lonlocal::texthash (
14193: domain => 'Domain role',
14194: author => 'Co-author role',
14195: course => 'Course role',
14196: community => 'Community role',
14197: );
14198: my %titles = &Apache::lonlocal::texthash (
14199: approval => 'Approval for role in different domain',
14200: othdom => 'User information available in other domain',
14201: priv => 'Information viewable by privileged user in same domain',
14202: unpriv => 'Information viewable by unprivileged user in same domain',
14203: instdom => 'Other domain shares institution/provider',
14204: extdom => 'Other domain has different institution/provider',
14205: none => 'Not allowed',
14206: user => 'User authorizes',
14207: domain => 'Domain Coordinator authorizes',
14208: auto => 'Unrestricted',
14209: );
14210: my %fieldnames = &Apache::lonlocal::texthash (
14211: id => 'Student/Employee ID',
14212: permanentemail => 'E-mail address',
14213: lastname => 'Last Name',
14214: firstname => 'First Name',
14215: middlename => 'Middle Name',
14216: generation => 'Generation',
14217: );
14218: my ($othertitle,$usertypes,$types) =
14219: &Apache::loncommon::sorted_inst_types($dom);
14220: my (%by_ip,%by_location,@intdoms,@instdoms);
14221: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14222:
14223: my %privacyhash = (
14224: 'approval' => {
14225: instdom => {},
14226: extdom => {},
14227: },
14228: 'othdom' => {},
14229: 'priv' => {},
14230: 'unpriv' => {},
14231: );
14232: foreach my $item (@items) {
14233: if (@instdoms > 1) {
14234: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
14235: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
14236: }
14237: if (ref($current{'approval'}) eq 'HASH') {
14238: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
14239: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
14240: $changes{'approval'} = 1;
14241: }
14242: }
14243: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
14244: $changes{'approval'} = 1;
14245: }
14246: }
14247: if (keys(%by_location) > 0) {
14248: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
14249: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
14250: }
14251: if (ref($current{'approval'}) eq 'HASH') {
14252: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
14253: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
14254: $changes{'approval'} = 1;
14255: }
14256: }
14257: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
14258: $changes{'approval'} = 1;
14259: }
14260: }
14261: foreach my $status ('priv','unpriv') {
14262: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
14263: my @newvalues;
14264: foreach my $field (@possibles) {
14265: if (grep(/^\Q$field\E$/,@fields)) {
14266: $privacyhash{$status}{$item}{$field} = 1;
14267: push(@newvalues,$field);
14268: }
14269: }
14270: @newvalues = sort(@newvalues);
14271: if (ref($current{$status}) eq 'HASH') {
14272: if (ref($current{$status}{$item}) eq 'HASH') {
14273: my @currvalues = sort(keys(%{$current{$status}{$item}}));
14274: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14275: if (@diffs > 0) {
14276: $changes{$status} = 1;
14277: }
14278: }
14279: } else {
14280: my @stdfields;
14281: foreach my $field (@fields) {
14282: if ($field eq 'id') {
14283: next if ($status eq 'unpriv');
14284: next if (($status eq 'priv') && ($item eq 'community'));
14285: }
14286: push(@stdfields,$field);
14287: }
14288: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14289: if (@diffs > 0) {
14290: $changes{$status} = 1;
14291: }
14292: }
14293: }
14294: }
14295: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
14296: my @statuses;
14297: if (ref($types) eq 'ARRAY') {
14298: @statuses = @{$types};
14299: }
14300: foreach my $type (@statuses,'default') {
14301: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
14302: my @newvalues;
14303: foreach my $field (sort(@possfields)) {
14304: if (grep(/^\Q$field\E$/,@fields)) {
14305: $privacyhash{'othdom'}{$type}{$field} = 1;
14306: push(@newvalues,$field);
14307: }
14308: }
14309: @newvalues = sort(@newvalues);
14310: if (ref($current{'othdom'}) eq 'HASH') {
14311: if (ref($current{'othdom'}{$type}) eq 'HASH') {
14312: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
14313: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14314: if (@diffs > 0) {
14315: $changes{'othdom'} = 1;
14316: }
14317: }
14318: } else {
14319: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
14320: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14321: if (@diffs > 0) {
14322: $changes{'othdom'} = 1;
14323: }
14324: }
14325: }
14326: }
14327: my %confighash = (
14328: privacy => \%privacyhash,
14329: );
14330: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14331: if ($putresult eq 'ok') {
14332: if (keys(%changes) > 0) {
14333: $resulttext = &mt('Changes made: ').'<ul>';
14334: foreach my $key ('approval','othdom','priv','unpriv') {
14335: if ($changes{$key}) {
14336: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14337: if ($key eq 'approval') {
14338: if (keys(%{$privacyhash{$key}{instdom}})) {
14339: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
14340: foreach my $item (@items) {
14341: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
14342: }
14343: $resulttext .= '</ul></li>';
14344: }
14345: if (keys(%{$privacyhash{$key}{extdom}})) {
14346: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
14347: foreach my $item (@items) {
14348: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
14349: }
14350: $resulttext .= '</ul></li>';
14351: }
14352: } elsif ($key eq 'othdom') {
14353: my @statuses;
14354: if (ref($types) eq 'ARRAY') {
14355: @statuses = @{$types};
14356: }
14357: if (ref($privacyhash{$key}) eq 'HASH') {
14358: foreach my $status (@statuses,'default') {
14359: if ($status eq 'default') {
14360: $resulttext .= '<li>'.$othertitle.': ';
14361: } elsif (ref($usertypes) eq 'HASH') {
14362: $resulttext .= '<li>'.$usertypes->{$status}.': ';
14363: } else {
14364: next;
14365: }
14366: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
14367: if (keys(%{$privacyhash{$key}{$status}})) {
14368: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
14369: } else {
14370: $resulttext .= &mt('none');
14371: }
14372: }
14373: $resulttext .= '</li>';
14374: }
14375: }
14376: } else {
14377: foreach my $item (@items) {
14378: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
14379: $resulttext .= '<li>'.$names{$item}.': ';
14380: if (keys(%{$privacyhash{$key}{$item}})) {
14381: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
14382: } else {
14383: $resulttext .= &mt('none');
14384: }
14385: $resulttext .= '</li>';
14386: }
14387: }
14388: }
14389: $resulttext .= '</ul></li>';
14390: }
14391: }
14392: } else {
14393: $resulttext = &mt('No changes made to user information settings');
14394: }
14395: } else {
14396: $resulttext = '<span class="LC_error">'.
14397: &mt('An error occurred: [_1]',$putresult).'</span>';
14398: }
14399: return $resulttext;
14400: }
14401:
1.354 raeburn 14402: sub modify_passwords {
14403: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 14404: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14405: $updatedefaults,$updateconf);
1.354 raeburn 14406: my $customfn = 'resetpw.html';
14407: if (ref($domconfig{'passwords'}) eq 'HASH') {
14408: %current = %{$domconfig{'passwords'}};
14409: }
14410: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14411: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14412: if (ref($types) eq 'ARRAY') {
14413: @oktypes = @{$types};
14414: }
14415: push(@oktypes,'default');
14416:
14417: my %titles = &Apache::lonlocal::texthash (
14418: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14419: intauth_check => 'Check bcrypt cost if authenticated',
14420: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14421: permanent => 'Permanent e-mail address',
14422: critical => 'Critical notification address',
14423: notify => 'Notification address',
14424: min => 'Minimum password length',
14425: max => 'Maximum password length',
14426: chars => 'Required characters',
14427: expire => 'Password expiration (days)',
1.356 raeburn 14428: numsaved => 'Number of previous passwords to save',
1.354 raeburn 14429: reset => 'Resetting Forgotten Password',
14430: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14431: rules => 'Rules for LON-CAPA Passwords',
14432: crsownerchg => 'Course Owner Changing Student Passwords',
14433: username => 'Username',
14434: email => 'E-mail address',
14435: );
14436:
14437: #
14438: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14439: #
14440: my (%curr_defaults,%save_defaults);
14441: if (ref($domconfig{'defaults'}) eq 'HASH') {
14442: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14443: if ($key =~ /^intauth_(cost|check|switch)$/) {
14444: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14445: } else {
14446: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14447: }
14448: }
14449: }
14450: my %staticdefaults = (
14451: 'resetlink' => 2,
14452: 'resetcase' => \@oktypes,
14453: 'resetprelink' => 'both',
14454: 'resetemail' => ['critical','notify','permanent'],
14455: 'intauth_cost' => 10,
14456: 'intauth_check' => 0,
14457: 'intauth_switch' => 0,
14458: 'min' => 7,
14459: );
14460: foreach my $type (@oktypes) {
14461: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14462: }
14463: my $linklife = $env{'form.passwords_link'};
14464: $linklife =~ s/^\s+|\s+$//g;
14465: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14466: $newvalues{'resetlink'} = $linklife;
14467: if ($current{'resetlink'}) {
14468: if ($current{'resetlink'} ne $linklife) {
14469: $changes{'reset'} = 1;
14470: }
14471: } elsif (!exists($domconfig{passwords})) {
14472: if ($staticdefaults{'resetlink'} ne $linklife) {
14473: $changes{'reset'} = 1;
14474: }
14475: }
14476: } elsif ($current{'resetlink'}) {
14477: $changes{'reset'} = 1;
14478: }
14479: my @casesens;
14480: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14481: foreach my $case (sort(@posscase)) {
14482: if (grep(/^\Q$case\E$/,@oktypes)) {
14483: push(@casesens,$case);
14484: }
14485: }
14486: $newvalues{'resetcase'} = \@casesens;
14487: if (ref($current{'resetcase'}) eq 'ARRAY') {
14488: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14489: if (@diffs > 0) {
14490: $changes{'reset'} = 1;
14491: }
14492: } elsif (!exists($domconfig{passwords})) {
14493: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14494: if (@diffs > 0) {
14495: $changes{'reset'} = 1;
14496: }
14497: }
14498: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14499: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14500: if (exists($current{'resetprelink'})) {
14501: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14502: $changes{'reset'} = 1;
14503: }
14504: } elsif (!exists($domconfig{passwords})) {
14505: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14506: $changes{'reset'} = 1;
14507: }
14508: }
14509: } elsif ($current{'resetprelink'}) {
14510: $changes{'reset'} = 1;
14511: }
14512: foreach my $type (@oktypes) {
14513: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14514: my @postlink;
14515: foreach my $item (sort(@possplink)) {
14516: if ($item =~ /^(email|username)$/) {
14517: push(@postlink,$item);
14518: }
14519: }
14520: $newvalues{'resetpostlink'}{$type} = \@postlink;
14521: unless ($changes{'reset'}) {
14522: if (ref($current{'resetpostlink'}) eq 'HASH') {
14523: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14524: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14525: if (@diffs > 0) {
14526: $changes{'reset'} = 1;
14527: }
14528: } else {
14529: $changes{'reset'} = 1;
14530: }
14531: } elsif (!exists($domconfig{passwords})) {
14532: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14533: if (@diffs > 0) {
14534: $changes{'reset'} = 1;
14535: }
14536: }
14537: }
14538: }
14539: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14540: my @resetemail;
14541: foreach my $item (sort(@possemailsrc)) {
14542: if ($item =~ /^(permanent|critical|notify)$/) {
14543: push(@resetemail,$item);
14544: }
14545: }
14546: $newvalues{'resetemail'} = \@resetemail;
14547: unless ($changes{'reset'}) {
14548: if (ref($current{'resetemail'}) eq 'ARRAY') {
14549: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14550: if (@diffs > 0) {
14551: $changes{'reset'} = 1;
14552: }
14553: } elsif (!exists($domconfig{passwords})) {
14554: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14555: if (@diffs > 0) {
14556: $changes{'reset'} = 1;
14557: }
14558: }
14559: }
14560: if ($env{'form.passwords_stdtext'} == 0) {
14561: $newvalues{'resetremove'} = 1;
14562: unless ($current{'resetremove'}) {
14563: $changes{'reset'} = 1;
14564: }
14565: } elsif ($current{'resetremove'}) {
14566: $changes{'reset'} = 1;
14567: }
14568: if ($env{'form.passwords_customfile.filename'} ne '') {
14569: my $servadm = $r->dir_config('lonAdmEMail');
14570: my ($configuserok,$author_ok,$switchserver) =
14571: &config_check($dom,$confname,$servadm);
14572: my $error;
14573: if ($configuserok eq 'ok') {
14574: if ($switchserver) {
14575: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14576: } else {
14577: if ($author_ok eq 'ok') {
14578: my ($result,$customurl) =
14579: &publishlogo($r,'upload','passwords_customfile',$dom,
14580: $confname,'customtext/resetpw','','',$customfn);
14581: if ($result eq 'ok') {
14582: $newvalues{'resetcustom'} = $customurl;
14583: $changes{'reset'} = 1;
14584: } else {
14585: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14586: }
14587: } else {
14588: $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);
14589: }
14590: }
14591: } else {
14592: $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);
14593: }
14594: if ($error) {
14595: &Apache::lonnet::logthis($error);
14596: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14597: }
14598: } elsif ($current{'resetcustom'}) {
14599: if ($env{'form.passwords_custom_del'}) {
14600: $changes{'reset'} = 1;
14601: } else {
14602: $newvalues{'resetcustom'} = $current{'resetcustom'};
14603: }
14604: }
14605: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14606: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14607: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14608: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14609: $changes{'intauth'} = 1;
14610: }
14611: } else {
14612: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14613: }
14614: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14615: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14616: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14617: $changes{'intauth'} = 1;
14618: }
14619: } else {
14620: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14621: }
14622: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14623: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14624: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14625: $changes{'intauth'} = 1;
14626: }
14627: } else {
14628: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14629: }
14630: foreach my $item ('cost','check','switch') {
14631: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14632: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14633: $updatedefaults = 1;
14634: }
14635: }
1.356 raeburn 14636: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14637: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 14638: my $ruleok;
14639: if ($rule eq 'expire') {
14640: if ($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) {
1.359 raeburn 14641: $ruleok = 1;
1.356 raeburn 14642: }
14643: } elsif ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
14644: $ruleok = 1;
14645: }
14646: if ($ruleok) {
1.354 raeburn 14647: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14648: if (exists($current{$rule})) {
14649: if ($newvalues{$rule} ne $current{$rule}) {
14650: $changes{'rules'} = 1;
14651: }
14652: } elsif ($rule eq 'min') {
14653: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14654: $changes{'rules'} = 1;
14655: }
14656: }
14657: } elsif (exists($current{$rule})) {
14658: $changes{'rules'} = 1;
14659: }
14660: }
14661: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14662: my @chars;
14663: foreach my $item (sort(@posschars)) {
14664: if ($item =~ /^(uc|lc|num|spec)$/) {
14665: push(@chars,$item);
14666: }
14667: }
14668: $newvalues{'chars'} = \@chars;
14669: unless ($changes{'rules'}) {
14670: if (ref($current{'chars'}) eq 'ARRAY') {
14671: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14672: if (@diffs > 0) {
14673: $changes{'rules'} = 1;
14674: }
14675: } else {
14676: if (@chars > 0) {
14677: $changes{'rules'} = 1;
14678: }
14679: }
14680: }
1.359 raeburn 14681: my %crsownerchg = (
14682: by => [],
14683: for => [],
14684: );
14685: foreach my $item ('by','for') {
14686: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14687: foreach my $type (sort(@posstypes)) {
14688: if (grep(/^\Q$type\E$/,@oktypes)) {
14689: push(@{$crsownerchg{$item}},$type);
14690: }
14691: }
14692: }
14693: $newvalues{'crsownerchg'} = \%crsownerchg;
14694: if (ref($current{'crsownerchg'}) eq 'HASH') {
14695: foreach my $item ('by','for') {
14696: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14697: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14698: if (@diffs > 0) {
14699: $changes{'crsownerchg'} = 1;
14700: last;
14701: }
14702: }
14703: }
14704: } elsif (!exists($domconfig{passwords})) {
14705: foreach my $item ('by','for') {
14706: if (@{$crsownerchg{$item}} > 0) {
14707: $changes{'crsownerchg'} = 1;
14708: last;
14709: }
1.354 raeburn 14710: }
14711: }
14712:
14713: my %confighash = (
14714: defaults => \%save_defaults,
14715: passwords => \%newvalues,
14716: );
14717: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14718:
14719: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14720: if ($putresult eq 'ok') {
14721: if (keys(%changes) > 0) {
14722: $resulttext = &mt('Changes made: ').'<ul>';
14723: foreach my $key ('reset','intauth','rules','crsownerchg') {
14724: if ($changes{$key}) {
1.355 raeburn 14725: unless ($key eq 'intauth') {
14726: $updateconf = 1;
14727: }
1.354 raeburn 14728: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14729: if ($key eq 'reset') {
14730: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14731: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14732: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14733: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14734: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
14735: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
14736: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
14737: } else {
14738: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14739: }
14740: if ($confighash{'passwords'}{'resetlink'}) {
14741: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14742: } else {
14743: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14744: &mt('Will default to 2 hours').'</li>';
14745: }
14746: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14747: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14748: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14749: } else {
14750: my $casesens;
14751: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14752: if ($type eq 'default') {
14753: $casesens .= $othertitle.', ';
14754: } elsif ($usertypes->{$type} ne '') {
14755: $casesens .= $usertypes->{$type}.', ';
14756: }
14757: }
14758: $casesens =~ s/\Q, \E$//;
14759: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14760: }
14761: } else {
14762: $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>';
14763: }
14764: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14765: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14766: } else {
14767: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14768: }
14769: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14770: my $output;
14771: if (ref($types) eq 'ARRAY') {
14772: foreach my $type (@{$types}) {
14773: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14774: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14775: $output .= $usertypes->{$type}.' -- '.&mt('none');
14776: } else {
14777: $output .= $usertypes->{$type}.' -- '.
14778: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14779: }
14780: }
14781: }
14782: }
14783: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14784: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14785: $output .= $othertitle.' -- '.&mt('none');
14786: } else {
14787: $output .= $othertitle.' -- '.
14788: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14789: }
14790: }
14791: if ($output) {
14792: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14793: } else {
14794: $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>';
14795: }
14796: } else {
14797: $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>';
14798: }
14799: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14800: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14801: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14802: } else {
14803: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14804: }
14805: } else {
14806: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14807: }
14808: if ($confighash{'passwords'}{'resetremove'}) {
14809: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14810: } else {
14811: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14812: }
14813: if ($confighash{'passwords'}{'resetcustom'}) {
14814: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14815: $titles{custom},600,500);
14816: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
14817: } else {
14818: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14819: }
14820: } elsif ($key eq 'intauth') {
14821: foreach my $item ('cost','switch','check') {
14822: my $value = $save_defaults{$key.'_'.$item};
14823: if ($item eq 'switch') {
14824: my %optiondesc = &Apache::lonlocal::texthash (
14825: 0 => 'No',
14826: 1 => 'Yes',
14827: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14828: );
14829: if ($value =~ /^(0|1|2)$/) {
14830: $value = $optiondesc{$value};
14831: } else {
14832: $value = &mt('none -- defaults to No');
14833: }
14834: } elsif ($item eq 'check') {
14835: my %optiondesc = &Apache::lonlocal::texthash (
14836: 0 => 'No',
14837: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14838: 2 => 'Yes, disallow login if stored cost is less than domain default',
14839: );
14840: if ($value =~ /^(0|1|2)$/) {
14841: $value = $optiondesc{$value};
14842: } else {
14843: $value = &mt('none -- defaults to No');
14844: }
14845: }
14846: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14847: }
14848: } elsif ($key eq 'rules') {
1.356 raeburn 14849: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14850: if ($confighash{'passwords'}{$rule} eq '') {
14851: if ($rule eq 'min') {
1.356 raeburn 14852: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14853: ' '.&mt('Default of 7 will be used').'</li>';
14854: } else {
14855: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 14856: }
14857: } else {
14858: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14859: }
14860: }
14861: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 14862: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14863: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14864: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14865: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14866: } else {
14867: my %crsownerstr;
14868: foreach my $item ('by','for') {
14869: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14870: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14871: if ($type eq 'default') {
14872: $crsownerstr{$item} .= $othertitle.', ';
14873: } elsif ($usertypes->{$type} ne '') {
14874: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14875: }
14876: }
14877: $crsownerstr{$item} =~ s/\Q, \E$//;
14878: }
14879: }
14880: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14881: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14882: }
1.354 raeburn 14883: } else {
1.359 raeburn 14884: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 14885: }
14886: }
14887: $resulttext .= '</ul></li>';
14888: }
14889: }
14890: $resulttext .= '</ul>';
14891: } else {
14892: $resulttext = &mt('No changes made to password settings');
14893: }
1.355 raeburn 14894: my $cachetime = 24*60*60;
1.354 raeburn 14895: if ($updatedefaults) {
14896: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14897: if (ref($lastactref) eq 'HASH') {
14898: $lastactref->{'domdefaults'} = 1;
14899: }
14900: }
1.355 raeburn 14901: if ($updateconf) {
14902: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14903: if (ref($lastactref) eq 'HASH') {
14904: $lastactref->{'passwdconf'} = 1;
14905: }
14906: }
1.354 raeburn 14907: } else {
14908: $resulttext = '<span class="LC_error">'.
14909: &mt('An error occurred: [_1]',$putresult).'</span>';
14910: }
14911: if ($errors) {
14912: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14913: $errors.'</ul></p>';
14914: }
14915: return $resulttext;
14916: }
14917:
1.28 raeburn 14918: sub modify_usercreation {
1.27 raeburn 14919: my ($dom,%domconfig) = @_;
1.224 raeburn 14920: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 14921: my $warningmsg;
1.27 raeburn 14922: if (ref($domconfig{'usercreation'}) eq 'HASH') {
14923: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 14924: if ($key eq 'cancreate') {
14925: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
14926: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 14927: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
14928: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14929: } else {
1.224 raeburn 14930: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
14931: }
14932: }
14933: }
14934: } elsif ($key eq 'email_rule') {
14935: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
14936: } else {
14937: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
14938: }
1.27 raeburn 14939: }
14940: }
14941: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 14942: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 14943: my @contexts = ('author','course','requestcrs');
1.34 raeburn 14944: foreach my $item(@contexts) {
1.224 raeburn 14945: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 14946: }
1.34 raeburn 14947: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
14948: foreach my $item (@contexts) {
1.224 raeburn 14949: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
14950: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 14951: }
1.27 raeburn 14952: }
1.34 raeburn 14953: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
14954: foreach my $item (@contexts) {
1.43 raeburn 14955: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 14956: if ($cancreate{$item} ne 'any') {
14957: push(@{$changes{'cancreate'}},$item);
14958: }
14959: } else {
14960: if ($cancreate{$item} ne 'none') {
14961: push(@{$changes{'cancreate'}},$item);
14962: }
1.27 raeburn 14963: }
14964: }
14965: } else {
1.43 raeburn 14966: foreach my $item (@contexts) {
1.34 raeburn 14967: push(@{$changes{'cancreate'}},$item);
14968: }
1.27 raeburn 14969: }
1.34 raeburn 14970:
1.27 raeburn 14971: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
14972: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
14973: if (!grep(/^\Q$type\E$/,@username_rule)) {
14974: push(@{$changes{'username_rule'}},$type);
14975: }
14976: }
14977: foreach my $type (@username_rule) {
14978: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
14979: push(@{$changes{'username_rule'}},$type);
14980: }
14981: }
14982: } else {
14983: push(@{$changes{'username_rule'}},@username_rule);
14984: }
14985:
1.32 raeburn 14986: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
14987: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
14988: if (!grep(/^\Q$type\E$/,@id_rule)) {
14989: push(@{$changes{'id_rule'}},$type);
14990: }
14991: }
14992: foreach my $type (@id_rule) {
14993: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
14994: push(@{$changes{'id_rule'}},$type);
14995: }
14996: }
14997: } else {
14998: push(@{$changes{'id_rule'}},@id_rule);
14999: }
15000:
1.43 raeburn 15001: my @authen_contexts = ('author','course','domain');
1.325 raeburn 15002: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 15003: my %authhash;
1.43 raeburn 15004: foreach my $item (@authen_contexts) {
1.28 raeburn 15005: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15006: foreach my $auth (@authtypes) {
15007: if (grep(/^\Q$auth\E$/,@authallowed)) {
15008: $authhash{$item}{$auth} = 1;
15009: } else {
15010: $authhash{$item}{$auth} = 0;
15011: }
15012: }
15013: }
15014: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15015: foreach my $item (@authen_contexts) {
1.28 raeburn 15016: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15017: foreach my $auth (@authtypes) {
15018: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15019: push(@{$changes{'authtypes'}},$item);
15020: last;
15021: }
15022: }
15023: }
15024: }
15025: } else {
1.43 raeburn 15026: foreach my $item (@authen_contexts) {
1.28 raeburn 15027: push(@{$changes{'authtypes'}},$item);
15028: }
15029: }
15030:
1.224 raeburn 15031: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15032: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15033: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15034: $save_usercreate{'id_rule'} = \@id_rule;
15035: $save_usercreate{'username_rule'} = \@username_rule,
15036: $save_usercreate{'authtypes'} = \%authhash;
15037:
1.27 raeburn 15038: my %usercreation_hash = (
1.224 raeburn 15039: usercreation => \%save_usercreate,
15040: );
1.27 raeburn 15041:
15042: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15043: $dom);
1.50 raeburn 15044:
1.224 raeburn 15045: if ($putresult eq 'ok') {
15046: if (keys(%changes) > 0) {
15047: $resulttext = &mt('Changes made:').'<ul>';
15048: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15049: my %lt = &usercreation_types();
15050: foreach my $type (@{$changes{'cancreate'}}) {
15051: my $chgtext = $lt{$type}.', ';
15052: if ($cancreate{$type} eq 'none') {
15053: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15054: } elsif ($cancreate{$type} eq 'any') {
15055: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15056: } elsif ($cancreate{$type} eq 'official') {
15057: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15058: } elsif ($cancreate{$type} eq 'unofficial') {
15059: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15060: }
15061: $resulttext .= '<li>'.$chgtext.'</li>';
15062: }
15063: }
15064: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15065: my ($rules,$ruleorder) =
15066: &Apache::lonnet::inst_userrules($dom,'username');
15067: my $chgtext = '<ul>';
15068: foreach my $type (@username_rule) {
15069: if (ref($rules->{$type}) eq 'HASH') {
15070: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15071: }
15072: }
15073: $chgtext .= '</ul>';
15074: if (@username_rule > 0) {
15075: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15076: } else {
15077: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15078: }
15079: }
15080: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15081: my ($idrules,$idruleorder) =
15082: &Apache::lonnet::inst_userrules($dom,'id');
15083: my $chgtext = '<ul>';
15084: foreach my $type (@id_rule) {
15085: if (ref($idrules->{$type}) eq 'HASH') {
15086: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15087: }
15088: }
15089: $chgtext .= '</ul>';
15090: if (@id_rule > 0) {
15091: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15092: } else {
15093: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15094: }
15095: }
15096: my %authname = &authtype_names();
15097: my %context_title = &context_names();
15098: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15099: my $chgtext = '<ul>';
15100: foreach my $type (@{$changes{'authtypes'}}) {
15101: my @allowed;
15102: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15103: foreach my $auth (@authtypes) {
15104: if ($authhash{$type}{$auth}) {
15105: push(@allowed,$authname{$auth});
15106: }
15107: }
15108: if (@allowed > 0) {
15109: $chgtext .= join(', ',@allowed).'</li>';
15110: } else {
15111: $chgtext .= &mt('none').'</li>';
15112: }
15113: }
15114: $chgtext .= '</ul>';
15115: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15116: $resulttext .= '</li>';
15117: }
15118: $resulttext .= '</ul>';
15119: } else {
15120: $resulttext = &mt('No changes made to user creation settings');
15121: }
15122: } else {
15123: $resulttext = '<span class="LC_error">'.
15124: &mt('An error occurred: [_1]',$putresult).'</span>';
15125: }
15126: if ($warningmsg ne '') {
15127: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15128: }
15129: return $resulttext;
15130: }
15131:
15132: sub modify_selfcreation {
1.305 raeburn 15133: my ($dom,$lastactref,%domconfig) = @_;
15134: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15135: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15136: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 15137: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15138: if (ref($typesref) eq 'ARRAY') {
15139: @types = @{$typesref};
15140: }
15141: if (ref($usertypesref) eq 'HASH') {
15142: %usertypes = %{$usertypesref};
1.228 raeburn 15143: }
1.303 raeburn 15144: $usertypes{'default'} = $othertitle;
1.224 raeburn 15145: #
15146: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15147: #
15148: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15149: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15150: if ($key eq 'cancreate') {
15151: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15152: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15153: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 15154: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15155: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15156: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15157: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 15158: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 15159: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15160: } else {
15161: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15162: }
15163: }
15164: }
15165: } elsif ($key eq 'email_rule') {
15166: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15167: } else {
15168: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15169: }
15170: }
15171: }
15172: #
15173: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15174: #
15175: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15176: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15177: if ($key eq 'selfcreate') {
15178: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15179: } else {
15180: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15181: }
15182: }
15183: }
1.305 raeburn 15184: #
15185: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15186: #
15187: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15188: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15189: if ($key eq 'inststatusguest') {
15190: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15191: } else {
15192: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15193: }
15194: }
15195: }
1.224 raeburn 15196:
15197: my @contexts = ('selfcreate');
15198: @{$cancreate{'selfcreate'}} = ();
15199: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 15200: if (@types) {
15201: @{$cancreate{'statustocreate'}} = ();
15202: }
1.236 raeburn 15203: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 15204: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 15205: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 15206: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 15207: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15208: my %selfcreatetypes = (
15209: sso => 'users authenticated by institutional single sign on',
15210: login => 'users authenticated by institutional log-in',
1.303 raeburn 15211: email => 'users verified by e-mail',
1.50 raeburn 15212: );
1.224 raeburn 15213: #
15214: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15215: # is permitted.
15216: #
1.305 raeburn 15217: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 15218:
1.305 raeburn 15219: my (@statuses,%email_rule);
1.228 raeburn 15220: foreach my $item ('login','sso','email') {
1.224 raeburn 15221: if ($item eq 'email') {
1.236 raeburn 15222: if ($env{'form.cancreate_email'}) {
1.305 raeburn 15223: if (@types) {
15224: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15225: foreach my $status (@poss_statuses) {
15226: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15227: push(@statuses,$status);
15228: }
15229: }
15230: $save_inststatus{'inststatusguest'} = \@statuses;
15231: } else {
15232: push(@statuses,'default');
15233: }
15234: if (@statuses) {
15235: my %curr_rule;
15236: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15237: foreach my $type (@statuses) {
15238: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 15239: }
1.305 raeburn 15240: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15241: foreach my $type (@statuses) {
15242: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15243: }
15244: }
15245: push(@{$cancreate{'selfcreate'}},'email');
15246: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15247: my %curremaildom;
15248: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15249: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15250: }
15251: foreach my $type (@statuses) {
15252: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15253: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15254: }
15255: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15256: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15257: }
15258: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15259: #
15260: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15261: #
15262: my $chosen = $1;
15263: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15264: my $emaildom;
15265: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15266: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15267: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15268: if (ref($curremaildom{$type}) eq 'HASH') {
15269: if (exists($curremaildom{$type}{$chosen})) {
15270: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15271: push(@{$changes{'cancreate'}},'emaildomain');
15272: }
15273: } elsif ($emaildom ne '') {
15274: push(@{$changes{'cancreate'}},'emaildomain');
15275: }
15276: } elsif ($emaildom ne '') {
15277: push(@{$changes{'cancreate'}},'emaildomain');
15278: }
15279: }
15280: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15281: } elsif ($chosen eq 'custom') {
15282: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15283: $email_rule{$type} = [];
15284: if (ref($emailrules) eq 'HASH') {
15285: foreach my $rule (@possemail_rules) {
15286: if (exists($emailrules->{$rule})) {
15287: push(@{$email_rule{$type}},$rule);
15288: }
15289: }
15290: }
15291: if (@{$email_rule{$type}}) {
15292: $cancreate{'emailoptions'}{$type} = 'custom';
15293: if (ref($curr_rule{$type}) eq 'ARRAY') {
15294: if (@{$curr_rule{$type}} > 0) {
15295: foreach my $rule (@{$curr_rule{$type}}) {
15296: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15297: push(@{$changes{'email_rule'}},$type);
15298: }
15299: }
15300: }
15301: foreach my $type (@{$email_rule{$type}}) {
15302: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15303: push(@{$changes{'email_rule'}},$type);
15304: }
15305: }
15306: } else {
15307: push(@{$changes{'email_rule'}},$type);
15308: }
15309: }
15310: } else {
15311: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15312: }
15313: }
15314: }
15315: if (@types) {
15316: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15317: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15318: if (@changed) {
15319: push(@{$changes{'inststatus'}},'inststatusguest');
15320: }
15321: } else {
15322: push(@{$changes{'inststatus'}},'inststatusguest');
15323: }
15324: }
15325: } else {
15326: delete($env{'form.cancreate_email'});
15327: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15328: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15329: push(@{$changes{'inststatus'}},'inststatusguest');
15330: }
15331: }
15332: }
15333: } else {
15334: $save_inststatus{'inststatusguest'} = [];
15335: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15336: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15337: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 15338: }
15339: }
1.224 raeburn 15340: }
15341: } else {
15342: if ($env{'form.cancreate_'.$item}) {
15343: push(@{$cancreate{'selfcreate'}},$item);
15344: }
15345: }
15346: }
1.305 raeburn 15347: my (%userinfo,%savecaptcha);
1.224 raeburn 15348: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15349: #
1.228 raeburn 15350: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15351: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 15352: #
1.236 raeburn 15353:
1.244 raeburn 15354: if ($env{'form.cancreate_email'}) {
1.228 raeburn 15355: push(@contexts,'emailusername');
1.305 raeburn 15356: if (@statuses) {
15357: foreach my $type (@statuses) {
1.228 raeburn 15358: if (ref($infofields) eq 'ARRAY') {
15359: foreach my $field (@{$infofields}) {
15360: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15361: $cancreate{'emailusername'}{$type}{$field} = $1;
15362: }
15363: }
1.224 raeburn 15364: }
15365: }
15366: }
15367: #
15368: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 15369: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 15370: #
15371:
15372: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15373: @approvalnotify = sort(@approvalnotify);
15374: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15375: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15376: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15377: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15378: push(@{$changes{'cancreate'}},'notify');
15379: }
15380: } else {
15381: if ($cancreate{'notify'}{'approval'}) {
15382: push(@{$changes{'cancreate'}},'notify');
15383: }
15384: }
15385: } elsif ($cancreate{'notify'}{'approval'}) {
15386: push(@{$changes{'cancreate'}},'notify');
15387: }
15388:
15389: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15390: }
15391: #
1.236 raeburn 15392: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 15393: # institutional log-in.
15394: #
15395: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15396: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15397: ($domdefaults{'auth_def'} eq 'localauth'))) {
15398: $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.').' '.
15399: &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.');
15400: }
15401: }
15402: my @fields = ('lastname','firstname','middlename','generation',
15403: 'permanentemail','id');
1.240 raeburn 15404: my @shibfields = (@fields,'inststatus');
1.224 raeburn 15405: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15406: #
15407: # Where usernames may created for institutional log-in and/or institutional single sign on:
15408: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15409: # may self-create accounts
15410: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15411: # which the user may supply, if institutional data is unavailable.
15412: #
15413: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 15414: if (@types) {
1.305 raeburn 15415: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15416: push(@contexts,'statustocreate');
1.303 raeburn 15417: foreach my $type (@types) {
1.224 raeburn 15418: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15419: foreach my $field (@fields) {
15420: if (grep(/^\Q$field\E$/,@modifiable)) {
15421: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15422: } else {
15423: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15424: }
15425: }
15426: }
15427: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 15428: foreach my $type (@types) {
1.224 raeburn 15429: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15430: foreach my $field (@fields) {
15431: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15432: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15433: push(@{$changes{'selfcreate'}},$type);
15434: last;
15435: }
15436: }
15437: }
15438: }
15439: } else {
1.303 raeburn 15440: foreach my $type (@types) {
1.224 raeburn 15441: push(@{$changes{'selfcreate'}},$type);
15442: }
15443: }
15444: }
1.240 raeburn 15445: foreach my $field (@shibfields) {
15446: if ($env{'form.shibenv_'.$field} ne '') {
15447: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15448: }
15449: }
15450: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15451: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15452: foreach my $field (@shibfields) {
15453: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15454: push(@{$changes{'cancreate'}},'shibenv');
15455: }
15456: }
15457: } else {
15458: foreach my $field (@shibfields) {
15459: if ($env{'form.shibenv_'.$field}) {
15460: push(@{$changes{'cancreate'}},'shibenv');
15461: last;
15462: }
15463: }
15464: }
15465: }
1.224 raeburn 15466: }
15467: foreach my $item (@contexts) {
15468: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15469: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15470: if (ref($cancreate{$item}) eq 'ARRAY') {
15471: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15472: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15473: push(@{$changes{'cancreate'}},$item);
15474: }
15475: }
15476: }
15477: }
15478: if (ref($cancreate{$item}) eq 'ARRAY') {
15479: foreach my $type (@{$cancreate{$item}}) {
15480: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15481: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15482: push(@{$changes{'cancreate'}},$item);
15483: }
15484: }
15485: }
15486: }
15487: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15488: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 15489: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15490: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15491: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15492: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15493: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15494: push(@{$changes{'cancreate'}},$item);
15495: }
15496: }
15497: }
1.305 raeburn 15498: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15499: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15500: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15501: push(@{$changes{'cancreate'}},$item);
15502: }
1.224 raeburn 15503: }
15504: }
15505: }
1.305 raeburn 15506: foreach my $type (keys(%{$cancreate{$item}})) {
15507: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15508: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15509: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15510: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15511: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15512: push(@{$changes{'cancreate'}},$item);
15513: }
15514: }
15515: } else {
15516: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15517: push(@{$changes{'cancreate'}},$item);
15518: }
15519: }
15520: }
1.305 raeburn 15521: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15522: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15523: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15524: push(@{$changes{'cancreate'}},$item);
15525: }
1.224 raeburn 15526: }
15527: }
15528: }
15529: }
15530: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15531: if (ref($cancreate{$item}) eq 'ARRAY') {
15532: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15533: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15534: push(@{$changes{'cancreate'}},$item);
15535: }
15536: }
1.305 raeburn 15537: }
15538: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15539: if (ref($cancreate{$item}) eq 'HASH') {
15540: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15541: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 15542: }
15543: }
15544: } elsif ($item eq 'emailusername') {
1.228 raeburn 15545: if (ref($cancreate{$item}) eq 'HASH') {
15546: foreach my $type (keys(%{$cancreate{$item}})) {
15547: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15548: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15549: if ($cancreate{$item}{$type}{$field}) {
15550: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15551: push(@{$changes{'cancreate'}},$item);
15552: }
15553: last;
15554: }
15555: }
15556: }
15557: }
1.224 raeburn 15558: }
15559: }
15560: }
15561: #
15562: # Populate %save_usercreate hash with updates to self-creation configuration.
15563: #
15564: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15565: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 15566: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 15567: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15568: if (ref($cancreate{'notify'}) eq 'HASH') {
15569: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15570: }
1.236 raeburn 15571: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15572: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15573: }
1.303 raeburn 15574: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15575: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15576: }
1.305 raeburn 15577: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15578: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15579: }
1.303 raeburn 15580: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15581: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15582: }
1.224 raeburn 15583: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15584: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15585: }
1.240 raeburn 15586: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15587: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15588: }
1.224 raeburn 15589: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 15590: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 15591:
15592: my %userconfig_hash = (
15593: usercreation => \%save_usercreate,
15594: usermodification => \%save_usermodify,
1.305 raeburn 15595: inststatus => \%save_inststatus,
1.224 raeburn 15596: );
1.305 raeburn 15597:
1.224 raeburn 15598: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15599: $dom);
15600: #
1.305 raeburn 15601: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 15602: #
1.27 raeburn 15603: if ($putresult eq 'ok') {
15604: if (keys(%changes) > 0) {
15605: $resulttext = &mt('Changes made:').'<ul>';
15606: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 15607: my %lt = &selfcreation_types();
1.34 raeburn 15608: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 15609: my $chgtext = '';
1.45 raeburn 15610: if ($type eq 'selfcreate') {
1.50 raeburn 15611: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 15612: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15613: } else {
1.224 raeburn 15614: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15615: '<ul>';
1.50 raeburn 15616: foreach my $case (@{$cancreate{$type}}) {
15617: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15618: }
15619: $chgtext .= '</ul>';
1.100 raeburn 15620: if (ref($cancreate{$type}) eq 'ARRAY') {
15621: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15622: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15623: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 15624: $chgtext .= '<span class="LC_warning">'.
15625: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15626: '</span><br />';
15627: }
15628: }
15629: }
15630: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 15631: if (!@statuses) {
15632: $chgtext .= '<span class="LC_warning">'.
15633: &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.").
15634: '</span><br />';
1.303 raeburn 15635:
1.100 raeburn 15636: }
15637: }
15638: }
1.43 raeburn 15639: }
1.240 raeburn 15640: } elsif ($type eq 'shibenv') {
15641: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 15642: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 15643: } else {
15644: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15645: '<ul>';
15646: foreach my $field (@shibfields) {
15647: next if ($cancreate{$type}{$field} eq '');
15648: if ($field eq 'inststatus') {
15649: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15650: } else {
15651: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15652: }
15653: }
15654: $chgtext .= '</ul>';
1.303 raeburn 15655: }
1.93 raeburn 15656: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15657: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15658: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15659: if (@{$cancreate{'selfcreate'}} > 0) {
15660: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15661: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15662: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 15663: $chgtext .= '<br />'.
15664: '<span class="LC_warning">'.
15665: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15666: '</span>';
15667: }
1.303 raeburn 15668: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15669: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15670: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15671: } else {
15672: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15673: }
15674: $chgtext .= '<ul>';
15675: foreach my $case (@{$cancreate{$type}}) {
15676: if ($case eq 'default') {
15677: $chgtext .= '<li>'.$othertitle.'</li>';
15678: } else {
1.303 raeburn 15679: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15680: }
15681: }
1.100 raeburn 15682: $chgtext .= '</ul>';
15683: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 15684: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 15685: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15686: '</span>';
1.100 raeburn 15687: }
15688: }
15689: } else {
15690: if (@{$cancreate{$type}} == 0) {
15691: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15692: } else {
15693: $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 15694: }
15695: }
1.303 raeburn 15696: $chgtext .= '<br />';
1.93 raeburn 15697: }
1.236 raeburn 15698: } elsif ($type eq 'selfcreateprocessing') {
15699: my %choices = &Apache::lonlocal::texthash (
15700: automatic => 'Automatic approval',
15701: approval => 'Queued for approval',
15702: );
1.305 raeburn 15703: if (@types) {
15704: if (@statuses) {
1.303 raeburn 15705: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 15706: '<ul>';
1.305 raeburn 15707: foreach my $status (@statuses) {
15708: if ($status eq 'default') {
15709: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15710: } else {
1.305 raeburn 15711: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15712: }
15713: }
15714: $chgtext .= '</ul>';
15715: }
15716: } else {
15717: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15718: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15719: }
15720: } elsif ($type eq 'emailverified') {
15721: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 15722: all => 'Same as e-mail',
15723: first => 'Omit @domain',
15724: free => 'Free to choose',
1.303 raeburn 15725: );
1.305 raeburn 15726: if (@types) {
15727: if (@statuses) {
1.303 raeburn 15728: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15729: '<ul>';
1.305 raeburn 15730: foreach my $status (@statuses) {
1.362 ! raeburn 15731: if ($status eq 'default') {
1.305 raeburn 15732: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15733: } else {
1.305 raeburn 15734: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15735: }
15736: }
15737: $chgtext .= '</ul>';
15738: }
15739: } else {
1.305 raeburn 15740: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 15741: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 15742: }
1.305 raeburn 15743: } elsif ($type eq 'emailoptions') {
15744: my %options = &Apache::lonlocal::texthash (
15745: any => 'Any e-mail',
15746: inst => 'Institutional only',
15747: noninst => 'Non-institutional only',
15748: custom => 'Custom restrictions',
15749: );
15750: if (@types) {
15751: if (@statuses) {
15752: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15753: '<ul>';
15754: foreach my $status (@statuses) {
15755: if ($type eq 'default') {
15756: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15757: } else {
15758: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 15759: }
15760: }
1.305 raeburn 15761: $chgtext .= '</ul>';
15762: }
15763: } else {
15764: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15765: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15766: } else {
15767: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15768: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 15769: }
1.305 raeburn 15770: }
15771: } elsif ($type eq 'emaildomain') {
15772: my $output;
15773: if (@statuses) {
15774: foreach my $type (@statuses) {
15775: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15776: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15777: if ($type eq 'default') {
15778: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15779: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15780: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15781: } else {
15782: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15783: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15784: }
1.303 raeburn 15785: } else {
1.305 raeburn 15786: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15787: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15788: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15789: } else {
15790: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15791: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15792: }
1.303 raeburn 15793: }
1.305 raeburn 15794: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15795: if ($type eq 'default') {
15796: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15797: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15798: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15799: } else {
15800: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15801: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15802: }
1.303 raeburn 15803: } else {
1.305 raeburn 15804: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15805: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15806: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15807: } else {
15808: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15809: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15810: }
1.303 raeburn 15811: }
15812: }
15813: }
15814: }
1.305 raeburn 15815: }
15816: if ($output ne '') {
15817: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15818: '<ul>'.$output.'</ul>';
1.236 raeburn 15819: }
1.165 raeburn 15820: } elsif ($type eq 'captcha') {
1.224 raeburn 15821: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 15822: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15823: } else {
15824: my %captchas = &captcha_phrases();
1.224 raeburn 15825: if ($captchas{$savecaptcha{$type}}) {
15826: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 15827: } else {
1.210 raeburn 15828: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 15829: }
15830: }
15831: } elsif ($type eq 'recaptchakeys') {
15832: my ($privkey,$pubkey);
1.224 raeburn 15833: if (ref($savecaptcha{$type}) eq 'HASH') {
15834: $pubkey = $savecaptcha{$type}{'public'};
15835: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 15836: }
15837: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15838: if (!$pubkey) {
15839: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15840: } else {
15841: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15842: }
15843: if (!$privkey) {
15844: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15845: } else {
15846: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15847: }
15848: $chgtext .= '</ul>';
1.269 raeburn 15849: } elsif ($type eq 'recaptchaversion') {
15850: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 15851: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 15852: }
1.224 raeburn 15853: } elsif ($type eq 'emailusername') {
15854: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 15855: if (@statuses) {
15856: foreach my $type (@statuses) {
1.228 raeburn 15857: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15858: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 15859: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 15860: '<ul>';
15861: foreach my $field (@{$infofields}) {
15862: if ($cancreate{'emailusername'}{$type}{$field}) {
15863: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15864: }
15865: }
1.245 raeburn 15866: $chgtext .= '</ul>';
15867: } else {
1.303 raeburn 15868: $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 15869: }
15870: } else {
1.303 raeburn 15871: $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 15872: }
15873: }
15874: }
15875: }
15876: } elsif ($type eq 'notify') {
1.303 raeburn 15877: my $numapprove = 0;
1.224 raeburn 15878: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15879: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15880: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 15881: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15882: $numapprove ++;
1.224 raeburn 15883: }
15884: }
1.43 raeburn 15885: }
1.303 raeburn 15886: unless ($numapprove) {
15887: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15888: }
1.34 raeburn 15889: }
1.224 raeburn 15890: if ($chgtext) {
15891: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15892: }
15893: }
15894: }
1.305 raeburn 15895: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 15896: my ($emailrules,$emailruleorder) =
15897: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 15898: foreach my $type (@{$changes{'email_rule'}}) {
15899: if (ref($email_rule{$type}) eq 'ARRAY') {
15900: my $chgtext = '<ul>';
15901: foreach my $rule (@{$email_rule{$type}}) {
15902: if (ref($emailrules->{$rule}) eq 'HASH') {
15903: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
15904: }
15905: }
15906: $chgtext .= '</ul>';
1.310 raeburn 15907: my $typename;
1.305 raeburn 15908: if (@types) {
15909: if ($type eq 'default') {
15910: $typename = $othertitle;
15911: } else {
15912: $typename = $usertypes{$type};
15913: }
15914: $chgtext .= &mt('(Affiliation: [_1])',$typename);
15915: }
15916: if (@{$email_rule{$type}} > 0) {
15917: $resulttext .= '<li>'.
15918: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
15919: $usertypes{$type}).
15920: $chgtext.
15921: '</li>';
15922: } else {
15923: $resulttext .= '<li>'.
1.310 raeburn 15924: &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 15925: '</li>'.
1.310 raeburn 15926: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 15927: }
1.43 raeburn 15928: }
15929: }
1.305 raeburn 15930: }
15931: if (ref($changes{'inststatus'}) eq 'ARRAY') {
15932: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
15933: if (@{$save_inststatus{'inststatusguest'}} > 0) {
15934: my $chgtext = '<ul>';
15935: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
15936: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
15937: }
15938: $chgtext .= '</ul>';
15939: $resulttext .= '<li>'.
15940: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
15941: $chgtext.
15942: '</li>';
15943: } else {
15944: $resulttext .= '<li>'.
15945: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
15946: '</li>';
15947: }
1.43 raeburn 15948: }
15949: }
1.224 raeburn 15950: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
15951: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
15952: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15953: foreach my $type (@{$changes{'selfcreate'}}) {
15954: my $typename = $type;
1.303 raeburn 15955: if (keys(%usertypes) > 0) {
15956: if ($usertypes{$type} ne '') {
15957: $typename = $usertypes{$type};
1.224 raeburn 15958: }
15959: }
15960: my @modifiable;
15961: $resulttext .= '<li>'.
15962: &mt('Self-creation of account by users with status: [_1]',
15963: '<span class="LC_cusr_emph">'.$typename.'</span>').
15964: ' - '.&mt('modifiable fields (if institutional data blank): ');
15965: foreach my $field (@fields) {
15966: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
15967: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 15968: }
15969: }
1.224 raeburn 15970: if (@modifiable > 0) {
15971: $resulttext .= join(', ',@modifiable);
1.43 raeburn 15972: } else {
1.224 raeburn 15973: $resulttext .= &mt('none');
1.43 raeburn 15974: }
1.224 raeburn 15975: $resulttext .= '</li>';
1.28 raeburn 15976: }
1.224 raeburn 15977: $resulttext .= '</ul></li>';
1.28 raeburn 15978: }
1.27 raeburn 15979: $resulttext .= '</ul>';
1.305 raeburn 15980: my $cachetime = 24*60*60;
15981: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
15982: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15983: if (ref($lastactref) eq 'HASH') {
15984: $lastactref->{'domdefaults'} = 1;
15985: }
1.27 raeburn 15986: } else {
1.224 raeburn 15987: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 15988: }
15989: } else {
15990: $resulttext = '<span class="LC_error">'.
1.23 raeburn 15991: &mt('An error occurred: [_1]',$putresult).'</span>';
15992: }
1.43 raeburn 15993: if ($warningmsg ne '') {
15994: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15995: }
1.23 raeburn 15996: return $resulttext;
15997: }
15998:
1.165 raeburn 15999: sub process_captcha {
16000: my ($container,$changes,$newsettings,$current) = @_;
16001: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
16002: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16003: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16004: $newsettings->{'captcha'} = 'original';
16005: }
16006: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 16007: if ($container eq 'cancreate') {
1.169 raeburn 16008: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16009: push(@{$changes->{'cancreate'}},'captcha');
16010: } elsif (!defined($changes->{'cancreate'})) {
16011: $changes->{'cancreate'} = ['captcha'];
16012: }
16013: } else {
16014: $changes->{'captcha'} = 1;
1.165 raeburn 16015: }
16016: }
1.269 raeburn 16017: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 16018: if ($newsettings->{'captcha'} eq 'recaptcha') {
16019: $newpub = $env{'form.'.$container.'_recaptchapub'};
16020: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 16021: $newpub =~ s/[^\w\-]//g;
16022: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 16023: $newsettings->{'recaptchakeys'} = {
16024: public => $newpub,
16025: private => $newpriv,
16026: };
1.269 raeburn 16027: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16028: $newversion =~ s/\D//g;
16029: if ($newversion ne '2') {
16030: $newversion = 1;
16031: }
16032: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 16033: }
16034: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
16035: $currpub = $current->{'recaptchakeys'}{'public'};
16036: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 16037: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16038: $newsettings->{'recaptchakeys'} = {
16039: public => '',
16040: private => '',
16041: }
16042: }
1.165 raeburn 16043: }
1.269 raeburn 16044: if ($current->{'captcha'} eq 'recaptcha') {
16045: $currversion = $current->{'recaptchaversion'};
16046: if ($currversion ne '2') {
16047: $currversion = 1;
16048: }
16049: }
16050: if ($currversion ne $newversion) {
16051: if ($container eq 'cancreate') {
16052: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16053: push(@{$changes->{'cancreate'}},'recaptchaversion');
16054: } elsif (!defined($changes->{'cancreate'})) {
16055: $changes->{'cancreate'} = ['recaptchaversion'];
16056: }
16057: } else {
16058: $changes->{'recaptchaversion'} = 1;
16059: }
16060: }
1.165 raeburn 16061: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 16062: if ($container eq 'cancreate') {
16063: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16064: push(@{$changes->{'cancreate'}},'recaptchakeys');
16065: } elsif (!defined($changes->{'cancreate'})) {
16066: $changes->{'cancreate'} = ['recaptchakeys'];
16067: }
16068: } else {
1.210 raeburn 16069: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 16070: }
16071: }
16072: return;
16073: }
16074:
1.33 raeburn 16075: sub modify_usermodification {
16076: my ($dom,%domconfig) = @_;
1.224 raeburn 16077: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16078: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16079: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 16080: if ($key eq 'selfcreate') {
16081: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16082: } else {
16083: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16084: }
1.33 raeburn 16085: }
16086: }
1.224 raeburn 16087: my @contexts = ('author','course');
1.33 raeburn 16088: my %context_title = (
16089: author => 'In author context',
16090: course => 'In course context',
16091: );
16092: my @fields = ('lastname','firstname','middlename','generation',
16093: 'permanentemail','id');
16094: my %roles = (
16095: author => ['ca','aa'],
16096: course => ['st','ep','ta','in','cr'],
16097: );
16098: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16099: foreach my $context (@contexts) {
16100: foreach my $role (@{$roles{$context}}) {
16101: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16102: foreach my $item (@fields) {
16103: if (grep(/^\Q$item\E$/,@modifiable)) {
16104: $modifyhash{$context}{$role}{$item} = 1;
16105: } else {
16106: $modifyhash{$context}{$role}{$item} = 0;
16107: }
16108: }
16109: }
16110: if (ref($curr_usermodification{$context}) eq 'HASH') {
16111: foreach my $role (@{$roles{$context}}) {
16112: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16113: foreach my $field (@fields) {
16114: if ($modifyhash{$context}{$role}{$field} ne
16115: $curr_usermodification{$context}{$role}{$field}) {
16116: push(@{$changes{$context}},$role);
16117: last;
16118: }
16119: }
16120: }
16121: }
16122: } else {
16123: foreach my $context (@contexts) {
16124: foreach my $role (@{$roles{$context}}) {
16125: push(@{$changes{$context}},$role);
16126: }
16127: }
16128: }
16129: }
16130: my %usermodification_hash = (
16131: usermodification => \%modifyhash,
16132: );
16133: my $putresult = &Apache::lonnet::put_dom('configuration',
16134: \%usermodification_hash,$dom);
16135: if ($putresult eq 'ok') {
16136: if (keys(%changes) > 0) {
16137: $resulttext = &mt('Changes made: ').'<ul>';
16138: foreach my $context (@contexts) {
16139: if (ref($changes{$context}) eq 'ARRAY') {
16140: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16141: if (ref($changes{$context}) eq 'ARRAY') {
16142: foreach my $role (@{$changes{$context}}) {
16143: my $rolename;
1.224 raeburn 16144: if ($role eq 'cr') {
16145: $rolename = &mt('Custom');
1.33 raeburn 16146: } else {
1.224 raeburn 16147: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16148: }
16149: my @modifiable;
1.224 raeburn 16150: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16151: foreach my $field (@fields) {
16152: if ($modifyhash{$context}{$role}{$field}) {
16153: push(@modifiable,$fieldtitles{$field});
16154: }
16155: }
16156: if (@modifiable > 0) {
16157: $resulttext .= join(', ',@modifiable);
16158: } else {
16159: $resulttext .= &mt('none');
16160: }
16161: $resulttext .= '</li>';
16162: }
16163: $resulttext .= '</ul></li>';
16164: }
16165: }
16166: }
16167: $resulttext .= '</ul>';
16168: } else {
16169: $resulttext = &mt('No changes made to user modification settings');
16170: }
16171: } else {
16172: $resulttext = '<span class="LC_error">'.
16173: &mt('An error occurred: [_1]',$putresult).'</span>';
16174: }
16175: return $resulttext;
16176: }
16177:
1.43 raeburn 16178: sub modify_defaults {
1.212 raeburn 16179: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16180: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 16181: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 16182: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 16183: 'portal_def');
1.325 raeburn 16184: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 16185: foreach my $item (@items) {
16186: $newvalues{$item} = $env{'form.'.$item};
16187: if ($item eq 'auth_def') {
16188: if ($newvalues{$item} ne '') {
16189: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16190: push(@errors,$item);
16191: }
16192: }
16193: } elsif ($item eq 'lang_def') {
16194: if ($newvalues{$item} ne '') {
16195: if ($newvalues{$item} =~ /^(\w+)/) {
16196: my $langcode = $1;
1.103 raeburn 16197: if ($langcode ne 'x_chef') {
16198: if (code2language($langcode) eq '') {
16199: push(@errors,$item);
16200: }
1.43 raeburn 16201: }
16202: } else {
16203: push(@errors,$item);
16204: }
16205: }
1.54 raeburn 16206: } elsif ($item eq 'timezone_def') {
16207: if ($newvalues{$item} ne '') {
1.62 raeburn 16208: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16209: push(@errors,$item);
16210: }
16211: }
1.68 raeburn 16212: } elsif ($item eq 'datelocale_def') {
16213: if ($newvalues{$item} ne '') {
16214: my @datelocale_ids = DateTime::Locale->ids();
16215: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16216: push(@errors,$item);
16217: }
16218: }
1.141 raeburn 16219: } elsif ($item eq 'portal_def') {
16220: if ($newvalues{$item} ne '') {
16221: 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])\/?$/) {
16222: push(@errors,$item);
16223: }
16224: }
1.43 raeburn 16225: }
16226: if (grep(/^\Q$item\E$/,@errors)) {
16227: $newvalues{$item} = $domdefaults{$item};
16228: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16229: $changes{$item} = 1;
16230: }
1.72 raeburn 16231: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16232: }
1.354 raeburn 16233: my %staticdefaults = (
16234: 'intauth_cost' => 10,
16235: 'intauth_check' => 0,
16236: 'intauth_switch' => 0,
16237: );
16238: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16239: if (exists($domdefaults{$item})) {
16240: $newvalues{$item} = $domdefaults{$item};
16241: } else {
16242: $newvalues{$item} = $staticdefaults{$item};
16243: }
16244: }
1.43 raeburn 16245: my %defaults_hash = (
1.72 raeburn 16246: defaults => \%newvalues,
16247: );
1.43 raeburn 16248: my $title = &defaults_titles();
1.236 raeburn 16249:
16250: my $currinststatus;
16251: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16252: $currinststatus = $domconfig{'inststatus'};
16253: } else {
16254: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16255: $currinststatus = {
16256: inststatustypes => $usertypes,
16257: inststatusorder => $types,
16258: inststatusguest => [],
16259: };
16260: }
16261: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16262: my @allpos;
16263: my %alltypes;
1.305 raeburn 16264: my @inststatusguest;
16265: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16266: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16267: unless (grep(/^\Q$type\E$/,@todelete)) {
16268: push(@inststatusguest,$type);
16269: }
16270: }
16271: }
16272: my ($currtitles,$currorder);
1.236 raeburn 16273: if (ref($currinststatus) eq 'HASH') {
16274: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16275: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16276: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16277: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16278: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16279: }
16280: }
16281: unless (grep(/^\Q$type\E$/,@todelete)) {
16282: my $position = $env{'form.inststatus_pos_'.$type};
16283: $position =~ s/\D+//g;
16284: $allpos[$position] = $type;
16285: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16286: $alltypes{$type} =~ s/`//g;
16287: }
16288: }
16289: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16290: $currtitles =~ s/,$//;
16291: }
16292: }
16293: if ($env{'form.addinststatus'}) {
16294: my $newtype = $env{'form.addinststatus'};
16295: $newtype =~ s/\W//g;
16296: unless (exists($alltypes{$newtype})) {
16297: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16298: $alltypes{$newtype} =~ s/`//g;
16299: my $position = $env{'form.addinststatus_pos'};
16300: $position =~ s/\D+//g;
16301: if ($position ne '') {
16302: $allpos[$position] = $newtype;
16303: }
16304: }
16305: }
1.305 raeburn 16306: my @orderedstatus;
1.236 raeburn 16307: foreach my $type (@allpos) {
16308: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16309: push(@orderedstatus,$type);
16310: }
16311: }
16312: foreach my $type (keys(%alltypes)) {
16313: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16314: delete($alltypes{$type});
16315: }
16316: }
16317: $defaults_hash{'inststatus'} = {
16318: inststatustypes => \%alltypes,
16319: inststatusorder => \@orderedstatus,
1.305 raeburn 16320: inststatusguest => \@inststatusguest,
1.236 raeburn 16321: };
16322: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16323: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16324: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16325: }
16326: }
16327: if ($currorder ne join(',',@orderedstatus)) {
16328: $changes{'inststatus'}{'inststatusorder'} = 1;
16329: }
16330: my $newtitles;
16331: foreach my $item (@orderedstatus) {
16332: $newtitles .= $alltypes{$item}.',';
16333: }
16334: $newtitles =~ s/,$//;
16335: if ($currtitles ne $newtitles) {
16336: $changes{'inststatus'}{'inststatustypes'} = 1;
16337: }
1.43 raeburn 16338: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16339: $dom);
16340: if ($putresult eq 'ok') {
16341: if (keys(%changes) > 0) {
16342: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 16343: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16344: 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";
16345: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 16346: if ($item eq 'inststatus') {
16347: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 16348: if (@orderedstatus) {
1.236 raeburn 16349: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16350: foreach my $type (@orderedstatus) {
16351: $resulttext .= $alltypes{$type}.', ';
16352: }
16353: $resulttext =~ s/, $//;
16354: $resulttext .= '</li>';
1.305 raeburn 16355: } else {
16356: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 16357: }
16358: }
16359: } else {
16360: my $value = $env{'form.'.$item};
16361: if ($value eq '') {
16362: $value = &mt('none');
16363: } elsif ($item eq 'auth_def') {
16364: my %authnames = &authtype_names();
16365: my %shortauth = (
16366: internal => 'int',
16367: krb4 => 'krb4',
16368: krb5 => 'krb5',
16369: localauth => 'loc',
1.325 raeburn 16370: lti => 'lti',
1.236 raeburn 16371: );
16372: $value = $authnames{$shortauth{$value}};
16373: }
16374: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16375: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 16376: }
16377: }
16378: $resulttext .= '</ul>';
16379: $mailmsgtext .= "\n";
16380: my $cachetime = 24*60*60;
1.72 raeburn 16381: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16382: if (ref($lastactref) eq 'HASH') {
16383: $lastactref->{'domdefaults'} = 1;
16384: }
1.68 raeburn 16385: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 16386: my $notify = 1;
16387: if (ref($domconfig{'contacts'}) eq 'HASH') {
16388: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16389: $notify = 0;
16390: }
16391: }
16392: if ($notify) {
16393: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16394: "LON-CAPA Domain Settings Change - $dom",
16395: $mailmsgtext);
16396: }
1.54 raeburn 16397: }
1.43 raeburn 16398: } else {
1.54 raeburn 16399: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16400: }
16401: } else {
16402: $resulttext = '<span class="LC_error">'.
16403: &mt('An error occurred: [_1]',$putresult).'</span>';
16404: }
16405: if (@errors > 0) {
16406: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16407: foreach my $item (@errors) {
16408: $resulttext .= ' "'.$title->{$item}.'",';
16409: }
16410: $resulttext =~ s/,$//;
16411: }
16412: return $resulttext;
16413: }
16414:
1.46 raeburn 16415: sub modify_scantron {
1.205 raeburn 16416: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16417: my ($resulttext,%confhash,%changes,$errors);
16418: my $custom = 'custom.tab';
16419: my $default = 'default.tab';
16420: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 16421: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16422: &config_check($dom,$confname,$servadm);
16423: if ($env{'form.scantronformat.filename'} ne '') {
16424: my $error;
16425: if ($configuserok eq 'ok') {
16426: if ($switchserver) {
1.130 raeburn 16427: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16428: } else {
16429: if ($author_ok eq 'ok') {
16430: my ($result,$scantronurl) =
16431: &publishlogo($r,'upload','scantronformat',$dom,
16432: $confname,'scantron','','',$custom);
16433: if ($result eq 'ok') {
16434: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16435: $changes{'scantronformat'} = 1;
1.46 raeburn 16436: } else {
16437: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16438: }
16439: } else {
16440: $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);
16441: }
16442: }
16443: } else {
16444: $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);
16445: }
16446: if ($error) {
16447: &Apache::lonnet::logthis($error);
16448: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16449: }
16450: }
1.48 raeburn 16451: if (ref($domconfig{'scantron'}) eq 'HASH') {
16452: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16453: if ($env{'form.scantronformat_del'}) {
16454: $confhash{'scantron'}{'scantronformat'} = '';
16455: $changes{'scantronformat'} = 1;
1.347 raeburn 16456: } else {
16457: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 16458: }
16459: }
16460: }
1.347 raeburn 16461: my @options = ('hdr','pad','rem');
1.346 raeburn 16462: my @fields = &scantroncsv_fields();
16463: my %titles = &scantronconfig_titles();
1.347 raeburn 16464: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 16465: my ($newdat,$currdat,%newcol,%currcol);
16466: if (grep(/^dat$/,@formats)) {
16467: $confhash{'scantron'}{config}{dat} = 1;
16468: $newdat = 1;
16469: } else {
16470: $newdat = 0;
16471: }
16472: if (grep(/^csv$/,@formats)) {
16473: my %bynum;
16474: foreach my $field (@fields) {
16475: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16476: my $posscol = $1;
16477: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 16478: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 16479: $bynum{$posscol} = $field;
16480: $newcol{$field} = $posscol;
16481: }
16482: }
16483: }
1.347 raeburn 16484: if (keys(%newcol)) {
16485: foreach my $option (@options) {
16486: if ($env{'form.scantroncsv_'.$option}) {
16487: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16488: }
16489: }
16490: }
1.346 raeburn 16491: }
16492: $currdat = 1;
16493: if (ref($domconfig{'scantron'}) eq 'HASH') {
16494: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 16495: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 16496: $currdat = 0;
16497: }
16498: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16499: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16500: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16501: }
1.346 raeburn 16502: }
16503: }
16504: }
16505: if ($currdat != $newdat) {
16506: $changes{'config'} = 1;
16507: } else {
16508: foreach my $field (@fields) {
16509: if ($currcol{$field} ne '') {
16510: if ($currcol{$field} ne $newcol{$field}) {
16511: $changes{'config'} = 1;
16512: last;
1.347 raeburn 16513: }
1.346 raeburn 16514: } elsif ($newcol{$field} ne '') {
16515: $changes{'config'} = 1;
16516: last;
16517: }
16518: }
16519: }
1.46 raeburn 16520: if (keys(%confhash) > 0) {
16521: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16522: $dom);
16523: if ($putresult eq 'ok') {
16524: if (keys(%changes) > 0) {
1.48 raeburn 16525: if (ref($confhash{'scantron'}) eq 'HASH') {
16526: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 16527: if ($changes{'scantronformat'}) {
16528: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16529: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16530: } else {
16531: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16532: }
16533: }
1.347 raeburn 16534: if ($changes{'config'}) {
1.346 raeburn 16535: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16536: if ($confhash{'scantron'}{'config'}{'dat'}) {
16537: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16538: }
16539: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16540: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16541: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16542: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16543: foreach my $field (@fields) {
16544: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16545: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16546: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16547: }
16548: }
16549: $resulttext .= '</ul></li>';
16550: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16551: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16552: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16553: foreach my $option (@options) {
16554: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16555: $resulttext .= '<li>'.$titles{$option}.'</li>';
16556: }
16557: }
16558: $resulttext .= '</ul></li>';
16559: }
1.346 raeburn 16560: }
16561: }
16562: }
16563: }
16564: } else {
16565: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16566: }
1.46 raeburn 16567: }
1.48 raeburn 16568: $resulttext .= '</ul>';
16569: } else {
1.130 raeburn 16570: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16571: }
16572: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16573: if (ref($lastactref) eq 'HASH') {
16574: $lastactref->{'domainconfig'} = 1;
16575: }
1.46 raeburn 16576: } else {
1.346 raeburn 16577: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16578: }
16579: } else {
16580: $resulttext = '<span class="LC_error">'.
16581: &mt('An error occurred: [_1]',$putresult).'</span>';
16582: }
16583: } else {
1.130 raeburn 16584: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 16585: }
16586: if ($errors) {
1.353 raeburn 16587: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16588: $errors.'</ul></p>';
1.46 raeburn 16589: }
16590: return $resulttext;
16591: }
16592:
1.48 raeburn 16593: sub modify_coursecategories {
1.239 raeburn 16594: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16595: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16596: $cathash);
1.48 raeburn 16597: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 16598: my @catitems = ('unauth','auth');
16599: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16600: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16601: $cathash = $domconfig{'coursecategories'}{'cats'};
16602: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16603: $changes{'togglecats'} = 1;
16604: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16605: }
16606: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16607: $changes{'categorize'} = 1;
16608: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16609: }
1.120 raeburn 16610: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16611: $changes{'togglecatscomm'} = 1;
16612: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16613: }
16614: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16615: $changes{'categorizecomm'} = 1;
16616: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 16617:
16618: }
16619: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
16620: $changes{'togglecatsplace'} = 1;
16621: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
16622: }
16623: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
16624: $changes{'categorizeplace'} = 1;
16625: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 16626: }
1.238 raeburn 16627: foreach my $item (@catitems) {
16628: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16629: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16630: $changes{$item} = 1;
16631: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16632: }
16633: }
16634: }
1.57 raeburn 16635: } else {
16636: $changes{'togglecats'} = 1;
16637: $changes{'categorize'} = 1;
1.124 raeburn 16638: $changes{'togglecatscomm'} = 1;
16639: $changes{'categorizecomm'} = 1;
1.272 raeburn 16640: $changes{'togglecatsplace'} = 1;
16641: $changes{'categorizeplace'} = 1;
1.87 raeburn 16642: $domconfig{'coursecategories'} = {
16643: togglecats => $env{'form.togglecats'},
16644: categorize => $env{'form.categorize'},
1.124 raeburn 16645: togglecatscomm => $env{'form.togglecatscomm'},
16646: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 16647: togglecatsplace => $env{'form.togglecatsplace'},
16648: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 16649: };
1.238 raeburn 16650: foreach my $item (@catitems) {
16651: if ($env{'form.coursecat_'.$item} ne 'std') {
16652: $changes{$item} = 1;
16653: }
16654: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16655: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16656: }
16657: }
1.57 raeburn 16658: }
16659: if (ref($cathash) eq 'HASH') {
16660: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16661: push (@deletecategory,'instcode::0');
16662: }
1.120 raeburn 16663: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16664: push(@deletecategory,'communities::0');
16665: }
1.272 raeburn 16666: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
16667: push(@deletecategory,'placement::0');
16668: }
1.48 raeburn 16669: }
1.57 raeburn 16670: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16671: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16672: if (@deletecategory > 0) {
16673: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16674: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16675: foreach my $item (@deletecategory) {
1.57 raeburn 16676: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16677: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16678: $deletions{$item} = 1;
1.57 raeburn 16679: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16680: }
16681: }
16682: }
1.57 raeburn 16683: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16684: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16685: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16686: $reorderings{$item} = 1;
1.57 raeburn 16687: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16688: }
16689: if ($env{'form.addcategory_name_'.$item} ne '') {
16690: my $newcat = $env{'form.addcategory_name_'.$item};
16691: my $newdepth = $depth+1;
16692: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16693: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16694: $adds{$newitem} = 1;
16695: }
16696: if ($env{'form.subcat_'.$item} ne '') {
16697: my $newcat = $env{'form.subcat_'.$item};
16698: my $newdepth = $depth+1;
16699: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16700: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16701: $adds{$newitem} = 1;
16702: }
16703: }
16704: }
16705: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16706: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16707: my $newitem = 'instcode::0';
1.57 raeburn 16708: if ($cathash->{$newitem} eq '') {
16709: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16710: $adds{$newitem} = 1;
16711: }
16712: } else {
16713: my $newitem = 'instcode::0';
1.57 raeburn 16714: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16715: $adds{$newitem} = 1;
16716: }
16717: }
1.120 raeburn 16718: if ($env{'form.communities'} eq '1') {
16719: if (ref($cathash) eq 'HASH') {
16720: my $newitem = 'communities::0';
16721: if ($cathash->{$newitem} eq '') {
16722: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16723: $adds{$newitem} = 1;
16724: }
16725: } else {
16726: my $newitem = 'communities::0';
16727: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16728: $adds{$newitem} = 1;
16729: }
16730: }
1.272 raeburn 16731: if ($env{'form.placement'} eq '1') {
16732: if (ref($cathash) eq 'HASH') {
16733: my $newitem = 'placement::0';
16734: if ($cathash->{$newitem} eq '') {
16735: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16736: $adds{$newitem} = 1;
16737: }
16738: } else {
16739: my $newitem = 'placement::0';
16740: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16741: $adds{$newitem} = 1;
16742: }
16743: }
1.48 raeburn 16744: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16745: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 16746: ($env{'form.addcategory_name'} ne 'communities') &&
16747: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 16748: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16749: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16750: $adds{$newitem} = 1;
16751: }
1.48 raeburn 16752: }
1.57 raeburn 16753: my $putresult;
1.48 raeburn 16754: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16755: if (keys(%deletions) > 0) {
16756: foreach my $key (keys(%deletions)) {
16757: if ($predelallitems{$key} ne '') {
16758: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16759: }
16760: }
16761: }
16762: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16763: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16764: if (ref($chkcats[0]) eq 'ARRAY') {
16765: my $depth = 0;
16766: my $chg = 0;
16767: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16768: my $name = $chkcats[0][$i];
16769: my $item;
16770: if ($name eq '') {
16771: $chg ++;
16772: } else {
16773: $item = &escape($name).'::0';
16774: if ($chg) {
1.57 raeburn 16775: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16776: }
16777: $depth ++;
1.57 raeburn 16778: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16779: $depth --;
16780: }
16781: }
16782: }
1.57 raeburn 16783: }
16784: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16785: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16786: if ($putresult eq 'ok') {
1.57 raeburn 16787: my %title = (
1.120 raeburn 16788: togglecats => 'Show/Hide a course in catalog',
16789: categorize => 'Assign a category to a course',
16790: togglecatscomm => 'Show/Hide a community in catalog',
16791: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16792: );
16793: my %level = (
1.120 raeburn 16794: dom => 'set in Domain ("Modify Course/Community")',
16795: crs => 'set in Course ("Course Configuration")',
16796: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 16797: none => 'No catalog',
16798: std => 'Standard catalog',
16799: domonly => 'Domain-only catalog',
16800: codesrch => 'Code search form',
1.57 raeburn 16801: );
1.48 raeburn 16802: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16803: if ($changes{'togglecats'}) {
16804: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16805: }
16806: if ($changes{'categorize'}) {
16807: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16808: }
1.120 raeburn 16809: if ($changes{'togglecatscomm'}) {
16810: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16811: }
16812: if ($changes{'categorizecomm'}) {
16813: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16814: }
1.238 raeburn 16815: if ($changes{'unauth'}) {
16816: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16817: }
16818: if ($changes{'auth'}) {
16819: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16820: }
1.57 raeburn 16821: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16822: my $cathash;
16823: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16824: $cathash = $domconfig{'coursecategories'}{'cats'};
16825: } else {
16826: $cathash = {};
16827: }
16828: my (@cats,@trails,%allitems);
16829: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16830: if (keys(%deletions) > 0) {
16831: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16832: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16833: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16834: }
16835: $resulttext .= '</ul></li>';
16836: }
16837: if (keys(%reorderings) > 0) {
16838: my %sort_by_trail;
16839: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16840: foreach my $key (keys(%reorderings)) {
16841: if ($allitems{$key} ne '') {
16842: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16843: }
1.48 raeburn 16844: }
1.57 raeburn 16845: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16846: $resulttext .= '<li>'.$trails[$trail].'</li>';
16847: }
16848: $resulttext .= '</ul></li>';
1.48 raeburn 16849: }
1.57 raeburn 16850: if (keys(%adds) > 0) {
16851: my %sort_by_trail;
16852: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16853: foreach my $key (keys(%adds)) {
16854: if ($allitems{$key} ne '') {
16855: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16856: }
16857: }
16858: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16859: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16860: }
1.57 raeburn 16861: $resulttext .= '</ul></li>';
1.48 raeburn 16862: }
16863: }
16864: $resulttext .= '</ul>';
1.239 raeburn 16865: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 16866: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16867: if ($changes{'auth'}) {
16868: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16869: }
16870: if ($changes{'unauth'}) {
16871: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16872: }
16873: my $cachetime = 24*60*60;
16874: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 16875: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 16876: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 16877: }
16878: }
1.48 raeburn 16879: } else {
16880: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16881: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16882: }
16883: } else {
1.120 raeburn 16884: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16885: }
16886: return $resulttext;
16887: }
16888:
1.69 raeburn 16889: sub modify_serverstatuses {
16890: my ($dom,%domconfig) = @_;
16891: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
16892: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
16893: %currserverstatus = %{$domconfig{'serverstatuses'}};
16894: }
16895: my @pages = &serverstatus_pages();
16896: foreach my $type (@pages) {
16897: $newserverstatus{$type}{'namedusers'} = '';
16898: $newserverstatus{$type}{'machines'} = '';
16899: if (defined($env{'form.'.$type.'_namedusers'})) {
16900: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
16901: my @okusers;
16902: foreach my $user (@users) {
16903: my ($uname,$udom) = split(/:/,$user);
16904: if (($udom =~ /^$match_domain$/) &&
16905: (&Apache::lonnet::domain($udom)) &&
16906: ($uname =~ /^$match_username$/)) {
16907: if (!grep(/^\Q$user\E/,@okusers)) {
16908: push(@okusers,$user);
16909: }
16910: }
16911: }
16912: if (@okusers > 0) {
16913: @okusers = sort(@okusers);
16914: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
16915: }
16916: }
16917: if (defined($env{'form.'.$type.'_machines'})) {
16918: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
16919: my @okmachines;
16920: foreach my $ip (@machines) {
16921: my @parts = split(/\./,$ip);
16922: next if (@parts < 4);
16923: my $badip = 0;
16924: for (my $i=0; $i<4; $i++) {
16925: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
16926: $badip = 1;
16927: last;
16928: }
16929: }
16930: if (!$badip) {
16931: push(@okmachines,$ip);
16932: }
16933: }
16934: @okmachines = sort(@okmachines);
16935: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
16936: }
16937: }
16938: my %serverstatushash = (
16939: serverstatuses => \%newserverstatus,
16940: );
16941: foreach my $type (@pages) {
1.83 raeburn 16942: foreach my $setting ('namedusers','machines') {
1.84 raeburn 16943: my (@current,@new);
1.83 raeburn 16944: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 16945: if ($currserverstatus{$type}{$setting} ne '') {
16946: @current = split(/,/,$currserverstatus{$type}{$setting});
16947: }
16948: }
16949: if ($newserverstatus{$type}{$setting} ne '') {
16950: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 16951: }
16952: if (@current > 0) {
16953: if (@new > 0) {
16954: foreach my $item (@current) {
16955: if (!grep(/^\Q$item\E$/,@new)) {
16956: $changes{$type}{$setting} = 1;
1.82 raeburn 16957: last;
16958: }
16959: }
1.84 raeburn 16960: foreach my $item (@new) {
16961: if (!grep(/^\Q$item\E$/,@current)) {
16962: $changes{$type}{$setting} = 1;
16963: last;
1.82 raeburn 16964: }
16965: }
16966: } else {
1.83 raeburn 16967: $changes{$type}{$setting} = 1;
1.69 raeburn 16968: }
1.83 raeburn 16969: } elsif (@new > 0) {
16970: $changes{$type}{$setting} = 1;
1.69 raeburn 16971: }
16972: }
16973: }
16974: if (keys(%changes) > 0) {
1.81 raeburn 16975: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 16976: my $putresult = &Apache::lonnet::put_dom('configuration',
16977: \%serverstatushash,$dom);
16978: if ($putresult eq 'ok') {
16979: $resulttext .= &mt('Changes made:').'<ul>';
16980: foreach my $type (@pages) {
1.84 raeburn 16981: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 16982: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 16983: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 16984: if ($newserverstatus{$type}{'namedusers'} eq '') {
16985: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
16986: } else {
16987: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
16988: }
1.84 raeburn 16989: }
16990: if ($changes{$type}{'machines'}) {
1.69 raeburn 16991: if ($newserverstatus{$type}{'machines'} eq '') {
16992: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
16993: } else {
16994: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
16995: }
16996:
16997: }
16998: $resulttext .= '</ul></li>';
16999: }
17000: }
17001: $resulttext .= '</ul>';
17002: } else {
17003: $resulttext = '<span class="LC_error">'.
17004: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17005:
17006: }
17007: } else {
17008: $resulttext = &mt('No changes made to access to server status pages');
17009: }
17010: return $resulttext;
17011: }
17012:
1.118 jms 17013: sub modify_helpsettings {
1.285 raeburn 17014: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 17015: my ($resulttext,$errors,%changes,%helphash);
17016: my %defaultchecked = ('submitbugs' => 'on');
17017: my @offon = ('off','on');
1.118 jms 17018: my @toggles = ('submitbugs');
1.285 raeburn 17019: my %current = ('submitbugs' => '',
17020: 'adhoc' => {},
17021: );
1.118 jms 17022: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 17023: %current = %{$domconfig{'helpsettings'}};
17024: }
1.285 raeburn 17025: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 17026: foreach my $item (@toggles) {
17027: if ($defaultchecked{$item} eq 'on') {
17028: if ($current{$item} eq '') {
17029: if ($env{'form.'.$item} eq '0') {
17030: $changes{$item} = 1;
17031: }
17032: } elsif ($current{$item} ne $env{'form.'.$item}) {
17033: $changes{$item} = 1;
17034: }
17035: } elsif ($defaultchecked{$item} eq 'off') {
17036: if ($current{$item} eq '') {
17037: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 17038: $changes{$item} = 1;
17039: }
1.282 raeburn 17040: } elsif ($current{$item} ne $env{'form.'.$item}) {
17041: $changes{$item} = 1;
17042: }
17043: }
17044: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17045: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17046: }
17047: }
1.285 raeburn 17048: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 17049: my $confname = $dom.'-domainconfig';
17050: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 17051: my (@allpos,%newsettings,%changedprivs,$newrole);
17052: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 17053: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 17054: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 17055: my %lt = &Apache::lonlocal::texthash(
17056: s => 'system',
17057: d => 'domain',
17058: order => 'Display order',
17059: access => 'Role usage',
1.291 raeburn 17060: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 17061: dh => 'All with domain helpdesk role',
17062: da => 'All with domain helpdesk assistant role',
1.285 raeburn 17063: none => 'None',
17064: status => 'Determined based on institutional status',
17065: inc => 'Include all, but exclude specific personnel',
17066: exc => 'Exclude all, but include specific personnel',
17067: );
17068: for (my $num=0; $num<=$maxnum; $num++) {
17069: my ($prefix,$identifier,$rolename,%curr);
17070: if ($num == $maxnum) {
17071: next unless ($env{'form.newcusthelp'} == $maxnum);
17072: $identifier = 'custhelp'.$num;
17073: $prefix = 'helproles_'.$num;
17074: $rolename = $env{'form.custhelpname'.$num};
17075: $rolename=~s/[^A-Za-z0-9]//gs;
17076: next if ($rolename eq '');
17077: next if (exists($existing{'rolesdef_'.$rolename}));
17078: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17079: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17080: $newprivs{'c'},$confname,$dom);
17081: if ($result ne 'ok') {
17082: $errors .= '<li><span class="LC_error">'.
17083: &mt('An error occurred storing the new custom role: [_1]',
17084: $result).'</span></li>';
17085: next;
17086: } else {
17087: $changedprivs{$rolename} = \%newprivs;
17088: $newrole = $rolename;
17089: }
17090: } else {
17091: $prefix = 'helproles_'.$num;
17092: $rolename = $env{'form.'.$prefix};
17093: next if ($rolename eq '');
17094: next unless (exists($existing{'rolesdef_'.$rolename}));
17095: $identifier = 'custhelp'.$num;
17096: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17097: my %currprivs;
1.289 raeburn 17098: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 17099: split(/\_/,$existing{'rolesdef_'.$rolename});
17100: foreach my $level ('c','d','s') {
17101: if ($newprivs{$level} ne $currprivs{$level}) {
17102: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17103: $newprivs{'c'},$confname,$dom);
17104: if ($result ne 'ok') {
17105: $errors .= '<li><span class="LC_error">'.
17106: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17107: $rolename,$result).'</span></li>';
17108: } else {
17109: $changedprivs{$rolename} = \%newprivs;
17110: }
17111: last;
17112: }
17113: }
17114: if (ref($current{'adhoc'}) eq 'HASH') {
17115: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17116: %curr = %{$current{'adhoc'}{$rolename}};
17117: }
17118: }
17119: }
17120: my $newpos = $env{'form.'.$prefix.'_pos'};
17121: $newpos =~ s/\D+//g;
17122: $allpos[$newpos] = $rolename;
17123: my $newdesc = $env{'form.'.$prefix.'_desc'};
17124: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17125: if ($curr{'desc'}) {
17126: if ($curr{'desc'} ne $newdesc) {
17127: $changes{'customrole'}{$rolename}{'desc'} = 1;
17128: $newsettings{$rolename}{'desc'} = $newdesc;
17129: }
17130: } elsif ($newdesc ne '') {
17131: $changes{'customrole'}{$rolename}{'desc'} = 1;
17132: $newsettings{$rolename}{'desc'} = $newdesc;
17133: }
17134: my $access = $env{'form.'.$prefix.'_access'};
17135: if (grep(/^\Q$access\E$/,@accesstypes)) {
17136: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17137: if ($access eq 'status') {
17138: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17139: if (scalar(@statuses) == 0) {
1.289 raeburn 17140: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 17141: } else {
17142: my (@shownstatus,$numtypes);
17143: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17144: if (ref($types) eq 'ARRAY') {
17145: $numtypes = scalar(@{$types});
17146: foreach my $type (sort(@statuses)) {
17147: if ($type eq 'default') {
17148: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17149: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17150: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17151: push(@shownstatus,$usertypes->{$type});
17152: }
17153: }
17154: }
17155: if (grep(/^default$/,@statuses)) {
17156: push(@shownstatus,$othertitle);
17157: }
17158: if (scalar(@shownstatus) == 1+$numtypes) {
17159: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17160: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17161: } else {
17162: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17163: if (ref($curr{'status'}) eq 'ARRAY') {
17164: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17165: if (@diffs) {
17166: $changes{'customrole'}{$rolename}{$access} = 1;
17167: }
17168: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17169: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 17170: }
1.166 raeburn 17171: }
17172: }
1.285 raeburn 17173: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17174: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17175: my @newspecstaff;
17176: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17177: foreach my $person (sort(@personnel)) {
17178: if ($domhelpdesk{$person}) {
17179: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17180: }
17181: }
17182: if (ref($curr{$access}) eq 'ARRAY') {
17183: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17184: if (@diffs) {
17185: $changes{'customrole'}{$rolename}{$access} = 1;
17186: }
17187: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17188: $changes{'customrole'}{$rolename}{$access} = 1;
17189: }
17190: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17191: my ($uname,$udom) = split(/:/,$person);
17192: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17193: }
17194: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 17195: }
1.285 raeburn 17196: } else {
17197: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17198: }
17199: unless ($curr{'access'} eq $access) {
17200: $changes{'customrole'}{$rolename}{'access'} = 1;
17201: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 17202: }
17203: }
1.285 raeburn 17204: if (@allpos > 0) {
17205: my $idx = 0;
17206: foreach my $rolename (@allpos) {
17207: if ($rolename ne '') {
17208: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17209: if (ref($current{'adhoc'}) eq 'HASH') {
17210: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17211: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17212: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 17213: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 17214: }
17215: }
1.282 raeburn 17216: }
1.285 raeburn 17217: $idx ++;
1.166 raeburn 17218: }
17219: }
1.118 jms 17220: }
1.123 jms 17221: my $putresult;
17222: if (keys(%changes) > 0) {
1.166 raeburn 17223: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 17224: if ($putresult eq 'ok') {
1.285 raeburn 17225: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17226: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17227: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17228: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17229: }
17230: }
17231: my $cachetime = 24*60*60;
17232: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17233: if (ref($lastactref) eq 'HASH') {
17234: $lastactref->{'domdefaults'} = 1;
17235: }
17236: } else {
17237: $errors .= '<li><span class="LC_error">'.
17238: &mt('An error occurred storing the settings: [_1]',
17239: $putresult).'</span></li>';
17240: }
17241: }
17242: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17243: $resulttext = &mt('Changes made:').'<ul>';
17244: my (%shownprivs,@levelorder);
17245: @levelorder = ('c','d','s');
17246: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 17247: foreach my $item (sort(keys(%changes))) {
17248: if ($item eq 'submitbugs') {
17249: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17250: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17251: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 17252: } elsif ($item eq 'customrole') {
17253: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 17254: my @keyorder = ('order','desc','access','status','exc','inc');
17255: my %keytext = &Apache::lonlocal::texthash(
17256: order => 'Order',
17257: desc => 'Role description',
17258: access => 'Role usage',
1.300 droeschl 17259: status => 'Allowed institutional types',
1.285 raeburn 17260: exc => 'Allowed personnel',
17261: inc => 'Disallowed personnel',
17262: );
1.282 raeburn 17263: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 17264: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17265: if ($role eq $newrole) {
17266: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17267: $role).'<ul>';
17268: } else {
17269: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17270: $role).'<ul>';
17271: }
17272: foreach my $key (@keyorder) {
17273: if ($changes{'customrole'}{$role}{$key}) {
17274: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17275: $keytext{$key},$newsettings{$role}{$key}).
17276: '</li>';
17277: }
17278: }
17279: if (ref($changedprivs{$role}) eq 'HASH') {
17280: $shownprivs{$role} = 1;
17281: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17282: foreach my $level (@levelorder) {
17283: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17284: next if ($item eq '');
17285: my ($priv) = split(/\&/,$item,2);
17286: if (&Apache::lonnet::plaintext($priv)) {
17287: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17288: unless ($level eq 'c') {
17289: $resulttext .= ' ('.$lt{$level}.')';
17290: }
17291: $resulttext .= '</li>';
17292: }
17293: }
17294: }
17295: $resulttext .= '</ul>';
17296: }
17297: $resulttext .= '</ul></li>';
17298: }
17299: }
17300: }
17301: }
17302: }
17303: }
17304: if (keys(%changedprivs)) {
17305: foreach my $role (sort(keys(%changedprivs))) {
17306: unless ($shownprivs{$role}) {
17307: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17308: $role).'<ul>'.
17309: '<li>'.&mt('Privileges set to :').'<ul>';
17310: foreach my $level (@levelorder) {
17311: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17312: next if ($item eq '');
17313: my ($priv) = split(/\&/,$item,2);
17314: if (&Apache::lonnet::plaintext($priv)) {
17315: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17316: unless ($level eq 'c') {
17317: $resulttext .= ' ('.$lt{$level}.')';
17318: }
17319: $resulttext .= '</li>';
17320: }
1.282 raeburn 17321: }
17322: }
1.285 raeburn 17323: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 17324: }
17325: }
17326: }
1.285 raeburn 17327: $resulttext .= '</ul>';
17328: } else {
17329: $resulttext = &mt('No changes made to help settings');
1.118 jms 17330: }
17331: if ($errors) {
1.168 raeburn 17332: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 17333: $errors.'</ul>';
1.118 jms 17334: }
17335: return $resulttext;
17336: }
17337:
1.121 raeburn 17338: sub modify_coursedefaults {
1.212 raeburn 17339: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17340: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 17341: my %defaultchecked = (
17342: 'canuse_pdfforms' => 'off',
17343: 'uselcmath' => 'on',
17344: 'usejsme' => 'on'
17345: );
17346: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 17347: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 17348: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
17349: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
17350: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 17351: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 17352: my %staticdefaults = (
17353: anonsurvey_threshold => 10,
17354: uploadquota => 500,
1.257 raeburn 17355: postsubmit => 60,
1.276 raeburn 17356: mysqltables => 172800,
1.198 raeburn 17357: );
1.314 raeburn 17358: my %texoptions = (
17359: MathJax => 'MathJax',
17360: mimetex => &mt('Convert to Images'),
17361: tth => &mt('TeX to HTML'),
17362: );
1.121 raeburn 17363: $defaultshash{'coursedefaults'} = {};
17364:
17365: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17366: if ($domconfig{'coursedefaults'} eq '') {
17367: $domconfig{'coursedefaults'} = {};
17368: }
17369: }
17370:
17371: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17372: foreach my $item (@toggles) {
17373: if ($defaultchecked{$item} eq 'on') {
17374: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17375: ($env{'form.'.$item} eq '0')) {
17376: $changes{$item} = 1;
1.192 raeburn 17377: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17378: $changes{$item} = 1;
17379: }
17380: } elsif ($defaultchecked{$item} eq 'off') {
17381: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17382: ($env{'form.'.$item} eq '1')) {
17383: $changes{$item} = 1;
17384: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17385: $changes{$item} = 1;
17386: }
17387: }
17388: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17389: }
1.198 raeburn 17390: foreach my $item (@numbers) {
17391: my ($currdef,$newdef);
1.208 raeburn 17392: $newdef = $env{'form.'.$item};
1.198 raeburn 17393: if ($item eq 'anonsurvey_threshold') {
17394: $currdef = $domconfig{'coursedefaults'}{$item};
17395: $newdef =~ s/\D//g;
17396: if ($newdef eq '' || $newdef < 1) {
17397: $newdef = 1;
17398: }
17399: $defaultshash{'coursedefaults'}{$item} = $newdef;
17400: } else {
1.276 raeburn 17401: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17402: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17403: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 17404: }
17405: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 17406: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 17407: }
17408: if ($currdef ne $newdef) {
17409: if ($item eq 'anonsurvey_threshold') {
17410: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17411: $changes{$item} = 1;
17412: }
1.276 raeburn 17413: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 17414: my $setting = $1;
1.276 raeburn 17415: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17416: $changes{$setting} = 1;
1.198 raeburn 17417: }
17418: }
1.139 raeburn 17419: }
17420: }
1.314 raeburn 17421: my $texengine;
17422: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17423: $texengine = $env{'form.texengine'};
1.349 raeburn 17424: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17425: if ($currdef eq '') {
17426: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 17427: $changes{'texengine'} = 1;
17428: }
1.349 raeburn 17429: } elsif ($currdef ne $texengine) {
1.314 raeburn 17430: $changes{'texengine'} = 1;
17431: }
17432: }
17433: if ($texengine ne '') {
17434: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17435: }
1.264 raeburn 17436: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17437: my @currclonecode;
17438: if (ref($currclone) eq 'HASH') {
17439: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17440: @currclonecode = @{$currclone->{'instcode'}};
17441: }
17442: }
17443: my $newclone;
1.289 raeburn 17444: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 17445: $newclone = $env{'form.canclone'};
17446: }
17447: if ($newclone eq 'instcode') {
17448: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17449: my (%codedefaults,@code_order,@clonecode);
17450: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17451: \@code_order);
17452: foreach my $item (@code_order) {
17453: if (grep(/^\Q$item\E$/,@newcodes)) {
17454: push(@clonecode,$item);
17455: }
17456: }
17457: if (@clonecode) {
17458: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17459: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17460: if (@diffs) {
17461: $changes{'canclone'} = 1;
17462: }
17463: } else {
17464: $newclone eq '';
17465: }
17466: } elsif ($newclone ne '') {
1.289 raeburn 17467: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17468: }
1.264 raeburn 17469: if ($newclone ne $currclone) {
17470: $changes{'canclone'} = 1;
17471: }
1.257 raeburn 17472: my %credits;
17473: foreach my $type (@types) {
17474: unless ($type eq 'community') {
17475: $credits{$type} = $env{'form.'.$type.'_credits'};
17476: $credits{$type} =~ s/[^\d.]+//g;
17477: }
17478: }
17479: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17480: ($env{'form.coursecredits'} eq '1')) {
17481: $changes{'coursecredits'} = 1;
17482: foreach my $type (keys(%credits)) {
17483: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17484: }
17485: } else {
1.289 raeburn 17486: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 17487: foreach my $type (@types) {
17488: unless ($type eq 'community') {
1.289 raeburn 17489: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 17490: $changes{'coursecredits'} = 1;
17491: }
17492: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17493: }
17494: }
17495: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17496: foreach my $type (@types) {
17497: unless ($type eq 'community') {
17498: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17499: $changes{'coursecredits'} = 1;
17500: last;
17501: }
17502: }
17503: }
17504: }
17505: }
17506: if ($env{'form.postsubmit'} eq '1') {
17507: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17508: my %currtimeout;
17509: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17510: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17511: $changes{'postsubmit'} = 1;
17512: }
17513: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17514: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17515: }
17516: } else {
17517: $changes{'postsubmit'} = 1;
17518: }
17519: foreach my $type (@types) {
17520: my $timeout = $env{'form.'.$type.'_timeout'};
17521: $timeout =~ s/\D//g;
17522: if ($timeout == $staticdefaults{'postsubmit'}) {
17523: $timeout = '';
17524: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17525: $timeout = '0';
17526: }
17527: unless ($timeout eq '') {
17528: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17529: }
17530: if (exists($currtimeout{$type})) {
17531: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 17532: $changes{'postsubmit'} = 1;
1.257 raeburn 17533: }
17534: } elsif ($timeout ne '') {
17535: $changes{'postsubmit'} = 1;
17536: }
17537: }
17538: } else {
17539: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17540: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17541: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17542: $changes{'postsubmit'} = 1;
17543: }
17544: } else {
17545: $changes{'postsubmit'} = 1;
17546: }
1.192 raeburn 17547: }
1.121 raeburn 17548: }
17549: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17550: $dom);
17551: if ($putresult eq 'ok') {
17552: if (keys(%changes) > 0) {
1.213 raeburn 17553: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 17554: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 17555: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 17556: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
17557: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 17558: if ($changes{$item}) {
17559: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17560: }
1.289 raeburn 17561: }
1.192 raeburn 17562: if ($changes{'coursecredits'}) {
17563: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 17564: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17565: $domdefaults{$type.'credits'} =
17566: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17567: }
17568: }
17569: }
17570: if ($changes{'postsubmit'}) {
17571: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17572: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17573: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17574: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17575: $domdefaults{$type.'postsubtimeout'} =
17576: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17577: }
17578: }
1.192 raeburn 17579: }
17580: }
1.198 raeburn 17581: if ($changes{'uploadquota'}) {
17582: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17583: foreach my $type (@types) {
17584: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17585: }
17586: }
17587: }
1.264 raeburn 17588: if ($changes{'canclone'}) {
17589: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17590: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17591: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17592: if (@clonecodes) {
17593: $domdefaults{'canclone'} = join('+',@clonecodes);
17594: }
17595: }
17596: } else {
17597: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17598: }
17599: }
1.121 raeburn 17600: my $cachetime = 24*60*60;
17601: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17602: if (ref($lastactref) eq 'HASH') {
17603: $lastactref->{'domdefaults'} = 1;
17604: }
1.121 raeburn 17605: }
17606: $resulttext = &mt('Changes made:').'<ul>';
17607: foreach my $item (sort(keys(%changes))) {
17608: if ($item eq 'canuse_pdfforms') {
17609: if ($env{'form.'.$item} eq '1') {
17610: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
17611: } else {
17612: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
17613: }
1.257 raeburn 17614: } elsif ($item eq 'uselcmath') {
17615: if ($env{'form.'.$item} eq '1') {
17616: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17617: } else {
17618: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17619: }
17620: } elsif ($item eq 'usejsme') {
17621: if ($env{'form.'.$item} eq '1') {
17622: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17623: } else {
1.289 raeburn 17624: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 17625: }
1.314 raeburn 17626: } elsif ($item eq 'texengine') {
17627: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17628: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17629: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17630: }
1.139 raeburn 17631: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 17632: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 17633: } elsif ($item eq 'uploadquota') {
17634: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17635: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17636: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17637: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 17638: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 17639: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 17640: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17641: '</ul>'.
17642: '</li>';
17643: } else {
17644: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17645: }
1.276 raeburn 17646: } elsif ($item eq 'mysqltables') {
17647: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17648: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17649: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17650: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17651: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17652: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
17653: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17654: '</ul>'.
17655: '</li>';
17656: } else {
17657: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17658: }
1.257 raeburn 17659: } elsif ($item eq 'postsubmit') {
17660: if ($domdefaults{'postsubmit'} eq 'off') {
17661: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17662: } else {
17663: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 17664: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 17665: $resulttext .= &mt('durations:').'<ul>';
17666: foreach my $type (@types) {
17667: $resulttext .= '<li>';
17668: my $timeout;
17669: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17670: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17671: }
17672: my $display;
17673: if ($timeout eq '0') {
17674: $display = &mt('unlimited');
17675: } elsif ($timeout eq '') {
17676: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17677: } else {
17678: $display = &mt('[quant,_1,second]',$timeout);
17679: }
17680: if ($type eq 'community') {
17681: $resulttext .= &mt('Communities');
17682: } elsif ($type eq 'official') {
17683: $resulttext .= &mt('Official courses');
17684: } elsif ($type eq 'unofficial') {
17685: $resulttext .= &mt('Unofficial courses');
17686: } elsif ($type eq 'textbook') {
17687: $resulttext .= &mt('Textbook courses');
1.271 raeburn 17688: } elsif ($type eq 'placement') {
17689: $resulttext .= &mt('Placement tests');
1.257 raeburn 17690: }
17691: $resulttext .= ' -- '.$display.'</li>';
17692: }
17693: $resulttext .= '</ul>';
17694: }
1.289 raeburn 17695: $resulttext .= '</li>';
1.257 raeburn 17696: }
1.192 raeburn 17697: } elsif ($item eq 'coursecredits') {
17698: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17699: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 17700: ($domdefaults{'unofficialcredits'} eq '') &&
17701: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 17702: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17703: } else {
17704: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17705: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17706: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 17707: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 17708: '</ul>'.
17709: '</li>';
17710: }
17711: } else {
17712: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17713: }
1.264 raeburn 17714: } elsif ($item eq 'canclone') {
17715: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17716: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17717: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17718: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17719: }
17720: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17721: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17722: } else {
1.289 raeburn 17723: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 17724: }
1.140 raeburn 17725: }
1.121 raeburn 17726: }
17727: $resulttext .= '</ul>';
17728: } else {
17729: $resulttext = &mt('No changes made to course defaults');
17730: }
17731: } else {
17732: $resulttext = '<span class="LC_error">'.
17733: &mt('An error occurred: [_1]',$putresult).'</span>';
17734: }
17735: return $resulttext;
17736: }
17737:
1.231 raeburn 17738: sub modify_selfenrollment {
17739: my ($dom,$lastactref,%domconfig) = @_;
17740: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 17741: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 17742: my %titles = &tool_titles();
1.232 raeburn 17743: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17744: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 17745: $ordered{'default'} = ['types','registered','approval','limit'];
17746:
17747: my (%roles,%shown,%toplevel);
17748: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17749:
17750: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17751: if ($domconfig{'selfenrollment'} eq '') {
17752: $domconfig{'selfenrollment'} = {};
17753: }
17754: }
17755: %toplevel = (
17756: admin => 'Configuration Rights',
17757: default => 'Default settings',
17758: validation => 'Validation of self-enrollment requests',
17759: );
1.233 raeburn 17760: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 17761:
17762: if (ref($ordered{'admin'}) eq 'ARRAY') {
17763: foreach my $item (@{$ordered{'admin'}}) {
17764: foreach my $type (@types) {
17765: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17766: $selfenrollhash{'admin'}{$type}{$item} = 1;
17767: } else {
17768: $selfenrollhash{'admin'}{$type}{$item} = 0;
17769: }
17770: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17771: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17772: if ($selfenrollhash{'admin'}{$type}{$item} ne
17773: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17774: push(@{$changes{'admin'}{$type}},$item);
17775: }
17776: } else {
17777: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17778: push(@{$changes{'admin'}{$type}},$item);
17779: }
17780: }
17781: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17782: push(@{$changes{'admin'}{$type}},$item);
17783: }
17784: }
17785: }
17786: }
17787:
17788: foreach my $item (@{$ordered{'default'}}) {
17789: foreach my $type (@types) {
17790: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17791: if ($item eq 'types') {
17792: unless (($value eq 'all') || ($value eq 'dom')) {
17793: $value = '';
17794: }
17795: } elsif ($item eq 'registered') {
17796: unless ($value eq '1') {
17797: $value = 0;
17798: }
17799: } elsif ($item eq 'approval') {
17800: unless ($value =~ /^[012]$/) {
17801: $value = 0;
17802: }
17803: } else {
17804: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17805: $value = 'none';
17806: }
17807: }
17808: $selfenrollhash{'default'}{$type}{$item} = $value;
17809: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17810: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17811: if ($selfenrollhash{'default'}{$type}{$item} ne
17812: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17813: push(@{$changes{'default'}{$type}},$item);
17814: }
17815: } else {
17816: push(@{$changes{'default'}{$type}},$item);
17817: }
17818: } else {
17819: push(@{$changes{'default'}{$type}},$item);
17820: }
17821: if ($item eq 'limit') {
17822: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17823: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17824: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17825: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17826: }
17827: } else {
17828: $selfenrollhash{'default'}{$type}{'cap'} = '';
17829: }
17830: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17831: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17832: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17833: push(@{$changes{'default'}{$type}},'cap');
17834: }
17835: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17836: push(@{$changes{'default'}{$type}},'cap');
17837: }
17838: }
17839: }
17840: }
17841:
17842: foreach my $item (@{$itemsref}) {
17843: if ($item eq 'fields') {
17844: my @changed;
17845: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17846: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17847: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17848: }
17849: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17850: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17851: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17852: $domconfig{'selfenrollment'}{'validation'}{$item});
17853: } else {
17854: @changed = @{$selfenrollhash{'validation'}{$item}};
17855: }
17856: } else {
17857: @changed = @{$selfenrollhash{'validation'}{$item}};
17858: }
17859: if (@changed) {
17860: if ($selfenrollhash{'validation'}{$item}) {
17861: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17862: } else {
17863: $changes{'validation'}{$item} = &mt('None');
17864: }
17865: }
17866: } else {
17867: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17868: if ($item eq 'markup') {
17869: if ($env{'form.selfenroll_validation_'.$item}) {
17870: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17871: }
17872: }
17873: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17874: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17875: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17876: }
17877: }
17878: }
17879: }
17880:
17881: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17882: $dom);
17883: if ($putresult eq 'ok') {
17884: if (keys(%changes) > 0) {
17885: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17886: $resulttext = &mt('Changes made:').'<ul>';
17887: foreach my $key ('admin','default','validation') {
17888: if (ref($changes{$key}) eq 'HASH') {
17889: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17890: if ($key eq 'validation') {
17891: foreach my $item (@{$itemsref}) {
17892: if (exists($changes{$key}{$item})) {
17893: if ($item eq 'markup') {
17894: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17895: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
17896: } else {
17897: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
17898: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
17899: }
17900: }
17901: }
17902: } else {
17903: foreach my $type (@types) {
17904: if ($type eq 'community') {
17905: $roles{'1'} = &mt('Community personnel');
17906: } else {
17907: $roles{'1'} = &mt('Course personnel');
17908: }
17909: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 17910: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17911: if ($key eq 'admin') {
17912: my @mgrdc = ();
17913: if (ref($ordered{$key}) eq 'ARRAY') {
17914: foreach my $item (@{$ordered{'admin'}}) {
17915: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
17916: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
17917: push(@mgrdc,$item);
17918: }
17919: }
17920: }
17921: if (@mgrdc) {
17922: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
17923: } else {
17924: delete($domdefaults{$type.'selfenrolladmdc'});
17925: }
17926: }
17927: } else {
17928: if (ref($ordered{$key}) eq 'ARRAY') {
17929: foreach my $item (@{$ordered{$key}}) {
17930: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17931: $domdefaults{$type.'selfenroll'.$item} =
17932: $selfenrollhash{$key}{$type}{$item};
17933: }
17934: }
17935: }
17936: }
17937: }
1.231 raeburn 17938: $resulttext .= '<li>'.$titles{$type}.'<ul>';
17939: foreach my $item (@{$ordered{$key}}) {
17940: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
17941: $resulttext .= '<li>';
17942: if ($key eq 'admin') {
17943: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
17944: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
17945: } else {
17946: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
17947: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
17948: }
17949: $resulttext .= '</li>';
17950: }
17951: }
17952: $resulttext .= '</ul></li>';
17953: }
17954: }
17955: $resulttext .= '</ul></li>';
17956: }
17957: }
1.305 raeburn 17958: }
17959: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
17960: my $cachetime = 24*60*60;
17961: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17962: if (ref($lastactref) eq 'HASH') {
17963: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 17964: }
1.231 raeburn 17965: }
17966: $resulttext .= '</ul>';
17967: } else {
17968: $resulttext = &mt('No changes made to self-enrollment settings');
17969: }
17970: } else {
17971: $resulttext = '<span class="LC_error">'.
17972: &mt('An error occurred: [_1]',$putresult).'</span>';
17973: }
17974: return $resulttext;
17975: }
17976:
1.137 raeburn 17977: sub modify_usersessions {
1.212 raeburn 17978: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 17979: my @hostingtypes = ('version','excludedomain','includedomain');
17980: my @offloadtypes = ('primary','default');
17981: my %types = (
17982: remote => \@hostingtypes,
17983: hosted => \@hostingtypes,
17984: spares => \@offloadtypes,
17985: );
17986: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 17987: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 17988: my (%by_ip,%by_location,@intdoms,@instdoms);
17989: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 17990: my @locations = sort(keys(%by_location));
1.137 raeburn 17991: my (%defaultshash,%changes);
17992: foreach my $prefix (@prefixes) {
17993: $defaultshash{'usersessions'}{$prefix} = {};
17994: }
1.212 raeburn 17995: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 17996: my $resulttext;
1.138 raeburn 17997: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 17998: foreach my $prefix (@prefixes) {
1.145 raeburn 17999: next if ($prefix eq 'spares');
18000: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 18001: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18002: if ($type eq 'version') {
18003: my $value = $env{'form.'.$prefix.'_'.$type};
18004: my $okvalue;
18005: if ($value ne '') {
18006: if (grep(/^\Q$value\E$/,@lcversions)) {
18007: $okvalue = $value;
18008: }
18009: }
18010: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18011: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18012: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18013: if ($inuse == 0) {
18014: $changes{$prefix}{$type} = 1;
18015: } else {
18016: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18017: $changes{$prefix}{$type} = 1;
18018: }
18019: if ($okvalue ne '') {
18020: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18021: }
18022: }
18023: } else {
18024: if (($inuse == 1) && ($okvalue ne '')) {
18025: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18026: $changes{$prefix}{$type} = 1;
18027: }
18028: }
18029: } else {
18030: if (($inuse == 1) && ($okvalue ne '')) {
18031: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18032: $changes{$prefix}{$type} = 1;
18033: }
18034: }
18035: } else {
18036: if (($inuse == 1) && ($okvalue ne '')) {
18037: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18038: $changes{$prefix}{$type} = 1;
18039: }
18040: }
18041: } else {
18042: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18043: my @okvals;
18044: foreach my $val (@vals) {
1.138 raeburn 18045: if ($val =~ /:/) {
18046: my @items = split(/:/,$val);
18047: foreach my $item (@items) {
18048: if (ref($by_location{$item}) eq 'ARRAY') {
18049: push(@okvals,$item);
18050: }
18051: }
18052: } else {
18053: if (ref($by_location{$val}) eq 'ARRAY') {
18054: push(@okvals,$val);
18055: }
1.137 raeburn 18056: }
18057: }
18058: @okvals = sort(@okvals);
18059: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18060: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18061: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18062: if ($inuse == 0) {
18063: $changes{$prefix}{$type} = 1;
18064: } else {
18065: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18066: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18067: if (@changed > 0) {
18068: $changes{$prefix}{$type} = 1;
18069: }
18070: }
18071: } else {
18072: if ($inuse == 1) {
18073: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18074: $changes{$prefix}{$type} = 1;
18075: }
18076: }
18077: } else {
18078: if ($inuse == 1) {
18079: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18080: $changes{$prefix}{$type} = 1;
18081: }
18082: }
18083: } else {
18084: if ($inuse == 1) {
18085: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18086: $changes{$prefix}{$type} = 1;
18087: }
18088: }
18089: }
18090: }
18091: }
1.145 raeburn 18092:
18093: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18094: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18095: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18096: my $savespares;
18097:
18098: foreach my $lonhost (sort(keys(%servers))) {
18099: my $serverhomeID =
18100: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18101: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18102: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18103: my %spareschg;
18104: foreach my $type (@{$types{'spares'}}) {
18105: my @okspares;
18106: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18107: foreach my $server (@checked) {
1.152 raeburn 18108: if (&Apache::lonnet::hostname($server) ne '') {
18109: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18110: unless (grep(/^\Q$server\E$/,@okspares)) {
18111: push(@okspares,$server);
18112: }
1.145 raeburn 18113: }
18114: }
18115: }
18116: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18117: my $newspare;
1.152 raeburn 18118: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18119: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18120: $newspare = $new;
18121: }
18122: }
1.152 raeburn 18123: my @spares;
18124: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18125: @spares = sort(@okspares,$newspare);
18126: } else {
18127: @spares = sort(@okspares);
18128: }
18129: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18130: if (ref($spareid{$lonhost}) eq 'HASH') {
18131: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18132: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18133: if (@diffs > 0) {
18134: $spareschg{$type} = 1;
18135: }
18136: }
18137: }
18138: }
18139: if (keys(%spareschg) > 0) {
18140: $changes{'spares'}{$lonhost} = \%spareschg;
18141: }
18142: }
1.261 raeburn 18143: $defaultshash{'usersessions'}{'offloadnow'} = {};
18144: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18145: my @okoffload;
18146: if (@offloadnow) {
18147: foreach my $server (@offloadnow) {
18148: if (&Apache::lonnet::hostname($server) ne '') {
18149: unless (grep(/^\Q$server\E$/,@okoffload)) {
18150: push(@okoffload,$server);
18151: }
18152: }
18153: }
18154: if (@okoffload) {
18155: foreach my $lonhost (@okoffload) {
18156: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18157: }
18158: }
18159: }
1.145 raeburn 18160: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18161: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18162: if (ref($changes{'spares'}) eq 'HASH') {
18163: if (keys(%{$changes{'spares'}}) > 0) {
18164: $savespares = 1;
18165: }
18166: }
18167: } else {
18168: $savespares = 1;
18169: }
1.261 raeburn 18170: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
18171: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
18172: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
18173: $changes{'offloadnow'} = 1;
18174: last;
18175: }
18176: }
18177: unless ($changes{'offloadnow'}) {
1.289 raeburn 18178: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 18179: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
18180: $changes{'offloadnow'} = 1;
18181: last;
18182: }
18183: }
18184: }
18185: } elsif (@okoffload) {
18186: $changes{'offloadnow'} = 1;
18187: }
18188: } elsif (@okoffload) {
18189: $changes{'offloadnow'} = 1;
1.145 raeburn 18190: }
1.147 raeburn 18191: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18192: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18193: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18194: $dom);
18195: if ($putresult eq 'ok') {
18196: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18197: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18198: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18199: }
18200: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18201: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18202: }
1.261 raeburn 18203: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18204: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18205: }
1.137 raeburn 18206: }
18207: my $cachetime = 24*60*60;
18208: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 18209: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 18210: if (ref($lastactref) eq 'HASH') {
18211: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 18212: $lastactref->{'usersessions'} = 1;
1.212 raeburn 18213: }
1.147 raeburn 18214: if (keys(%changes) > 0) {
18215: my %lt = &usersession_titles();
18216: $resulttext = &mt('Changes made:').'<ul>';
18217: foreach my $prefix (@prefixes) {
18218: if (ref($changes{$prefix}) eq 'HASH') {
18219: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18220: if ($prefix eq 'spares') {
18221: if (ref($changes{$prefix}) eq 'HASH') {
18222: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18223: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18224: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 18225: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18226: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18227: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18228: foreach my $type (@{$types{$prefix}}) {
18229: if ($changes{$prefix}{$lonhost}{$type}) {
18230: my $offloadto = &mt('None');
18231: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18232: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18233: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18234: }
1.145 raeburn 18235: }
1.147 raeburn 18236: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18237: }
1.137 raeburn 18238: }
18239: }
1.147 raeburn 18240: $resulttext .= '</li>';
1.137 raeburn 18241: }
18242: }
1.147 raeburn 18243: } else {
18244: foreach my $type (@{$types{$prefix}}) {
18245: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18246: my ($newvalue,$notinuse);
1.147 raeburn 18247: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18248: if (ref($defaultshash{'usersessions'}{$prefix})) {
18249: if ($type eq 'version') {
18250: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 18251: } else {
18252: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18253: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18254: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18255: }
18256: } else {
18257: $notinuse = 1;
1.147 raeburn 18258: }
1.145 raeburn 18259: }
18260: }
18261: }
1.147 raeburn 18262: if ($newvalue eq '') {
18263: if ($type eq 'version') {
18264: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 18265: } elsif ($notinuse) {
18266: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 18267: } else {
18268: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18269: }
1.145 raeburn 18270: } else {
1.147 raeburn 18271: if ($type eq 'version') {
1.344 raeburn 18272: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 18273: }
18274: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18275: }
1.137 raeburn 18276: }
18277: }
18278: }
1.147 raeburn 18279: $resulttext .= '</ul>';
1.137 raeburn 18280: }
18281: }
1.261 raeburn 18282: if ($changes{'offloadnow'}) {
18283: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18284: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
18285: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
18286: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18287: $resulttext .= '<li>'.$lonhost.'</li>';
18288: }
18289: $resulttext .= '</ul>';
18290: } else {
18291: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
18292: }
18293: } else {
18294: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
18295: }
18296: }
1.147 raeburn 18297: $resulttext .= '</ul>';
18298: } else {
18299: $resulttext = $nochgmsg;
1.137 raeburn 18300: }
18301: } else {
18302: $resulttext = '<span class="LC_error">'.
18303: &mt('An error occurred: [_1]',$putresult).'</span>';
18304: }
18305: } else {
1.147 raeburn 18306: $resulttext = $nochgmsg;
1.137 raeburn 18307: }
18308: return $resulttext;
18309: }
18310:
1.275 raeburn 18311: sub modify_ssl {
18312: my ($dom,$lastactref,%domconfig) = @_;
18313: my (%by_ip,%by_location,@intdoms,@instdoms);
18314: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18315: my @locations = sort(keys(%by_location));
18316: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18317: my (%defaultshash,%changes);
18318: my $action = 'ssl';
1.293 raeburn 18319: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 18320: foreach my $prefix (@prefixes) {
18321: $defaultshash{$action}{$prefix} = {};
18322: }
18323: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18324: my $resulttext;
18325: my %iphost = &Apache::lonnet::get_iphost();
18326: my @reptypes = ('certreq','nocertreq');
18327: my @connecttypes = ('dom','intdom','other');
18328: my %types = (
1.293 raeburn 18329: connto => \@connecttypes,
18330: connfrom => \@connecttypes,
18331: replication => \@reptypes,
1.275 raeburn 18332: );
18333: foreach my $prefix (sort(keys(%types))) {
18334: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 18335: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18336: my $value = 'yes';
18337: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
18338: $value = $env{'form.'.$prefix.'_'.$type};
18339: }
1.335 raeburn 18340: if (ref($domconfig{$action}) eq 'HASH') {
18341: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18342: if ($domconfig{$action}{$prefix}{$type} ne '') {
18343: if ($value ne $domconfig{$action}{$prefix}{$type}) {
18344: $changes{$prefix}{$type} = 1;
18345: }
18346: $defaultshash{$action}{$prefix}{$type} = $value;
18347: } else {
18348: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 18349: $changes{$prefix}{$type} = 1;
18350: }
18351: } else {
18352: $defaultshash{$action}{$prefix}{$type} = $value;
18353: $changes{$prefix}{$type} = 1;
18354: }
18355: } else {
18356: $defaultshash{$action}{$prefix}{$type} = $value;
18357: $changes{$prefix}{$type} = 1;
18358: }
18359: if (($type eq 'dom') && (keys(%servers) == 1)) {
18360: delete($changes{$prefix}{$type});
18361: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
18362: delete($changes{$prefix}{$type});
18363: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
18364: delete($changes{$prefix}{$type});
18365: }
18366: } elsif ($prefix eq 'replication') {
18367: if (@locations > 0) {
18368: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18369: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18370: my @okvals;
18371: foreach my $val (@vals) {
18372: if ($val =~ /:/) {
18373: my @items = split(/:/,$val);
18374: foreach my $item (@items) {
18375: if (ref($by_location{$item}) eq 'ARRAY') {
18376: push(@okvals,$item);
18377: }
18378: }
18379: } else {
18380: if (ref($by_location{$val}) eq 'ARRAY') {
18381: push(@okvals,$val);
18382: }
18383: }
18384: }
18385: @okvals = sort(@okvals);
18386: if (ref($domconfig{$action}) eq 'HASH') {
18387: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18388: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
18389: if ($inuse == 0) {
18390: $changes{$prefix}{$type} = 1;
18391: } else {
18392: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18393: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
18394: if (@changed > 0) {
18395: $changes{$prefix}{$type} = 1;
18396: }
18397: }
18398: } else {
18399: if ($inuse == 1) {
18400: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18401: $changes{$prefix}{$type} = 1;
18402: }
18403: }
18404: } else {
18405: if ($inuse == 1) {
18406: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18407: $changes{$prefix}{$type} = 1;
18408: }
18409: }
18410: } else {
18411: if ($inuse == 1) {
18412: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18413: $changes{$prefix}{$type} = 1;
18414: }
18415: }
18416: }
18417: }
18418: }
18419: }
1.336 raeburn 18420: if (keys(%changes)) {
18421: foreach my $prefix (keys(%changes)) {
18422: if (ref($changes{$prefix}) eq 'HASH') {
18423: if (scalar(keys(%{$changes{$prefix}})) == 0) {
18424: delete($changes{$prefix});
18425: }
18426: } else {
18427: delete($changes{$prefix});
18428: }
18429: }
18430: }
1.275 raeburn 18431: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
18432: if (keys(%changes) > 0) {
18433: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18434: $dom);
18435: if ($putresult eq 'ok') {
18436: if (ref($defaultshash{$action}) eq 'HASH') {
18437: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
18438: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
18439: }
1.293 raeburn 18440: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 18441: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 18442: }
18443: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 18444: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 18445: }
18446: }
18447: my $cachetime = 24*60*60;
18448: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18449: if (ref($lastactref) eq 'HASH') {
18450: $lastactref->{'domdefaults'} = 1;
18451: }
18452: if (keys(%changes) > 0) {
18453: my %titles = &ssl_titles();
18454: $resulttext = &mt('Changes made:').'<ul>';
18455: foreach my $prefix (@prefixes) {
18456: if (ref($changes{$prefix}) eq 'HASH') {
18457: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
18458: foreach my $type (@{$types{$prefix}}) {
18459: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18460: my ($newvalue,$notinuse);
1.275 raeburn 18461: if (ref($defaultshash{$action}) eq 'HASH') {
18462: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 18463: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18464: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 18465: } else {
18466: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
18467: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
18468: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
18469: }
18470: } else {
18471: $notinuse = 1;
1.275 raeburn 18472: }
18473: }
18474: }
1.344 raeburn 18475: if ($notinuse) {
18476: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
18477: } elsif ($newvalue eq '') {
1.275 raeburn 18478: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
18479: } else {
18480: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
18481: }
18482: }
18483: }
18484: }
18485: $resulttext .= '</ul>';
18486: }
18487: }
18488: } else {
18489: $resulttext = $nochgmsg;
18490: }
18491: } else {
18492: $resulttext = '<span class="LC_error">'.
18493: &mt('An error occurred: [_1]',$putresult).'</span>';
18494: }
18495: } else {
18496: $resulttext = $nochgmsg;
18497: }
18498: return $resulttext;
18499: }
18500:
1.279 raeburn 18501: sub modify_trust {
18502: my ($dom,$lastactref,%domconfig) = @_;
18503: my (%by_ip,%by_location,@intdoms,@instdoms);
18504: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18505: my @locations = sort(keys(%by_location));
18506: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
18507: my @types = ('exc','inc');
18508: my (%defaultshash,%changes);
18509: foreach my $prefix (@prefixes) {
18510: $defaultshash{'trust'}{$prefix} = {};
18511: }
18512: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18513: my $resulttext;
18514: foreach my $prefix (@prefixes) {
18515: foreach my $type (@types) {
18516: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18517: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18518: my @okvals;
18519: foreach my $val (@vals) {
18520: if ($val =~ /:/) {
18521: my @items = split(/:/,$val);
18522: foreach my $item (@items) {
18523: if (ref($by_location{$item}) eq 'ARRAY') {
18524: push(@okvals,$item);
18525: }
18526: }
18527: } else {
18528: if (ref($by_location{$val}) eq 'ARRAY') {
18529: push(@okvals,$val);
18530: }
18531: }
18532: }
18533: @okvals = sort(@okvals);
18534: if (ref($domconfig{'trust'}) eq 'HASH') {
18535: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
18536: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18537: if ($inuse == 0) {
18538: $changes{$prefix}{$type} = 1;
18539: } else {
18540: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18541: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
18542: if (@changed > 0) {
18543: $changes{$prefix}{$type} = 1;
18544: }
18545: }
18546: } else {
18547: if ($inuse == 1) {
18548: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18549: $changes{$prefix}{$type} = 1;
18550: }
18551: }
18552: } else {
18553: if ($inuse == 1) {
18554: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18555: $changes{$prefix}{$type} = 1;
18556: }
18557: }
18558: } else {
18559: if ($inuse == 1) {
18560: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18561: $changes{$prefix}{$type} = 1;
18562: }
18563: }
18564: }
18565: }
18566: my $nochgmsg = &mt('No changes made to trust settings.');
18567: if (keys(%changes) > 0) {
18568: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18569: $dom);
18570: if ($putresult eq 'ok') {
18571: if (ref($defaultshash{'trust'}) eq 'HASH') {
18572: foreach my $prefix (@prefixes) {
18573: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
18574: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
18575: }
18576: }
18577: }
18578: my $cachetime = 24*60*60;
18579: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18580: if (ref($lastactref) eq 'HASH') {
18581: $lastactref->{'domdefaults'} = 1;
18582: }
18583: if (keys(%changes) > 0) {
18584: my %lt = &trust_titles();
18585: $resulttext = &mt('Changes made:').'<ul>';
18586: foreach my $prefix (@prefixes) {
18587: if (ref($changes{$prefix}) eq 'HASH') {
18588: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18589: foreach my $type (@types) {
18590: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18591: my ($newvalue,$notinuse);
1.279 raeburn 18592: if (ref($defaultshash{'trust'}) eq 'HASH') {
18593: if (ref($defaultshash{'trust'}{$prefix})) {
18594: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18595: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
18596: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
18597: }
1.344 raeburn 18598: } else {
18599: $notinuse = 1;
1.279 raeburn 18600: }
18601: }
18602: }
1.344 raeburn 18603: if ($notinuse) {
18604: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
18605: } elsif ($newvalue eq '') {
1.279 raeburn 18606: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18607: } else {
18608: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18609: }
18610: }
18611: }
18612: $resulttext .= '</ul>';
18613: }
18614: }
18615: $resulttext .= '</ul>';
18616: } else {
18617: $resulttext = $nochgmsg;
18618: }
18619: } else {
18620: $resulttext = '<span class="LC_error">'.
18621: &mt('An error occurred: [_1]',$putresult).'</span>';
18622: }
18623: } else {
18624: $resulttext = $nochgmsg;
18625: }
18626: return $resulttext;
18627: }
18628:
1.150 raeburn 18629: sub modify_loadbalancing {
18630: my ($dom,%domconfig) = @_;
18631: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18632: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18633: my ($othertitle,$usertypes,$types) =
18634: &Apache::loncommon::sorted_inst_types($dom);
18635: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 18636: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18637: my @sparestypes = ('primary','default');
18638: my %typetitles = &sparestype_titles();
18639: my $resulttext;
1.342 raeburn 18640: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18641: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18642: %existing = %{$domconfig{'loadbalancing'}};
18643: }
18644: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 18645: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 18646: my ($saveloadbalancing,%defaultshash,%changes);
18647: my ($alltypes,$othertypes,$titles) =
18648: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18649: my %ruletitles = &offloadtype_text();
18650: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18651: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18652: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18653: if ($balancer eq '') {
18654: next;
18655: }
1.210 raeburn 18656: if (!exists($servers{$balancer})) {
1.171 raeburn 18657: if (exists($currbalancer{$balancer})) {
18658: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18659: }
1.171 raeburn 18660: next;
18661: }
18662: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18663: push(@{$changes{'delete'}},$balancer);
18664: next;
18665: }
18666: if (!exists($currbalancer{$balancer})) {
18667: push(@{$changes{'add'}},$balancer);
18668: }
18669: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18670: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18671: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18672: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18673: $saveloadbalancing = 1;
18674: }
18675: foreach my $sparetype (@sparestypes) {
18676: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18677: my @offloadto;
18678: foreach my $target (@targets) {
18679: if (($servers{$target}) && ($target ne $balancer)) {
18680: if ($sparetype eq 'default') {
18681: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18682: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18683: }
18684: }
1.171 raeburn 18685: unless(grep(/^\Q$target\E$/,@offloadto)) {
18686: push(@offloadto,$target);
18687: }
1.150 raeburn 18688: }
18689: }
1.284 raeburn 18690: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18691: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18692: push(@offloadto,$balancer);
18693: }
18694: }
18695: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18696: }
1.342 raeburn 18697: if ($env{'form.loadbalancing_cookie_'.$i}) {
18698: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18699: if (exists($currbalancer{$balancer})) {
18700: unless ($currcookies{$balancer}) {
18701: $changes{'curr'}{$balancer}{'cookie'} = 1;
18702: }
18703: }
18704: } elsif (exists($currbalancer{$balancer})) {
18705: if ($currcookies{$balancer}) {
18706: $changes{'curr'}{$balancer}{'cookie'} = 1;
18707: }
18708: }
1.171 raeburn 18709: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18710: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18711: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18712: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18713: if (@targetdiffs > 0) {
1.171 raeburn 18714: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18715: }
1.171 raeburn 18716: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18717: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18718: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18719: }
18720: }
18721: }
18722: } else {
1.171 raeburn 18723: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 18724: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18725: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18726: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18727: $changes{'curr'}{$balancer}{'targets'} = 1;
18728: }
1.150 raeburn 18729: }
18730: }
1.210 raeburn 18731: }
1.150 raeburn 18732: }
18733: my $ishomedom;
1.171 raeburn 18734: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18735: $ishomedom = 1;
1.150 raeburn 18736: }
18737: if (ref($alltypes) eq 'ARRAY') {
18738: foreach my $type (@{$alltypes}) {
18739: my $rule;
1.210 raeburn 18740: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18741: (!$ishomedom)) {
1.171 raeburn 18742: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18743: }
18744: if ($rule eq 'specific') {
1.255 raeburn 18745: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 18746: if (exists($servers{$specifiedhost})) {
1.255 raeburn 18747: $rule = $specifiedhost;
18748: }
1.150 raeburn 18749: }
1.171 raeburn 18750: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18751: if (ref($currrules{$balancer}) eq 'HASH') {
18752: if ($rule ne $currrules{$balancer}{$type}) {
18753: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18754: }
18755: } elsif ($rule ne '') {
1.171 raeburn 18756: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18757: }
18758: }
18759: }
1.171 raeburn 18760: }
18761: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18762: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18763: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18764: $defaultshash{'loadbalancing'} = {};
18765: }
18766: my $putresult = &Apache::lonnet::put_dom('configuration',
18767: \%defaultshash,$dom);
18768: if ($putresult eq 'ok') {
18769: if (keys(%changes) > 0) {
1.252 raeburn 18770: my %toupdate;
1.171 raeburn 18771: if (ref($changes{'delete'}) eq 'ARRAY') {
18772: foreach my $balancer (sort(@{$changes{'delete'}})) {
18773: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 18774: $toupdate{$balancer} = 1;
1.150 raeburn 18775: }
1.171 raeburn 18776: }
18777: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 18778: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 18779: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 18780: $toupdate{$balancer} = 1;
1.171 raeburn 18781: }
18782: }
18783: if (ref($changes{'curr'}) eq 'HASH') {
18784: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 18785: $toupdate{$balancer} = 1;
1.171 raeburn 18786: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18787: if ($changes{'curr'}{$balancer}{'targets'}) {
18788: my %offloadstr;
18789: foreach my $sparetype (@sparestypes) {
18790: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18791: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18792: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18793: }
18794: }
1.150 raeburn 18795: }
1.171 raeburn 18796: if (keys(%offloadstr) == 0) {
18797: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18798: } else {
1.171 raeburn 18799: my $showoffload;
18800: foreach my $sparetype (@sparestypes) {
18801: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18802: if (defined($offloadstr{$sparetype})) {
18803: $showoffload .= $offloadstr{$sparetype};
18804: } else {
18805: $showoffload .= &mt('None');
18806: }
18807: $showoffload .= (' 'x3);
18808: }
18809: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18810: }
18811: }
18812: }
1.171 raeburn 18813: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18814: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18815: foreach my $type (@{$alltypes}) {
18816: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18817: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18818: my $balancetext;
18819: if ($rule eq '') {
18820: $balancetext = $ruletitles{'default'};
1.209 raeburn 18821: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 18822: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 18823: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 18824: foreach my $sparetype (@sparestypes) {
18825: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18826: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18827: }
18828: }
1.253 raeburn 18829: foreach my $item (@{$alltypes}) {
18830: next if ($item =~ /^_LC_ipchange/);
18831: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18832: if ($hasrule eq 'homeserver') {
18833: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18834: } else {
18835: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18836: if ($servers{$hasrule}) {
18837: $toupdate{$hasrule} = 1;
18838: }
18839: }
18840: }
18841: }
1.254 raeburn 18842: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18843: $balancetext = $ruletitles{$rule};
18844: } else {
18845: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18846: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18847: if ($receiver) {
18848: $toupdate{$receiver};
18849: }
18850: }
18851: } else {
18852: $balancetext = $ruletitles{$rule};
1.252 raeburn 18853: }
1.171 raeburn 18854: } else {
18855: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18856: }
1.210 raeburn 18857: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18858: }
18859: }
18860: }
18861: }
1.342 raeburn 18862: if ($changes{'curr'}{$balancer}{'cookie'}) {
18863: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18864: $balancer).'</li>';
18865: }
1.252 raeburn 18866: if (keys(%toupdate)) {
18867: my %thismachine;
18868: my $updatedhere;
18869: my $cachetime = 60*60*24;
18870: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18871: foreach my $lonhost (keys(%toupdate)) {
18872: if ($thismachine{$lonhost}) {
18873: unless ($updatedhere) {
18874: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18875: $defaultshash{'loadbalancing'},
18876: $cachetime);
18877: $updatedhere = 1;
18878: }
18879: } else {
18880: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18881: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18882: }
18883: }
18884: }
1.150 raeburn 18885: }
1.171 raeburn 18886: }
18887: if ($resulttext ne '') {
18888: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18889: } else {
18890: $resulttext = $nochgmsg;
18891: }
18892: } else {
1.171 raeburn 18893: $resulttext = $nochgmsg;
1.150 raeburn 18894: }
18895: } else {
1.171 raeburn 18896: $resulttext = '<span class="LC_error">'.
18897: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 18898: }
18899: } else {
1.171 raeburn 18900: $resulttext = $nochgmsg;
1.150 raeburn 18901: }
18902: return $resulttext;
18903: }
18904:
1.48 raeburn 18905: sub recurse_check {
18906: my ($chkcats,$categories,$depth,$name) = @_;
18907: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
18908: my $chg = 0;
18909: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
18910: my $category = $chkcats->[$depth]{$name}[$j];
18911: my $item;
18912: if ($category eq '') {
18913: $chg ++;
18914: } else {
18915: my $deeper = $depth + 1;
18916: $item = &escape($category).':'.&escape($name).':'.$depth;
18917: if ($chg) {
18918: $categories->{$item} -= $chg;
18919: }
18920: &recurse_check($chkcats,$categories,$deeper,$category);
18921: $deeper --;
18922: }
18923: }
18924: }
18925: return;
18926: }
18927:
18928: sub recurse_cat_deletes {
18929: my ($item,$coursecategories,$deletions) = @_;
18930: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
18931: my $subdepth = $depth + 1;
18932: if (ref($coursecategories) eq 'HASH') {
18933: foreach my $subitem (keys(%{$coursecategories})) {
18934: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
18935: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
18936: delete($coursecategories->{$subitem});
18937: $deletions->{$subitem} = 1;
18938: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 18939: }
1.48 raeburn 18940: }
18941: }
18942: return;
18943: }
18944:
1.125 raeburn 18945: sub active_dc_picker {
1.191 raeburn 18946: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 18947: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 18948: my @domcoord = keys(%domcoords);
18949: if (keys(%currhash)) {
18950: foreach my $dc (keys(%currhash)) {
18951: unless (exists($domcoords{$dc})) {
18952: push(@domcoord,$dc);
18953: }
18954: }
18955: }
18956: @domcoord = sort(@domcoord);
1.210 raeburn 18957: my $numdcs = scalar(@domcoord);
1.191 raeburn 18958: my $rows = 0;
18959: my $table;
1.125 raeburn 18960: if ($numdcs > 1) {
1.191 raeburn 18961: $table = '<table>';
18962: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 18963: my $rem = $i%($numinrow);
18964: if ($rem == 0) {
18965: if ($i > 0) {
1.191 raeburn 18966: $table .= '</tr>';
1.125 raeburn 18967: }
1.191 raeburn 18968: $table .= '<tr>';
18969: $rows ++;
1.125 raeburn 18970: }
1.191 raeburn 18971: my $check = '';
18972: if ($inputtype eq 'radio') {
18973: if (keys(%currhash) == 0) {
18974: if (!$i) {
18975: $check = ' checked="checked"';
18976: }
18977: } elsif (exists($currhash{$domcoord[$i]})) {
18978: $check = ' checked="checked"';
18979: }
18980: } else {
18981: if (exists($currhash{$domcoord[$i]})) {
18982: $check = ' checked="checked"';
1.125 raeburn 18983: }
18984: }
1.191 raeburn 18985: if ($i == @domcoord - 1) {
1.125 raeburn 18986: my $colsleft = $numinrow - $rem;
18987: if ($colsleft > 1) {
1.191 raeburn 18988: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 18989: } else {
1.191 raeburn 18990: $table .= '<td class="LC_left_item">';
1.125 raeburn 18991: }
18992: } else {
1.191 raeburn 18993: $table .= '<td class="LC_left_item">';
18994: }
18995: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
18996: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
18997: $table .= '<span class="LC_nobreak"><label>'.
18998: '<input type="'.$inputtype.'" name="'.$name.'"'.
18999: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19000: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 19001: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 19002: }
1.219 raeburn 19003: $table .= '</label></span></td>';
1.191 raeburn 19004: }
19005: $table .= '</tr></table>';
19006: } elsif ($numdcs == 1) {
1.219 raeburn 19007: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19008: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 19009: if ($inputtype eq 'radio') {
1.247 raeburn 19010: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 19011: if ($user ne $dcname.':'.$dcdom) {
19012: $table .= ' ('.$dcname.':'.$dcdom.')';
19013: }
1.191 raeburn 19014: } else {
19015: my $check;
19016: if (exists($currhash{$domcoord[0]})) {
19017: $check = ' checked="checked"';
1.125 raeburn 19018: }
1.247 raeburn 19019: $table = '<span class="LC_nobreak"><label>'.
19020: '<input type="checkbox" name="'.$name.'" '.
19021: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 19022: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 19023: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 19024: }
1.220 raeburn 19025: $table .= '</label></span>';
1.191 raeburn 19026: $rows ++;
1.125 raeburn 19027: }
19028: }
1.191 raeburn 19029: return ($numdcs,$table,$rows);
1.125 raeburn 19030: }
19031:
1.137 raeburn 19032: sub usersession_titles {
19033: return &Apache::lonlocal::texthash(
19034: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19035: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19036: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19037: version => 'LON-CAPA version requirement',
1.138 raeburn 19038: excludedomain => 'Allow all, but exclude specific domains',
19039: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19040: primary => 'Primary (checked first)',
1.154 raeburn 19041: default => 'Default',
1.137 raeburn 19042: );
19043: }
19044:
1.152 raeburn 19045: sub id_for_thisdom {
19046: my (%servers) = @_;
19047: my %altids;
19048: foreach my $server (keys(%servers)) {
19049: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19050: if ($serverhome ne $server) {
19051: $altids{$serverhome} = $server;
19052: }
19053: }
19054: return %altids;
19055: }
19056:
1.150 raeburn 19057: sub count_servers {
19058: my ($currbalancer,%servers) = @_;
19059: my (@spares,$numspares);
19060: foreach my $lonhost (sort(keys(%servers))) {
19061: next if ($currbalancer eq $lonhost);
19062: push(@spares,$lonhost);
19063: }
19064: if ($currbalancer) {
19065: $numspares = scalar(@spares);
19066: } else {
19067: $numspares = scalar(@spares) - 1;
19068: }
19069: return ($numspares,@spares);
19070: }
19071:
19072: sub lonbalance_targets_js {
1.171 raeburn 19073: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19074: my $select = &mt('Select');
19075: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19076: if (ref($servers) eq 'HASH') {
19077: $alltargets = join("','",sort(keys(%{$servers})));
19078: my @homedoms;
19079: foreach my $server (sort(keys(%{$servers}))) {
19080: if (&Apache::lonnet::host_domain($server) eq $dom) {
19081: push(@homedoms,'1');
19082: } else {
19083: push(@homedoms,'0');
19084: }
19085: }
19086: $allishome = join("','",@homedoms);
19087: }
19088: if (ref($types) eq 'ARRAY') {
19089: if (@{$types} > 0) {
19090: @alltypes = @{$types};
19091: }
19092: }
19093: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19094: $allinsttypes = join("','",@alltypes);
1.342 raeburn 19095: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 19096: if (ref($settings) eq 'HASH') {
19097: %existing = %{$settings};
19098: }
19099: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 19100: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 19101: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19102: return <<"END";
19103:
19104: <script type="text/javascript">
19105: // <![CDATA[
19106:
1.171 raeburn 19107: currBalancers = new Array('$balancers');
19108:
19109: function toggleTargets(balnum) {
19110: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19111: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19112: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19113: var prevbalancer = prevhostitem.value;
19114: var baltotal = document.getElementById('loadbalancing_total').value;
19115: prevhostitem.value = balancer;
19116: if (prevbalancer != '') {
19117: var prevIdx = currBalancers.indexOf(prevbalancer);
19118: if (prevIdx != -1) {
19119: currBalancers.splice(prevIdx,1);
19120: }
19121: }
1.150 raeburn 19122: if (balancer == '') {
1.171 raeburn 19123: hideSpares(balnum);
1.150 raeburn 19124: } else {
1.171 raeburn 19125: var currIdx = currBalancers.indexOf(balancer);
19126: if (currIdx == -1) {
19127: currBalancers.push(balancer);
19128: }
1.150 raeburn 19129: var homedoms = new Array('$allishome');
1.171 raeburn 19130: var ishomedom = homedoms[lonhostitem.selectedIndex];
19131: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19132: }
1.171 raeburn 19133: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19134: return;
19135: }
19136:
1.171 raeburn 19137: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19138: var alltargets = new Array('$alltargets');
19139: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19140: var offloadtypes = new Array('primary','default');
19141:
1.171 raeburn 19142: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19143: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19144:
1.151 raeburn 19145: for (var i=0; i<offloadtypes.length; i++) {
19146: var count = 0;
19147: for (var j=0; j<alltargets.length; j++) {
19148: if (alltargets[j] != balancer) {
1.171 raeburn 19149: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19150: item.value = alltargets[j];
19151: item.style.textAlign='left';
19152: item.style.textFace='normal';
19153: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19154: if (currBalancers.indexOf(alltargets[j]) == -1) {
19155: item.disabled = '';
19156: } else {
19157: item.disabled = 'disabled';
19158: item.checked = false;
19159: }
1.151 raeburn 19160: count ++;
19161: }
1.150 raeburn 19162: }
19163: }
1.151 raeburn 19164: for (var k=0; k<insttypes.length; k++) {
19165: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19166: if (ishomedom == 1) {
1.171 raeburn 19167: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19168: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19169: } else {
1.171 raeburn 19170: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19171: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19172: }
19173: } else {
1.171 raeburn 19174: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19175: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19176: }
1.151 raeburn 19177: if ((insttypes[k] != '_LC_external') &&
19178: ((insttypes[k] != '_LC_internetdom') ||
19179: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 19180: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19181: item.options.length = 0;
19182: item.options[0] = new Option("","",true,true);
1.210 raeburn 19183: var idx = 0;
1.151 raeburn 19184: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 19185: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19186: idx ++;
19187: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19188: }
19189: }
19190: }
19191: }
19192: return;
19193: }
19194:
1.171 raeburn 19195: function hideSpares(balnum) {
1.150 raeburn 19196: var alltargets = new Array('$alltargets');
19197: var insttypes = new Array('$allinsttypes');
19198: var offloadtypes = new Array('primary','default');
19199:
1.171 raeburn 19200: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19201: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19202:
19203: var total = alltargets.length - 1;
19204: for (var i=0; i<offloadtypes; i++) {
19205: for (var j=0; j<total; j++) {
1.171 raeburn 19206: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19207: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19208: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19209: }
1.150 raeburn 19210: }
19211: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 19212: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19213: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19214: if (insttypes[k] != '_LC_external') {
1.171 raeburn 19215: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19216: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19217: }
19218: }
19219: return;
19220: }
19221:
1.171 raeburn 19222: function checkOffloads(item,balnum,type) {
1.150 raeburn 19223: var alltargets = new Array('$alltargets');
19224: var offloadtypes = new Array('primary','default');
19225: if (item.checked) {
19226: var total = alltargets.length - 1;
19227: var other;
19228: if (type == offloadtypes[0]) {
1.151 raeburn 19229: other = offloadtypes[1];
1.150 raeburn 19230: } else {
1.151 raeburn 19231: other = offloadtypes[0];
1.150 raeburn 19232: }
19233: for (var i=0; i<total; i++) {
1.171 raeburn 19234: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19235: if (server == item.value) {
1.171 raeburn 19236: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19237: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19238: }
19239: }
19240: }
19241: }
19242: return;
19243: }
19244:
1.171 raeburn 19245: function singleServerToggle(balnum,type) {
19246: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19247: if (offloadtoSelIdx == 0) {
1.171 raeburn 19248: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19249: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19250:
19251: } else {
1.171 raeburn 19252: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19253: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19254: }
19255: return;
19256: }
19257:
1.171 raeburn 19258: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19259: if (type == '_LC_external') {
1.171 raeburn 19260: return;
1.150 raeburn 19261: }
1.171 raeburn 19262: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19263: for (var i=0; i<typesRules.length; i++) {
19264: if (formname.elements[typesRules[i]].checked) {
19265: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 19266: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19267: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19268: } else {
1.171 raeburn 19269: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19270: }
19271: }
19272: }
19273: return;
19274: }
19275:
19276: function balancerDeleteChange(balnum) {
19277: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19278: var baltotal = document.getElementById('loadbalancing_total').value;
19279: var addtarget;
19280: var removetarget;
19281: var action = 'delete';
19282: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19283: var lonhost = hostitem.value;
19284: var currIdx = currBalancers.indexOf(lonhost);
19285: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19286: if (currIdx != -1) {
19287: currBalancers.splice(currIdx,1);
19288: }
19289: addtarget = lonhost;
19290: } else {
19291: if (currIdx == -1) {
19292: currBalancers.push(lonhost);
19293: }
19294: removetarget = lonhost;
19295: action = 'undelete';
19296: }
19297: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19298: }
19299: return;
19300: }
19301:
19302: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19303: if (baltotal > 1) {
19304: var offloadtypes = new Array('primary','default');
19305: var alltargets = new Array('$alltargets');
19306: var insttypes = new Array('$allinsttypes');
19307: for (var i=0; i<baltotal; i++) {
19308: if (i != balnum) {
19309: for (var j=0; j<offloadtypes.length; j++) {
19310: var total = alltargets.length - 1;
19311: for (var k=0; k<total; k++) {
19312: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19313: var server = serveritem.value;
19314: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19315: if (server == addtarget) {
19316: serveritem.disabled = '';
19317: }
19318: }
19319: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19320: if (server == removetarget) {
19321: serveritem.disabled = 'disabled';
19322: serveritem.checked = false;
19323: }
19324: }
19325: }
19326: }
19327: for (var j=0; j<insttypes.length; j++) {
19328: if (insttypes[j] != '_LC_external') {
19329: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19330: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19331: var currSel = singleserver.selectedIndex;
19332: var currVal = singleserver.options[currSel].value;
19333: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19334: var numoptions = singleserver.options.length;
19335: var needsnew = 1;
19336: for (var k=0; k<numoptions; k++) {
19337: if (singleserver.options[k] == addtarget) {
19338: needsnew = 0;
19339: break;
19340: }
19341: }
19342: if (needsnew == 1) {
19343: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19344: }
19345: }
19346: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19347: singleserver.options.length = 0;
19348: if ((currVal) && (currVal != removetarget)) {
19349: singleserver.options[0] = new Option("","",false,false);
19350: } else {
19351: singleserver.options[0] = new Option("","",true,true);
19352: }
19353: var idx = 0;
19354: for (var m=0; m<alltargets.length; m++) {
19355: if (currBalancers.indexOf(alltargets[m]) == -1) {
19356: idx ++;
19357: if (currVal == alltargets[m]) {
19358: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19359: } else {
19360: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19361: }
19362: }
19363: }
19364: }
19365: }
19366: }
19367: }
1.150 raeburn 19368: }
19369: }
19370: }
19371: return;
19372: }
19373:
1.152 raeburn 19374: // ]]>
19375: </script>
19376:
19377: END
19378: }
19379:
19380: sub new_spares_js {
19381: my @sparestypes = ('primary','default');
19382: my $types = join("','",@sparestypes);
19383: my $select = &mt('Select');
19384: return <<"END";
19385:
19386: <script type="text/javascript">
19387: // <![CDATA[
19388:
19389: function updateNewSpares(formname,lonhost) {
19390: var types = new Array('$types');
19391: var include = new Array();
19392: var exclude = new Array();
19393: for (var i=0; i<types.length; i++) {
19394: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19395: for (var j=0; j<spareboxes.length; j++) {
19396: if (formname.elements[spareboxes[j]].checked) {
19397: exclude.push(formname.elements[spareboxes[j]].value);
19398: } else {
19399: include.push(formname.elements[spareboxes[j]].value);
19400: }
19401: }
19402: }
19403: for (var i=0; i<types.length; i++) {
19404: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19405: var selIdx = newSpare.selectedIndex;
19406: var currnew = newSpare.options[selIdx].value;
19407: var okSpares = new Array();
19408: for (var j=0; j<newSpare.options.length; j++) {
19409: var possible = newSpare.options[j].value;
19410: if (possible != '') {
19411: if (exclude.indexOf(possible) == -1) {
19412: okSpares.push(possible);
19413: } else {
19414: if (currnew == possible) {
19415: selIdx = 0;
19416: }
19417: }
19418: }
19419: }
19420: for (var k=0; k<include.length; k++) {
19421: if (okSpares.indexOf(include[k]) == -1) {
19422: okSpares.push(include[k]);
19423: }
19424: }
19425: okSpares.sort();
19426: newSpare.options.length = 0;
19427: if (selIdx == 0) {
19428: newSpare.options[0] = new Option("$select","",true,true);
19429: } else {
19430: newSpare.options[0] = new Option("$select","",false,false);
19431: }
19432: for (var m=0; m<okSpares.length; m++) {
19433: var idx = m+1;
19434: var selThis = 0;
19435: if (selIdx != 0) {
19436: if (okSpares[m] == currnew) {
19437: selThis = 1;
19438: }
19439: }
19440: if (selThis == 1) {
19441: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19442: } else {
19443: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19444: }
19445: }
19446: }
19447: return;
19448: }
19449:
19450: function checkNewSpares(lonhost,type) {
19451: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19452: var chosen = newSpare.options[newSpare.selectedIndex].value;
19453: if (chosen != '') {
19454: var othertype;
19455: var othernewSpare;
19456: if (type == 'primary') {
19457: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19458: }
19459: if (type == 'default') {
19460: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19461: }
19462: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19463: othernewSpare.selectedIndex = 0;
19464: }
19465: }
19466: return;
19467: }
19468:
19469: // ]]>
19470: </script>
19471:
19472: END
19473:
19474: }
19475:
19476: sub common_domprefs_js {
19477: return <<"END";
19478:
19479: <script type="text/javascript">
19480: // <![CDATA[
19481:
1.150 raeburn 19482: function getIndicesByName(formname,item) {
1.152 raeburn 19483: var group = new Array();
1.150 raeburn 19484: for (var i=0;i<formname.elements.length;i++) {
19485: if (formname.elements[i].name == item) {
1.152 raeburn 19486: group.push(formname.elements[i].id);
1.150 raeburn 19487: }
19488: }
1.152 raeburn 19489: return group;
1.150 raeburn 19490: }
19491:
19492: // ]]>
19493: </script>
19494:
19495: END
1.152 raeburn 19496:
1.150 raeburn 19497: }
19498:
1.165 raeburn 19499: sub recaptcha_js {
19500: my %lt = &captcha_phrases();
19501: return <<"END";
19502:
19503: <script type="text/javascript">
19504: // <![CDATA[
19505:
19506: function updateCaptcha(caller,context) {
19507: var privitem;
19508: var pubitem;
19509: var privtext;
19510: var pubtext;
1.269 raeburn 19511: var versionitem;
19512: var versiontext;
1.165 raeburn 19513: if (document.getElementById(context+'_recaptchapub')) {
19514: pubitem = document.getElementById(context+'_recaptchapub');
19515: } else {
19516: return;
19517: }
19518: if (document.getElementById(context+'_recaptchapriv')) {
19519: privitem = document.getElementById(context+'_recaptchapriv');
19520: } else {
19521: return;
19522: }
19523: if (document.getElementById(context+'_recaptchapubtxt')) {
19524: pubtext = document.getElementById(context+'_recaptchapubtxt');
19525: } else {
19526: return;
19527: }
19528: if (document.getElementById(context+'_recaptchaprivtxt')) {
19529: privtext = document.getElementById(context+'_recaptchaprivtxt');
19530: } else {
19531: return;
19532: }
1.269 raeburn 19533: if (document.getElementById(context+'_recaptchaversion')) {
19534: versionitem = document.getElementById(context+'_recaptchaversion');
19535: } else {
19536: return;
19537: }
19538: if (document.getElementById(context+'_recaptchavertxt')) {
19539: versiontext = document.getElementById(context+'_recaptchavertxt');
19540: } else {
19541: return;
19542: }
1.165 raeburn 19543: if (caller.checked) {
19544: if (caller.value == 'recaptcha') {
19545: pubitem.type = 'text';
19546: privitem.type = 'text';
19547: pubitem.size = '40';
19548: privitem.size = '40';
19549: pubtext.innerHTML = "$lt{'pub'}";
19550: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 19551: versionitem.type = 'text';
19552: versionitem.size = '3';
1.289 raeburn 19553: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 19554: } else {
19555: pubitem.type = 'hidden';
19556: privitem.type = 'hidden';
1.269 raeburn 19557: versionitem.type = 'hidden';
1.165 raeburn 19558: pubtext.innerHTML = '';
19559: privtext.innerHTML = '';
1.269 raeburn 19560: versiontext.innerHTML = '';
1.165 raeburn 19561: }
19562: }
19563: return;
19564: }
19565:
19566: // ]]>
19567: </script>
19568:
19569: END
19570:
19571: }
19572:
1.236 raeburn 19573: sub toggle_display_js {
1.192 raeburn 19574: return <<"END";
19575:
19576: <script type="text/javascript">
19577: // <![CDATA[
19578:
1.236 raeburn 19579: function toggleDisplay(domForm,caller) {
19580: if (document.getElementById(caller)) {
19581: var divitem = document.getElementById(caller);
19582: var optionsElement = domForm.coursecredits;
1.264 raeburn 19583: var checkval = 1;
19584: var dispval = 'block';
1.303 raeburn 19585: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 19586: if (caller == 'emailoptions') {
19587: optionsElement = domForm.cancreate_email;
19588: }
1.257 raeburn 19589: if (caller == 'studentsubmission') {
19590: optionsElement = domForm.postsubmit;
19591: }
1.264 raeburn 19592: if (caller == 'cloneinstcode') {
19593: optionsElement = domForm.canclone;
19594: checkval = 'instcode';
19595: }
1.303 raeburn 19596: if (selfcreateRegExp.test(caller)) {
19597: optionsElement = domForm.elements[caller];
19598: checkval = 'other';
19599: dispval = 'inline'
19600: }
1.236 raeburn 19601: if (optionsElement.length) {
1.192 raeburn 19602: var currval;
1.236 raeburn 19603: for (var i=0; i<optionsElement.length; i++) {
19604: if (optionsElement[i].checked) {
19605: currval = optionsElement[i].value;
1.192 raeburn 19606: }
19607: }
1.264 raeburn 19608: if (currval == checkval) {
19609: divitem.style.display = dispval;
1.192 raeburn 19610: } else {
1.236 raeburn 19611: divitem.style.display = 'none';
1.192 raeburn 19612: }
19613: }
19614: }
19615: return;
19616: }
19617:
19618: // ]]>
19619: </script>
19620:
19621: END
19622:
19623: }
19624:
1.165 raeburn 19625: sub captcha_phrases {
19626: return &Apache::lonlocal::texthash (
19627: priv => 'Private key',
19628: pub => 'Public key',
19629: original => 'original (CAPTCHA)',
19630: recaptcha => 'successor (ReCAPTCHA)',
19631: notused => 'unused',
1.289 raeburn 19632: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 19633: );
19634: }
19635:
1.205 raeburn 19636: sub devalidate_remote_domconfs {
1.212 raeburn 19637: my ($dom,$cachekeys) = @_;
19638: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 19639: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19640: my %thismachine;
19641: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 19642: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
19643: 'directorysrch','passwdconf');
1.260 raeburn 19644: if (keys(%servers)) {
1.205 raeburn 19645: foreach my $server (keys(%servers)) {
19646: next if ($thismachine{$server});
1.212 raeburn 19647: my @cached;
19648: foreach my $name (@posscached) {
19649: if ($cachekeys->{$name}) {
19650: push(@cached,&escape($name).':'.&escape($dom));
19651: }
19652: }
19653: if (@cached) {
19654: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19655: }
1.205 raeburn 19656: }
19657: }
19658: return;
19659: }
19660:
1.3 raeburn 19661: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>