Annotation of loncom/interface/domainprefs.pm, revision 1.366
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.366 ! raeburn 4: # $Id: domainprefs.pm,v 1.365 2019/08/25 02:42:55 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: }
1.363 raeburn 2908: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
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.363 raeburn 2917: } else if (setting == 'callback') {
2918: radioname = 'lti_callback_'+item;
2919: divid = 'lti_callbackfield_'+item;
1.337 raeburn 2920: } else {
1.351 raeburn 2921: radioname = 'lti_passback_'+item;
1.337 raeburn 2922: divid = 'lti_passback_'+item;
1.320 raeburn 2923: }
2924: var num = form.elements[radioname].length;
2925: if (num) {
2926: var setvis = '';
2927: for (var i=0; i<num; i++) {
2928: if (form.elements[radioname][i].checked) {
1.363 raeburn 2929: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 2930: if (form.elements[radioname][i].value == '1') {
2931: if (document.getElementById(divid)) {
2932: document.getElementById(divid).style.display = 'inline-block';
2933: }
2934: setvis = 1;
2935: break;
2936: }
2937: } else {
2938: if (form.elements[radioname][i].value == 'other') {
2939: if (document.getElementById(divid)) {
2940: document.getElementById(divid).style.display = 'inline-block';
2941: }
2942: setvis = 1;
2943: break;
1.320 raeburn 2944: }
2945: }
2946: }
2947: }
2948: if (!setvis) {
2949: if (document.getElementById(divid)) {
2950: document.getElementById(divid).style.display = 'none';
2951: }
2952: }
2953: }
2954: } else if ((setting == 'sec') || (setting == 'secsrc')) {
2955: var numsec = form.elements['lti_crssec_'+item].length;
2956: if (numsec) {
2957: var setvis = '';
2958: for (var i=0; i<numsec; i++) {
2959: if (form.elements['lti_crssec_'+item][i].checked) {
2960: if (form.elements['lti_crssec_'+item][i].value == '1') {
2961: if (document.getElementById('lti_crssecfield_'+item)) {
2962: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
2963: setvis = 1;
2964: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
2965: if (numsrcsec) {
2966: var setsrcvis = '';
2967: for (var j=0; j<numsrcsec; j++) {
2968: if (form.elements['lti_crssecsrc_'+item][j].checked) {
2969: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
2970: if (document.getElementById('lti_secsrcfield_'+item)) {
2971: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
2972: setsrcvis = 1;
2973: }
2974: }
2975: }
2976: }
2977: if (!setsrcvis) {
2978: if (document.getElementById('lti_secsrcfield_'+item)) {
2979: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2980: }
2981: }
2982: }
2983: }
2984: }
2985: }
2986: }
2987: if (!setvis) {
2988: if (document.getElementById('lti_crssecfield_'+item)) {
2989: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
2990: }
2991: if (document.getElementById('lti_secsrcfield_'+item)) {
2992: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
2993: }
2994: }
2995: }
1.325 raeburn 2996: } else if (setting == 'lcauth') {
2997: var numauth = form.elements['lti_lcauth_'+item].length;
2998: if (numauth) {
2999: for (var i=0; i<numauth; i++) {
3000: if (form.elements['lti_lcauth_'+item][i].checked) {
3001: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3002: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3003: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3004: } else {
3005: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3006: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3007: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3008: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3009: } else {
3010: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3011: }
3012: }
3013: }
3014: }
3015: }
3016: }
3017: }
1.326 raeburn 3018: } else if (setting == 'lcmenu') {
3019: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3020: var divid = 'lti_menufield_'+item;
3021: var setvis = '';
3022: for (var i=0; i<menus.length; i++) {
3023: var radioname = menus[i];
3024: var num = form.elements[radioname].length;
3025: if (num) {
3026: for (var j=0; j<num; j++) {
3027: if (form.elements[radioname][j].checked) {
3028: if (form.elements[radioname][j].value == '1') {
3029: if (document.getElementById(divid)) {
3030: document.getElementById(divid).style.display = 'inline-block';
3031: }
3032: setvis = 1;
3033: break;
3034: }
3035: }
3036: }
3037: }
3038: if (setvis == 1) {
3039: break;
3040: }
3041: }
3042: if (!setvis) {
3043: if (document.getElementById(divid)) {
3044: document.getElementById(divid).style.display = 'none';
3045: }
3046: }
1.320 raeburn 3047: }
3048: return;
3049: }
3050: // ]]>
3051: </script>
3052:
3053: ENDSCRIPT
3054: }
3055:
1.3 raeburn 3056: sub print_autoenroll {
1.30 raeburn 3057: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3058: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 3059: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 3060: if (ref($settings) eq 'HASH') {
3061: if (exists($settings->{'run'})) {
3062: if ($settings->{'run'} eq '0') {
3063: $runoff = ' checked="checked" ';
3064: $runon = ' ';
3065: } else {
3066: $runon = ' checked="checked" ';
3067: $runoff = ' ';
3068: }
3069: } else {
3070: if ($autorun) {
3071: $runon = ' checked="checked" ';
3072: $runoff = ' ';
3073: } else {
3074: $runoff = ' checked="checked" ';
3075: $runon = ' ';
3076: }
3077: }
1.129 raeburn 3078: if (exists($settings->{'co-owners'})) {
3079: if ($settings->{'co-owners'} eq '0') {
3080: $coownersoff = ' checked="checked" ';
3081: $coownerson = ' ';
3082: } else {
3083: $coownerson = ' checked="checked" ';
3084: $coownersoff = ' ';
3085: }
3086: } else {
3087: $coownersoff = ' checked="checked" ';
3088: $coownerson = ' ';
3089: }
1.3 raeburn 3090: if (exists($settings->{'sender_domain'})) {
3091: $defdom = $settings->{'sender_domain'};
3092: }
1.274 raeburn 3093: if (exists($settings->{'autofailsafe'})) {
3094: $failsafe = $settings->{'autofailsafe'};
3095: }
1.14 raeburn 3096: } else {
3097: if ($autorun) {
3098: $runon = ' checked="checked" ';
3099: $runoff = ' ';
3100: } else {
3101: $runoff = ' checked="checked" ';
3102: $runon = ' ';
3103: }
1.3 raeburn 3104: }
3105: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3106: my $notif_sender;
3107: if (ref($settings) eq 'HASH') {
3108: $notif_sender = $settings->{'sender_uname'};
3109: }
1.3 raeburn 3110: my $datatable='<tr class="LC_odd_row">'.
3111: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3112: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3113: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3114: $runon.' value="1" />'.&mt('Yes').'</label> '.
3115: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3116: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3117: '</tr><tr>'.
3118: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3119: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3120: &mt('username').': '.
3121: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3122: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3123: ': '.$domform.'</span></td></tr>'.
3124: '<tr class="LC_odd_row">'.
3125: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3126: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3127: '<input type="radio" name="autoassign_coowners"'.
3128: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3129: '<label><input type="radio" name="autoassign_coowners"'.
3130: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 3131: '</tr><tr>'.
3132: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
3133: '<td class="LC_right_item"><span class="LC_nobreak">'.
3134: '<input type="text" name="autoenroll_failsafe"'.
1.333 raeburn 3135: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274 raeburn 3136: $$rowtotal += 4;
1.3 raeburn 3137: return $datatable;
3138: }
3139:
3140: sub print_autoupdate {
1.30 raeburn 3141: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 3142: my $datatable;
3143: if ($position eq 'top') {
3144: my $updateon = ' ';
3145: my $updateoff = ' checked="checked" ';
3146: my $classlistson = ' ';
3147: my $classlistsoff = ' checked="checked" ';
3148: if (ref($settings) eq 'HASH') {
3149: if ($settings->{'run'} eq '1') {
3150: $updateon = $updateoff;
3151: $updateoff = ' ';
3152: }
3153: if ($settings->{'classlists'} eq '1') {
3154: $classlistson = $classlistsoff;
3155: $classlistsoff = ' ';
3156: }
3157: }
3158: my %title = (
3159: run => 'Auto-update active?',
3160: classlists => 'Update information in classlists?',
3161: );
3162: $datatable = '<tr class="LC_odd_row">'.
3163: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 3164: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3165: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 3166: $updateon.' value="1" />'.&mt('Yes').'</label> '.
3167: '<label><input type="radio" name="autoupdate_run"'.
3168: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3169: '</tr><tr>'.
3170: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 3171: '<td class="LC_right_item"><span class="LC_nobreak">'.
3172: '<label><input type="radio" name="classlists"'.
3173: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
3174: '<label><input type="radio" name="classlists"'.
3175: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3176: '</tr>';
1.30 raeburn 3177: $$rowtotal += 2;
1.131 raeburn 3178: } elsif ($position eq 'middle') {
3179: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3180: my $numinrow = 3;
3181: my $locknamesettings;
3182: $datatable .= &insttypes_row($settings,$types,$usertypes,
3183: $dom,$numinrow,$othertitle,
1.305 raeburn 3184: 'lockablenames',$rowtotal);
1.131 raeburn 3185: $$rowtotal ++;
1.3 raeburn 3186: } else {
1.44 raeburn 3187: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3188: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3189: 'permanentemail','id');
1.33 raeburn 3190: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3191: my $numrows = 0;
1.26 raeburn 3192: if (ref($types) eq 'ARRAY') {
3193: if (@{$types} > 0) {
3194: $datatable =
3195: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3196: \@fields,$types,\$numrows);
1.30 raeburn 3197: $$rowtotal += @{$types};
1.26 raeburn 3198: }
1.3 raeburn 3199: }
3200: $datatable .=
3201: &usertype_update_row($settings,{'default' => $othertitle},
3202: \%fieldtitles,\@fields,['default'],
3203: \$numrows);
1.30 raeburn 3204: $$rowtotal ++;
1.3 raeburn 3205: }
3206: return $datatable;
3207: }
3208:
1.125 raeburn 3209: sub print_autocreate {
3210: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 3211: my (%createon,%createoff,%currhash);
1.125 raeburn 3212: my @types = ('xml','req');
3213: if (ref($settings) eq 'HASH') {
3214: foreach my $item (@types) {
3215: $createoff{$item} = ' checked="checked" ';
3216: $createon{$item} = ' ';
3217: if (exists($settings->{$item})) {
3218: if ($settings->{$item}) {
3219: $createon{$item} = ' checked="checked" ';
3220: $createoff{$item} = ' ';
3221: }
3222: }
3223: }
1.210 raeburn 3224: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 3225: $currhash{$settings->{'xmldc'}} = 1;
3226: }
1.125 raeburn 3227: } else {
3228: foreach my $item (@types) {
3229: $createoff{$item} = ' checked="checked" ';
3230: $createon{$item} = ' ';
3231: }
3232: }
3233: $$rowtotal += 2;
1.191 raeburn 3234: my $numinrow = 2;
1.125 raeburn 3235: my $datatable='<tr class="LC_odd_row">'.
3236: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3237: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3238: '<input type="radio" name="autocreate_xml"'.
3239: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3240: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3241: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3242: '</td></tr><tr>'.
3243: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3244: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3245: '<input type="radio" name="autocreate_req"'.
3246: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3247: '<label><input type="radio" name="autocreate_req"'.
3248: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 3249: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3250: 'autocreate_xmldc',%currhash);
1.247 raeburn 3251: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3252: if ($numdc > 1) {
1.247 raeburn 3253: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3254: '</td><td class="LC_left_item">';
1.125 raeburn 3255: } else {
1.247 raeburn 3256: $datatable .= &mt('Course creation processed as:').
3257: '</td><td class="LC_right_item">';
1.125 raeburn 3258: }
1.247 raeburn 3259: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 3260: $$rowtotal += $rows;
1.125 raeburn 3261: return $datatable;
3262: }
3263:
1.23 raeburn 3264: sub print_directorysrch {
1.277 raeburn 3265: my ($position,$dom,$settings,$rowtotal) = @_;
3266: my $datatable;
3267: if ($position eq 'top') {
3268: my $instsrchon = ' ';
3269: my $instsrchoff = ' checked="checked" ';
3270: my ($exacton,$containson,$beginson);
3271: my $instlocalon = ' ';
3272: my $instlocaloff = ' checked="checked" ';
3273: if (ref($settings) eq 'HASH') {
3274: if ($settings->{'available'} eq '1') {
3275: $instsrchon = $instsrchoff;
3276: $instsrchoff = ' ';
3277: }
3278: if ($settings->{'localonly'} eq '1') {
3279: $instlocalon = $instlocaloff;
3280: $instlocaloff = ' ';
3281: }
3282: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3283: foreach my $type (@{$settings->{'searchtypes'}}) {
3284: if ($type eq 'exact') {
3285: $exacton = ' checked="checked" ';
3286: } elsif ($type eq 'contains') {
3287: $containson = ' checked="checked" ';
3288: } elsif ($type eq 'begins') {
3289: $beginson = ' checked="checked" ';
3290: }
3291: }
3292: } else {
3293: if ($settings->{'searchtypes'} eq 'exact') {
3294: $exacton = ' checked="checked" ';
3295: } elsif ($settings->{'searchtypes'} eq 'contains') {
3296: $containson = ' checked="checked" ';
3297: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3298: $exacton = ' checked="checked" ';
3299: $containson = ' checked="checked" ';
3300: }
3301: }
1.277 raeburn 3302: }
3303: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3304: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3305:
3306: my $numinrow = 4;
3307: my $cansrchrow = 0;
3308: $datatable='<tr class="LC_odd_row">'.
3309: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3310: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3311: '<input type="radio" name="dirsrch_available"'.
3312: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3313: '<label><input type="radio" name="dirsrch_available"'.
3314: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3315: '</tr><tr>'.
3316: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3317: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3318: '<input type="radio" name="dirsrch_instlocalonly"'.
3319: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3320: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3321: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3322: '</tr>';
3323: $$rowtotal += 2;
3324: if (ref($usertypes) eq 'HASH') {
3325: if (keys(%{$usertypes}) > 0) {
3326: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 3327: $numinrow,$othertitle,'cansearch',
3328: $rowtotal);
1.277 raeburn 3329: $cansrchrow = 1;
1.25 raeburn 3330: }
1.23 raeburn 3331: }
1.277 raeburn 3332: if ($cansrchrow) {
3333: $$rowtotal ++;
3334: $datatable .= '<tr>';
3335: } else {
3336: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 3337: }
1.277 raeburn 3338: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3339: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3340: foreach my $title (@{$titleorder}) {
3341: if (defined($searchtitles->{$title})) {
3342: my $check = ' ';
3343: if (ref($settings) eq 'HASH') {
3344: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3345: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3346: $check = ' checked="checked" ';
3347: }
1.39 raeburn 3348: }
1.25 raeburn 3349: }
1.277 raeburn 3350: $datatable .= '<td class="LC_left_item">'.
3351: '<span class="LC_nobreak"><label>'.
3352: '<input type="checkbox" name="searchby" '.
3353: 'value="'.$title.'"'.$check.'/>'.
3354: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3355: }
3356: }
1.277 raeburn 3357: $datatable .= '</tr></table></td></tr>';
3358: $$rowtotal ++;
3359: if ($cansrchrow) {
3360: $datatable .= '<tr class="LC_odd_row">';
3361: } else {
3362: $datatable .= '<tr>';
3363: }
3364: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3365: '<td class="LC_left_item" colspan="2">'.
3366: '<span class="LC_nobreak"><label>'.
3367: '<input type="checkbox" name="searchtypes" '.
3368: $exacton.' value="exact" />'.&mt('Exact match').
3369: '</label> '.
3370: '<label><input type="checkbox" name="searchtypes" '.
3371: $beginson.' value="begins" />'.&mt('Begins with').
3372: '</label> '.
3373: '<label><input type="checkbox" name="searchtypes" '.
3374: $containson.' value="contains" />'.&mt('Contains').
3375: '</label></span></td></tr>';
3376: $$rowtotal ++;
1.26 raeburn 3377: } else {
1.277 raeburn 3378: my $domsrchon = ' checked="checked" ';
3379: my $domsrchoff = ' ';
3380: my $domlocalon = ' ';
3381: my $domlocaloff = ' checked="checked" ';
3382: if (ref($settings) eq 'HASH') {
3383: if ($settings->{'lclocalonly'} eq '1') {
3384: $domlocalon = $domlocaloff;
3385: $domlocaloff = ' ';
3386: }
3387: if ($settings->{'lcavailable'} eq '0') {
3388: $domsrchoff = $domsrchon;
3389: $domsrchon = ' ';
3390: }
3391: }
3392: $datatable='<tr class="LC_odd_row">'.
3393: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3394: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3395: '<input type="radio" name="dirsrch_domavailable"'.
3396: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3397: '<label><input type="radio" name="dirsrch_domavailable"'.
3398: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3399: '</tr><tr>'.
3400: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3401: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3402: '<input type="radio" name="dirsrch_domlocalonly"'.
3403: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3404: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3405: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3406: '</tr>';
3407: $$rowtotal += 2;
1.26 raeburn 3408: }
1.25 raeburn 3409: return $datatable;
3410: }
3411:
1.28 raeburn 3412: sub print_contacts {
1.286 raeburn 3413: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3414: my $datatable;
3415: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3416: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 3417: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 3418: if ($position eq 'top') {
3419: if (ref($settings) eq 'HASH') {
3420: foreach my $item (@contacts) {
3421: if (exists($settings->{$item})) {
3422: $to{$item} = $settings->{$item};
3423: }
3424: }
3425: }
3426: } elsif ($position eq 'middle') {
3427: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 3428: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 3429: foreach my $type (@mailings) {
3430: $otheremails{$type} = '';
3431: }
1.340 raeburn 3432: } elsif ($position eq 'lower') {
3433: if (ref($settings) eq 'HASH') {
3434: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3435: %lonstatus = %{$settings->{'lonstatus'}};
3436: }
3437: }
1.286 raeburn 3438: } else {
3439: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3440: foreach my $type (@mailings) {
3441: $otheremails{$type} = '';
3442: }
1.286 raeburn 3443: $bccemails{'helpdeskmail'} = '';
3444: $bccemails{'otherdomsmail'} = '';
3445: $includestr{'helpdeskmail'} = '';
3446: $includestr{'otherdomsmail'} = '';
3447: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3448: }
1.28 raeburn 3449: if (ref($settings) eq 'HASH') {
1.340 raeburn 3450: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3451: foreach my $type (@mailings) {
3452: if (exists($settings->{$type})) {
3453: if (ref($settings->{$type}) eq 'HASH') {
3454: foreach my $item (@contacts) {
3455: if ($settings->{$type}{$item}) {
3456: $checked{$type}{$item} = ' checked="checked" ';
3457: }
3458: }
3459: $otheremails{$type} = $settings->{$type}{'others'};
3460: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3461: $bccemails{$type} = $settings->{$type}{'bcc'};
3462: if ($settings->{$type}{'include'} ne '') {
3463: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3464: $includestr{$type} = &unescape($includestr{$type});
3465: }
3466: }
3467: }
3468: } elsif ($type eq 'lonstatusmail') {
3469: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3470: }
1.28 raeburn 3471: }
3472: }
1.286 raeburn 3473: if ($position eq 'bottom') {
3474: foreach my $type (@mailings) {
3475: $bccemails{$type} = $settings->{$type}{'bcc'};
3476: if ($settings->{$type}{'include'} ne '') {
3477: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3478: $includestr{$type} = &unescape($includestr{$type});
3479: }
3480: }
3481: if (ref($settings->{'helpform'}) eq 'HASH') {
3482: if (ref($fields) eq 'ARRAY') {
3483: foreach my $field (@{$fields}) {
3484: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3485: }
1.286 raeburn 3486: }
3487: if (exists($settings->{'helpform'}{'maxsize'})) {
3488: $maxsize = $settings->{'helpform'}{'maxsize'};
3489: } else {
1.289 raeburn 3490: $maxsize = '1.0';
1.286 raeburn 3491: }
3492: } else {
3493: if (ref($fields) eq 'ARRAY') {
3494: foreach my $field (@{$fields}) {
3495: $currfield{$field} = 'yes';
1.134 raeburn 3496: }
1.28 raeburn 3497: }
1.286 raeburn 3498: $maxsize = '1.0';
1.28 raeburn 3499: }
3500: }
3501: } else {
1.286 raeburn 3502: if ($position eq 'top') {
3503: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3504: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3505: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3506: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3507: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3508: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3509: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3510: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 3511: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3512: } elsif ($position eq 'bottom') {
3513: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3514: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3515: if (ref($fields) eq 'ARRAY') {
3516: foreach my $field (@{$fields}) {
3517: $currfield{$field} = 'yes';
3518: }
3519: }
3520: $maxsize = '1.0';
3521: }
1.28 raeburn 3522: }
3523: my ($titles,$short_titles) = &contact_titles();
3524: my $rownum = 0;
3525: my $css_class;
1.286 raeburn 3526: if ($position eq 'top') {
3527: foreach my $item (@contacts) {
3528: $css_class = $rownum%2?' class="LC_odd_row"':'';
3529: $datatable .= '<tr'.$css_class.'>'.
3530: '<td><span class="LC_nobreak">'.$titles->{$item}.
3531: '</span></td><td class="LC_right_item">'.
3532: '<input type="text" name="'.$item.'" value="'.
3533: $to{$item}.'" /></td></tr>';
3534: $rownum ++;
3535: }
1.315 raeburn 3536: } elsif ($position eq 'bottom') {
3537: $css_class = $rownum%2?' class="LC_odd_row"':'';
3538: $datatable .= '<tr'.$css_class.'>'.
3539: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3540: &mt('(e-mail, subject, and description always shown)').
3541: '</td><td class="LC_left_item">';
3542: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3543: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3544: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3545: foreach my $field (@{$fields}) {
3546: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3547: if (($field eq 'screenshot') || ($field eq 'cc')) {
3548: $datatable .= ' '.&mt('(logged-in users)');
3549: }
3550: $datatable .='</td><td>';
3551: my $clickaction;
3552: if ($field eq 'screenshot') {
3553: $clickaction = ' onclick="screenshotSize(this);"';
3554: }
3555: if (ref($possoptions->{$field}) eq 'ARRAY') {
3556: foreach my $option (@{$possoptions->{$field}}) {
3557: my $checked;
3558: if ($currfield{$field} eq $option) {
3559: $checked = ' checked="checked"';
3560: }
3561: $datatable .= '<span class="LC_nobreak"><label>'.
3562: '<input type="radio" name="helpform_'.$field.'" '.
3563: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3564: '</label></span>'.(' 'x2);
3565: }
3566: }
3567: if ($field eq 'screenshot') {
3568: my $display;
3569: if ($currfield{$field} eq 'no') {
3570: $display = ' style="display:none"';
3571: }
1.334 raeburn 3572: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 3573: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3574: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3575: }
3576: $datatable .= '</td></tr>';
3577: }
3578: $datatable .= '</table>';
3579: }
3580: $datatable .= '</td></tr>'."\n";
3581: $rownum ++;
3582: }
1.340 raeburn 3583: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 3584: foreach my $type (@mailings) {
3585: $css_class = $rownum%2?' class="LC_odd_row"':'';
3586: $datatable .= '<tr'.$css_class.'>'.
3587: '<td><span class="LC_nobreak">'.
3588: $titles->{$type}.': </span></td>'.
3589: '<td class="LC_left_item">';
3590: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3591: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3592: }
3593: $datatable .= '<span class="LC_nobreak">';
3594: foreach my $item (@contacts) {
3595: $datatable .= '<label>'.
3596: '<input type="checkbox" name="'.$type.'"'.
3597: $checked{$type}{$item}.
3598: ' value="'.$item.'" />'.$short_titles->{$item}.
3599: '</label> ';
3600: }
3601: $datatable .= '</span><br />'.&mt('Others').': '.
3602: '<input type="text" name="'.$type.'_others" '.
3603: 'value="'.$otheremails{$type}.'" />';
3604: my %locchecked;
3605: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3606: foreach my $loc ('s','b') {
3607: if ($includeloc{$type} eq $loc) {
3608: $locchecked{$loc} = ' checked="checked"';
3609: last;
3610: }
3611: }
3612: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3613: '<input type="text" name="'.$type.'_bcc" '.
3614: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3615: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3616: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3617: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 3618: '<span class="LC_nobreak">'.&mt('Location:').' '.
3619: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3620: (' 'x2).
3621: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3622: '</span></fieldset>';
3623: }
3624: $datatable .= '</td></tr>'."\n";
3625: $rownum ++;
3626: }
1.28 raeburn 3627: }
1.286 raeburn 3628: if ($position eq 'middle') {
3629: my %choices;
1.340 raeburn 3630: my $corelink = &core_link_msu();
3631: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 3632: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 3633: $corelink);
3634: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
3635: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 3636: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 3637: 'reportupdates' => 'on',
3638: 'reportstatus' => 'on');
1.286 raeburn 3639: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3640: \%choices,$rownum);
3641: $datatable .= $reports;
1.340 raeburn 3642: } elsif ($position eq 'lower') {
3643: $css_class = $rownum%2?' class="LC_odd_row"':'';
3644: my ($threshold,$sysmail,%excluded,%weights);
3645: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
3646: if ($lonstatus{'threshold'} =~ /^\d+$/) {
3647: $threshold = $lonstatus{'threshold'};
3648: } else {
3649: $threshold = $defaults->{'threshold'};
3650: }
3651: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
3652: $sysmail = $lonstatus{'sysmail'};
3653: } else {
3654: $sysmail = $defaults->{'sysmail'};
3655: }
3656: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 3657: foreach my $type ('E','W','N','U') {
1.340 raeburn 3658: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
3659: $weights{$type} = $lonstatus{'weights'}{$type};
3660: } else {
3661: $weights{$type} = $defaults->{$type};
3662: }
3663: }
3664: } else {
1.341 raeburn 3665: foreach my $type ('E','W','N','U') {
1.340 raeburn 3666: $weights{$type} = $defaults->{$type};
3667: }
3668: }
3669: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
3670: if (@{$lonstatus{'excluded'}} > 0) {
3671: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
3672: }
3673: }
3674: $datatable .= '<tr'.$css_class.'>'.
3675: '<td class="LC_left_item"><span class="LC_nobreak">'.
3676: $titles->{'errorthreshold'}.
3677: '</span></td><td class="LC_left_item">'.
3678: '<input type="text" name="errorthreshold" value="'.
3679: $threshold.'" size="5" /></td></tr>';
3680: $rownum ++;
3681: $css_class = $rownum%2?' class="LC_odd_row"':'';
3682: $datatable .= '<tr'.$css_class.'>'.
3683: '<td class="LC_left_item">'.
3684: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
3685: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 3686: foreach my $type ('E','W','N','U') {
1.340 raeburn 3687: $datatable .= '<td>'.$names->{$type}.'<br />'.
3688: '<input type="text" name="errorweights_'.$type.'" value="'.
3689: $weights{$type}.'" size="5" /></td>';
3690: }
3691: $datatable .= '</tr></table></tr>';
3692: $rownum ++;
3693: $css_class = $rownum%2?' class="LC_odd_row"':'';
3694: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
3695: $titles->{'errorexcluded'}.'</td>'.
3696: '<td class="LC_left_item"><table>';
3697: my $numinrow = 4;
3698: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
3699: for (my $i=0; $i<@ids; $i++) {
3700: my $rem = $i%($numinrow);
3701: if ($rem == 0) {
3702: if ($i > 0) {
3703: $datatable .= '</tr>';
3704: }
3705: $datatable .= '<tr>';
3706: }
3707: my $check;
3708: if ($excluded{$ids[$i]}) {
3709: $check = ' checked="checked" ';
3710: }
3711: $datatable .= '<td class="LC_left_item">'.
3712: '<span class="LC_nobreak"><label>'.
3713: '<input type="checkbox" name="errorexcluded" '.
3714: 'value="'.$ids[$i].'"'.$check.' />'.
3715: $ids[$i].'</label></span></td>';
3716: }
3717: my $colsleft = $numinrow - @ids%($numinrow);
3718: if ($colsleft > 1 ) {
3719: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3720: ' </td>';
3721: } elsif ($colsleft == 1) {
3722: $datatable .= '<td class="LC_left_item"> </td>';
3723: }
3724: $datatable .= '</tr></table></td></tr>';
3725: $rownum ++;
3726: $css_class = $rownum%2?' class="LC_odd_row"':'';
3727: $datatable .= '<tr'.$css_class.'>'.
3728: '<td class="LC_left_item"><span class="LC_nobreak">'.
3729: $titles->{'errorsysmail'}.
3730: '</span></td><td class="LC_left_item">'.
3731: '<input type="text" name="errorsysmail" value="'.
3732: $sysmail.'" size="5" /></td></tr>';
3733: $rownum ++;
1.286 raeburn 3734: } elsif ($position eq 'bottom') {
1.315 raeburn 3735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3736: my (@posstypes,%usertypeshash);
3737: if (ref($types) eq 'ARRAY') {
3738: @posstypes = @{$types};
3739: }
3740: if (@posstypes) {
3741: if (ref($usertypes) eq 'HASH') {
3742: %usertypeshash = %{$usertypes};
3743: }
3744: my @overridden;
3745: my $numinrow = 4;
3746: if (ref($settings) eq 'HASH') {
3747: if (ref($settings->{'overrides'}) eq 'HASH') {
3748: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
3749: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
3750: push(@overridden,$key);
3751: foreach my $item (@contacts) {
3752: if ($settings->{'overrides'}{$key}{$item}) {
3753: $checked{'override_'.$key}{$item} = ' checked="checked" ';
3754: }
3755: }
3756: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
3757: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
3758: $includeloc{'override_'.$key} = '';
3759: $includestr{'override_'.$key} = '';
3760: if ($settings->{'overrides'}{$key}{'include'} ne '') {
3761: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
3762: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
3763: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
3764: }
1.286 raeburn 3765: }
3766: }
3767: }
1.315 raeburn 3768: }
3769: my $customclass = 'LC_helpdesk_override';
3770: my $optionsprefix = 'LC_options_helpdesk_';
3771:
3772: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
3773:
3774: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
3775: $numinrow,$othertitle,'overrides',
3776: \$rownum,$onclicktypes,$customclass);
3777: $rownum ++;
3778: $usertypeshash{'default'} = $othertitle;
3779: foreach my $status (@posstypes) {
3780: my $css_class;
3781: if ($rownum%2) {
3782: $css_class = 'LC_odd_row ';
3783: }
3784: $css_class .= $customclass;
3785: my $rowid = $optionsprefix.$status;
3786: my $hidden = 1;
3787: my $currstyle = 'display:none';
3788: if (grep(/^\Q$status\E$/,@overridden)) {
3789: $currstyle = 'display:table-row';
3790: $hidden = 0;
3791: }
3792: my $key = 'override_'.$status;
3793: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
3794: $includeloc{$key},$includestr{$key},$status,$rowid,
3795: $usertypeshash{$status},$css_class,$currstyle,
3796: \@contacts,$short_titles);
3797: unless ($hidden) {
3798: $rownum ++;
1.286 raeburn 3799: }
3800: }
1.134 raeburn 3801: }
1.28 raeburn 3802: }
1.30 raeburn 3803: $$rowtotal += $rownum;
1.28 raeburn 3804: return $datatable;
3805: }
3806:
1.340 raeburn 3807: sub core_link_msu {
3808: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3809: &mt('LON-CAPA core group - MSU'),600,500);
3810: }
3811:
1.315 raeburn 3812: sub overridden_helpdesk {
3813: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
3814: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
3815: my $class = 'LC_left_item';
3816: if ($css_class) {
3817: $css_class = ' class="'.$css_class.'"';
3818: }
3819: if ($rowid) {
3820: $rowid = ' id="'.$rowid.'"';
3821: }
3822: if ($rowstyle) {
3823: $rowstyle = ' style="'.$rowstyle.'"';
3824: }
3825: my ($output,$description);
3826: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
3827: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
3828: "<td>$description</td>\n".
3829: '<td class="'.$class.'" colspan="2">'.
3830: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
3831: '<span class="LC_nobreak">';
3832: if (ref($contacts) eq 'ARRAY') {
3833: foreach my $item (@{$contacts}) {
3834: my $check;
3835: if (ref($checked) eq 'HASH') {
3836: $check = $checked->{$item};
3837: }
3838: my $title;
3839: if (ref($short_titles) eq 'HASH') {
3840: $title = $short_titles->{$item};
3841: }
3842: $output .= '<label>'.
3843: '<input type="checkbox" name="override_'.$type.'"'.$check.
3844: ' value="'.$item.'" />'.$title.'</label> ';
3845: }
3846: }
3847: $output .= '</span><br />'.&mt('Others').': '.
3848: '<input type="text" name="override_'.$type.'_others" '.
3849: 'value="'.$otheremails.'" />';
3850: my %locchecked;
3851: foreach my $loc ('s','b') {
3852: if ($includeloc eq $loc) {
3853: $locchecked{$loc} = ' checked="checked"';
3854: last;
3855: }
3856: }
3857: $output .= '<br />'.&mt('Bcc:').(' 'x6).
3858: '<input type="text" name="override_'.$type.'_bcc" '.
3859: 'value="'.$bccemails.'" /></fieldset>'.
3860: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3861: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 3862: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 3863: '<span class="LC_nobreak">'.&mt('Location:').' '.
3864: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3865: (' 'x2).
3866: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3867: '</span></fieldset>'.
3868: '</td></tr>'."\n";
3869: return $output;
3870: }
3871:
1.286 raeburn 3872: sub contacts_javascript {
3873: return <<"ENDSCRIPT";
3874:
3875: <script type="text/javascript">
3876: // <![CDATA[
3877:
3878: function screenshotSize(field) {
3879: if (document.getElementById('help_screenshotsize')) {
3880: if (field.value == 'no') {
1.289 raeburn 3881: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3882: } else {
3883: document.getElementById('help_screenshotsize').style.display="";
3884: }
3885: }
3886: return;
3887: }
3888:
1.315 raeburn 3889: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
3890: if (form.elements[checkbox].length != undefined) {
3891: var count = 0;
3892: if (docount) {
3893: for (var i=0; i<form.elements[checkbox].length; i++) {
3894: if (form.elements[checkbox][i].checked) {
3895: count ++;
3896: }
3897: }
3898: }
3899: for (var i=0; i<form.elements[checkbox].length; i++) {
3900: var type = form.elements[checkbox][i].value;
3901: if (document.getElementById(prefix+type)) {
3902: if (form.elements[checkbox][i].checked) {
3903: document.getElementById(prefix+type).style.display = 'table-row';
3904: if (count % 2 == 1) {
3905: document.getElementById(prefix+type).className = target+' LC_odd_row';
3906: } else {
3907: document.getElementById(prefix+type).className = target;
3908: }
3909: count ++;
3910: } else {
3911: document.getElementById(prefix+type).style.display = 'none';
3912: }
3913: }
3914: }
3915: }
3916: return;
3917: }
3918:
3919:
1.286 raeburn 3920: // ]]>
3921: </script>
3922:
3923: ENDSCRIPT
3924: }
3925:
1.118 jms 3926: sub print_helpsettings {
1.282 raeburn 3927: my ($position,$dom,$settings,$rowtotal) = @_;
3928: my $confname = $dom.'-domainconfig';
1.285 raeburn 3929: my $formname = 'display';
1.168 raeburn 3930: my ($datatable,$itemcount);
1.282 raeburn 3931: if ($position eq 'top') {
3932: $itemcount = 1;
3933: my (%choices,%defaultchecked,@toggles);
3934: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3935: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3936: &mt('LON-CAPA bug tracker'),600,500));
3937: %defaultchecked = ('submitbugs' => 'on');
3938: @toggles = ('submitbugs');
3939: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3940: \%choices,$itemcount);
3941: $$rowtotal ++;
3942: } else {
3943: my $css_class;
3944: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3945: my (%customroles,%ordered,%current);
1.301 raeburn 3946: if (ref($settings) eq 'HASH') {
3947: if (ref($settings->{'adhoc'}) eq 'HASH') {
3948: %current = %{$settings->{'adhoc'}};
3949: }
1.285 raeburn 3950: }
3951: my $count = 0;
3952: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3953: if ($key=~/^rolesdef\_(\w+)$/) {
3954: my $rolename = $1;
1.285 raeburn 3955: my (%privs,$order);
1.282 raeburn 3956: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3957: $customroles{$rolename} = \%privs;
1.285 raeburn 3958: if (ref($current{$rolename}) eq 'HASH') {
3959: $order = $current{$rolename}{'order'};
3960: }
3961: if ($order eq '') {
3962: $order = $count;
3963: }
3964: $ordered{$order} = $rolename;
3965: $count++;
3966: }
3967: }
3968: my $maxnum = scalar(keys(%ordered));
3969: my @roles_by_num = ();
3970: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3971: push(@roles_by_num,$item);
3972: }
3973: my $context = 'domprefs';
3974: my $crstype = 'Course';
3975: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3976: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3977: my ($numstatustypes,@jsarray);
3978: if (ref($types) eq 'ARRAY') {
3979: if (@{$types} > 0) {
3980: $numstatustypes = scalar(@{$types});
3981: push(@accesstypes,'status');
3982: @jsarray = ('bystatus');
1.282 raeburn 3983: }
3984: }
1.290 raeburn 3985: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3986: if (keys(%domhelpdesk)) {
3987: push(@accesstypes,('inc','exc'));
3988: push(@jsarray,('notinc','notexc'));
3989: }
3990: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 3991: my $context = 'domprefs';
3992: my $crstype = 'Course';
1.285 raeburn 3993: my $prefix = 'helproles_';
3994: my $add_class = 'LC_hidden';
3995: foreach my $num (@roles_by_num) {
3996: my $role = $ordered{$num};
3997: my ($desc,$access,@statuses);
3998: if (ref($current{$role}) eq 'HASH') {
3999: $desc = $current{$role}{'desc'};
4000: $access = $current{$role}{'access'};
4001: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4002: @statuses = @{$current{$role}{'insttypes'}};
4003: }
4004: }
4005: if ($desc eq '') {
4006: $desc = $role;
4007: }
4008: my $identifier = 'custhelp'.$num;
1.282 raeburn 4009: my %full=();
4010: my %levels= (
4011: course => {},
4012: domain => {},
4013: system => {},
4014: );
4015: my %levelscurrent=(
4016: course => {},
4017: domain => {},
4018: system => {},
4019: );
4020: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4021: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4022: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4023: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4024: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4025: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4026: for (my $k=0; $k<=$maxnum; $k++) {
4027: my $vpos = $k+1;
4028: my $selstr;
4029: if ($k == $num) {
4030: $selstr = ' selected="selected" ';
4031: }
4032: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4033: }
4034: $datatable .= '</select>'.(' 'x2).
4035: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4036: '</td>'.
4037: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4038: &mt('Name shown to users:').
4039: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4040: '</fieldset>'.
4041: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4042: $othertitle,$usertypes,$types,\%domhelpdesk).
4043: '<fieldset>'.
4044: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4045: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4046: \%levelscurrent,$identifier,
4047: 'LC_hidden',$prefix.$num.'_privs').
4048: '</fieldset></td>';
1.282 raeburn 4049: $itemcount ++;
4050: }
4051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4052: my $newcust = 'custhelp'.$count;
4053: my (%privs,%levelscurrent);
4054: my %full=();
4055: my %levels= (
4056: course => {},
4057: domain => {},
4058: system => {},
4059: );
4060: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4061: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 4062: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 4063: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 4064: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4065: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4066: for (my $k=0; $k<$maxnum+1; $k++) {
4067: my $vpos = $k+1;
4068: my $selstr;
4069: if ($k == $maxnum) {
4070: $selstr = ' selected="selected" ';
4071: }
4072: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4073: }
4074: $datatable .= '</select> '."\n".
1.282 raeburn 4075: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4076: '</label></span></td>'.
1.285 raeburn 4077: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4078: '<span class="LC_nobreak">'.
4079: &mt('Internal name:').
4080: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4081: '</span>'.(' 'x4).
4082: '<span class="LC_nobreak">'.
4083: &mt('Name shown to users:').
4084: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4085: '</span></fieldset>'.
4086: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4087: $usertypes,$types,\%domhelpdesk).
4088: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 4089: &Apache::lonuserutils::custom_role_header($context,$crstype,
4090: \@templateroles,$newcust).
4091: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4092: \%levelscurrent,$newcust).
1.334 raeburn 4093: '</fieldset>'.
4094: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4095: '</td></tr>';
1.282 raeburn 4096: $count ++;
4097: $$rowtotal += $count;
4098: }
1.166 raeburn 4099: return $datatable;
1.121 raeburn 4100: }
4101:
1.285 raeburn 4102: sub adhocbutton {
4103: my ($prefix,$num,$field,$visibility) = @_;
4104: my %lt = &Apache::lonlocal::texthash(
4105: show => 'Show details',
4106: hide => 'Hide details',
4107: );
4108: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4109: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4110: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4111: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4112: }
4113:
4114: sub helpsettings_javascript {
4115: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4116: return unless(ref($roles_by_num) eq 'ARRAY');
4117: my %html_js_lt = &Apache::lonlocal::texthash(
4118: show => 'Show details',
4119: hide => 'Hide details',
4120: );
4121: &html_escape(\%html_js_lt);
4122: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4123: return <<"ENDSCRIPT";
4124: <script type="text/javascript">
4125: // <![CDATA[
4126:
4127: function reorderHelpRoles(form,item) {
4128: var changedVal;
4129: $jstext
4130: var newpos = 'helproles_${total}_pos';
4131: var maxh = 1 + $total;
4132: var current = new Array();
4133: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4134: if (item == newpos) {
4135: changedVal = newitemVal;
4136: } else {
4137: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4138: current[newitemVal] = newpos;
4139: }
4140: for (var i=0; i<helproles.length; i++) {
4141: var elementName = 'helproles_'+helproles[i]+'_pos';
4142: if (elementName != item) {
4143: if (form.elements[elementName]) {
4144: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4145: current[currVal] = elementName;
4146: }
4147: }
4148: }
4149: var oldVal;
4150: for (var j=0; j<maxh; j++) {
4151: if (current[j] == undefined) {
4152: oldVal = j;
4153: }
4154: }
4155: if (oldVal < changedVal) {
4156: for (var k=oldVal+1; k<=changedVal ; k++) {
4157: var elementName = current[k];
4158: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4159: }
4160: } else {
4161: for (var k=changedVal; k<oldVal; k++) {
4162: var elementName = current[k];
4163: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4164: }
4165: }
4166: return;
4167: }
4168:
4169: function helpdeskAccess(num) {
4170: var curraccess = null;
4171: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4172: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4173: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4174: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4175: }
4176: }
4177: }
4178: var shown = Array();
4179: var hidden = Array();
4180: if (curraccess == 'none') {
4181: hidden = Array('$hiddenstr');
4182: } else {
4183: if (curraccess == 'status') {
4184: shown = Array('bystatus');
4185: hidden = Array('notinc','notexc');
4186: } else {
4187: if (curraccess == 'exc') {
4188: shown = Array('notexc');
4189: hidden = Array('notinc','bystatus');
4190: }
4191: if (curraccess == 'inc') {
4192: shown = Array('notinc');
4193: hidden = Array('notexc','bystatus');
4194: }
1.293 raeburn 4195: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 4196: hidden = Array('notinc','notexc','bystatus');
4197: }
4198: }
4199: }
4200: if (hidden.length > 0) {
4201: for (var i=0; i<hidden.length; i++) {
4202: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4203: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4204: }
4205: }
4206: }
4207: if (shown.length > 0) {
4208: for (var i=0; i<shown.length; i++) {
4209: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4210: if (shown[i] == 'privs') {
4211: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4212: } else {
4213: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4214: }
4215: }
4216: }
4217: }
4218: return;
4219: }
4220:
4221: function toggleHelpdeskItem(num,field) {
4222: if (document.getElementById('helproles_'+num+'_'+field)) {
4223: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 4224: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 4225: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4226: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4227: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4228: }
4229: } else {
4230: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4231: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4232: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4233: }
4234: }
4235: }
4236: return;
4237: }
4238:
4239: // ]]>
4240: </script>
4241:
4242: ENDSCRIPT
4243: }
4244:
4245: sub helpdeskroles_access {
4246: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4247: $usertypes,$types,$domhelpdesk) = @_;
4248: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4249: my %lt = &Apache::lonlocal::texthash(
4250: 'rou' => 'Role usage',
4251: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 4252: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4253: 'dh' => 'All with domain helpdesk role',
4254: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 4255: 'none' => 'None',
4256: 'status' => 'Determined based on institutional status',
4257: 'inc' => 'Include all, but exclude specific personnel',
4258: 'exc' => 'Exclude all, but include specific personnel',
4259: );
4260: my %usecheck = (
4261: all => ' checked="checked"',
4262: );
4263: my %displaydiv = (
4264: status => 'none',
4265: inc => 'none',
4266: exc => 'none',
4267: priv => 'block',
4268: );
4269: my $output;
4270: if (ref($current) eq 'HASH') {
4271: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4272: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4273: $usecheck{$current->{access}} = $usecheck{'all'};
4274: delete($usecheck{'all'});
4275: if ($current->{access} =~ /^(status|inc|exc)$/) {
4276: my $access = $1;
4277: $displaydiv{$access} = 'inline';
4278: } elsif ($current->{access} eq 'none') {
4279: $displaydiv{'priv'} = 'none';
4280: }
4281: }
4282: }
4283: }
4284: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4285: '<p>'.$lt{'whi'}.'</p>';
4286: foreach my $access (@{$accesstypes}) {
4287: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4288: ' onclick="helpdeskAccess('."'$num'".');" />'.
4289: $lt{$access}.'</label>';
4290: if ($access eq 'status') {
4291: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4292: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4293: $othertitle,$usertypes,$types).
4294: '</div>';
4295: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4296: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4297: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4298: '</div>';
4299: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4300: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4301: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4302: '</div>';
4303: }
4304: $output .= '</p>';
4305: }
4306: $output .= '</fieldset>';
4307: return $output;
4308: }
4309:
1.121 raeburn 4310: sub radiobutton_prefs {
1.192 raeburn 4311: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 4312: $additional,$align) = @_;
1.121 raeburn 4313: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4314: (ref($choices) eq 'HASH'));
4315:
1.170 raeburn 4316: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 4317:
4318: foreach my $item (@{$toggles}) {
4319: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4320: $checkedon{$item} = ' checked="checked" ';
4321: $checkedoff{$item} = ' ';
1.121 raeburn 4322: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4323: $checkedoff{$item} = ' checked="checked" ';
4324: $checkedon{$item} = ' ';
4325: }
4326: }
4327: if (ref($settings) eq 'HASH') {
1.121 raeburn 4328: foreach my $item (@{$toggles}) {
1.118 jms 4329: if ($settings->{$item} eq '1') {
4330: $checkedon{$item} = ' checked="checked" ';
4331: $checkedoff{$item} = ' ';
4332: } elsif ($settings->{$item} eq '0') {
4333: $checkedoff{$item} = ' checked="checked" ';
4334: $checkedon{$item} = ' ';
4335: }
4336: }
1.121 raeburn 4337: }
1.192 raeburn 4338: if ($onclick) {
4339: $onclick = ' onclick="'.$onclick.'"';
4340: }
1.121 raeburn 4341: foreach my $item (@{$toggles}) {
1.118 jms 4342: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4343: $datatable .=
1.306 raeburn 4344: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 4345: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 4346: '</span></td>';
4347: if ($align eq 'left') {
4348: $datatable .= '<td class="LC_left_item">';
4349: } else {
4350: $datatable .= '<td class="LC_right_item">';
4351: }
1.289 raeburn 4352: $datatable .=
1.257 raeburn 4353: '<span class="LC_nobreak">'.
1.118 jms 4354: '<label><input type="radio" name="'.
1.192 raeburn 4355: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4356: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 4357: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
4358: '</span>'.$additional.
4359: '</td>'.
1.118 jms 4360: '</tr>';
4361: $itemcount ++;
1.121 raeburn 4362: }
4363: return ($datatable,$itemcount);
4364: }
4365:
1.267 raeburn 4366: sub print_ltitools {
4367: my ($dom,$settings,$rowtotal) = @_;
4368: my $rownum = 0;
4369: my $css_class;
4370: my $itemcount = 1;
4371: my $maxnum = 0;
4372: my %ordered;
4373: if (ref($settings) eq 'HASH') {
4374: foreach my $item (keys(%{$settings})) {
4375: if (ref($settings->{$item}) eq 'HASH') {
4376: my $num = $settings->{$item}{'order'};
4377: $ordered{$num} = $item;
4378: }
4379: }
4380: }
4381: my $confname = $dom.'-domainconfig';
4382: my $switchserver = &check_switchserver($dom,$confname);
4383: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4384: my $datatable;
1.267 raeburn 4385: my %lt = <itools_names();
4386: my @courseroles = ('cc','in','ta','ep','st');
4387: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324 raeburn 4388: my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267 raeburn 4389: if (keys(%ordered)) {
4390: my @items = sort { $a <=> $b } keys(%ordered);
4391: for (my $i=0; $i<@items; $i++) {
4392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4393: my $item = $ordered{$items[$i]};
1.323 raeburn 4394: my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267 raeburn 4395: if (ref($settings->{$item}) eq 'HASH') {
4396: $title = $settings->{$item}->{'title'};
4397: $url = $settings->{$item}->{'url'};
4398: $key = $settings->{$item}->{'key'};
4399: $secret = $settings->{$item}->{'secret'};
1.322 raeburn 4400: $lifetime = $settings->{$item}->{'lifetime'};
1.267 raeburn 4401: my $image = $settings->{$item}->{'image'};
4402: if ($image ne '') {
4403: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4404: }
1.323 raeburn 4405: if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4406: $sigsel{'HMAC-256'} = ' selected="selected"';
4407: } else {
4408: $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4409: }
1.267 raeburn 4410: }
1.319 raeburn 4411: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267 raeburn 4412: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4413: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4414: for (my $k=0; $k<=$maxnum; $k++) {
4415: my $vpos = $k+1;
4416: my $selstr;
4417: if ($k == $i) {
4418: $selstr = ' selected="selected" ';
4419: }
4420: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4421: }
4422: $datatable .= '</select>'.(' 'x2).
4423: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4424: &mt('Delete?').'</label></span></td>'.
4425: '<td colspan="2">'.
4426: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4427: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267 raeburn 4428: (' 'x2).
4429: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4430: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4431: (' 'x2).
4432: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4433: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4434: (' 'x2).
4435: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4436: '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4437: '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267 raeburn 4438: '<br /><br />'.
1.323 raeburn 4439: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267 raeburn 4440: ' value="'.$url.'" /></span>'.
4441: (' 'x2).
1.319 raeburn 4442: '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267 raeburn 4443: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4444: (' 'x2).
1.322 raeburn 4445: '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4446: '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4447: (' 'x2).
1.267 raeburn 4448: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4449: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4450: '<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>'.
4451: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4452: '</fieldset>'.
4453: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4454: '<span class="LC_nobreak">'.&mt('Display target:');
4455: my %currdisp;
4456: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4457: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4458: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 4459: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4460: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 4461: } else {
4462: $currdisp{'iframe'} = ' checked="checked"';
4463: }
4464: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4465: $currdisp{'width'} = $1;
4466: }
4467: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4468: $currdisp{'height'} = $1;
4469: }
1.296 raeburn 4470: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4471: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 4472: } else {
4473: $currdisp{'iframe'} = ' checked="checked"';
4474: }
1.298 raeburn 4475: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4476: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4477: $lt{$disp}.'</label>'.(' 'x2);
4478: }
4479: $datatable .= (' 'x4);
4480: foreach my $dimen ('width','height') {
4481: $datatable .= '<label>'.$lt{$dimen}.' '.
4482: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4483: (' 'x2);
4484: }
1.334 raeburn 4485: $datatable .= '</span><br />'.
1.296 raeburn 4486: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4487: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296 raeburn 4488: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4489: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4490: '</textarea></div><div style=""></div><br />';
1.319 raeburn 4491: my %units = (
4492: 'passback' => 'days',
4493: 'roster' => 'seconds',
4494: );
1.267 raeburn 4495: foreach my $extra ('passback','roster') {
1.319 raeburn 4496: my $validsty = 'none';
4497: my $currvalid;
1.267 raeburn 4498: my $checkedon = '';
4499: my $checkedoff = ' checked="checked"';
4500: if ($settings->{$item}->{$extra}) {
4501: $checkedon = $checkedoff;
4502: $checkedoff = '';
1.319 raeburn 4503: $validsty = 'inline-block';
4504: if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
4505: $currvalid = $settings->{$item}->{$extra.'valid'};
4506: }
4507: }
4508: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
4509: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4510: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
4511: &mt('No').'</label>'.(' 'x2).
4512: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
4513: &mt('Yes').'</label></span></div>'.
4514: '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
4515: '<span class="LC_nobreak">'.
4516: &mt("at least [_1] $units{$extra} after launch",
4517: '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
4518: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4519: }
1.319 raeburn 4520: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
1.267 raeburn 4521: if ($imgsrc) {
4522: $datatable .= $imgsrc.
4523: '<label><input type="checkbox" name="ltitools_image_del"'.
4524: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4525: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4526: } else {
4527: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4528: }
4529: if ($switchserver) {
4530: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4531: } else {
4532: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4533: }
4534: $datatable .= '</span></fieldset>';
1.324 raeburn 4535: my (%checkedfields,%rolemaps,$userincdom);
1.267 raeburn 4536: if (ref($settings->{$item}) eq 'HASH') {
4537: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4538: %checkedfields = %{$settings->{$item}->{'fields'}};
4539: }
1.324 raeburn 4540: $userincdom = $settings->{$item}->{'incdom'};
1.267 raeburn 4541: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4542: %rolemaps = %{$settings->{$item}->{'roles'}};
4543: $checkedfields{'roles'} = 1;
4544: }
4545: }
4546: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4547: '<span class="LC_nobreak">';
1.324 raeburn 4548: my $userfieldstyle = 'display:none;';
4549: my $seluserdom = '';
4550: my $unseluserdom = ' selected="selected"';
1.267 raeburn 4551: foreach my $field (@fields) {
1.324 raeburn 4552: my ($checked,$onclick,$id,$spacer);
1.267 raeburn 4553: if ($checkedfields{$field}) {
4554: $checked = ' checked="checked"';
4555: }
1.324 raeburn 4556: if ($field eq 'user') {
4557: $id = ' id="ltitools_user_field_'.$i.'"';
4558: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4559: if ($checked) {
4560: $userfieldstyle = 'display:inline-block';
4561: if ($userincdom) {
4562: $seluserdom = $unseluserdom;
4563: $unseluserdom = '';
4564: }
4565: }
4566: } else {
4567: $spacer = (' ' x2);
4568: }
1.267 raeburn 4569: $datatable .= '<label>'.
1.324 raeburn 4570: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4571: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4572: }
1.324 raeburn 4573: $datatable .= '</span>';
4574: $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4575: '<span class="LC_nobreak"> : '.
4576: '<select name="ltitools_userincdom_'.$i.'">'.
4577: '<option value="">'.&mt('Select').'</option>'.
4578: '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
4579: '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
4580: '</select></span></div>';
4581: $datatable .= '</fieldset>'.
1.267 raeburn 4582: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4583: foreach my $role (@courseroles) {
4584: my ($selected,$selectnone);
4585: if (!$rolemaps{$role}) {
4586: $selectnone = ' selected="selected"';
4587: }
1.306 raeburn 4588: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4589: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4590: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4591: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4592: foreach my $ltirole (@ltiroles) {
4593: unless ($selectnone) {
4594: if ($rolemaps{$role} eq $ltirole) {
4595: $selected = ' selected="selected"';
4596: } else {
4597: $selected = '';
4598: }
4599: }
4600: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4601: }
4602: $datatable .= '</select></td>';
4603: }
1.273 raeburn 4604: $datatable .= '</tr></table></fieldset>';
4605: my %courseconfig;
4606: if (ref($settings->{$item}) eq 'HASH') {
4607: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4608: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4609: }
4610: }
4611: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4612: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 4613: my $checked;
4614: if ($courseconfig{$item}) {
4615: $checked = ' checked="checked"';
4616: }
4617: $datatable .= '<label>'.
4618: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4619: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4620: }
4621: $datatable .= '</span></fieldset>'.
1.267 raeburn 4622: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4623: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4624: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4625: my %custom = %{$settings->{$item}->{'custom'}};
4626: if (keys(%custom) > 0) {
4627: foreach my $key (sort(keys(%custom))) {
4628: $datatable .= '<tr><td><span class="LC_nobreak">'.
4629: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4630: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4631: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4632: ' value="'.$custom{$key}.'" /></td></tr>';
4633: }
4634: }
4635: }
4636: $datatable .= '<tr><td><span class="LC_nobreak">'.
4637: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4638: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4639: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4640: $datatable .= '</table></fieldset></td></tr>'."\n";
4641: $itemcount ++;
4642: }
4643: }
4644: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319 raeburn 4645: my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267 raeburn 4646: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4647: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4648: '<select name="ltitools_add_pos"'.$chgstr.'>';
4649: for (my $k=0; $k<$maxnum+1; $k++) {
4650: my $vpos = $k+1;
4651: my $selstr;
4652: if ($k == $maxnum) {
4653: $selstr = ' selected="selected" ';
4654: }
4655: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4656: }
4657: $datatable .= '</select> '."\n".
1.334 raeburn 4658: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267 raeburn 4659: '<td colspan="2">'.
4660: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323 raeburn 4661: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267 raeburn 4662: (' 'x2).
4663: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4664: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4665: (' 'x2).
4666: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4667: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323 raeburn 4668: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
4669: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
4670: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267 raeburn 4671: '<br />'.
1.323 raeburn 4672: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267 raeburn 4673: (' 'x2).
4674: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4675: (' 'x2).
1.322 raeburn 4676: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
4677: (' 'x2).
1.267 raeburn 4678: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4679: '<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".
4680: '</fieldset>'.
4681: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4682: '<span class="LC_nobreak">'.&mt('Display target:');
4683: my %defaultdisp;
4684: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4685: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4686: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4687: $lt{$disp}.'</label>'.(' 'x2);
4688: }
4689: $datatable .= (' 'x4);
4690: foreach my $dimen ('width','height') {
4691: $datatable .= '<label>'.$lt{$dimen}.' '.
4692: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4693: (' 'x2);
4694: }
1.334 raeburn 4695: $datatable .= '</span><br />'.
1.296 raeburn 4696: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334 raeburn 4697: '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296 raeburn 4698: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334 raeburn 4699: '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296 raeburn 4700: '</div><div style=""></div><br />';
1.319 raeburn 4701: my %units = (
4702: 'passback' => 'days',
4703: 'roster' => 'seconds',
4704: );
4705: my %defaulttimes = (
4706: 'passback' => '7',
1.322 raeburn 4707: 'roster' => '300',
1.319 raeburn 4708: );
1.267 raeburn 4709: foreach my $extra ('passback','roster') {
1.319 raeburn 4710: my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
4711: $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.' '.
4712: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
4713: &mt('No').'</label></span>'.(' 'x2).'<span class="LC_nobreak">'.
4714: '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
4715: &mt('Yes').'</label></span></div>'.
4716: '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
4717: '<span class="LC_nobreak">'.
4718: &mt("at least [_1] $units{$extra} after launch",
4719: '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
4720: '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267 raeburn 4721: }
1.319 raeburn 4722: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
1.267 raeburn 4723: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4724: if ($switchserver) {
4725: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4726: } else {
4727: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4728: }
4729: $datatable .= '</span></fieldset>'.
4730: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4731: '<span class="LC_nobreak">';
4732: foreach my $field (@fields) {
1.324 raeburn 4733: my ($id,$onclick,$spacer);
4734: if ($field eq 'user') {
4735: $id = ' id="ltitools_user_field_add"';
4736: $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
4737: } else {
4738: $spacer = (' ' x2);
4739: }
1.267 raeburn 4740: $datatable .= '<label>'.
1.324 raeburn 4741: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
4742: $lt{$field}.'</label>'.$spacer;
1.267 raeburn 4743: }
1.324 raeburn 4744: $datatable .= '</span>'.
4745: '<div style="display:none;" id="ltitools_user_div_add">'.
4746: '<span class="LC_nobreak"> : '.
4747: '<select name="ltitools_userincdom_add">'.
4748: '<option value="" selected="selected">'.&mt('Select').'</option>'.
4749: '<option value="0">'.&mt('username').'</option>'.
4750: '<option value="1">'.&mt('username:domain').'</option>'.
4751: '</select></span></div></fieldset>';
4752: $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267 raeburn 4753: foreach my $role (@courseroles) {
4754: my ($checked,$checkednone);
1.306 raeburn 4755: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4756: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4757: '<select name="ltitools_add_roles_'.$role.'">'.
4758: '<option value="" selected="selected">'.&mt('Select').'</option>';
4759: foreach my $ltirole (@ltiroles) {
4760: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4761: }
4762: $datatable .= '</select></td>';
4763: }
4764: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4765: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318 raeburn 4766: foreach my $item ('label','title','target','linktext','explanation','append') {
1.296 raeburn 4767: $datatable .= '<label>'.
4768: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4769: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4770: }
4771: $datatable .= '</span></fieldset>'.
1.267 raeburn 4772: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4773: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4774: '<tr><td><span class="LC_nobreak">'.
4775: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4776: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4777: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334 raeburn 4778: '</table></fieldset>'."\n".
1.267 raeburn 4779: '</td>'."\n".
4780: '</tr>'."\n";
4781: $itemcount ++;
4782: return $datatable;
4783: }
4784:
4785: sub ltitools_names {
4786: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4787: 'title' => 'Title',
4788: 'version' => 'Version',
4789: 'msgtype' => 'Message Type',
1.323 raeburn 4790: 'sigmethod' => 'Signature Method',
1.296 raeburn 4791: 'url' => 'URL',
4792: 'key' => 'Key',
1.322 raeburn 4793: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 4794: 'secret' => 'Secret',
4795: 'icon' => 'Icon',
1.324 raeburn 4796: 'user' => 'User',
1.296 raeburn 4797: 'fullname' => 'Full Name',
4798: 'firstname' => 'First Name',
4799: 'lastname' => 'Last Name',
4800: 'email' => 'E-mail',
4801: 'roles' => 'Role',
1.298 raeburn 4802: 'window' => 'Window',
4803: 'tab' => 'Tab',
1.296 raeburn 4804: 'iframe' => 'iFrame',
4805: 'height' => 'Height',
4806: 'width' => 'Width',
4807: 'linktext' => 'Default Link Text',
4808: 'explanation' => 'Default Explanation',
4809: 'passback' => 'Tool can return grades:',
4810: 'roster' => 'Tool can retrieve roster:',
4811: 'crstarget' => 'Display target',
4812: 'crslabel' => 'Course label',
4813: 'crstitle' => 'Course title',
4814: 'crslinktext' => 'Link Text',
4815: 'crsexplanation' => 'Explanation',
1.318 raeburn 4816: 'crsappend' => 'Provider URL',
1.267 raeburn 4817: );
4818: return %lt;
4819: }
4820:
1.320 raeburn 4821: sub print_lti {
4822: my ($dom,$settings,$rowtotal) = @_;
4823: my $itemcount = 1;
4824: my $maxnum = 0;
4825: my $css_class;
4826: my %ordered;
4827: if (ref($settings) eq 'HASH') {
4828: foreach my $item (keys(%{$settings})) {
4829: if (ref($settings->{$item}) eq 'HASH') {
4830: my $num = $settings->{$item}{'order'};
4831: $ordered{$num} = $item;
4832: }
4833: }
4834: }
4835: my $maxnum = scalar(keys(%ordered));
1.334 raeburn 4836: my $datatable;
1.320 raeburn 4837: my %lt = <i_names();
4838: if (keys(%ordered)) {
4839: my @items = sort { $a <=> $b } keys(%ordered);
4840: for (my $i=0; $i<@items; $i++) {
4841: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4842: my $item = $ordered{$items[$i]};
1.345 raeburn 4843: my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320 raeburn 4844: if (ref($settings->{$item}) eq 'HASH') {
4845: $key = $settings->{$item}->{'key'};
4846: $secret = $settings->{$item}->{'secret'};
4847: $lifetime = $settings->{$item}->{'lifetime'};
4848: $consumer = $settings->{$item}->{'consumer'};
1.345 raeburn 4849: $requser = $settings->{$item}->{'requser'};
1.320 raeburn 4850: $current = $settings->{$item};
4851: }
1.345 raeburn 4852: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
4853: my %checkedrequser = (
4854: yes => ' checked="checked"',
4855: no => '',
4856: );
4857: if (!$requser) {
4858: $checkedrequser{'no'} = $checkedrequser{'yes'};
4859: $checkedrequser{'yes'} = '';
1.352 raeburn 4860: }
1.320 raeburn 4861: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
4862: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4863: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
4864: for (my $k=0; $k<=$maxnum; $k++) {
4865: my $vpos = $k+1;
4866: my $selstr;
4867: if ($k == $i) {
4868: $selstr = ' selected="selected" ';
4869: }
4870: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4871: }
4872: $datatable .= '</select>'.(' 'x2).
4873: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
4874: &mt('Delete?').'</label></span></td>'.
4875: '<td colspan="2">'.
4876: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4877: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4878: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320 raeburn 4879: (' 'x2).
4880: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
4881: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4882: (' 'x2).
4883: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345 raeburn 4884: 'value="'.$lifetime.'" size="3" /></span>'.
4885: (' 'x2).
4886: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4887: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
4888: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4889: '<br /><br />'.
4890: '<span class="LC_nobreak">'.$lt{'key'}.
4891: ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
4892: (' 'x2).
4893: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4894: '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
4895: '<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>'.
4896: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325 raeburn 4897: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320 raeburn 4898: $itemcount ++;
4899: }
4900: }
4901: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4902: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
4903: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4904: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
4905: '<select name="lti_pos_add"'.$chgstr.'>';
4906: for (my $k=0; $k<$maxnum+1; $k++) {
4907: my $vpos = $k+1;
4908: my $selstr;
4909: if ($k == $maxnum) {
4910: $selstr = ' selected="selected" ';
4911: }
4912: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4913: }
4914: $datatable .= '</select> '."\n".
1.334 raeburn 4915: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320 raeburn 4916: '<td colspan="2">'.
4917: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4918: '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345 raeburn 4919: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320 raeburn 4920: (' 'x2).
4921: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
4922: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4923: (' 'x2).
1.345 raeburn 4924: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
4925: (' 'x2).
4926: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
4927: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
4928: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320 raeburn 4929: '<br /><br />'.
4930: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
4931: (' 'x2).
4932: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
4933: '<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 4934: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
1.320 raeburn 4935: '</td>'."\n".
4936: '</tr>'."\n";
4937: $$rowtotal ++;
4938: return $datatable;;
4939: }
4940:
4941: sub lti_names {
4942: my %lt = &Apache::lonlocal::texthash(
4943: 'version' => 'LTI Version',
4944: 'url' => 'URL',
4945: 'key' => 'Key',
1.322 raeburn 4946: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 4947: 'consumer' => 'Consumer',
1.320 raeburn 4948: 'secret' => 'Secret',
1.345 raeburn 4949: 'requser' => "User's identity sent",
1.320 raeburn 4950: 'email' => 'Email address',
4951: 'sourcedid' => 'User ID',
4952: 'other' => 'Other',
4953: 'passback' => 'Can return grades to Consumer:',
4954: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 4955: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 4956: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 4957: );
4958: return %lt;
4959: }
4960:
4961: sub lti_options {
1.325 raeburn 4962: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 4963: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 4964: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
4965: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
4966: $checked{'makecrs'}{'N'} = ' checked="checked"';
4967: $checked{'mapcrstype'} = {};
4968: $checked{'makeuser'} = {};
4969: $checked{'selfenroll'} = {};
4970: $checked{'crssec'} = {};
4971: $checked{'crssecsrc'} = {};
1.325 raeburn 4972: $checked{'lcauth'} = {};
1.326 raeburn 4973: $checked{'menuitem'} = {};
1.325 raeburn 4974: if ($num eq 'add') {
4975: $checked{'lcauth'}{'lti'} = ' checked="checked"';
4976: }
1.320 raeburn 4977: my $userfieldsty = 'none';
4978: my $crsfieldsty = 'none';
4979: my $crssecfieldsty = 'none';
4980: my $secsrcfieldsty = 'none';
1.363 raeburn 4981: my $callbacksty = 'none';
1.337 raeburn 4982: my $passbacksty = 'none';
1.345 raeburn 4983: my $optionsty = 'block';
1.325 raeburn 4984: my $lcauthparm;
4985: my $lcauthparmstyle = 'display:none';
4986: my $lcauthparmtext;
1.326 raeburn 4987: my $menusty;
1.325 raeburn 4988: my $numinrow = 4;
1.326 raeburn 4989: my %menutitles = <imenu_titles();
1.320 raeburn 4990:
4991: if (ref($current) eq 'HASH') {
1.345 raeburn 4992: if (!$current->{'requser'}) {
4993: $optionsty = 'none';
4994: }
1.320 raeburn 4995: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
4996: $checked{'mapuser'}{'sourcedid'} = '';
4997: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
4998: $checked{'mapuser'}{'email'} = ' checked="checked"';
4999: } else {
5000: $checked{'mapuser'}{'other'} = ' checked="checked"';
5001: $userfield = $current->{'mapuser'};
5002: $userfieldsty = 'inline-block';
5003: }
5004: }
5005: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5006: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5007: if ($current->{'mapcrs'} eq 'context_id') {
5008: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5009: } else {
5010: $checked{'mapcrs'}{'other'} = ' checked="checked"';
5011: $cidfield = $current->{'mapcrs'};
5012: $crsfieldsty = 'inline-block';
5013: }
5014: }
5015: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5016: foreach my $type (@{$current->{'mapcrstype'}}) {
5017: $checked{'mapcrstype'}{$type} = ' checked="checked"';
5018: }
5019: }
1.345 raeburn 5020: if ($current->{'makecrs'}) {
1.320 raeburn 5021: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 5022: }
1.320 raeburn 5023: if (ref($current->{'makeuser'}) eq 'ARRAY') {
5024: foreach my $role (@{$current->{'makeuser'}}) {
5025: $checked{'makeuser'}{$role} = ' checked="checked"';
5026: }
5027: }
1.325 raeburn 5028: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5029: $checked{'lcauth'}{$1} = ' checked="checked"';
5030: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5031: $lcauthparm = $current->{'lcauthparm'};
5032: $lcauthparmstyle = 'display:table-row';
5033: if ($current->{'lcauth'} eq 'localauth') {
5034: $lcauthparmtext = &mt('Local auth argument');
5035: } else {
5036: $lcauthparmtext = &mt('Kerberos domain');
5037: }
5038: }
5039: }
1.320 raeburn 5040: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5041: foreach my $role (@{$current->{'selfenroll'}}) {
5042: $checked{'selfenroll'}{$role} = ' checked="checked"';
5043: }
5044: }
5045: if (ref($current->{'maproles'}) eq 'HASH') {
5046: %rolemaps = %{$current->{'maproles'}};
5047: }
5048: if ($current->{'section'} ne '') {
5049: $checked{'crssec'}{'Y'} = ' checked="checked"';
5050: $crssecfieldsty = 'inline-block';
5051: if ($current->{'section'} eq 'course_section_sourcedid') {
5052: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5053: } else {
5054: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5055: $crssecsrc = $current->{'section'};
5056: $secsrcfieldsty = 'inline-block';
5057: }
5058: } else {
5059: $checked{'crssec'}{'N'} = ' checked="checked"';
5060: }
1.363 raeburn 5061: if ($current->{'callback'} ne '') {
5062: $callback = $current->{'callback'};
5063: $checked{'callback'}{'Y'} = ' checked="checked"';
5064: $callbacksty = 'inline-block';
5065: } else {
5066: $checked{'callback'}{'N'} = ' checked="checked"';
5067: }
1.326 raeburn 5068: if ($current->{'topmenu'}) {
5069: $checked{'topmenu'}{'Y'} = ' checked="checked"';
5070: } else {
5071: $checked{'topmenu'}{'N'} = ' checked="checked"';
5072: }
5073: if ($current->{'inlinemenu'}) {
5074: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5075: } else {
5076: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5077: }
5078: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5079: $menusty = 'inline-block';
5080: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5081: foreach my $item (@{$current->{'lcmenu'}}) {
5082: if (exists($menutitles{$item})) {
5083: $checked{'menuitem'}{$item} = ' checked="checked"';
5084: }
5085: }
5086: }
5087: } else {
5088: $menusty = 'none';
5089: }
1.320 raeburn 5090: } else {
5091: $checked{'makecrs'}{'N'} = ' checked="checked"';
5092: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 5093: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 5094: $checked{'topmenu'}{'N'} = ' checked="checked"';
5095: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5096: $checked{'menuitem'}{'grades'} = ' checked="checked"';
5097: $menusty = 'inline-block';
1.320 raeburn 5098: }
1.325 raeburn 5099: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 5100: my %coursetypetitles = &Apache::lonlocal::texthash (
5101: official => 'Official',
5102: unofficial => 'Unofficial',
5103: community => 'Community',
5104: textbook => 'Textbook',
5105: placement => 'Placement Test',
1.325 raeburn 5106: lti => 'LTI Provider',
1.320 raeburn 5107: );
1.325 raeburn 5108: my @authtypes = ('internal','krb4','krb5','localauth');
5109: my %shortauth = (
5110: internal => 'int',
5111: krb4 => 'krb4',
5112: krb5 => 'krb5',
5113: localauth => 'loc'
5114: );
5115: my %authnames = &authtype_names();
1.320 raeburn 5116: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5117: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5118: my @courseroles = ('cc','in','ta','ep','st');
5119: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5120: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5121: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 5122: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 5123: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 5124: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 5125: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345 raeburn 5126: my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 5127: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5128: foreach my $option ('sourcedid','email','other') {
5129: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5130: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5131: ($option eq 'other' ? '' : (' 'x2) );
5132: }
5133: $output .= '</span></div>'.
5134: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5135: '<input type="text" name="lti_customuser_'.$num.'" '.
5136: 'value="'.$userfield.'" /></div></fieldset>'.
1.345 raeburn 5137: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320 raeburn 5138: foreach my $ltirole (@lticourseroles) {
5139: my ($selected,$selectnone);
5140: if ($rolemaps{$ltirole} eq '') {
5141: $selectnone = ' selected="selected"';
5142: }
5143: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5144: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5145: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5146: foreach my $role (@courseroles) {
5147: unless ($selectnone) {
5148: if ($rolemaps{$ltirole} eq $role) {
5149: $selected = ' selected="selected"';
5150: } else {
5151: $selected = '';
5152: }
5153: }
5154: $output .= '<option value="'.$role.'"'.$selected.'>'.
5155: &Apache::lonnet::plaintext($role,'Course').
5156: '</option>';
5157: }
5158: $output .= '</select></td>';
5159: }
5160: $output .= '</tr></table></fieldset>'.
1.345 raeburn 5161: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 5162: foreach my $ltirole (@ltiroles) {
5163: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5164: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5165: }
5166: $output .= '</fieldset>'.
1.345 raeburn 5167: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 5168: '<table>'.
5169: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5170: '</table>'.
5171: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5172: '<td class="LC_left_item">';
5173: foreach my $auth ('lti',@authtypes) {
5174: my $authtext;
5175: if ($auth eq 'lti') {
5176: $authtext = &mt('None');
5177: } else {
5178: $authtext = $authnames{$shortauth{$auth}};
5179: }
5180: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5181: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5182: $authtext.'</label></span> ';
5183: }
5184: $output .= '</td></tr>'.
5185: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5186: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5187: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5188: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5189: '</table></fieldset>'.
1.345 raeburn 5190: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 5191: '<div class="LC_floatleft"><span class="LC_nobreak">'.
5192: &mt('Unique course identifier').': ';
5193: foreach my $option ('course_offering_sourcedid','context_id','other') {
5194: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5195: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5196: ($option eq 'other' ? '' : (' 'x2) );
5197: }
1.334 raeburn 5198: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 5199: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5200: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5201: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5202: foreach my $type (@coursetypes) {
5203: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5204: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5205: (' 'x2);
5206: }
5207: $output .= '</span></fieldset>'.
1.345 raeburn 5208: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 5209: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5210: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5211: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5212: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5213: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5214: '</fieldset>'.
1.345 raeburn 5215: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 5216: foreach my $lticrsrole (@lticourseroles) {
5217: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5218: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5219: }
5220: $output .= '</fieldset>'.
1.345 raeburn 5221: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 5222: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5223: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5224: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5225: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 5226: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 5227: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5228: '<span class="LC_nobreak">'.&mt('From').':<label>'.
5229: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5230: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5231: &mt('Standard field').'</label>'.(' 'x2).
5232: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5233: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 5234: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 5235: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 5236: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5237: my ($pb1p1chk,$pb1p0chk,$onclickpb);
5238: foreach my $extra ('roster','passback') {
1.320 raeburn 5239: my $checkedon = '';
5240: my $checkedoff = ' checked="checked"';
1.337 raeburn 5241: if ($extra eq 'passback') {
5242: $pb1p1chk = ' checked="checked"';
5243: $pb1p0chk = '';
5244: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5245: } else {
5246: $onclickpb = '';
5247: }
1.320 raeburn 5248: if (ref($current) eq 'HASH') {
5249: if (($current->{$extra})) {
5250: $checkedon = $checkedoff;
5251: $checkedoff = '';
1.337 raeburn 5252: if ($extra eq 'passback') {
5253: $passbacksty = 'inline-block';
5254: }
5255: if ($current->{'passbackformat'} eq '1.0') {
5256: $pb1p0chk = ' checked="checked"';
5257: $pb1p1chk = '';
5258: }
1.320 raeburn 5259: }
5260: }
5261: $output .= $lt{$extra}.' '.
1.337 raeburn 5262: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 5263: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 5264: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 5265: &mt('Yes').'</label><br />';
5266: }
1.337 raeburn 5267: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5268: '<span class="LC_nobreak">'.&mt('Grade format').
5269: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5270: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5271: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 5272: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5273: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5274: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').': '.
5275: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5276: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5277: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5278: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5279: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5280: '<span class="LC_nobreak">'.&mt('Parameter').': '.
5281: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5282: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345 raeburn 5283: '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326 raeburn 5284: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5285: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5286: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5287: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334 raeburn 5288: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326 raeburn 5289: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5290: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5291: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5292: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5293: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334 raeburn 5294: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326 raeburn 5295: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5296: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5297: '<span class="LC_nobreak">'.&mt('Menu items').': ';
5298: foreach my $type ('fullname','coursetitle','role','logout','grades') {
5299: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5300: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5301: (' 'x2);
5302: }
1.334 raeburn 5303: $output .= '</span></div></fieldset>';
1.320 raeburn 5304: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5305: #
5306: # $output .= '</fieldset>'.
5307: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5308: return $output;
5309: }
5310:
1.326 raeburn 5311: sub ltimenu_titles {
5312: return &Apache::lonlocal::texthash(
5313: fullname => 'Full name',
5314: coursetitle => 'Course title',
5315: role => 'Role',
5316: logout => 'Logout',
5317: grades => 'Grades',
5318: );
5319: }
5320:
1.121 raeburn 5321: sub print_coursedefaults {
1.139 raeburn 5322: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 5323: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5324: my $itemcount = 1;
1.192 raeburn 5325: my %choices = &Apache::lonlocal::texthash (
5326: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 5327: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 5328: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5329: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 5330: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5331: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 5332: texengine => 'Default method to display mathematics',
1.257 raeburn 5333: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 5334: canclone => "People who may clone a course (besides course's owner and coordinators)",
5335: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 5336: );
1.198 raeburn 5337: my %staticdefaults = (
5338: anonsurvey_threshold => 10,
5339: uploadquota => 500,
1.257 raeburn 5340: postsubmit => 60,
1.276 raeburn 5341: mysqltables => 172800,
1.198 raeburn 5342: );
1.139 raeburn 5343: if ($position eq 'top') {
1.257 raeburn 5344: %defaultchecked = (
5345: 'canuse_pdfforms' => 'off',
5346: 'uselcmath' => 'on',
5347: 'usejsme' => 'on',
1.289 raeburn 5348: 'canclone' => 'none',
1.257 raeburn 5349: );
5350: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349 raeburn 5351: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 5352: if (ref($settings) eq 'HASH') {
5353: if ($settings->{'texengine'}) {
5354: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5355: $deftex = $settings->{'texengine'};
5356: }
5357: }
5358: }
5359: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5360: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5361: '<span class="LC_nobreak">'.$choices{'texengine'}.
5362: '</span></td><td class="LC_right_item">'.
5363: '<select name="texengine">'."\n";
5364: my %texoptions = (
5365: MathJax => 'MathJax',
5366: mimetex => &mt('Convert to Images'),
5367: tth => &mt('TeX to HTML'),
5368: );
5369: foreach my $renderer ('MathJax','mimetex','tth') {
5370: my $selected = '';
5371: if ($renderer eq $deftex) {
5372: $selected = ' selected="selected"';
5373: }
5374: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5375: }
5376: $mathdisp .= '</select></td></tr>'."\n";
5377: $itemcount ++;
1.139 raeburn 5378: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 5379: \%choices,$itemcount);
1.314 raeburn 5380: $datatable = $mathdisp.$datatable;
1.264 raeburn 5381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5382: $datatable .=
1.306 raeburn 5383: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 5384: '<span class="LC_nobreak">'.$choices{'canclone'}.
5385: '</span></td><td class="LC_left_item">';
5386: my $currcanclone = 'none';
5387: my $onclick;
5388: my @cloneoptions = ('none','domain');
5389: my %clonetitles = (
5390: none => 'No additional course requesters',
5391: domain => "Any course requester in course's domain",
5392: instcode => 'Course requests for official courses ...',
5393: );
5394: my (%codedefaults,@code_order,@posscodes);
5395: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5396: \@code_order) eq 'ok') {
5397: if (@code_order > 0) {
5398: push(@cloneoptions,'instcode');
5399: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5400: }
5401: }
5402: if (ref($settings) eq 'HASH') {
5403: if ($settings->{'canclone'}) {
5404: if (ref($settings->{'canclone'}) eq 'HASH') {
5405: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5406: if (@code_order > 0) {
5407: $currcanclone = 'instcode';
5408: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5409: }
5410: }
5411: } elsif ($settings->{'canclone'} eq 'domain') {
5412: $currcanclone = $settings->{'canclone'};
5413: }
5414: }
1.289 raeburn 5415: }
1.264 raeburn 5416: foreach my $option (@cloneoptions) {
5417: my ($checked,$additional);
5418: if ($currcanclone eq $option) {
5419: $checked = ' checked="checked"';
5420: }
5421: if ($option eq 'instcode') {
5422: if (@code_order) {
5423: my $show = 'none';
5424: if ($checked) {
5425: $show = 'block';
5426: }
1.317 raeburn 5427: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 5428: &mt('Institutional codes for new and cloned course have identical:').
5429: '<br />';
5430: foreach my $item (@code_order) {
5431: my $codechk;
5432: if ($checked) {
5433: if (grep(/^\Q$item\E$/,@posscodes)) {
5434: $codechk = ' checked="checked"';
5435: }
5436: }
5437: $additional .= '<label>'.
5438: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5439: $item.'</label>';
5440: }
5441: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5442: }
5443: }
5444: $datatable .=
5445: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5446: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5447: '</label> '.$additional.'</span><br />';
5448: }
5449: $datatable .= '</td>'.
5450: '</tr>';
5451: $itemcount ++;
1.139 raeburn 5452: } else {
5453: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 5454: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 5455: my $currusecredits = 0;
1.257 raeburn 5456: my $postsubmitclient = 1;
1.271 raeburn 5457: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 5458: if (ref($settings) eq 'HASH') {
5459: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 5460: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5461: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5462: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5463: }
5464: }
1.192 raeburn 5465: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 5466: foreach my $type (@types) {
5467: next if ($type eq 'community');
5468: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5469: if ($defcredits{$type} ne '') {
5470: $currusecredits = 1;
5471: }
5472: }
5473: }
5474: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5475: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5476: $postsubmitclient = 0;
5477: foreach my $type (@types) {
5478: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5479: }
5480: } else {
5481: foreach my $type (@types) {
5482: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5483: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 5484: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 5485: } else {
5486: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5487: }
5488: } else {
5489: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5490: }
5491: }
5492: }
5493: } else {
5494: foreach my $type (@types) {
5495: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 5496: }
5497: }
1.276 raeburn 5498: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5499: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5500: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5501: }
5502: } else {
5503: foreach my $type (@types) {
5504: $currmysql{$type} = $staticdefaults{'mysqltables'};
5505: }
5506: }
1.258 raeburn 5507: } else {
5508: foreach my $type (@types) {
5509: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5510: }
1.139 raeburn 5511: }
5512: if (!$currdefresponder) {
1.198 raeburn 5513: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5514: } elsif ($currdefresponder < 1) {
5515: $currdefresponder = 1;
5516: }
1.198 raeburn 5517: foreach my $type (@types) {
5518: if ($curruploadquota{$type} eq '') {
5519: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5520: }
5521: }
1.139 raeburn 5522: $datatable .=
1.192 raeburn 5523: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5524: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5525: '</span></td>'.
5526: '<td class="LC_right_item"><span class="LC_nobreak">'.
5527: '<input type="text" name="anonsurvey_threshold"'.
5528: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 5529: '</td></tr>'."\n";
5530: $itemcount ++;
5531: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5532: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5533: $choices{'uploadquota'}.
5534: '</span></td>'.
1.306 raeburn 5535: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 5536: '<table><tr>';
1.198 raeburn 5537: foreach my $type (@types) {
1.306 raeburn 5538: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 5539: '<input type="text" name="uploadquota_'.$type.'"'.
5540: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5541: }
5542: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 5543: $itemcount ++;
1.236 raeburn 5544: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 5545: my $display = 'none';
1.192 raeburn 5546: if ($currusecredits) {
5547: $display = 'block';
5548: }
5549: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 5550: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5551: foreach my $type (@types) {
5552: next if ($type eq 'community');
1.306 raeburn 5553: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5554: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 5555: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 5556: }
5557: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 5558: %defaultchecked = ('coursecredits' => 'off');
5559: @toggles = ('coursecredits');
5560: my $current = {
5561: 'coursecredits' => $currusecredits,
5562: };
5563: (my $table,$itemcount) =
5564: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 5565: \%choices,$itemcount,$onclick,$additional,'left');
5566: $datatable .= $table;
5567: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5568: my $display = 'none';
5569: if ($postsubmitclient) {
5570: $display = 'block';
5571: }
5572: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 5573: &mt('Number of seconds submit is disabled').'<br />'.
5574: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5575: '<table><tr>';
1.257 raeburn 5576: foreach my $type (@types) {
1.306 raeburn 5577: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 5578: '<input type="text" name="'.$type.'_timeout" value="'.
5579: $deftimeout{$type}.'" size="5" /></td>';
5580: }
5581: $additional .= '</tr></table></div>'."\n";
5582: %defaultchecked = ('postsubmit' => 'on');
5583: @toggles = ('postsubmit');
1.280 raeburn 5584: $current = {
5585: 'postsubmit' => $postsubmitclient,
5586: };
1.257 raeburn 5587: ($table,$itemcount) =
5588: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5589: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 5590: $datatable .= $table;
1.276 raeburn 5591: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5592: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5593: $choices{'mysqltables'}.
5594: '</span></td>'.
1.306 raeburn 5595: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 5596: '<table><tr>';
5597: foreach my $type (@types) {
1.306 raeburn 5598: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 5599: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 5600: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 5601: }
5602: $datatable .= '</tr></table></td></tr>'."\n";
5603: $itemcount ++;
5604:
1.139 raeburn 5605: }
1.192 raeburn 5606: $$rowtotal += $itemcount;
1.121 raeburn 5607: return $datatable;
1.118 jms 5608: }
5609:
1.231 raeburn 5610: sub print_selfenrollment {
5611: my ($position,$dom,$settings,$rowtotal) = @_;
5612: my ($css_class,$datatable);
5613: my $itemcount = 1;
1.271 raeburn 5614: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 5615: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 5616: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5617: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 5618: my @rows;
5619: my $key;
5620: if ($position eq 'top') {
5621: $key = 'admin';
5622: if (ref($rowsref) eq 'ARRAY') {
5623: @rows = @{$rowsref};
5624: }
5625: } elsif ($position eq 'middle') {
5626: $key = 'default';
5627: @rows = ('types','registered','approval','limit');
5628: }
5629: foreach my $row (@rows) {
5630: if (defined($titlesref->{$row})) {
5631: $itemcount ++;
5632: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5633: $datatable .= '<tr'.$css_class.'>'.
5634: '<td>'.$titlesref->{$row}.'</td>'.
5635: '<td class="LC_left_item">'.
5636: '<table><tr>';
5637: my (%current,%currentcap);
5638: if (ref($settings) eq 'HASH') {
5639: if (ref($settings->{$key}) eq 'HASH') {
5640: foreach my $type (@types) {
5641: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5642: $current{$type} = $settings->{$key}->{$type}->{$row};
5643: }
5644: if (($row eq 'limit') && ($key eq 'default')) {
5645: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5646: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5647: }
5648: }
5649: }
5650: }
5651: }
5652: my %roles = (
5653: '0' => &Apache::lonnet::plaintext('dc'),
5654: );
5655:
5656: foreach my $type (@types) {
5657: unless (($row eq 'registered') && ($key eq 'default')) {
5658: $datatable .= '<th>'.&mt($type).'</th>';
5659: }
5660: }
5661: unless (($row eq 'registered') && ($key eq 'default')) {
5662: $datatable .= '</tr><tr>';
5663: }
5664: foreach my $type (@types) {
5665: if ($type eq 'community') {
5666: $roles{'1'} = &mt('Community personnel');
5667: } else {
5668: $roles{'1'} = &mt('Course personnel');
5669: }
5670: $datatable .= '<td style="vertical-align: top">';
5671: if ($position eq 'top') {
5672: my %checked;
5673: if ($current{$type} eq '0') {
5674: $checked{'0'} = ' checked="checked"';
5675: } else {
5676: $checked{'1'} = ' checked="checked"';
5677: }
5678: foreach my $role ('1','0') {
5679: $datatable .= '<span class="LC_nobreak"><label>'.
5680: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5681: 'value="'.$role.'"'.$checked{$role}.' />'.
5682: $roles{$role}.'</label></span> ';
5683: }
5684: } else {
5685: if ($row eq 'types') {
5686: my %checked;
5687: if ($current{$type} =~ /^(all|dom)$/) {
5688: $checked{$1} = ' checked="checked"';
5689: } else {
5690: $checked{''} = ' checked="checked"';
5691: }
5692: foreach my $val ('','dom','all') {
5693: $datatable .= '<span class="LC_nobreak"><label>'.
5694: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5695: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5696: }
5697: } elsif ($row eq 'registered') {
5698: my %checked;
5699: if ($current{$type} eq '1') {
5700: $checked{'1'} = ' checked="checked"';
5701: } else {
5702: $checked{'0'} = ' checked="checked"';
5703: }
5704: foreach my $val ('0','1') {
5705: $datatable .= '<span class="LC_nobreak"><label>'.
5706: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5707: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5708: }
5709: } elsif ($row eq 'approval') {
5710: my %checked;
5711: if ($current{$type} =~ /^([12])$/) {
5712: $checked{$1} = ' checked="checked"';
5713: } else {
5714: $checked{'0'} = ' checked="checked"';
5715: }
5716: for my $val (0..2) {
5717: $datatable .= '<span class="LC_nobreak"><label>'.
5718: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5719: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5720: }
5721: } elsif ($row eq 'limit') {
5722: my %checked;
5723: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5724: $checked{$1} = ' checked="checked"';
5725: } else {
5726: $checked{'none'} = ' checked="checked"';
5727: }
5728: my $cap;
5729: if ($currentcap{$type} =~ /^\d+$/) {
5730: $cap = $currentcap{$type};
5731: }
5732: foreach my $val ('none','allstudents','selfenrolled') {
5733: $datatable .= '<span class="LC_nobreak"><label>'.
5734: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5735: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5736: }
5737: $datatable .= '<br />'.
5738: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5739: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5740: '</span>';
5741: }
5742: }
5743: $datatable .= '</td>';
5744: }
5745: $datatable .= '</tr>';
5746: }
5747: $datatable .= '</table></td></tr>';
5748: }
5749: } elsif ($position eq 'bottom') {
1.235 raeburn 5750: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5751: }
5752: $$rowtotal += $itemcount;
5753: return $datatable;
5754: }
5755:
5756: sub print_validation_rows {
5757: my ($caller,$dom,$settings,$rowtotal) = @_;
5758: my ($itemsref,$namesref,$fieldsref);
5759: if ($caller eq 'selfenroll') {
5760: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5761: } elsif ($caller eq 'requestcourses') {
5762: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5763: }
5764: my %currvalidation;
5765: if (ref($settings) eq 'HASH') {
5766: if (ref($settings->{'validation'}) eq 'HASH') {
5767: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 5768: }
1.235 raeburn 5769: }
5770: my $datatable;
5771: my $itemcount = 0;
5772: foreach my $item (@{$itemsref}) {
5773: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5774: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5775: $namesref->{$item}.
5776: '</span></td>'.
5777: '<td class="LC_left_item">';
5778: if (($item eq 'url') || ($item eq 'button')) {
5779: $datatable .= '<span class="LC_nobreak">'.
5780: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5781: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5782: } elsif ($item eq 'fields') {
5783: my @currfields;
5784: if (ref($currvalidation{$item}) eq 'ARRAY') {
5785: @currfields = @{$currvalidation{$item}};
5786: }
5787: foreach my $field (@{$fieldsref}) {
5788: my $check = '';
5789: if (grep(/^\Q$field\E$/,@currfields)) {
5790: $check = ' checked="checked"';
5791: }
5792: $datatable .= '<span class="LC_nobreak"><label>'.
5793: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5794: ' value="'.$field.'"'.$check.' />'.$field.
5795: '</label></span> ';
5796: }
5797: } elsif ($item eq 'markup') {
1.334 raeburn 5798: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 5799: $currvalidation{$item}.
1.231 raeburn 5800: '</textarea>';
1.235 raeburn 5801: }
5802: $datatable .= '</td></tr>'."\n";
5803: if (ref($rowtotal)) {
1.231 raeburn 5804: $itemcount ++;
5805: }
5806: }
1.235 raeburn 5807: if ($caller eq 'requestcourses') {
5808: my %currhash;
1.248 raeburn 5809: if (ref($settings) eq 'HASH') {
5810: if (ref($settings->{'validation'}) eq 'HASH') {
5811: if ($settings->{'validation'}{'dc'} ne '') {
5812: $currhash{$settings->{'validation'}{'dc'}} = 1;
5813: }
1.235 raeburn 5814: }
5815: }
5816: my $numinrow = 2;
5817: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5818: 'validationdc',%currhash);
1.247 raeburn 5819: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 5820: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 5821: if ($numdc > 1) {
1.247 raeburn 5822: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 5823: } else {
1.247 raeburn 5824: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 5825: }
1.247 raeburn 5826: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 5827: $itemcount ++;
5828: }
5829: if (ref($rowtotal)) {
5830: $$rowtotal += $itemcount;
5831: }
1.231 raeburn 5832: return $datatable;
5833: }
5834:
1.357 raeburn 5835: sub print_privacy {
5836: my ($position,$dom,$settings,$rowtotal) = @_;
5837: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
5838: my $itemcount = 0;
5839: unless ($position eq 'top') {
5840: @items = ('domain','author','course','community');
5841: %names = &Apache::lonlocal::texthash (
5842: domain => 'Assigned domain role(s)',
5843: author => 'Assigned co-author role(s)',
5844: course => 'Assigned course role(s)',
5845: community => 'Assigned community role',
5846: );
5847: $numinrow = 4;
5848: ($othertitle,$usertypes,$types) =
5849: &Apache::loncommon::sorted_inst_types($dom);
5850: }
5851: if (($position eq 'top') || ($position eq 'middle')) {
5852: my (%by_ip,%by_location,@intdoms,@instdoms);
5853: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5854: if ($position eq 'top') {
5855: my %curr;
5856: my @options = ('none','user','domain','auto');
5857: my %titles = &Apache::lonlocal::texthash (
5858: none => 'Not allowed',
5859: user => 'User authorizes',
5860: domain => 'DC authorizes',
5861: auto => 'Unrestricted',
5862: instdom => 'Other domain shares institution/provider',
5863: extdom => 'Other domain has different institution/provider',
5864: );
5865: my %names = &Apache::lonlocal::texthash (
5866: domain => 'Domain role',
5867: author => 'Co-author role',
5868: course => 'Course role',
5869: community => 'Community role',
5870: );
5871: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5872: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5873: foreach my $domtype ('instdom','extdom') {
5874: my (%checked,$skip);
5875: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5876: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
5877: '<td class="LC_left_item">';
5878: if ($domtype eq 'instdom') {
5879: unless (@instdoms > 1) {
5880: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
5881: $skip = 1;
5882: }
5883: } elsif ($domtype eq 'extdom') {
5884: if (keys(%by_location) == 0) {
5885: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
5886: $skip = 1;
5887: }
5888: }
5889: unless ($skip) {
5890: foreach my $roletype ('domain','author','course','community') {
5891: $checked{'auto'} = ' checked="checked"';
5892: if (ref($settings) eq 'HASH') {
5893: if (ref($settings->{approval}) eq 'HASH') {
5894: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
5895: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
5896: $checked{$1} = ' checked="checked"';
5897: $checked{'auto'} = '';
5898: }
5899: }
5900: }
5901: }
5902: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
5903: foreach my $option (@options) {
5904: $datatable .= '<span class="LC_nobreak"><label>'.
5905: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
5906: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
5907: '</label></span> ';
5908: }
5909: $datatable .= '</fieldset>';
5910: }
5911: }
5912: $datatable .= '</td></tr>';
5913: $itemcount ++;
5914: }
5915: } elsif ($position eq 'middle') {
5916: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
5917: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5918: foreach my $item (@{$types}) {
5919: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
5920: $numinrow,$itemcount,'','','','','',
5921: '',$usertypes->{$item});
5922: $itemcount ++;
5923: }
5924: }
5925: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
5926: $numinrow,$itemcount,'','','','','',
5927: '',$othertitle);
5928: $itemcount ++;
5929: } else {
1.360 raeburn 5930: my (@insttypes,%insttitles);
5931: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5932: @insttypes = @{$types};
5933: %insttitles = %{$usertypes};
5934: }
5935: foreach my $item (@insttypes,'default') {
5936: my $title;
5937: if ($item eq 'default') {
5938: $title = $othertitle;
5939: } else {
5940: $title = $insttitles{$item};
5941: }
5942: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5943: $datatable .= '<tr'.$css_class.'>'.
5944: '<td class="LC_left_item">'.$title.'</td>'.
5945: '<td class="LC_left_item">'.
5946: &mt('Nothing to set here, as there are no other domains').
5947: '</td></tr>';
5948: $itemcount ++;
5949: }
1.357 raeburn 5950: }
5951: }
5952: } else {
5953: my $prefix;
5954: if ($position eq 'lower') {
5955: $prefix = 'priv';
5956: } else {
5957: $prefix = 'unpriv';
5958: }
5959: foreach my $item (@items) {
5960: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
5961: $numinrow,$itemcount,'','','','','',
5962: '',$names{$item});
5963: $itemcount ++;
5964: }
5965: }
5966: if (ref($rowtotal)) {
5967: $$rowtotal += $itemcount;
5968: }
5969: return $datatable;
5970: }
5971:
1.354 raeburn 5972: sub print_passwords {
5973: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5974: my ($datatable,$css_class);
5975: my $itemcount = 0;
5976: my %titles = &Apache::lonlocal::texthash (
5977: captcha => '"Forgot Password" CAPTCHA validation',
5978: link => 'Reset link expiration (hours)',
5979: case => 'Case-sensitive usernames/e-mail',
5980: prelink => 'Information required (form 1)',
5981: postlink => 'Information required (form 2)',
5982: emailsrc => 'LON-CAPA e-mail address type(s)',
5983: customtext => 'Domain specific text (HTML)',
5984: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5985: intauth_check => 'Check bcrypt cost if authenticated',
5986: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5987: permanent => 'Permanent e-mail address',
5988: critical => 'Critical notification address',
5989: notify => 'Notification address',
5990: min => 'Minimum password length',
5991: max => 'Maximum password length',
5992: chars => 'Required characters',
5993: expire => 'Password expiration (days)',
1.356 raeburn 5994: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 5995: );
5996: if ($position eq 'top') {
5997: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5998: my $shownlinklife = 2;
5999: my $prelink = 'both';
6000: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6001: if (ref($settings) eq 'HASH') {
6002: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6003: $shownlinklife = $settings->{resetlink};
6004: }
6005: if (ref($settings->{resetcase}) eq 'ARRAY') {
6006: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6007: }
6008: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6009: $prelink = $settings->{resetprelink};
6010: }
6011: if (ref($settings->{resetpostlink}) eq 'HASH') {
6012: %postlink = %{$settings->{resetpostlink}};
6013: }
6014: if (ref($settings->{resetemail}) eq 'ARRAY') {
6015: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6016: }
6017: if ($settings->{resetremove}) {
6018: $nostdtext = 1;
6019: }
6020: if ($settings->{resetcustom}) {
6021: $customurl = $settings->{resetcustom};
6022: }
6023: } else {
6024: if (ref($types) eq 'ARRAY') {
6025: foreach my $item (@{$types}) {
6026: $casesens{$item} = 1;
6027: $postlink{$item} = ['username','email'];
6028: }
6029: }
6030: $casesens{'default'} = 1;
6031: $postlink{'default'} = ['username','email'];
6032: $prelink = 'both';
6033: %emailsrc = (
6034: permanent => 1,
6035: critical => 1,
6036: notify => 1,
6037: );
6038: }
6039: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6040: $itemcount ++;
6041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6042: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6043: '<td class="LC_left_item">'.
6044: '<input type="textbox" value="'.$shownlinklife.'" '.
6045: 'name="passwords_link" size="3" /></td></tr>';
6046: $itemcount ++;
6047: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6048: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6049: '<td class="LC_left_item">';
6050: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6051: foreach my $item (@{$types}) {
6052: my $checkedcase;
6053: if ($casesens{$item}) {
6054: $checkedcase = ' checked="checked"';
6055: }
6056: $datatable .= '<span class="LC_nobreak"><label>'.
6057: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6058: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
6059: '<span> ';
6060: }
6061: }
6062: my $checkedcase;
6063: if ($casesens{'default'}) {
6064: $checkedcase = ' checked="checked"';
6065: }
6066: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6067: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6068: $othertitle.'</label></span></td>';
6069: $itemcount ++;
6070: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6071: my %checkedpre = (
6072: both => ' checked="checked"',
6073: either => '',
6074: );
6075: if ($prelink eq 'either') {
6076: $checkedpre{either} = ' checked="checked"';
6077: $checkedpre{both} = '';
6078: }
6079: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6080: '<td class="LC_left_item"><span class="LC_nobreak">'.
6081: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6082: &mt('Both username and e-mail address').'</label></span> '.
6083: '<span class="LC_nobreak"><label>'.
6084: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6085: &mt('Either username or e-mail address').'</label></span></td></tr>';
6086: $itemcount ++;
6087: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6088: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6089: '<td class="LC_left_item">';
6090: my %postlinked;
6091: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6092: foreach my $item (@{$types}) {
6093: undef(%postlinked);
6094: $datatable .= '<fieldset style="display: inline-block;">'.
6095: '<legend>'.$usertypes->{$item}.'</legend>';
6096: if (ref($postlink{$item}) eq 'ARRAY') {
6097: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6098: }
6099: foreach my $field ('email','username') {
6100: my $checked;
6101: if ($postlinked{$field}) {
6102: $checked = ' checked="checked"';
6103: }
6104: $datatable .= '<span class="LC_nobreak"><label>'.
6105: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6106: $field.'"'.$checked.' />'.$field.'</label>'.
6107: '<span> ';
6108: }
6109: $datatable .= '</fieldset>';
6110: }
6111: }
6112: if (ref($postlink{'default'}) eq 'ARRAY') {
6113: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6114: }
6115: $datatable .= '<fieldset style="display: inline-block;">'.
6116: '<legend>'.$othertitle.'</legend>';
6117: foreach my $field ('email','username') {
6118: my $checked;
6119: if ($postlinked{$field}) {
6120: $checked = ' checked="checked"';
6121: }
6122: $datatable .= '<span class="LC_nobreak"><label>'.
6123: '<input type="checkbox" name="passwords_postlink_default" value="'.
6124: $field.'"'.$checked.' />'.$field.'</label>'.
6125: '<span> ';
6126: }
6127: $datatable .= '</fieldset></td></tr>';
6128: $itemcount ++;
6129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6130: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6131: '<td class="LC_left_item">';
6132: foreach my $type ('permanent','critical','notify') {
6133: my $checkedemail;
6134: if ($emailsrc{$type}) {
6135: $checkedemail = ' checked="checked"';
6136: }
6137: $datatable .= '<span class="LC_nobreak"><label>'.
6138: '<input type="checkbox" name="passwords_emailsrc" value="'.
6139: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6140: '<span> ';
6141: }
6142: $datatable .= '</td></tr>';
6143: $itemcount ++;
6144: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6145: my $switchserver = &check_switchserver($dom,$confname);
6146: my ($showstd,$noshowstd);
6147: if ($nostdtext) {
6148: $noshowstd = ' checked="checked"';
6149: } else {
6150: $showstd = ' checked="checked"';
6151: }
6152: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6153: '<td class="LC_left_item"><span class="LC_nobreak">'.
6154: &mt('Retain standard text:').
6155: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6156: &mt('Yes').'</label>'.' '.
6157: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6158: &mt('No').'</label></span><br />'.
6159: '<span class="LC_fontsize_small">'.
6160: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6161: &mt('Include custom text:');
6162: if ($customurl) {
6163: my $link = &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
6164: undef,undef,undef,undef,'background-color:#ffffff');
6165: $datatable .= '<span class="LC_nobreak"> '.$link.
6166: '<label><input type="checkbox" name="passwords_custom_del"'.
6167: ' value="1" />'.&mt('Delete?').'</label></span>'.
6168: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6169: }
6170: if ($switchserver) {
6171: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6172: } else {
6173: $datatable .='<span class="LC_nobreak"> '.
6174: '<input type="file" name="passwords_customfile" /></span>';
6175: }
6176: $datatable .= '</td></tr>';
6177: } elsif ($position eq 'middle') {
6178: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6179: my @items = ('intauth_cost','intauth_check','intauth_switch');
6180: my %defaults;
6181: if (ref($domconf{'defaults'}) eq 'HASH') {
6182: %defaults = %{$domconf{'defaults'}};
6183: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6184: $defaults{'intauth_cost'} = 10;
6185: }
6186: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6187: $defaults{'intauth_check'} = 0;
6188: }
6189: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6190: $defaults{'intauth_switch'} = 0;
6191: }
6192: } else {
6193: %defaults = (
6194: 'intauth_cost' => 10,
6195: 'intauth_check' => 0,
6196: 'intauth_switch' => 0,
6197: );
6198: }
6199: foreach my $item (@items) {
6200: if ($itemcount%2) {
6201: $css_class = '';
6202: } else {
6203: $css_class = ' class="LC_odd_row" ';
6204: }
6205: $datatable .= '<tr'.$css_class.'>'.
6206: '<td><span class="LC_nobreak">'.$titles{$item}.
6207: '</span></td><td class="LC_left_item" colspan="3">';
6208: if ($item eq 'intauth_switch') {
6209: my @options = (0,1,2);
6210: my %optiondesc = &Apache::lonlocal::texthash (
6211: 0 => 'No',
6212: 1 => 'Yes',
6213: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6214: );
6215: $datatable .= '<table width="100%">';
6216: foreach my $option (@options) {
6217: my $checked = ' ';
6218: if ($defaults{$item} eq $option) {
6219: $checked = ' checked="checked"';
6220: }
6221: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6222: '<label><input type="radio" name="'.$item.
6223: '" value="'.$option.'"'.$checked.' />'.
6224: $optiondesc{$option}.'</label></span></td></tr>';
6225: }
6226: $datatable .= '</table>';
6227: } elsif ($item eq 'intauth_check') {
6228: my @options = (0,1,2);
6229: my %optiondesc = &Apache::lonlocal::texthash (
6230: 0 => 'No',
6231: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6232: 2 => 'Yes, disallow login if stored cost is less than domain default',
6233: );
6234: $datatable .= '<table width="100%">';
6235: foreach my $option (@options) {
6236: my $checked = ' ';
6237: my $onclick;
6238: if ($defaults{$item} eq $option) {
6239: $checked = ' checked="checked"';
6240: }
6241: if ($option == 2) {
6242: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6243: }
6244: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6245: '<label><input type="radio" name="'.$item.
6246: '" value="'.$option.'"'.$checked.$onclick.' />'.
6247: $optiondesc{$option}.'</label></span></td></tr>';
6248: }
6249: $datatable .= '</table>';
6250: } else {
6251: $datatable .= '<input type="text" name="'.$item.'" value="'.
6252: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6253: }
6254: $datatable .= '</td></tr>';
6255: $itemcount ++;
6256: }
6257: } elsif ($position eq 'lower') {
1.356 raeburn 6258: my ($min,$max,%chars,$expire,$numsaved);
1.365 raeburn 6259: $min = $Apache::lonnet::passwdmin;
1.354 raeburn 6260: if (ref($settings) eq 'HASH') {
6261: if ($settings->{min}) {
6262: $min = $settings->{min};
6263: }
6264: if ($settings->{max}) {
6265: $max = $settings->{max};
6266: }
6267: if (ref($settings->{chars}) eq 'ARRAY') {
6268: map { $chars{$_} = 1; } (@{$settings->{chars}});
6269: }
6270: if ($settings->{expire}) {
6271: $expire = $settings->{expire};
6272: }
1.358 raeburn 6273: if ($settings->{numsaved}) {
6274: $numsaved = $settings->{numsaved};
1.356 raeburn 6275: }
1.354 raeburn 6276: }
6277: my %rulenames = &Apache::lonlocal::texthash(
6278: uc => 'At least one upper case letter',
6279: lc => 'At least one lower case letter',
6280: num => 'At least one number',
6281: spec => 'At least one non-alphanumeric',
6282: );
6283: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6284: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6285: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 6286: '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
6287: 'onblur="javascript:warnIntPass(this);" />'.
6288: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354 raeburn 6289: '</span></td></tr>';
6290: $itemcount ++;
6291: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6292: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6293: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 6294: '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
6295: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 6296: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6297: '</span></td></tr>';
6298: $itemcount ++;
6299: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6300: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6301: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6302: '</span></td>';
6303: my $numinrow = 2;
6304: my @possrules = ('uc','lc','num','spec');
6305: $datatable .= '<td class="LC_left_item"><table>';
6306: for (my $i=0; $i<@possrules; $i++) {
6307: my ($rem,$checked);
6308: if ($chars{$possrules[$i]}) {
6309: $checked = ' checked="checked"';
6310: }
6311: $rem = $i%($numinrow);
6312: if ($rem == 0) {
6313: if ($i > 0) {
6314: $datatable .= '</tr>';
6315: }
6316: $datatable .= '<tr>';
6317: }
6318: $datatable .= '<td><span class="LC_nobreak"><label>'.
6319: '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6320: $rulenames{$possrules[$i]}.'</label></span></td>';
6321: }
6322: my $rem = @possrules%($numinrow);
6323: my $colsleft = $numinrow - $rem;
6324: if ($colsleft > 1 ) {
6325: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6326: ' </td>';
6327: } elsif ($colsleft == 1) {
6328: $datatable .= '<td class="LC_left_item"> </td>';
6329: }
6330: $datatable .='</table></td></tr>';
6331: $itemcount ++;
6332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6333: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
6334: '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365 raeburn 6335: '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
6336: 'onblur="javascript:warnIntPass(this);" />'.
1.354 raeburn 6337: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
6338: '</span></td></tr>';
1.356 raeburn 6339: $itemcount ++;
6340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6341: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6342: '<td class="LC_left_item"><span class="LC_nobreak">'.
6343: '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
6344: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6345: '</span></td></tr>';
1.354 raeburn 6346: } else {
1.359 raeburn 6347: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6348: my %ownerchg = (
6349: by => {},
6350: for => {},
6351: );
6352: my %ownertitles = &Apache::lonlocal::texthash (
6353: by => 'Course owner status(es) allowed',
6354: for => 'Student status(es) allowed',
6355: );
1.354 raeburn 6356: if (ref($settings) eq 'HASH') {
1.359 raeburn 6357: if (ref($settings->{crsownerchg}) eq 'HASH') {
6358: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6359: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6360: }
6361: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6362: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6363: }
1.354 raeburn 6364: }
6365: }
6366: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6367: $datatable .= '<tr '.$css_class.'>'.
6368: '<td>'.
6369: &mt('Requirements').'<ul>'.
1.359 raeburn 6370: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 6371: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6372: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 6373: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 6374: '</ul>'.
6375: '</td>'.
1.359 raeburn 6376: '<td class="LC_left_item">';
6377: foreach my $item ('by','for') {
6378: $datatable .= '<fieldset style="display: inline-block;">'.
6379: '<legend>'.$ownertitles{$item}.'</legend>';
6380: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6381: foreach my $type (@{$types}) {
6382: my $checked;
6383: if ($ownerchg{$item}{$type}) {
6384: $checked = ' checked="checked"';
6385: }
6386: $datatable .= '<span class="LC_nobreak"><label>'.
6387: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6388: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
6389: '<span> ';
6390: }
6391: }
6392: my $checked;
6393: if ($ownerchg{$item}{'default'}) {
6394: $checked = ' checked="checked"';
6395: }
6396: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6397: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6398: $othertitle.'</label></span></fieldset>';
6399: }
6400: $datatable .= '</td></tr>';
1.354 raeburn 6401: }
6402: return $datatable;
6403: }
6404:
1.137 raeburn 6405: sub print_usersessions {
6406: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 6407: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 6408: my (%by_ip,%by_location,@intdoms,@instdoms);
6409: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 6410:
6411: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6412: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6413: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6414: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6415: if ($position eq 'top') {
1.152 raeburn 6416: if (keys(%serverhomes) > 1) {
1.145 raeburn 6417: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 6418: my $curroffloadnow;
6419: if (ref($settings) eq 'HASH') {
6420: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6421: $curroffloadnow = $settings->{'offloadnow'};
6422: }
6423: }
6424: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 6425: } else {
1.140 raeburn 6426: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 6427: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
6428: '</td></tr>';
1.140 raeburn 6429: }
1.137 raeburn 6430: } else {
1.279 raeburn 6431: my %titles = &usersession_titles();
6432: my ($prefix,@types);
6433: if ($position eq 'bottom') {
6434: $prefix = 'remote';
6435: @types = ('version','excludedomain','includedomain');
1.145 raeburn 6436: } else {
1.279 raeburn 6437: $prefix = 'hosted';
6438: @types = ('excludedomain','includedomain');
6439: }
6440: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6441: }
6442: $$rowtotal += $itemcount;
6443: return $datatable;
6444: }
6445:
6446: sub rules_by_location {
6447: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
6448: my ($datatable,$itemcount,$css_class);
6449: if (keys(%{$by_location}) == 0) {
6450: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6451: $datatable = '<tr'.$css_class.'><td colspan="2">'.
6452: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
6453: '</td></tr>';
6454: $itemcount = 1;
6455: } else {
6456: $itemcount = 0;
6457: my $numinrow = 5;
6458: my (%current,%checkedon,%checkedoff);
6459: my @locations = sort(keys(%{$by_location}));
6460: foreach my $type (@{$types}) {
6461: $checkedon{$type} = '';
6462: $checkedoff{$type} = ' checked="checked"';
6463: }
6464: if (ref($settings) eq 'HASH') {
6465: if (ref($settings->{$prefix}) eq 'HASH') {
6466: foreach my $key (keys(%{$settings->{$prefix}})) {
6467: $current{$key} = $settings->{$prefix}{$key};
6468: if ($key eq 'version') {
6469: if ($current{$key} ne '') {
1.145 raeburn 6470: $checkedon{$key} = ' checked="checked"';
6471: $checkedoff{$key} = '';
6472: }
1.279 raeburn 6473: } elsif (ref($current{$key}) eq 'ARRAY') {
6474: $checkedon{$key} = ' checked="checked"';
6475: $checkedoff{$key} = '';
1.137 raeburn 6476: }
6477: }
6478: }
1.279 raeburn 6479: }
6480: foreach my $type (@{$types}) {
6481: next if ($type ne 'version' && !@locations);
6482: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6483: $datatable .= '<tr'.$css_class.'>
6484: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
6485: <span class="LC_nobreak">
6486: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6487: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6488: if ($type eq 'version') {
6489: my @lcversions = &Apache::lonnet::all_loncaparevs();
6490: my $selector = '<select name="'.$prefix.'_version">';
6491: foreach my $version (@lcversions) {
6492: my $selected = '';
6493: if ($current{'version'} eq $version) {
6494: $selected = ' selected="selected"';
1.145 raeburn 6495: }
1.279 raeburn 6496: $selector .= ' <option value="'.$version.'"'.
6497: $selected.'>'.$version.'</option>';
6498: }
6499: $selector .= '</select> ';
6500: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6501: } else {
6502: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6503: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6504: ' />'.(' 'x2).
6505: '<input type="button" value="'.&mt('uncheck all').'" '.
6506: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6507: "\n".
6508: '</div><div><table>';
6509: my $rem;
6510: for (my $i=0; $i<@locations; $i++) {
6511: my ($showloc,$value,$checkedtype);
6512: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
6513: my $ip = $by_location->{$locations[$i]}->[0];
6514: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6515: $value = join(':',@{$by_ip->{$ip}});
6516: $showloc = join(', ',@{$by_ip->{$ip}});
6517: if (ref($current{$type}) eq 'ARRAY') {
6518: foreach my $loc (@{$by_ip->{$ip}}) {
6519: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6520: $checkedtype = ' checked="checked"';
6521: last;
1.145 raeburn 6522: }
1.138 raeburn 6523: }
6524: }
6525: }
1.137 raeburn 6526: }
1.279 raeburn 6527: $rem = $i%($numinrow);
6528: if ($rem == 0) {
6529: if ($i > 0) {
6530: $datatable .= '</tr>';
6531: }
6532: $datatable .= '<tr>';
6533: }
6534: $datatable .= '<td class="LC_left_item">'.
6535: '<span class="LC_nobreak"><label>'.
6536: '<input type="checkbox" name="'.$prefix.'_'.$type.
6537: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6538: '</label></span></td>';
6539: }
6540: $rem = @locations%($numinrow);
6541: my $colsleft = $numinrow - $rem;
6542: if ($colsleft > 1 ) {
6543: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6544: ' </td>';
6545: } elsif ($colsleft == 1) {
6546: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6547: }
1.279 raeburn 6548: $datatable .= '</tr></table>';
1.137 raeburn 6549: }
1.279 raeburn 6550: $datatable .= '</td></tr>';
6551: $itemcount ++;
1.137 raeburn 6552: }
6553: }
1.279 raeburn 6554: return ($datatable,$itemcount);
1.137 raeburn 6555: }
6556:
1.275 raeburn 6557: sub print_ssl {
6558: my ($position,$dom,$settings,$rowtotal) = @_;
6559: my ($css_class,$datatable);
6560: my $itemcount = 1;
6561: if ($position eq 'top') {
1.281 raeburn 6562: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6563: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6564: my $same_institution;
6565: if ($intdom ne '') {
6566: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
6567: if (ref($internet_names) eq 'ARRAY') {
6568: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
6569: $same_institution = 1;
6570: }
6571: }
6572: }
1.275 raeburn 6573: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 6574: $datatable = '<tr'.$css_class.'><td colspan="2">';
6575: if ($same_institution) {
6576: my %domservers = &Apache::lonnet::get_servers($dom);
6577: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
6578: } else {
6579: $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.");
6580: }
6581: $datatable .= '</td></tr>';
1.275 raeburn 6582: $itemcount ++;
6583: } else {
6584: my %titles = &ssl_titles();
6585: my (%by_ip,%by_location,@intdoms,@instdoms);
6586: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6587: my @alldoms = &Apache::lonnet::all_domains();
6588: my %serverhomes = %Apache::lonnet::serverhomeIDs;
6589: my @domservers = &Apache::lonnet::get_servers($dom);
6590: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6591: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 6592: if (($position eq 'connto') || ($position eq 'connfrom')) {
6593: my $legacy;
6594: unless (ref($settings) eq 'HASH') {
6595: my $name;
6596: if ($position eq 'connto') {
6597: $name = 'loncAllowInsecure';
6598: } else {
6599: $name = 'londAllowInsecure';
6600: }
6601: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
6602: my @ids=&Apache::lonnet::current_machine_ids();
6603: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
6604: my %what = (
6605: $name => 1,
6606: );
6607: my ($result,$returnhash) =
6608: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
6609: if ($result eq 'ok') {
6610: if (ref($returnhash) eq 'HASH') {
6611: $legacy = $returnhash->{$name};
6612: }
6613: }
6614: } else {
6615: $legacy = $Apache::lonnet::perlvar{$name};
6616: }
6617: }
1.275 raeburn 6618: foreach my $type ('dom','intdom','other') {
6619: my %checked;
6620: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6621: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
6622: '<td class="LC_right_item">';
6623: my $skip;
6624: if ($type eq 'dom') {
6625: unless (keys(%servers) > 1) {
6626: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
6627: $skip = 1;
6628: }
6629: }
6630: if ($type eq 'intdom') {
6631: unless (@instdoms > 1) {
6632: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
6633: $skip = 1;
6634: }
6635: } elsif ($type eq 'other') {
6636: if (keys(%by_location) == 0) {
6637: $datatable .= &mt('Nothing to set here, as there are no other institutions');
6638: $skip = 1;
6639: }
6640: }
6641: unless ($skip) {
6642: $checked{'yes'} = ' checked="checked"';
6643: if (ref($settings) eq 'HASH') {
1.293 raeburn 6644: if (ref($settings->{$position}) eq 'HASH') {
6645: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 6646: $checked{$1} = $checked{'yes'};
6647: delete($checked{'yes'});
6648: }
6649: }
1.293 raeburn 6650: } else {
6651: if ($legacy == 0) {
6652: $checked{'req'} = $checked{'yes'};
6653: delete($checked{'yes'});
6654: }
1.275 raeburn 6655: }
6656: foreach my $option ('no','yes','req') {
6657: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 6658: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 6659: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
6660: '</label></span>'.(' 'x2);
6661: }
6662: }
6663: $datatable .= '</td></tr>';
6664: $itemcount ++;
6665: }
6666: } else {
6667: my $prefix = 'replication';
6668: my @types = ('certreq','nocertreq');
1.279 raeburn 6669: if (keys(%by_location) == 0) {
6670: $datatable .= '<tr'.$css_class.'><td>'.
6671: &mt('Nothing to set here, as there are no other institutions').
6672: '</td></tr>';
6673: $itemcount ++;
1.275 raeburn 6674: } else {
1.279 raeburn 6675: ($datatable,$itemcount) =
6676: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 6677: }
6678: }
6679: }
6680: $$rowtotal += $itemcount;
6681: return $datatable;
6682: }
6683:
6684: sub ssl_titles {
6685: return &Apache::lonlocal::texthash (
6686: dom => 'LON-CAPA servers/VMs from same domain',
6687: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
6688: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 6689: connto => 'Connections to other servers',
6690: connfrom => 'Connections from other servers',
1.275 raeburn 6691: replication => 'Replicating content to other institutions',
6692: certreq => 'Client certificate required, but specific domains exempt',
6693: nocertreq => 'No client certificate required, except for specific domains',
6694: no => 'SSL not used',
6695: yes => 'SSL Optional (used if available)',
6696: req => 'SSL Required',
6697: );
1.279 raeburn 6698: }
6699:
6700: sub print_trust {
6701: my ($prefix,$dom,$settings,$rowtotal) = @_;
6702: my ($css_class,$datatable,%checked,%choices);
6703: my (%by_ip,%by_location,@intdoms,@instdoms);
6704: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
6705: my $itemcount = 1;
6706: my %titles = &trust_titles();
6707: my @types = ('exc','inc');
6708: if ($prefix eq 'top') {
6709: $prefix = 'content';
6710: } elsif ($prefix eq 'bottom') {
6711: $prefix = 'msg';
6712: }
6713: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
6714: $$rowtotal += $itemcount;
6715: return $datatable;
6716: }
6717:
6718: sub trust_titles {
6719: return &Apache::lonlocal::texthash(
6720: content => "Access to this domain's content by others",
6721: shared => "Access to other domain's content by this domain",
6722: enroll => "Enrollment in this domain's courses by others",
6723: othcoau => "Co-author roles in this domain for others",
6724: coaurem => "Co-author roles for this domain's users elsewhere",
6725: domroles => "Domain roles in this domain assignable to others",
6726: catalog => "Course Catalog for this domain displayed elsewhere",
6727: reqcrs => "Requests for creation of courses in this domain by others",
6728: msg => "Users in other domains can send messages to this domain",
6729: exc => "Allow all, but exclude specific domains",
6730: inc => "Deny all, but include specific domains",
6731: );
1.275 raeburn 6732: }
6733:
1.138 raeburn 6734: sub build_location_hashes {
1.275 raeburn 6735: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 6736: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 6737: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 6738: my %iphost = &Apache::lonnet::get_iphost();
6739: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6740: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6741: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6742: foreach my $id (@{$iphost{$primary_ip}}) {
6743: my $intdom = &Apache::lonnet::internet_dom($id);
6744: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6745: push(@{$intdoms},$intdom);
6746: }
6747: }
6748: }
6749: foreach my $ip (keys(%iphost)) {
6750: if (ref($iphost{$ip}) eq 'ARRAY') {
6751: foreach my $id (@{$iphost{$ip}}) {
6752: my $location = &Apache::lonnet::internet_dom($id);
6753: if ($location) {
1.275 raeburn 6754: if (grep(/^\Q$location\E$/,@{$intdoms})) {
6755: my $dom = &Apache::lonnet::host_domain($id);
6756: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
6757: push(@{$instdoms},$dom);
6758: }
6759: next;
6760: }
1.138 raeburn 6761: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6762: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6763: push(@{$by_ip->{$ip}},$location);
6764: }
6765: } else {
6766: $by_ip->{$ip} = [$location];
6767: }
6768: }
6769: }
6770: }
6771: }
6772: foreach my $ip (sort(keys(%{$by_ip}))) {
6773: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6774: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6775: my $first = $by_ip->{$ip}->[0];
6776: if (ref($by_location->{$first}) eq 'ARRAY') {
6777: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6778: push(@{$by_location->{$first}},$ip);
6779: }
6780: } else {
6781: $by_location->{$first} = [$ip];
6782: }
6783: }
6784: }
6785: return;
6786: }
6787:
1.145 raeburn 6788: sub current_offloads_to {
6789: my ($dom,$settings,$servers) = @_;
6790: my (%spareid,%otherdomconfigs);
1.152 raeburn 6791: if (ref($servers) eq 'HASH') {
1.145 raeburn 6792: foreach my $lonhost (sort(keys(%{$servers}))) {
6793: my $gotspares;
1.152 raeburn 6794: if (ref($settings) eq 'HASH') {
6795: if (ref($settings->{'spares'}) eq 'HASH') {
6796: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6797: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6798: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6799: $gotspares = 1;
6800: }
1.145 raeburn 6801: }
6802: }
6803: unless ($gotspares) {
6804: my $gotspares;
6805: my $serverhomeID =
6806: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6807: my $serverhomedom =
6808: &Apache::lonnet::host_domain($serverhomeID);
6809: if ($serverhomedom ne $dom) {
6810: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6811: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6812: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6813: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6814: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6815: $gotspares = 1;
6816: }
6817: }
6818: } else {
6819: $otherdomconfigs{$serverhomedom} =
6820: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6821: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6822: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6823: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6824: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6825: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6826: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6827: $gotspares = 1;
6828: }
6829: }
6830: }
6831: }
6832: }
6833: }
6834: }
6835: unless ($gotspares) {
6836: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6837: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6838: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6839: } else {
6840: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6841: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6842: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6843: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6844: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6845: } else {
1.150 raeburn 6846: my %what = (
6847: spareid => 1,
6848: );
6849: my ($result,$returnhash) =
6850: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6851: if ($result eq 'ok') {
6852: if (ref($returnhash) eq 'HASH') {
6853: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6854: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6855: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6856: }
6857: }
1.145 raeburn 6858: }
6859: }
6860: }
6861: }
6862: }
6863: }
6864: return %spareid;
6865: }
6866:
6867: sub spares_row {
1.261 raeburn 6868: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 6869: my $css_class;
6870: my $numinrow = 4;
6871: my $itemcount = 1;
6872: my $datatable;
1.152 raeburn 6873: my %typetitles = &sparestype_titles();
6874: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6875: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6876: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6877: my ($othercontrol,$serverdom);
6878: if ($serverhome ne $server) {
6879: $serverdom = &Apache::lonnet::host_domain($serverhome);
6880: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6881: } else {
6882: $serverdom = &Apache::lonnet::host_domain($server);
6883: if ($serverdom ne $dom) {
6884: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6885: }
6886: }
6887: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 6888: my $checkednow;
6889: if (ref($curroffloadnow) eq 'HASH') {
6890: if ($curroffloadnow->{$server}) {
6891: $checkednow = ' checked="checked"';
6892: }
6893: }
1.145 raeburn 6894: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6895: $datatable .= '<tr'.$css_class.'>
6896: <td rowspan="2">
1.183 bisitz 6897: <span class="LC_nobreak">'.
6898: &mt('[_1] when busy, offloads to:'
1.261 raeburn 6899: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 6900: '<span class="LC_nobreak">'."\n".
1.261 raeburn 6901: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
6902: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 6903: "\n";
1.145 raeburn 6904: my (%current,%canselect);
1.152 raeburn 6905: my @choices =
6906: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6907: foreach my $type ('primary','default') {
6908: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6909: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6910: my @spares = @{$spareid->{$server}{$type}};
6911: if (@spares > 0) {
1.152 raeburn 6912: if ($othercontrol) {
6913: $current{$type} = join(', ',@spares);
6914: } else {
6915: $current{$type} .= '<table>';
6916: my $numspares = scalar(@spares);
6917: for (my $i=0; $i<@spares; $i++) {
6918: my $rem = $i%($numinrow);
6919: if ($rem == 0) {
6920: if ($i > 0) {
6921: $current{$type} .= '</tr>';
6922: }
6923: $current{$type} .= '<tr>';
1.145 raeburn 6924: }
1.152 raeburn 6925: $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'".');" /> '.
6926: $spareid->{$server}{$type}[$i].
6927: '</label></td>'."\n";
6928: }
6929: my $rem = @spares%($numinrow);
6930: my $colsleft = $numinrow - $rem;
6931: if ($colsleft > 1 ) {
6932: $current{$type} .= '<td colspan="'.$colsleft.
6933: '" class="LC_left_item">'.
6934: ' </td>';
6935: } elsif ($colsleft == 1) {
6936: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 6937: }
1.152 raeburn 6938: $current{$type} .= '</tr></table>';
1.150 raeburn 6939: }
1.145 raeburn 6940: }
6941: }
6942: if ($current{$type} eq '') {
6943: $current{$type} = &mt('None specified');
6944: }
1.152 raeburn 6945: if ($othercontrol) {
6946: if ($type eq 'primary') {
6947: $canselect{$type} = $othercontrol;
6948: }
6949: } else {
6950: $canselect{$type} =
6951: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
6952: '<select name="newspare_'.$type.'_'.$server.'" '.
6953: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
6954: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
6955: if (@choices > 0) {
6956: foreach my $lonhost (@choices) {
6957: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
6958: }
6959: }
6960: $canselect{$type} .= '</select>'."\n";
6961: }
6962: } else {
6963: $current{$type} = &mt('Could not be determined');
6964: if ($type eq 'primary') {
6965: $canselect{$type} = $othercontrol;
6966: }
1.145 raeburn 6967: }
1.152 raeburn 6968: if ($type eq 'default') {
6969: $datatable .= '<tr'.$css_class.'>';
6970: }
6971: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
6972: '<td>'.$current{$type}.'</td>'."\n".
6973: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 6974: }
6975: $itemcount ++;
6976: }
6977: }
6978: $$rowtotal += $itemcount;
6979: return $datatable;
6980: }
6981:
1.152 raeburn 6982: sub possible_newspares {
6983: my ($server,$currspares,$serverhomes,$altids) = @_;
6984: my $serverhostname = &Apache::lonnet::hostname($server);
6985: my %excluded;
6986: if ($serverhostname ne '') {
6987: %excluded = (
6988: $serverhostname => 1,
6989: );
6990: }
6991: if (ref($currspares) eq 'HASH') {
6992: foreach my $type (keys(%{$currspares})) {
6993: if (ref($currspares->{$type}) eq 'ARRAY') {
6994: if (@{$currspares->{$type}} > 0) {
6995: foreach my $curr (@{$currspares->{$type}}) {
6996: my $hostname = &Apache::lonnet::hostname($curr);
6997: $excluded{$hostname} = 1;
6998: }
6999: }
7000: }
7001: }
7002: }
7003: my @choices;
7004: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7005: if (keys(%{$serverhomes}) > 1) {
7006: foreach my $name (sort(keys(%{$serverhomes}))) {
7007: unless ($excluded{$name}) {
7008: if (exists($altids->{$serverhomes->{$name}})) {
7009: push(@choices,$altids->{$serverhomes->{$name}});
7010: } else {
7011: push(@choices,$serverhomes->{$name});
1.145 raeburn 7012: }
7013: }
7014: }
7015: }
7016: }
1.152 raeburn 7017: return sort(@choices);
1.145 raeburn 7018: }
7019:
1.150 raeburn 7020: sub print_loadbalancing {
7021: my ($dom,$settings,$rowtotal) = @_;
7022: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7023: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7024: my $numinrow = 1;
7025: my $datatable;
7026: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 7027: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 7028: if (ref($settings) eq 'HASH') {
7029: %existing = %{$settings};
7030: }
7031: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7032: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 7033: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7034: } else {
7035: return;
7036: }
7037: my ($othertitle,$usertypes,$types) =
7038: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 7039: my $rownum = 8;
1.150 raeburn 7040: if (ref($types) eq 'ARRAY') {
7041: $rownum += scalar(@{$types});
7042: }
1.171 raeburn 7043: my @css_class = ('LC_odd_row','LC_even_row');
7044: my $balnum = 0;
7045: my $islast;
7046: my (@toshow,$disabledtext);
7047: if (keys(%currbalancer) > 0) {
7048: @toshow = sort(keys(%currbalancer));
7049: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7050: push(@toshow,'');
7051: }
7052: } else {
7053: @toshow = ('');
7054: $disabledtext = &mt('No existing load balancer');
7055: }
7056: foreach my $lonhost (@toshow) {
7057: if ($balnum == scalar(@toshow)-1) {
7058: $islast = 1;
7059: } else {
7060: $islast = 0;
7061: }
7062: my $cssidx = $balnum%2;
7063: my $targets_div_style = 'display: none';
7064: my $disabled_div_style = 'display: block';
7065: my $homedom_div_style = 'display: none';
7066: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 7067: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7068: '<p>';
7069: if ($lonhost eq '') {
1.210 raeburn 7070: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 7071: if (keys(%currbalancer) > 0) {
7072: $datatable .= &mt('Add balancer:');
7073: } else {
7074: $datatable .= &mt('Enable balancer:');
7075: }
7076: $datatable .= ' '.
7077: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7078: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7079: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7080: '<option value="" selected="selected">'.&mt('None').
7081: '</option>'."\n";
7082: foreach my $server (sort(keys(%servers))) {
7083: next if ($currbalancer{$server});
7084: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7085: }
1.210 raeburn 7086: $datatable .=
1.171 raeburn 7087: '</select>'."\n".
7088: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7089: } else {
7090: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7091: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7092: &mt('Stop balancing').'</label>'.
7093: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7094: $targets_div_style = 'display: block';
7095: $disabled_div_style = 'display: none';
7096: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7097: $homedom_div_style = 'display: block';
7098: }
7099: }
1.306 raeburn 7100: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 7101: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7102: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7103: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7104: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7105: my @sparestypes = ('primary','default');
7106: my %typetitles = &sparestype_titles();
1.284 raeburn 7107: my %hostherechecked = (
7108: no => ' checked="checked"',
7109: );
1.342 raeburn 7110: my %balcookiechecked = (
7111: no => ' checked="checked"',
7112: );
1.171 raeburn 7113: foreach my $sparetype (@sparestypes) {
7114: my $targettable;
7115: for (my $i=0; $i<$numspares; $i++) {
7116: my $checked;
7117: if (ref($currtargets{$lonhost}) eq 'HASH') {
7118: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7119: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7120: $checked = ' checked="checked"';
7121: }
7122: }
7123: }
7124: my ($chkboxval,$disabled);
7125: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7126: $chkboxval = $spares[$i];
7127: }
7128: if (exists($currbalancer{$spares[$i]})) {
7129: $disabled = ' disabled="disabled"';
7130: }
1.210 raeburn 7131: $targettable .=
1.253 raeburn 7132: '<td><span class="LC_nobreak"><label>'.
7133: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 7134: $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 7135: '</span></label></span></td>';
1.171 raeburn 7136: my $rem = $i%($numinrow);
7137: if ($rem == 0) {
7138: if (($i > 0) && ($i < $numspares-1)) {
7139: $targettable .= '</tr>';
7140: }
7141: if ($i < $numspares-1) {
7142: $targettable .= '<tr>';
1.150 raeburn 7143: }
7144: }
7145: }
1.171 raeburn 7146: if ($targettable ne '') {
7147: my $rem = $numspares%($numinrow);
7148: my $colsleft = $numinrow - $rem;
7149: if ($colsleft > 1 ) {
7150: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7151: ' </td>';
7152: } elsif ($colsleft == 1) {
7153: $targettable .= '<td class="LC_left_item"> </td>';
7154: }
7155: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7156: '<table><tr>'.$targettable.'</tr></table><br />';
7157: }
1.284 raeburn 7158: $hostherechecked{$sparetype} = '';
7159: if (ref($currtargets{$lonhost}) eq 'HASH') {
7160: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7161: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7162: $hostherechecked{$sparetype} = ' checked="checked"';
7163: $hostherechecked{'no'} = '';
7164: }
7165: }
7166: }
7167: }
1.342 raeburn 7168: if ($currcookies{$lonhost}) {
7169: %balcookiechecked = (
7170: yes => ' checked="checked"',
7171: );
7172: }
1.284 raeburn 7173: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7174: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7175: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7176: foreach my $sparetype (@sparestypes) {
7177: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7178: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7179: '</i></label><br />';
1.171 raeburn 7180: }
1.342 raeburn 7181: $datatable .= &mt('Use balancer cookie').'<br />'.
7182: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7183: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7184: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7185: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7186: '</div></td></tr>'.
1.171 raeburn 7187: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7188: $othertitle,$usertypes,$types,\%servers,
7189: \%currbalancer,$lonhost,
7190: $targets_div_style,$homedom_div_style,
7191: $css_class[$cssidx],$balnum,$islast);
7192: $$rowtotal += $rownum;
7193: $balnum ++;
7194: }
7195: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7196: return $datatable;
7197: }
7198:
7199: sub get_loadbalancers_config {
1.342 raeburn 7200: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 7201: return unless ((ref($servers) eq 'HASH') &&
7202: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 7203: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7204: (ref($currcookies) eq 'HASH'));
1.171 raeburn 7205: if (keys(%{$existing}) > 0) {
7206: my $oldlonhost;
7207: foreach my $key (sort(keys(%{$existing}))) {
7208: if ($key eq 'lonhost') {
7209: $oldlonhost = $existing->{'lonhost'};
7210: $currbalancer->{$oldlonhost} = 1;
7211: } elsif ($key eq 'targets') {
7212: if ($oldlonhost) {
7213: $currtargets->{$oldlonhost} = $existing->{'targets'};
7214: }
7215: } elsif ($key eq 'rules') {
7216: if ($oldlonhost) {
7217: $currrules->{$oldlonhost} = $existing->{'rules'};
7218: }
7219: } elsif (ref($existing->{$key}) eq 'HASH') {
7220: $currbalancer->{$key} = 1;
7221: $currtargets->{$key} = $existing->{$key}{'targets'};
7222: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 7223: if ($existing->{$key}{'cookie'}) {
7224: $currcookies->{$key} = 1;
7225: }
1.150 raeburn 7226: }
7227: }
1.171 raeburn 7228: } else {
7229: my ($balancerref,$targetsref) =
7230: &Apache::lonnet::get_lonbalancer_config($servers);
7231: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7232: foreach my $server (sort(keys(%{$balancerref}))) {
7233: $currbalancer->{$server} = 1;
7234: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7235: }
7236: }
7237: }
1.171 raeburn 7238: return;
1.150 raeburn 7239: }
7240:
7241: sub loadbalancing_rules {
7242: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 7243: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7244: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7245: my $output;
1.171 raeburn 7246: my $num = 0;
1.210 raeburn 7247: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7248: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7249: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7250: foreach my $type (@{$alltypes}) {
1.171 raeburn 7251: $num ++;
1.150 raeburn 7252: my $current;
7253: if (ref($currrules) eq 'HASH') {
7254: $current = $currrules->{$type};
7255: }
1.253 raeburn 7256: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 7257: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7258: $current = '';
7259: }
7260: }
7261: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 7262: $servers,$currbalancer,$lonhost,$dom,
7263: $targets_div_style,$homedom_div_style,
7264: $css_class,$balnum,$num,$islast);
1.150 raeburn 7265: }
7266: }
7267: return $output;
7268: }
7269:
7270: sub loadbalancing_titles {
7271: my ($dom,$intdom,$usertypes,$types) = @_;
7272: my %othertypes = (
7273: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7274: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7275: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7276: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 7277: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7278: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7279: );
1.209 raeburn 7280: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 7281: my @available;
1.150 raeburn 7282: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7283: @available = @{$types};
1.150 raeburn 7284: }
1.302 raeburn 7285: unless (grep(/^default$/,@available)) {
7286: push(@available,'default');
7287: }
7288: unshift(@alltypes,@available);
1.150 raeburn 7289: my %titles;
7290: foreach my $type (@alltypes) {
7291: if ($type =~ /^_LC_/) {
7292: $titles{$type} = $othertypes{$type};
7293: } elsif ($type eq 'default') {
7294: $titles{$type} = &mt('All users from [_1]',$dom);
7295: if (ref($types) eq 'ARRAY') {
7296: if (@{$types} > 0) {
7297: $titles{$type} = &mt('Other users from [_1]',$dom);
7298: }
7299: }
7300: } elsif (ref($usertypes) eq 'HASH') {
7301: $titles{$type} = $usertypes->{$type};
7302: }
7303: }
7304: return (\@alltypes,\%othertypes,\%titles);
7305: }
7306:
7307: sub loadbalance_rule_row {
1.171 raeburn 7308: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7309: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 7310: my @rulenames;
1.150 raeburn 7311: my %ruletitles = &offloadtype_text();
1.209 raeburn 7312: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 7313: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7314: } else {
1.209 raeburn 7315: @rulenames = ('default','homeserver');
7316: if ($type eq '_LC_external') {
7317: push(@rulenames,'externalbalancer');
7318: } else {
7319: push(@rulenames,'specific');
7320: }
7321: push(@rulenames,'none');
1.150 raeburn 7322: }
7323: my $style = $targets_div_style;
1.253 raeburn 7324: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7325: $style = $homedom_div_style;
7326: }
1.171 raeburn 7327: my $space;
7328: if ($islast && $num == 1) {
1.317 raeburn 7329: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 7330: }
1.210 raeburn 7331: my $output =
1.306 raeburn 7332: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 7333: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7334: '<td valaign="top">'.$space.
7335: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7336: for (my $i=0; $i<@rulenames; $i++) {
7337: my $rule = $rulenames[$i];
7338: my ($checked,$extra);
7339: if ($rulenames[$i] eq 'default') {
7340: $rule = '';
7341: }
7342: if ($rulenames[$i] eq 'specific') {
7343: if (ref($servers) eq 'HASH') {
7344: my $default;
7345: if (($current ne '') && (exists($servers->{$current}))) {
7346: $checked = ' checked="checked"';
7347: }
7348: unless ($checked) {
7349: $default = ' selected="selected"';
7350: }
1.210 raeburn 7351: $extra =
1.171 raeburn 7352: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7353: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7354: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7355: '<option value=""'.$default.'></option>'."\n";
7356: foreach my $server (sort(keys(%{$servers}))) {
7357: if (ref($currbalancer) eq 'HASH') {
7358: next if (exists($currbalancer->{$server}));
7359: }
1.150 raeburn 7360: my $selected;
1.171 raeburn 7361: if ($server eq $current) {
1.150 raeburn 7362: $selected = ' selected="selected"';
7363: }
1.171 raeburn 7364: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7365: }
7366: $extra .= '</select>';
7367: }
7368: } elsif ($rule eq $current) {
7369: $checked = ' checked="checked"';
7370: }
7371: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 7372: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7373: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7374: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 7375: ')"'.$checked.' /> ';
7376: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
7377: $output .= $ruletitles{'particular'};
7378: } else {
7379: $output .= $ruletitles{$rulenames[$i]};
7380: }
7381: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7382: }
7383: $output .= '</div></td></tr>'."\n";
7384: return $output;
7385: }
7386:
7387: sub offloadtype_text {
7388: my %ruletitles = &Apache::lonlocal::texthash (
7389: 'default' => 'Offloads to default destinations',
7390: 'homeserver' => "Offloads to user's home server",
7391: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7392: 'specific' => 'Offloads to specific server',
1.161 raeburn 7393: 'none' => 'No offload',
1.209 raeburn 7394: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7395: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 7396: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7397: );
7398: return %ruletitles;
7399: }
7400:
7401: sub sparestype_titles {
7402: my %typestitles = &Apache::lonlocal::texthash (
7403: 'primary' => 'primary',
7404: 'default' => 'default',
7405: );
7406: return %typestitles;
7407: }
7408:
1.28 raeburn 7409: sub contact_titles {
7410: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 7411: 'supportemail' => 'Support E-mail address',
7412: 'adminemail' => 'Default Server Admin E-mail address',
7413: 'errormail' => 'Error reports to be e-mailed to',
7414: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 7415: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7416: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 7417: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7418: 'requestsmail' => 'E-mail from course requests requiring approval',
7419: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 7420: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 7421: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.340 raeburn 7422: 'errorthreshold' => 'Error/warning threshold for status e-mail',
7423: 'errorsysmail' => 'Error threshold for e-mail to core group',
7424: 'errorweights' => 'Weights used to compute error count',
7425: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7426: );
7427: my %short_titles = &Apache::lonlocal::texthash (
7428: adminemail => 'Admin E-mail address',
7429: supportemail => 'Support E-mail',
7430: );
7431: return (\%titles,\%short_titles);
7432: }
7433:
1.286 raeburn 7434: sub helpform_fields {
7435: my %titles = &Apache::lonlocal::texthash (
7436: 'username' => 'Name',
7437: 'user' => 'Username/domain',
7438: 'phone' => 'Phone',
7439: 'cc' => 'Cc e-mail',
7440: 'course' => 'Course Details',
7441: 'section' => 'Sections',
1.289 raeburn 7442: 'screenshot' => 'File upload',
1.286 raeburn 7443: );
7444: my @fields = ('username','phone','user','course','section','cc','screenshot');
7445: my %possoptions = (
7446: username => ['yes','no','req'],
1.289 raeburn 7447: phone => ['yes','no','req'],
1.286 raeburn 7448: user => ['yes','no'],
1.289 raeburn 7449: cc => ['yes','no'],
1.286 raeburn 7450: course => ['yes','no'],
7451: section => ['yes','no'],
7452: screenshot => ['yes','no'],
7453: );
7454: my %fieldoptions = &Apache::lonlocal::texthash (
7455: 'yes' => 'Optional',
7456: 'req' => 'Required',
7457: 'no' => "Not shown",
7458: );
7459: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7460: }
7461:
1.72 raeburn 7462: sub tool_titles {
7463: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 7464: aboutme => 'Personal web page',
1.86 raeburn 7465: blog => 'Blog',
1.162 raeburn 7466: webdav => 'WebDAV',
1.86 raeburn 7467: portfolio => 'Portfolio',
1.88 bisitz 7468: official => 'Official courses (with institutional codes)',
7469: unofficial => 'Unofficial courses',
1.98 raeburn 7470: community => 'Communities',
1.216 raeburn 7471: textbook => 'Textbook courses',
1.271 raeburn 7472: placement => 'Placement tests',
1.86 raeburn 7473: );
1.72 raeburn 7474: return %titles;
7475: }
7476:
1.101 raeburn 7477: sub courserequest_titles {
7478: my %titles = &Apache::lonlocal::texthash (
7479: official => 'Official',
7480: unofficial => 'Unofficial',
7481: community => 'Communities',
1.216 raeburn 7482: textbook => 'Textbook',
1.271 raeburn 7483: placement => 'Placement tests',
1.325 raeburn 7484: lti => 'LTI Provider',
1.101 raeburn 7485: norequest => 'Not allowed',
1.325 raeburn 7486: approval => 'Approval by DC',
1.101 raeburn 7487: validate => 'With validation',
7488: autolimit => 'Numerical limit',
1.103 raeburn 7489: unlimited => '(blank for unlimited)',
1.101 raeburn 7490: );
7491: return %titles;
7492: }
7493:
1.163 raeburn 7494: sub authorrequest_titles {
7495: my %titles = &Apache::lonlocal::texthash (
7496: norequest => 'Not allowed',
7497: approval => 'Approval by Dom. Coord.',
7498: automatic => 'Automatic approval',
7499: );
7500: return %titles;
1.210 raeburn 7501: }
1.163 raeburn 7502:
1.101 raeburn 7503: sub courserequest_conditions {
7504: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7505: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 7506: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7507: );
7508: return %conditions;
7509: }
7510:
7511:
1.27 raeburn 7512: sub print_usercreation {
1.30 raeburn 7513: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7514: my $numinrow = 4;
1.28 raeburn 7515: my $datatable;
7516: if ($position eq 'top') {
1.30 raeburn 7517: $$rowtotal ++;
1.34 raeburn 7518: my $rowcount = 0;
1.32 raeburn 7519: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7520: if (ref($rules) eq 'HASH') {
7521: if (keys(%{$rules}) > 0) {
1.32 raeburn 7522: $datatable .= &user_formats_row('username',$settings,$rules,
7523: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7524: $$rowtotal ++;
1.32 raeburn 7525: $rowcount ++;
7526: }
7527: }
7528: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7529: if (ref($idrules) eq 'HASH') {
7530: if (keys(%{$idrules}) > 0) {
7531: $datatable .= &user_formats_row('id',$settings,$idrules,
7532: $idruleorder,$numinrow,$rowcount);
7533: $$rowtotal ++;
7534: $rowcount ++;
1.28 raeburn 7535: }
7536: }
1.39 raeburn 7537: if ($rowcount == 0) {
7538: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7539: $$rowtotal ++;
7540: $rowcount ++;
7541: }
1.34 raeburn 7542: } elsif ($position eq 'middle') {
1.224 raeburn 7543: my @creators = ('author','course','requestcrs');
1.37 raeburn 7544: my ($rules,$ruleorder) =
7545: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7546: my %lt = &usercreation_types();
7547: my %checked;
7548: if (ref($settings) eq 'HASH') {
7549: if (ref($settings->{'cancreate'}) eq 'HASH') {
7550: foreach my $item (@creators) {
7551: $checked{$item} = $settings->{'cancreate'}{$item};
7552: }
7553: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7554: foreach my $item (@creators) {
7555: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7556: $checked{$item} = 'none';
7557: }
7558: }
7559: }
7560: }
7561: my $rownum = 0;
7562: foreach my $item (@creators) {
7563: $rownum ++;
1.224 raeburn 7564: if ($checked{$item} eq '') {
7565: $checked{$item} = 'any';
1.34 raeburn 7566: }
7567: my $css_class;
7568: if ($rownum%2) {
7569: $css_class = '';
7570: } else {
7571: $css_class = ' class="LC_odd_row" ';
7572: }
7573: $datatable .= '<tr'.$css_class.'>'.
7574: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 7575: '</span></td><td style="text-align: right">';
1.224 raeburn 7576: my @options = ('any');
7577: if (ref($rules) eq 'HASH') {
7578: if (keys(%{$rules}) > 0) {
7579: push(@options,('official','unofficial'));
1.37 raeburn 7580: }
7581: }
1.224 raeburn 7582: push(@options,'none');
1.37 raeburn 7583: foreach my $option (@options) {
1.50 raeburn 7584: my $type = 'radio';
1.34 raeburn 7585: my $check = ' ';
1.224 raeburn 7586: if ($checked{$item} eq $option) {
7587: $check = ' checked="checked" ';
1.34 raeburn 7588: }
7589: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7590: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7591: $item.'" value="'.$option.'"'.$check.'/> '.
7592: $lt{$option}.'</label> </span>';
7593: }
7594: $datatable .= '</td></tr>';
7595: }
1.28 raeburn 7596: } else {
7597: my @contexts = ('author','course','domain');
1.325 raeburn 7598: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 7599: my %checked;
7600: if (ref($settings) eq 'HASH') {
7601: if (ref($settings->{'authtypes'}) eq 'HASH') {
7602: foreach my $item (@contexts) {
7603: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7604: foreach my $auth (@authtypes) {
7605: if ($settings->{'authtypes'}{$item}{$auth}) {
7606: $checked{$item}{$auth} = ' checked="checked" ';
7607: }
7608: }
7609: }
7610: }
1.27 raeburn 7611: }
1.35 raeburn 7612: } else {
7613: foreach my $item (@contexts) {
1.36 raeburn 7614: foreach my $auth (@authtypes) {
1.35 raeburn 7615: $checked{$item}{$auth} = ' checked="checked" ';
7616: }
7617: }
1.27 raeburn 7618: }
1.28 raeburn 7619: my %title = &context_names();
7620: my %authname = &authtype_names();
7621: my $rownum = 0;
7622: my $css_class;
7623: foreach my $item (@contexts) {
7624: if ($rownum%2) {
7625: $css_class = '';
7626: } else {
7627: $css_class = ' class="LC_odd_row" ';
7628: }
1.30 raeburn 7629: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7630: '<td>'.$title{$item}.
7631: '</td><td class="LC_left_item">'.
7632: '<span class="LC_nobreak">';
7633: foreach my $auth (@authtypes) {
7634: $datatable .= '<label>'.
7635: '<input type="checkbox" name="'.$item.'_auth" '.
7636: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7637: $authname{$auth}.'</label> ';
7638: }
7639: $datatable .= '</span></td></tr>';
7640: $rownum ++;
1.27 raeburn 7641: }
1.30 raeburn 7642: $$rowtotal += $rownum;
1.27 raeburn 7643: }
7644: return $datatable;
7645: }
7646:
1.224 raeburn 7647: sub print_selfcreation {
7648: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 7649: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7650: $emaildomain,$datatable);
1.224 raeburn 7651: if (ref($settings) eq 'HASH') {
7652: if (ref($settings->{'cancreate'}) eq 'HASH') {
7653: $createsettings = $settings->{'cancreate'};
1.236 raeburn 7654: if (ref($createsettings) eq 'HASH') {
7655: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7656: @selfcreate = @{$createsettings->{'selfcreate'}};
7657: } elsif ($createsettings->{'selfcreate'} ne '') {
7658: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7659: @selfcreate = ('email','login','sso');
7660: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7661: @selfcreate = ($createsettings->{'selfcreate'});
7662: }
7663: }
7664: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7665: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 7666: }
1.305 raeburn 7667: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7668: $emailoptions = $createsettings->{'emailoptions'};
7669: }
1.303 raeburn 7670: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7671: $emailverified = $createsettings->{'emailverified'};
7672: }
7673: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7674: $emaildomain = $createsettings->{'emaildomain'};
7675: }
1.224 raeburn 7676: }
7677: }
7678: }
7679: my %radiohash;
7680: my $numinrow = 4;
7681: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 7682: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 7683: if ($position eq 'top') {
7684: my %choices = &Apache::lonlocal::texthash (
7685: cancreate_login => 'Institutional Login',
7686: cancreate_sso => 'Institutional Single Sign On',
7687: );
7688: my @toggles = sort(keys(%choices));
7689: my %defaultchecked = (
7690: 'cancreate_login' => 'off',
7691: 'cancreate_sso' => 'off',
7692: );
1.228 raeburn 7693: my ($onclick,$itemcount);
1.224 raeburn 7694: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7695: \%choices,$itemcount,$onclick);
1.228 raeburn 7696: $$rowtotal += $itemcount;
7697:
1.224 raeburn 7698: if (ref($usertypes) eq 'HASH') {
7699: if (keys(%{$usertypes}) > 0) {
7700: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7701: $dom,$numinrow,$othertitle,
1.305 raeburn 7702: 'statustocreate',$rowtotal);
1.224 raeburn 7703: $$rowtotal ++;
7704: }
7705: }
1.240 raeburn 7706: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7707: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7708: $fieldtitles{'inststatus'} = &mt('Institutional status');
7709: my $rem;
7710: my $numperrow = 2;
7711: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7712: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 7713: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 7714: '<td class="LC_left_item">'."\n".
1.334 raeburn 7715: '<table>'."\n";
1.240 raeburn 7716: for (my $i=0; $i<@fields; $i++) {
7717: $rem = $i%($numperrow);
7718: if ($rem == 0) {
7719: if ($i > 0) {
7720: $datatable .= '</tr>';
7721: }
7722: $datatable .= '<tr>';
7723: }
7724: my $currval;
1.248 raeburn 7725: if (ref($createsettings) eq 'HASH') {
7726: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7727: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7728: }
1.240 raeburn 7729: }
7730: $datatable .= '<td class="LC_left_item">'.
7731: '<span class="LC_nobreak">'.
7732: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7733: 'value="'.$currval.'" size="10" /> '.
7734: $fieldtitles{$fields[$i]}.'</span></td>';
7735: }
7736: my $colsleft = $numperrow - $rem;
7737: if ($colsleft > 1 ) {
7738: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7739: ' </td>';
7740: } elsif ($colsleft == 1) {
7741: $datatable .= '<td class="LC_left_item"> </td>';
7742: }
7743: $datatable .= '</tr></table></td></tr>';
7744: $$rowtotal ++;
1.224 raeburn 7745: } elsif ($position eq 'middle') {
7746: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 7747: my @posstypes;
1.224 raeburn 7748: if (ref($types) eq 'ARRAY') {
1.302 raeburn 7749: @posstypes = @{$types};
7750: }
7751: unless (grep(/^default$/,@posstypes)) {
7752: push(@posstypes,'default');
7753: }
7754: my %usertypeshash;
7755: if (ref($usertypes) eq 'HASH') {
7756: %usertypeshash = %{$usertypes};
7757: }
7758: $usertypeshash{'default'} = $othertitle;
7759: foreach my $status (@posstypes) {
7760: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7761: $numinrow,$$rowtotal,\%usertypeshash);
7762: $$rowtotal ++;
1.224 raeburn 7763: }
7764: } else {
1.236 raeburn 7765: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 7766: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 7767: );
7768: my @toggles = sort(keys(%choices));
7769: my %defaultchecked = (
7770: 'cancreate_email' => 'off',
7771: );
1.305 raeburn 7772: my $customclass = 'LC_selfcreate_email';
7773: my $classprefix = 'LC_canmodify_emailusername_';
7774: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 7775: my $display = 'none';
1.305 raeburn 7776: my $rowstyle = 'display:none';
1.236 raeburn 7777: if (grep(/^\Qemail\E$/,@selfcreate)) {
7778: $display = 'block';
1.305 raeburn 7779: $rowstyle = 'display:table-row';
1.236 raeburn 7780: }
1.305 raeburn 7781: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7782: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7783: \%choices,$$rowtotal,$onclick);
7784: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7785: $rowstyle);
7786: $$rowtotal ++;
7787: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7788: $rowstyle);
7789: $$rowtotal ++;
7790: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 7791: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 7792: my ($emailrules,$emailruleorder) =
7793: &Apache::lonnet::inst_userrules($dom,'email');
7794: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7795: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7796: if (ref($types) eq 'ARRAY') {
7797: @posstypes = @{$types};
7798: }
7799: if (@posstypes) {
7800: unless (grep(/^default$/,@posstypes)) {
7801: push(@posstypes,'default');
1.302 raeburn 7802: }
7803: if (ref($usertypes) eq 'HASH') {
7804: %usertypeshash = %{$usertypes};
7805: }
1.305 raeburn 7806: my $currassign;
7807: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7808: $currassign = {
7809: selfassign => $domdefaults{'inststatusguest'},
7810: };
7811: @ordered = @{$domdefaults{'inststatusguest'}};
7812: } else {
7813: $currassign = { selfassign => [] };
7814: }
7815: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7816: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7817: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7818: $numinrow,$othertitle,'selfassign',
7819: $rowtotal,$onclicktypes,$customclass,
7820: $rowstyle);
7821: $$rowtotal ++;
1.302 raeburn 7822: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7823: foreach my $status (@posstypes) {
7824: my $css_class;
7825: if ($$rowtotal%2) {
7826: $css_class = 'LC_odd_row ';
7827: }
7828: $css_class .= $customclass;
7829: my $rowid = $optionsprefix.$status;
7830: my $hidden = 1;
7831: my $currstyle = 'display:none';
7832: if (grep(/^\Q$status\E$/,@ordered)) {
7833: $currstyle = $rowstyle;
7834: $hidden = 0;
7835: }
7836: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7837: $emailrules,$emailruleorder,$settings,$status,$rowid,
7838: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7839: unless ($hidden) {
7840: $$rowtotal ++;
7841: }
1.224 raeburn 7842: }
1.302 raeburn 7843: } else {
1.305 raeburn 7844: my $css_class;
7845: if ($$rowtotal%2) {
7846: $css_class = 'LC_odd_row ';
7847: }
7848: $css_class .= $customclass;
1.302 raeburn 7849: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 7850: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7851: $emailrules,$emailruleorder,$settings,'default','',
7852: $othertitle,$css_class,$rowstyle,$intdom);
7853: $$rowtotal ++;
1.224 raeburn 7854: }
7855: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 7856: $numinrow = 1;
1.305 raeburn 7857: if (@posstypes) {
7858: foreach my $status (@posstypes) {
7859: my $rowid = $classprefix.$status;
7860: my $datarowstyle = 'display:none';
7861: if (grep(/^\Q$status\E$/,@ordered)) {
7862: $datarowstyle = $rowstyle;
7863: }
7864: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7865: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7866: $infotitles,$rowid,$customclass,$datarowstyle);
7867: unless ($datarowstyle eq 'display:none') {
7868: $$rowtotal ++;
7869: }
1.224 raeburn 7870: }
1.305 raeburn 7871: } else {
7872: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7873: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7874: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 7875: }
7876: }
7877: return $datatable;
7878: }
7879:
1.305 raeburn 7880: sub selfcreate_javascript {
7881: return <<"ENDSCRIPT";
7882:
7883: <script type="text/javascript">
7884: // <![CDATA[
7885:
7886: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7887: var x = document.getElementsByClassName(target);
7888: var insttypes = 0;
7889: var insttypeRegExp = new RegExp(prefix);
7890: if ((x.length != undefined) && (x.length > 0)) {
7891: if (form.elements[radio].length != undefined) {
7892: for (var i=0; i<form.elements[radio].length; i++) {
7893: if (form.elements[radio][i].checked) {
7894: if (form.elements[radio][i].value == 1) {
7895: for (var j=0; j<x.length; j++) {
7896: if (x[j].id == 'undefined') {
7897: x[j].style.display = 'table-row';
7898: } else if (insttypeRegExp.test(x[j].id)) {
7899: insttypes ++;
7900: } else {
7901: x[j].style.display = 'table-row';
7902: }
7903: }
7904: } else {
7905: for (var j=0; j<x.length; j++) {
7906: x[j].style.display = 'none';
7907: }
1.236 raeburn 7908: }
1.305 raeburn 7909: break;
7910: }
7911: }
7912: if (insttypes > 0) {
7913: toggleDataRow(form,checkbox,target,altprefix);
7914: toggleDataRow(form,checkbox,target,prefix,1);
7915: }
7916: }
7917: }
7918: return;
7919: }
7920:
7921: function toggleDataRow(form,checkbox,target,prefix,docount) {
7922: if (form.elements[checkbox].length != undefined) {
7923: var count = 0;
7924: if (docount) {
7925: for (var i=0; i<form.elements[checkbox].length; i++) {
7926: if (form.elements[checkbox][i].checked) {
7927: count ++;
1.236 raeburn 7928: }
1.305 raeburn 7929: }
7930: }
7931: for (var i=0; i<form.elements[checkbox].length; i++) {
7932: var type = form.elements[checkbox][i].value;
7933: if (document.getElementById(prefix+type)) {
7934: if (form.elements[checkbox][i].checked) {
7935: document.getElementById(prefix+type).style.display = 'table-row';
7936: if (count % 2 == 1) {
7937: document.getElementById(prefix+type).className = target+' LC_odd_row';
7938: } else {
7939: document.getElementById(prefix+type).className = target;
1.236 raeburn 7940: }
1.305 raeburn 7941: count ++;
1.236 raeburn 7942: } else {
1.305 raeburn 7943: document.getElementById(prefix+type).style.display = 'none';
7944: }
7945: }
7946: }
7947: }
7948: return;
7949: }
7950:
7951: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
7952: var caller = radio+'_'+status;
7953: if (form.elements[caller].length != undefined) {
7954: for (var i=0; i<form.elements[caller].length; i++) {
7955: if (form.elements[caller][i].checked) {
7956: if (document.getElementById(altprefix+'_inst_'+status)) {
7957: var curr = form.elements[caller][i].value;
7958: if (prefix) {
7959: document.getElementById(prefix+'_'+status).style.display = 'none';
7960: }
7961: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
7962: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
7963: if (curr == 'custom') {
7964: if (prefix) {
7965: document.getElementById(prefix+'_'+status).style.display = 'inline';
7966: }
7967: } else if (curr == 'inst') {
7968: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
7969: } else if (curr == 'noninst') {
7970: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 7971: }
1.305 raeburn 7972: break;
1.236 raeburn 7973: }
7974: }
7975: }
7976: }
7977: }
7978:
1.305 raeburn 7979: // ]]>
7980: </script>
7981:
7982: ENDSCRIPT
7983: }
7984:
7985: sub noninst_users {
7986: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
7987: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
7988: my $class = 'LC_left_item';
7989: if ($css_class) {
7990: $css_class = ' class="'.$css_class.'"';
7991: }
7992: if ($rowid) {
7993: $rowid = ' id="'.$rowid.'"';
7994: }
7995: if ($rowstyle) {
7996: $rowstyle = ' style="'.$rowstyle.'"';
7997: }
7998: my ($output,$description);
7999: if ($type eq 'default') {
8000: $description = &mt('Requests for: [_1]',$typetitle);
8001: } else {
8002: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8003: }
8004: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8005: "<td>$description</td>\n".
8006: '<td class="'.$class.'" colspan="2">'.
8007: '<table><tr>';
8008: my %headers = &Apache::lonlocal::texthash(
8009: approve => 'Processing',
8010: email => 'E-mail',
8011: username => 'Username',
8012: );
8013: foreach my $item ('approve','email','username') {
8014: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 8015: }
1.305 raeburn 8016: $output .= '</tr><tr>';
8017: foreach my $item ('approve','email','username') {
1.306 raeburn 8018: $output .= '<td style="vertical-align: top">';
1.305 raeburn 8019: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8020: if ($item eq 'approve') {
8021: %choices = &Apache::lonlocal::texthash (
8022: automatic => 'Automatically approved',
8023: approval => 'Queued for approval',
8024: );
8025: @options = ('automatic','approval');
8026: $hashref = $processing;
8027: $defoption = 'automatic';
8028: $name = 'cancreate_emailprocess_'.$type;
8029: } elsif ($item eq 'email') {
8030: %choices = &Apache::lonlocal::texthash (
8031: any => 'Any e-mail',
8032: inst => 'Institutional only',
8033: noninst => 'Non-institutional only',
8034: custom => 'Custom restrictions',
8035: );
8036: @options = ('any','inst','noninst');
8037: my $showcustom;
8038: if (ref($emailrules) eq 'HASH') {
8039: if (keys(%{$emailrules}) > 0) {
8040: push(@options,'custom');
8041: $showcustom = 'cancreate_emailrule';
8042: if (ref($settings) eq 'HASH') {
8043: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8044: foreach my $rule (@{$settings->{'email_rule'}}) {
8045: if (exists($emailrules->{$rule})) {
8046: $hascustom ++;
8047: }
8048: }
8049: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8050: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8051: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8052: if (exists($emailrules->{$rule})) {
8053: $hascustom ++;
8054: }
8055: }
8056: }
8057: }
8058: }
8059: }
8060: }
8061: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8062: "'cancreate_emaildomain','$type'".');"';
8063: $hashref = $emailoptions;
8064: $defoption = 'any';
8065: $name = 'cancreate_emailoptions_'.$type;
8066: } elsif ($item eq 'username') {
8067: %choices = &Apache::lonlocal::texthash (
8068: all => 'Same as e-mail',
8069: first => 'Omit @domain',
8070: free => 'Free to choose',
8071: );
8072: @options = ('all','first','free');
8073: $hashref = $emailverified;
8074: $defoption = 'all';
8075: $name = 'cancreate_usernameoptions_'.$type;
8076: }
8077: foreach my $option (@options) {
8078: my $checked;
8079: if (ref($hashref) eq 'HASH') {
8080: if ($type eq '') {
8081: if (!exists($hashref->{'default'})) {
8082: if ($option eq $defoption) {
8083: $checked = ' checked="checked"';
8084: }
8085: } else {
8086: if ($hashref->{'default'} eq $option) {
8087: $checked = ' checked="checked"';
8088: }
1.303 raeburn 8089: }
8090: } else {
1.305 raeburn 8091: if (!exists($hashref->{$type})) {
8092: if ($option eq $defoption) {
8093: $checked = ' checked="checked"';
8094: }
8095: } else {
8096: if ($hashref->{$type} eq $option) {
8097: $checked = ' checked="checked"';
8098: }
1.303 raeburn 8099: }
8100: }
1.305 raeburn 8101: } elsif (($item eq 'email') && ($hascustom)) {
8102: if ($option eq 'custom') {
8103: $checked = ' checked="checked"';
8104: }
8105: } elsif ($option eq $defoption) {
8106: $checked = ' checked="checked"';
8107: }
8108: $output .= '<span class="LC_nobreak"><label>'.
8109: '<input type="radio" name="'.$name.'"'.
8110: $checked.' value="'.$option.'"'.$onclick.' />'.
8111: $choices{$option}.'</label></span><br />';
8112: if ($item eq 'email') {
8113: if ($option eq 'custom') {
8114: my $id = 'cancreate_emailrule_'.$type;
8115: my $display = 'none';
8116: if ($checked) {
8117: $display = 'inline';
1.303 raeburn 8118: }
1.305 raeburn 8119: my $numinrow = 2;
8120: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8121: '<legend>'.&mt('Disallow').'</legend><table>'.
8122: &user_formats_row('email',$settings,$emailrules,
8123: $emailruleorder,$numinrow,'',$type);
8124: '</table></fieldset>';
8125: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8126: my %text = &Apache::lonlocal::texthash (
8127: inst => 'must end:',
8128: noninst => 'cannot end:',
8129: );
8130: my $value;
8131: if (ref($emaildomain) eq 'HASH') {
8132: if (ref($emaildomain->{$type}) eq 'HASH') {
8133: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 8134: }
8135: }
1.305 raeburn 8136: if ($value eq '') {
8137: $value = '@'.$intdom;
8138: }
8139: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8140: my $display = 'none';
8141: if ($checked) {
8142: $display = 'inline';
8143: }
8144: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8145: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8146: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8147: '</div>';
1.303 raeburn 8148: }
8149: }
8150: }
1.305 raeburn 8151: $output .= '</td>'."\n";
1.303 raeburn 8152: }
1.305 raeburn 8153: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 8154: return $output;
8155: }
8156:
1.165 raeburn 8157: sub captcha_choice {
1.305 raeburn 8158: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 8159: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8160: $vertext,$currver);
1.165 raeburn 8161: my %lt = &captcha_phrases();
8162: $keyentry = 'hidden';
1.354 raeburn 8163: my $colspan=2;
1.165 raeburn 8164: if ($context eq 'cancreate') {
1.224 raeburn 8165: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 8166: } elsif ($context eq 'login') {
8167: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 8168: } elsif ($context eq 'passwords') {
8169: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8170: $colspan=1;
1.165 raeburn 8171: }
8172: if (ref($settings) eq 'HASH') {
8173: if ($settings->{'captcha'}) {
8174: $checked{$settings->{'captcha'}} = ' checked="checked"';
8175: } else {
8176: $checked{'original'} = ' checked="checked"';
8177: }
8178: if ($settings->{'captcha'} eq 'recaptcha') {
8179: $pubtext = $lt{'pub'};
8180: $privtext = $lt{'priv'};
8181: $keyentry = 'text';
1.269 raeburn 8182: $vertext = $lt{'ver'};
8183: $currver = $settings->{'recaptchaversion'};
8184: if ($currver ne '2') {
8185: $currver = 1;
8186: }
1.165 raeburn 8187: }
8188: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8189: $currpub = $settings->{'recaptchakeys'}{'public'};
8190: $currpriv = $settings->{'recaptchakeys'}{'private'};
8191: }
8192: } else {
8193: $checked{'original'} = ' checked="checked"';
8194: }
1.305 raeburn 8195: my $css_class;
8196: if ($itemcount%2) {
8197: $css_class = 'LC_odd_row';
8198: }
8199: if ($customcss) {
8200: $css_class .= " $customcss";
8201: }
8202: $css_class =~ s/^\s+//;
8203: if ($css_class) {
8204: $css_class = ' class="'.$css_class.'"';
8205: }
8206: if ($rowstyle) {
8207: $css_class .= ' style="'.$rowstyle.'"';
8208: }
1.169 raeburn 8209: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 8210: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 8211: '<table><tr><td>'."\n";
8212: foreach my $option ('original','recaptcha','notused') {
8213: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8214: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8215: $lt{$option}.'</label></span>';
8216: unless ($option eq 'notused') {
8217: $output .= (' 'x2)."\n";
8218: }
8219: }
8220: #
8221: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8222: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 8223: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 8224: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 8225: #
1.165 raeburn 8226: $output .= '</td></tr>'."\n".
1.305 raeburn 8227: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 8228: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8229: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8230: $currpub.'" size="40" /></span><br />'."\n".
8231: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8232: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 8233: $currpriv.'" size="40" /></span><br />'.
8234: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8235: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8236: $currver.'" size="3" /></span><br />'.
8237: '</td></tr></table>'."\n".
1.165 raeburn 8238: '</td></tr>';
8239: return $output;
8240: }
8241:
1.32 raeburn 8242: sub user_formats_row {
1.305 raeburn 8243: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8244: my $output;
8245: my %text = (
8246: 'username' => 'new usernames',
8247: 'id' => 'IDs',
8248: );
1.305 raeburn 8249: unless ($type eq 'email') {
8250: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8251: $output = '<tr '.$css_class.'>'.
8252: '<td><span class="LC_nobreak">'.
8253: &mt("Format rules to check for $text{$type}: ").
8254: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8255: }
1.27 raeburn 8256: my $rem;
8257: if (ref($ruleorder) eq 'ARRAY') {
8258: for (my $i=0; $i<@{$ruleorder}; $i++) {
8259: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8260: my $rem = $i%($numinrow);
8261: if ($rem == 0) {
8262: if ($i > 0) {
8263: $output .= '</tr>';
8264: }
8265: $output .= '<tr>';
8266: }
8267: my $check = ' ';
1.39 raeburn 8268: if (ref($settings) eq 'HASH') {
8269: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8270: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8271: $check = ' checked="checked" ';
8272: }
1.305 raeburn 8273: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8274: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8275: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8276: $check = ' checked="checked" ';
8277: }
8278: }
1.27 raeburn 8279: }
8280: }
1.305 raeburn 8281: my $name = $type.'_rule';
8282: if ($type eq 'email') {
8283: $name .= '_'.$status;
8284: }
1.27 raeburn 8285: $output .= '<td class="LC_left_item">'.
8286: '<span class="LC_nobreak"><label>'.
1.311 raeburn 8287: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8288: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8289: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8290: }
8291: }
8292: $rem = @{$ruleorder}%($numinrow);
8293: }
1.305 raeburn 8294: my $colsleft;
8295: if ($rem) {
8296: $colsleft = $numinrow - $rem;
8297: }
1.27 raeburn 8298: if ($colsleft > 1 ) {
8299: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8300: ' </td>';
8301: } elsif ($colsleft == 1) {
8302: $output .= '<td class="LC_left_item"> </td>';
8303: }
1.305 raeburn 8304: $output .= '</tr></table>';
8305: unless ($type eq 'email') {
8306: $output .= '</td></tr>';
8307: }
1.27 raeburn 8308: return $output;
8309: }
8310:
1.34 raeburn 8311: sub usercreation_types {
8312: my %lt = &Apache::lonlocal::texthash (
8313: author => 'When adding a co-author',
8314: course => 'When adding a user to a course',
1.100 raeburn 8315: requestcrs => 'When requesting a course',
1.34 raeburn 8316: any => 'Any',
8317: official => 'Institutional only ',
8318: unofficial => 'Non-institutional only',
8319: none => 'None',
8320: );
8321: return %lt;
1.48 raeburn 8322: }
1.34 raeburn 8323:
1.224 raeburn 8324: sub selfcreation_types {
8325: my %lt = &Apache::lonlocal::texthash (
8326: selfcreate => 'User creates own account',
8327: any => 'Any',
8328: official => 'Institutional only ',
8329: unofficial => 'Non-institutional only',
8330: email => 'E-mail address',
8331: login => 'Institutional Login',
8332: sso => 'SSO',
8333: );
8334: }
8335:
1.28 raeburn 8336: sub authtype_names {
8337: my %lt = &Apache::lonlocal::texthash(
8338: int => 'Internal',
8339: krb4 => 'Kerberos 4',
8340: krb5 => 'Kerberos 5',
8341: loc => 'Local',
1.325 raeburn 8342: lti => 'LTI',
1.28 raeburn 8343: );
8344: return %lt;
8345: }
8346:
8347: sub context_names {
8348: my %context_title = &Apache::lonlocal::texthash(
8349: author => 'Creating users when an Author',
8350: course => 'Creating users when in a course',
8351: domain => 'Creating users when a Domain Coordinator',
8352: );
8353: return %context_title;
8354: }
8355:
1.33 raeburn 8356: sub print_usermodification {
8357: my ($position,$dom,$settings,$rowtotal) = @_;
8358: my $numinrow = 4;
8359: my ($context,$datatable,$rowcount);
8360: if ($position eq 'top') {
8361: $rowcount = 0;
8362: $context = 'author';
8363: foreach my $role ('ca','aa') {
8364: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8365: $numinrow,$rowcount);
8366: $$rowtotal ++;
8367: $rowcount ++;
8368: }
1.230 raeburn 8369: } elsif ($position eq 'bottom') {
1.33 raeburn 8370: $context = 'course';
8371: $rowcount = 0;
8372: foreach my $role ('st','ep','ta','in','cr') {
8373: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8374: $numinrow,$rowcount);
8375: $$rowtotal ++;
8376: $rowcount ++;
8377: }
8378: }
8379: return $datatable;
8380: }
8381:
1.43 raeburn 8382: sub print_defaults {
1.236 raeburn 8383: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8384: my $rownum = 0;
1.294 raeburn 8385: my ($datatable,$css_class,$titles);
8386: unless ($position eq 'bottom') {
8387: $titles = &defaults_titles($dom);
8388: }
1.236 raeburn 8389: if ($position eq 'top') {
8390: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8391: 'datelocale_def','portal_def');
8392: my %defaults;
8393: if (ref($settings) eq 'HASH') {
8394: %defaults = %{$settings};
1.43 raeburn 8395: } else {
1.236 raeburn 8396: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8397: foreach my $item (@items) {
8398: $defaults{$item} = $domdefaults{$item};
8399: }
1.43 raeburn 8400: }
1.236 raeburn 8401: foreach my $item (@items) {
8402: if ($rownum%2) {
8403: $css_class = '';
8404: } else {
8405: $css_class = ' class="LC_odd_row" ';
8406: }
8407: $datatable .= '<tr'.$css_class.'>'.
8408: '<td><span class="LC_nobreak">'.$titles->{$item}.
8409: '</span></td><td class="LC_right_item" colspan="3">';
8410: if ($item eq 'auth_def') {
1.325 raeburn 8411: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 8412: my %shortauth = (
8413: internal => 'int',
8414: krb4 => 'krb4',
8415: krb5 => 'krb5',
1.325 raeburn 8416: localauth => 'loc',
8417: lti => 'lti',
1.236 raeburn 8418: );
8419: my %authnames = &authtype_names();
8420: foreach my $auth (@authtypes) {
8421: my $checked = ' ';
8422: if ($defaults{$item} eq $auth) {
8423: $checked = ' checked="checked" ';
8424: }
8425: $datatable .= '<label><input type="radio" name="'.$item.
8426: '" value="'.$auth.'"'.$checked.'/>'.
8427: $authnames{$shortauth{$auth}}.'</label> ';
8428: }
8429: } elsif ($item eq 'timezone_def') {
8430: my $includeempty = 1;
8431: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8432: } elsif ($item eq 'datelocale_def') {
8433: my $includeempty = 1;
8434: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8435: } elsif ($item eq 'lang_def') {
1.263 raeburn 8436: my $includeempty = 1;
8437: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 8438: } else {
8439: my $size;
8440: if ($item eq 'portal_def') {
8441: $size = ' size="25"';
8442: }
8443: $datatable .= '<input type="text" name="'.$item.'" value="'.
8444: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 8445: }
1.236 raeburn 8446: $datatable .= '</td></tr>';
8447: $rownum ++;
8448: }
1.354 raeburn 8449: } else {
1.294 raeburn 8450: my %defaults;
8451: if (ref($settings) eq 'HASH') {
1.354 raeburn 8452: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
8453: my $maxnum = @{$settings->{'inststatusorder'}};
8454: for (my $i=0; $i<$maxnum; $i++) {
8455: $css_class = $rownum%2?' class="LC_odd_row"':'';
8456: my $item = $settings->{'inststatusorder'}->[$i];
8457: my $title = $settings->{'inststatustypes'}->{$item};
8458: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8459: $datatable .= '<tr'.$css_class.'>'.
8460: '<td><span class="LC_nobreak">'.
8461: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8462: for (my $k=0; $k<=$maxnum; $k++) {
8463: my $vpos = $k+1;
8464: my $selstr;
8465: if ($k == $i) {
8466: $selstr = ' selected="selected" ';
8467: }
8468: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8469: }
8470: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8471: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8472: &mt('delete').'</span></td>'.
8473: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
8474: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
8475: '</span></td></tr>';
8476: }
8477: $css_class = $rownum%2?' class="LC_odd_row"':'';
8478: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8479: $datatable .= '<tr '.$css_class.'>'.
8480: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8481: for (my $k=0; $k<=$maxnum; $k++) {
8482: my $vpos = $k+1;
8483: my $selstr;
8484: if ($k == $maxnum) {
8485: $selstr = ' selected="selected" ';
8486: }
8487: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8488: }
8489: $datatable .= '</select> '.&mt('Internal ID:').
8490: '<input type="text" size="10" name="addinststatus" value="" />'.
8491: ' '.&mt('(new)').
8492: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
8493: &mt('Name displayed:').
8494: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8495: '</tr>'."\n";
8496: $rownum ++;
1.294 raeburn 8497: }
1.354 raeburn 8498: }
8499: }
8500: $$rowtotal += $rownum;
1.43 raeburn 8501: return $datatable;
8502: }
8503:
1.168 raeburn 8504: sub get_languages_hash {
8505: my %langchoices;
8506: foreach my $id (&Apache::loncommon::languageids()) {
8507: my $code = &Apache::loncommon::supportedlanguagecode($id);
8508: if ($code ne '') {
8509: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8510: }
8511: }
8512: return %langchoices;
8513: }
8514:
1.43 raeburn 8515: sub defaults_titles {
1.141 raeburn 8516: my ($dom) = @_;
1.43 raeburn 8517: my %titles = &Apache::lonlocal::texthash (
8518: 'auth_def' => 'Default authentication type',
8519: 'auth_arg_def' => 'Default authentication argument',
8520: 'lang_def' => 'Default language',
1.54 raeburn 8521: 'timezone_def' => 'Default timezone',
1.68 raeburn 8522: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8523: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 8524: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8525: 'intauth_check' => 'Check bcrypt cost if authenticated',
8526: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8527: );
1.141 raeburn 8528: if ($dom) {
8529: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8530: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8531: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8532: $protocol = 'http' if ($protocol ne 'https');
8533: if ($uint_dom) {
8534: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8535: $uint_dom);
8536: }
8537: }
1.43 raeburn 8538: return (\%titles);
8539: }
8540:
1.346 raeburn 8541: sub print_scantron {
8542: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8543: if ($position eq 'top') {
8544: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8545: } else {
8546: return &print_scantronconfig($dom,$settings,\$rowtotal);
8547: }
8548: }
8549:
8550: sub scantron_javascript {
8551: return <<"ENDSCRIPT";
8552:
8553: <script type="text/javascript">
8554: // <![CDATA[
8555:
8556: function toggleScantron(form) {
1.347 raeburn 8557: var csvfieldset = new Array();
1.346 raeburn 8558: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 8559: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8560: }
8561: if (document.getElementById('scantroncsv_options')) {
8562: csvfieldset.push(document.getElementById('scantroncsv_options'));
8563: }
8564: if (csvfieldset.length) {
1.346 raeburn 8565: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 8566: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 8567: if (scantroncsv.checked) {
1.347 raeburn 8568: for (var i=0; i<csvfieldset.length; i++) {
8569: csvfieldset[i].style.display = 'block';
8570: }
1.346 raeburn 8571: } else {
1.347 raeburn 8572: for (var i=0; i<csvfieldset.length; i++) {
8573: csvfieldset[i].style.display = 'none';
8574: }
1.346 raeburn 8575: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8576: if (csvselects.length) {
8577: for (var j=0; j<csvselects.length; j++) {
8578: csvselects[j].selectedIndex = 0;
8579: }
8580: }
8581: }
8582: }
8583: }
8584: return;
8585: }
8586: // ]]>
8587: </script>
8588:
8589: ENDSCRIPT
8590:
8591: }
8592:
1.46 raeburn 8593: sub print_scantronformat {
8594: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8595: my $itemcount = 1;
1.60 raeburn 8596: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8597: %confhash);
1.46 raeburn 8598: my $switchserver = &check_switchserver($dom,$confname);
8599: my %lt = &Apache::lonlocal::texthash (
1.95 www 8600: default => 'Default bubblesheet format file error',
8601: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8602: );
8603: my %scantronfiles = (
8604: default => 'default.tab',
8605: custom => 'custom.tab',
8606: );
8607: foreach my $key (keys(%scantronfiles)) {
8608: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8609: .$scantronfiles{$key};
8610: }
8611: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8612: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8613: if (!$switchserver) {
8614: my $servadm = $r->dir_config('lonAdmEMail');
8615: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8616: if ($configuserok eq 'ok') {
8617: if ($author_ok eq 'ok') {
8618: my %legacyfile = (
1.346 raeburn 8619: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8620: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8621: );
8622: my %md5chk;
8623: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8624: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8625: chomp($md5chk{$type});
1.46 raeburn 8626: }
8627: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8628: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 8629: ($scantronurls{$type},my $error) =
1.46 raeburn 8630: &legacy_scantronformat($r,$dom,$confname,
8631: $type,$legacyfile{$type},
8632: $scantronurls{$type},
8633: $scantronfiles{$type});
1.60 raeburn 8634: if ($error ne '') {
8635: $error{$type} = $error;
8636: }
8637: }
8638: if (keys(%error) == 0) {
8639: $is_custom = 1;
1.346 raeburn 8640: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8641: $scantronurls{'custom'};
1.346 raeburn 8642: my $putresult =
1.60 raeburn 8643: &Apache::lonnet::put_dom('configuration',
8644: \%confhash,$dom);
8645: if ($putresult ne 'ok') {
1.346 raeburn 8646: $error{'custom'} =
1.60 raeburn 8647: '<span class="LC_error">'.
8648: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8649: }
1.46 raeburn 8650: }
8651: } else {
1.60 raeburn 8652: ($scantronurls{'default'},my $error) =
1.46 raeburn 8653: &legacy_scantronformat($r,$dom,$confname,
8654: 'default',$legacyfile{'default'},
8655: $scantronurls{'default'},
8656: $scantronfiles{'default'});
1.60 raeburn 8657: if ($error eq '') {
8658: $confhash{'scantron'}{'scantronformat'} = '';
8659: my $putresult =
8660: &Apache::lonnet::put_dom('configuration',
8661: \%confhash,$dom);
8662: if ($putresult ne 'ok') {
8663: $error{'default'} =
8664: '<span class="LC_error">'.
8665: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8666: }
8667: } else {
8668: $error{'default'} = $error;
8669: }
1.46 raeburn 8670: }
8671: }
8672: }
8673: } else {
1.95 www 8674: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8675: }
8676: }
8677: if (ref($settings) eq 'HASH') {
8678: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8679: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8680: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8681: $scantronurl = '';
8682: } else {
8683: $scantronurl = $settings->{'scantronformat'};
8684: }
8685: $is_custom = 1;
8686: } else {
8687: $scantronurl = $scantronurls{'default'};
8688: }
8689: } else {
1.60 raeburn 8690: if ($is_custom) {
8691: $scantronurl = $scantronurls{'custom'};
8692: } else {
8693: $scantronurl = $scantronurls{'default'};
8694: }
1.46 raeburn 8695: }
8696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8697: $datatable .= '<tr'.$css_class.'>';
8698: if (!$is_custom) {
1.65 raeburn 8699: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8700: '<span class="LC_nobreak">';
1.46 raeburn 8701: if ($scantronurl) {
1.199 raeburn 8702: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8703: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8704: } else {
8705: $datatable = &mt('File unavailable for display');
8706: }
1.65 raeburn 8707: $datatable .= '</span></td>';
1.60 raeburn 8708: if (keys(%error) == 0) {
1.306 raeburn 8709: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 8710: if (!$switchserver) {
8711: $datatable .= &mt('Upload:').'<br />';
8712: }
8713: } else {
8714: my $errorstr;
8715: foreach my $key (sort(keys(%error))) {
8716: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8717: }
8718: $datatable .= '<td>'.$errorstr;
8719: }
1.46 raeburn 8720: } else {
8721: if (keys(%error) > 0) {
8722: my $errorstr;
8723: foreach my $key (sort(keys(%error))) {
8724: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8725: }
1.60 raeburn 8726: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8727: } elsif ($scantronurl) {
1.199 raeburn 8728: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
8729: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8730: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 8731: $link.
8732: '<label><input type="checkbox" name="scantronformat_del"'.
8733: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8734: '<td><span class="LC_nobreak"> '.
8735: &mt('Replace:').'</span><br />';
1.46 raeburn 8736: }
8737: }
8738: if (keys(%error) == 0) {
8739: if ($switchserver) {
8740: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8741: } else {
1.65 raeburn 8742: $datatable .='<span class="LC_nobreak"> '.
8743: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8744: }
8745: }
8746: $datatable .= '</td></tr>';
8747: $$rowtotal ++;
8748: return $datatable;
8749: }
8750:
8751: sub legacy_scantronformat {
8752: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8753: my ($url,$error);
8754: my @statinfo = &Apache::lonnet::stat_file($newurl);
8755: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8756: (my $result,$url) =
8757: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8758: '','',$newfile);
8759: if ($result ne 'ok') {
1.130 raeburn 8760: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8761: }
8762: }
8763: return ($url,$error);
8764: }
1.43 raeburn 8765:
1.346 raeburn 8766: sub print_scantronconfig {
8767: my ($dom,$settings,$rowtotal) = @_;
8768: my $itemcount = 2;
8769: my $is_checked = ' checked="checked"';
1.347 raeburn 8770: my %optionson = (
8771: hdr => ' checked="checked"',
8772: pad => ' checked="checked"',
8773: rem => ' checked="checked"',
8774: );
8775: my %optionsoff = (
8776: hdr => '',
8777: pad => '',
8778: rem => '',
8779: );
1.346 raeburn 8780: my $currcsvsty = 'none';
1.347 raeburn 8781: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 8782: my @fields = &scantroncsv_fields();
8783: my %titles = &scantronconfig_titles();
8784: if (ref($settings) eq 'HASH') {
8785: if (ref($settings->{config}) eq 'HASH') {
8786: if ($settings->{config}->{dat}) {
8787: $checked{'dat'} = $is_checked;
8788: }
8789: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 8790: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8791: %csvfields = %{$settings->{config}->{csv}->{fields}};
8792: if (keys(%csvfields) > 0) {
8793: $checked{'csv'} = $is_checked;
8794: $currcsvsty = 'block';
8795: }
8796: }
8797: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8798: %csvoptions = %{$settings->{config}->{csv}->{options}};
8799: foreach my $option (keys(%optionson)) {
8800: unless ($csvoptions{$option}) {
8801: $optionsoff{$option} = $optionson{$option};
8802: $optionson{$option} = '';
8803: }
8804: }
1.346 raeburn 8805: }
8806: }
8807: } else {
8808: $checked{'dat'} = $is_checked;
8809: }
8810: } else {
8811: $checked{'dat'} = $is_checked;
8812: }
8813: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8814: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8815: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8816: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8817: foreach my $item ('dat','csv') {
8818: my $id;
8819: if ($item eq 'csv') {
8820: $id = 'id="scantronconfcsv" ';
1.347 raeburn 8821: }
1.346 raeburn 8822: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8823: $titles{$item}.'</label>'.(' 'x3);
8824: if ($item eq 'csv') {
8825: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8826: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8827: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8828: foreach my $col (@fields) {
8829: my $selnone;
8830: if ($csvfields{$col} eq '') {
8831: $selnone = ' selected="selected"';
8832: }
8833: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8834: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8835: '<option value=""'.$selnone.'></option>';
8836: for (my $i=0; $i<20; $i++) {
8837: my $shown = $i+1;
8838: my $sel;
8839: unless ($selnone) {
8840: if (exists($csvfields{$col})) {
8841: if ($csvfields{$col} == $i) {
8842: $sel = ' selected="selected"';
8843: }
8844: }
8845: }
8846: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8847: }
8848: $datatable .= '</select></td></tr>';
8849: }
1.347 raeburn 8850: $datatable .= '</table></fieldset>'.
8851: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8852: '<legend>'.&mt('CSV Options').'</legend>';
8853: foreach my $option ('hdr','pad','rem') {
8854: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8855: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8856: &mt('Yes').'</label>'.(' 'x2)."\n".
8857: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8858: }
8859: $datatable .= '</fieldset>';
1.346 raeburn 8860: $itemcount ++;
8861: }
8862: }
8863: $datatable .= '</td></tr>';
8864: $$rowtotal ++;
8865: return $datatable;
8866: }
8867:
8868: sub scantronconfig_titles {
8869: return &Apache::lonlocal::texthash(
8870: dat => 'Standard format (.dat)',
8871: csv => 'Comma separated values (.csv)',
1.347 raeburn 8872: hdr => 'Remove first line in file (contains column titles)',
8873: pad => 'Prepend 0s to PaperID',
1.348 raeburn 8874: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 8875: CODE => 'CODE',
8876: ID => 'Student ID',
8877: PaperID => 'Paper ID',
8878: FirstName => 'First Name',
8879: LastName => 'Last Name',
8880: FirstQuestion => 'First Question Response',
8881: Section => 'Section',
8882: );
8883: }
8884:
8885: sub scantroncsv_fields {
8886: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8887: }
8888:
1.49 raeburn 8889: sub print_coursecategories {
1.57 raeburn 8890: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8891: my $datatable;
8892: if ($position eq 'top') {
1.238 raeburn 8893: my (%checked);
8894: my @catitems = ('unauth','auth');
8895: my @cattypes = ('std','domonly','codesrch','none');
8896: $checked{'unauth'} = 'std';
8897: $checked{'auth'} = 'std';
8898: if (ref($settings) eq 'HASH') {
8899: foreach my $type (@cattypes) {
8900: if ($type eq $settings->{'unauth'}) {
8901: $checked{'unauth'} = $type;
8902: }
8903: if ($type eq $settings->{'auth'}) {
8904: $checked{'auth'} = $type;
8905: }
8906: }
8907: }
8908: my %lt = &Apache::lonlocal::texthash (
8909: unauth => 'Catalog type for unauthenticated users',
8910: auth => 'Catalog type for authenticated users',
8911: none => 'No catalog',
8912: std => 'Standard catalog',
8913: domonly => 'Domain-only catalog',
8914: codesrch => "Code search form",
8915: );
8916: my $itemcount = 0;
8917: foreach my $item (@catitems) {
8918: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8919: $datatable .= '<tr '.$css_class.'>'.
8920: '<td>'.$lt{$item}.'</td>'.
8921: '<td class="LC_right_item"><span class="LC_nobreak">';
8922: foreach my $type (@cattypes) {
8923: my $ischecked;
8924: if ($checked{$item} eq $type) {
8925: $ischecked=' checked="checked"';
8926: }
8927: $datatable .= '<label>'.
8928: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
8929: ' />'.$lt{$type}.'</label> ';
8930: }
1.327 raeburn 8931: $datatable .= '</span></td></tr>';
1.238 raeburn 8932: $itemcount ++;
8933: }
8934: $$rowtotal += $itemcount;
8935: } elsif ($position eq 'middle') {
1.57 raeburn 8936: my $toggle_cats_crs = ' ';
8937: my $toggle_cats_dom = ' checked="checked" ';
8938: my $can_cat_crs = ' ';
8939: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 8940: my $toggle_catscomm_comm = ' ';
8941: my $toggle_catscomm_dom = ' checked="checked" ';
8942: my $can_catcomm_comm = ' ';
8943: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 8944: my $toggle_catsplace_place = ' ';
8945: my $toggle_catsplace_dom = ' checked="checked" ';
8946: my $can_catplace_place = ' ';
8947: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 8948:
1.57 raeburn 8949: if (ref($settings) eq 'HASH') {
8950: if ($settings->{'togglecats'} eq 'crs') {
8951: $toggle_cats_crs = $toggle_cats_dom;
8952: $toggle_cats_dom = ' ';
8953: }
8954: if ($settings->{'categorize'} eq 'crs') {
8955: $can_cat_crs = $can_cat_dom;
8956: $can_cat_dom = ' ';
8957: }
1.120 raeburn 8958: if ($settings->{'togglecatscomm'} eq 'comm') {
8959: $toggle_catscomm_comm = $toggle_catscomm_dom;
8960: $toggle_catscomm_dom = ' ';
8961: }
8962: if ($settings->{'categorizecomm'} eq 'comm') {
8963: $can_catcomm_comm = $can_catcomm_dom;
8964: $can_catcomm_dom = ' ';
8965: }
1.272 raeburn 8966: if ($settings->{'togglecatsplace'} eq 'place') {
8967: $toggle_catsplace_place = $toggle_catsplace_dom;
8968: $toggle_catsplace_dom = ' ';
8969: }
8970: if ($settings->{'categorizeplace'} eq 'place') {
8971: $can_catplace_place = $can_catplace_dom;
8972: $can_catplace_dom = ' ';
8973: }
1.57 raeburn 8974: }
8975: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 8976: togglecats => 'Show/Hide a course in catalog',
8977: togglecatscomm => 'Show/Hide a community in catalog',
8978: togglecatsplace => 'Show/Hide a placement test in catalog',
8979: categorize => 'Assign a category to a course',
8980: categorizecomm => 'Assign a category to a community',
8981: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 8982: );
8983: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 8984: dom => 'Set in Domain',
8985: crs => 'Set in Course',
8986: comm => 'Set in Community',
8987: place => 'Set in Placement Test',
1.57 raeburn 8988: );
8989: $datatable = '<tr class="LC_odd_row">'.
8990: '<td>'.$title{'togglecats'}.'</td>'.
8991: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
8992: '<input type="radio" name="togglecats"'.
8993: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
8994: '<label><input type="radio" name="togglecats"'.
8995: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
8996: '</tr><tr>'.
8997: '<td>'.$title{'categorize'}.'</td>'.
8998: '<td class="LC_right_item"><span class="LC_nobreak">'.
8999: '<label><input type="radio" name="categorize"'.
9000: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9001: '<label><input type="radio" name="categorize"'.
9002: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9003: '</tr><tr class="LC_odd_row">'.
9004: '<td>'.$title{'togglecatscomm'}.'</td>'.
9005: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9006: '<input type="radio" name="togglecatscomm"'.
9007: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9008: '<label><input type="radio" name="togglecatscomm"'.
9009: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9010: '</tr><tr>'.
9011: '<td>'.$title{'categorizecomm'}.'</td>'.
9012: '<td class="LC_right_item"><span class="LC_nobreak">'.
9013: '<label><input type="radio" name="categorizecomm"'.
9014: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9015: '<label><input type="radio" name="categorizecomm"'.
9016: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 9017: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 9018: '<td>'.$title{'togglecatsplace'}.'</td>'.
9019: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9020: '<input type="radio" name="togglecatsplace"'.
9021: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9022: '<label><input type="radio" name="togglecatscomm"'.
9023: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
9024: '</tr><tr>'.
9025: '<td>'.$title{'categorizeplace'}.'</td>'.
9026: '<td class="LC_right_item"><span class="LC_nobreak">'.
9027: '<label><input type="radio" name="categorizeplace"'.
9028: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9029: '<label><input type="radio" name="categorizeplace"'.
9030: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 9031: '</tr>';
1.272 raeburn 9032: $$rowtotal += 6;
1.57 raeburn 9033: } else {
9034: my $css_class;
9035: my $itemcount = 1;
9036: my $cathash;
9037: if (ref($settings) eq 'HASH') {
9038: $cathash = $settings->{'cats'};
9039: }
9040: if (ref($cathash) eq 'HASH') {
9041: my (@cats,@trails,%allitems,%idx,@jsarray);
9042: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9043: \%allitems,\%idx,\@jsarray);
9044: my $maxdepth = scalar(@cats);
9045: my $colattrib = '';
9046: if ($maxdepth > 2) {
9047: $colattrib = ' colspan="2" ';
9048: }
9049: my @path;
9050: if (@cats > 0) {
9051: if (ref($cats[0]) eq 'ARRAY') {
9052: my $numtop = @{$cats[0]};
9053: my $maxnum = $numtop;
1.120 raeburn 9054: my %default_names = (
9055: instcode => &mt('Official courses'),
9056: communities => &mt('Communities'),
1.272 raeburn 9057: placement => &mt('Placement Tests'),
1.120 raeburn 9058: );
9059:
9060: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9061: ($cathash->{'instcode::0'} eq '') ||
9062: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 9063: ($cathash->{'communities::0'} eq '') ||
9064: (!grep(/^placement$/,@{$cats[0]})) ||
9065: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 9066: $maxnum ++;
9067: }
9068: my $lastidx;
9069: for (my $i=0; $i<$numtop; $i++) {
9070: my $parent = $cats[0][$i];
9071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9072: my $item = &escape($parent).'::0';
9073: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9074: $lastidx = $idx{$item};
9075: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9076: .'<select name="'.$item.'"'.$chgstr.'>';
9077: for (my $k=0; $k<=$maxnum; $k++) {
9078: my $vpos = $k+1;
9079: my $selstr;
9080: if ($k == $i) {
9081: $selstr = ' selected="selected" ';
9082: }
9083: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9084: }
1.214 raeburn 9085: $datatable .= '</select></span></td><td>';
1.272 raeburn 9086: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 9087: $datatable .= '<span class="LC_nobreak">'
9088: .$default_names{$parent}.'</span>';
9089: if ($parent eq 'instcode') {
9090: $datatable .= '<br /><span class="LC_nobreak">('
9091: .&mt('with institutional codes')
9092: .')</span></td><td'.$colattrib.'>';
9093: } else {
9094: $datatable .= '<table><tr><td>';
9095: }
9096: $datatable .= '<span class="LC_nobreak">'
9097: .'<label><input type="radio" name="'
9098: .$parent.'" value="1" checked="checked" />'
9099: .&mt('Display').'</label>';
9100: if ($parent eq 'instcode') {
9101: $datatable .= ' ';
9102: } else {
9103: $datatable .= '</span></td></tr><tr><td>'
9104: .'<span class="LC_nobreak">';
9105: }
9106: $datatable .= '<label><input type="radio" name="'
9107: .$parent.'" value="0" />'
9108: .&mt('Do not display').'</label></span>';
1.272 raeburn 9109: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 9110: $datatable .= '</td></tr></table>';
9111: }
9112: $datatable .= '</td>';
1.57 raeburn 9113: } else {
9114: $datatable .= $parent
1.214 raeburn 9115: .' <span class="LC_nobreak"><label>'
9116: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9117: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9118: }
9119: my $depth = 1;
9120: push(@path,$parent);
9121: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9122: pop(@path);
9123: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9124: $itemcount ++;
9125: }
1.48 raeburn 9126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9127: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9128: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9129: for (my $k=0; $k<=$maxnum; $k++) {
9130: my $vpos = $k+1;
9131: my $selstr;
1.57 raeburn 9132: if ($k == $numtop) {
1.48 raeburn 9133: $selstr = ' selected="selected" ';
9134: }
9135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9136: }
1.59 bisitz 9137: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9138: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9139: .'</tr>'."\n";
1.48 raeburn 9140: $itemcount ++;
1.272 raeburn 9141: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9142: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9143: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9144: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9145: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9146: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9147: for (my $k=0; $k<=$maxnum; $k++) {
9148: my $vpos = $k+1;
9149: my $selstr;
9150: if ($k == $maxnum) {
9151: $selstr = ' selected="selected" ';
9152: }
9153: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9154: }
1.120 raeburn 9155: $datatable .= '</select></span></td>'.
9156: '<td><span class="LC_nobreak">'.
9157: $default_names{$default}.'</span>';
9158: if ($default eq 'instcode') {
9159: $datatable .= '<br /><span class="LC_nobreak">('
9160: .&mt('with institutional codes').')</span>';
9161: }
9162: $datatable .= '</td>'
9163: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9164: .&mt('Display').'</label> '
9165: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9166: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9167: }
9168: }
9169: }
1.57 raeburn 9170: } else {
9171: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9172: }
9173: } else {
1.327 raeburn 9174: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9175: .&initialize_categories($itemcount);
1.48 raeburn 9176: }
1.57 raeburn 9177: $$rowtotal += $itemcount;
1.48 raeburn 9178: }
9179: return $datatable;
9180: }
9181:
1.69 raeburn 9182: sub print_serverstatuses {
9183: my ($dom,$settings,$rowtotal) = @_;
9184: my $datatable;
9185: my @pages = &serverstatus_pages();
9186: my (%namedaccess,%machineaccess);
9187: foreach my $type (@pages) {
9188: $namedaccess{$type} = '';
9189: $machineaccess{$type}= '';
9190: }
9191: if (ref($settings) eq 'HASH') {
9192: foreach my $type (@pages) {
9193: if (exists($settings->{$type})) {
9194: if (ref($settings->{$type}) eq 'HASH') {
9195: foreach my $key (keys(%{$settings->{$type}})) {
9196: if ($key eq 'namedusers') {
9197: $namedaccess{$type} = $settings->{$type}->{$key};
9198: } elsif ($key eq 'machines') {
9199: $machineaccess{$type} = $settings->{$type}->{$key};
9200: }
9201: }
9202: }
9203: }
9204: }
9205: }
1.81 raeburn 9206: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9207: my $rownum = 0;
9208: my $css_class;
9209: foreach my $type (@pages) {
9210: $rownum ++;
9211: $css_class = $rownum%2?' class="LC_odd_row"':'';
9212: $datatable .= '<tr'.$css_class.'>'.
9213: '<td><span class="LC_nobreak">'.
9214: $titles->{$type}.'</span></td>'.
9215: '<td class="LC_left_item">'.
9216: '<input type="text" name="'.$type.'_namedusers" '.
9217: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9218: '<td class="LC_right_item">'.
9219: '<span class="LC_nobreak">'.
9220: '<input type="text" name="'.$type.'_machines" '.
9221: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 9222: '</span></td></tr>'."\n";
1.69 raeburn 9223: }
9224: $$rowtotal += $rownum;
9225: return $datatable;
9226: }
9227:
9228: sub serverstatus_pages {
9229: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 9230: 'checksums','clusterstatus','certstatus','metadata_keywords',
9231: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
9232: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9233: }
9234:
1.236 raeburn 9235: sub defaults_javascript {
9236: my ($settings) = @_;
1.354 raeburn 9237: return unless (ref($settings) eq 'HASH');
1.236 raeburn 9238: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9239: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9240: if ($maxnum eq '') {
9241: $maxnum = 0;
9242: }
9243: $maxnum ++;
1.249 raeburn 9244: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 9245: return <<"ENDSCRIPT";
9246: <script type="text/javascript">
9247: // <![CDATA[
9248: function reorderTypes(form,caller) {
9249: var changedVal;
9250: $jstext
9251: var newpos = 'addinststatus_pos';
9252: var current = new Array;
9253: var maxh = $maxnum;
9254: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9255: var oldVal;
9256: if (caller == newpos) {
9257: changedVal = newitemVal;
9258: } else {
9259: var curritem = 'inststatus_pos_'+caller;
9260: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9261: current[newitemVal] = newpos;
9262: }
9263: for (var i=0; i<inststatuses.length; i++) {
9264: if (inststatuses[i] != caller) {
9265: var elementName = 'inststatus_pos_'+inststatuses[i];
9266: if (form.elements[elementName]) {
9267: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9268: current[currVal] = elementName;
9269: }
9270: }
9271: }
9272: for (var j=0; j<maxh; j++) {
9273: if (current[j] == undefined) {
9274: oldVal = j;
9275: }
9276: }
9277: if (oldVal < changedVal) {
9278: for (var k=oldVal+1; k<=changedVal ; k++) {
9279: var elementName = current[k];
9280: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9281: }
9282: } else {
9283: for (var k=changedVal; k<oldVal; k++) {
9284: var elementName = current[k];
9285: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9286: }
9287: }
9288: return;
9289: }
9290:
9291: // ]]>
9292: </script>
9293:
9294: ENDSCRIPT
9295: }
1.354 raeburn 9296: return;
9297: }
9298:
9299: sub passwords_javascript {
1.365 raeburn 9300: my %intalert = &Apache::lonlocal::texthash (
9301: authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
9302: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
9303: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
9304: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
9305: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
9306: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
9307: );
9308: &js_escape(\%intalert);
9309: my $defmin = $Apache::lonnet::passwdmin;
1.354 raeburn 9310: my $intauthjs = <<"ENDSCRIPT";
9311:
9312: function warnIntAuth(field) {
9313: if (field.name == 'intauth_check') {
9314: if (field.value == '2') {
1.365 raeburn 9315: alert('$intalert{authcheck}');
1.354 raeburn 9316: }
9317: }
9318: if (field.name == 'intauth_cost') {
9319: field.value.replace(/\s/g,'');
9320: if (field.value != '') {
9321: var regexdigit=/^\\d+\$/;
9322: if (!regexdigit.test(field.value)) {
1.365 raeburn 9323: alert('$intalert{authcost}');
9324: }
9325: }
9326: }
9327: return;
9328: }
9329:
9330: function warnIntPass(field) {
9331: field.value.replace(/^\s+/,'');
9332: field.value.replace(/\s+\$/,'');
9333: var regexdigit=/^\\d+\$/;
9334: if (field.name == 'passwords_min') {
9335: if (field.value == '') {
9336: alert('$intalert{passmin}');
9337: field.value = '$defmin';
9338: } else {
9339: if (!regexdigit.test(field.value)) {
9340: alert('$intalert{passmin}');
9341: field.value = '$defmin';
9342: }
1.366 ! raeburn 9343: var minval = parseInt(field.value,10);
1.365 raeburn 9344: if (minval < $defmin) {
9345: alert('$intalert{passmin}');
9346: field.value = '$defmin';
9347: }
9348: }
9349: } else {
9350: if (field.value == '0') {
9351: field.value = '';
9352: }
9353: if (field.value != '') {
9354: if (field.name == 'passwords_expire') {
9355: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
9356: if (!regexpposnum.test(field.value)) {
9357: alert('$intalert{passexp}');
9358: field.value = '';
9359: } else {
9360: var expval = parseFloat(field.value);
9361: if (expval == 0) {
9362: alert('$intalert{passexp}');
9363: field.value = '';
9364: }
9365: }
9366: } else {
9367: if (!regexdigit.test(field.value)) {
9368: if (field.name == 'passwords_max') {
9369: alert('$intalert{passmax}');
9370: } else {
9371: if (field.name == 'passwords_numsaved') {
9372: alert('$intalert{passnum}');
9373: }
9374: }
9375: }
9376: field.value = '';
1.354 raeburn 9377: }
9378: }
9379: }
9380: return;
9381: }
9382:
9383: ENDSCRIPT
9384: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 9385: }
9386:
1.49 raeburn 9387: sub coursecategories_javascript {
9388: my ($settings) = @_;
1.57 raeburn 9389: my ($output,$jstext,$cathash);
1.49 raeburn 9390: if (ref($settings) eq 'HASH') {
1.57 raeburn 9391: $cathash = $settings->{'cats'};
9392: }
9393: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9394: my (@cats,@jsarray,%idx);
1.57 raeburn 9395: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9396: if (@jsarray > 0) {
9397: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9398: for (my $i=0; $i<@jsarray; $i++) {
9399: if (ref($jsarray[$i]) eq 'ARRAY') {
9400: my $catstr = join('","',@{$jsarray[$i]});
9401: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9402: }
9403: }
9404: }
9405: } else {
9406: $jstext = ' var categories = Array(1);'."\n".
9407: ' categories[0] = Array("instcode_pos");'."\n";
9408: }
1.237 bisitz 9409: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9410: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 9411: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 9412: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9413: &js_escape(\$instcode_reserved);
9414: &js_escape(\$communities_reserved);
1.272 raeburn 9415: &js_escape(\$placement_reserved);
1.265 damieng 9416: &js_escape(\$choose_again);
1.49 raeburn 9417: $output = <<"ENDSCRIPT";
9418: <script type="text/javascript">
1.109 raeburn 9419: // <![CDATA[
1.49 raeburn 9420: function reorderCats(form,parent,item,idx) {
9421: var changedVal;
9422: $jstext
9423: var newpos = 'addcategory_pos';
9424: if (parent == '') {
9425: var has_instcode = 0;
9426: var maxtop = categories[idx].length;
9427: for (var j=0; j<maxtop; j++) {
9428: if (categories[idx][j] == 'instcode::0') {
9429: has_instcode == 1;
9430: }
9431: }
9432: if (has_instcode == 0) {
9433: categories[idx][maxtop] = 'instcode_pos';
9434: }
9435: } else {
9436: newpos += '_'+parent;
9437: }
9438: var maxh = 1 + categories[idx].length;
9439: var current = new Array;
9440: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9441: if (item == newpos) {
9442: changedVal = newitemVal;
9443: } else {
9444: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9445: current[newitemVal] = newpos;
9446: }
9447: for (var i=0; i<categories[idx].length; i++) {
9448: var elementName = categories[idx][i];
9449: if (elementName != item) {
9450: if (form.elements[elementName]) {
9451: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9452: current[currVal] = elementName;
9453: }
9454: }
9455: }
9456: var oldVal;
9457: for (var j=0; j<maxh; j++) {
9458: if (current[j] == undefined) {
9459: oldVal = j;
9460: }
9461: }
9462: if (oldVal < changedVal) {
9463: for (var k=oldVal+1; k<=changedVal ; k++) {
9464: var elementName = current[k];
9465: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9466: }
9467: } else {
9468: for (var k=changedVal; k<oldVal; k++) {
9469: var elementName = current[k];
9470: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9471: }
9472: }
9473: return;
9474: }
1.120 raeburn 9475:
9476: function categoryCheck(form) {
9477: if (form.elements['addcategory_name'].value == 'instcode') {
9478: alert('$instcode_reserved\\n$choose_again');
9479: return false;
9480: }
9481: if (form.elements['addcategory_name'].value == 'communities') {
9482: alert('$communities_reserved\\n$choose_again');
9483: return false;
9484: }
1.272 raeburn 9485: if (form.elements['addcategory_name'].value == 'placement') {
9486: alert('$placement_reserved\\n$choose_again');
9487: return false;
9488: }
1.120 raeburn 9489: return true;
9490: }
9491:
1.109 raeburn 9492: // ]]>
1.49 raeburn 9493: </script>
9494:
9495: ENDSCRIPT
9496: return $output;
9497: }
9498:
1.48 raeburn 9499: sub initialize_categories {
9500: my ($itemcount) = @_;
1.120 raeburn 9501: my ($datatable,$css_class,$chgstr);
9502: my %default_names = (
9503: instcode => 'Official courses (with institutional codes)',
9504: communities => 'Communities',
1.272 raeburn 9505: placement => 'Placement Tests',
1.120 raeburn 9506: );
1.328 raeburn 9507: my %selnum = (
9508: instcode => '0',
9509: communities => '1',
9510: placement => '2',
9511: );
9512: my %selected;
1.272 raeburn 9513: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 9514: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 9515: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 9516: map { $selected{$selnum{$_}} = '' } keys(%selnum);
9517: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 9518: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 9519: .'<select name="'.$default.'_pos"'.$chgstr.'>'
9520: .'<option value="0"'.$selected{'0'}.'>1</option>'
9521: .'<option value="1"'.$selected{'1'}.'>2</option>'
9522: .'<option value="2"'.$selected{'2'}.'>3</option>'
9523: .'<option value="3">4</option></select> '
1.120 raeburn 9524: .$default_names{$default}
9525: .'</span></td><td><span class="LC_nobreak">'
9526: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9527: .&mt('Display').'</label> <label>'
9528: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9529: .'</label></span></td></tr>';
1.120 raeburn 9530: $itemcount ++;
9531: }
1.48 raeburn 9532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9533: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9534: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9535: .'<select name="addcategory_pos"'.$chgstr.'>'
9536: .'<option value="0">1</option>'
9537: .'<option value="1">2</option>'
1.328 raeburn 9538: .'<option value="2">3</option>'
9539: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 9540: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
9541: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9542: .'</td></tr>';
1.48 raeburn 9543: return $datatable;
9544: }
9545:
9546: sub build_category_rows {
1.49 raeburn 9547: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9548: my ($text,$name,$item,$chgstr);
1.48 raeburn 9549: if (ref($cats) eq 'ARRAY') {
9550: my $maxdepth = scalar(@{$cats});
9551: if (ref($cats->[$depth]) eq 'HASH') {
9552: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9553: my $numchildren = @{$cats->[$depth]{$parent}};
9554: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 9555: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9556: my ($idxnum,$parent_name,$parent_item);
9557: my $higher = $depth - 1;
9558: if ($higher == 0) {
9559: $parent_name = &escape($parent).'::'.$higher;
9560: } else {
9561: if (ref($path) eq 'ARRAY') {
9562: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9563: }
9564: }
9565: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9566: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9567: if ($j < $numchildren) {
1.48 raeburn 9568: $name = $cats->[$depth]{$parent}[$j];
9569: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9570: $idxnum = $idx->{$item};
9571: } else {
9572: $name = $parent_name;
9573: $item = $parent_item;
1.48 raeburn 9574: }
1.49 raeburn 9575: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9576: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9577: for (my $i=0; $i<=$numchildren; $i++) {
9578: my $vpos = $i+1;
9579: my $selstr;
9580: if ($j == $i) {
9581: $selstr = ' selected="selected" ';
9582: }
9583: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9584: }
9585: $text .= '</select> ';
9586: if ($j < $numchildren) {
9587: my $deeper = $depth+1;
9588: $text .= $name.' '
9589: .'<label><input type="checkbox" name="deletecategory" value="'
9590: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9591: if(ref($path) eq 'ARRAY') {
9592: push(@{$path},$name);
1.49 raeburn 9593: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9594: pop(@{$path});
9595: }
9596: } else {
1.330 raeburn 9597: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9598: if ($j == $numchildren) {
9599: $text .= $name;
9600: } else {
9601: $text .= $item;
9602: }
9603: $text .= '" value="" />';
9604: }
9605: $text .= '</td></tr>';
9606: }
9607: $text .= '</table></td>';
9608: } else {
9609: my $higher = $depth-1;
9610: if ($higher == 0) {
9611: $name = &escape($parent).'::'.$higher;
9612: } else {
9613: if (ref($path) eq 'ARRAY') {
9614: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9615: }
9616: }
9617: my $colspan;
9618: if ($parent ne 'instcode') {
9619: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 9620: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9621: }
9622: }
9623: }
9624: }
9625: return $text;
9626: }
9627:
1.33 raeburn 9628: sub modifiable_userdata_row {
1.305 raeburn 9629: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 9630: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 9631: my ($role,$rolename,$statustype);
9632: $role = $item;
1.224 raeburn 9633: if ($context eq 'cancreate') {
1.305 raeburn 9634: if ($item =~ /^(emailusername)_(.+)$/) {
9635: $role = $1;
9636: $statustype = $2;
1.228 raeburn 9637: if (ref($usertypes) eq 'HASH') {
9638: if ($usertypes->{$statustype}) {
9639: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9640: } else {
9641: $rolename = &mt('Data provided by user');
9642: }
9643: }
1.224 raeburn 9644: }
9645: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9646: if (ref($usertypes) eq 'HASH') {
9647: $rolename = $usertypes->{$role};
9648: } else {
9649: $rolename = $role;
9650: }
1.325 raeburn 9651: } elsif ($context eq 'lti') {
9652: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 9653: } elsif ($context eq 'privacy') {
9654: $rolename = $itemdesc;
1.33 raeburn 9655: } else {
1.63 raeburn 9656: if ($role eq 'cr') {
9657: $rolename = &mt('Custom role');
9658: } else {
9659: $rolename = &Apache::lonnet::plaintext($role);
9660: }
1.33 raeburn 9661: }
1.224 raeburn 9662: my (@fields,%fieldtitles);
9663: if (ref($fieldsref) eq 'ARRAY') {
9664: @fields = @{$fieldsref};
9665: } else {
9666: @fields = ('lastname','firstname','middlename','generation',
9667: 'permanentemail','id');
9668: }
9669: if ((ref($titlesref) eq 'HASH')) {
9670: %fieldtitles = %{$titlesref};
9671: } else {
9672: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9673: }
1.33 raeburn 9674: my $output;
1.305 raeburn 9675: my $css_class;
9676: if ($rowcount%2) {
9677: $css_class = 'LC_odd_row';
9678: }
9679: if ($customcss) {
9680: $css_class .= " $customcss";
9681: }
9682: $css_class =~ s/^\s+//;
9683: if ($css_class) {
9684: $css_class = ' class="'.$css_class.'"';
9685: }
9686: if ($rowstyle) {
9687: $css_class .= ' style="'.$rowstyle.'"';
9688: }
9689: if ($rowid) {
9690: $rowid = ' id="'.$rowid.'"';
9691: }
9692: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9693: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9694: '<td class="LC_left_item" colspan="2"><table>';
9695: my $rem;
9696: my %checks;
1.325 raeburn 9697: my %current;
1.33 raeburn 9698: if (ref($settings) eq 'HASH') {
1.325 raeburn 9699: my $hashref;
9700: if ($context eq 'lti') {
9701: if (ref($settings) eq 'HASH') {
9702: $hashref = $settings->{'instdata'};
9703: }
1.357 raeburn 9704: } elsif ($context eq 'privacy') {
9705: my ($key,$inner) = split(/_/,$role);
9706: if (ref($settings) eq 'HASH') {
9707: if (ref($settings->{$key}) eq 'HASH') {
9708: $hashref = $settings->{$key}->{$inner};
9709: }
9710: }
1.325 raeburn 9711: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 9712: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 9713: $hashref = $settings->{'lti_instdata'};
9714: }
9715: if ($role eq 'emailusername') {
9716: if ($statustype) {
9717: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9718: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 9719: }
1.325 raeburn 9720: }
9721: }
9722: }
9723: if (ref($hashref) eq 'HASH') {
9724: foreach my $field (@fields) {
9725: if ($hashref->{$field}) {
9726: if ($role eq 'emailusername') {
9727: $checks{$field} = $hashref->{$field};
9728: } else {
9729: $checks{$field} = ' checked="checked" ';
1.33 raeburn 9730: }
9731: }
9732: }
9733: }
9734: }
1.305 raeburn 9735:
9736: my $total = scalar(@fields);
9737: for (my $i=0; $i<$total; $i++) {
9738: $rem = $i%($numinrow);
1.33 raeburn 9739: if ($rem == 0) {
9740: if ($i > 0) {
9741: $output .= '</tr>';
9742: }
9743: $output .= '<tr>';
9744: }
9745: my $check = ' ';
1.228 raeburn 9746: unless ($role eq 'emailusername') {
9747: if (exists($checks{$fields[$i]})) {
1.354 raeburn 9748: $check = $checks{$fields[$i]};
1.357 raeburn 9749: } elsif ($context eq 'privacy') {
9750: if ($role =~ /^priv_(domain|course)$/) {
9751: if (ref($settings) ne 'HASH') {
9752: $check = ' checked="checked" ';
9753: }
9754: } elsif ($role =~ /^priv_(author|community)$/) {
9755: if (ref($settings) ne 'HASH') {
9756: unless ($fields[$i] eq 'id') {
9757: $check = ' checked="checked" ';
9758: }
9759: }
9760: } elsif ($role =~ /^(unpriv|othdom)_/) {
9761: if (ref($settings) ne 'HASH') {
9762: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
9763: $check = ' checked="checked" ';
9764: }
9765: }
9766: }
1.325 raeburn 9767: } elsif ($context ne 'lti') {
1.228 raeburn 9768: if ($role eq 'st') {
9769: if (ref($settings) ne 'HASH') {
9770: $check = ' checked="checked" ';
9771: }
1.33 raeburn 9772: }
9773: }
9774: }
9775: $output .= '<td class="LC_left_item">'.
1.228 raeburn 9776: '<span class="LC_nobreak">';
1.325 raeburn 9777: my $prefix = 'canmodify';
1.228 raeburn 9778: if ($role eq 'emailusername') {
9779: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9780: $checks{$fields[$i]} = 'omit';
9781: }
9782: foreach my $option ('required','optional','omit') {
9783: my $checked='';
9784: if ($checks{$fields[$i]} eq $option) {
9785: $checked='checked="checked" ';
9786: }
9787: $output .= '<label>'.
1.325 raeburn 9788: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 9789: &mt($option).'</label>'.(' ' x2);
9790: }
9791: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9792: } else {
1.325 raeburn 9793: if ($context eq 'lti') {
9794: $prefix = 'lti';
1.357 raeburn 9795: } elsif ($context eq 'privacy') {
9796: $prefix = 'privacy';
1.325 raeburn 9797: }
1.228 raeburn 9798: $output .= '<label>'.
1.325 raeburn 9799: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 9800: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9801: '</label>';
9802: }
9803: $output .= '</span></td>';
1.33 raeburn 9804: }
1.305 raeburn 9805: $rem = $total%$numinrow;
9806: my $colsleft;
9807: if ($rem) {
9808: $colsleft = $numinrow - $rem;
9809: }
9810: if ($colsleft > 1) {
1.33 raeburn 9811: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9812: ' </td>';
9813: } elsif ($colsleft == 1) {
9814: $output .= '<td class="LC_left_item"> </td>';
9815: }
9816: $output .= '</tr></table></td></tr>';
9817: return $output;
9818: }
1.28 raeburn 9819:
1.93 raeburn 9820: sub insttypes_row {
1.305 raeburn 9821: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9822: $customcss,$rowstyle) = @_;
1.93 raeburn 9823: my %lt = &Apache::lonlocal::texthash (
9824: cansearch => 'Users allowed to search',
9825: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9826: lockablenames => 'User preference to lock name',
1.305 raeburn 9827: selfassign => 'Self-reportable affiliations',
1.315 raeburn 9828: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9829: );
9830: my $showdom;
9831: if ($context eq 'cansearch') {
9832: $showdom = ' ('.$dom.')';
9833: }
1.165 raeburn 9834: my $class = 'LC_left_item';
9835: if ($context eq 'statustocreate') {
9836: $class = 'LC_right_item';
9837: }
1.305 raeburn 9838: my $css_class;
9839: if ($$rowtotal%2) {
9840: $css_class = 'LC_odd_row';
9841: }
9842: if ($customcss) {
9843: $css_class .= ' '.$customcss;
9844: }
9845: $css_class =~ s/^\s+//;
9846: if ($css_class) {
9847: $css_class = ' class="'.$css_class.'"';
9848: }
9849: if ($rowstyle) {
9850: $css_class .= ' style="'.$rowstyle.'"';
9851: }
9852: if ($onclick) {
9853: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 9854: }
9855: my $output = '<tr'.$css_class.'>'.
9856: '<td>'.$lt{$context}.$showdom.
9857: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9858: my $rem;
9859: if (ref($types) eq 'ARRAY') {
9860: for (my $i=0; $i<@{$types}; $i++) {
9861: if (defined($usertypes->{$types->[$i]})) {
9862: my $rem = $i%($numinrow);
9863: if ($rem == 0) {
9864: if ($i > 0) {
9865: $output .= '</tr>';
9866: }
9867: $output .= '<tr>';
1.23 raeburn 9868: }
1.26 raeburn 9869: my $check = ' ';
1.99 raeburn 9870: if (ref($settings) eq 'HASH') {
9871: if (ref($settings->{$context}) eq 'ARRAY') {
9872: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9873: $check = ' checked="checked" ';
9874: }
1.315 raeburn 9875: } elsif (ref($settings->{$context}) eq 'HASH') {
9876: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9877: $check = ' checked="checked" ';
9878: }
1.99 raeburn 9879: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9880: $check = ' checked="checked" ';
9881: }
1.23 raeburn 9882: }
1.26 raeburn 9883: $output .= '<td class="LC_left_item">'.
9884: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9885: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 9886: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 9887: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9888: }
9889: }
1.26 raeburn 9890: $rem = @{$types}%($numinrow);
1.23 raeburn 9891: }
9892: my $colsleft = $numinrow - $rem;
1.315 raeburn 9893: if ($context eq 'overrides') {
9894: if ($colsleft > 1) {
9895: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9896: } else {
9897: $output .= '<td class="LC_left_item">';
9898: }
9899: $output .= ' ';
1.23 raeburn 9900: } else {
1.334 raeburn 9901: if ($rem == 0) {
1.315 raeburn 9902: $output .= '<tr>';
9903: }
9904: if ($colsleft > 1) {
9905: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9906: } else {
9907: $output .= '<td class="LC_left_item">';
9908: }
9909: my $defcheck = ' ';
9910: if (ref($settings) eq 'HASH') {
9911: if (ref($settings->{$context}) eq 'ARRAY') {
9912: if (grep(/^default$/,@{$settings->{$context}})) {
9913: $defcheck = ' checked="checked" ';
9914: }
9915: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9916: $defcheck = ' checked="checked" ';
9917: }
1.26 raeburn 9918: }
1.315 raeburn 9919: $output .= '<span class="LC_nobreak"><label>'.
9920: '<input type="checkbox" name="'.$context.'" '.
9921: 'value="default"'.$defcheck.$onclick.' />'.
9922: $othertitle.'</label></span>';
1.23 raeburn 9923: }
1.315 raeburn 9924: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9925: return $output;
1.23 raeburn 9926: }
9927:
9928: sub sorted_searchtitles {
9929: my %searchtitles = &Apache::lonlocal::texthash(
9930: 'uname' => 'username',
9931: 'lastname' => 'last name',
9932: 'lastfirst' => 'last name, first name',
9933: );
9934: my @titleorder = ('uname','lastname','lastfirst');
9935: return (\%searchtitles,\@titleorder);
9936: }
9937:
1.25 raeburn 9938: sub sorted_searchtypes {
9939: my %srchtypes_desc = (
9940: exact => 'is exact match',
9941: contains => 'contains ..',
9942: begins => 'begins with ..',
9943: );
9944: my @srchtypeorder = ('exact','begins','contains');
9945: return (\%srchtypes_desc,\@srchtypeorder);
9946: }
9947:
1.3 raeburn 9948: sub usertype_update_row {
9949: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9950: my $datatable;
9951: my $numinrow = 4;
9952: foreach my $type (@{$types}) {
9953: if (defined($usertypes->{$type})) {
9954: $$rownums ++;
9955: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9956: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9957: '</td><td class="LC_left_item"><table>';
9958: for (my $i=0; $i<@{$fields}; $i++) {
9959: my $rem = $i%($numinrow);
9960: if ($rem == 0) {
9961: if ($i > 0) {
9962: $datatable .= '</tr>';
9963: }
9964: $datatable .= '<tr>';
9965: }
9966: my $check = ' ';
1.39 raeburn 9967: if (ref($settings) eq 'HASH') {
9968: if (ref($settings->{'fields'}) eq 'HASH') {
9969: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9970: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9971: $check = ' checked="checked" ';
9972: }
1.3 raeburn 9973: }
9974: }
9975: }
9976:
9977: if ($i == @{$fields}-1) {
9978: my $colsleft = $numinrow - $rem;
9979: if ($colsleft > 1) {
9980: $datatable .= '<td colspan="'.$colsleft.'">';
9981: } else {
9982: $datatable .= '<td>';
9983: }
9984: } else {
9985: $datatable .= '<td>';
9986: }
1.8 raeburn 9987: $datatable .= '<span class="LC_nobreak"><label>'.
9988: '<input type="checkbox" name="updateable_'.$type.
9989: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9990: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9991: }
9992: $datatable .= '</tr></table></td></tr>';
9993: }
9994: }
9995: return $datatable;
1.1 raeburn 9996: }
9997:
9998: sub modify_login {
1.205 raeburn 9999: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 10000: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
10001: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
10002: %title = ( coursecatalog => 'Display course catalog',
10003: adminmail => 'Display administrator E-mail address',
1.188 raeburn 10004: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 10005: newuser => 'Link for visitors to create a user account',
10006: loginheader => 'Log-in box header');
10007: @offon = ('off','on');
1.112 raeburn 10008: if (ref($domconfig{login}) eq 'HASH') {
10009: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10010: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10011: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10012: }
10013: }
10014: }
1.9 raeburn 10015: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10016: \%domconfig,\%loginhash);
1.188 raeburn 10017: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10018: foreach my $item (@toggles) {
10019: $loginhash{login}{$item} = $env{'form.'.$item};
10020: }
1.41 raeburn 10021: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10022: if (ref($colchanges{'login'}) eq 'HASH') {
10023: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10024: \%loginhash);
10025: }
1.110 raeburn 10026:
1.149 raeburn 10027: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 10028: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10029: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10030: if (keys(%servers) > 1) {
10031: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10032: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10033: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10034: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10035: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10036: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10037: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10038: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10039: $changes{'loginvia'}{$lonhost} = 1;
10040: } else {
10041: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10042: $changes{'loginvia'}{$lonhost} = 1;
10043: }
10044: } else {
10045: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10046: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10047: $changes{'loginvia'}{$lonhost} = 1;
10048: }
10049: }
10050: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10051: foreach my $item (@loginvia_attribs) {
10052: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10053: }
10054: } else {
10055: foreach my $item (@loginvia_attribs) {
10056: my $new = $env{'form.'.$lonhost.'_'.$item};
10057: if (($item eq 'serverpath') && ($new eq 'custom')) {
10058: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10059: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10060: $new = '/';
10061: }
10062: }
10063: if (($item eq 'custompath') &&
10064: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10065: $new = '';
10066: }
10067: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10068: $changes{'loginvia'}{$lonhost} = 1;
10069: }
10070: if ($item eq 'exempt') {
1.256 raeburn 10071: $new = &check_exempt_addresses($new);
1.128 raeburn 10072: }
10073: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10074: }
10075: }
1.112 raeburn 10076: } else {
1.128 raeburn 10077: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10078: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10079: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10080: foreach my $item (@loginvia_attribs) {
10081: my $new = $env{'form.'.$lonhost.'_'.$item};
10082: if (($item eq 'serverpath') && ($new eq 'custom')) {
10083: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10084: $new = '/';
10085: }
10086: }
10087: if (($item eq 'custompath') &&
10088: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10089: $new = '';
10090: }
10091: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10092: }
1.110 raeburn 10093: }
10094: }
10095: }
10096: }
1.119 raeburn 10097:
1.168 raeburn 10098: my $servadm = $r->dir_config('lonAdmEMail');
10099: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10100: if (ref($domconfig{'login'}) eq 'HASH') {
10101: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10102: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10103: if ($lang eq 'nolang') {
10104: push(@currlangs,$lang);
10105: } elsif (defined($langchoices{$lang})) {
10106: push(@currlangs,$lang);
10107: } else {
10108: next;
10109: }
10110: }
10111: }
10112: }
10113: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10114: if (@currlangs > 0) {
10115: foreach my $lang (@currlangs) {
10116: if (grep(/^\Q$lang\E$/,@delurls)) {
10117: $changes{'helpurl'}{$lang} = 1;
10118: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10119: $changes{'helpurl'}{$lang} = 1;
10120: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10121: push(@newlangs,$lang);
10122: } else {
10123: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10124: }
10125: }
10126: }
10127: unless (grep(/^nolang$/,@currlangs)) {
10128: if ($env{'form.loginhelpurl_nolang.filename'}) {
10129: $changes{'helpurl'}{'nolang'} = 1;
10130: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10131: push(@newlangs,'nolang');
10132: }
10133: }
10134: if ($env{'form.loginhelpurl_add_lang'}) {
10135: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10136: ($env{'form.loginhelpurl_add_file.filename'})) {
10137: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10138: $addedfile = $env{'form.loginhelpurl_add_lang'};
10139: }
10140: }
10141: if ((@newlangs > 0) || ($addedfile)) {
10142: my $error;
10143: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10144: if ($configuserok eq 'ok') {
10145: if ($switchserver) {
10146: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10147: } elsif ($author_ok eq 'ok') {
10148: my @allnew = @newlangs;
10149: if ($addedfile ne '') {
10150: push(@allnew,$addedfile);
10151: }
10152: foreach my $lang (@allnew) {
10153: my $formelem = 'loginhelpurl_'.$lang;
10154: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10155: $formelem = 'loginhelpurl_add_file';
10156: }
10157: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10158: "help/$lang",'','',$newfile{$lang});
10159: if ($result eq 'ok') {
10160: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10161: $changes{'helpurl'}{$lang} = 1;
10162: } else {
10163: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10164: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 10165: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 10166: (!grep(/^\Q$lang\E$/,@delurls))) {
10167: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10168: }
10169: }
10170: }
10171: } else {
10172: $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);
10173: }
10174: } else {
10175: $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);
10176: }
10177: if ($error) {
10178: &Apache::lonnet::logthis($error);
10179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10180: }
10181: }
1.256 raeburn 10182:
10183: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10184: if (ref($domconfig{'login'}) eq 'HASH') {
10185: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10186: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10187: if ($domservers{$lonhost}) {
10188: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10189: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 10190: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 10191: }
10192: }
10193: }
10194: }
10195: }
10196: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10197: foreach my $lonhost (sort(keys(%domservers))) {
10198: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10199: $changes{'headtag'}{$lonhost} = 1;
10200: } else {
10201: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10202: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10203: }
10204: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10205: push(@newhosts,$lonhost);
10206: } elsif ($currheadtagurls{$lonhost}) {
10207: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10208: if ($currexempt{$lonhost}) {
1.289 raeburn 10209: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 10210: $changes{'headtag'}{$lonhost} = 1;
10211: }
10212: } elsif ($possexempt{$lonhost}) {
10213: $changes{'headtag'}{$lonhost} = 1;
10214: }
10215: if ($possexempt{$lonhost}) {
10216: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10217: }
10218: }
10219: }
10220: }
10221: if (@newhosts) {
10222: my $error;
10223: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10224: if ($configuserok eq 'ok') {
10225: if ($switchserver) {
10226: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10227: } elsif ($author_ok eq 'ok') {
10228: foreach my $lonhost (@newhosts) {
10229: my $formelem = 'loginheadtag_'.$lonhost;
10230: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10231: "login/headtag/$lonhost",'','',
10232: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10233: if ($result eq 'ok') {
10234: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10235: $changes{'headtag'}{$lonhost} = 1;
10236: if ($possexempt{$lonhost}) {
10237: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10238: }
10239: } else {
10240: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10241: $newheadtagurls{$lonhost},$result);
10242: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10243: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10244: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10245: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10246: }
10247: }
10248: }
10249: } else {
10250: $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);
10251: }
10252: } else {
10253: $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);
10254: }
10255: if ($error) {
10256: &Apache::lonnet::logthis($error);
10257: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10258: }
10259: }
1.169 raeburn 10260: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 10261:
10262: my $defaulthelpfile = '/adm/loginproblems.html';
10263: my $defaulttext = &mt('Default in use');
10264:
1.1 raeburn 10265: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10266: $dom);
10267: if ($putresult eq 'ok') {
1.188 raeburn 10268: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10269: my %defaultchecked = (
10270: 'coursecatalog' => 'on',
1.188 raeburn 10271: 'helpdesk' => 'on',
1.42 raeburn 10272: 'adminmail' => 'off',
1.43 raeburn 10273: 'newuser' => 'off',
1.42 raeburn 10274: );
1.55 raeburn 10275: if (ref($domconfig{'login'}) eq 'HASH') {
10276: foreach my $item (@toggles) {
10277: if ($defaultchecked{$item} eq 'on') {
10278: if (($domconfig{'login'}{$item} eq '0') &&
10279: ($env{'form.'.$item} eq '1')) {
10280: $changes{$item} = 1;
10281: } elsif (($domconfig{'login'}{$item} eq '' ||
10282: $domconfig{'login'}{$item} eq '1') &&
10283: ($env{'form.'.$item} eq '0')) {
10284: $changes{$item} = 1;
10285: }
10286: } elsif ($defaultchecked{$item} eq 'off') {
10287: if (($domconfig{'login'}{$item} eq '1') &&
10288: ($env{'form.'.$item} eq '0')) {
10289: $changes{$item} = 1;
10290: } elsif (($domconfig{'login'}{$item} eq '' ||
10291: $domconfig{'login'}{$item} eq '0') &&
10292: ($env{'form.'.$item} eq '1')) {
10293: $changes{$item} = 1;
10294: }
1.42 raeburn 10295: }
10296: }
1.41 raeburn 10297: }
1.6 raeburn 10298: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10299: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10300: if (ref($lastactref) eq 'HASH') {
10301: $lastactref->{'domainconfig'} = 1;
10302: }
1.1 raeburn 10303: $resulttext = &mt('Changes made:').'<ul>';
10304: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10305: if ($item eq 'loginvia') {
1.112 raeburn 10306: if (ref($changes{$item}) eq 'HASH') {
10307: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10308: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10309: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10310: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10311: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10312: $protocol = 'http' if ($protocol ne 'https');
10313: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10314:
10315: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10316: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10317: } else {
10318: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10319: }
10320: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10321: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10322: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10323: }
10324: $resulttext .= '</li>';
10325: } else {
10326: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10327: }
1.112 raeburn 10328: } else {
1.128 raeburn 10329: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10330: }
10331: }
1.128 raeburn 10332: $resulttext .= '</ul></li>';
1.112 raeburn 10333: }
1.168 raeburn 10334: } elsif ($item eq 'helpurl') {
10335: if (ref($changes{$item}) eq 'HASH') {
10336: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10337: if (grep(/^\Q$lang\E$/,@delurls)) {
10338: my ($chg,$link);
10339: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10340: if ($lang eq 'nolang') {
10341: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10342: } else {
10343: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10344: }
10345: $resulttext .= '<li>'.$chg.'</li>';
10346: } else {
10347: my $chg;
10348: if ($lang eq 'nolang') {
10349: $chg = &mt('custom log-in help file for no preferred language');
10350: } else {
10351: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10352: }
10353: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10354: $loginhash{'login'}{'helpurl'}{$lang}.
10355: '?inhibitmenu=yes',$chg,600,500).
10356: '</li>';
10357: }
10358: }
10359: }
1.256 raeburn 10360: } elsif ($item eq 'headtag') {
10361: if (ref($changes{$item}) eq 'HASH') {
10362: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10363: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10364: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10365: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10366: $resulttext .= '<li><a href="'.
10367: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10368: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10369: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10370: if ($possexempt{$lonhost}) {
10371: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10372: } else {
10373: $resulttext .= &mt('included for any client IP');
10374: }
10375: $resulttext .= '</li>';
10376: }
10377: }
10378: }
1.169 raeburn 10379: } elsif ($item eq 'captcha') {
10380: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 10381: my $chgtxt;
1.169 raeburn 10382: if ($loginhash{'login'}{$item} eq 'notused') {
10383: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10384: } else {
10385: my %captchas = &captcha_phrases();
10386: if ($captchas{$loginhash{'login'}{$item}}) {
10387: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10388: } else {
10389: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10390: }
10391: }
10392: $resulttext .= '<li>'.$chgtxt.'</li>';
10393: }
10394: } elsif ($item eq 'recaptchakeys') {
10395: if (ref($loginhash{'login'}) eq 'HASH') {
10396: my ($privkey,$pubkey);
10397: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10398: $pubkey = $loginhash{'login'}{$item}{'public'};
10399: $privkey = $loginhash{'login'}{$item}{'private'};
10400: }
10401: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10402: if (!$pubkey) {
10403: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10404: } else {
10405: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10406: }
10407: if (!$privkey) {
10408: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10409: } else {
1.251 raeburn 10410: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 10411: }
10412: $chgtxt .= '</ul>';
10413: $resulttext .= '<li>'.$chgtxt.'</li>';
10414: }
1.269 raeburn 10415: } elsif ($item eq 'recaptchaversion') {
10416: if (ref($loginhash{'login'}) eq 'HASH') {
10417: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 10418: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 10419: '</li>';
10420: }
10421: }
1.41 raeburn 10422: } else {
10423: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10424: }
1.1 raeburn 10425: }
1.6 raeburn 10426: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10427: } else {
10428: $resulttext = &mt('No changes made to log-in page settings');
10429: }
10430: } else {
1.11 albertel 10431: $resulttext = '<span class="LC_error">'.
10432: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10433: }
1.6 raeburn 10434: if ($errors) {
1.9 raeburn 10435: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10436: $errors.'</ul>';
10437: }
10438: return $resulttext;
10439: }
10440:
1.256 raeburn 10441: sub check_exempt_addresses {
10442: my ($iplist) = @_;
10443: $iplist =~ s/^\s+//;
10444: $iplist =~ s/\s+$//;
10445: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10446: my (@okips,$new);
10447: foreach my $ip (@poss_ips) {
10448: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10449: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10450: push(@okips,$ip);
10451: }
10452: }
10453: }
10454: if (@okips > 0) {
10455: $new = join(',',@okips);
10456: } else {
10457: $new = '';
10458: }
10459: return $new;
10460: }
10461:
1.6 raeburn 10462: sub color_font_choices {
10463: my %choices =
10464: &Apache::lonlocal::texthash (
10465: img => "Header",
10466: bgs => "Background colors",
10467: links => "Link colors",
1.55 raeburn 10468: images => "Images",
1.6 raeburn 10469: font => "Font color",
1.201 raeburn 10470: fontmenu => "Font menu",
1.76 raeburn 10471: pgbg => "Page",
1.6 raeburn 10472: tabbg => "Header",
10473: sidebg => "Border",
10474: link => "Link",
10475: alink => "Active link",
10476: vlink => "Visited link",
10477: );
10478: return %choices;
10479: }
10480:
10481: sub modify_rolecolors {
1.205 raeburn 10482: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10483: my ($resulttext,%rolehash);
10484: $rolehash{'rolecolors'} = {};
1.55 raeburn 10485: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10486: if ($domconfig{'rolecolors'} eq '') {
10487: $domconfig{'rolecolors'} = {};
10488: }
10489: }
1.9 raeburn 10490: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10491: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10492: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10493: $dom);
10494: if ($putresult eq 'ok') {
10495: if (keys(%changes) > 0) {
1.41 raeburn 10496: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10497: if (ref($lastactref) eq 'HASH') {
10498: $lastactref->{'domainconfig'} = 1;
10499: }
1.6 raeburn 10500: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10501: $rolehash{'rolecolors'});
10502: } else {
10503: $resulttext = &mt('No changes made to default color schemes');
10504: }
10505: } else {
1.11 albertel 10506: $resulttext = '<span class="LC_error">'.
10507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10508: }
10509: if ($errors) {
10510: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10511: $errors.'</ul>';
10512: }
10513: return $resulttext;
10514: }
10515:
10516: sub modify_colors {
1.9 raeburn 10517: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10518: my (%changes,%choices);
1.51 raeburn 10519: my @bgs;
1.6 raeburn 10520: my @links = ('link','alink','vlink');
1.41 raeburn 10521: my @logintext;
1.6 raeburn 10522: my @images;
10523: my $servadm = $r->dir_config('lonAdmEMail');
10524: my $errors;
1.200 raeburn 10525: my %defaults;
1.6 raeburn 10526: foreach my $role (@{$roles}) {
10527: if ($role eq 'login') {
1.12 raeburn 10528: %choices = &login_choices();
1.41 raeburn 10529: @logintext = ('textcol','bgcol');
1.12 raeburn 10530: } else {
10531: %choices = &color_font_choices();
10532: }
10533: if ($role eq 'login') {
1.41 raeburn 10534: @images = ('img','logo','domlogo','login');
1.51 raeburn 10535: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10536: } else {
10537: @images = ('img');
1.200 raeburn 10538: @bgs = ('pgbg','tabbg','sidebg');
10539: }
10540: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10541: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10542: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10543: }
10544: if ($role eq 'login') {
10545: foreach my $item (@logintext) {
1.234 raeburn 10546: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10547: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10548: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10549: }
10550: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 10551: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10552: }
10553: }
10554: } else {
1.234 raeburn 10555: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10556: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10557: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10558: }
10559: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 10560: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10561: }
1.6 raeburn 10562: }
1.200 raeburn 10563: foreach my $item (@bgs) {
1.234 raeburn 10564: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10565: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10566: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10567: }
10568: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 10569: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10570: }
10571: }
10572: foreach my $item (@links) {
1.234 raeburn 10573: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10574: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10575: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10576: }
10577: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 10578: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10579: }
1.6 raeburn 10580: }
1.46 raeburn 10581: my ($configuserok,$author_ok,$switchserver) =
10582: &config_check($dom,$confname,$servadm);
1.9 raeburn 10583: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 10584: if (ref($domconfig->{$role}) ne 'HASH') {
10585: $domconfig->{$role} = {};
10586: }
1.8 raeburn 10587: foreach my $img (@images) {
1.70 raeburn 10588: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
10589: if (defined($env{'form.login_showlogo_'.$img})) {
10590: $confhash->{$role}{'showlogo'}{$img} = 1;
10591: } else {
10592: $confhash->{$role}{'showlogo'}{$img} = 0;
10593: }
10594: }
1.18 albertel 10595: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
10596: && !defined($domconfig->{$role}{$img})
10597: && !$env{'form.'.$role.'_del_'.$img}
10598: && $env{'form.'.$role.'_import_'.$img}) {
10599: # import the old configured image from the .tab setting
10600: # if they haven't provided a new one
10601: $domconfig->{$role}{$img} =
10602: $env{'form.'.$role.'_import_'.$img};
10603: }
1.6 raeburn 10604: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 10605: my $error;
1.6 raeburn 10606: if ($configuserok eq 'ok') {
1.9 raeburn 10607: if ($switchserver) {
1.12 raeburn 10608: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 10609: } else {
10610: if ($author_ok eq 'ok') {
10611: my ($result,$logourl) =
10612: &publishlogo($r,'upload',$role.'_'.$img,
10613: $dom,$confname,$img,$width,$height);
10614: if ($result eq 'ok') {
10615: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 10616: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10617: } else {
1.12 raeburn 10618: $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 10619: }
10620: } else {
1.46 raeburn 10621: $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 10622: }
10623: }
10624: } else {
1.46 raeburn 10625: $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 10626: }
10627: if ($error) {
1.8 raeburn 10628: &Apache::lonnet::logthis($error);
1.11 albertel 10629: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 10630: }
10631: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 10632: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
10633: my $error;
10634: if ($configuserok eq 'ok') {
10635: # is confname an author?
10636: if ($switchserver eq '') {
10637: if ($author_ok eq 'ok') {
10638: my ($result,$logourl) =
10639: &publishlogo($r,'copy',$domconfig->{$role}{$img},
10640: $dom,$confname,$img,$width,$height);
10641: if ($result eq 'ok') {
10642: $confhash->{$role}{$img} = $logourl;
1.18 albertel 10643: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 10644: }
10645: }
10646: }
10647: }
1.6 raeburn 10648: }
10649: }
10650: }
10651: if (ref($domconfig) eq 'HASH') {
10652: if (ref($domconfig->{$role}) eq 'HASH') {
10653: foreach my $img (@images) {
10654: if ($domconfig->{$role}{$img} ne '') {
10655: if ($env{'form.'.$role.'_del_'.$img}) {
10656: $confhash->{$role}{$img} = '';
1.12 raeburn 10657: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10658: } else {
1.9 raeburn 10659: if ($confhash->{$role}{$img} eq '') {
10660: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
10661: }
1.6 raeburn 10662: }
10663: } else {
10664: if ($env{'form.'.$role.'_del_'.$img}) {
10665: $confhash->{$role}{$img} = '';
1.12 raeburn 10666: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 10667: }
10668: }
1.70 raeburn 10669: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
10670: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
10671: if ($confhash->{$role}{'showlogo'}{$img} ne
10672: $domconfig->{$role}{'showlogo'}{$img}) {
10673: $changes{$role}{'showlogo'}{$img} = 1;
10674: }
10675: } else {
10676: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10677: $changes{$role}{'showlogo'}{$img} = 1;
10678: }
10679: }
10680: }
10681: }
1.6 raeburn 10682: if ($domconfig->{$role}{'font'} ne '') {
10683: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
10684: $changes{$role}{'font'} = 1;
10685: }
10686: } else {
10687: if ($confhash->{$role}{'font'}) {
10688: $changes{$role}{'font'} = 1;
10689: }
10690: }
1.107 raeburn 10691: if ($role ne 'login') {
10692: if ($domconfig->{$role}{'fontmenu'} ne '') {
10693: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
10694: $changes{$role}{'fontmenu'} = 1;
10695: }
10696: } else {
10697: if ($confhash->{$role}{'fontmenu'}) {
10698: $changes{$role}{'fontmenu'} = 1;
10699: }
1.97 tempelho 10700: }
10701: }
1.6 raeburn 10702: foreach my $item (@bgs) {
10703: if ($domconfig->{$role}{$item} ne '') {
10704: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10705: $changes{$role}{'bgs'}{$item} = 1;
10706: }
10707: } else {
10708: if ($confhash->{$role}{$item}) {
10709: $changes{$role}{'bgs'}{$item} = 1;
10710: }
10711: }
10712: }
10713: foreach my $item (@links) {
10714: if ($domconfig->{$role}{$item} ne '') {
10715: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10716: $changes{$role}{'links'}{$item} = 1;
10717: }
10718: } else {
10719: if ($confhash->{$role}{$item}) {
10720: $changes{$role}{'links'}{$item} = 1;
10721: }
10722: }
10723: }
1.41 raeburn 10724: foreach my $item (@logintext) {
10725: if ($domconfig->{$role}{$item} ne '') {
10726: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
10727: $changes{$role}{'logintext'}{$item} = 1;
10728: }
10729: } else {
10730: if ($confhash->{$role}{$item}) {
10731: $changes{$role}{'logintext'}{$item} = 1;
10732: }
10733: }
10734: }
1.6 raeburn 10735: } else {
10736: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10737: \@logintext,$confhash,\%changes);
1.6 raeburn 10738: }
10739: } else {
10740: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 10741: \@logintext,$confhash,\%changes);
1.6 raeburn 10742: }
10743: }
10744: return ($errors,%changes);
10745: }
10746:
1.46 raeburn 10747: sub config_check {
10748: my ($dom,$confname,$servadm) = @_;
10749: my ($configuserok,$author_ok,$switchserver,%currroles);
10750: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
10751: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
10752: $confname,$servadm);
10753: if ($configuserok eq 'ok') {
10754: $switchserver = &check_switchserver($dom,$confname);
10755: if ($switchserver eq '') {
10756: $author_ok = &check_authorstatus($dom,$confname,%currroles);
10757: }
10758: }
10759: return ($configuserok,$author_ok,$switchserver);
10760: }
10761:
1.6 raeburn 10762: sub default_change_checker {
1.41 raeburn 10763: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 10764: foreach my $item (@{$links}) {
10765: if ($confhash->{$role}{$item}) {
10766: $changes->{$role}{'links'}{$item} = 1;
10767: }
10768: }
10769: foreach my $item (@{$bgs}) {
10770: if ($confhash->{$role}{$item}) {
10771: $changes->{$role}{'bgs'}{$item} = 1;
10772: }
10773: }
1.41 raeburn 10774: foreach my $item (@{$logintext}) {
10775: if ($confhash->{$role}{$item}) {
10776: $changes->{$role}{'logintext'}{$item} = 1;
10777: }
10778: }
1.6 raeburn 10779: foreach my $img (@{$images}) {
10780: if ($env{'form.'.$role.'_del_'.$img}) {
10781: $confhash->{$role}{$img} = '';
1.12 raeburn 10782: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 10783: }
1.70 raeburn 10784: if ($role eq 'login') {
10785: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
10786: $changes->{$role}{'showlogo'}{$img} = 1;
10787: }
10788: }
1.6 raeburn 10789: }
10790: if ($confhash->{$role}{'font'}) {
10791: $changes->{$role}{'font'} = 1;
10792: }
1.48 raeburn 10793: }
1.6 raeburn 10794:
10795: sub display_colorchgs {
10796: my ($dom,$changes,$roles,$confhash) = @_;
10797: my (%choices,$resulttext);
10798: if (!grep(/^login$/,@{$roles})) {
10799: $resulttext = &mt('Changes made:').'<br />';
10800: }
10801: foreach my $role (@{$roles}) {
10802: if ($role eq 'login') {
10803: %choices = &login_choices();
10804: } else {
10805: %choices = &color_font_choices();
10806: }
10807: if (ref($changes->{$role}) eq 'HASH') {
10808: if ($role ne 'login') {
10809: $resulttext .= '<h4>'.&mt($role).'</h4>';
10810: }
10811: foreach my $key (sort(keys(%{$changes->{$role}}))) {
10812: if ($role ne 'login') {
10813: $resulttext .= '<ul>';
10814: }
10815: if (ref($changes->{$role}{$key}) eq 'HASH') {
10816: if ($role ne 'login') {
10817: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
10818: }
10819: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 10820: if (($role eq 'login') && ($key eq 'showlogo')) {
10821: if ($confhash->{$role}{$key}{$item}) {
10822: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
10823: } else {
10824: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
10825: }
10826: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 10827: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
10828: } else {
1.12 raeburn 10829: my $newitem = $confhash->{$role}{$item};
10830: if ($key eq 'images') {
1.306 raeburn 10831: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 10832: }
10833: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 10834: }
10835: }
10836: if ($role ne 'login') {
10837: $resulttext .= '</ul></li>';
10838: }
10839: } else {
10840: if ($confhash->{$role}{$key} eq '') {
10841: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
10842: } else {
10843: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
10844: }
10845: }
10846: if ($role ne 'login') {
10847: $resulttext .= '</ul>';
10848: }
10849: }
10850: }
10851: }
1.3 raeburn 10852: return $resulttext;
1.1 raeburn 10853: }
10854:
1.9 raeburn 10855: sub thumb_dimensions {
10856: return ('200','50');
10857: }
10858:
1.16 raeburn 10859: sub check_dimensions {
10860: my ($inputfile) = @_;
10861: my ($fullwidth,$fullheight);
10862: if ($inputfile =~ m|^[/\w.\-]+$|) {
10863: if (open(PIPE,"identify $inputfile 2>&1 |")) {
10864: my $imageinfo = <PIPE>;
10865: if (!close(PIPE)) {
10866: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
10867: }
10868: chomp($imageinfo);
10869: my ($fullsize) =
1.21 raeburn 10870: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 10871: if ($fullsize) {
10872: ($fullwidth,$fullheight) = split(/x/,$fullsize);
10873: }
10874: }
10875: }
10876: return ($fullwidth,$fullheight);
10877: }
10878:
1.9 raeburn 10879: sub check_configuser {
10880: my ($uhome,$dom,$confname,$servadm) = @_;
10881: my ($configuserok,%currroles);
10882: if ($uhome eq 'no_host') {
10883: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 10884: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 10885: $configuserok =
10886: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
10887: $configpass,'','','','','',undef,$servadm);
10888: } else {
10889: $configuserok = 'ok';
10890: %currroles =
10891: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
10892: }
10893: return ($configuserok,%currroles);
10894: }
10895:
10896: sub check_authorstatus {
10897: my ($dom,$confname,%currroles) = @_;
10898: my $author_ok;
1.40 raeburn 10899: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 10900: my $start = time;
10901: my $end = 0;
10902: $author_ok =
10903: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 10904: 'au',$end,$start,'','','domconfig');
1.9 raeburn 10905: } else {
10906: $author_ok = 'ok';
10907: }
10908: return $author_ok;
10909: }
10910:
10911: sub publishlogo {
1.46 raeburn 10912: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 10913: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 10914: if ($action eq 'upload') {
10915: $fname=$env{'form.'.$formname.'.filename'};
10916: chop($env{'form.'.$formname});
10917: } else {
10918: ($fname) = ($formname =~ /([^\/]+)$/);
10919: }
1.46 raeburn 10920: if ($savefileas ne '') {
10921: $fname = $savefileas;
10922: }
1.9 raeburn 10923: $fname=&Apache::lonnet::clean_filename($fname);
10924: # See if there is anything left
10925: unless ($fname) { return ('error: no uploaded file'); }
10926: $fname="$subdir/$fname";
1.210 raeburn 10927: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 10928: my $filepath="$docroot/priv";
10929: my $relpath = "$dom/$confname";
1.9 raeburn 10930: my ($fnamepath,$file,$fetchthumb);
10931: $file=$fname;
10932: if ($fname=~m|/|) {
10933: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
10934: }
1.164 raeburn 10935: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 10936: my $count;
1.164 raeburn 10937: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 10938: $filepath.="/$parts[$count]";
10939: if ((-e $filepath)!=1) {
10940: mkdir($filepath,02770);
10941: }
10942: }
10943: # Check for bad extension and disallow upload
10944: if ($file=~/\.(\w+)$/ &&
10945: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
10946: $output =
1.207 bisitz 10947: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 10948: } elsif ($file=~/\.(\w+)$/ &&
10949: !defined(&Apache::loncommon::fileembstyle($1))) {
10950: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
10951: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 10952: $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 10953: } elsif (-d "$filepath/$file") {
1.195 bisitz 10954: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 10955: } else {
10956: my $source = $filepath.'/'.$file;
10957: my $logfile;
1.316 raeburn 10958: if (!open($logfile,">>",$source.'.log')) {
1.196 raeburn 10959: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 10960: }
10961: print $logfile
10962: "\n================= Publish ".localtime()." ================\n".
10963: $env{'user.name'}.':'.$env{'user.domain'}."\n";
10964: # Save the file
1.316 raeburn 10965: if (!open(FH,">",$source)) {
1.9 raeburn 10966: &Apache::lonnet::logthis('Failed to create '.$source);
10967: return (&mt('Failed to create file'));
10968: }
10969: if ($action eq 'upload') {
10970: if (!print FH ($env{'form.'.$formname})) {
10971: &Apache::lonnet::logthis('Failed to write to '.$source);
10972: return (&mt('Failed to write file'));
10973: }
10974: } else {
10975: my $original = &Apache::lonnet::filelocation('',$formname);
10976: if(!copy($original,$source)) {
10977: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
10978: return (&mt('Failed to write file'));
10979: }
10980: }
10981: close(FH);
10982: chmod(0660, $source); # Permissions to rw-rw---.
10983:
10984: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
10985: my $copyfile=$targetdir.'/'.$file;
10986:
10987: my @parts=split(/\//,$targetdir);
10988: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
10989: for (my $count=5;$count<=$#parts;$count++) {
10990: $path.="/$parts[$count]";
10991: if (!-e $path) {
10992: print $logfile "\nCreating directory ".$path;
10993: mkdir($path,02770);
10994: }
10995: }
10996: my $versionresult;
10997: if (-e $copyfile) {
10998: $versionresult = &logo_versioning($targetdir,$file,$logfile);
10999: } else {
11000: $versionresult = 'ok';
11001: }
11002: if ($versionresult eq 'ok') {
11003: if (copy($source,$copyfile)) {
11004: print $logfile "\nCopied original source to ".$copyfile."\n";
11005: $output = 'ok';
11006: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11007: push(@{$modified_urls},[$copyfile,$source]);
11008: my $metaoutput =
11009: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11010: unless ($registered_cleanup) {
11011: my $handlers = $r->get_handlers('PerlCleanupHandler');
11012: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11013: $registered_cleanup=1;
11014: }
1.9 raeburn 11015: } else {
11016: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11017: $output = &mt('Failed to copy file to RES space').", $!";
11018: }
11019: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11020: my $inputfile = $filepath.'/'.$file;
11021: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11022: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11023: if ($fullwidth ne '' && $fullheight ne '') {
11024: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11025: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316 raeburn 11026: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11027: system({$args[0]} @args);
1.16 raeburn 11028: chmod(0660, $filepath.'/tn-'.$file);
11029: if (-e $outfile) {
11030: my $copyfile=$targetdir.'/tn-'.$file;
11031: if (copy($outfile,$copyfile)) {
11032: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11033: my $thumb_metaoutput =
11034: &write_metadata($dom,$confname,$formname,
11035: $targetdir,'tn-'.$file,$logfile);
11036: push(@{$modified_urls},[$copyfile,$outfile]);
11037: unless ($registered_cleanup) {
11038: my $handlers = $r->get_handlers('PerlCleanupHandler');
11039: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11040: $registered_cleanup=1;
11041: }
1.267 raeburn 11042: $madethumb = 1;
1.16 raeburn 11043: } else {
11044: print $logfile "\nUnable to write ".$copyfile.
11045: ':'.$!."\n";
11046: }
11047: }
1.9 raeburn 11048: }
11049: }
11050: }
11051: } else {
11052: $output = $versionresult;
11053: }
11054: }
1.267 raeburn 11055: return ($output,$logourl,$madethumb);
1.9 raeburn 11056: }
11057:
11058: sub logo_versioning {
11059: my ($targetdir,$file,$logfile) = @_;
11060: my $target = $targetdir.'/'.$file;
11061: my ($maxversion,$fn,$extn,$output);
11062: $maxversion = 0;
11063: if ($file =~ /^(.+)\.(\w+)$/) {
11064: $fn=$1;
11065: $extn=$2;
11066: }
11067: opendir(DIR,$targetdir);
11068: while (my $filename=readdir(DIR)) {
11069: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11070: $maxversion=($1>$maxversion)?$1:$maxversion;
11071: }
11072: }
11073: $maxversion++;
11074: print $logfile "\nCreating old version ".$maxversion."\n";
11075: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11076: if (copy($target,$copyfile)) {
11077: print $logfile "Copied old target to ".$copyfile."\n";
11078: $copyfile=$copyfile.'.meta';
11079: if (copy($target.'.meta',$copyfile)) {
11080: print $logfile "Copied old target metadata to ".$copyfile."\n";
11081: $output = 'ok';
11082: } else {
11083: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11084: $output = &mt('Failed to copy old meta').", $!, ";
11085: }
11086: } else {
11087: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11088: $output = &mt('Failed to copy old target').", $!, ";
11089: }
11090: return $output;
11091: }
11092:
11093: sub write_metadata {
11094: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11095: my (%metadatafields,%metadatakeys,$output);
11096: $metadatafields{'title'}=$formname;
11097: $metadatafields{'creationdate'}=time;
11098: $metadatafields{'lastrevisiondate'}=time;
11099: $metadatafields{'copyright'}='public';
11100: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11101: $env{'user.domain'};
11102: $metadatafields{'authorspace'}=$confname.':'.$dom;
11103: $metadatafields{'domain'}=$dom;
11104: {
11105: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11106: my $mfh;
1.316 raeburn 11107: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 11108: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11109: unless ($_=~/\./) {
11110: my $unikey=$_;
11111: $unikey=~/^([A-Za-z]+)/;
11112: my $tag=$1;
11113: $tag=~tr/A-Z/a-z/;
11114: print $mfh "\n\<$tag";
11115: foreach (split(/\,/,$metadatakeys{$unikey})) {
11116: my $value=$metadatafields{$unikey.'.'.$_};
11117: $value=~s/\"/\'\'/g;
11118: print $mfh ' '.$_.'="'.$value.'"';
11119: }
11120: print $mfh '>'.
11121: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11122: .'</'.$tag.'>';
11123: }
11124: }
11125: $output = 'ok';
11126: print $logfile "\nWrote metadata";
11127: close($mfh);
11128: } else {
11129: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11130: $output = &mt('Could not write metadata');
11131: }
11132: }
1.155 raeburn 11133: return $output;
11134: }
11135:
11136: sub notifysubscribed {
11137: foreach my $targetsource (@{$modified_urls}){
11138: next unless (ref($targetsource) eq 'ARRAY');
11139: my ($target,$source)=@{$targetsource};
11140: if ($source ne '') {
1.316 raeburn 11141: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11142: print $logfh "\nCleanup phase: Notifications\n";
11143: my @subscribed=&subscribed_hosts($target);
11144: foreach my $subhost (@subscribed) {
11145: print $logfh "\nNotifying host ".$subhost.':';
11146: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11147: print $logfh $reply;
11148: }
11149: my @subscribedmeta=&subscribed_hosts("$target.meta");
11150: foreach my $subhost (@subscribedmeta) {
11151: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11152: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11153: $subhost);
11154: print $logfh $reply;
11155: }
11156: print $logfh "\n============ Done ============\n";
1.160 raeburn 11157: close($logfh);
1.155 raeburn 11158: }
11159: }
11160: }
11161: return OK;
11162: }
11163:
11164: sub subscribed_hosts {
11165: my ($target) = @_;
11166: my @subscribed;
1.316 raeburn 11167: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11168: while (my $subline=<$fh>) {
11169: if ($subline =~ /^($match_lonid):/) {
11170: my $host = $1;
11171: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11172: unless (grep(/^\Q$host\E$/,@subscribed)) {
11173: push(@subscribed,$host);
11174: }
11175: }
11176: }
11177: }
11178: }
11179: return @subscribed;
1.9 raeburn 11180: }
11181:
11182: sub check_switchserver {
11183: my ($dom,$confname) = @_;
11184: my ($allowed,$switchserver);
11185: my $home = &Apache::lonnet::homeserver($confname,$dom);
11186: if ($home eq 'no_host') {
11187: $home = &Apache::lonnet::domain($dom,'primary');
11188: }
11189: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11190: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11191: if (!$allowed) {
1.180 raeburn 11192: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11193: }
11194: return $switchserver;
11195: }
11196:
1.1 raeburn 11197: sub modify_quotas {
1.216 raeburn 11198: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11199: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 11200: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 11201: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11202: $validationfieldsref);
1.86 raeburn 11203: if ($action eq 'quotas') {
11204: $context = 'tools';
1.163 raeburn 11205: } else {
1.86 raeburn 11206: $context = $action;
11207: }
11208: if ($context eq 'requestcourses') {
1.325 raeburn 11209: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 11210: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11211: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11212: %titles = &courserequest_titles();
11213: $toolregexp = join('|',@usertools);
11214: %conditions = &courserequest_conditions();
1.216 raeburn 11215: $confname = $dom.'-domainconfig';
11216: my $servadm = $r->dir_config('lonAdmEMail');
11217: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 11218: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11219: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 11220: } elsif ($context eq 'requestauthor') {
11221: @usertools = ('author');
11222: %titles = &authorrequest_titles();
1.86 raeburn 11223: } else {
1.162 raeburn 11224: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11225: %titles = &tool_titles();
1.86 raeburn 11226: }
1.212 raeburn 11227: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11228: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11229: foreach my $key (keys(%env)) {
1.101 raeburn 11230: if ($context eq 'requestcourses') {
11231: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11232: my $item = $1;
11233: my $type = $2;
11234: if ($type =~ /^limit_(.+)/) {
11235: $limithash{$item}{$1} = $env{$key};
11236: } else {
11237: $confhash{$item}{$type} = $env{$key};
11238: }
11239: }
1.163 raeburn 11240: } elsif ($context eq 'requestauthor') {
11241: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11242: $confhash{$1} = $env{$key};
11243: }
1.101 raeburn 11244: } else {
1.86 raeburn 11245: if ($key =~ /^form\.quota_(.+)$/) {
11246: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 11247: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11248: $confhash{'authorquota'}{$1} = $env{$key};
11249: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11250: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11251: }
1.72 raeburn 11252: }
11253: }
1.163 raeburn 11254: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 11255: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11256: @approvalnotify = sort(@approvalnotify);
11257: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 11258: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 11259: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11260: foreach my $type (@hasuniquecode) {
11261: if (grep(/^\Q$type\E$/,@crstypes)) {
11262: $confhash{'uniquecode'}{$type} = 1;
11263: }
1.216 raeburn 11264: }
1.242 raeburn 11265: my (%newbook,%allpos);
1.216 raeburn 11266: if ($context eq 'requestcourses') {
1.242 raeburn 11267: foreach my $type ('textbooks','templates') {
11268: @{$allpos{$type}} = ();
11269: my $invalid;
11270: if ($type eq 'textbooks') {
11271: $invalid = &mt('Invalid LON-CAPA course for textbook');
11272: } else {
11273: $invalid = &mt('Invalid LON-CAPA course for template');
11274: }
11275: if ($env{'form.'.$type.'_addbook'}) {
11276: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11277: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11278: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11279: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11280: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11281: } else {
11282: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11283: my $position = $env{'form.'.$type.'_addbook_pos'};
11284: $position =~ s/\D+//g;
11285: if ($position ne '') {
11286: $allpos{$type}[$position] = $newbook{$type};
11287: }
1.216 raeburn 11288: }
1.242 raeburn 11289: } else {
11290: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 11291: }
11292: }
1.242 raeburn 11293: }
1.216 raeburn 11294: }
1.102 raeburn 11295: if (ref($domconfig{$action}) eq 'HASH') {
11296: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11297: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11298: $changes{'notify'}{'approval'} = 1;
11299: }
11300: } else {
1.144 raeburn 11301: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11302: $changes{'notify'}{'approval'} = 1;
11303: }
11304: }
1.218 raeburn 11305: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11306: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11307: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11308: unless ($confhash{'uniquecode'}{$crstype}) {
11309: $changes{'uniquecode'} = 1;
11310: }
11311: }
11312: unless ($changes{'uniquecode'}) {
11313: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11314: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11315: $changes{'uniquecode'} = 1;
11316: }
11317: }
11318: }
11319: } else {
11320: $changes{'uniquecode'} = 1;
11321: }
11322: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11323: $changes{'uniquecode'} = 1;
1.216 raeburn 11324: }
11325: if ($context eq 'requestcourses') {
1.242 raeburn 11326: foreach my $type ('textbooks','templates') {
11327: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11328: my %deletions;
11329: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11330: if (@todelete) {
11331: map { $deletions{$_} = 1; } @todelete;
11332: }
11333: my %imgdeletions;
11334: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11335: if (@todeleteimages) {
11336: map { $imgdeletions{$_} = 1; } @todeleteimages;
11337: }
11338: my $maxnum = $env{'form.'.$type.'_maxnum'};
11339: for (my $i=0; $i<=$maxnum; $i++) {
11340: my $itemid = $env{'form.'.$type.'_id_'.$i};
11341: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11342: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11343: if ($deletions{$key}) {
11344: if ($domconfig{$action}{$type}{$key}{'image'}) {
11345: #FIXME need to obsolete item in RES space
11346: }
11347: next;
11348: } else {
11349: my $newpos = $env{'form.'.$itemid};
11350: $newpos =~ s/\D+//g;
1.243 raeburn 11351: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 11352: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 11353: ($type eq 'templates'));
1.242 raeburn 11354: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11355: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11356: $changes{$type}{$key} = 1;
11357: }
11358: }
11359: $allpos{$type}[$newpos] = $key;
11360: }
11361: if ($imgdeletions{$key}) {
11362: $changes{$type}{$key} = 1;
1.216 raeburn 11363: #FIXME need to obsolete item in RES space
1.242 raeburn 11364: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11365: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 11366: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11367: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11368: } else {
11369: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11370: $cdom,$cnum,$type,$configuserok,
11371: $switchserver,$author_ok);
11372: if ($imgurl) {
11373: $confhash{$type}{$key}{'image'} = $imgurl;
11374: $changes{$type}{$key} = 1;
11375: }
11376: if ($error) {
11377: &Apache::lonnet::logthis($error);
11378: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11379: }
11380: }
1.242 raeburn 11381: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11382: $confhash{$type}{$key}{'image'} =
11383: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 11384: }
11385: }
11386: }
11387: }
11388: }
11389: }
1.102 raeburn 11390: } else {
1.144 raeburn 11391: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11392: $changes{'notify'}{'approval'} = 1;
11393: }
1.218 raeburn 11394: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 11395: $changes{'uniquecode'} = 1;
11396: }
11397: }
11398: if ($context eq 'requestcourses') {
1.242 raeburn 11399: foreach my $type ('textbooks','templates') {
11400: if ($newbook{$type}) {
11401: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 11402: foreach my $item ('subject','title','publisher','author') {
11403: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11404: ($type eq 'template'));
1.242 raeburn 11405: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11406: if ($env{'form.'.$type.'_addbook_'.$item}) {
11407: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11408: }
11409: }
11410: if ($type eq 'textbooks') {
11411: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11412: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 11413: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11414: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11415: } else {
11416: my ($imageurl,$error) =
11417: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11418: $configuserok,$switchserver,$author_ok);
11419: if ($imageurl) {
11420: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11421: }
11422: if ($error) {
11423: &Apache::lonnet::logthis($error);
11424: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11425: }
1.242 raeburn 11426: }
11427: }
1.216 raeburn 11428: }
11429: }
1.242 raeburn 11430: if (@{$allpos{$type}} > 0) {
11431: my $idx = 0;
11432: foreach my $item (@{$allpos{$type}}) {
11433: if ($item ne '') {
11434: $confhash{$type}{$item}{'order'} = $idx;
11435: if (ref($domconfig{$action}) eq 'HASH') {
11436: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11437: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11438: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11439: $changes{$type}{$item} = 1;
11440: }
1.216 raeburn 11441: }
11442: }
11443: }
1.242 raeburn 11444: $idx ++;
1.216 raeburn 11445: }
11446: }
11447: }
11448: }
1.235 raeburn 11449: if (ref($validationitemsref) eq 'ARRAY') {
11450: foreach my $item (@{$validationitemsref}) {
11451: if ($item eq 'fields') {
11452: my @changed;
11453: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11454: if (@{$confhash{'validation'}{$item}} > 0) {
11455: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11456: }
1.266 raeburn 11457: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11458: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11459: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11460: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11461: $domconfig{'requestcourses'}{'validation'}{$item});
11462: } else {
11463: @changed = @{$confhash{'validation'}{$item}};
11464: }
1.235 raeburn 11465: } else {
11466: @changed = @{$confhash{'validation'}{$item}};
11467: }
11468: } else {
11469: @changed = @{$confhash{'validation'}{$item}};
11470: }
11471: if (@changed) {
11472: if ($confhash{'validation'}{$item}) {
11473: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11474: } else {
11475: $changes{'validation'}{$item} = &mt('None');
11476: }
11477: }
11478: } else {
11479: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11480: if ($item eq 'markup') {
11481: if ($env{'form.requestcourses_validation_'.$item}) {
11482: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11483: }
11484: }
1.266 raeburn 11485: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11486: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11487: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11488: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11489: }
11490: } else {
11491: if ($confhash{'validation'}{$item} ne '') {
11492: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11493: }
1.235 raeburn 11494: }
11495: } else {
11496: if ($confhash{'validation'}{$item} ne '') {
11497: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11498: }
11499: }
11500: }
11501: }
11502: }
11503: if ($env{'form.validationdc'}) {
11504: my $newval = $env{'form.validationdc'};
1.285 raeburn 11505: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 11506: if (exists($domcoords{$newval})) {
11507: $confhash{'validation'}{'dc'} = $newval;
11508: }
11509: }
11510: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 11511: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11512: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11513: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11514: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11515: if ($confhash{'validation'}{'dc'} eq '') {
11516: $changes{'validation'}{'dc'} = &mt('None');
11517: } else {
11518: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11519: }
1.235 raeburn 11520: }
1.266 raeburn 11521: } elsif ($confhash{'validation'}{'dc'} ne '') {
11522: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 11523: }
11524: } elsif ($confhash{'validation'}{'dc'} ne '') {
11525: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11526: }
11527: } elsif ($confhash{'validation'}{'dc'} ne '') {
11528: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 11529: }
1.266 raeburn 11530: } else {
11531: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11532: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11533: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11534: $changes{'validation'}{'dc'} = &mt('None');
11535: }
11536: }
1.235 raeburn 11537: }
11538: }
1.102 raeburn 11539: }
11540: } else {
1.86 raeburn 11541: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 11542: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 11543: }
1.72 raeburn 11544: foreach my $item (@usertools) {
11545: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 11546: my $unset;
1.101 raeburn 11547: if ($context eq 'requestcourses') {
1.104 raeburn 11548: $unset = '0';
11549: if ($type eq '_LC_adv') {
11550: $unset = '';
11551: }
1.101 raeburn 11552: if ($confhash{$item}{$type} eq 'autolimit') {
11553: $confhash{$item}{$type} .= '=';
11554: unless ($limithash{$item}{$type} =~ /\D/) {
11555: $confhash{$item}{$type} .= $limithash{$item}{$type};
11556: }
11557: }
1.163 raeburn 11558: } elsif ($context eq 'requestauthor') {
11559: $unset = '0';
11560: if ($type eq '_LC_adv') {
11561: $unset = '';
11562: }
1.72 raeburn 11563: } else {
1.101 raeburn 11564: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
11565: $confhash{$item}{$type} = 1;
11566: } else {
11567: $confhash{$item}{$type} = 0;
11568: }
1.72 raeburn 11569: }
1.86 raeburn 11570: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 11571: if ($action eq 'requestauthor') {
11572: if ($domconfig{$action}{$type} ne $confhash{$type}) {
11573: $changes{$type} = 1;
11574: }
11575: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 11576: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
11577: $changes{$item}{$type} = 1;
11578: }
11579: } else {
11580: if ($context eq 'requestcourses') {
1.104 raeburn 11581: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 11582: $changes{$item}{$type} = 1;
11583: }
11584: } else {
11585: if (!$confhash{$item}{$type}) {
11586: $changes{$item}{$type} = 1;
11587: }
11588: }
11589: }
11590: } else {
11591: if ($context eq 'requestcourses') {
1.104 raeburn 11592: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 11593: $changes{$item}{$type} = 1;
11594: }
1.163 raeburn 11595: } elsif ($context eq 'requestauthor') {
11596: if ($confhash{$type} ne $unset) {
11597: $changes{$type} = 1;
11598: }
1.72 raeburn 11599: } else {
11600: if (!$confhash{$item}{$type}) {
11601: $changes{$item}{$type} = 1;
11602: }
11603: }
11604: }
1.1 raeburn 11605: }
11606: }
1.163 raeburn 11607: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 11608: if (ref($domconfig{'quotas'}) eq 'HASH') {
11609: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11610: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
11611: if (exists($confhash{'defaultquota'}{$key})) {
11612: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
11613: $changes{'defaultquota'}{$key} = 1;
11614: }
11615: } else {
11616: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 11617: }
11618: }
1.86 raeburn 11619: } else {
11620: foreach my $key (keys(%{$domconfig{'quotas'}})) {
11621: if (exists($confhash{'defaultquota'}{$key})) {
11622: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
11623: $changes{'defaultquota'}{$key} = 1;
11624: }
11625: } else {
11626: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 11627: }
1.1 raeburn 11628: }
11629: }
1.197 raeburn 11630: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11631: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
11632: if (exists($confhash{'authorquota'}{$key})) {
11633: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
11634: $changes{'authorquota'}{$key} = 1;
11635: }
11636: } else {
11637: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
11638: }
11639: }
11640: }
1.1 raeburn 11641: }
1.86 raeburn 11642: if (ref($confhash{'defaultquota'}) eq 'HASH') {
11643: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
11644: if (ref($domconfig{'quotas'}) eq 'HASH') {
11645: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
11646: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
11647: $changes{'defaultquota'}{$key} = 1;
11648: }
11649: } else {
11650: if (!exists($domconfig{'quotas'}{$key})) {
11651: $changes{'defaultquota'}{$key} = 1;
11652: }
1.72 raeburn 11653: }
11654: } else {
1.86 raeburn 11655: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 11656: }
1.1 raeburn 11657: }
11658: }
1.197 raeburn 11659: if (ref($confhash{'authorquota'}) eq 'HASH') {
11660: foreach my $key (keys(%{$confhash{'authorquota'}})) {
11661: if (ref($domconfig{'quotas'}) eq 'HASH') {
11662: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
11663: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
11664: $changes{'authorquota'}{$key} = 1;
11665: }
11666: } else {
11667: $changes{'authorquota'}{$key} = 1;
11668: }
11669: } else {
11670: $changes{'authorquota'}{$key} = 1;
11671: }
11672: }
11673: }
1.1 raeburn 11674: }
1.72 raeburn 11675:
1.163 raeburn 11676: if ($context eq 'requestauthor') {
11677: $domdefaults{'requestauthor'} = \%confhash;
11678: } else {
11679: foreach my $key (keys(%confhash)) {
1.242 raeburn 11680: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 11681: $domdefaults{$key} = $confhash{$key};
11682: }
1.163 raeburn 11683: }
1.72 raeburn 11684: }
1.163 raeburn 11685:
1.1 raeburn 11686: my %quotahash = (
1.86 raeburn 11687: $action => { %confhash }
1.1 raeburn 11688: );
11689: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
11690: $dom);
11691: if ($putresult eq 'ok') {
11692: if (keys(%changes) > 0) {
1.72 raeburn 11693: my $cachetime = 24*60*60;
11694: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 11695: if (ref($lastactref) eq 'HASH') {
11696: $lastactref->{'domdefaults'} = 1;
11697: }
1.1 raeburn 11698: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 11699: unless (($context eq 'requestcourses') ||
1.163 raeburn 11700: ($context eq 'requestauthor')) {
1.86 raeburn 11701: if (ref($changes{'defaultquota'}) eq 'HASH') {
11702: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
11703: foreach my $type (@{$types},'default') {
11704: if (defined($changes{'defaultquota'}{$type})) {
11705: my $typetitle = $usertypes->{$type};
11706: if ($type eq 'default') {
11707: $typetitle = $othertitle;
11708: }
1.213 raeburn 11709: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 11710: }
11711: }
1.86 raeburn 11712: $resulttext .= '</ul></li>';
1.72 raeburn 11713: }
1.197 raeburn 11714: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 11715: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 11716: foreach my $type (@{$types},'default') {
11717: if (defined($changes{'authorquota'}{$type})) {
11718: my $typetitle = $usertypes->{$type};
11719: if ($type eq 'default') {
11720: $typetitle = $othertitle;
11721: }
1.213 raeburn 11722: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 11723: }
11724: }
11725: $resulttext .= '</ul></li>';
11726: }
1.72 raeburn 11727: }
1.80 raeburn 11728: my %newenv;
1.72 raeburn 11729: foreach my $item (@usertools) {
1.163 raeburn 11730: my (%haschgs,%inconf);
11731: if ($context eq 'requestauthor') {
11732: %haschgs = %changes;
1.210 raeburn 11733: %inconf = %confhash;
1.163 raeburn 11734: } else {
11735: if (ref($changes{$item}) eq 'HASH') {
11736: %haschgs = %{$changes{$item}};
11737: }
11738: if (ref($confhash{$item}) eq 'HASH') {
11739: %inconf = %{$confhash{$item}};
11740: }
11741: }
11742: if (keys(%haschgs) > 0) {
1.80 raeburn 11743: my $newacc =
11744: &Apache::lonnet::usertools_access($env{'user.name'},
11745: $env{'user.domain'},
1.86 raeburn 11746: $item,'reload',$context);
1.210 raeburn 11747: if (($context eq 'requestcourses') ||
1.163 raeburn 11748: ($context eq 'requestauthor')) {
1.108 raeburn 11749: if ($env{'environment.canrequest.'.$item} ne $newacc) {
11750: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 11751: }
11752: } else {
11753: if ($env{'environment.availabletools.'.$item} ne $newacc) {
11754: $newenv{'environment.availabletools.'.$item} = $newacc;
11755: }
1.80 raeburn 11756: }
1.163 raeburn 11757: unless ($context eq 'requestauthor') {
11758: $resulttext .= '<li>'.$titles{$item}.'<ul>';
11759: }
1.72 raeburn 11760: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 11761: if ($haschgs{$type}) {
1.72 raeburn 11762: my $typetitle = $usertypes->{$type};
11763: if ($type eq 'default') {
11764: $typetitle = $othertitle;
11765: } elsif ($type eq '_LC_adv') {
11766: $typetitle = 'LON-CAPA Advanced Users';
11767: }
1.163 raeburn 11768: if ($inconf{$type}) {
1.101 raeburn 11769: if ($context eq 'requestcourses') {
11770: my $cond;
1.163 raeburn 11771: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 11772: if ($1 eq '') {
11773: $cond = &mt('(Automatic processing of any request).');
11774: } else {
11775: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
11776: }
11777: } else {
1.163 raeburn 11778: $cond = $conditions{$inconf{$type}};
1.101 raeburn 11779: }
11780: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 11781: } elsif ($context eq 'requestauthor') {
11782: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
11783: $titles{$inconf{$type}},$typetitle);
11784:
1.101 raeburn 11785: } else {
11786: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
11787: }
1.72 raeburn 11788: } else {
1.104 raeburn 11789: if ($type eq '_LC_adv') {
1.163 raeburn 11790: if ($inconf{$type} eq '0') {
1.104 raeburn 11791: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11792: } else {
11793: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
11794: }
11795: } else {
11796: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
11797: }
1.72 raeburn 11798: }
11799: }
1.26 raeburn 11800: }
1.163 raeburn 11801: unless ($context eq 'requestauthor') {
11802: $resulttext .= '</ul></li>';
11803: }
1.26 raeburn 11804: }
1.1 raeburn 11805: }
1.163 raeburn 11806: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 11807: if (ref($changes{'notify'}) eq 'HASH') {
11808: if ($changes{'notify'}{'approval'}) {
11809: if (ref($confhash{'notify'}) eq 'HASH') {
11810: if ($confhash{'notify'}{'approval'}) {
11811: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
11812: } else {
1.163 raeburn 11813: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 11814: }
11815: }
11816: }
11817: }
11818: }
1.216 raeburn 11819: if ($action eq 'requestcourses') {
11820: my @offon = ('off','on');
11821: if ($changes{'uniquecode'}) {
1.218 raeburn 11822: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11823: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
11824: $resulttext .= '<li>'.
11825: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
11826: '</li>';
11827: } else {
11828: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
11829: '</li>';
11830: }
1.216 raeburn 11831: }
1.242 raeburn 11832: foreach my $type ('textbooks','templates') {
11833: if (ref($changes{$type}) eq 'HASH') {
11834: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
11835: foreach my $key (sort(keys(%{$changes{$type}}))) {
11836: my %coursehash = &Apache::lonnet::coursedescription($key);
11837: my $coursetitle = $coursehash{'description'};
11838: my $position = $confhash{$type}{$key}{'order'} + 1;
11839: $resulttext .= '<li>';
1.243 raeburn 11840: foreach my $item ('subject','title','publisher','author') {
11841: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11842: ($type eq 'templates'));
1.242 raeburn 11843: my $name = $item.':';
11844: $name =~ s/^(\w)/\U$1/;
11845: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
11846: }
11847: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
11848: if ($type eq 'textbooks') {
11849: if ($confhash{$type}{$key}{'image'}) {
11850: $resulttext .= ' '.&mt('Image: [_1]',
11851: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
11852: ' alt="Textbook cover" />').'<br />';
11853: }
11854: }
11855: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 11856: }
1.242 raeburn 11857: $resulttext .= '</ul></li>';
1.216 raeburn 11858: }
11859: }
1.235 raeburn 11860: if (ref($changes{'validation'}) eq 'HASH') {
11861: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
11862: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
11863: foreach my $item (@{$validationitemsref}) {
11864: if (exists($changes{'validation'}{$item})) {
11865: if ($item eq 'markup') {
11866: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11867: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
11868: } else {
11869: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
11870: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
11871: }
11872: }
11873: }
11874: if (exists($changes{'validation'}{'dc'})) {
11875: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
11876: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
11877: }
11878: }
11879: }
1.216 raeburn 11880: }
1.1 raeburn 11881: $resulttext .= '</ul>';
1.80 raeburn 11882: if (keys(%newenv)) {
11883: &Apache::lonnet::appenv(\%newenv);
11884: }
1.1 raeburn 11885: } else {
1.86 raeburn 11886: if ($context eq 'requestcourses') {
11887: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 11888: } elsif ($context eq 'requestauthor') {
11889: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 11890: } else {
1.90 weissno 11891: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 11892: }
1.1 raeburn 11893: }
11894: } else {
1.11 albertel 11895: $resulttext = '<span class="LC_error">'.
11896: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11897: }
1.216 raeburn 11898: if ($errors) {
11899: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
11900: '<ul>'.$errors.'</ul></p>';
11901: }
1.3 raeburn 11902: return $resulttext;
1.1 raeburn 11903: }
11904:
1.216 raeburn 11905: sub process_textbook_image {
1.242 raeburn 11906: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 11907: my $filename = $env{'form.'.$caller.'.filename'};
11908: my ($error,$url);
11909: my ($width,$height) = (50,50);
11910: if ($configuserok eq 'ok') {
11911: if ($switchserver) {
11912: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
11913: $switchserver);
11914: } elsif ($author_ok eq 'ok') {
11915: my ($result,$imageurl) =
11916: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 11917: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 11918: if ($result eq 'ok') {
11919: $url = $imageurl;
11920: } else {
11921: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
11922: }
11923: } else {
11924: $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);
11925: }
11926: } else {
11927: $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);
11928: }
11929: return ($url,$error);
11930: }
11931:
1.267 raeburn 11932: sub modify_ltitools {
11933: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
11934: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 11935: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 11936: my $confname = $dom.'-domainconfig';
11937: my $servadm = $r->dir_config('lonAdmEMail');
11938: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11939: my (%posslti,%possfield);
11940: my @courseroles = ('cc','in','ta','ep','st');
11941: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
11942: map { $posslti{$_} = 1; } @ltiroles;
11943: my @allfields = ('fullname','firstname','lastname','email','user','roles');
11944: map { $possfield{$_} = 1; } @allfields;
11945: my %lt = <itools_names();
11946: if ($env{'form.ltitools_add'}) {
11947: my $title = $env{'form.ltitools_add_title'};
11948: $title =~ s/(`)/'/g;
11949: ($newid,my $error) = &get_ltitools_id($dom,$title);
11950: if ($newid) {
11951: my $position = $env{'form.ltitools_add_pos'};
11952: $position =~ s/\D+//g;
11953: if ($position ne '') {
11954: $allpos[$position] = $newid;
11955: }
11956: $changes{$newid} = 1;
1.322 raeburn 11957: foreach my $item ('title','url','key','secret','lifetime') {
1.267 raeburn 11958: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322 raeburn 11959: if ($item eq 'lifetime') {
11960: $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
11961: }
1.267 raeburn 11962: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 11963: if (($item eq 'key') || ($item eq 'secret')) {
11964: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11965: } else {
11966: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
11967: }
1.267 raeburn 11968: }
11969: }
11970: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
11971: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
11972: }
11973: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
11974: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
11975: }
1.323 raeburn 11976: if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
11977: $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
11978: } else {
11979: $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
11980: }
1.296 raeburn 11981: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 11982: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
11983: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 11984: if (($item eq 'width') || ($item eq 'height')) {
11985: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
11986: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11987: }
11988: } else {
11989: if ($env{'form.ltitools_add_'.$item} ne '') {
11990: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
11991: }
1.267 raeburn 11992: }
11993: }
11994: if ($env{'form.ltitools_add_target'} eq 'window') {
11995: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 11996: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
11997: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 11998: } else {
11999: $confhash{$newid}{'display'}{'target'} = 'iframe';
12000: }
12001: foreach my $item ('passback','roster') {
1.319 raeburn 12002: if ($env{'form.ltitools_'.$item.'_add'}) {
1.267 raeburn 12003: $confhash{$newid}{$item} = 1;
1.319 raeburn 12004: if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
12005: my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
12006: $lifetime =~ s/^\s+|\s+$//g;
12007: if ($lifetime =~ /^\d+\.?\d*$/) {
12008: $confhash{$newid}{$item.'valid'} = $lifetime;
12009: }
12010: }
1.267 raeburn 12011: }
12012: }
12013: if ($env{'form.ltitools_add_image.filename'} ne '') {
12014: my ($imageurl,$error) =
1.307 raeburn 12015: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 12016: $configuserok,$switchserver,$author_ok);
12017: if ($imageurl) {
12018: $confhash{$newid}{'image'} = $imageurl;
12019: }
12020: if ($error) {
12021: &Apache::lonnet::logthis($error);
12022: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12023: }
12024: }
12025: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12026: foreach my $field (@fields) {
12027: if ($possfield{$field}) {
12028: if ($field eq 'roles') {
12029: foreach my $role (@courseroles) {
12030: my $choice = $env{'form.ltitools_add_roles_'.$role};
12031: if (($choice ne '') && ($posslti{$choice})) {
12032: $confhash{$newid}{'roles'}{$role} = $choice;
12033: if ($role eq 'cc') {
12034: $confhash{$newid}{'roles'}{'co'} = $choice;
12035: }
12036: }
12037: }
12038: } else {
12039: $confhash{$newid}{'fields'}{$field} = 1;
12040: }
12041: }
12042: }
1.324 raeburn 12043: if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12044: if ($confhash{$newid}{'fields'}{'user'}) {
12045: if ($env{'form.ltitools_userincdom_add'}) {
12046: $confhash{$newid}{'incdom'} = 1;
12047: }
12048: }
12049: }
1.273 raeburn 12050: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12051: foreach my $item (@courseconfig) {
12052: $confhash{$newid}{'crsconf'}{$item} = 1;
12053: }
1.267 raeburn 12054: if ($env{'form.ltitools_add_custom'}) {
12055: my $name = $env{'form.ltitools_add_custom_name'};
12056: my $value = $env{'form.ltitools_add_custom_value'};
12057: $value =~ s/(`)/'/g;
12058: $name =~ s/(`)/'/g;
12059: $confhash{$newid}{'custom'}{$name} = $value;
12060: }
12061: } else {
12062: my $error = &mt('Failed to acquire unique ID for new external tool');
12063: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12064: }
12065: }
12066: if (ref($domconfig{$action}) eq 'HASH') {
12067: my %deletions;
12068: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12069: if (@todelete) {
12070: map { $deletions{$_} = 1; } @todelete;
12071: }
12072: my %customadds;
12073: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12074: if (@newcustom) {
12075: map { $customadds{$_} = 1; } @newcustom;
12076: }
12077: my %imgdeletions;
12078: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12079: if (@todeleteimages) {
12080: map { $imgdeletions{$_} = 1; } @todeleteimages;
12081: }
12082: my $maxnum = $env{'form.ltitools_maxnum'};
12083: for (my $i=0; $i<=$maxnum; $i++) {
12084: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 12085: $itemid =~ s/\D+//g;
1.267 raeburn 12086: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12087: if ($deletions{$itemid}) {
12088: if ($domconfig{$action}{$itemid}{'image'}) {
12089: #FIXME need to obsolete item in RES space
12090: }
12091: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12092: next;
12093: } else {
12094: my $newpos = $env{'form.ltitools_'.$itemid};
12095: $newpos =~ s/\D+//g;
1.322 raeburn 12096: foreach my $item ('title','url','lifetime') {
1.267 raeburn 12097: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12098: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12099: $changes{$itemid} = 1;
12100: }
12101: }
1.297 raeburn 12102: foreach my $item ('key','secret') {
12103: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12104: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12105: $changes{$itemid} = 1;
12106: }
12107: }
1.267 raeburn 12108: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12109: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12110: }
12111: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12112: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12113: }
1.323 raeburn 12114: if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12115: $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12116: } else {
12117: $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12118: }
12119: if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12120: if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12121: $changes{$itemid} = 1;
12122: }
12123: } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12124: $changes{$itemid} = 1;
12125: }
1.267 raeburn 12126: foreach my $size ('width','height') {
12127: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12128: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12129: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12130: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12131: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12132: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12133: $changes{$itemid} = 1;
12134: }
12135: } else {
12136: $changes{$itemid} = 1;
12137: }
1.296 raeburn 12138: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12139: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12140: $changes{$itemid} = 1;
12141: }
12142: }
12143: }
12144: foreach my $item ('linktext','explanation') {
12145: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12146: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12147: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12148: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12149: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12150: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12151: $changes{$itemid} = 1;
12152: }
12153: } else {
12154: $changes{$itemid} = 1;
12155: }
12156: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12157: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12158: $changes{$itemid} = 1;
12159: }
1.267 raeburn 12160: }
12161: }
12162: if ($env{'form.ltitools_target_'.$i} eq 'window') {
12163: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 12164: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12165: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 12166: } else {
12167: $confhash{$itemid}{'display'}{'target'} = 'iframe';
12168: }
12169: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12170: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12171: $changes{$itemid} = 1;
12172: }
12173: } else {
12174: $changes{$itemid} = 1;
12175: }
12176: foreach my $extra ('passback','roster') {
12177: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
12178: $confhash{$itemid}{$extra} = 1;
1.319 raeburn 12179: if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338 raeburn 12180: my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319 raeburn 12181: $lifetime =~ s/^\s+|\s+$//g;
12182: if ($lifetime =~ /^\d+\.?\d*$/) {
12183: $confhash{$itemid}{$extra.'valid'} = $lifetime;
12184: }
12185: }
1.267 raeburn 12186: }
12187: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
12188: $changes{$itemid} = 1;
12189: }
1.319 raeburn 12190: if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
12191: $changes{$itemid} = 1;
12192: }
1.267 raeburn 12193: }
1.273 raeburn 12194: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318 raeburn 12195: foreach my $item ('label','title','target','linktext','explanation','append') {
1.273 raeburn 12196: if (grep(/^\Q$item\E$/,@courseconfig)) {
12197: $confhash{$itemid}{'crsconf'}{$item} = 1;
12198: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12199: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12200: $changes{$itemid} = 1;
12201: }
12202: } else {
12203: $changes{$itemid} = 1;
12204: }
12205: }
12206: }
1.267 raeburn 12207: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12208: foreach my $field (@fields) {
12209: if ($possfield{$field}) {
12210: if ($field eq 'roles') {
12211: foreach my $role (@courseroles) {
12212: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12213: if (($choice ne '') && ($posslti{$choice})) {
12214: $confhash{$itemid}{'roles'}{$role} = $choice;
12215: if ($role eq 'cc') {
12216: $confhash{$itemid}{'roles'}{'co'} = $choice;
12217: }
12218: }
12219: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12220: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12221: $changes{$itemid} = 1;
12222: }
12223: } elsif ($confhash{$itemid}{'roles'}{$role}) {
12224: $changes{$itemid} = 1;
12225: }
12226: }
12227: } else {
12228: $confhash{$itemid}{'fields'}{$field} = 1;
12229: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12230: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12231: $changes{$itemid} = 1;
12232: }
12233: } else {
12234: $changes{$itemid} = 1;
12235: }
12236: }
12237: }
12238: }
1.324 raeburn 12239: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12240: if ($confhash{$itemid}{'fields'}{'user'}) {
12241: if ($env{'form.ltitools_userincdom_'.$i}) {
12242: $confhash{$itemid}{'incdom'} = 1;
12243: }
12244: if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12245: $changes{$itemid} = 1;
12246: }
12247: }
12248: }
1.267 raeburn 12249: $allpos[$newpos] = $itemid;
12250: }
12251: if ($imgdeletions{$itemid}) {
12252: $changes{$itemid} = 1;
12253: #FIXME need to obsolete item in RES space
12254: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12255: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12256: $itemid,$configuserok,$switchserver,
12257: $author_ok);
12258: if ($imgurl) {
12259: $confhash{$itemid}{'image'} = $imgurl;
12260: $changes{$itemid} = 1;
12261: }
12262: if ($error) {
12263: &Apache::lonnet::logthis($error);
12264: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12265: }
12266: } elsif ($domconfig{$action}{$itemid}{'image'}) {
12267: $confhash{$itemid}{'image'} =
12268: $domconfig{$action}{$itemid}{'image'};
12269: }
12270: if ($customadds{$i}) {
12271: my $name = $env{'form.ltitools_custom_name_'.$i};
12272: $name =~ s/(`)/'/g;
12273: $name =~ s/^\s+//;
12274: $name =~ s/\s+$//;
12275: my $value = $env{'form.ltitools_custom_value_'.$i};
12276: $value =~ s/(`)/'/g;
12277: $value =~ s/^\s+//;
12278: $value =~ s/\s+$//;
12279: if ($name ne '') {
12280: $confhash{$itemid}{'custom'}{$name} = $value;
12281: $changes{$itemid} = 1;
12282: }
12283: }
12284: my %customdels;
12285: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12286: if (@customdeletions) {
12287: $changes{$itemid} = 1;
12288: }
12289: map { $customdels{$_} = 1; } @customdeletions;
12290: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12291: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12292: unless ($customdels{$key}) {
12293: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12294: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12295: }
12296: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12297: $changes{$itemid} = 1;
12298: }
12299: }
12300: }
12301: }
12302: unless ($changes{$itemid}) {
12303: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12304: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12305: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12306: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12307: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12308: $changes{$itemid} = 1;
12309: last;
12310: }
12311: }
12312: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12313: $changes{$itemid} = 1;
12314: }
12315: }
12316: last if ($changes{$itemid});
12317: }
12318: }
12319: }
12320: }
12321: }
12322: if (@allpos > 0) {
12323: my $idx = 0;
12324: foreach my $itemid (@allpos) {
12325: if ($itemid ne '') {
12326: $confhash{$itemid}{'order'} = $idx;
12327: if (ref($domconfig{$action}) eq 'HASH') {
12328: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12329: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12330: $changes{$itemid} = 1;
12331: }
12332: }
12333: }
12334: $idx ++;
12335: }
12336: }
12337: }
12338: my %ltitoolshash = (
12339: $action => { %confhash }
12340: );
12341: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12342: $dom);
12343: if ($putresult eq 'ok') {
1.297 raeburn 12344: my %ltienchash = (
12345: $action => { %encconfig }
12346: );
12347: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 12348: if (keys(%changes) > 0) {
12349: my $cachetime = 24*60*60;
1.297 raeburn 12350: my %ltiall = %confhash;
12351: foreach my $id (keys(%ltiall)) {
12352: if (ref($encconfig{$id}) eq 'HASH') {
12353: foreach my $item ('key','secret') {
12354: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12355: }
12356: }
12357: }
12358: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 12359: if (ref($lastactref) eq 'HASH') {
12360: $lastactref->{'ltitools'} = 1;
12361: }
12362: $resulttext = &mt('Changes made:').'<ul>';
12363: my %bynum;
12364: foreach my $itemid (sort(keys(%changes))) {
12365: my $position = $confhash{$itemid}{'order'};
12366: $bynum{$position} = $itemid;
12367: }
12368: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12369: my $itemid = $bynum{$pos};
12370: if (ref($confhash{$itemid}) ne 'HASH') {
12371: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12372: } else {
12373: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12374: if ($confhash{$itemid}{'image'}) {
12375: $resulttext .= ' '.
12376: '<img src="'.$confhash{$itemid}{'image'}.'"'.
12377: ' alt="'.&mt('Tool Provider icon').'" />';
12378: }
12379: $resulttext .= '</li><ul>';
12380: my $position = $pos + 1;
12381: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323 raeburn 12382: foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267 raeburn 12383: if ($confhash{$itemid}{$item} ne '') {
12384: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12385: }
12386: }
1.297 raeburn 12387: if ($encconfig{$itemid}{'key'} ne '') {
12388: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12389: }
12390: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 12391: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 12392: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 12393: $resulttext .= ('*'x$num).'</li>';
12394: }
1.273 raeburn 12395: $resulttext .= '<li>'.&mt('Configurable in course:');
1.318 raeburn 12396: my @possconfig = ('label','title','target','linktext','explanation','append');
1.273 raeburn 12397: my $numconfig = 0;
12398: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12399: foreach my $item (@possconfig) {
12400: if ($confhash{$itemid}{'crsconf'}{$item}) {
12401: $numconfig ++;
1.296 raeburn 12402: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 12403: }
12404: }
12405: }
12406: if (!$numconfig) {
12407: $resulttext .= &mt('None');
12408: }
12409: $resulttext .= '</li>';
1.267 raeburn 12410: foreach my $item ('passback','roster') {
12411: $resulttext .= '<li>'.$lt{$item}.' ';
12412: if ($confhash{$itemid}{$item}) {
12413: $resulttext .= &mt('Yes');
1.319 raeburn 12414: if ($confhash{$itemid}{$item.'valid'}) {
12415: if ($item eq 'passback') {
12416: $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
12417: $confhash{$itemid}{$item.'valid'});
12418: } else {
12419: $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
12420: $confhash{$itemid}{$item.'valid'});
12421: }
12422: }
1.267 raeburn 12423: } else {
12424: $resulttext .= &mt('No');
12425: }
12426: $resulttext .= '</li>';
12427: }
12428: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12429: my $displaylist;
12430: if ($confhash{$itemid}{'display'}{'target'}) {
12431: $displaylist = &mt('Display target').': '.
12432: $confhash{$itemid}{'display'}{'target'}.',';
12433: }
12434: foreach my $size ('width','height') {
12435: if ($confhash{$itemid}{'display'}{$size}) {
12436: $displaylist .= (' 'x2).$lt{$size}.': '.
12437: $confhash{$itemid}{'display'}{$size}.',';
12438: }
12439: }
12440: if ($displaylist) {
12441: $displaylist =~ s/,$//;
12442: $resulttext .= '<li>'.$displaylist.'</li>';
12443: }
1.296 raeburn 12444: foreach my $item ('linktext','explanation') {
12445: if ($confhash{$itemid}{'display'}{$item}) {
12446: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12447: }
12448: }
12449: }
1.267 raeburn 12450: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12451: my $fieldlist;
12452: foreach my $field (@allfields) {
12453: if ($confhash{$itemid}{'fields'}{$field}) {
12454: $fieldlist .= (' 'x2).$lt{$field}.',';
12455: }
12456: }
12457: if ($fieldlist) {
12458: $fieldlist =~ s/,$//;
1.324 raeburn 12459: if ($confhash{$itemid}{'fields'}{'user'}) {
12460: if ($confhash{$itemid}{'incdom'}) {
12461: $fieldlist .= ' ('.&mt('username:domain').')';
12462: } else {
12463: $fieldlist .= ' ('.&mt('username').')';
12464: }
12465: }
1.267 raeburn 12466: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12467: }
12468: }
12469: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12470: my $rolemaps;
12471: foreach my $role (@courseroles) {
12472: if ($confhash{$itemid}{'roles'}{$role}) {
12473: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12474: $confhash{$itemid}{'roles'}{$role}.',';
12475: }
12476: }
12477: if ($rolemaps) {
12478: $rolemaps =~ s/,$//;
12479: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12480: }
12481: }
12482: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12483: my $customlist;
12484: if (keys(%{$confhash{$itemid}{'custom'}})) {
12485: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12486: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12487: }
12488: }
12489: if ($customlist) {
1.317 raeburn 12490: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267 raeburn 12491: }
12492: }
12493: $resulttext .= '</ul></li>';
12494: }
12495: }
12496: $resulttext .= '</ul>';
12497: } else {
12498: $resulttext = &mt('No changes made.');
12499: }
12500: } else {
12501: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12502: }
12503: if ($errors) {
12504: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12505: $errors.'</ul>';
12506: }
12507: return $resulttext;
12508: }
12509:
12510: sub process_ltitools_image {
12511: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12512: my $filename = $env{'form.'.$caller.'.filename'};
12513: my ($error,$url);
12514: my ($width,$height) = (21,21);
12515: if ($configuserok eq 'ok') {
12516: if ($switchserver) {
12517: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12518: $switchserver);
12519: } elsif ($author_ok eq 'ok') {
12520: my ($result,$imageurl,$madethumb) =
12521: &publishlogo($r,'upload',$caller,$dom,$confname,
12522: "ltitools/$itemid/icon",$width,$height);
12523: if ($result eq 'ok') {
12524: if ($madethumb) {
12525: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12526: my $imagethumb = "$path/tn-".$imagefile;
12527: $url = $imagethumb;
12528: } else {
12529: $url = $imageurl;
12530: }
12531: } else {
12532: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12533: }
12534: } else {
12535: $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);
12536: }
12537: } else {
12538: $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);
12539: }
12540: return ($url,$error);
12541: }
12542:
12543: sub get_ltitools_id {
12544: my ($cdom,$title) = @_;
12545: # get lock on ltitools db
12546: my $lockhash = {
12547: lock => $env{'user.name'}.
12548: ':'.$env{'user.domain'},
12549: };
12550: my $tries = 0;
12551: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12552: my ($id,$error);
12553:
12554: while (($gotlock ne 'ok') && ($tries<10)) {
12555: $tries ++;
12556: sleep (0.1);
12557: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12558: }
12559: if ($gotlock eq 'ok') {
12560: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12561: if ($currids{'lock'}) {
12562: delete($currids{'lock'});
12563: if (keys(%currids)) {
12564: my @curr = sort { $a <=> $b } keys(%currids);
12565: if ($curr[-1] =~ /^\d+$/) {
12566: $id = 1 + $curr[-1];
12567: }
12568: } else {
12569: $id = 1;
12570: }
12571: if ($id) {
12572: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12573: $error = 'nostore';
12574: }
12575: } else {
12576: $error = 'nonumber';
12577: }
12578: }
12579: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
12580: } else {
12581: $error = 'nolock';
12582: }
12583: return ($id,$error);
12584: }
12585:
1.320 raeburn 12586: sub modify_lti {
12587: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12588: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12589: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12590: my (%posslti,%posslticrs,%posscrstype);
12591: my @courseroles = ('cc','in','ta','ep','st');
12592: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
12593: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
12594: my @coursetypes = ('official','unofficial','community','textbook','placement');
12595: my %coursetypetitles = &Apache::lonlocal::texthash (
12596: official => 'Official',
12597: unofficial => 'Unofficial',
12598: community => 'Community',
12599: textbook => 'Textbook',
12600: placement => 'Placement Test',
12601: );
1.325 raeburn 12602: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 12603: my %lt = <i_names();
12604: map { $posslti{$_} = 1; } @ltiroles;
12605: map { $posslticrs{$_} = 1; } @lticourseroles;
12606: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 12607:
1.326 raeburn 12608: my %menutitles = <imenu_titles();
12609:
1.320 raeburn 12610: my (@items,%deletions,%itemids);
12611: if ($env{'form.lti_add'}) {
12612: my $consumer = $env{'form.lti_consumer_add'};
12613: $consumer =~ s/(`)/'/g;
12614: ($newid,my $error) = &get_lti_id($dom,$consumer);
12615: if ($newid) {
12616: $itemids{'add'} = $newid;
12617: push(@items,'add');
12618: $changes{$newid} = 1;
12619: } else {
12620: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
12621: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12622: }
12623: }
12624: if (ref($domconfig{$action}) eq 'HASH') {
12625: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
12626: if (@todelete) {
12627: map { $deletions{$_} = 1; } @todelete;
12628: }
12629: my $maxnum = $env{'form.lti_maxnum'};
12630: for (my $i=0; $i<=$maxnum; $i++) {
12631: my $itemid = $env{'form.lti_id_'.$i};
12632: $itemid =~ s/\D+//g;
12633: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12634: if ($deletions{$itemid}) {
12635: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
12636: } else {
12637: push(@items,$i);
12638: $itemids{$i} = $itemid;
12639: }
12640: }
12641: }
12642: }
12643: foreach my $idx (@items) {
12644: my $itemid = $itemids{$idx};
12645: next unless ($itemid);
12646: my $position = $env{'form.lti_pos_'.$idx};
12647: $position =~ s/\D+//g;
12648: if ($position ne '') {
12649: $allpos[$position] = $itemid;
12650: }
1.345 raeburn 12651: foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320 raeburn 12652: my $formitem = 'form.lti_'.$item.'_'.$idx;
12653: $env{$formitem} =~ s/(`)/'/g;
12654: if ($item eq 'lifetime') {
12655: $env{$formitem} =~ s/[^\d.]//g;
12656: }
12657: if ($env{$formitem} ne '') {
12658: if (($item eq 'key') || ($item eq 'secret')) {
12659: $encconfig{$itemid}{$item} = $env{$formitem};
12660: } else {
12661: $confhash{$itemid}{$item} = $env{$formitem};
12662: unless (($idx eq 'add') || ($changes{$itemid})) {
12663: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12664: $changes{$itemid} = 1;
12665: }
12666: }
12667: }
12668: }
12669: }
12670: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
12671: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
12672: }
1.345 raeburn 12673: if ($confhash{$itemid}{'requser'}) {
12674: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
12675: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
12676: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
12677: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
12678: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
12679: my $mapuser = $env{'form.lti_customuser_'.$idx};
12680: $mapuser =~ s/(`)/'/g;
12681: $mapuser =~ s/^\s+|\s+$//g;
12682: $confhash{$itemid}{'mapuser'} = $mapuser;
12683: }
12684: foreach my $ltirole (@lticourseroles) {
12685: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
12686: if (grep(/^\Q$possrole\E$/,@courseroles)) {
12687: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
12688: }
12689: }
12690: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
12691: my @makeuser;
12692: foreach my $ltirole (sort(@possmakeuser)) {
12693: if ($posslti{$ltirole}) {
12694: push(@makeuser,$ltirole);
12695: }
12696: }
12697: $confhash{$itemid}{'makeuser'} = \@makeuser;
12698: if (@makeuser) {
12699: my $lcauth = $env{'form.lti_lcauth_'.$idx};
12700: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
12701: $confhash{$itemid}{'lcauth'} = $lcauth;
12702: if ($lcauth ne 'internal') {
12703: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
12704: $lcauthparm =~ s/^(\s+|\s+)$//g;
12705: $lcauthparm =~ s/`//g;
12706: if ($lcauthparm ne '') {
12707: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
12708: }
12709: }
12710: } else {
12711: $confhash{$itemid}{'lcauth'} = 'lti';
12712: }
1.320 raeburn 12713: }
1.345 raeburn 12714: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
12715: if (@possinstdata) {
12716: foreach my $field (@possinstdata) {
12717: if (exists($fieldtitles{$field})) {
12718: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 12719: }
12720: }
12721: }
1.345 raeburn 12722: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
12723: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
12724: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
12725: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
12726: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
12727: $mapcrs =~ s/(`)/'/g;
12728: $mapcrs =~ s/^\s+|\s+$//g;
12729: $confhash{$itemid}{'mapcrs'} = $mapcrs;
12730: }
12731: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
12732: my @crstypes;
12733: foreach my $type (sort(@posstypes)) {
12734: if ($posscrstype{$type}) {
12735: push(@crstypes,$type);
1.325 raeburn 12736: }
12737: }
1.345 raeburn 12738: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
12739: if ($env{'form.lti_makecrs_'.$idx}) {
12740: $confhash{$itemid}{'makecrs'} = 1;
1.320 raeburn 12741: }
1.345 raeburn 12742: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
12743: my @selfenroll;
12744: foreach my $type (sort(@possenroll)) {
12745: if ($posslticrs{$type}) {
12746: push(@selfenroll,$type);
12747: }
1.320 raeburn 12748: }
1.345 raeburn 12749: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
12750: if ($env{'form.lti_crssec_'.$idx}) {
12751: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
12752: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
12753: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
12754: my $section = $env{'form.lti_customsection_'.$idx};
12755: $section =~ s/(`)/'/g;
12756: $section =~ s/^\s+|\s+$//g;
12757: if ($section ne '') {
12758: $confhash{$itemid}{'section'} = $section;
12759: }
1.320 raeburn 12760: }
12761: }
1.363 raeburn 12762: if ($env{'form.lti_callback_'.$idx}) {
12763: if ($env{'form.lti_callbackparam_'.$idx}) {
12764: my $callback = $env{'form.lti_callbackparam_'.$idx};
12765: $callback =~ s/^\s+|\s+$//g;
12766: $confhash{$itemid}{'callback'} = $callback;
12767: }
12768: }
1.345 raeburn 12769: foreach my $field ('passback','roster','topmenu','inlinemenu') {
12770: if ($env{'form.lti_'.$field.'_'.$idx}) {
12771: $confhash{$itemid}{$field} = 1;
12772: }
1.320 raeburn 12773: }
1.345 raeburn 12774: if ($env{'form.lti_passback_'.$idx}) {
12775: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
12776: $confhash{$itemid}{'passbackformat'} = '1.0';
12777: } else {
12778: $confhash{$itemid}{'passbackformat'} = '1.1';
12779: }
1.337 raeburn 12780: }
1.345 raeburn 12781: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
12782: $confhash{$itemid}{lcmenu} = [];
12783: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
12784: foreach my $field (@possmenu) {
12785: if (exists($menutitles{$field})) {
12786: if ($field eq 'grades') {
12787: next unless ($env{'form.lti_inlinemenu_'.$idx});
12788: }
12789: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 12790: }
12791: }
12792: }
1.345 raeburn 12793: unless (($idx eq 'add') || ($changes{$itemid})) {
1.363 raeburn 12794: foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345 raeburn 12795: if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337 raeburn 12796: $changes{$itemid} = 1;
12797: }
12798: }
1.320 raeburn 12799: unless ($changes{$itemid}) {
1.345 raeburn 12800: if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
12801: if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 12802: $changes{$itemid} = 1;
12803: }
1.345 raeburn 12804: }
1.320 raeburn 12805: }
1.345 raeburn 12806: foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
12807: unless ($changes{$itemid}) {
12808: if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
12809: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12810: my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
12811: $confhash{$itemid}{$field});
12812: if (@diffs) {
12813: $changes{$itemid} = 1;
12814: }
12815: } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
12816: $changes{$itemid} = 1;
12817: }
12818: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
12819: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 12820: $changes{$itemid} = 1;
12821: }
12822: }
1.345 raeburn 12823: }
12824: }
12825: unless ($changes{$itemid}) {
12826: if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
12827: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12828: foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
12829: if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne
12830: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320 raeburn 12831: $changes{$itemid} = 1;
12832: last;
12833: }
12834: }
1.345 raeburn 12835: unless ($changes{$itemid}) {
12836: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
12837: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
12838: $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
12839: $changes{$itemid} = 1;
12840: last;
12841: }
12842: }
12843: }
12844: } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
12845: $changes{$itemid} = 1;
1.320 raeburn 12846: }
1.345 raeburn 12847: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12848: unless ($changes{$itemid}) {
12849: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
12850: $changes{$itemid} = 1;
12851: }
1.320 raeburn 12852: }
12853: }
12854: }
12855: }
12856: }
12857: }
12858: if (@allpos > 0) {
12859: my $idx = 0;
12860: foreach my $itemid (@allpos) {
12861: if ($itemid ne '') {
12862: $confhash{$itemid}{'order'} = $idx;
12863: if (ref($domconfig{$action}) eq 'HASH') {
12864: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12865: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12866: $changes{$itemid} = 1;
12867: }
12868: }
12869: }
12870: $idx ++;
12871: }
12872: }
12873: }
12874: my %ltihash = (
12875: $action => { %confhash }
12876: );
12877: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
12878: $dom);
12879: if ($putresult eq 'ok') {
12880: my %ltienchash = (
12881: $action => { %encconfig }
12882: );
12883: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
12884: if (keys(%changes) > 0) {
12885: my $cachetime = 24*60*60;
12886: my %ltiall = %confhash;
12887: foreach my $id (keys(%ltiall)) {
12888: if (ref($encconfig{$id}) eq 'HASH') {
12889: foreach my $item ('key','secret') {
12890: $ltiall{$id}{$item} = $encconfig{$id}{$item};
12891: }
12892: }
12893: }
12894: &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
12895: if (ref($lastactref) eq 'HASH') {
12896: $lastactref->{'lti'} = 1;
12897: }
12898: $resulttext = &mt('Changes made:').'<ul>';
12899: my %bynum;
12900: foreach my $itemid (sort(keys(%changes))) {
12901: my $position = $confhash{$itemid}{'order'};
12902: $bynum{$position} = $itemid;
12903: }
12904: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12905: my $itemid = $bynum{$pos};
12906: if (ref($confhash{$itemid}) ne 'HASH') {
12907: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12908: } else {
12909: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
12910: my $position = $pos + 1;
12911: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12912: foreach my $item ('version','lifetime') {
12913: if ($confhash{$itemid}{$item} ne '') {
12914: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12915: }
12916: }
12917: if ($encconfig{$itemid}{'key'} ne '') {
12918: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12919: }
12920: if ($encconfig{$itemid}{'secret'} ne '') {
12921: $resulttext .= '<li>'.$lt{'secret'}.': ';
12922: my $num = length($encconfig{$itemid}{'secret'});
12923: $resulttext .= ('*'x$num).'</li>';
12924: }
1.345 raeburn 12925: if ($confhash{$itemid}{'requser'}) {
12926: if ($confhash{$itemid}{'mapuser'}) {
12927: my $shownmapuser;
12928: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
12929: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
12930: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
12931: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
12932: } else {
12933: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 12934: }
1.345 raeburn 12935: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 12936: }
1.345 raeburn 12937: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
12938: my $rolemaps;
12939: foreach my $role (@ltiroles) {
12940: if ($confhash{$itemid}{'maproles'}{$role}) {
12941: $rolemaps .= (' 'x2).$role.'='.
12942: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
12943: 'Course').',';
12944: }
12945: }
12946: if ($rolemaps) {
12947: $rolemaps =~ s/,$//;
12948: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12949: }
12950: }
12951: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
12952: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
12953: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
12954: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
12955: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
12956: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
12957: } else {
12958: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
12959: $confhash{$itemid}{'lcauth'});
12960: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
12961: $resulttext .= '; '.&mt('a randomly generated password will be created');
12962: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
12963: if ($confhash{$itemid}{'lcauthparm'} ne '') {
12964: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
12965: }
12966: } else {
12967: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
12968: }
12969: }
12970: $resulttext .= '</li>';
12971: } else {
12972: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
12973: }
1.320 raeburn 12974: }
1.345 raeburn 12975: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
12976: if (@{$confhash{$itemid}{'instdata'}} > 0) {
12977: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
12978: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 12979: } else {
1.345 raeburn 12980: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 12981: }
1.320 raeburn 12982: }
1.345 raeburn 12983: if ($confhash{$itemid}{'mapcrs'}) {
12984: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
12985: }
12986: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
12987: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
12988: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
12989: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
12990: '</li>';
12991: } else {
12992: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
12993: }
1.325 raeburn 12994: }
1.345 raeburn 12995: if ($confhash{$itemid}{'makecrs'}) {
12996: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320 raeburn 12997: } else {
1.345 raeburn 12998: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320 raeburn 12999: }
1.345 raeburn 13000: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
13001: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
13002: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
13003: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
13004: '</li>';
13005: } else {
13006: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
13007: }
1.320 raeburn 13008: }
1.345 raeburn 13009: if ($confhash{$itemid}{'section'}) {
13010: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
13011: $resulttext .= '<li>'.&mt('User section from standard field:').
13012: ' (course_section_sourcedid)'.'</li>';
13013: } else {
13014: $resulttext .= '<li>'.&mt('User section from:').' '.
13015: $confhash{$itemid}{'section'}.'</li>';
13016: }
1.320 raeburn 13017: } else {
1.345 raeburn 13018: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320 raeburn 13019: }
1.363 raeburn 13020: if ($confhash{$itemid}{'callback'}) {
13021: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
13022: } else {
13023: $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
13024: }
1.345 raeburn 13025: foreach my $item ('passback','roster','topmenu','inlinemenu') {
13026: $resulttext .= '<li>'.$lt{$item}.': ';
13027: if ($confhash{$itemid}{$item}) {
13028: $resulttext .= &mt('Yes');
13029: if ($item eq 'passback') {
13030: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
13031: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
13032: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
13033: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
13034: }
1.337 raeburn 13035: }
1.345 raeburn 13036: } else {
13037: $resulttext .= &mt('No');
1.337 raeburn 13038: }
1.345 raeburn 13039: $resulttext .= '</li>';
1.320 raeburn 13040: }
1.345 raeburn 13041: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
13042: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
13043: $resulttext .= '<li>'.&mt('Menu items:').' '.
13044: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
13045: } else {
13046: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
13047: }
1.326 raeburn 13048: }
13049: }
1.320 raeburn 13050: $resulttext .= '</ul></li>';
13051: }
13052: }
13053: $resulttext .= '</ul>';
13054: } else {
13055: $resulttext = &mt('No changes made.');
13056: }
13057: } else {
13058: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13059: }
13060: if ($errors) {
13061: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13062: $errors.'</ul>';
13063: }
13064: return $resulttext;
13065: }
13066:
13067: sub get_lti_id {
13068: my ($domain,$consumer) = @_;
13069: # get lock on lti db
13070: my $lockhash = {
13071: lock => $env{'user.name'}.
13072: ':'.$env{'user.domain'},
13073: };
13074: my $tries = 0;
13075: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
13076: my ($id,$error);
13077:
13078: while (($gotlock ne 'ok') && ($tries<10)) {
13079: $tries ++;
13080: sleep (0.1);
13081: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
13082: }
13083: if ($gotlock eq 'ok') {
13084: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
13085: if ($currids{'lock'}) {
13086: delete($currids{'lock'});
13087: if (keys(%currids)) {
13088: my @curr = sort { $a <=> $b } keys(%currids);
13089: if ($curr[-1] =~ /^\d+$/) {
13090: $id = 1 + $curr[-1];
13091: }
13092: } else {
13093: $id = 1;
13094: }
13095: if ($id) {
13096: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
13097: $error = 'nostore';
13098: }
13099: } else {
13100: $error = 'nonumber';
13101: }
13102: }
13103: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
13104: } else {
13105: $error = 'nolock';
13106: }
13107: return ($id,$error);
13108: }
13109:
1.3 raeburn 13110: sub modify_autoenroll {
1.205 raeburn 13111: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 13112: my ($resulttext,%changes);
13113: my %currautoenroll;
13114: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13115: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13116: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13117: }
13118: }
13119: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13120: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13121: sender => 'Sender for notification messages',
1.274 raeburn 13122: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
13123: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13124: my @offon = ('off','on');
1.17 raeburn 13125: my $sender_uname = $env{'form.sender_uname'};
13126: my $sender_domain = $env{'form.sender_domain'};
13127: if ($sender_domain eq '') {
13128: $sender_uname = '';
13129: } elsif ($sender_uname eq '') {
13130: $sender_domain = '';
13131: }
1.129 raeburn 13132: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 13133: my $failsafe = $env{'form.autoenroll_failsafe'};
13134: $failsafe =~ s{^\s+|\s+$}{}g;
13135: if ($failsafe =~ /\D/) {
13136: undef($failsafe);
13137: }
1.1 raeburn 13138: my %autoenrollhash = (
1.129 raeburn 13139: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13140: 'sender_uname' => $sender_uname,
13141: 'sender_domain' => $sender_domain,
13142: 'co-owners' => $coowners,
1.274 raeburn 13143: 'autofailsafe' => $failsafe,
1.1 raeburn 13144: }
13145: );
1.4 raeburn 13146: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13147: $dom);
1.1 raeburn 13148: if ($putresult eq 'ok') {
13149: if (exists($currautoenroll{'run'})) {
13150: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13151: $changes{'run'} = 1;
13152: }
13153: } elsif ($autorun) {
13154: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13155: $changes{'run'} = 1;
1.1 raeburn 13156: }
13157: }
1.17 raeburn 13158: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13159: $changes{'sender'} = 1;
13160: }
1.17 raeburn 13161: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13162: $changes{'sender'} = 1;
13163: }
1.129 raeburn 13164: if ($currautoenroll{'co-owners'} ne '') {
13165: if ($currautoenroll{'co-owners'} ne $coowners) {
13166: $changes{'coowners'} = 1;
13167: }
13168: } elsif ($coowners) {
13169: $changes{'coowners'} = 1;
1.274 raeburn 13170: }
13171: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
13172: $changes{'autofailsafe'} = 1;
13173: }
1.1 raeburn 13174: if (keys(%changes) > 0) {
13175: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13176: if ($changes{'run'}) {
1.1 raeburn 13177: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13178: }
13179: if ($changes{'sender'}) {
1.17 raeburn 13180: if ($sender_uname eq '' || $sender_domain eq '') {
13181: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13182: } else {
13183: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13184: }
1.1 raeburn 13185: }
1.129 raeburn 13186: if ($changes{'coowners'}) {
13187: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13188: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13189: if (ref($lastactref) eq 'HASH') {
13190: $lastactref->{'domainconfig'} = 1;
13191: }
1.129 raeburn 13192: }
1.274 raeburn 13193: if ($changes{'autofailsafe'}) {
13194: if ($failsafe ne '') {
1.299 raeburn 13195: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 13196: } else {
1.299 raeburn 13197: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 13198: }
13199: &Apache::lonnet::get_domain_defaults($dom,1);
13200: if (ref($lastactref) eq 'HASH') {
13201: $lastactref->{'domdefaults'} = 1;
13202: }
13203: }
1.1 raeburn 13204: $resulttext .= '</ul>';
13205: } else {
13206: $resulttext = &mt('No changes made to auto-enrollment settings');
13207: }
13208: } else {
1.11 albertel 13209: $resulttext = '<span class="LC_error">'.
13210: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13211: }
1.3 raeburn 13212: return $resulttext;
1.1 raeburn 13213: }
13214:
13215: sub modify_autoupdate {
1.3 raeburn 13216: my ($dom,%domconfig) = @_;
1.1 raeburn 13217: my ($resulttext,%currautoupdate,%fields,%changes);
13218: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13219: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13220: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13221: }
13222: }
13223: my @offon = ('off','on');
13224: my %title = &Apache::lonlocal::texthash (
13225: run => 'Auto-update:',
13226: classlists => 'Updates to user information in classlists?'
13227: );
1.44 raeburn 13228: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13229: my %fieldtitles = &Apache::lonlocal::texthash (
13230: id => 'Student/Employee ID',
1.20 raeburn 13231: permanentemail => 'E-mail address',
1.1 raeburn 13232: lastname => 'Last Name',
13233: firstname => 'First Name',
13234: middlename => 'Middle Name',
1.132 raeburn 13235: generation => 'Generation',
1.1 raeburn 13236: );
1.142 raeburn 13237: $othertitle = &mt('All users');
1.1 raeburn 13238: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13239: $othertitle = &mt('Other users');
1.1 raeburn 13240: }
13241: foreach my $key (keys(%env)) {
13242: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13243: my ($usertype,$item) = ($1,$2);
13244: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13245: if ($usertype eq 'default') {
13246: push(@{$fields{$1}},$2);
13247: } elsif (ref($types) eq 'ARRAY') {
13248: if (grep(/^\Q$usertype\E$/,@{$types})) {
13249: push(@{$fields{$1}},$2);
13250: }
13251: }
13252: }
1.1 raeburn 13253: }
13254: }
1.131 raeburn 13255: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13256: @lockablenames = sort(@lockablenames);
13257: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13258: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13259: if (@changed) {
13260: $changes{'lockablenames'} = 1;
13261: }
13262: } else {
13263: if (@lockablenames) {
13264: $changes{'lockablenames'} = 1;
13265: }
13266: }
1.1 raeburn 13267: my %updatehash = (
13268: autoupdate => { run => $env{'form.autoupdate_run'},
13269: classlists => $env{'form.classlists'},
13270: fields => {%fields},
1.131 raeburn 13271: lockablenames => \@lockablenames,
1.1 raeburn 13272: }
13273: );
13274: foreach my $key (keys(%currautoupdate)) {
13275: if (($key eq 'run') || ($key eq 'classlists')) {
13276: if (exists($updatehash{autoupdate}{$key})) {
13277: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13278: $changes{$key} = 1;
13279: }
13280: }
13281: } elsif ($key eq 'fields') {
13282: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13283: foreach my $item (@{$types},'default') {
1.1 raeburn 13284: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13285: my $change = 0;
13286: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13287: if (!exists($fields{$item})) {
13288: $change = 1;
1.132 raeburn 13289: last;
1.1 raeburn 13290: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13291: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13292: $change = 1;
1.132 raeburn 13293: last;
1.1 raeburn 13294: }
13295: }
13296: }
13297: if ($change) {
13298: push(@{$changes{$key}},$item);
13299: }
1.26 raeburn 13300: }
1.1 raeburn 13301: }
13302: }
1.131 raeburn 13303: } elsif ($key eq 'lockablenames') {
13304: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13305: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13306: if (@changed) {
13307: $changes{'lockablenames'} = 1;
13308: }
13309: } else {
13310: if (@lockablenames) {
13311: $changes{'lockablenames'} = 1;
13312: }
13313: }
13314: }
13315: }
13316: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13317: if (@lockablenames) {
13318: $changes{'lockablenames'} = 1;
1.1 raeburn 13319: }
13320: }
1.26 raeburn 13321: foreach my $item (@{$types},'default') {
13322: if (defined($fields{$item})) {
13323: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13324: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13325: my $change = 0;
13326: if (ref($fields{$item}) eq 'ARRAY') {
13327: foreach my $type (@{$fields{$item}}) {
13328: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13329: $change = 1;
13330: last;
13331: }
13332: }
13333: }
13334: if ($change) {
13335: push(@{$changes{'fields'}},$item);
13336: }
13337: } else {
1.26 raeburn 13338: push(@{$changes{'fields'}},$item);
13339: }
13340: } else {
13341: push(@{$changes{'fields'}},$item);
1.1 raeburn 13342: }
13343: }
13344: }
13345: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13346: $dom);
13347: if ($putresult eq 'ok') {
13348: if (keys(%changes) > 0) {
13349: $resulttext = &mt('Changes made:').'<ul>';
13350: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13351: if ($key eq 'lockablenames') {
13352: $resulttext .= '<li>';
13353: if (@lockablenames) {
13354: $usertypes->{'default'} = $othertitle;
13355: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13356: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13357: } else {
13358: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13359: }
13360: $resulttext .= '</li>';
13361: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13362: foreach my $item (@{$changes{$key}}) {
13363: my @newvalues;
13364: foreach my $type (@{$fields{$item}}) {
13365: push(@newvalues,$fieldtitles{$type});
13366: }
1.3 raeburn 13367: my $newvaluestr;
13368: if (@newvalues > 0) {
13369: $newvaluestr = join(', ',@newvalues);
13370: } else {
13371: $newvaluestr = &mt('none');
1.6 raeburn 13372: }
1.1 raeburn 13373: if ($item eq 'default') {
1.26 raeburn 13374: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13375: } else {
1.26 raeburn 13376: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13377: }
13378: }
13379: } else {
13380: my $newvalue;
13381: if ($key eq 'run') {
13382: $newvalue = $offon[$env{'form.autoupdate_run'}];
13383: } else {
13384: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13385: }
1.1 raeburn 13386: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13387: }
13388: }
13389: $resulttext .= '</ul>';
13390: } else {
1.3 raeburn 13391: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13392: }
13393: } else {
1.11 albertel 13394: $resulttext = '<span class="LC_error">'.
13395: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13396: }
1.3 raeburn 13397: return $resulttext;
1.1 raeburn 13398: }
13399:
1.125 raeburn 13400: sub modify_autocreate {
13401: my ($dom,%domconfig) = @_;
13402: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13403: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13404: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13405: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13406: }
13407: }
13408: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13409: req => 'Auto-creation of validated requests for official courses',
13410: xmldc => 'Identity of course creator of courses from XML files',
13411: );
13412: my @types = ('xml','req');
13413: foreach my $item (@types) {
13414: $newvals{$item} = $env{'form.autocreate_'.$item};
13415: $newvals{$item} =~ s/\D//g;
13416: $newvals{$item} = 0 if ($newvals{$item} eq '');
13417: }
13418: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 13419: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13420: unless (exists($domcoords{$newvals{'xmldc'}})) {
13421: $newvals{'xmldc'} = '';
13422: }
13423: %autocreatehash = (
13424: autocreate => { xml => $newvals{'xml'},
13425: req => $newvals{'req'},
13426: }
13427: );
13428: if ($newvals{'xmldc'} ne '') {
13429: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13430: }
13431: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13432: $dom);
13433: if ($putresult eq 'ok') {
13434: my @items = @types;
13435: if ($newvals{'xml'}) {
13436: push(@items,'xmldc');
13437: }
13438: foreach my $item (@items) {
13439: if (exists($currautocreate{$item})) {
13440: if ($currautocreate{$item} ne $newvals{$item}) {
13441: $changes{$item} = 1;
13442: }
13443: } elsif ($newvals{$item}) {
13444: $changes{$item} = 1;
13445: }
13446: }
13447: if (keys(%changes) > 0) {
13448: my @offon = ('off','on');
13449: $resulttext = &mt('Changes made:').'<ul>';
13450: foreach my $item (@types) {
13451: if ($changes{$item}) {
13452: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 13453: $resulttext .= '<li>'.
13454: &mt("$title{$item} set to [_1]$newtxt [_2]",
13455: '<b>','</b>').
13456: '</li>';
1.125 raeburn 13457: }
13458: }
13459: if ($changes{'xmldc'}) {
13460: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13461: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 13462: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13463: }
13464: $resulttext .= '</ul>';
13465: } else {
13466: $resulttext = &mt('No changes made to auto-creation settings');
13467: }
13468: } else {
13469: $resulttext = '<span class="LC_error">'.
13470: &mt('An error occurred: [_1]',$putresult).'</span>';
13471: }
13472: return $resulttext;
13473: }
13474:
1.23 raeburn 13475: sub modify_directorysrch {
1.295 raeburn 13476: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13477: my ($resulttext,%changes);
13478: my %currdirsrch;
13479: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13480: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13481: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13482: }
13483: }
1.277 raeburn 13484: my %title = ( available => 'Institutional directory search available',
13485: localonly => 'Other domains can search institution',
13486: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 13487: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13488: searchby => 'Search types',
13489: searchtypes => 'Search latitude');
13490: my @offon = ('off','on');
1.24 raeburn 13491: my @otherdoms = ('Yes','No');
1.23 raeburn 13492:
1.25 raeburn 13493: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13494: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13495: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13496:
1.44 raeburn 13497: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13498: if (keys(%{$usertypes}) == 0) {
13499: @cansearch = ('default');
13500: } else {
13501: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13502: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13503: if (!grep(/^\Q$type\E$/,@cansearch)) {
13504: push(@{$changes{'cansearch'}},$type);
13505: }
1.23 raeburn 13506: }
1.26 raeburn 13507: foreach my $type (@cansearch) {
13508: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13509: push(@{$changes{'cansearch'}},$type);
13510: }
1.23 raeburn 13511: }
1.26 raeburn 13512: } else {
13513: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13514: }
13515: }
13516:
13517: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13518: foreach my $by (@{$currdirsrch{'searchby'}}) {
13519: if (!grep(/^\Q$by\E$/,@searchby)) {
13520: push(@{$changes{'searchby'}},$by);
13521: }
13522: }
13523: foreach my $by (@searchby) {
13524: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13525: push(@{$changes{'searchby'}},$by);
13526: }
13527: }
13528: } else {
13529: push(@{$changes{'searchby'}},@searchby);
13530: }
1.25 raeburn 13531:
13532: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13533: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13534: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13535: push(@{$changes{'searchtypes'}},$type);
13536: }
13537: }
13538: foreach my $type (@searchtypes) {
13539: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13540: push(@{$changes{'searchtypes'}},$type);
13541: }
13542: }
13543: } else {
13544: if (exists($currdirsrch{'searchtypes'})) {
13545: foreach my $type (@searchtypes) {
13546: if ($type ne $currdirsrch{'searchtypes'}) {
13547: push(@{$changes{'searchtypes'}},$type);
13548: }
13549: }
13550: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13551: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13552: }
13553: } else {
13554: push(@{$changes{'searchtypes'}},@searchtypes);
13555: }
13556: }
13557:
1.23 raeburn 13558: my %dirsrch_hash = (
13559: directorysrch => { available => $env{'form.dirsrch_available'},
13560: cansearch => \@cansearch,
1.277 raeburn 13561: localonly => $env{'form.dirsrch_instlocalonly'},
13562: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13563: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13564: searchby => \@searchby,
1.25 raeburn 13565: searchtypes => \@searchtypes,
1.23 raeburn 13566: }
13567: );
13568: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13569: $dom);
13570: if ($putresult eq 'ok') {
13571: if (exists($currdirsrch{'available'})) {
13572: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13573: $changes{'available'} = 1;
13574: }
13575: } else {
13576: if ($env{'form.dirsrch_available'} eq '1') {
13577: $changes{'available'} = 1;
13578: }
13579: }
1.277 raeburn 13580: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 13581: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13582: $changes{'lcavailable'} = 1;
13583: }
1.277 raeburn 13584: } else {
13585: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13586: $changes{'lcavailable'} = 1;
13587: }
13588: }
1.24 raeburn 13589: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 13590: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
13591: $changes{'localonly'} = 1;
13592: }
1.24 raeburn 13593: } else {
1.277 raeburn 13594: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 13595: $changes{'localonly'} = 1;
13596: }
13597: }
1.277 raeburn 13598: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 13599: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13600: $changes{'lclocalonly'} = 1;
13601: }
1.277 raeburn 13602: } else {
13603: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13604: $changes{'lclocalonly'} = 1;
13605: }
13606: }
1.23 raeburn 13607: if (keys(%changes) > 0) {
13608: $resulttext = &mt('Changes made:').'<ul>';
13609: if ($changes{'available'}) {
13610: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13611: }
1.277 raeburn 13612: if ($changes{'lcavailable'}) {
13613: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13614: }
1.24 raeburn 13615: if ($changes{'localonly'}) {
1.277 raeburn 13616: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 13617: }
1.277 raeburn 13618: if ($changes{'lclocalonly'}) {
13619: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 13620: }
1.23 raeburn 13621: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13622: my $chgtext;
1.26 raeburn 13623: if (ref($usertypes) eq 'HASH') {
13624: if (keys(%{$usertypes}) > 0) {
13625: foreach my $type (@{$types}) {
13626: if (grep(/^\Q$type\E$/,@cansearch)) {
13627: $chgtext .= $usertypes->{$type}.'; ';
13628: }
13629: }
13630: if (grep(/^default$/,@cansearch)) {
13631: $chgtext .= $othertitle;
13632: } else {
13633: $chgtext =~ s/\; $//;
13634: }
1.210 raeburn 13635: $resulttext .=
1.178 raeburn 13636: '<li>'.
13637: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13638: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13639: '</li>';
1.23 raeburn 13640: }
13641: }
13642: }
13643: if (ref($changes{'searchby'}) eq 'ARRAY') {
13644: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13645: my $chgtext;
13646: foreach my $type (@{$titleorder}) {
13647: if (grep(/^\Q$type\E$/,@searchby)) {
13648: if (defined($searchtitles->{$type})) {
13649: $chgtext .= $searchtitles->{$type}.'; ';
13650: }
13651: }
13652: }
13653: $chgtext =~ s/\; $//;
13654: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13655: }
1.25 raeburn 13656: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13657: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13658: my $chgtext;
13659: foreach my $type (@{$srchtypeorder}) {
13660: if (grep(/^\Q$type\E$/,@searchtypes)) {
13661: if (defined($srchtypes_desc->{$type})) {
13662: $chgtext .= $srchtypes_desc->{$type}.'; ';
13663: }
13664: }
13665: }
13666: $chgtext =~ s/\; $//;
1.178 raeburn 13667: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13668: }
13669: $resulttext .= '</ul>';
1.295 raeburn 13670: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13671: if (ref($lastactref) eq 'HASH') {
13672: $lastactref->{'directorysrch'} = 1;
13673: }
1.23 raeburn 13674: } else {
1.277 raeburn 13675: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13676: }
13677: } else {
13678: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13679: &mt('An error occurred: [_1]',$putresult).'</span>';
13680: }
13681: return $resulttext;
13682: }
13683:
1.28 raeburn 13684: sub modify_contacts {
1.205 raeburn 13685: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13686: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13687: if (ref($domconfig{'contacts'}) eq 'HASH') {
13688: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13689: $currsetting{$key} = $domconfig{'contacts'}{$key};
13690: }
13691: }
1.286 raeburn 13692: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13693: my @contacts = ('supportemail','adminemail');
1.286 raeburn 13694: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 13695: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 13696: my @toggles = ('reporterrors','reportupdates','reportstatus');
13697: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 13698: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13699: foreach my $type (@mailings) {
13700: @{$newsetting{$type}} =
13701: &Apache::loncommon::get_env_multiple('form.'.$type);
13702: foreach my $item (@contacts) {
13703: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13704: $contacts_hash{contacts}{$type}{$item} = 1;
13705: } else {
13706: $contacts_hash{contacts}{$type}{$item} = 0;
13707: }
1.289 raeburn 13708: }
1.28 raeburn 13709: $others{$type} = $env{'form.'.$type.'_others'};
13710: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 13711: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13712: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13713: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 13714: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13715: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13716: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13717: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13718: }
1.134 raeburn 13719: }
1.28 raeburn 13720: }
13721: foreach my $item (@contacts) {
13722: $to{$item} = $env{'form.'.$item};
13723: $contacts_hash{'contacts'}{$item} = $to{$item};
13724: }
1.203 raeburn 13725: foreach my $item (@toggles) {
13726: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13727: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13728: }
13729: }
1.340 raeburn 13730: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13731: foreach my $item (@lonstatus) {
13732: if ($item eq 'excluded') {
13733: my (%serverhomes,@excluded);
13734: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13735: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13736: if (@possexcluded) {
13737: foreach my $id (sort(@possexcluded)) {
13738: if ($serverhomes{$id}) {
13739: push(@excluded,$id);
13740: }
13741: }
13742: }
13743: if (@excluded) {
13744: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13745: }
13746: } elsif ($item eq 'weights') {
13747: foreach my $type ('E','W','N') {
13748: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13749: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13750: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13751: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13752: $env{'form.error'.$item.'_'.$type};
13753: }
13754: }
13755: }
13756: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13757: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13758: if ($env{'form.error'.$item} =~ /^\d+$/) {
13759: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13760: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13761: }
13762: }
13763: }
13764: }
1.286 raeburn 13765: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13766: foreach my $field (@{$fields}) {
13767: if (ref($possoptions->{$field}) eq 'ARRAY') {
13768: my $value = $env{'form.helpform_'.$field};
13769: $value =~ s/^\s+|\s+$//g;
13770: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 13771: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 13772: if ($field eq 'screenshot') {
13773: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13774: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 13775: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 13776: }
13777: }
13778: }
13779: }
13780: }
13781: }
1.315 raeburn 13782: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13783: my (@statuses,%usertypeshash,@overrides);
13784: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13785: @statuses = @{$types};
13786: if (ref($usertypes) eq 'HASH') {
13787: %usertypeshash = %{$usertypes};
13788: }
13789: }
13790: if (@statuses) {
13791: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13792: foreach my $type (@possoverrides) {
13793: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13794: push(@overrides,$type);
13795: }
13796: }
13797: if (@overrides) {
13798: foreach my $type (@overrides) {
13799: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13800: foreach my $item (@contacts) {
13801: if (grep(/^\Q$item\E$/,@standard)) {
13802: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13803: $newsetting{'override_'.$type}{$item} = 1;
13804: } else {
13805: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
13806: $newsetting{'override_'.$type}{$item} = 0;
13807: }
13808: }
13809: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
13810: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13811: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
13812: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
13813: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
13814: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
13815: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
13816: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13817: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
13818: }
13819: }
13820: }
13821: }
1.28 raeburn 13822: if (keys(%currsetting) > 0) {
13823: foreach my $item (@contacts) {
13824: if ($to{$item} ne $currsetting{$item}) {
13825: $changes{$item} = 1;
13826: }
13827: }
13828: foreach my $type (@mailings) {
13829: foreach my $item (@contacts) {
13830: if (ref($currsetting{$type}) eq 'HASH') {
13831: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
13832: push(@{$changes{$type}},$item);
13833: }
13834: } else {
13835: push(@{$changes{$type}},@{$newsetting{$type}});
13836: }
13837: }
13838: if ($others{$type} ne $currsetting{$type}{'others'}) {
13839: push(@{$changes{$type}},'others');
13840: }
1.289 raeburn 13841: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13842: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
13843: push(@{$changes{$type}},'bcc');
13844: }
1.286 raeburn 13845: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
13846: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
13847: push(@{$changes{$type}},'include');
13848: }
13849: }
13850: }
13851: if (ref($fields) eq 'ARRAY') {
13852: if (ref($currsetting{'helpform'}) eq 'HASH') {
13853: foreach my $field (@{$fields}) {
13854: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
13855: push(@{$changes{'helpform'}},$field);
13856: }
13857: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13858: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
13859: push(@{$changes{'helpform'}},'maxsize');
13860: }
13861: }
13862: }
13863: } else {
13864: foreach my $field (@{$fields}) {
13865: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
13866: push(@{$changes{'helpform'}},$field);
13867: }
13868: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
13869: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
13870: push(@{$changes{'helpform'}},'maxsize');
13871: }
13872: }
13873: }
1.134 raeburn 13874: }
1.28 raeburn 13875: }
1.315 raeburn 13876: if (@statuses) {
13877: if (ref($currsetting{'overrides'}) eq 'HASH') {
13878: foreach my $key (keys(%{$currsetting{'overrides'}})) {
13879: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
13880: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
13881: foreach my $item (@contacts,'bcc','others','include') {
13882: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
13883: push(@{$changes{'overrides'}},$key);
13884: last;
13885: }
13886: }
13887: } else {
13888: push(@{$changes{'overrides'}},$key);
13889: }
13890: }
13891: }
13892: foreach my $key (@overrides) {
13893: unless (exists($currsetting{'overrides'}{$key})) {
13894: push(@{$changes{'overrides'}},$key);
13895: }
13896: }
13897: } else {
13898: foreach my $key (@overrides) {
13899: push(@{$changes{'overrides'}},$key);
13900: }
13901: }
13902: }
1.340 raeburn 13903: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
13904: foreach my $key ('excluded','weights','threshold','sysmail') {
13905: if ($key eq 'excluded') {
13906: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13907: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
13908: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13909: (@{$currsetting{'lonstatus'}{$key}})) {
13910: my @diffs =
13911: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
13912: $currsetting{'lonstatus'}{$key});
13913: if (@diffs) {
13914: push(@{$changes{'lonstatus'}},$key);
13915: }
13916: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
13917: push(@{$changes{'lonstatus'}},$key);
13918: }
13919: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
13920: (@{$currsetting{'lonstatus'}{$key}})) {
13921: push(@{$changes{'lonstatus'}},$key);
13922: }
13923: } elsif ($key eq 'weights') {
13924: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
13925: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
13926: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13927: foreach my $type ('E','W','N','U') {
1.340 raeburn 13928: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
13929: $currsetting{'lonstatus'}{$key}{$type}) {
13930: push(@{$changes{'lonstatus'}},$key);
13931: last;
13932: }
13933: }
13934: } else {
1.341 raeburn 13935: foreach my $type ('E','W','N','U') {
1.340 raeburn 13936: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
13937: push(@{$changes{'lonstatus'}},$key);
13938: last;
13939: }
13940: }
13941: }
13942: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 13943: foreach my $type ('E','W','N','U') {
1.340 raeburn 13944: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
13945: push(@{$changes{'lonstatus'}},$key);
13946: last;
13947: }
13948: }
13949: }
13950: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
13951: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13952: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13953: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
13954: push(@{$changes{'lonstatus'}},$key);
13955: }
13956: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
13957: push(@{$changes{'lonstatus'}},$key);
13958: }
13959: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
13960: push(@{$changes{'lonstatus'}},$key);
13961: }
13962: }
13963: }
13964: } else {
13965: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
13966: foreach my $key ('excluded','weights','threshold','sysmail') {
13967: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
13968: push(@{$changes{'lonstatus'}},$key);
13969: }
13970: }
13971: }
13972: }
1.28 raeburn 13973: } else {
13974: my %default;
13975: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
13976: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
13977: $default{'errormail'} = 'adminemail';
13978: $default{'packagesmail'} = 'adminemail';
13979: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 13980: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 13981: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 13982: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 13983: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 13984: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 13985: foreach my $item (@contacts) {
13986: if ($to{$item} ne $default{$item}) {
1.286 raeburn 13987: $changes{$item} = 1;
1.203 raeburn 13988: }
1.28 raeburn 13989: }
13990: foreach my $type (@mailings) {
13991: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
13992: push(@{$changes{$type}},@{$newsetting{$type}});
13993: }
13994: if ($others{$type} ne '') {
13995: push(@{$changes{$type}},'others');
1.134 raeburn 13996: }
1.286 raeburn 13997: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13998: if ($bcc{$type} ne '') {
13999: push(@{$changes{$type}},'bcc');
14000: }
1.286 raeburn 14001: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14002: push(@{$changes{$type}},'include');
14003: }
1.134 raeburn 14004: }
1.28 raeburn 14005: }
1.286 raeburn 14006: if (ref($fields) eq 'ARRAY') {
14007: foreach my $field (@{$fields}) {
14008: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14009: push(@{$changes{'helpform'}},$field);
14010: }
14011: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14012: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14013: push(@{$changes{'helpform'}},'maxsize');
14014: }
14015: }
14016: }
1.289 raeburn 14017: }
1.340 raeburn 14018: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14019: foreach my $key ('excluded','weights','threshold','sysmail') {
14020: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14021: push(@{$changes{'lonstatus'}},$key);
14022: }
14023: }
14024: }
1.28 raeburn 14025: }
1.203 raeburn 14026: foreach my $item (@toggles) {
14027: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
14028: $changes{$item} = 1;
14029: } elsif ((!$env{'form.'.$item}) &&
14030: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
14031: $changes{$item} = 1;
14032: }
14033: }
1.28 raeburn 14034: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
14035: $dom);
14036: if ($putresult eq 'ok') {
14037: if (keys(%changes) > 0) {
1.205 raeburn 14038: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 14039: if (ref($lastactref) eq 'HASH') {
14040: $lastactref->{'domainconfig'} = 1;
14041: }
1.28 raeburn 14042: my ($titles,$short_titles) = &contact_titles();
14043: $resulttext = &mt('Changes made:').'<ul>';
14044: foreach my $item (@contacts) {
14045: if ($changes{$item}) {
14046: $resulttext .= '<li>'.$titles->{$item}.
14047: &mt(' set to: ').
14048: '<span class="LC_cusr_emph">'.
14049: $to{$item}.'</span></li>';
14050: }
14051: }
14052: foreach my $type (@mailings) {
14053: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 14054: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 14055: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 14056: } else {
14057: $resulttext .= '<li>'.$titles->{$type}.': ';
14058: }
1.28 raeburn 14059: my @text;
14060: foreach my $item (@{$newsetting{$type}}) {
14061: push(@text,$short_titles->{$item});
14062: }
14063: if ($others{$type} ne '') {
14064: push(@text,$others{$type});
14065: }
1.286 raeburn 14066: if (@text) {
14067: $resulttext .= '<span class="LC_cusr_emph">'.
14068: join(', ',@text).'</span>';
14069: }
14070: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14071: if ($bcc{$type} ne '') {
1.286 raeburn 14072: my $bcctext;
14073: if (@text) {
1.289 raeburn 14074: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 14075: } else {
14076: $bcctext = '(Bcc)';
14077: }
14078: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
14079: } elsif (!@text) {
14080: $resulttext .= &mt('No one');
14081: }
1.289 raeburn 14082: if ($includestr{$type} ne '') {
1.286 raeburn 14083: if ($includeloc{$type} eq 'b') {
14084: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
14085: } elsif ($includeloc{$type} eq 's') {
14086: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
14087: }
1.134 raeburn 14088: }
1.286 raeburn 14089: } elsif (!@text) {
14090: $resulttext .= &mt('No recipients');
1.134 raeburn 14091: }
14092: $resulttext .= '</li>';
1.28 raeburn 14093: }
14094: }
1.315 raeburn 14095: if (ref($changes{'overrides'}) eq 'ARRAY') {
14096: my @deletions;
14097: foreach my $type (@{$changes{'overrides'}}) {
14098: if ($usertypeshash{$type}) {
14099: if (grep(/^\Q$type\E/,@overrides)) {
14100: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14101: $usertypeshash{$type}).'<ul><li>';
14102: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14103: my @text;
14104: foreach my $item (@contacts) {
14105: if ($newsetting{'override_'.$type}{$item}) {
14106: push(@text,$short_titles->{$item});
14107: }
14108: }
14109: if ($newsetting{'override_'.$type}{'others'} ne '') {
14110: push(@text,$newsetting{'override_'.$type}{'others'});
14111: }
14112:
14113: if (@text) {
14114: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14115: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14116: }
14117: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14118: my $bcctext;
14119: if (@text) {
14120: $bcctext = ' '.&mt('with Bcc to');
14121: } else {
14122: $bcctext = '(Bcc)';
14123: }
14124: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14125: } elsif (!@text) {
14126: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14127: }
14128: $resulttext .= '</li>';
14129: if ($newsetting{'override_'.$type}{'include'} ne '') {
14130: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14131: if ($loc eq 'b') {
14132: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14133: } elsif ($loc eq 's') {
14134: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14135: }
14136: }
14137: }
14138: $resulttext .= '</li></ul></li>';
14139: } else {
14140: push(@deletions,$usertypeshash{$type});
14141: }
14142: }
14143: }
14144: if (@deletions) {
14145: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14146: join(', ',@deletions)).'</li>';
14147: }
14148: }
1.203 raeburn 14149: my @offon = ('off','on');
1.340 raeburn 14150: my $corelink = &core_link_msu();
1.203 raeburn 14151: if ($changes{'reporterrors'}) {
14152: $resulttext .= '<li>'.
14153: &mt('E-mail error reports to [_1] set to "'.
14154: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 14155: $corelink).
1.203 raeburn 14156: '</li>';
14157: }
14158: if ($changes{'reportupdates'}) {
14159: $resulttext .= '<li>'.
14160: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14161: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 14162: $corelink).
1.203 raeburn 14163: '</li>';
14164: }
1.340 raeburn 14165: if ($changes{'reportstatus'}) {
14166: $resulttext .= '<li>'.
14167: &mt('E-mail status if errors above threshold to [_1] set to "'.
14168: $offon[$env{'form.reportstatus'}].'".',
14169: $corelink).
14170: '</li>';
14171: }
14172: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14173: $resulttext .= '<li>'.
14174: &mt('Nightly status check e-mail settings').':<ul>';
14175: my (%defval,%use_def,%shown);
14176: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14177: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14178: $defval{'weights'} =
1.341 raeburn 14179: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 14180: $defval{'excluded'} = &mt('None');
14181: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14182: foreach my $item ('threshold','sysmail','weights','excluded') {
14183: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14184: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14185: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14186: } elsif ($item eq 'weights') {
14187: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 14188: foreach my $type ('E','W','N','U') {
1.340 raeburn 14189: $shown{$item} .= $lonstatus_names->{$type}.'=';
14190: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14191: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14192: } else {
14193: $shown{$item} .= $lonstatus_defs->{$type};
14194: }
14195: $shown{$item} .= ', ';
14196: }
14197: $shown{$item} =~ s/, $//;
14198: } else {
14199: $shown{$item} = $defval{$item};
14200: }
14201: } elsif ($item eq 'excluded') {
14202: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14203: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14204: } else {
14205: $shown{$item} = $defval{$item};
14206: }
14207: }
14208: } else {
14209: $shown{$item} = $defval{$item};
14210: }
14211: }
14212: } else {
14213: foreach my $item ('threshold','weights','excluded','sysmail') {
14214: $shown{$item} = $defval{$item};
14215: }
14216: }
14217: foreach my $item ('threshold','weights','excluded','sysmail') {
14218: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14219: $shown{$item}).'</li>';
14220: }
14221: $resulttext .= '</ul></li>';
14222: }
1.286 raeburn 14223: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14224: my (@optional,@required,@unused,$maxsizechg);
14225: foreach my $field (@{$changes{'helpform'}}) {
14226: if ($field eq 'maxsize') {
14227: $maxsizechg = 1;
14228: next;
14229: }
14230: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 14231: push(@optional,$field);
1.286 raeburn 14232: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14233: push(@unused,$field);
14234: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 14235: push(@required,$field);
1.286 raeburn 14236: }
14237: }
14238: if (@optional) {
14239: $resulttext .= '<li>'.
14240: &mt('Help form fields changed to "Optional": [_1].',
14241: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14242: '</li>';
14243: }
14244: if (@required) {
14245: $resulttext .= '<li>'.
14246: &mt('Help form fields changed to "Required": [_1].',
14247: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14248: '</li>';
14249: }
14250: if (@unused) {
14251: $resulttext .= '<li>'.
14252: &mt('Help form fields changed to "Not shown": [_1].',
14253: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14254: '</li>';
14255: }
14256: if ($maxsizechg) {
14257: $resulttext .= '<li>'.
14258: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14259: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14260: '</li>';
14261: }
14262: }
1.28 raeburn 14263: $resulttext .= '</ul>';
14264: } else {
1.288 raeburn 14265: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14266: }
14267: } else {
14268: $resulttext = '<span class="LC_error">'.
14269: &mt('An error occurred: [_1].',$putresult).'</span>';
14270: }
14271: return $resulttext;
14272: }
14273:
1.357 raeburn 14274: sub modify_privacy {
14275: my ($dom,%domconfig) = @_;
14276: my ($resulttext,%current,%changes);
14277: if (ref($domconfig{'privacy'}) eq 'HASH') {
14278: %current = %{$domconfig{'privacy'}};
14279: }
14280: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
14281: my @items = ('domain','author','course','community');
14282: my %names = &Apache::lonlocal::texthash (
14283: domain => 'Assigned domain role(s)',
14284: author => 'Assigned co-author role(s)',
14285: course => 'Assigned course role(s)',
14286: community => 'Assigned community role',
14287: );
14288: my %roles = &Apache::lonlocal::texthash (
14289: domain => 'Domain role',
14290: author => 'Co-author role',
14291: course => 'Course role',
14292: community => 'Community role',
14293: );
14294: my %titles = &Apache::lonlocal::texthash (
14295: approval => 'Approval for role in different domain',
14296: othdom => 'User information available in other domain',
14297: priv => 'Information viewable by privileged user in same domain',
14298: unpriv => 'Information viewable by unprivileged user in same domain',
14299: instdom => 'Other domain shares institution/provider',
14300: extdom => 'Other domain has different institution/provider',
14301: none => 'Not allowed',
14302: user => 'User authorizes',
14303: domain => 'Domain Coordinator authorizes',
14304: auto => 'Unrestricted',
14305: );
14306: my %fieldnames = &Apache::lonlocal::texthash (
14307: id => 'Student/Employee ID',
14308: permanentemail => 'E-mail address',
14309: lastname => 'Last Name',
14310: firstname => 'First Name',
14311: middlename => 'Middle Name',
14312: generation => 'Generation',
14313: );
14314: my ($othertitle,$usertypes,$types) =
14315: &Apache::loncommon::sorted_inst_types($dom);
14316: my (%by_ip,%by_location,@intdoms,@instdoms);
14317: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14318:
14319: my %privacyhash = (
14320: 'approval' => {
14321: instdom => {},
14322: extdom => {},
14323: },
14324: 'othdom' => {},
14325: 'priv' => {},
14326: 'unpriv' => {},
14327: );
14328: foreach my $item (@items) {
14329: if (@instdoms > 1) {
14330: if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
14331: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
14332: }
14333: if (ref($current{'approval'}) eq 'HASH') {
14334: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
14335: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
14336: $changes{'approval'} = 1;
14337: }
14338: }
14339: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
14340: $changes{'approval'} = 1;
14341: }
14342: }
14343: if (keys(%by_location) > 0) {
14344: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
14345: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
14346: }
14347: if (ref($current{'approval'}) eq 'HASH') {
14348: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
14349: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
14350: $changes{'approval'} = 1;
14351: }
14352: }
14353: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
14354: $changes{'approval'} = 1;
14355: }
14356: }
14357: foreach my $status ('priv','unpriv') {
14358: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
14359: my @newvalues;
14360: foreach my $field (@possibles) {
14361: if (grep(/^\Q$field\E$/,@fields)) {
14362: $privacyhash{$status}{$item}{$field} = 1;
14363: push(@newvalues,$field);
14364: }
14365: }
14366: @newvalues = sort(@newvalues);
14367: if (ref($current{$status}) eq 'HASH') {
14368: if (ref($current{$status}{$item}) eq 'HASH') {
14369: my @currvalues = sort(keys(%{$current{$status}{$item}}));
14370: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14371: if (@diffs > 0) {
14372: $changes{$status} = 1;
14373: }
14374: }
14375: } else {
14376: my @stdfields;
14377: foreach my $field (@fields) {
14378: if ($field eq 'id') {
14379: next if ($status eq 'unpriv');
14380: next if (($status eq 'priv') && ($item eq 'community'));
14381: }
14382: push(@stdfields,$field);
14383: }
14384: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14385: if (@diffs > 0) {
14386: $changes{$status} = 1;
14387: }
14388: }
14389: }
14390: }
14391: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
14392: my @statuses;
14393: if (ref($types) eq 'ARRAY') {
14394: @statuses = @{$types};
14395: }
14396: foreach my $type (@statuses,'default') {
14397: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
14398: my @newvalues;
14399: foreach my $field (sort(@possfields)) {
14400: if (grep(/^\Q$field\E$/,@fields)) {
14401: $privacyhash{'othdom'}{$type}{$field} = 1;
14402: push(@newvalues,$field);
14403: }
14404: }
14405: @newvalues = sort(@newvalues);
14406: if (ref($current{'othdom'}) eq 'HASH') {
14407: if (ref($current{'othdom'}{$type}) eq 'HASH') {
14408: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
14409: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
14410: if (@diffs > 0) {
14411: $changes{'othdom'} = 1;
14412: }
14413: }
14414: } else {
14415: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
14416: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
14417: if (@diffs > 0) {
14418: $changes{'othdom'} = 1;
14419: }
14420: }
14421: }
14422: }
14423: my %confighash = (
14424: privacy => \%privacyhash,
14425: );
14426: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14427: if ($putresult eq 'ok') {
14428: if (keys(%changes) > 0) {
14429: $resulttext = &mt('Changes made: ').'<ul>';
14430: foreach my $key ('approval','othdom','priv','unpriv') {
14431: if ($changes{$key}) {
14432: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14433: if ($key eq 'approval') {
14434: if (keys(%{$privacyhash{$key}{instdom}})) {
14435: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
14436: foreach my $item (@items) {
14437: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
14438: }
14439: $resulttext .= '</ul></li>';
14440: }
14441: if (keys(%{$privacyhash{$key}{extdom}})) {
14442: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
14443: foreach my $item (@items) {
14444: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
14445: }
14446: $resulttext .= '</ul></li>';
14447: }
14448: } elsif ($key eq 'othdom') {
14449: my @statuses;
14450: if (ref($types) eq 'ARRAY') {
14451: @statuses = @{$types};
14452: }
14453: if (ref($privacyhash{$key}) eq 'HASH') {
14454: foreach my $status (@statuses,'default') {
14455: if ($status eq 'default') {
14456: $resulttext .= '<li>'.$othertitle.': ';
14457: } elsif (ref($usertypes) eq 'HASH') {
14458: $resulttext .= '<li>'.$usertypes->{$status}.': ';
14459: } else {
14460: next;
14461: }
14462: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
14463: if (keys(%{$privacyhash{$key}{$status}})) {
14464: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
14465: } else {
14466: $resulttext .= &mt('none');
14467: }
14468: }
14469: $resulttext .= '</li>';
14470: }
14471: }
14472: } else {
14473: foreach my $item (@items) {
14474: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
14475: $resulttext .= '<li>'.$names{$item}.': ';
14476: if (keys(%{$privacyhash{$key}{$item}})) {
14477: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
14478: } else {
14479: $resulttext .= &mt('none');
14480: }
14481: $resulttext .= '</li>';
14482: }
14483: }
14484: }
14485: $resulttext .= '</ul></li>';
14486: }
14487: }
14488: } else {
14489: $resulttext = &mt('No changes made to user information settings');
14490: }
14491: } else {
14492: $resulttext = '<span class="LC_error">'.
14493: &mt('An error occurred: [_1]',$putresult).'</span>';
14494: }
14495: return $resulttext;
14496: }
14497:
1.354 raeburn 14498: sub modify_passwords {
14499: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 14500: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14501: $updatedefaults,$updateconf);
1.354 raeburn 14502: my $customfn = 'resetpw.html';
14503: if (ref($domconfig{'passwords'}) eq 'HASH') {
14504: %current = %{$domconfig{'passwords'}};
14505: }
14506: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14507: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14508: if (ref($types) eq 'ARRAY') {
14509: @oktypes = @{$types};
14510: }
14511: push(@oktypes,'default');
14512:
14513: my %titles = &Apache::lonlocal::texthash (
14514: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14515: intauth_check => 'Check bcrypt cost if authenticated',
14516: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14517: permanent => 'Permanent e-mail address',
14518: critical => 'Critical notification address',
14519: notify => 'Notification address',
14520: min => 'Minimum password length',
14521: max => 'Maximum password length',
14522: chars => 'Required characters',
14523: expire => 'Password expiration (days)',
1.356 raeburn 14524: numsaved => 'Number of previous passwords to save',
1.354 raeburn 14525: reset => 'Resetting Forgotten Password',
14526: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14527: rules => 'Rules for LON-CAPA Passwords',
14528: crsownerchg => 'Course Owner Changing Student Passwords',
14529: username => 'Username',
14530: email => 'E-mail address',
14531: );
14532:
14533: #
14534: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14535: #
14536: my (%curr_defaults,%save_defaults);
14537: if (ref($domconfig{'defaults'}) eq 'HASH') {
14538: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14539: if ($key =~ /^intauth_(cost|check|switch)$/) {
14540: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14541: } else {
14542: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14543: }
14544: }
14545: }
14546: my %staticdefaults = (
14547: 'resetlink' => 2,
14548: 'resetcase' => \@oktypes,
14549: 'resetprelink' => 'both',
14550: 'resetemail' => ['critical','notify','permanent'],
14551: 'intauth_cost' => 10,
14552: 'intauth_check' => 0,
14553: 'intauth_switch' => 0,
14554: );
1.365 raeburn 14555: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 14556: foreach my $type (@oktypes) {
14557: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14558: }
14559: my $linklife = $env{'form.passwords_link'};
14560: $linklife =~ s/^\s+|\s+$//g;
14561: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14562: $newvalues{'resetlink'} = $linklife;
14563: if ($current{'resetlink'}) {
14564: if ($current{'resetlink'} ne $linklife) {
14565: $changes{'reset'} = 1;
14566: }
14567: } elsif (!exists($domconfig{passwords})) {
14568: if ($staticdefaults{'resetlink'} ne $linklife) {
14569: $changes{'reset'} = 1;
14570: }
14571: }
14572: } elsif ($current{'resetlink'}) {
14573: $changes{'reset'} = 1;
14574: }
14575: my @casesens;
14576: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14577: foreach my $case (sort(@posscase)) {
14578: if (grep(/^\Q$case\E$/,@oktypes)) {
14579: push(@casesens,$case);
14580: }
14581: }
14582: $newvalues{'resetcase'} = \@casesens;
14583: if (ref($current{'resetcase'}) eq 'ARRAY') {
14584: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14585: if (@diffs > 0) {
14586: $changes{'reset'} = 1;
14587: }
14588: } elsif (!exists($domconfig{passwords})) {
14589: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14590: if (@diffs > 0) {
14591: $changes{'reset'} = 1;
14592: }
14593: }
14594: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14595: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14596: if (exists($current{'resetprelink'})) {
14597: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14598: $changes{'reset'} = 1;
14599: }
14600: } elsif (!exists($domconfig{passwords})) {
14601: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14602: $changes{'reset'} = 1;
14603: }
14604: }
14605: } elsif ($current{'resetprelink'}) {
14606: $changes{'reset'} = 1;
14607: }
14608: foreach my $type (@oktypes) {
14609: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14610: my @postlink;
14611: foreach my $item (sort(@possplink)) {
14612: if ($item =~ /^(email|username)$/) {
14613: push(@postlink,$item);
14614: }
14615: }
14616: $newvalues{'resetpostlink'}{$type} = \@postlink;
14617: unless ($changes{'reset'}) {
14618: if (ref($current{'resetpostlink'}) eq 'HASH') {
14619: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14620: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14621: if (@diffs > 0) {
14622: $changes{'reset'} = 1;
14623: }
14624: } else {
14625: $changes{'reset'} = 1;
14626: }
14627: } elsif (!exists($domconfig{passwords})) {
14628: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14629: if (@diffs > 0) {
14630: $changes{'reset'} = 1;
14631: }
14632: }
14633: }
14634: }
14635: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14636: my @resetemail;
14637: foreach my $item (sort(@possemailsrc)) {
14638: if ($item =~ /^(permanent|critical|notify)$/) {
14639: push(@resetemail,$item);
14640: }
14641: }
14642: $newvalues{'resetemail'} = \@resetemail;
14643: unless ($changes{'reset'}) {
14644: if (ref($current{'resetemail'}) eq 'ARRAY') {
14645: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14646: if (@diffs > 0) {
14647: $changes{'reset'} = 1;
14648: }
14649: } elsif (!exists($domconfig{passwords})) {
14650: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14651: if (@diffs > 0) {
14652: $changes{'reset'} = 1;
14653: }
14654: }
14655: }
14656: if ($env{'form.passwords_stdtext'} == 0) {
14657: $newvalues{'resetremove'} = 1;
14658: unless ($current{'resetremove'}) {
14659: $changes{'reset'} = 1;
14660: }
14661: } elsif ($current{'resetremove'}) {
14662: $changes{'reset'} = 1;
14663: }
14664: if ($env{'form.passwords_customfile.filename'} ne '') {
14665: my $servadm = $r->dir_config('lonAdmEMail');
14666: my ($configuserok,$author_ok,$switchserver) =
14667: &config_check($dom,$confname,$servadm);
14668: my $error;
14669: if ($configuserok eq 'ok') {
14670: if ($switchserver) {
14671: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14672: } else {
14673: if ($author_ok eq 'ok') {
14674: my ($result,$customurl) =
14675: &publishlogo($r,'upload','passwords_customfile',$dom,
14676: $confname,'customtext/resetpw','','',$customfn);
14677: if ($result eq 'ok') {
14678: $newvalues{'resetcustom'} = $customurl;
14679: $changes{'reset'} = 1;
14680: } else {
14681: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14682: }
14683: } else {
14684: $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);
14685: }
14686: }
14687: } else {
14688: $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);
14689: }
14690: if ($error) {
14691: &Apache::lonnet::logthis($error);
14692: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14693: }
14694: } elsif ($current{'resetcustom'}) {
14695: if ($env{'form.passwords_custom_del'}) {
14696: $changes{'reset'} = 1;
14697: } else {
14698: $newvalues{'resetcustom'} = $current{'resetcustom'};
14699: }
14700: }
14701: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14702: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14703: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14704: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14705: $changes{'intauth'} = 1;
14706: }
14707: } else {
14708: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14709: }
14710: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14711: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14712: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14713: $changes{'intauth'} = 1;
14714: }
14715: } else {
14716: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14717: }
14718: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14719: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14720: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14721: $changes{'intauth'} = 1;
14722: }
14723: } else {
14724: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14725: }
14726: foreach my $item ('cost','check','switch') {
14727: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14728: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14729: $updatedefaults = 1;
14730: }
14731: }
1.356 raeburn 14732: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14733: $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356 raeburn 14734: my $ruleok;
14735: if ($rule eq 'expire') {
1.365 raeburn 14736: if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
14737: ($env{'form.passwords_'.$rule} ne '0')) {
1.359 raeburn 14738: $ruleok = 1;
1.356 raeburn 14739: }
1.365 raeburn 14740: } elsif ($rule eq 'min') {
14741: if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
14742: if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
14743: $ruleok = 1;
14744: }
14745: }
14746: } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
14747: ($env{'form.passwords_'.$rule} ne '0')) {
1.356 raeburn 14748: $ruleok = 1;
14749: }
14750: if ($ruleok) {
1.354 raeburn 14751: $newvalues{$rule} = $env{'form.passwords_'.$rule};
14752: if (exists($current{$rule})) {
14753: if ($newvalues{$rule} ne $current{$rule}) {
14754: $changes{'rules'} = 1;
14755: }
14756: } elsif ($rule eq 'min') {
14757: if ($staticdefaults{$rule} ne $newvalues{$rule}) {
14758: $changes{'rules'} = 1;
14759: }
14760: }
14761: } elsif (exists($current{$rule})) {
14762: $changes{'rules'} = 1;
14763: }
14764: }
14765: my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
14766: my @chars;
14767: foreach my $item (sort(@posschars)) {
14768: if ($item =~ /^(uc|lc|num|spec)$/) {
14769: push(@chars,$item);
14770: }
14771: }
14772: $newvalues{'chars'} = \@chars;
14773: unless ($changes{'rules'}) {
14774: if (ref($current{'chars'}) eq 'ARRAY') {
14775: my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
14776: if (@diffs > 0) {
14777: $changes{'rules'} = 1;
14778: }
14779: } else {
14780: if (@chars > 0) {
14781: $changes{'rules'} = 1;
14782: }
14783: }
14784: }
1.359 raeburn 14785: my %crsownerchg = (
14786: by => [],
14787: for => [],
14788: );
14789: foreach my $item ('by','for') {
14790: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14791: foreach my $type (sort(@posstypes)) {
14792: if (grep(/^\Q$type\E$/,@oktypes)) {
14793: push(@{$crsownerchg{$item}},$type);
14794: }
14795: }
14796: }
14797: $newvalues{'crsownerchg'} = \%crsownerchg;
14798: if (ref($current{'crsownerchg'}) eq 'HASH') {
14799: foreach my $item ('by','for') {
14800: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14801: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14802: if (@diffs > 0) {
14803: $changes{'crsownerchg'} = 1;
14804: last;
14805: }
14806: }
14807: }
14808: } elsif (!exists($domconfig{passwords})) {
14809: foreach my $item ('by','for') {
14810: if (@{$crsownerchg{$item}} > 0) {
14811: $changes{'crsownerchg'} = 1;
14812: last;
14813: }
1.354 raeburn 14814: }
14815: }
14816:
14817: my %confighash = (
14818: defaults => \%save_defaults,
14819: passwords => \%newvalues,
14820: );
14821: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14822:
14823: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14824: if ($putresult eq 'ok') {
14825: if (keys(%changes) > 0) {
14826: $resulttext = &mt('Changes made: ').'<ul>';
14827: foreach my $key ('reset','intauth','rules','crsownerchg') {
14828: if ($changes{$key}) {
1.355 raeburn 14829: unless ($key eq 'intauth') {
14830: $updateconf = 1;
14831: }
1.354 raeburn 14832: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14833: if ($key eq 'reset') {
14834: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14835: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14836: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14837: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
14838: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
14839: &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
14840: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
14841: } else {
14842: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14843: }
14844: if ($confighash{'passwords'}{'resetlink'}) {
14845: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14846: } else {
14847: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14848: &mt('Will default to 2 hours').'</li>';
14849: }
14850: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14851: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14852: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14853: } else {
14854: my $casesens;
14855: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14856: if ($type eq 'default') {
14857: $casesens .= $othertitle.', ';
14858: } elsif ($usertypes->{$type} ne '') {
14859: $casesens .= $usertypes->{$type}.', ';
14860: }
14861: }
14862: $casesens =~ s/\Q, \E$//;
14863: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14864: }
14865: } else {
14866: $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>';
14867: }
14868: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14869: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14870: } else {
14871: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14872: }
14873: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14874: my $output;
14875: if (ref($types) eq 'ARRAY') {
14876: foreach my $type (@{$types}) {
14877: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14878: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14879: $output .= $usertypes->{$type}.' -- '.&mt('none');
14880: } else {
14881: $output .= $usertypes->{$type}.' -- '.
14882: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14883: }
14884: }
14885: }
14886: }
14887: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14888: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14889: $output .= $othertitle.' -- '.&mt('none');
14890: } else {
14891: $output .= $othertitle.' -- '.
14892: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14893: }
14894: }
14895: if ($output) {
14896: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14897: } else {
14898: $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>';
14899: }
14900: } else {
14901: $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>';
14902: }
14903: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14904: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14905: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14906: } else {
14907: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14908: }
14909: } else {
14910: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14911: }
14912: if ($confighash{'passwords'}{'resetremove'}) {
14913: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14914: } else {
14915: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14916: }
14917: if ($confighash{'passwords'}{'resetcustom'}) {
14918: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
14919: $titles{custom},600,500);
14920: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
14921: } else {
14922: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14923: }
14924: } elsif ($key eq 'intauth') {
14925: foreach my $item ('cost','switch','check') {
14926: my $value = $save_defaults{$key.'_'.$item};
14927: if ($item eq 'switch') {
14928: my %optiondesc = &Apache::lonlocal::texthash (
14929: 0 => 'No',
14930: 1 => 'Yes',
14931: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14932: );
14933: if ($value =~ /^(0|1|2)$/) {
14934: $value = $optiondesc{$value};
14935: } else {
14936: $value = &mt('none -- defaults to No');
14937: }
14938: } elsif ($item eq 'check') {
14939: my %optiondesc = &Apache::lonlocal::texthash (
14940: 0 => 'No',
14941: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14942: 2 => 'Yes, disallow login if stored cost is less than domain default',
14943: );
14944: if ($value =~ /^(0|1|2)$/) {
14945: $value = $optiondesc{$value};
14946: } else {
14947: $value = &mt('none -- defaults to No');
14948: }
14949: }
14950: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14951: }
14952: } elsif ($key eq 'rules') {
1.356 raeburn 14953: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 14954: if ($confighash{'passwords'}{$rule} eq '') {
14955: if ($rule eq 'min') {
1.356 raeburn 14956: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 14957: ' '.&mt('Default of [_1] will be used',
14958: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 14959: } else {
14960: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 14961: }
14962: } else {
14963: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14964: }
14965: }
14966: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 14967: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14968: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14969: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14970: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14971: } else {
14972: my %crsownerstr;
14973: foreach my $item ('by','for') {
14974: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14975: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14976: if ($type eq 'default') {
14977: $crsownerstr{$item} .= $othertitle.', ';
14978: } elsif ($usertypes->{$type} ne '') {
14979: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14980: }
14981: }
14982: $crsownerstr{$item} =~ s/\Q, \E$//;
14983: }
14984: }
14985: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14986: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14987: }
1.354 raeburn 14988: } else {
1.359 raeburn 14989: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 14990: }
14991: }
14992: $resulttext .= '</ul></li>';
14993: }
14994: }
14995: $resulttext .= '</ul>';
14996: } else {
14997: $resulttext = &mt('No changes made to password settings');
14998: }
1.355 raeburn 14999: my $cachetime = 24*60*60;
1.354 raeburn 15000: if ($updatedefaults) {
15001: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15002: if (ref($lastactref) eq 'HASH') {
15003: $lastactref->{'domdefaults'} = 1;
15004: }
15005: }
1.355 raeburn 15006: if ($updateconf) {
15007: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
15008: if (ref($lastactref) eq 'HASH') {
15009: $lastactref->{'passwdconf'} = 1;
15010: }
15011: }
1.354 raeburn 15012: } else {
15013: $resulttext = '<span class="LC_error">'.
15014: &mt('An error occurred: [_1]',$putresult).'</span>';
15015: }
15016: if ($errors) {
15017: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15018: $errors.'</ul></p>';
15019: }
15020: return $resulttext;
15021: }
15022:
1.28 raeburn 15023: sub modify_usercreation {
1.27 raeburn 15024: my ($dom,%domconfig) = @_;
1.224 raeburn 15025: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15026: my $warningmsg;
1.27 raeburn 15027: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15028: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 15029: if ($key eq 'cancreate') {
15030: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15031: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 15032: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
15033: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15034: } else {
1.224 raeburn 15035: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15036: }
15037: }
15038: }
15039: } elsif ($key eq 'email_rule') {
15040: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15041: } else {
15042: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15043: }
1.27 raeburn 15044: }
15045: }
15046: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 15047: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 15048: my @contexts = ('author','course','requestcrs');
1.34 raeburn 15049: foreach my $item(@contexts) {
1.224 raeburn 15050: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 15051: }
1.34 raeburn 15052: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15053: foreach my $item (@contexts) {
1.224 raeburn 15054: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15055: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 15056: }
1.27 raeburn 15057: }
1.34 raeburn 15058: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15059: foreach my $item (@contexts) {
1.43 raeburn 15060: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 15061: if ($cancreate{$item} ne 'any') {
15062: push(@{$changes{'cancreate'}},$item);
15063: }
15064: } else {
15065: if ($cancreate{$item} ne 'none') {
15066: push(@{$changes{'cancreate'}},$item);
15067: }
1.27 raeburn 15068: }
15069: }
15070: } else {
1.43 raeburn 15071: foreach my $item (@contexts) {
1.34 raeburn 15072: push(@{$changes{'cancreate'}},$item);
15073: }
1.27 raeburn 15074: }
1.34 raeburn 15075:
1.27 raeburn 15076: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15077: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15078: if (!grep(/^\Q$type\E$/,@username_rule)) {
15079: push(@{$changes{'username_rule'}},$type);
15080: }
15081: }
15082: foreach my $type (@username_rule) {
15083: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15084: push(@{$changes{'username_rule'}},$type);
15085: }
15086: }
15087: } else {
15088: push(@{$changes{'username_rule'}},@username_rule);
15089: }
15090:
1.32 raeburn 15091: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15092: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15093: if (!grep(/^\Q$type\E$/,@id_rule)) {
15094: push(@{$changes{'id_rule'}},$type);
15095: }
15096: }
15097: foreach my $type (@id_rule) {
15098: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15099: push(@{$changes{'id_rule'}},$type);
15100: }
15101: }
15102: } else {
15103: push(@{$changes{'id_rule'}},@id_rule);
15104: }
15105:
1.43 raeburn 15106: my @authen_contexts = ('author','course','domain');
1.325 raeburn 15107: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 15108: my %authhash;
1.43 raeburn 15109: foreach my $item (@authen_contexts) {
1.28 raeburn 15110: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15111: foreach my $auth (@authtypes) {
15112: if (grep(/^\Q$auth\E$/,@authallowed)) {
15113: $authhash{$item}{$auth} = 1;
15114: } else {
15115: $authhash{$item}{$auth} = 0;
15116: }
15117: }
15118: }
15119: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15120: foreach my $item (@authen_contexts) {
1.28 raeburn 15121: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15122: foreach my $auth (@authtypes) {
15123: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15124: push(@{$changes{'authtypes'}},$item);
15125: last;
15126: }
15127: }
15128: }
15129: }
15130: } else {
1.43 raeburn 15131: foreach my $item (@authen_contexts) {
1.28 raeburn 15132: push(@{$changes{'authtypes'}},$item);
15133: }
15134: }
15135:
1.224 raeburn 15136: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15137: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15138: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15139: $save_usercreate{'id_rule'} = \@id_rule;
15140: $save_usercreate{'username_rule'} = \@username_rule,
15141: $save_usercreate{'authtypes'} = \%authhash;
15142:
1.27 raeburn 15143: my %usercreation_hash = (
1.224 raeburn 15144: usercreation => \%save_usercreate,
15145: );
1.27 raeburn 15146:
15147: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15148: $dom);
1.50 raeburn 15149:
1.224 raeburn 15150: if ($putresult eq 'ok') {
15151: if (keys(%changes) > 0) {
15152: $resulttext = &mt('Changes made:').'<ul>';
15153: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15154: my %lt = &usercreation_types();
15155: foreach my $type (@{$changes{'cancreate'}}) {
15156: my $chgtext = $lt{$type}.', ';
15157: if ($cancreate{$type} eq 'none') {
15158: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15159: } elsif ($cancreate{$type} eq 'any') {
15160: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15161: } elsif ($cancreate{$type} eq 'official') {
15162: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15163: } elsif ($cancreate{$type} eq 'unofficial') {
15164: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15165: }
15166: $resulttext .= '<li>'.$chgtext.'</li>';
15167: }
15168: }
15169: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15170: my ($rules,$ruleorder) =
15171: &Apache::lonnet::inst_userrules($dom,'username');
15172: my $chgtext = '<ul>';
15173: foreach my $type (@username_rule) {
15174: if (ref($rules->{$type}) eq 'HASH') {
15175: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15176: }
15177: }
15178: $chgtext .= '</ul>';
15179: if (@username_rule > 0) {
15180: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15181: } else {
15182: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15183: }
15184: }
15185: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15186: my ($idrules,$idruleorder) =
15187: &Apache::lonnet::inst_userrules($dom,'id');
15188: my $chgtext = '<ul>';
15189: foreach my $type (@id_rule) {
15190: if (ref($idrules->{$type}) eq 'HASH') {
15191: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15192: }
15193: }
15194: $chgtext .= '</ul>';
15195: if (@id_rule > 0) {
15196: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15197: } else {
15198: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15199: }
15200: }
15201: my %authname = &authtype_names();
15202: my %context_title = &context_names();
15203: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15204: my $chgtext = '<ul>';
15205: foreach my $type (@{$changes{'authtypes'}}) {
15206: my @allowed;
15207: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15208: foreach my $auth (@authtypes) {
15209: if ($authhash{$type}{$auth}) {
15210: push(@allowed,$authname{$auth});
15211: }
15212: }
15213: if (@allowed > 0) {
15214: $chgtext .= join(', ',@allowed).'</li>';
15215: } else {
15216: $chgtext .= &mt('none').'</li>';
15217: }
15218: }
15219: $chgtext .= '</ul>';
15220: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15221: $resulttext .= '</li>';
15222: }
15223: $resulttext .= '</ul>';
15224: } else {
15225: $resulttext = &mt('No changes made to user creation settings');
15226: }
15227: } else {
15228: $resulttext = '<span class="LC_error">'.
15229: &mt('An error occurred: [_1]',$putresult).'</span>';
15230: }
15231: if ($warningmsg ne '') {
15232: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15233: }
15234: return $resulttext;
15235: }
15236:
15237: sub modify_selfcreation {
1.305 raeburn 15238: my ($dom,$lastactref,%domconfig) = @_;
15239: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15240: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15241: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 15242: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15243: if (ref($typesref) eq 'ARRAY') {
15244: @types = @{$typesref};
15245: }
15246: if (ref($usertypesref) eq 'HASH') {
15247: %usertypes = %{$usertypesref};
1.228 raeburn 15248: }
1.303 raeburn 15249: $usertypes{'default'} = $othertitle;
1.224 raeburn 15250: #
15251: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15252: #
15253: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15254: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15255: if ($key eq 'cancreate') {
15256: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15257: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15258: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 15259: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15260: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15261: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15262: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 15263: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 15264: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15265: } else {
15266: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15267: }
15268: }
15269: }
15270: } elsif ($key eq 'email_rule') {
15271: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15272: } else {
15273: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15274: }
15275: }
15276: }
15277: #
15278: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15279: #
15280: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15281: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15282: if ($key eq 'selfcreate') {
15283: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15284: } else {
15285: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15286: }
15287: }
15288: }
1.305 raeburn 15289: #
15290: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15291: #
15292: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15293: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15294: if ($key eq 'inststatusguest') {
15295: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15296: } else {
15297: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15298: }
15299: }
15300: }
1.224 raeburn 15301:
15302: my @contexts = ('selfcreate');
15303: @{$cancreate{'selfcreate'}} = ();
15304: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 15305: if (@types) {
15306: @{$cancreate{'statustocreate'}} = ();
15307: }
1.236 raeburn 15308: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 15309: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 15310: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 15311: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 15312: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15313: my %selfcreatetypes = (
15314: sso => 'users authenticated by institutional single sign on',
15315: login => 'users authenticated by institutional log-in',
1.303 raeburn 15316: email => 'users verified by e-mail',
1.50 raeburn 15317: );
1.224 raeburn 15318: #
15319: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15320: # is permitted.
15321: #
1.305 raeburn 15322: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 15323:
1.305 raeburn 15324: my (@statuses,%email_rule);
1.228 raeburn 15325: foreach my $item ('login','sso','email') {
1.224 raeburn 15326: if ($item eq 'email') {
1.236 raeburn 15327: if ($env{'form.cancreate_email'}) {
1.305 raeburn 15328: if (@types) {
15329: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15330: foreach my $status (@poss_statuses) {
15331: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15332: push(@statuses,$status);
15333: }
15334: }
15335: $save_inststatus{'inststatusguest'} = \@statuses;
15336: } else {
15337: push(@statuses,'default');
15338: }
15339: if (@statuses) {
15340: my %curr_rule;
15341: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15342: foreach my $type (@statuses) {
15343: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 15344: }
1.305 raeburn 15345: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15346: foreach my $type (@statuses) {
15347: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15348: }
15349: }
15350: push(@{$cancreate{'selfcreate'}},'email');
15351: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15352: my %curremaildom;
15353: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15354: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15355: }
15356: foreach my $type (@statuses) {
15357: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15358: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15359: }
15360: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15361: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15362: }
15363: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15364: #
15365: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15366: #
15367: my $chosen = $1;
15368: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15369: my $emaildom;
15370: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15371: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15372: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15373: if (ref($curremaildom{$type}) eq 'HASH') {
15374: if (exists($curremaildom{$type}{$chosen})) {
15375: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15376: push(@{$changes{'cancreate'}},'emaildomain');
15377: }
15378: } elsif ($emaildom ne '') {
15379: push(@{$changes{'cancreate'}},'emaildomain');
15380: }
15381: } elsif ($emaildom ne '') {
15382: push(@{$changes{'cancreate'}},'emaildomain');
15383: }
15384: }
15385: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15386: } elsif ($chosen eq 'custom') {
15387: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15388: $email_rule{$type} = [];
15389: if (ref($emailrules) eq 'HASH') {
15390: foreach my $rule (@possemail_rules) {
15391: if (exists($emailrules->{$rule})) {
15392: push(@{$email_rule{$type}},$rule);
15393: }
15394: }
15395: }
15396: if (@{$email_rule{$type}}) {
15397: $cancreate{'emailoptions'}{$type} = 'custom';
15398: if (ref($curr_rule{$type}) eq 'ARRAY') {
15399: if (@{$curr_rule{$type}} > 0) {
15400: foreach my $rule (@{$curr_rule{$type}}) {
15401: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15402: push(@{$changes{'email_rule'}},$type);
15403: }
15404: }
15405: }
15406: foreach my $type (@{$email_rule{$type}}) {
15407: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15408: push(@{$changes{'email_rule'}},$type);
15409: }
15410: }
15411: } else {
15412: push(@{$changes{'email_rule'}},$type);
15413: }
15414: }
15415: } else {
15416: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15417: }
15418: }
15419: }
15420: if (@types) {
15421: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15422: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15423: if (@changed) {
15424: push(@{$changes{'inststatus'}},'inststatusguest');
15425: }
15426: } else {
15427: push(@{$changes{'inststatus'}},'inststatusguest');
15428: }
15429: }
15430: } else {
15431: delete($env{'form.cancreate_email'});
15432: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15433: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15434: push(@{$changes{'inststatus'}},'inststatusguest');
15435: }
15436: }
15437: }
15438: } else {
15439: $save_inststatus{'inststatusguest'} = [];
15440: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15441: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15442: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 15443: }
15444: }
1.224 raeburn 15445: }
15446: } else {
15447: if ($env{'form.cancreate_'.$item}) {
15448: push(@{$cancreate{'selfcreate'}},$item);
15449: }
15450: }
15451: }
1.305 raeburn 15452: my (%userinfo,%savecaptcha);
1.224 raeburn 15453: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15454: #
1.228 raeburn 15455: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15456: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 15457: #
1.236 raeburn 15458:
1.244 raeburn 15459: if ($env{'form.cancreate_email'}) {
1.228 raeburn 15460: push(@contexts,'emailusername');
1.305 raeburn 15461: if (@statuses) {
15462: foreach my $type (@statuses) {
1.228 raeburn 15463: if (ref($infofields) eq 'ARRAY') {
15464: foreach my $field (@{$infofields}) {
15465: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15466: $cancreate{'emailusername'}{$type}{$field} = $1;
15467: }
15468: }
1.224 raeburn 15469: }
15470: }
15471: }
15472: #
15473: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 15474: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 15475: #
15476:
15477: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15478: @approvalnotify = sort(@approvalnotify);
15479: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15480: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15481: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15482: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15483: push(@{$changes{'cancreate'}},'notify');
15484: }
15485: } else {
15486: if ($cancreate{'notify'}{'approval'}) {
15487: push(@{$changes{'cancreate'}},'notify');
15488: }
15489: }
15490: } elsif ($cancreate{'notify'}{'approval'}) {
15491: push(@{$changes{'cancreate'}},'notify');
15492: }
15493:
15494: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15495: }
15496: #
1.236 raeburn 15497: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 15498: # institutional log-in.
15499: #
15500: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15501: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15502: ($domdefaults{'auth_def'} eq 'localauth'))) {
15503: $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.').' '.
15504: &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.');
15505: }
15506: }
15507: my @fields = ('lastname','firstname','middlename','generation',
15508: 'permanentemail','id');
1.240 raeburn 15509: my @shibfields = (@fields,'inststatus');
1.224 raeburn 15510: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15511: #
15512: # Where usernames may created for institutional log-in and/or institutional single sign on:
15513: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15514: # may self-create accounts
15515: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15516: # which the user may supply, if institutional data is unavailable.
15517: #
15518: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 15519: if (@types) {
1.305 raeburn 15520: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15521: push(@contexts,'statustocreate');
1.303 raeburn 15522: foreach my $type (@types) {
1.224 raeburn 15523: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15524: foreach my $field (@fields) {
15525: if (grep(/^\Q$field\E$/,@modifiable)) {
15526: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15527: } else {
15528: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15529: }
15530: }
15531: }
15532: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 15533: foreach my $type (@types) {
1.224 raeburn 15534: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15535: foreach my $field (@fields) {
15536: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15537: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15538: push(@{$changes{'selfcreate'}},$type);
15539: last;
15540: }
15541: }
15542: }
15543: }
15544: } else {
1.303 raeburn 15545: foreach my $type (@types) {
1.224 raeburn 15546: push(@{$changes{'selfcreate'}},$type);
15547: }
15548: }
15549: }
1.240 raeburn 15550: foreach my $field (@shibfields) {
15551: if ($env{'form.shibenv_'.$field} ne '') {
15552: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15553: }
15554: }
15555: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15556: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15557: foreach my $field (@shibfields) {
15558: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15559: push(@{$changes{'cancreate'}},'shibenv');
15560: }
15561: }
15562: } else {
15563: foreach my $field (@shibfields) {
15564: if ($env{'form.shibenv_'.$field}) {
15565: push(@{$changes{'cancreate'}},'shibenv');
15566: last;
15567: }
15568: }
15569: }
15570: }
1.224 raeburn 15571: }
15572: foreach my $item (@contexts) {
15573: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15574: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15575: if (ref($cancreate{$item}) eq 'ARRAY') {
15576: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15577: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15578: push(@{$changes{'cancreate'}},$item);
15579: }
15580: }
15581: }
15582: }
15583: if (ref($cancreate{$item}) eq 'ARRAY') {
15584: foreach my $type (@{$cancreate{$item}}) {
15585: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15586: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15587: push(@{$changes{'cancreate'}},$item);
15588: }
15589: }
15590: }
15591: }
15592: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15593: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 15594: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15595: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15596: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15597: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15598: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15599: push(@{$changes{'cancreate'}},$item);
15600: }
15601: }
15602: }
1.305 raeburn 15603: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15604: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15605: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15606: push(@{$changes{'cancreate'}},$item);
15607: }
1.224 raeburn 15608: }
15609: }
15610: }
1.305 raeburn 15611: foreach my $type (keys(%{$cancreate{$item}})) {
15612: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15613: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15614: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15615: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 15616: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15617: push(@{$changes{'cancreate'}},$item);
15618: }
15619: }
15620: } else {
15621: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15622: push(@{$changes{'cancreate'}},$item);
15623: }
15624: }
15625: }
1.305 raeburn 15626: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15627: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 15628: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15629: push(@{$changes{'cancreate'}},$item);
15630: }
1.224 raeburn 15631: }
15632: }
15633: }
15634: }
15635: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15636: if (ref($cancreate{$item}) eq 'ARRAY') {
15637: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15638: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15639: push(@{$changes{'cancreate'}},$item);
15640: }
15641: }
1.305 raeburn 15642: }
15643: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15644: if (ref($cancreate{$item}) eq 'HASH') {
15645: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15646: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 15647: }
15648: }
15649: } elsif ($item eq 'emailusername') {
1.228 raeburn 15650: if (ref($cancreate{$item}) eq 'HASH') {
15651: foreach my $type (keys(%{$cancreate{$item}})) {
15652: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15653: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15654: if ($cancreate{$item}{$type}{$field}) {
15655: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15656: push(@{$changes{'cancreate'}},$item);
15657: }
15658: last;
15659: }
15660: }
15661: }
15662: }
1.224 raeburn 15663: }
15664: }
15665: }
15666: #
15667: # Populate %save_usercreate hash with updates to self-creation configuration.
15668: #
15669: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15670: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 15671: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 15672: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15673: if (ref($cancreate{'notify'}) eq 'HASH') {
15674: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15675: }
1.236 raeburn 15676: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15677: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15678: }
1.303 raeburn 15679: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15680: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15681: }
1.305 raeburn 15682: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15683: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15684: }
1.303 raeburn 15685: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15686: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15687: }
1.224 raeburn 15688: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15689: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15690: }
1.240 raeburn 15691: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15692: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15693: }
1.224 raeburn 15694: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 15695: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 15696:
15697: my %userconfig_hash = (
15698: usercreation => \%save_usercreate,
15699: usermodification => \%save_usermodify,
1.305 raeburn 15700: inststatus => \%save_inststatus,
1.224 raeburn 15701: );
1.305 raeburn 15702:
1.224 raeburn 15703: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15704: $dom);
15705: #
1.305 raeburn 15706: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 15707: #
1.27 raeburn 15708: if ($putresult eq 'ok') {
15709: if (keys(%changes) > 0) {
15710: $resulttext = &mt('Changes made:').'<ul>';
15711: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 15712: my %lt = &selfcreation_types();
1.34 raeburn 15713: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 15714: my $chgtext = '';
1.45 raeburn 15715: if ($type eq 'selfcreate') {
1.50 raeburn 15716: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 15717: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15718: } else {
1.224 raeburn 15719: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15720: '<ul>';
1.50 raeburn 15721: foreach my $case (@{$cancreate{$type}}) {
15722: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15723: }
15724: $chgtext .= '</ul>';
1.100 raeburn 15725: if (ref($cancreate{$type}) eq 'ARRAY') {
15726: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15727: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15728: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 15729: $chgtext .= '<span class="LC_warning">'.
15730: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15731: '</span><br />';
15732: }
15733: }
15734: }
15735: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 15736: if (!@statuses) {
15737: $chgtext .= '<span class="LC_warning">'.
15738: &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.").
15739: '</span><br />';
1.303 raeburn 15740:
1.100 raeburn 15741: }
15742: }
15743: }
1.43 raeburn 15744: }
1.240 raeburn 15745: } elsif ($type eq 'shibenv') {
15746: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 15747: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 15748: } else {
15749: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15750: '<ul>';
15751: foreach my $field (@shibfields) {
15752: next if ($cancreate{$type}{$field} eq '');
15753: if ($field eq 'inststatus') {
15754: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15755: } else {
15756: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15757: }
15758: }
15759: $chgtext .= '</ul>';
1.303 raeburn 15760: }
1.93 raeburn 15761: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15762: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15763: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15764: if (@{$cancreate{'selfcreate'}} > 0) {
15765: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15766: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15767: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 15768: $chgtext .= '<br />'.
15769: '<span class="LC_warning">'.
15770: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15771: '</span>';
15772: }
1.303 raeburn 15773: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15774: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15775: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15776: } else {
15777: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15778: }
15779: $chgtext .= '<ul>';
15780: foreach my $case (@{$cancreate{$type}}) {
15781: if ($case eq 'default') {
15782: $chgtext .= '<li>'.$othertitle.'</li>';
15783: } else {
1.303 raeburn 15784: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15785: }
15786: }
1.100 raeburn 15787: $chgtext .= '</ul>';
15788: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 15789: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 15790: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15791: '</span>';
1.100 raeburn 15792: }
15793: }
15794: } else {
15795: if (@{$cancreate{$type}} == 0) {
15796: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15797: } else {
15798: $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 15799: }
15800: }
1.303 raeburn 15801: $chgtext .= '<br />';
1.93 raeburn 15802: }
1.236 raeburn 15803: } elsif ($type eq 'selfcreateprocessing') {
15804: my %choices = &Apache::lonlocal::texthash (
15805: automatic => 'Automatic approval',
15806: approval => 'Queued for approval',
15807: );
1.305 raeburn 15808: if (@types) {
15809: if (@statuses) {
1.303 raeburn 15810: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 15811: '<ul>';
1.305 raeburn 15812: foreach my $status (@statuses) {
15813: if ($status eq 'default') {
15814: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15815: } else {
1.305 raeburn 15816: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 15817: }
15818: }
15819: $chgtext .= '</ul>';
15820: }
15821: } else {
15822: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15823: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15824: }
15825: } elsif ($type eq 'emailverified') {
15826: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 15827: all => 'Same as e-mail',
15828: first => 'Omit @domain',
15829: free => 'Free to choose',
1.303 raeburn 15830: );
1.305 raeburn 15831: if (@types) {
15832: if (@statuses) {
1.303 raeburn 15833: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15834: '<ul>';
1.305 raeburn 15835: foreach my $status (@statuses) {
1.362 raeburn 15836: if ($status eq 'default') {
1.305 raeburn 15837: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15838: } else {
1.305 raeburn 15839: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 15840: }
15841: }
15842: $chgtext .= '</ul>';
15843: }
15844: } else {
1.305 raeburn 15845: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 15846: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 15847: }
1.305 raeburn 15848: } elsif ($type eq 'emailoptions') {
15849: my %options = &Apache::lonlocal::texthash (
15850: any => 'Any e-mail',
15851: inst => 'Institutional only',
15852: noninst => 'Non-institutional only',
15853: custom => 'Custom restrictions',
15854: );
15855: if (@types) {
15856: if (@statuses) {
15857: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15858: '<ul>';
15859: foreach my $status (@statuses) {
15860: if ($type eq 'default') {
15861: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15862: } else {
15863: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 15864: }
15865: }
1.305 raeburn 15866: $chgtext .= '</ul>';
15867: }
15868: } else {
15869: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15870: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15871: } else {
15872: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15873: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 15874: }
1.305 raeburn 15875: }
15876: } elsif ($type eq 'emaildomain') {
15877: my $output;
15878: if (@statuses) {
15879: foreach my $type (@statuses) {
15880: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15881: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15882: if ($type eq 'default') {
15883: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15884: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15885: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15886: } else {
15887: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15888: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15889: }
1.303 raeburn 15890: } else {
1.305 raeburn 15891: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15892: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15893: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15894: } else {
15895: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15896: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15897: }
1.303 raeburn 15898: }
1.305 raeburn 15899: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15900: if ($type eq 'default') {
15901: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15902: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15903: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15904: } else {
15905: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15906: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15907: }
1.303 raeburn 15908: } else {
1.305 raeburn 15909: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15910: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15911: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15912: } else {
15913: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15914: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15915: }
1.303 raeburn 15916: }
15917: }
15918: }
15919: }
1.305 raeburn 15920: }
15921: if ($output ne '') {
15922: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15923: '<ul>'.$output.'</ul>';
1.236 raeburn 15924: }
1.165 raeburn 15925: } elsif ($type eq 'captcha') {
1.224 raeburn 15926: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 15927: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15928: } else {
15929: my %captchas = &captcha_phrases();
1.224 raeburn 15930: if ($captchas{$savecaptcha{$type}}) {
15931: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 15932: } else {
1.210 raeburn 15933: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 15934: }
15935: }
15936: } elsif ($type eq 'recaptchakeys') {
15937: my ($privkey,$pubkey);
1.224 raeburn 15938: if (ref($savecaptcha{$type}) eq 'HASH') {
15939: $pubkey = $savecaptcha{$type}{'public'};
15940: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 15941: }
15942: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15943: if (!$pubkey) {
15944: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15945: } else {
15946: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15947: }
15948: if (!$privkey) {
15949: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15950: } else {
15951: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15952: }
15953: $chgtext .= '</ul>';
1.269 raeburn 15954: } elsif ($type eq 'recaptchaversion') {
15955: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 15956: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 15957: }
1.224 raeburn 15958: } elsif ($type eq 'emailusername') {
15959: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 15960: if (@statuses) {
15961: foreach my $type (@statuses) {
1.228 raeburn 15962: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15963: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 15964: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 15965: '<ul>';
15966: foreach my $field (@{$infofields}) {
15967: if ($cancreate{'emailusername'}{$type}{$field}) {
15968: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15969: }
15970: }
1.245 raeburn 15971: $chgtext .= '</ul>';
15972: } else {
1.303 raeburn 15973: $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 15974: }
15975: } else {
1.303 raeburn 15976: $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 15977: }
15978: }
15979: }
15980: }
15981: } elsif ($type eq 'notify') {
1.303 raeburn 15982: my $numapprove = 0;
1.224 raeburn 15983: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15984: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15985: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 15986: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15987: $numapprove ++;
1.224 raeburn 15988: }
15989: }
1.43 raeburn 15990: }
1.303 raeburn 15991: unless ($numapprove) {
15992: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15993: }
1.34 raeburn 15994: }
1.224 raeburn 15995: if ($chgtext) {
15996: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 15997: }
15998: }
15999: }
1.305 raeburn 16000: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 16001: my ($emailrules,$emailruleorder) =
16002: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 16003: foreach my $type (@{$changes{'email_rule'}}) {
16004: if (ref($email_rule{$type}) eq 'ARRAY') {
16005: my $chgtext = '<ul>';
16006: foreach my $rule (@{$email_rule{$type}}) {
16007: if (ref($emailrules->{$rule}) eq 'HASH') {
16008: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16009: }
16010: }
16011: $chgtext .= '</ul>';
1.310 raeburn 16012: my $typename;
1.305 raeburn 16013: if (@types) {
16014: if ($type eq 'default') {
16015: $typename = $othertitle;
16016: } else {
16017: $typename = $usertypes{$type};
16018: }
16019: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16020: }
16021: if (@{$email_rule{$type}} > 0) {
16022: $resulttext .= '<li>'.
16023: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16024: $usertypes{$type}).
16025: $chgtext.
16026: '</li>';
16027: } else {
16028: $resulttext .= '<li>'.
1.310 raeburn 16029: &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 16030: '</li>'.
1.310 raeburn 16031: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 16032: }
1.43 raeburn 16033: }
16034: }
1.305 raeburn 16035: }
16036: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16037: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16038: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16039: my $chgtext = '<ul>';
16040: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16041: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16042: }
16043: $chgtext .= '</ul>';
16044: $resulttext .= '<li>'.
16045: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16046: $chgtext.
16047: '</li>';
16048: } else {
16049: $resulttext .= '<li>'.
16050: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16051: '</li>';
16052: }
1.43 raeburn 16053: }
16054: }
1.224 raeburn 16055: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16056: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16057: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16058: foreach my $type (@{$changes{'selfcreate'}}) {
16059: my $typename = $type;
1.303 raeburn 16060: if (keys(%usertypes) > 0) {
16061: if ($usertypes{$type} ne '') {
16062: $typename = $usertypes{$type};
1.224 raeburn 16063: }
16064: }
16065: my @modifiable;
16066: $resulttext .= '<li>'.
16067: &mt('Self-creation of account by users with status: [_1]',
16068: '<span class="LC_cusr_emph">'.$typename.'</span>').
16069: ' - '.&mt('modifiable fields (if institutional data blank): ');
16070: foreach my $field (@fields) {
16071: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16072: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 16073: }
16074: }
1.224 raeburn 16075: if (@modifiable > 0) {
16076: $resulttext .= join(', ',@modifiable);
1.43 raeburn 16077: } else {
1.224 raeburn 16078: $resulttext .= &mt('none');
1.43 raeburn 16079: }
1.224 raeburn 16080: $resulttext .= '</li>';
1.28 raeburn 16081: }
1.224 raeburn 16082: $resulttext .= '</ul></li>';
1.28 raeburn 16083: }
1.27 raeburn 16084: $resulttext .= '</ul>';
1.305 raeburn 16085: my $cachetime = 24*60*60;
16086: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16087: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16088: if (ref($lastactref) eq 'HASH') {
16089: $lastactref->{'domdefaults'} = 1;
16090: }
1.27 raeburn 16091: } else {
1.224 raeburn 16092: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 16093: }
16094: } else {
16095: $resulttext = '<span class="LC_error">'.
1.23 raeburn 16096: &mt('An error occurred: [_1]',$putresult).'</span>';
16097: }
1.43 raeburn 16098: if ($warningmsg ne '') {
16099: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16100: }
1.23 raeburn 16101: return $resulttext;
16102: }
16103:
1.165 raeburn 16104: sub process_captcha {
16105: my ($container,$changes,$newsettings,$current) = @_;
16106: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
16107: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16108: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16109: $newsettings->{'captcha'} = 'original';
16110: }
16111: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 16112: if ($container eq 'cancreate') {
1.169 raeburn 16113: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16114: push(@{$changes->{'cancreate'}},'captcha');
16115: } elsif (!defined($changes->{'cancreate'})) {
16116: $changes->{'cancreate'} = ['captcha'];
16117: }
16118: } else {
16119: $changes->{'captcha'} = 1;
1.165 raeburn 16120: }
16121: }
1.269 raeburn 16122: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 16123: if ($newsettings->{'captcha'} eq 'recaptcha') {
16124: $newpub = $env{'form.'.$container.'_recaptchapub'};
16125: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 16126: $newpub =~ s/[^\w\-]//g;
16127: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 16128: $newsettings->{'recaptchakeys'} = {
16129: public => $newpub,
16130: private => $newpriv,
16131: };
1.269 raeburn 16132: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16133: $newversion =~ s/\D//g;
16134: if ($newversion ne '2') {
16135: $newversion = 1;
16136: }
16137: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 16138: }
16139: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
16140: $currpub = $current->{'recaptchakeys'}{'public'};
16141: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 16142: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16143: $newsettings->{'recaptchakeys'} = {
16144: public => '',
16145: private => '',
16146: }
16147: }
1.165 raeburn 16148: }
1.269 raeburn 16149: if ($current->{'captcha'} eq 'recaptcha') {
16150: $currversion = $current->{'recaptchaversion'};
16151: if ($currversion ne '2') {
16152: $currversion = 1;
16153: }
16154: }
16155: if ($currversion ne $newversion) {
16156: if ($container eq 'cancreate') {
16157: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16158: push(@{$changes->{'cancreate'}},'recaptchaversion');
16159: } elsif (!defined($changes->{'cancreate'})) {
16160: $changes->{'cancreate'} = ['recaptchaversion'];
16161: }
16162: } else {
16163: $changes->{'recaptchaversion'} = 1;
16164: }
16165: }
1.165 raeburn 16166: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 16167: if ($container eq 'cancreate') {
16168: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16169: push(@{$changes->{'cancreate'}},'recaptchakeys');
16170: } elsif (!defined($changes->{'cancreate'})) {
16171: $changes->{'cancreate'} = ['recaptchakeys'];
16172: }
16173: } else {
1.210 raeburn 16174: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 16175: }
16176: }
16177: return;
16178: }
16179:
1.33 raeburn 16180: sub modify_usermodification {
16181: my ($dom,%domconfig) = @_;
1.224 raeburn 16182: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16183: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16184: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 16185: if ($key eq 'selfcreate') {
16186: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16187: } else {
16188: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16189: }
1.33 raeburn 16190: }
16191: }
1.224 raeburn 16192: my @contexts = ('author','course');
1.33 raeburn 16193: my %context_title = (
16194: author => 'In author context',
16195: course => 'In course context',
16196: );
16197: my @fields = ('lastname','firstname','middlename','generation',
16198: 'permanentemail','id');
16199: my %roles = (
16200: author => ['ca','aa'],
16201: course => ['st','ep','ta','in','cr'],
16202: );
16203: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16204: foreach my $context (@contexts) {
16205: foreach my $role (@{$roles{$context}}) {
16206: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16207: foreach my $item (@fields) {
16208: if (grep(/^\Q$item\E$/,@modifiable)) {
16209: $modifyhash{$context}{$role}{$item} = 1;
16210: } else {
16211: $modifyhash{$context}{$role}{$item} = 0;
16212: }
16213: }
16214: }
16215: if (ref($curr_usermodification{$context}) eq 'HASH') {
16216: foreach my $role (@{$roles{$context}}) {
16217: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16218: foreach my $field (@fields) {
16219: if ($modifyhash{$context}{$role}{$field} ne
16220: $curr_usermodification{$context}{$role}{$field}) {
16221: push(@{$changes{$context}},$role);
16222: last;
16223: }
16224: }
16225: }
16226: }
16227: } else {
16228: foreach my $context (@contexts) {
16229: foreach my $role (@{$roles{$context}}) {
16230: push(@{$changes{$context}},$role);
16231: }
16232: }
16233: }
16234: }
16235: my %usermodification_hash = (
16236: usermodification => \%modifyhash,
16237: );
16238: my $putresult = &Apache::lonnet::put_dom('configuration',
16239: \%usermodification_hash,$dom);
16240: if ($putresult eq 'ok') {
16241: if (keys(%changes) > 0) {
16242: $resulttext = &mt('Changes made: ').'<ul>';
16243: foreach my $context (@contexts) {
16244: if (ref($changes{$context}) eq 'ARRAY') {
16245: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16246: if (ref($changes{$context}) eq 'ARRAY') {
16247: foreach my $role (@{$changes{$context}}) {
16248: my $rolename;
1.224 raeburn 16249: if ($role eq 'cr') {
16250: $rolename = &mt('Custom');
1.33 raeburn 16251: } else {
1.224 raeburn 16252: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16253: }
16254: my @modifiable;
1.224 raeburn 16255: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16256: foreach my $field (@fields) {
16257: if ($modifyhash{$context}{$role}{$field}) {
16258: push(@modifiable,$fieldtitles{$field});
16259: }
16260: }
16261: if (@modifiable > 0) {
16262: $resulttext .= join(', ',@modifiable);
16263: } else {
16264: $resulttext .= &mt('none');
16265: }
16266: $resulttext .= '</li>';
16267: }
16268: $resulttext .= '</ul></li>';
16269: }
16270: }
16271: }
16272: $resulttext .= '</ul>';
16273: } else {
16274: $resulttext = &mt('No changes made to user modification settings');
16275: }
16276: } else {
16277: $resulttext = '<span class="LC_error">'.
16278: &mt('An error occurred: [_1]',$putresult).'</span>';
16279: }
16280: return $resulttext;
16281: }
16282:
1.43 raeburn 16283: sub modify_defaults {
1.212 raeburn 16284: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16285: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 16286: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 16287: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 16288: 'portal_def');
1.325 raeburn 16289: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 16290: foreach my $item (@items) {
16291: $newvalues{$item} = $env{'form.'.$item};
16292: if ($item eq 'auth_def') {
16293: if ($newvalues{$item} ne '') {
16294: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16295: push(@errors,$item);
16296: }
16297: }
16298: } elsif ($item eq 'lang_def') {
16299: if ($newvalues{$item} ne '') {
16300: if ($newvalues{$item} =~ /^(\w+)/) {
16301: my $langcode = $1;
1.103 raeburn 16302: if ($langcode ne 'x_chef') {
16303: if (code2language($langcode) eq '') {
16304: push(@errors,$item);
16305: }
1.43 raeburn 16306: }
16307: } else {
16308: push(@errors,$item);
16309: }
16310: }
1.54 raeburn 16311: } elsif ($item eq 'timezone_def') {
16312: if ($newvalues{$item} ne '') {
1.62 raeburn 16313: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16314: push(@errors,$item);
16315: }
16316: }
1.68 raeburn 16317: } elsif ($item eq 'datelocale_def') {
16318: if ($newvalues{$item} ne '') {
16319: my @datelocale_ids = DateTime::Locale->ids();
16320: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16321: push(@errors,$item);
16322: }
16323: }
1.141 raeburn 16324: } elsif ($item eq 'portal_def') {
16325: if ($newvalues{$item} ne '') {
16326: 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])\/?$/) {
16327: push(@errors,$item);
16328: }
16329: }
1.43 raeburn 16330: }
16331: if (grep(/^\Q$item\E$/,@errors)) {
16332: $newvalues{$item} = $domdefaults{$item};
16333: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16334: $changes{$item} = 1;
16335: }
1.72 raeburn 16336: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16337: }
1.354 raeburn 16338: my %staticdefaults = (
16339: 'intauth_cost' => 10,
16340: 'intauth_check' => 0,
16341: 'intauth_switch' => 0,
16342: );
16343: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16344: if (exists($domdefaults{$item})) {
16345: $newvalues{$item} = $domdefaults{$item};
16346: } else {
16347: $newvalues{$item} = $staticdefaults{$item};
16348: }
16349: }
1.43 raeburn 16350: my %defaults_hash = (
1.72 raeburn 16351: defaults => \%newvalues,
16352: );
1.43 raeburn 16353: my $title = &defaults_titles();
1.236 raeburn 16354:
16355: my $currinststatus;
16356: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16357: $currinststatus = $domconfig{'inststatus'};
16358: } else {
16359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16360: $currinststatus = {
16361: inststatustypes => $usertypes,
16362: inststatusorder => $types,
16363: inststatusguest => [],
16364: };
16365: }
16366: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16367: my @allpos;
16368: my %alltypes;
1.305 raeburn 16369: my @inststatusguest;
16370: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16371: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16372: unless (grep(/^\Q$type\E$/,@todelete)) {
16373: push(@inststatusguest,$type);
16374: }
16375: }
16376: }
16377: my ($currtitles,$currorder);
1.236 raeburn 16378: if (ref($currinststatus) eq 'HASH') {
16379: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16380: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16381: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16382: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16383: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16384: }
16385: }
16386: unless (grep(/^\Q$type\E$/,@todelete)) {
16387: my $position = $env{'form.inststatus_pos_'.$type};
16388: $position =~ s/\D+//g;
16389: $allpos[$position] = $type;
16390: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16391: $alltypes{$type} =~ s/`//g;
16392: }
16393: }
16394: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16395: $currtitles =~ s/,$//;
16396: }
16397: }
16398: if ($env{'form.addinststatus'}) {
16399: my $newtype = $env{'form.addinststatus'};
16400: $newtype =~ s/\W//g;
16401: unless (exists($alltypes{$newtype})) {
16402: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16403: $alltypes{$newtype} =~ s/`//g;
16404: my $position = $env{'form.addinststatus_pos'};
16405: $position =~ s/\D+//g;
16406: if ($position ne '') {
16407: $allpos[$position] = $newtype;
16408: }
16409: }
16410: }
1.305 raeburn 16411: my @orderedstatus;
1.236 raeburn 16412: foreach my $type (@allpos) {
16413: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16414: push(@orderedstatus,$type);
16415: }
16416: }
16417: foreach my $type (keys(%alltypes)) {
16418: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16419: delete($alltypes{$type});
16420: }
16421: }
16422: $defaults_hash{'inststatus'} = {
16423: inststatustypes => \%alltypes,
16424: inststatusorder => \@orderedstatus,
1.305 raeburn 16425: inststatusguest => \@inststatusguest,
1.236 raeburn 16426: };
16427: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16428: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16429: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16430: }
16431: }
16432: if ($currorder ne join(',',@orderedstatus)) {
16433: $changes{'inststatus'}{'inststatusorder'} = 1;
16434: }
16435: my $newtitles;
16436: foreach my $item (@orderedstatus) {
16437: $newtitles .= $alltypes{$item}.',';
16438: }
16439: $newtitles =~ s/,$//;
16440: if ($currtitles ne $newtitles) {
16441: $changes{'inststatus'}{'inststatustypes'} = 1;
16442: }
1.43 raeburn 16443: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16444: $dom);
16445: if ($putresult eq 'ok') {
16446: if (keys(%changes) > 0) {
16447: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 16448: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16449: 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";
16450: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 16451: if ($item eq 'inststatus') {
16452: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 16453: if (@orderedstatus) {
1.236 raeburn 16454: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16455: foreach my $type (@orderedstatus) {
16456: $resulttext .= $alltypes{$type}.', ';
16457: }
16458: $resulttext =~ s/, $//;
16459: $resulttext .= '</li>';
1.305 raeburn 16460: } else {
16461: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 16462: }
16463: }
16464: } else {
16465: my $value = $env{'form.'.$item};
16466: if ($value eq '') {
16467: $value = &mt('none');
16468: } elsif ($item eq 'auth_def') {
16469: my %authnames = &authtype_names();
16470: my %shortauth = (
16471: internal => 'int',
16472: krb4 => 'krb4',
16473: krb5 => 'krb5',
16474: localauth => 'loc',
1.325 raeburn 16475: lti => 'lti',
1.236 raeburn 16476: );
16477: $value = $authnames{$shortauth{$value}};
16478: }
16479: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16480: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 16481: }
16482: }
16483: $resulttext .= '</ul>';
16484: $mailmsgtext .= "\n";
16485: my $cachetime = 24*60*60;
1.72 raeburn 16486: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 16487: if (ref($lastactref) eq 'HASH') {
16488: $lastactref->{'domdefaults'} = 1;
16489: }
1.68 raeburn 16490: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 16491: my $notify = 1;
16492: if (ref($domconfig{'contacts'}) eq 'HASH') {
16493: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16494: $notify = 0;
16495: }
16496: }
16497: if ($notify) {
16498: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16499: "LON-CAPA Domain Settings Change - $dom",
16500: $mailmsgtext);
16501: }
1.54 raeburn 16502: }
1.43 raeburn 16503: } else {
1.54 raeburn 16504: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16505: }
16506: } else {
16507: $resulttext = '<span class="LC_error">'.
16508: &mt('An error occurred: [_1]',$putresult).'</span>';
16509: }
16510: if (@errors > 0) {
16511: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16512: foreach my $item (@errors) {
16513: $resulttext .= ' "'.$title->{$item}.'",';
16514: }
16515: $resulttext =~ s/,$//;
16516: }
16517: return $resulttext;
16518: }
16519:
1.46 raeburn 16520: sub modify_scantron {
1.205 raeburn 16521: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16522: my ($resulttext,%confhash,%changes,$errors);
16523: my $custom = 'custom.tab';
16524: my $default = 'default.tab';
16525: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 16526: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16527: &config_check($dom,$confname,$servadm);
16528: if ($env{'form.scantronformat.filename'} ne '') {
16529: my $error;
16530: if ($configuserok eq 'ok') {
16531: if ($switchserver) {
1.130 raeburn 16532: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16533: } else {
16534: if ($author_ok eq 'ok') {
16535: my ($result,$scantronurl) =
16536: &publishlogo($r,'upload','scantronformat',$dom,
16537: $confname,'scantron','','',$custom);
16538: if ($result eq 'ok') {
16539: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16540: $changes{'scantronformat'} = 1;
1.46 raeburn 16541: } else {
16542: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16543: }
16544: } else {
16545: $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);
16546: }
16547: }
16548: } else {
16549: $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);
16550: }
16551: if ($error) {
16552: &Apache::lonnet::logthis($error);
16553: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16554: }
16555: }
1.48 raeburn 16556: if (ref($domconfig{'scantron'}) eq 'HASH') {
16557: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16558: if ($env{'form.scantronformat_del'}) {
16559: $confhash{'scantron'}{'scantronformat'} = '';
16560: $changes{'scantronformat'} = 1;
1.347 raeburn 16561: } else {
16562: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 16563: }
16564: }
16565: }
1.347 raeburn 16566: my @options = ('hdr','pad','rem');
1.346 raeburn 16567: my @fields = &scantroncsv_fields();
16568: my %titles = &scantronconfig_titles();
1.347 raeburn 16569: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 16570: my ($newdat,$currdat,%newcol,%currcol);
16571: if (grep(/^dat$/,@formats)) {
16572: $confhash{'scantron'}{config}{dat} = 1;
16573: $newdat = 1;
16574: } else {
16575: $newdat = 0;
16576: }
16577: if (grep(/^csv$/,@formats)) {
16578: my %bynum;
16579: foreach my $field (@fields) {
16580: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16581: my $posscol = $1;
16582: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 16583: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 16584: $bynum{$posscol} = $field;
16585: $newcol{$field} = $posscol;
16586: }
16587: }
16588: }
1.347 raeburn 16589: if (keys(%newcol)) {
16590: foreach my $option (@options) {
16591: if ($env{'form.scantroncsv_'.$option}) {
16592: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16593: }
16594: }
16595: }
1.346 raeburn 16596: }
16597: $currdat = 1;
16598: if (ref($domconfig{'scantron'}) eq 'HASH') {
16599: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 16600: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 16601: $currdat = 0;
16602: }
16603: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16604: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16605: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16606: }
1.346 raeburn 16607: }
16608: }
16609: }
16610: if ($currdat != $newdat) {
16611: $changes{'config'} = 1;
16612: } else {
16613: foreach my $field (@fields) {
16614: if ($currcol{$field} ne '') {
16615: if ($currcol{$field} ne $newcol{$field}) {
16616: $changes{'config'} = 1;
16617: last;
1.347 raeburn 16618: }
1.346 raeburn 16619: } elsif ($newcol{$field} ne '') {
16620: $changes{'config'} = 1;
16621: last;
16622: }
16623: }
16624: }
1.46 raeburn 16625: if (keys(%confhash) > 0) {
16626: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16627: $dom);
16628: if ($putresult eq 'ok') {
16629: if (keys(%changes) > 0) {
1.48 raeburn 16630: if (ref($confhash{'scantron'}) eq 'HASH') {
16631: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 16632: if ($changes{'scantronformat'}) {
16633: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16634: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16635: } else {
16636: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16637: }
16638: }
1.347 raeburn 16639: if ($changes{'config'}) {
1.346 raeburn 16640: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16641: if ($confhash{'scantron'}{'config'}{'dat'}) {
16642: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16643: }
16644: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 16645: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16646: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16647: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16648: foreach my $field (@fields) {
16649: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16650: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16651: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16652: }
16653: }
16654: $resulttext .= '</ul></li>';
16655: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16656: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16657: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16658: foreach my $option (@options) {
16659: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16660: $resulttext .= '<li>'.$titles{$option}.'</li>';
16661: }
16662: }
16663: $resulttext .= '</ul></li>';
16664: }
1.346 raeburn 16665: }
16666: }
16667: }
16668: }
16669: } else {
16670: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16671: }
1.46 raeburn 16672: }
1.48 raeburn 16673: $resulttext .= '</ul>';
16674: } else {
1.130 raeburn 16675: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16676: }
16677: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16678: if (ref($lastactref) eq 'HASH') {
16679: $lastactref->{'domainconfig'} = 1;
16680: }
1.46 raeburn 16681: } else {
1.346 raeburn 16682: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16683: }
16684: } else {
16685: $resulttext = '<span class="LC_error">'.
16686: &mt('An error occurred: [_1]',$putresult).'</span>';
16687: }
16688: } else {
1.130 raeburn 16689: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 16690: }
16691: if ($errors) {
1.353 raeburn 16692: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16693: $errors.'</ul></p>';
1.46 raeburn 16694: }
16695: return $resulttext;
16696: }
16697:
1.48 raeburn 16698: sub modify_coursecategories {
1.239 raeburn 16699: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16700: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16701: $cathash);
1.48 raeburn 16702: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 16703: my @catitems = ('unauth','auth');
16704: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16705: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16706: $cathash = $domconfig{'coursecategories'}{'cats'};
16707: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16708: $changes{'togglecats'} = 1;
16709: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16710: }
16711: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16712: $changes{'categorize'} = 1;
16713: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16714: }
1.120 raeburn 16715: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16716: $changes{'togglecatscomm'} = 1;
16717: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16718: }
16719: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16720: $changes{'categorizecomm'} = 1;
16721: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 16722:
16723: }
16724: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
16725: $changes{'togglecatsplace'} = 1;
16726: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
16727: }
16728: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
16729: $changes{'categorizeplace'} = 1;
16730: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 16731: }
1.238 raeburn 16732: foreach my $item (@catitems) {
16733: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16734: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16735: $changes{$item} = 1;
16736: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16737: }
16738: }
16739: }
1.57 raeburn 16740: } else {
16741: $changes{'togglecats'} = 1;
16742: $changes{'categorize'} = 1;
1.124 raeburn 16743: $changes{'togglecatscomm'} = 1;
16744: $changes{'categorizecomm'} = 1;
1.272 raeburn 16745: $changes{'togglecatsplace'} = 1;
16746: $changes{'categorizeplace'} = 1;
1.87 raeburn 16747: $domconfig{'coursecategories'} = {
16748: togglecats => $env{'form.togglecats'},
16749: categorize => $env{'form.categorize'},
1.124 raeburn 16750: togglecatscomm => $env{'form.togglecatscomm'},
16751: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 16752: togglecatsplace => $env{'form.togglecatsplace'},
16753: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 16754: };
1.238 raeburn 16755: foreach my $item (@catitems) {
16756: if ($env{'form.coursecat_'.$item} ne 'std') {
16757: $changes{$item} = 1;
16758: }
16759: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16760: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16761: }
16762: }
1.57 raeburn 16763: }
16764: if (ref($cathash) eq 'HASH') {
16765: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16766: push (@deletecategory,'instcode::0');
16767: }
1.120 raeburn 16768: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16769: push(@deletecategory,'communities::0');
16770: }
1.272 raeburn 16771: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
16772: push(@deletecategory,'placement::0');
16773: }
1.48 raeburn 16774: }
1.57 raeburn 16775: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16776: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16777: if (@deletecategory > 0) {
16778: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16779: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16780: foreach my $item (@deletecategory) {
1.57 raeburn 16781: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16782: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16783: $deletions{$item} = 1;
1.57 raeburn 16784: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16785: }
16786: }
16787: }
1.57 raeburn 16788: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16789: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16790: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16791: $reorderings{$item} = 1;
1.57 raeburn 16792: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16793: }
16794: if ($env{'form.addcategory_name_'.$item} ne '') {
16795: my $newcat = $env{'form.addcategory_name_'.$item};
16796: my $newdepth = $depth+1;
16797: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16798: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16799: $adds{$newitem} = 1;
16800: }
16801: if ($env{'form.subcat_'.$item} ne '') {
16802: my $newcat = $env{'form.subcat_'.$item};
16803: my $newdepth = $depth+1;
16804: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16805: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16806: $adds{$newitem} = 1;
16807: }
16808: }
16809: }
16810: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16811: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16812: my $newitem = 'instcode::0';
1.57 raeburn 16813: if ($cathash->{$newitem} eq '') {
16814: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16815: $adds{$newitem} = 1;
16816: }
16817: } else {
16818: my $newitem = 'instcode::0';
1.57 raeburn 16819: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16820: $adds{$newitem} = 1;
16821: }
16822: }
1.120 raeburn 16823: if ($env{'form.communities'} eq '1') {
16824: if (ref($cathash) eq 'HASH') {
16825: my $newitem = 'communities::0';
16826: if ($cathash->{$newitem} eq '') {
16827: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16828: $adds{$newitem} = 1;
16829: }
16830: } else {
16831: my $newitem = 'communities::0';
16832: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16833: $adds{$newitem} = 1;
16834: }
16835: }
1.272 raeburn 16836: if ($env{'form.placement'} eq '1') {
16837: if (ref($cathash) eq 'HASH') {
16838: my $newitem = 'placement::0';
16839: if ($cathash->{$newitem} eq '') {
16840: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16841: $adds{$newitem} = 1;
16842: }
16843: } else {
16844: my $newitem = 'placement::0';
16845: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
16846: $adds{$newitem} = 1;
16847: }
16848: }
1.48 raeburn 16849: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16850: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 16851: ($env{'form.addcategory_name'} ne 'communities') &&
16852: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 16853: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16854: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16855: $adds{$newitem} = 1;
16856: }
1.48 raeburn 16857: }
1.57 raeburn 16858: my $putresult;
1.48 raeburn 16859: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16860: if (keys(%deletions) > 0) {
16861: foreach my $key (keys(%deletions)) {
16862: if ($predelallitems{$key} ne '') {
16863: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16864: }
16865: }
16866: }
16867: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16868: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16869: if (ref($chkcats[0]) eq 'ARRAY') {
16870: my $depth = 0;
16871: my $chg = 0;
16872: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16873: my $name = $chkcats[0][$i];
16874: my $item;
16875: if ($name eq '') {
16876: $chg ++;
16877: } else {
16878: $item = &escape($name).'::0';
16879: if ($chg) {
1.57 raeburn 16880: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16881: }
16882: $depth ++;
1.57 raeburn 16883: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16884: $depth --;
16885: }
16886: }
16887: }
1.57 raeburn 16888: }
16889: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16890: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16891: if ($putresult eq 'ok') {
1.57 raeburn 16892: my %title = (
1.120 raeburn 16893: togglecats => 'Show/Hide a course in catalog',
16894: categorize => 'Assign a category to a course',
16895: togglecatscomm => 'Show/Hide a community in catalog',
16896: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16897: );
16898: my %level = (
1.120 raeburn 16899: dom => 'set in Domain ("Modify Course/Community")',
16900: crs => 'set in Course ("Course Configuration")',
16901: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 16902: none => 'No catalog',
16903: std => 'Standard catalog',
16904: domonly => 'Domain-only catalog',
16905: codesrch => 'Code search form',
1.57 raeburn 16906: );
1.48 raeburn 16907: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16908: if ($changes{'togglecats'}) {
16909: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16910: }
16911: if ($changes{'categorize'}) {
16912: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16913: }
1.120 raeburn 16914: if ($changes{'togglecatscomm'}) {
16915: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16916: }
16917: if ($changes{'categorizecomm'}) {
16918: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16919: }
1.238 raeburn 16920: if ($changes{'unauth'}) {
16921: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16922: }
16923: if ($changes{'auth'}) {
16924: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16925: }
1.57 raeburn 16926: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16927: my $cathash;
16928: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16929: $cathash = $domconfig{'coursecategories'}{'cats'};
16930: } else {
16931: $cathash = {};
16932: }
16933: my (@cats,@trails,%allitems);
16934: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16935: if (keys(%deletions) > 0) {
16936: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16937: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16938: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16939: }
16940: $resulttext .= '</ul></li>';
16941: }
16942: if (keys(%reorderings) > 0) {
16943: my %sort_by_trail;
16944: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16945: foreach my $key (keys(%reorderings)) {
16946: if ($allitems{$key} ne '') {
16947: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16948: }
1.48 raeburn 16949: }
1.57 raeburn 16950: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16951: $resulttext .= '<li>'.$trails[$trail].'</li>';
16952: }
16953: $resulttext .= '</ul></li>';
1.48 raeburn 16954: }
1.57 raeburn 16955: if (keys(%adds) > 0) {
16956: my %sort_by_trail;
16957: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
16958: foreach my $key (keys(%adds)) {
16959: if ($allitems{$key} ne '') {
16960: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16961: }
16962: }
16963: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16964: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 16965: }
1.57 raeburn 16966: $resulttext .= '</ul></li>';
1.48 raeburn 16967: }
1.364 raeburn 16968: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
16969: if (ref($lastactref) eq 'HASH') {
16970: $lastactref->{'cats'} = 1;
16971: }
1.48 raeburn 16972: }
16973: $resulttext .= '</ul>';
1.239 raeburn 16974: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 16975: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
16976: if ($changes{'auth'}) {
16977: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
16978: }
16979: if ($changes{'unauth'}) {
16980: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
16981: }
16982: my $cachetime = 24*60*60;
16983: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 16984: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 16985: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 16986: }
16987: }
1.48 raeburn 16988: } else {
16989: $resulttext = '<span class="LC_error">'.
1.57 raeburn 16990: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 16991: }
16992: } else {
1.120 raeburn 16993: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 16994: }
16995: return $resulttext;
16996: }
16997:
1.69 raeburn 16998: sub modify_serverstatuses {
16999: my ($dom,%domconfig) = @_;
17000: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17001: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17002: %currserverstatus = %{$domconfig{'serverstatuses'}};
17003: }
17004: my @pages = &serverstatus_pages();
17005: foreach my $type (@pages) {
17006: $newserverstatus{$type}{'namedusers'} = '';
17007: $newserverstatus{$type}{'machines'} = '';
17008: if (defined($env{'form.'.$type.'_namedusers'})) {
17009: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17010: my @okusers;
17011: foreach my $user (@users) {
17012: my ($uname,$udom) = split(/:/,$user);
17013: if (($udom =~ /^$match_domain$/) &&
17014: (&Apache::lonnet::domain($udom)) &&
17015: ($uname =~ /^$match_username$/)) {
17016: if (!grep(/^\Q$user\E/,@okusers)) {
17017: push(@okusers,$user);
17018: }
17019: }
17020: }
17021: if (@okusers > 0) {
17022: @okusers = sort(@okusers);
17023: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17024: }
17025: }
17026: if (defined($env{'form.'.$type.'_machines'})) {
17027: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17028: my @okmachines;
17029: foreach my $ip (@machines) {
17030: my @parts = split(/\./,$ip);
17031: next if (@parts < 4);
17032: my $badip = 0;
17033: for (my $i=0; $i<4; $i++) {
17034: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17035: $badip = 1;
17036: last;
17037: }
17038: }
17039: if (!$badip) {
17040: push(@okmachines,$ip);
17041: }
17042: }
17043: @okmachines = sort(@okmachines);
17044: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17045: }
17046: }
17047: my %serverstatushash = (
17048: serverstatuses => \%newserverstatus,
17049: );
17050: foreach my $type (@pages) {
1.83 raeburn 17051: foreach my $setting ('namedusers','machines') {
1.84 raeburn 17052: my (@current,@new);
1.83 raeburn 17053: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 17054: if ($currserverstatus{$type}{$setting} ne '') {
17055: @current = split(/,/,$currserverstatus{$type}{$setting});
17056: }
17057: }
17058: if ($newserverstatus{$type}{$setting} ne '') {
17059: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 17060: }
17061: if (@current > 0) {
17062: if (@new > 0) {
17063: foreach my $item (@current) {
17064: if (!grep(/^\Q$item\E$/,@new)) {
17065: $changes{$type}{$setting} = 1;
1.82 raeburn 17066: last;
17067: }
17068: }
1.84 raeburn 17069: foreach my $item (@new) {
17070: if (!grep(/^\Q$item\E$/,@current)) {
17071: $changes{$type}{$setting} = 1;
17072: last;
1.82 raeburn 17073: }
17074: }
17075: } else {
1.83 raeburn 17076: $changes{$type}{$setting} = 1;
1.69 raeburn 17077: }
1.83 raeburn 17078: } elsif (@new > 0) {
17079: $changes{$type}{$setting} = 1;
1.69 raeburn 17080: }
17081: }
17082: }
17083: if (keys(%changes) > 0) {
1.81 raeburn 17084: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 17085: my $putresult = &Apache::lonnet::put_dom('configuration',
17086: \%serverstatushash,$dom);
17087: if ($putresult eq 'ok') {
17088: $resulttext .= &mt('Changes made:').'<ul>';
17089: foreach my $type (@pages) {
1.84 raeburn 17090: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 17091: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 17092: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 17093: if ($newserverstatus{$type}{'namedusers'} eq '') {
17094: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17095: } else {
17096: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17097: }
1.84 raeburn 17098: }
17099: if ($changes{$type}{'machines'}) {
1.69 raeburn 17100: if ($newserverstatus{$type}{'machines'} eq '') {
17101: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17102: } else {
17103: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
17104: }
17105:
17106: }
17107: $resulttext .= '</ul></li>';
17108: }
17109: }
17110: $resulttext .= '</ul>';
17111: } else {
17112: $resulttext = '<span class="LC_error">'.
17113: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17114:
17115: }
17116: } else {
17117: $resulttext = &mt('No changes made to access to server status pages');
17118: }
17119: return $resulttext;
17120: }
17121:
1.118 jms 17122: sub modify_helpsettings {
1.285 raeburn 17123: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 17124: my ($resulttext,$errors,%changes,%helphash);
17125: my %defaultchecked = ('submitbugs' => 'on');
17126: my @offon = ('off','on');
1.118 jms 17127: my @toggles = ('submitbugs');
1.285 raeburn 17128: my %current = ('submitbugs' => '',
17129: 'adhoc' => {},
17130: );
1.118 jms 17131: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 17132: %current = %{$domconfig{'helpsettings'}};
17133: }
1.285 raeburn 17134: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 17135: foreach my $item (@toggles) {
17136: if ($defaultchecked{$item} eq 'on') {
17137: if ($current{$item} eq '') {
17138: if ($env{'form.'.$item} eq '0') {
17139: $changes{$item} = 1;
17140: }
17141: } elsif ($current{$item} ne $env{'form.'.$item}) {
17142: $changes{$item} = 1;
17143: }
17144: } elsif ($defaultchecked{$item} eq 'off') {
17145: if ($current{$item} eq '') {
17146: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 17147: $changes{$item} = 1;
17148: }
1.282 raeburn 17149: } elsif ($current{$item} ne $env{'form.'.$item}) {
17150: $changes{$item} = 1;
17151: }
17152: }
17153: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17154: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17155: }
17156: }
1.285 raeburn 17157: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 17158: my $confname = $dom.'-domainconfig';
17159: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 17160: my (@allpos,%newsettings,%changedprivs,$newrole);
17161: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 17162: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 17163: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 17164: my %lt = &Apache::lonlocal::texthash(
17165: s => 'system',
17166: d => 'domain',
17167: order => 'Display order',
17168: access => 'Role usage',
1.291 raeburn 17169: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 17170: dh => 'All with domain helpdesk role',
17171: da => 'All with domain helpdesk assistant role',
1.285 raeburn 17172: none => 'None',
17173: status => 'Determined based on institutional status',
17174: inc => 'Include all, but exclude specific personnel',
17175: exc => 'Exclude all, but include specific personnel',
17176: );
17177: for (my $num=0; $num<=$maxnum; $num++) {
17178: my ($prefix,$identifier,$rolename,%curr);
17179: if ($num == $maxnum) {
17180: next unless ($env{'form.newcusthelp'} == $maxnum);
17181: $identifier = 'custhelp'.$num;
17182: $prefix = 'helproles_'.$num;
17183: $rolename = $env{'form.custhelpname'.$num};
17184: $rolename=~s/[^A-Za-z0-9]//gs;
17185: next if ($rolename eq '');
17186: next if (exists($existing{'rolesdef_'.$rolename}));
17187: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17188: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17189: $newprivs{'c'},$confname,$dom);
17190: if ($result ne 'ok') {
17191: $errors .= '<li><span class="LC_error">'.
17192: &mt('An error occurred storing the new custom role: [_1]',
17193: $result).'</span></li>';
17194: next;
17195: } else {
17196: $changedprivs{$rolename} = \%newprivs;
17197: $newrole = $rolename;
17198: }
17199: } else {
17200: $prefix = 'helproles_'.$num;
17201: $rolename = $env{'form.'.$prefix};
17202: next if ($rolename eq '');
17203: next unless (exists($existing{'rolesdef_'.$rolename}));
17204: $identifier = 'custhelp'.$num;
17205: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17206: my %currprivs;
1.289 raeburn 17207: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 17208: split(/\_/,$existing{'rolesdef_'.$rolename});
17209: foreach my $level ('c','d','s') {
17210: if ($newprivs{$level} ne $currprivs{$level}) {
17211: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17212: $newprivs{'c'},$confname,$dom);
17213: if ($result ne 'ok') {
17214: $errors .= '<li><span class="LC_error">'.
17215: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17216: $rolename,$result).'</span></li>';
17217: } else {
17218: $changedprivs{$rolename} = \%newprivs;
17219: }
17220: last;
17221: }
17222: }
17223: if (ref($current{'adhoc'}) eq 'HASH') {
17224: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17225: %curr = %{$current{'adhoc'}{$rolename}};
17226: }
17227: }
17228: }
17229: my $newpos = $env{'form.'.$prefix.'_pos'};
17230: $newpos =~ s/\D+//g;
17231: $allpos[$newpos] = $rolename;
17232: my $newdesc = $env{'form.'.$prefix.'_desc'};
17233: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17234: if ($curr{'desc'}) {
17235: if ($curr{'desc'} ne $newdesc) {
17236: $changes{'customrole'}{$rolename}{'desc'} = 1;
17237: $newsettings{$rolename}{'desc'} = $newdesc;
17238: }
17239: } elsif ($newdesc ne '') {
17240: $changes{'customrole'}{$rolename}{'desc'} = 1;
17241: $newsettings{$rolename}{'desc'} = $newdesc;
17242: }
17243: my $access = $env{'form.'.$prefix.'_access'};
17244: if (grep(/^\Q$access\E$/,@accesstypes)) {
17245: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17246: if ($access eq 'status') {
17247: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17248: if (scalar(@statuses) == 0) {
1.289 raeburn 17249: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 17250: } else {
17251: my (@shownstatus,$numtypes);
17252: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17253: if (ref($types) eq 'ARRAY') {
17254: $numtypes = scalar(@{$types});
17255: foreach my $type (sort(@statuses)) {
17256: if ($type eq 'default') {
17257: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17258: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17259: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17260: push(@shownstatus,$usertypes->{$type});
17261: }
17262: }
17263: }
17264: if (grep(/^default$/,@statuses)) {
17265: push(@shownstatus,$othertitle);
17266: }
17267: if (scalar(@shownstatus) == 1+$numtypes) {
17268: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17269: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17270: } else {
17271: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17272: if (ref($curr{'status'}) eq 'ARRAY') {
17273: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17274: if (@diffs) {
17275: $changes{'customrole'}{$rolename}{$access} = 1;
17276: }
17277: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17278: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 17279: }
1.166 raeburn 17280: }
17281: }
1.285 raeburn 17282: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17283: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17284: my @newspecstaff;
17285: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17286: foreach my $person (sort(@personnel)) {
17287: if ($domhelpdesk{$person}) {
17288: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17289: }
17290: }
17291: if (ref($curr{$access}) eq 'ARRAY') {
17292: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17293: if (@diffs) {
17294: $changes{'customrole'}{$rolename}{$access} = 1;
17295: }
17296: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17297: $changes{'customrole'}{$rolename}{$access} = 1;
17298: }
17299: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17300: my ($uname,$udom) = split(/:/,$person);
17301: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17302: }
17303: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 17304: }
1.285 raeburn 17305: } else {
17306: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17307: }
17308: unless ($curr{'access'} eq $access) {
17309: $changes{'customrole'}{$rolename}{'access'} = 1;
17310: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 17311: }
17312: }
1.285 raeburn 17313: if (@allpos > 0) {
17314: my $idx = 0;
17315: foreach my $rolename (@allpos) {
17316: if ($rolename ne '') {
17317: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17318: if (ref($current{'adhoc'}) eq 'HASH') {
17319: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17320: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17321: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 17322: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 17323: }
17324: }
1.282 raeburn 17325: }
1.285 raeburn 17326: $idx ++;
1.166 raeburn 17327: }
17328: }
1.118 jms 17329: }
1.123 jms 17330: my $putresult;
17331: if (keys(%changes) > 0) {
1.166 raeburn 17332: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 17333: if ($putresult eq 'ok') {
1.285 raeburn 17334: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17335: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17336: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17337: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17338: }
17339: }
17340: my $cachetime = 24*60*60;
17341: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17342: if (ref($lastactref) eq 'HASH') {
17343: $lastactref->{'domdefaults'} = 1;
17344: }
17345: } else {
17346: $errors .= '<li><span class="LC_error">'.
17347: &mt('An error occurred storing the settings: [_1]',
17348: $putresult).'</span></li>';
17349: }
17350: }
17351: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17352: $resulttext = &mt('Changes made:').'<ul>';
17353: my (%shownprivs,@levelorder);
17354: @levelorder = ('c','d','s');
17355: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 17356: foreach my $item (sort(keys(%changes))) {
17357: if ($item eq 'submitbugs') {
17358: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17359: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17360: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 17361: } elsif ($item eq 'customrole') {
17362: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 17363: my @keyorder = ('order','desc','access','status','exc','inc');
17364: my %keytext = &Apache::lonlocal::texthash(
17365: order => 'Order',
17366: desc => 'Role description',
17367: access => 'Role usage',
1.300 droeschl 17368: status => 'Allowed institutional types',
1.285 raeburn 17369: exc => 'Allowed personnel',
17370: inc => 'Disallowed personnel',
17371: );
1.282 raeburn 17372: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 17373: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17374: if ($role eq $newrole) {
17375: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17376: $role).'<ul>';
17377: } else {
17378: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17379: $role).'<ul>';
17380: }
17381: foreach my $key (@keyorder) {
17382: if ($changes{'customrole'}{$role}{$key}) {
17383: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17384: $keytext{$key},$newsettings{$role}{$key}).
17385: '</li>';
17386: }
17387: }
17388: if (ref($changedprivs{$role}) eq 'HASH') {
17389: $shownprivs{$role} = 1;
17390: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17391: foreach my $level (@levelorder) {
17392: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17393: next if ($item eq '');
17394: my ($priv) = split(/\&/,$item,2);
17395: if (&Apache::lonnet::plaintext($priv)) {
17396: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17397: unless ($level eq 'c') {
17398: $resulttext .= ' ('.$lt{$level}.')';
17399: }
17400: $resulttext .= '</li>';
17401: }
17402: }
17403: }
17404: $resulttext .= '</ul>';
17405: }
17406: $resulttext .= '</ul></li>';
17407: }
17408: }
17409: }
17410: }
17411: }
17412: }
17413: if (keys(%changedprivs)) {
17414: foreach my $role (sort(keys(%changedprivs))) {
17415: unless ($shownprivs{$role}) {
17416: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17417: $role).'<ul>'.
17418: '<li>'.&mt('Privileges set to :').'<ul>';
17419: foreach my $level (@levelorder) {
17420: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17421: next if ($item eq '');
17422: my ($priv) = split(/\&/,$item,2);
17423: if (&Apache::lonnet::plaintext($priv)) {
17424: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17425: unless ($level eq 'c') {
17426: $resulttext .= ' ('.$lt{$level}.')';
17427: }
17428: $resulttext .= '</li>';
17429: }
1.282 raeburn 17430: }
17431: }
1.285 raeburn 17432: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 17433: }
17434: }
17435: }
1.285 raeburn 17436: $resulttext .= '</ul>';
17437: } else {
17438: $resulttext = &mt('No changes made to help settings');
1.118 jms 17439: }
17440: if ($errors) {
1.168 raeburn 17441: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 17442: $errors.'</ul>';
1.118 jms 17443: }
17444: return $resulttext;
17445: }
17446:
1.121 raeburn 17447: sub modify_coursedefaults {
1.212 raeburn 17448: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17449: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 17450: my %defaultchecked = (
17451: 'canuse_pdfforms' => 'off',
17452: 'uselcmath' => 'on',
17453: 'usejsme' => 'on'
17454: );
17455: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 17456: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 17457: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
17458: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
17459: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 17460: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 17461: my %staticdefaults = (
17462: anonsurvey_threshold => 10,
17463: uploadquota => 500,
1.257 raeburn 17464: postsubmit => 60,
1.276 raeburn 17465: mysqltables => 172800,
1.198 raeburn 17466: );
1.314 raeburn 17467: my %texoptions = (
17468: MathJax => 'MathJax',
17469: mimetex => &mt('Convert to Images'),
17470: tth => &mt('TeX to HTML'),
17471: );
1.121 raeburn 17472: $defaultshash{'coursedefaults'} = {};
17473:
17474: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17475: if ($domconfig{'coursedefaults'} eq '') {
17476: $domconfig{'coursedefaults'} = {};
17477: }
17478: }
17479:
17480: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17481: foreach my $item (@toggles) {
17482: if ($defaultchecked{$item} eq 'on') {
17483: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17484: ($env{'form.'.$item} eq '0')) {
17485: $changes{$item} = 1;
1.192 raeburn 17486: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17487: $changes{$item} = 1;
17488: }
17489: } elsif ($defaultchecked{$item} eq 'off') {
17490: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17491: ($env{'form.'.$item} eq '1')) {
17492: $changes{$item} = 1;
17493: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17494: $changes{$item} = 1;
17495: }
17496: }
17497: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17498: }
1.198 raeburn 17499: foreach my $item (@numbers) {
17500: my ($currdef,$newdef);
1.208 raeburn 17501: $newdef = $env{'form.'.$item};
1.198 raeburn 17502: if ($item eq 'anonsurvey_threshold') {
17503: $currdef = $domconfig{'coursedefaults'}{$item};
17504: $newdef =~ s/\D//g;
17505: if ($newdef eq '' || $newdef < 1) {
17506: $newdef = 1;
17507: }
17508: $defaultshash{'coursedefaults'}{$item} = $newdef;
17509: } else {
1.276 raeburn 17510: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17511: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17512: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 17513: }
17514: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 17515: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 17516: }
17517: if ($currdef ne $newdef) {
17518: if ($item eq 'anonsurvey_threshold') {
17519: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17520: $changes{$item} = 1;
17521: }
1.276 raeburn 17522: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 17523: my $setting = $1;
1.276 raeburn 17524: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17525: $changes{$setting} = 1;
1.198 raeburn 17526: }
17527: }
1.139 raeburn 17528: }
17529: }
1.314 raeburn 17530: my $texengine;
17531: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17532: $texengine = $env{'form.texengine'};
1.349 raeburn 17533: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17534: if ($currdef eq '') {
17535: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 17536: $changes{'texengine'} = 1;
17537: }
1.349 raeburn 17538: } elsif ($currdef ne $texengine) {
1.314 raeburn 17539: $changes{'texengine'} = 1;
17540: }
17541: }
17542: if ($texengine ne '') {
17543: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17544: }
1.264 raeburn 17545: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17546: my @currclonecode;
17547: if (ref($currclone) eq 'HASH') {
17548: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17549: @currclonecode = @{$currclone->{'instcode'}};
17550: }
17551: }
17552: my $newclone;
1.289 raeburn 17553: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 17554: $newclone = $env{'form.canclone'};
17555: }
17556: if ($newclone eq 'instcode') {
17557: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17558: my (%codedefaults,@code_order,@clonecode);
17559: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17560: \@code_order);
17561: foreach my $item (@code_order) {
17562: if (grep(/^\Q$item\E$/,@newcodes)) {
17563: push(@clonecode,$item);
17564: }
17565: }
17566: if (@clonecode) {
17567: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17568: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17569: if (@diffs) {
17570: $changes{'canclone'} = 1;
17571: }
17572: } else {
17573: $newclone eq '';
17574: }
17575: } elsif ($newclone ne '') {
1.289 raeburn 17576: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17577: }
1.264 raeburn 17578: if ($newclone ne $currclone) {
17579: $changes{'canclone'} = 1;
17580: }
1.257 raeburn 17581: my %credits;
17582: foreach my $type (@types) {
17583: unless ($type eq 'community') {
17584: $credits{$type} = $env{'form.'.$type.'_credits'};
17585: $credits{$type} =~ s/[^\d.]+//g;
17586: }
17587: }
17588: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17589: ($env{'form.coursecredits'} eq '1')) {
17590: $changes{'coursecredits'} = 1;
17591: foreach my $type (keys(%credits)) {
17592: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17593: }
17594: } else {
1.289 raeburn 17595: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 17596: foreach my $type (@types) {
17597: unless ($type eq 'community') {
1.289 raeburn 17598: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 17599: $changes{'coursecredits'} = 1;
17600: }
17601: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17602: }
17603: }
17604: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17605: foreach my $type (@types) {
17606: unless ($type eq 'community') {
17607: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17608: $changes{'coursecredits'} = 1;
17609: last;
17610: }
17611: }
17612: }
17613: }
17614: }
17615: if ($env{'form.postsubmit'} eq '1') {
17616: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17617: my %currtimeout;
17618: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17619: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17620: $changes{'postsubmit'} = 1;
17621: }
17622: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17623: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17624: }
17625: } else {
17626: $changes{'postsubmit'} = 1;
17627: }
17628: foreach my $type (@types) {
17629: my $timeout = $env{'form.'.$type.'_timeout'};
17630: $timeout =~ s/\D//g;
17631: if ($timeout == $staticdefaults{'postsubmit'}) {
17632: $timeout = '';
17633: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17634: $timeout = '0';
17635: }
17636: unless ($timeout eq '') {
17637: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17638: }
17639: if (exists($currtimeout{$type})) {
17640: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 17641: $changes{'postsubmit'} = 1;
1.257 raeburn 17642: }
17643: } elsif ($timeout ne '') {
17644: $changes{'postsubmit'} = 1;
17645: }
17646: }
17647: } else {
17648: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17649: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17650: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17651: $changes{'postsubmit'} = 1;
17652: }
17653: } else {
17654: $changes{'postsubmit'} = 1;
17655: }
1.192 raeburn 17656: }
1.121 raeburn 17657: }
17658: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17659: $dom);
17660: if ($putresult eq 'ok') {
17661: if (keys(%changes) > 0) {
1.213 raeburn 17662: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 17663: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 17664: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 17665: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
17666: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 17667: if ($changes{$item}) {
17668: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17669: }
1.289 raeburn 17670: }
1.192 raeburn 17671: if ($changes{'coursecredits'}) {
17672: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 17673: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17674: $domdefaults{$type.'credits'} =
17675: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17676: }
17677: }
17678: }
17679: if ($changes{'postsubmit'}) {
17680: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17681: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17682: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17683: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17684: $domdefaults{$type.'postsubtimeout'} =
17685: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17686: }
17687: }
1.192 raeburn 17688: }
17689: }
1.198 raeburn 17690: if ($changes{'uploadquota'}) {
17691: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17692: foreach my $type (@types) {
17693: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17694: }
17695: }
17696: }
1.264 raeburn 17697: if ($changes{'canclone'}) {
17698: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17699: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17700: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17701: if (@clonecodes) {
17702: $domdefaults{'canclone'} = join('+',@clonecodes);
17703: }
17704: }
17705: } else {
17706: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17707: }
17708: }
1.121 raeburn 17709: my $cachetime = 24*60*60;
17710: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 17711: if (ref($lastactref) eq 'HASH') {
17712: $lastactref->{'domdefaults'} = 1;
17713: }
1.121 raeburn 17714: }
17715: $resulttext = &mt('Changes made:').'<ul>';
17716: foreach my $item (sort(keys(%changes))) {
17717: if ($item eq 'canuse_pdfforms') {
17718: if ($env{'form.'.$item} eq '1') {
17719: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
17720: } else {
17721: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
17722: }
1.257 raeburn 17723: } elsif ($item eq 'uselcmath') {
17724: if ($env{'form.'.$item} eq '1') {
17725: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
17726: } else {
17727: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17728: }
17729: } elsif ($item eq 'usejsme') {
17730: if ($env{'form.'.$item} eq '1') {
17731: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17732: } else {
1.289 raeburn 17733: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 17734: }
1.314 raeburn 17735: } elsif ($item eq 'texengine') {
17736: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17737: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17738: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17739: }
1.139 raeburn 17740: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 17741: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 17742: } elsif ($item eq 'uploadquota') {
17743: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17744: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17745: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17746: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 17747: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 17748: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 17749: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17750: '</ul>'.
17751: '</li>';
17752: } else {
17753: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17754: }
1.276 raeburn 17755: } elsif ($item eq 'mysqltables') {
17756: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17757: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17758: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17759: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17760: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17761: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
17762: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17763: '</ul>'.
17764: '</li>';
17765: } else {
17766: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17767: }
1.257 raeburn 17768: } elsif ($item eq 'postsubmit') {
17769: if ($domdefaults{'postsubmit'} eq 'off') {
17770: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17771: } else {
17772: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 17773: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 17774: $resulttext .= &mt('durations:').'<ul>';
17775: foreach my $type (@types) {
17776: $resulttext .= '<li>';
17777: my $timeout;
17778: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17779: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17780: }
17781: my $display;
17782: if ($timeout eq '0') {
17783: $display = &mt('unlimited');
17784: } elsif ($timeout eq '') {
17785: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17786: } else {
17787: $display = &mt('[quant,_1,second]',$timeout);
17788: }
17789: if ($type eq 'community') {
17790: $resulttext .= &mt('Communities');
17791: } elsif ($type eq 'official') {
17792: $resulttext .= &mt('Official courses');
17793: } elsif ($type eq 'unofficial') {
17794: $resulttext .= &mt('Unofficial courses');
17795: } elsif ($type eq 'textbook') {
17796: $resulttext .= &mt('Textbook courses');
1.271 raeburn 17797: } elsif ($type eq 'placement') {
17798: $resulttext .= &mt('Placement tests');
1.257 raeburn 17799: }
17800: $resulttext .= ' -- '.$display.'</li>';
17801: }
17802: $resulttext .= '</ul>';
17803: }
1.289 raeburn 17804: $resulttext .= '</li>';
1.257 raeburn 17805: }
1.192 raeburn 17806: } elsif ($item eq 'coursecredits') {
17807: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17808: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 17809: ($domdefaults{'unofficialcredits'} eq '') &&
17810: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 17811: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17812: } else {
17813: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17814: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17815: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 17816: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 17817: '</ul>'.
17818: '</li>';
17819: }
17820: } else {
17821: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17822: }
1.264 raeburn 17823: } elsif ($item eq 'canclone') {
17824: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17825: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17826: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17827: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17828: }
17829: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17830: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17831: } else {
1.289 raeburn 17832: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 17833: }
1.140 raeburn 17834: }
1.121 raeburn 17835: }
17836: $resulttext .= '</ul>';
17837: } else {
17838: $resulttext = &mt('No changes made to course defaults');
17839: }
17840: } else {
17841: $resulttext = '<span class="LC_error">'.
17842: &mt('An error occurred: [_1]',$putresult).'</span>';
17843: }
17844: return $resulttext;
17845: }
17846:
1.231 raeburn 17847: sub modify_selfenrollment {
17848: my ($dom,$lastactref,%domconfig) = @_;
17849: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 17850: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 17851: my %titles = &tool_titles();
1.232 raeburn 17852: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17853: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 17854: $ordered{'default'} = ['types','registered','approval','limit'];
17855:
17856: my (%roles,%shown,%toplevel);
17857: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17858:
17859: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17860: if ($domconfig{'selfenrollment'} eq '') {
17861: $domconfig{'selfenrollment'} = {};
17862: }
17863: }
17864: %toplevel = (
17865: admin => 'Configuration Rights',
17866: default => 'Default settings',
17867: validation => 'Validation of self-enrollment requests',
17868: );
1.233 raeburn 17869: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 17870:
17871: if (ref($ordered{'admin'}) eq 'ARRAY') {
17872: foreach my $item (@{$ordered{'admin'}}) {
17873: foreach my $type (@types) {
17874: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17875: $selfenrollhash{'admin'}{$type}{$item} = 1;
17876: } else {
17877: $selfenrollhash{'admin'}{$type}{$item} = 0;
17878: }
17879: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17880: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17881: if ($selfenrollhash{'admin'}{$type}{$item} ne
17882: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17883: push(@{$changes{'admin'}{$type}},$item);
17884: }
17885: } else {
17886: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17887: push(@{$changes{'admin'}{$type}},$item);
17888: }
17889: }
17890: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17891: push(@{$changes{'admin'}{$type}},$item);
17892: }
17893: }
17894: }
17895: }
17896:
17897: foreach my $item (@{$ordered{'default'}}) {
17898: foreach my $type (@types) {
17899: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17900: if ($item eq 'types') {
17901: unless (($value eq 'all') || ($value eq 'dom')) {
17902: $value = '';
17903: }
17904: } elsif ($item eq 'registered') {
17905: unless ($value eq '1') {
17906: $value = 0;
17907: }
17908: } elsif ($item eq 'approval') {
17909: unless ($value =~ /^[012]$/) {
17910: $value = 0;
17911: }
17912: } else {
17913: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17914: $value = 'none';
17915: }
17916: }
17917: $selfenrollhash{'default'}{$type}{$item} = $value;
17918: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17919: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17920: if ($selfenrollhash{'default'}{$type}{$item} ne
17921: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17922: push(@{$changes{'default'}{$type}},$item);
17923: }
17924: } else {
17925: push(@{$changes{'default'}{$type}},$item);
17926: }
17927: } else {
17928: push(@{$changes{'default'}{$type}},$item);
17929: }
17930: if ($item eq 'limit') {
17931: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17932: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17933: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17934: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17935: }
17936: } else {
17937: $selfenrollhash{'default'}{$type}{'cap'} = '';
17938: }
17939: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17940: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17941: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17942: push(@{$changes{'default'}{$type}},'cap');
17943: }
17944: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17945: push(@{$changes{'default'}{$type}},'cap');
17946: }
17947: }
17948: }
17949: }
17950:
17951: foreach my $item (@{$itemsref}) {
17952: if ($item eq 'fields') {
17953: my @changed;
17954: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
17955: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
17956: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
17957: }
17958: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17959: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
17960: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
17961: $domconfig{'selfenrollment'}{'validation'}{$item});
17962: } else {
17963: @changed = @{$selfenrollhash{'validation'}{$item}};
17964: }
17965: } else {
17966: @changed = @{$selfenrollhash{'validation'}{$item}};
17967: }
17968: if (@changed) {
17969: if ($selfenrollhash{'validation'}{$item}) {
17970: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
17971: } else {
17972: $changes{'validation'}{$item} = &mt('None');
17973: }
17974: }
17975: } else {
17976: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
17977: if ($item eq 'markup') {
17978: if ($env{'form.selfenroll_validation_'.$item}) {
17979: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
17980: }
17981: }
17982: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
17983: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
17984: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
17985: }
17986: }
17987: }
17988: }
17989:
17990: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
17991: $dom);
17992: if ($putresult eq 'ok') {
17993: if (keys(%changes) > 0) {
17994: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17995: $resulttext = &mt('Changes made:').'<ul>';
17996: foreach my $key ('admin','default','validation') {
17997: if (ref($changes{$key}) eq 'HASH') {
17998: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
17999: if ($key eq 'validation') {
18000: foreach my $item (@{$itemsref}) {
18001: if (exists($changes{$key}{$item})) {
18002: if ($item eq 'markup') {
18003: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18004: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
18005: } else {
18006: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18007: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
18008: }
18009: }
18010: }
18011: } else {
18012: foreach my $type (@types) {
18013: if ($type eq 'community') {
18014: $roles{'1'} = &mt('Community personnel');
18015: } else {
18016: $roles{'1'} = &mt('Course personnel');
18017: }
18018: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 18019: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18020: if ($key eq 'admin') {
18021: my @mgrdc = ();
18022: if (ref($ordered{$key}) eq 'ARRAY') {
18023: foreach my $item (@{$ordered{'admin'}}) {
18024: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18025: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
18026: push(@mgrdc,$item);
18027: }
18028: }
18029: }
18030: if (@mgrdc) {
18031: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
18032: } else {
18033: delete($domdefaults{$type.'selfenrolladmdc'});
18034: }
18035: }
18036: } else {
18037: if (ref($ordered{$key}) eq 'ARRAY') {
18038: foreach my $item (@{$ordered{$key}}) {
18039: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18040: $domdefaults{$type.'selfenroll'.$item} =
18041: $selfenrollhash{$key}{$type}{$item};
18042: }
18043: }
18044: }
18045: }
18046: }
1.231 raeburn 18047: $resulttext .= '<li>'.$titles{$type}.'<ul>';
18048: foreach my $item (@{$ordered{$key}}) {
18049: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18050: $resulttext .= '<li>';
18051: if ($key eq 'admin') {
18052: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
18053: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
18054: } else {
18055: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
18056: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
18057: }
18058: $resulttext .= '</li>';
18059: }
18060: }
18061: $resulttext .= '</ul></li>';
18062: }
18063: }
18064: $resulttext .= '</ul></li>';
18065: }
18066: }
1.305 raeburn 18067: }
18068: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
18069: my $cachetime = 24*60*60;
18070: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18071: if (ref($lastactref) eq 'HASH') {
18072: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 18073: }
1.231 raeburn 18074: }
18075: $resulttext .= '</ul>';
18076: } else {
18077: $resulttext = &mt('No changes made to self-enrollment settings');
18078: }
18079: } else {
18080: $resulttext = '<span class="LC_error">'.
18081: &mt('An error occurred: [_1]',$putresult).'</span>';
18082: }
18083: return $resulttext;
18084: }
18085:
1.137 raeburn 18086: sub modify_usersessions {
1.212 raeburn 18087: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 18088: my @hostingtypes = ('version','excludedomain','includedomain');
18089: my @offloadtypes = ('primary','default');
18090: my %types = (
18091: remote => \@hostingtypes,
18092: hosted => \@hostingtypes,
18093: spares => \@offloadtypes,
18094: );
18095: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 18096: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 18097: my (%by_ip,%by_location,@intdoms,@instdoms);
18098: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 18099: my @locations = sort(keys(%by_location));
1.137 raeburn 18100: my (%defaultshash,%changes);
18101: foreach my $prefix (@prefixes) {
18102: $defaultshash{'usersessions'}{$prefix} = {};
18103: }
1.212 raeburn 18104: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 18105: my $resulttext;
1.138 raeburn 18106: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 18107: foreach my $prefix (@prefixes) {
1.145 raeburn 18108: next if ($prefix eq 'spares');
18109: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 18110: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18111: if ($type eq 'version') {
18112: my $value = $env{'form.'.$prefix.'_'.$type};
18113: my $okvalue;
18114: if ($value ne '') {
18115: if (grep(/^\Q$value\E$/,@lcversions)) {
18116: $okvalue = $value;
18117: }
18118: }
18119: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18120: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18121: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18122: if ($inuse == 0) {
18123: $changes{$prefix}{$type} = 1;
18124: } else {
18125: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18126: $changes{$prefix}{$type} = 1;
18127: }
18128: if ($okvalue ne '') {
18129: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18130: }
18131: }
18132: } else {
18133: if (($inuse == 1) && ($okvalue ne '')) {
18134: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18135: $changes{$prefix}{$type} = 1;
18136: }
18137: }
18138: } else {
18139: if (($inuse == 1) && ($okvalue ne '')) {
18140: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18141: $changes{$prefix}{$type} = 1;
18142: }
18143: }
18144: } else {
18145: if (($inuse == 1) && ($okvalue ne '')) {
18146: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18147: $changes{$prefix}{$type} = 1;
18148: }
18149: }
18150: } else {
18151: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18152: my @okvals;
18153: foreach my $val (@vals) {
1.138 raeburn 18154: if ($val =~ /:/) {
18155: my @items = split(/:/,$val);
18156: foreach my $item (@items) {
18157: if (ref($by_location{$item}) eq 'ARRAY') {
18158: push(@okvals,$item);
18159: }
18160: }
18161: } else {
18162: if (ref($by_location{$val}) eq 'ARRAY') {
18163: push(@okvals,$val);
18164: }
1.137 raeburn 18165: }
18166: }
18167: @okvals = sort(@okvals);
18168: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18169: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18170: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18171: if ($inuse == 0) {
18172: $changes{$prefix}{$type} = 1;
18173: } else {
18174: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18175: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18176: if (@changed > 0) {
18177: $changes{$prefix}{$type} = 1;
18178: }
18179: }
18180: } else {
18181: if ($inuse == 1) {
18182: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18183: $changes{$prefix}{$type} = 1;
18184: }
18185: }
18186: } else {
18187: if ($inuse == 1) {
18188: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18189: $changes{$prefix}{$type} = 1;
18190: }
18191: }
18192: } else {
18193: if ($inuse == 1) {
18194: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18195: $changes{$prefix}{$type} = 1;
18196: }
18197: }
18198: }
18199: }
18200: }
1.145 raeburn 18201:
18202: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18203: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18204: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18205: my $savespares;
18206:
18207: foreach my $lonhost (sort(keys(%servers))) {
18208: my $serverhomeID =
18209: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18210: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18211: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18212: my %spareschg;
18213: foreach my $type (@{$types{'spares'}}) {
18214: my @okspares;
18215: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18216: foreach my $server (@checked) {
1.152 raeburn 18217: if (&Apache::lonnet::hostname($server) ne '') {
18218: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18219: unless (grep(/^\Q$server\E$/,@okspares)) {
18220: push(@okspares,$server);
18221: }
1.145 raeburn 18222: }
18223: }
18224: }
18225: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18226: my $newspare;
1.152 raeburn 18227: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18228: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18229: $newspare = $new;
18230: }
18231: }
1.152 raeburn 18232: my @spares;
18233: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18234: @spares = sort(@okspares,$newspare);
18235: } else {
18236: @spares = sort(@okspares);
18237: }
18238: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18239: if (ref($spareid{$lonhost}) eq 'HASH') {
18240: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18241: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18242: if (@diffs > 0) {
18243: $spareschg{$type} = 1;
18244: }
18245: }
18246: }
18247: }
18248: if (keys(%spareschg) > 0) {
18249: $changes{'spares'}{$lonhost} = \%spareschg;
18250: }
18251: }
1.261 raeburn 18252: $defaultshash{'usersessions'}{'offloadnow'} = {};
18253: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18254: my @okoffload;
18255: if (@offloadnow) {
18256: foreach my $server (@offloadnow) {
18257: if (&Apache::lonnet::hostname($server) ne '') {
18258: unless (grep(/^\Q$server\E$/,@okoffload)) {
18259: push(@okoffload,$server);
18260: }
18261: }
18262: }
18263: if (@okoffload) {
18264: foreach my $lonhost (@okoffload) {
18265: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18266: }
18267: }
18268: }
1.145 raeburn 18269: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18270: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18271: if (ref($changes{'spares'}) eq 'HASH') {
18272: if (keys(%{$changes{'spares'}}) > 0) {
18273: $savespares = 1;
18274: }
18275: }
18276: } else {
18277: $savespares = 1;
18278: }
1.261 raeburn 18279: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
18280: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
18281: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
18282: $changes{'offloadnow'} = 1;
18283: last;
18284: }
18285: }
18286: unless ($changes{'offloadnow'}) {
1.289 raeburn 18287: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 18288: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
18289: $changes{'offloadnow'} = 1;
18290: last;
18291: }
18292: }
18293: }
18294: } elsif (@okoffload) {
18295: $changes{'offloadnow'} = 1;
18296: }
18297: } elsif (@okoffload) {
18298: $changes{'offloadnow'} = 1;
1.145 raeburn 18299: }
1.147 raeburn 18300: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18301: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18302: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18303: $dom);
18304: if ($putresult eq 'ok') {
18305: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18306: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18307: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18308: }
18309: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18310: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18311: }
1.261 raeburn 18312: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18313: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18314: }
1.137 raeburn 18315: }
18316: my $cachetime = 24*60*60;
18317: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 18318: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 18319: if (ref($lastactref) eq 'HASH') {
18320: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 18321: $lastactref->{'usersessions'} = 1;
1.212 raeburn 18322: }
1.147 raeburn 18323: if (keys(%changes) > 0) {
18324: my %lt = &usersession_titles();
18325: $resulttext = &mt('Changes made:').'<ul>';
18326: foreach my $prefix (@prefixes) {
18327: if (ref($changes{$prefix}) eq 'HASH') {
18328: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18329: if ($prefix eq 'spares') {
18330: if (ref($changes{$prefix}) eq 'HASH') {
18331: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18332: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18333: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 18334: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18335: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18336: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18337: foreach my $type (@{$types{$prefix}}) {
18338: if ($changes{$prefix}{$lonhost}{$type}) {
18339: my $offloadto = &mt('None');
18340: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18341: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18342: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18343: }
1.145 raeburn 18344: }
1.147 raeburn 18345: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18346: }
1.137 raeburn 18347: }
18348: }
1.147 raeburn 18349: $resulttext .= '</li>';
1.137 raeburn 18350: }
18351: }
1.147 raeburn 18352: } else {
18353: foreach my $type (@{$types{$prefix}}) {
18354: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18355: my ($newvalue,$notinuse);
1.147 raeburn 18356: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18357: if (ref($defaultshash{'usersessions'}{$prefix})) {
18358: if ($type eq 'version') {
18359: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 18360: } else {
18361: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18362: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18363: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18364: }
18365: } else {
18366: $notinuse = 1;
1.147 raeburn 18367: }
1.145 raeburn 18368: }
18369: }
18370: }
1.147 raeburn 18371: if ($newvalue eq '') {
18372: if ($type eq 'version') {
18373: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 18374: } elsif ($notinuse) {
18375: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 18376: } else {
18377: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18378: }
1.145 raeburn 18379: } else {
1.147 raeburn 18380: if ($type eq 'version') {
1.344 raeburn 18381: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 18382: }
18383: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18384: }
1.137 raeburn 18385: }
18386: }
18387: }
1.147 raeburn 18388: $resulttext .= '</ul>';
1.137 raeburn 18389: }
18390: }
1.261 raeburn 18391: if ($changes{'offloadnow'}) {
18392: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18393: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
18394: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
18395: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18396: $resulttext .= '<li>'.$lonhost.'</li>';
18397: }
18398: $resulttext .= '</ul>';
18399: } else {
18400: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
18401: }
18402: } else {
18403: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
18404: }
18405: }
1.147 raeburn 18406: $resulttext .= '</ul>';
18407: } else {
18408: $resulttext = $nochgmsg;
1.137 raeburn 18409: }
18410: } else {
18411: $resulttext = '<span class="LC_error">'.
18412: &mt('An error occurred: [_1]',$putresult).'</span>';
18413: }
18414: } else {
1.147 raeburn 18415: $resulttext = $nochgmsg;
1.137 raeburn 18416: }
18417: return $resulttext;
18418: }
18419:
1.275 raeburn 18420: sub modify_ssl {
18421: my ($dom,$lastactref,%domconfig) = @_;
18422: my (%by_ip,%by_location,@intdoms,@instdoms);
18423: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18424: my @locations = sort(keys(%by_location));
18425: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18426: my (%defaultshash,%changes);
18427: my $action = 'ssl';
1.293 raeburn 18428: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 18429: foreach my $prefix (@prefixes) {
18430: $defaultshash{$action}{$prefix} = {};
18431: }
18432: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18433: my $resulttext;
18434: my %iphost = &Apache::lonnet::get_iphost();
18435: my @reptypes = ('certreq','nocertreq');
18436: my @connecttypes = ('dom','intdom','other');
18437: my %types = (
1.293 raeburn 18438: connto => \@connecttypes,
18439: connfrom => \@connecttypes,
18440: replication => \@reptypes,
1.275 raeburn 18441: );
18442: foreach my $prefix (sort(keys(%types))) {
18443: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 18444: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18445: my $value = 'yes';
18446: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
18447: $value = $env{'form.'.$prefix.'_'.$type};
18448: }
1.335 raeburn 18449: if (ref($domconfig{$action}) eq 'HASH') {
18450: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18451: if ($domconfig{$action}{$prefix}{$type} ne '') {
18452: if ($value ne $domconfig{$action}{$prefix}{$type}) {
18453: $changes{$prefix}{$type} = 1;
18454: }
18455: $defaultshash{$action}{$prefix}{$type} = $value;
18456: } else {
18457: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 18458: $changes{$prefix}{$type} = 1;
18459: }
18460: } else {
18461: $defaultshash{$action}{$prefix}{$type} = $value;
18462: $changes{$prefix}{$type} = 1;
18463: }
18464: } else {
18465: $defaultshash{$action}{$prefix}{$type} = $value;
18466: $changes{$prefix}{$type} = 1;
18467: }
18468: if (($type eq 'dom') && (keys(%servers) == 1)) {
18469: delete($changes{$prefix}{$type});
18470: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
18471: delete($changes{$prefix}{$type});
18472: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
18473: delete($changes{$prefix}{$type});
18474: }
18475: } elsif ($prefix eq 'replication') {
18476: if (@locations > 0) {
18477: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18478: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18479: my @okvals;
18480: foreach my $val (@vals) {
18481: if ($val =~ /:/) {
18482: my @items = split(/:/,$val);
18483: foreach my $item (@items) {
18484: if (ref($by_location{$item}) eq 'ARRAY') {
18485: push(@okvals,$item);
18486: }
18487: }
18488: } else {
18489: if (ref($by_location{$val}) eq 'ARRAY') {
18490: push(@okvals,$val);
18491: }
18492: }
18493: }
18494: @okvals = sort(@okvals);
18495: if (ref($domconfig{$action}) eq 'HASH') {
18496: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
18497: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
18498: if ($inuse == 0) {
18499: $changes{$prefix}{$type} = 1;
18500: } else {
18501: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18502: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
18503: if (@changed > 0) {
18504: $changes{$prefix}{$type} = 1;
18505: }
18506: }
18507: } else {
18508: if ($inuse == 1) {
18509: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18510: $changes{$prefix}{$type} = 1;
18511: }
18512: }
18513: } else {
18514: if ($inuse == 1) {
18515: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18516: $changes{$prefix}{$type} = 1;
18517: }
18518: }
18519: } else {
18520: if ($inuse == 1) {
18521: $defaultshash{$action}{$prefix}{$type} = \@okvals;
18522: $changes{$prefix}{$type} = 1;
18523: }
18524: }
18525: }
18526: }
18527: }
18528: }
1.336 raeburn 18529: if (keys(%changes)) {
18530: foreach my $prefix (keys(%changes)) {
18531: if (ref($changes{$prefix}) eq 'HASH') {
18532: if (scalar(keys(%{$changes{$prefix}})) == 0) {
18533: delete($changes{$prefix});
18534: }
18535: } else {
18536: delete($changes{$prefix});
18537: }
18538: }
18539: }
1.275 raeburn 18540: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
18541: if (keys(%changes) > 0) {
18542: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18543: $dom);
18544: if ($putresult eq 'ok') {
18545: if (ref($defaultshash{$action}) eq 'HASH') {
18546: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
18547: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
18548: }
1.293 raeburn 18549: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 18550: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 18551: }
18552: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 18553: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 18554: }
18555: }
18556: my $cachetime = 24*60*60;
18557: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18558: if (ref($lastactref) eq 'HASH') {
18559: $lastactref->{'domdefaults'} = 1;
18560: }
18561: if (keys(%changes) > 0) {
18562: my %titles = &ssl_titles();
18563: $resulttext = &mt('Changes made:').'<ul>';
18564: foreach my $prefix (@prefixes) {
18565: if (ref($changes{$prefix}) eq 'HASH') {
18566: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
18567: foreach my $type (@{$types{$prefix}}) {
18568: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18569: my ($newvalue,$notinuse);
1.275 raeburn 18570: if (ref($defaultshash{$action}) eq 'HASH') {
18571: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 18572: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 18573: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 18574: } else {
18575: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
18576: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
18577: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
18578: }
18579: } else {
18580: $notinuse = 1;
1.275 raeburn 18581: }
18582: }
18583: }
1.344 raeburn 18584: if ($notinuse) {
18585: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
18586: } elsif ($newvalue eq '') {
1.275 raeburn 18587: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
18588: } else {
18589: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
18590: }
18591: }
18592: }
18593: }
18594: $resulttext .= '</ul>';
18595: }
18596: }
18597: } else {
18598: $resulttext = $nochgmsg;
18599: }
18600: } else {
18601: $resulttext = '<span class="LC_error">'.
18602: &mt('An error occurred: [_1]',$putresult).'</span>';
18603: }
18604: } else {
18605: $resulttext = $nochgmsg;
18606: }
18607: return $resulttext;
18608: }
18609:
1.279 raeburn 18610: sub modify_trust {
18611: my ($dom,$lastactref,%domconfig) = @_;
18612: my (%by_ip,%by_location,@intdoms,@instdoms);
18613: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
18614: my @locations = sort(keys(%by_location));
18615: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
18616: my @types = ('exc','inc');
18617: my (%defaultshash,%changes);
18618: foreach my $prefix (@prefixes) {
18619: $defaultshash{'trust'}{$prefix} = {};
18620: }
18621: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18622: my $resulttext;
18623: foreach my $prefix (@prefixes) {
18624: foreach my $type (@types) {
18625: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18626: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18627: my @okvals;
18628: foreach my $val (@vals) {
18629: if ($val =~ /:/) {
18630: my @items = split(/:/,$val);
18631: foreach my $item (@items) {
18632: if (ref($by_location{$item}) eq 'ARRAY') {
18633: push(@okvals,$item);
18634: }
18635: }
18636: } else {
18637: if (ref($by_location{$val}) eq 'ARRAY') {
18638: push(@okvals,$val);
18639: }
18640: }
18641: }
18642: @okvals = sort(@okvals);
18643: if (ref($domconfig{'trust'}) eq 'HASH') {
18644: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
18645: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18646: if ($inuse == 0) {
18647: $changes{$prefix}{$type} = 1;
18648: } else {
18649: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18650: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
18651: if (@changed > 0) {
18652: $changes{$prefix}{$type} = 1;
18653: }
18654: }
18655: } else {
18656: if ($inuse == 1) {
18657: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18658: $changes{$prefix}{$type} = 1;
18659: }
18660: }
18661: } else {
18662: if ($inuse == 1) {
18663: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18664: $changes{$prefix}{$type} = 1;
18665: }
18666: }
18667: } else {
18668: if ($inuse == 1) {
18669: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
18670: $changes{$prefix}{$type} = 1;
18671: }
18672: }
18673: }
18674: }
18675: my $nochgmsg = &mt('No changes made to trust settings.');
18676: if (keys(%changes) > 0) {
18677: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18678: $dom);
18679: if ($putresult eq 'ok') {
18680: if (ref($defaultshash{'trust'}) eq 'HASH') {
18681: foreach my $prefix (@prefixes) {
18682: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
18683: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
18684: }
18685: }
18686: }
18687: my $cachetime = 24*60*60;
18688: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18689: if (ref($lastactref) eq 'HASH') {
18690: $lastactref->{'domdefaults'} = 1;
18691: }
18692: if (keys(%changes) > 0) {
18693: my %lt = &trust_titles();
18694: $resulttext = &mt('Changes made:').'<ul>';
18695: foreach my $prefix (@prefixes) {
18696: if (ref($changes{$prefix}) eq 'HASH') {
18697: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18698: foreach my $type (@types) {
18699: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 18700: my ($newvalue,$notinuse);
1.279 raeburn 18701: if (ref($defaultshash{'trust'}) eq 'HASH') {
18702: if (ref($defaultshash{'trust'}{$prefix})) {
18703: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
18704: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
18705: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
18706: }
1.344 raeburn 18707: } else {
18708: $notinuse = 1;
1.279 raeburn 18709: }
18710: }
18711: }
1.344 raeburn 18712: if ($notinuse) {
18713: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
18714: } elsif ($newvalue eq '') {
1.279 raeburn 18715: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18716: } else {
18717: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
18718: }
18719: }
18720: }
18721: $resulttext .= '</ul>';
18722: }
18723: }
18724: $resulttext .= '</ul>';
18725: } else {
18726: $resulttext = $nochgmsg;
18727: }
18728: } else {
18729: $resulttext = '<span class="LC_error">'.
18730: &mt('An error occurred: [_1]',$putresult).'</span>';
18731: }
18732: } else {
18733: $resulttext = $nochgmsg;
18734: }
18735: return $resulttext;
18736: }
18737:
1.150 raeburn 18738: sub modify_loadbalancing {
18739: my ($dom,%domconfig) = @_;
18740: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18741: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18742: my ($othertitle,$usertypes,$types) =
18743: &Apache::loncommon::sorted_inst_types($dom);
18744: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 18745: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18746: my @sparestypes = ('primary','default');
18747: my %typetitles = &sparestype_titles();
18748: my $resulttext;
1.342 raeburn 18749: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 18750: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18751: %existing = %{$domconfig{'loadbalancing'}};
18752: }
18753: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 18754: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 18755: my ($saveloadbalancing,%defaultshash,%changes);
18756: my ($alltypes,$othertypes,$titles) =
18757: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18758: my %ruletitles = &offloadtype_text();
18759: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18760: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18761: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18762: if ($balancer eq '') {
18763: next;
18764: }
1.210 raeburn 18765: if (!exists($servers{$balancer})) {
1.171 raeburn 18766: if (exists($currbalancer{$balancer})) {
18767: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18768: }
1.171 raeburn 18769: next;
18770: }
18771: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18772: push(@{$changes{'delete'}},$balancer);
18773: next;
18774: }
18775: if (!exists($currbalancer{$balancer})) {
18776: push(@{$changes{'add'}},$balancer);
18777: }
18778: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18779: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18780: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18781: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18782: $saveloadbalancing = 1;
18783: }
18784: foreach my $sparetype (@sparestypes) {
18785: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18786: my @offloadto;
18787: foreach my $target (@targets) {
18788: if (($servers{$target}) && ($target ne $balancer)) {
18789: if ($sparetype eq 'default') {
18790: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18791: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18792: }
18793: }
1.171 raeburn 18794: unless(grep(/^\Q$target\E$/,@offloadto)) {
18795: push(@offloadto,$target);
18796: }
1.150 raeburn 18797: }
18798: }
1.284 raeburn 18799: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18800: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18801: push(@offloadto,$balancer);
18802: }
18803: }
18804: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18805: }
1.342 raeburn 18806: if ($env{'form.loadbalancing_cookie_'.$i}) {
18807: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18808: if (exists($currbalancer{$balancer})) {
18809: unless ($currcookies{$balancer}) {
18810: $changes{'curr'}{$balancer}{'cookie'} = 1;
18811: }
18812: }
18813: } elsif (exists($currbalancer{$balancer})) {
18814: if ($currcookies{$balancer}) {
18815: $changes{'curr'}{$balancer}{'cookie'} = 1;
18816: }
18817: }
1.171 raeburn 18818: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18819: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18820: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18821: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18822: if (@targetdiffs > 0) {
1.171 raeburn 18823: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18824: }
1.171 raeburn 18825: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18826: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18827: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18828: }
18829: }
18830: }
18831: } else {
1.171 raeburn 18832: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 18833: foreach my $sparetype (@sparestypes) {
1.171 raeburn 18834: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18835: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18836: $changes{'curr'}{$balancer}{'targets'} = 1;
18837: }
1.150 raeburn 18838: }
18839: }
1.210 raeburn 18840: }
1.150 raeburn 18841: }
18842: my $ishomedom;
1.171 raeburn 18843: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18844: $ishomedom = 1;
1.150 raeburn 18845: }
18846: if (ref($alltypes) eq 'ARRAY') {
18847: foreach my $type (@{$alltypes}) {
18848: my $rule;
1.210 raeburn 18849: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18850: (!$ishomedom)) {
1.171 raeburn 18851: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18852: }
18853: if ($rule eq 'specific') {
1.255 raeburn 18854: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 18855: if (exists($servers{$specifiedhost})) {
1.255 raeburn 18856: $rule = $specifiedhost;
18857: }
1.150 raeburn 18858: }
1.171 raeburn 18859: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18860: if (ref($currrules{$balancer}) eq 'HASH') {
18861: if ($rule ne $currrules{$balancer}{$type}) {
18862: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18863: }
18864: } elsif ($rule ne '') {
1.171 raeburn 18865: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18866: }
18867: }
18868: }
1.171 raeburn 18869: }
18870: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18871: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18872: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18873: $defaultshash{'loadbalancing'} = {};
18874: }
18875: my $putresult = &Apache::lonnet::put_dom('configuration',
18876: \%defaultshash,$dom);
18877: if ($putresult eq 'ok') {
18878: if (keys(%changes) > 0) {
1.252 raeburn 18879: my %toupdate;
1.171 raeburn 18880: if (ref($changes{'delete'}) eq 'ARRAY') {
18881: foreach my $balancer (sort(@{$changes{'delete'}})) {
18882: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 18883: $toupdate{$balancer} = 1;
1.150 raeburn 18884: }
1.171 raeburn 18885: }
18886: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 18887: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 18888: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 18889: $toupdate{$balancer} = 1;
1.171 raeburn 18890: }
18891: }
18892: if (ref($changes{'curr'}) eq 'HASH') {
18893: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 18894: $toupdate{$balancer} = 1;
1.171 raeburn 18895: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
18896: if ($changes{'curr'}{$balancer}{'targets'}) {
18897: my %offloadstr;
18898: foreach my $sparetype (@sparestypes) {
18899: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18900: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18901: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18902: }
18903: }
1.150 raeburn 18904: }
1.171 raeburn 18905: if (keys(%offloadstr) == 0) {
18906: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 18907: } else {
1.171 raeburn 18908: my $showoffload;
18909: foreach my $sparetype (@sparestypes) {
18910: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
18911: if (defined($offloadstr{$sparetype})) {
18912: $showoffload .= $offloadstr{$sparetype};
18913: } else {
18914: $showoffload .= &mt('None');
18915: }
18916: $showoffload .= (' 'x3);
18917: }
18918: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 18919: }
18920: }
18921: }
1.171 raeburn 18922: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
18923: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
18924: foreach my $type (@{$alltypes}) {
18925: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
18926: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18927: my $balancetext;
18928: if ($rule eq '') {
18929: $balancetext = $ruletitles{'default'};
1.209 raeburn 18930: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 18931: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 18932: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 18933: foreach my $sparetype (@sparestypes) {
18934: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18935: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
18936: }
18937: }
1.253 raeburn 18938: foreach my $item (@{$alltypes}) {
18939: next if ($item =~ /^_LC_ipchange/);
18940: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
18941: if ($hasrule eq 'homeserver') {
18942: map { $toupdate{$_} = 1; } (keys(%libraryservers));
18943: } else {
18944: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
18945: if ($servers{$hasrule}) {
18946: $toupdate{$hasrule} = 1;
18947: }
18948: }
18949: }
18950: }
1.254 raeburn 18951: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
18952: $balancetext = $ruletitles{$rule};
18953: } else {
18954: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
18955: $balancetext = $ruletitles{'particular'}.' '.$receiver;
18956: if ($receiver) {
18957: $toupdate{$receiver};
18958: }
18959: }
18960: } else {
18961: $balancetext = $ruletitles{$rule};
1.252 raeburn 18962: }
1.171 raeburn 18963: } else {
18964: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
18965: }
1.210 raeburn 18966: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 18967: }
18968: }
18969: }
18970: }
1.342 raeburn 18971: if ($changes{'curr'}{$balancer}{'cookie'}) {
18972: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
18973: $balancer).'</li>';
18974: }
1.252 raeburn 18975: if (keys(%toupdate)) {
18976: my %thismachine;
18977: my $updatedhere;
18978: my $cachetime = 60*60*24;
18979: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
18980: foreach my $lonhost (keys(%toupdate)) {
18981: if ($thismachine{$lonhost}) {
18982: unless ($updatedhere) {
18983: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
18984: $defaultshash{'loadbalancing'},
18985: $cachetime);
18986: $updatedhere = 1;
18987: }
18988: } else {
18989: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
18990: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
18991: }
18992: }
18993: }
1.150 raeburn 18994: }
1.171 raeburn 18995: }
18996: if ($resulttext ne '') {
18997: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 18998: } else {
18999: $resulttext = $nochgmsg;
19000: }
19001: } else {
1.171 raeburn 19002: $resulttext = $nochgmsg;
1.150 raeburn 19003: }
19004: } else {
1.171 raeburn 19005: $resulttext = '<span class="LC_error">'.
19006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 19007: }
19008: } else {
1.171 raeburn 19009: $resulttext = $nochgmsg;
1.150 raeburn 19010: }
19011: return $resulttext;
19012: }
19013:
1.48 raeburn 19014: sub recurse_check {
19015: my ($chkcats,$categories,$depth,$name) = @_;
19016: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
19017: my $chg = 0;
19018: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
19019: my $category = $chkcats->[$depth]{$name}[$j];
19020: my $item;
19021: if ($category eq '') {
19022: $chg ++;
19023: } else {
19024: my $deeper = $depth + 1;
19025: $item = &escape($category).':'.&escape($name).':'.$depth;
19026: if ($chg) {
19027: $categories->{$item} -= $chg;
19028: }
19029: &recurse_check($chkcats,$categories,$deeper,$category);
19030: $deeper --;
19031: }
19032: }
19033: }
19034: return;
19035: }
19036:
19037: sub recurse_cat_deletes {
19038: my ($item,$coursecategories,$deletions) = @_;
19039: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
19040: my $subdepth = $depth + 1;
19041: if (ref($coursecategories) eq 'HASH') {
19042: foreach my $subitem (keys(%{$coursecategories})) {
19043: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
19044: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
19045: delete($coursecategories->{$subitem});
19046: $deletions->{$subitem} = 1;
19047: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 19048: }
1.48 raeburn 19049: }
19050: }
19051: return;
19052: }
19053:
1.125 raeburn 19054: sub active_dc_picker {
1.191 raeburn 19055: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 19056: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 19057: my @domcoord = keys(%domcoords);
19058: if (keys(%currhash)) {
19059: foreach my $dc (keys(%currhash)) {
19060: unless (exists($domcoords{$dc})) {
19061: push(@domcoord,$dc);
19062: }
19063: }
19064: }
19065: @domcoord = sort(@domcoord);
1.210 raeburn 19066: my $numdcs = scalar(@domcoord);
1.191 raeburn 19067: my $rows = 0;
19068: my $table;
1.125 raeburn 19069: if ($numdcs > 1) {
1.191 raeburn 19070: $table = '<table>';
19071: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 19072: my $rem = $i%($numinrow);
19073: if ($rem == 0) {
19074: if ($i > 0) {
1.191 raeburn 19075: $table .= '</tr>';
1.125 raeburn 19076: }
1.191 raeburn 19077: $table .= '<tr>';
19078: $rows ++;
1.125 raeburn 19079: }
1.191 raeburn 19080: my $check = '';
19081: if ($inputtype eq 'radio') {
19082: if (keys(%currhash) == 0) {
19083: if (!$i) {
19084: $check = ' checked="checked"';
19085: }
19086: } elsif (exists($currhash{$domcoord[$i]})) {
19087: $check = ' checked="checked"';
19088: }
19089: } else {
19090: if (exists($currhash{$domcoord[$i]})) {
19091: $check = ' checked="checked"';
1.125 raeburn 19092: }
19093: }
1.191 raeburn 19094: if ($i == @domcoord - 1) {
1.125 raeburn 19095: my $colsleft = $numinrow - $rem;
19096: if ($colsleft > 1) {
1.191 raeburn 19097: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 19098: } else {
1.191 raeburn 19099: $table .= '<td class="LC_left_item">';
1.125 raeburn 19100: }
19101: } else {
1.191 raeburn 19102: $table .= '<td class="LC_left_item">';
19103: }
19104: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
19105: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19106: $table .= '<span class="LC_nobreak"><label>'.
19107: '<input type="'.$inputtype.'" name="'.$name.'"'.
19108: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19109: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 19110: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 19111: }
1.219 raeburn 19112: $table .= '</label></span></td>';
1.191 raeburn 19113: }
19114: $table .= '</tr></table>';
19115: } elsif ($numdcs == 1) {
1.219 raeburn 19116: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19117: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 19118: if ($inputtype eq 'radio') {
1.247 raeburn 19119: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 19120: if ($user ne $dcname.':'.$dcdom) {
19121: $table .= ' ('.$dcname.':'.$dcdom.')';
19122: }
1.191 raeburn 19123: } else {
19124: my $check;
19125: if (exists($currhash{$domcoord[0]})) {
19126: $check = ' checked="checked"';
1.125 raeburn 19127: }
1.247 raeburn 19128: $table = '<span class="LC_nobreak"><label>'.
19129: '<input type="checkbox" name="'.$name.'" '.
19130: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 19131: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 19132: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 19133: }
1.220 raeburn 19134: $table .= '</label></span>';
1.191 raeburn 19135: $rows ++;
1.125 raeburn 19136: }
19137: }
1.191 raeburn 19138: return ($numdcs,$table,$rows);
1.125 raeburn 19139: }
19140:
1.137 raeburn 19141: sub usersession_titles {
19142: return &Apache::lonlocal::texthash(
19143: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19144: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19145: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19146: version => 'LON-CAPA version requirement',
1.138 raeburn 19147: excludedomain => 'Allow all, but exclude specific domains',
19148: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19149: primary => 'Primary (checked first)',
1.154 raeburn 19150: default => 'Default',
1.137 raeburn 19151: );
19152: }
19153:
1.152 raeburn 19154: sub id_for_thisdom {
19155: my (%servers) = @_;
19156: my %altids;
19157: foreach my $server (keys(%servers)) {
19158: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19159: if ($serverhome ne $server) {
19160: $altids{$serverhome} = $server;
19161: }
19162: }
19163: return %altids;
19164: }
19165:
1.150 raeburn 19166: sub count_servers {
19167: my ($currbalancer,%servers) = @_;
19168: my (@spares,$numspares);
19169: foreach my $lonhost (sort(keys(%servers))) {
19170: next if ($currbalancer eq $lonhost);
19171: push(@spares,$lonhost);
19172: }
19173: if ($currbalancer) {
19174: $numspares = scalar(@spares);
19175: } else {
19176: $numspares = scalar(@spares) - 1;
19177: }
19178: return ($numspares,@spares);
19179: }
19180:
19181: sub lonbalance_targets_js {
1.171 raeburn 19182: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19183: my $select = &mt('Select');
19184: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19185: if (ref($servers) eq 'HASH') {
19186: $alltargets = join("','",sort(keys(%{$servers})));
19187: my @homedoms;
19188: foreach my $server (sort(keys(%{$servers}))) {
19189: if (&Apache::lonnet::host_domain($server) eq $dom) {
19190: push(@homedoms,'1');
19191: } else {
19192: push(@homedoms,'0');
19193: }
19194: }
19195: $allishome = join("','",@homedoms);
19196: }
19197: if (ref($types) eq 'ARRAY') {
19198: if (@{$types} > 0) {
19199: @alltypes = @{$types};
19200: }
19201: }
19202: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19203: $allinsttypes = join("','",@alltypes);
1.342 raeburn 19204: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 19205: if (ref($settings) eq 'HASH') {
19206: %existing = %{$settings};
19207: }
19208: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 19209: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 19210: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19211: return <<"END";
19212:
19213: <script type="text/javascript">
19214: // <![CDATA[
19215:
1.171 raeburn 19216: currBalancers = new Array('$balancers');
19217:
19218: function toggleTargets(balnum) {
19219: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19220: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19221: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19222: var prevbalancer = prevhostitem.value;
19223: var baltotal = document.getElementById('loadbalancing_total').value;
19224: prevhostitem.value = balancer;
19225: if (prevbalancer != '') {
19226: var prevIdx = currBalancers.indexOf(prevbalancer);
19227: if (prevIdx != -1) {
19228: currBalancers.splice(prevIdx,1);
19229: }
19230: }
1.150 raeburn 19231: if (balancer == '') {
1.171 raeburn 19232: hideSpares(balnum);
1.150 raeburn 19233: } else {
1.171 raeburn 19234: var currIdx = currBalancers.indexOf(balancer);
19235: if (currIdx == -1) {
19236: currBalancers.push(balancer);
19237: }
1.150 raeburn 19238: var homedoms = new Array('$allishome');
1.171 raeburn 19239: var ishomedom = homedoms[lonhostitem.selectedIndex];
19240: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19241: }
1.171 raeburn 19242: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19243: return;
19244: }
19245:
1.171 raeburn 19246: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19247: var alltargets = new Array('$alltargets');
19248: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19249: var offloadtypes = new Array('primary','default');
19250:
1.171 raeburn 19251: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19252: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19253:
1.151 raeburn 19254: for (var i=0; i<offloadtypes.length; i++) {
19255: var count = 0;
19256: for (var j=0; j<alltargets.length; j++) {
19257: if (alltargets[j] != balancer) {
1.171 raeburn 19258: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19259: item.value = alltargets[j];
19260: item.style.textAlign='left';
19261: item.style.textFace='normal';
19262: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19263: if (currBalancers.indexOf(alltargets[j]) == -1) {
19264: item.disabled = '';
19265: } else {
19266: item.disabled = 'disabled';
19267: item.checked = false;
19268: }
1.151 raeburn 19269: count ++;
19270: }
1.150 raeburn 19271: }
19272: }
1.151 raeburn 19273: for (var k=0; k<insttypes.length; k++) {
19274: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19275: if (ishomedom == 1) {
1.171 raeburn 19276: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19277: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19278: } else {
1.171 raeburn 19279: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19280: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19281: }
19282: } else {
1.171 raeburn 19283: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19284: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19285: }
1.151 raeburn 19286: if ((insttypes[k] != '_LC_external') &&
19287: ((insttypes[k] != '_LC_internetdom') ||
19288: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 19289: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19290: item.options.length = 0;
19291: item.options[0] = new Option("","",true,true);
1.210 raeburn 19292: var idx = 0;
1.151 raeburn 19293: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 19294: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19295: idx ++;
19296: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19297: }
19298: }
19299: }
19300: }
19301: return;
19302: }
19303:
1.171 raeburn 19304: function hideSpares(balnum) {
1.150 raeburn 19305: var alltargets = new Array('$alltargets');
19306: var insttypes = new Array('$allinsttypes');
19307: var offloadtypes = new Array('primary','default');
19308:
1.171 raeburn 19309: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19310: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19311:
19312: var total = alltargets.length - 1;
19313: for (var i=0; i<offloadtypes; i++) {
19314: for (var j=0; j<total; j++) {
1.171 raeburn 19315: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19316: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19317: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19318: }
1.150 raeburn 19319: }
19320: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 19321: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19322: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19323: if (insttypes[k] != '_LC_external') {
1.171 raeburn 19324: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19325: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19326: }
19327: }
19328: return;
19329: }
19330:
1.171 raeburn 19331: function checkOffloads(item,balnum,type) {
1.150 raeburn 19332: var alltargets = new Array('$alltargets');
19333: var offloadtypes = new Array('primary','default');
19334: if (item.checked) {
19335: var total = alltargets.length - 1;
19336: var other;
19337: if (type == offloadtypes[0]) {
1.151 raeburn 19338: other = offloadtypes[1];
1.150 raeburn 19339: } else {
1.151 raeburn 19340: other = offloadtypes[0];
1.150 raeburn 19341: }
19342: for (var i=0; i<total; i++) {
1.171 raeburn 19343: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19344: if (server == item.value) {
1.171 raeburn 19345: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19346: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19347: }
19348: }
19349: }
19350: }
19351: return;
19352: }
19353:
1.171 raeburn 19354: function singleServerToggle(balnum,type) {
19355: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19356: if (offloadtoSelIdx == 0) {
1.171 raeburn 19357: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19358: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19359:
19360: } else {
1.171 raeburn 19361: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19362: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19363: }
19364: return;
19365: }
19366:
1.171 raeburn 19367: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19368: if (type == '_LC_external') {
1.171 raeburn 19369: return;
1.150 raeburn 19370: }
1.171 raeburn 19371: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19372: for (var i=0; i<typesRules.length; i++) {
19373: if (formname.elements[typesRules[i]].checked) {
19374: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 19375: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19376: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19377: } else {
1.171 raeburn 19378: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19379: }
19380: }
19381: }
19382: return;
19383: }
19384:
19385: function balancerDeleteChange(balnum) {
19386: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19387: var baltotal = document.getElementById('loadbalancing_total').value;
19388: var addtarget;
19389: var removetarget;
19390: var action = 'delete';
19391: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19392: var lonhost = hostitem.value;
19393: var currIdx = currBalancers.indexOf(lonhost);
19394: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19395: if (currIdx != -1) {
19396: currBalancers.splice(currIdx,1);
19397: }
19398: addtarget = lonhost;
19399: } else {
19400: if (currIdx == -1) {
19401: currBalancers.push(lonhost);
19402: }
19403: removetarget = lonhost;
19404: action = 'undelete';
19405: }
19406: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19407: }
19408: return;
19409: }
19410:
19411: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19412: if (baltotal > 1) {
19413: var offloadtypes = new Array('primary','default');
19414: var alltargets = new Array('$alltargets');
19415: var insttypes = new Array('$allinsttypes');
19416: for (var i=0; i<baltotal; i++) {
19417: if (i != balnum) {
19418: for (var j=0; j<offloadtypes.length; j++) {
19419: var total = alltargets.length - 1;
19420: for (var k=0; k<total; k++) {
19421: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19422: var server = serveritem.value;
19423: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19424: if (server == addtarget) {
19425: serveritem.disabled = '';
19426: }
19427: }
19428: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19429: if (server == removetarget) {
19430: serveritem.disabled = 'disabled';
19431: serveritem.checked = false;
19432: }
19433: }
19434: }
19435: }
19436: for (var j=0; j<insttypes.length; j++) {
19437: if (insttypes[j] != '_LC_external') {
19438: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19439: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19440: var currSel = singleserver.selectedIndex;
19441: var currVal = singleserver.options[currSel].value;
19442: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19443: var numoptions = singleserver.options.length;
19444: var needsnew = 1;
19445: for (var k=0; k<numoptions; k++) {
19446: if (singleserver.options[k] == addtarget) {
19447: needsnew = 0;
19448: break;
19449: }
19450: }
19451: if (needsnew == 1) {
19452: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19453: }
19454: }
19455: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19456: singleserver.options.length = 0;
19457: if ((currVal) && (currVal != removetarget)) {
19458: singleserver.options[0] = new Option("","",false,false);
19459: } else {
19460: singleserver.options[0] = new Option("","",true,true);
19461: }
19462: var idx = 0;
19463: for (var m=0; m<alltargets.length; m++) {
19464: if (currBalancers.indexOf(alltargets[m]) == -1) {
19465: idx ++;
19466: if (currVal == alltargets[m]) {
19467: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19468: } else {
19469: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19470: }
19471: }
19472: }
19473: }
19474: }
19475: }
19476: }
1.150 raeburn 19477: }
19478: }
19479: }
19480: return;
19481: }
19482:
1.152 raeburn 19483: // ]]>
19484: </script>
19485:
19486: END
19487: }
19488:
19489: sub new_spares_js {
19490: my @sparestypes = ('primary','default');
19491: my $types = join("','",@sparestypes);
19492: my $select = &mt('Select');
19493: return <<"END";
19494:
19495: <script type="text/javascript">
19496: // <![CDATA[
19497:
19498: function updateNewSpares(formname,lonhost) {
19499: var types = new Array('$types');
19500: var include = new Array();
19501: var exclude = new Array();
19502: for (var i=0; i<types.length; i++) {
19503: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19504: for (var j=0; j<spareboxes.length; j++) {
19505: if (formname.elements[spareboxes[j]].checked) {
19506: exclude.push(formname.elements[spareboxes[j]].value);
19507: } else {
19508: include.push(formname.elements[spareboxes[j]].value);
19509: }
19510: }
19511: }
19512: for (var i=0; i<types.length; i++) {
19513: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19514: var selIdx = newSpare.selectedIndex;
19515: var currnew = newSpare.options[selIdx].value;
19516: var okSpares = new Array();
19517: for (var j=0; j<newSpare.options.length; j++) {
19518: var possible = newSpare.options[j].value;
19519: if (possible != '') {
19520: if (exclude.indexOf(possible) == -1) {
19521: okSpares.push(possible);
19522: } else {
19523: if (currnew == possible) {
19524: selIdx = 0;
19525: }
19526: }
19527: }
19528: }
19529: for (var k=0; k<include.length; k++) {
19530: if (okSpares.indexOf(include[k]) == -1) {
19531: okSpares.push(include[k]);
19532: }
19533: }
19534: okSpares.sort();
19535: newSpare.options.length = 0;
19536: if (selIdx == 0) {
19537: newSpare.options[0] = new Option("$select","",true,true);
19538: } else {
19539: newSpare.options[0] = new Option("$select","",false,false);
19540: }
19541: for (var m=0; m<okSpares.length; m++) {
19542: var idx = m+1;
19543: var selThis = 0;
19544: if (selIdx != 0) {
19545: if (okSpares[m] == currnew) {
19546: selThis = 1;
19547: }
19548: }
19549: if (selThis == 1) {
19550: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19551: } else {
19552: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19553: }
19554: }
19555: }
19556: return;
19557: }
19558:
19559: function checkNewSpares(lonhost,type) {
19560: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19561: var chosen = newSpare.options[newSpare.selectedIndex].value;
19562: if (chosen != '') {
19563: var othertype;
19564: var othernewSpare;
19565: if (type == 'primary') {
19566: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19567: }
19568: if (type == 'default') {
19569: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19570: }
19571: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19572: othernewSpare.selectedIndex = 0;
19573: }
19574: }
19575: return;
19576: }
19577:
19578: // ]]>
19579: </script>
19580:
19581: END
19582:
19583: }
19584:
19585: sub common_domprefs_js {
19586: return <<"END";
19587:
19588: <script type="text/javascript">
19589: // <![CDATA[
19590:
1.150 raeburn 19591: function getIndicesByName(formname,item) {
1.152 raeburn 19592: var group = new Array();
1.150 raeburn 19593: for (var i=0;i<formname.elements.length;i++) {
19594: if (formname.elements[i].name == item) {
1.152 raeburn 19595: group.push(formname.elements[i].id);
1.150 raeburn 19596: }
19597: }
1.152 raeburn 19598: return group;
1.150 raeburn 19599: }
19600:
19601: // ]]>
19602: </script>
19603:
19604: END
1.152 raeburn 19605:
1.150 raeburn 19606: }
19607:
1.165 raeburn 19608: sub recaptcha_js {
19609: my %lt = &captcha_phrases();
19610: return <<"END";
19611:
19612: <script type="text/javascript">
19613: // <![CDATA[
19614:
19615: function updateCaptcha(caller,context) {
19616: var privitem;
19617: var pubitem;
19618: var privtext;
19619: var pubtext;
1.269 raeburn 19620: var versionitem;
19621: var versiontext;
1.165 raeburn 19622: if (document.getElementById(context+'_recaptchapub')) {
19623: pubitem = document.getElementById(context+'_recaptchapub');
19624: } else {
19625: return;
19626: }
19627: if (document.getElementById(context+'_recaptchapriv')) {
19628: privitem = document.getElementById(context+'_recaptchapriv');
19629: } else {
19630: return;
19631: }
19632: if (document.getElementById(context+'_recaptchapubtxt')) {
19633: pubtext = document.getElementById(context+'_recaptchapubtxt');
19634: } else {
19635: return;
19636: }
19637: if (document.getElementById(context+'_recaptchaprivtxt')) {
19638: privtext = document.getElementById(context+'_recaptchaprivtxt');
19639: } else {
19640: return;
19641: }
1.269 raeburn 19642: if (document.getElementById(context+'_recaptchaversion')) {
19643: versionitem = document.getElementById(context+'_recaptchaversion');
19644: } else {
19645: return;
19646: }
19647: if (document.getElementById(context+'_recaptchavertxt')) {
19648: versiontext = document.getElementById(context+'_recaptchavertxt');
19649: } else {
19650: return;
19651: }
1.165 raeburn 19652: if (caller.checked) {
19653: if (caller.value == 'recaptcha') {
19654: pubitem.type = 'text';
19655: privitem.type = 'text';
19656: pubitem.size = '40';
19657: privitem.size = '40';
19658: pubtext.innerHTML = "$lt{'pub'}";
19659: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 19660: versionitem.type = 'text';
19661: versionitem.size = '3';
1.289 raeburn 19662: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 19663: } else {
19664: pubitem.type = 'hidden';
19665: privitem.type = 'hidden';
1.269 raeburn 19666: versionitem.type = 'hidden';
1.165 raeburn 19667: pubtext.innerHTML = '';
19668: privtext.innerHTML = '';
1.269 raeburn 19669: versiontext.innerHTML = '';
1.165 raeburn 19670: }
19671: }
19672: return;
19673: }
19674:
19675: // ]]>
19676: </script>
19677:
19678: END
19679:
19680: }
19681:
1.236 raeburn 19682: sub toggle_display_js {
1.192 raeburn 19683: return <<"END";
19684:
19685: <script type="text/javascript">
19686: // <![CDATA[
19687:
1.236 raeburn 19688: function toggleDisplay(domForm,caller) {
19689: if (document.getElementById(caller)) {
19690: var divitem = document.getElementById(caller);
19691: var optionsElement = domForm.coursecredits;
1.264 raeburn 19692: var checkval = 1;
19693: var dispval = 'block';
1.303 raeburn 19694: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 19695: if (caller == 'emailoptions') {
19696: optionsElement = domForm.cancreate_email;
19697: }
1.257 raeburn 19698: if (caller == 'studentsubmission') {
19699: optionsElement = domForm.postsubmit;
19700: }
1.264 raeburn 19701: if (caller == 'cloneinstcode') {
19702: optionsElement = domForm.canclone;
19703: checkval = 'instcode';
19704: }
1.303 raeburn 19705: if (selfcreateRegExp.test(caller)) {
19706: optionsElement = domForm.elements[caller];
19707: checkval = 'other';
19708: dispval = 'inline'
19709: }
1.236 raeburn 19710: if (optionsElement.length) {
1.192 raeburn 19711: var currval;
1.236 raeburn 19712: for (var i=0; i<optionsElement.length; i++) {
19713: if (optionsElement[i].checked) {
19714: currval = optionsElement[i].value;
1.192 raeburn 19715: }
19716: }
1.264 raeburn 19717: if (currval == checkval) {
19718: divitem.style.display = dispval;
1.192 raeburn 19719: } else {
1.236 raeburn 19720: divitem.style.display = 'none';
1.192 raeburn 19721: }
19722: }
19723: }
19724: return;
19725: }
19726:
19727: // ]]>
19728: </script>
19729:
19730: END
19731:
19732: }
19733:
1.165 raeburn 19734: sub captcha_phrases {
19735: return &Apache::lonlocal::texthash (
19736: priv => 'Private key',
19737: pub => 'Public key',
19738: original => 'original (CAPTCHA)',
19739: recaptcha => 'successor (ReCAPTCHA)',
19740: notused => 'unused',
1.289 raeburn 19741: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 19742: );
19743: }
19744:
1.205 raeburn 19745: sub devalidate_remote_domconfs {
1.212 raeburn 19746: my ($dom,$cachekeys) = @_;
19747: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 19748: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19749: my %thismachine;
19750: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 19751: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.364 raeburn 19752: 'directorysrch','passwdconf','cats');
1.260 raeburn 19753: if (keys(%servers)) {
1.205 raeburn 19754: foreach my $server (keys(%servers)) {
19755: next if ($thismachine{$server});
1.212 raeburn 19756: my @cached;
19757: foreach my $name (@posscached) {
19758: if ($cachekeys->{$name}) {
19759: push(@cached,&escape($name).':'.&escape($dom));
19760: }
19761: }
19762: if (@cached) {
19763: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19764: }
1.205 raeburn 19765: }
19766: }
19767: return;
19768: }
19769:
1.3 raeburn 19770: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>